1

I'm trying to figure whats wrong with some autogenerated (with Pyste) boost::python code, but have no luck so far.

There is C++ library, Magick++, which provides two classes, Magick::Drawable and Magick::DrawableRectangle:

https://www.imagemagick.org/subversion/ImageMagick/trunk/Magick++/lib/Magick++/Drawable.h

class MagickDLLDecl DrawableBase:
   public std::unary_function<MagickCore::DrawingWand,void>
{...}
class MagickDLLDecl Drawable
{
  public:
    // Constructor
    Drawable ( void );
    // Construct from DrawableBase
    Drawable ( const DrawableBase& original_ );
...
}
class MagickDLLDecl DrawableRectangle : public DrawableBase
{ ... }

These are used as arguments for Image.draw(): https://www.imagemagick.org/subversion/ImageMagick/trunk/Magick++/lib/Magick++/Image.h

// Draw on image using a single drawable
void            draw ( const Drawable &drawable_ );
// Draw on image using a drawable list
void            draw ( const std::list<Magick::Drawable> &drawable_ );

I'm trying to make python bindings for it, there are autogenned wrappers for all the classes,

http://bitbucket.org/dan.kluev/pythonmagick/src/65d45c998ef3/src/_Drawable.cpp

http://bitbucket.org/dan.kluev/pythonmagick/src/65d45c998ef3/src/_DrawableRectangle.cpp

http://bitbucket.org/dan.kluev/pythonmagick/src/65d45c998ef3/src/_Image.cpp

Problem is, due to indirect class casts from DrawableBase to Drawable, these wrappers do not work:

>>> import PythonMagick
>>> image = PythonMagick.Image()
>>> square = PythonMagick._PythonMagick.DrawableRectangle(0,0,200,200)
>>> image.draw(square)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
    Image.draw(Image, DrawableRectangle)
did not match C++ signature:
    draw(Magick::Image {lvalue}, std::list<Magick::Drawable, std::allocator<Magick::Drawable> >)
    draw(Magick::Image {lvalue}, Magick::Drawable)
# But abstract Drawable() does work:
>>> image.draw(PythonMagick._PythonMagick.Drawable())
>>> 

Is there any better way to handle this than write my own draw() wrapper in C++, which would cast PyObject into Drawable?

2
  • This should be tagged with 'pyste' as well as 'boost-python'. Commented Dec 2, 2010 at 17:14
  • @Matthew, pyste was used before to autogen code, but is dropped now, and code is supported w/out it. Commented Dec 3, 2010 at 1:35

1 Answer 1

1

If you want BP to implicitly convert objects foy you , you must tell BP that thay are implicitly convertable. put something like this in your bp::code:

boost::python::implicitly_convertible<SourceType,DestType>();

I do not know how to induce Pyste to do this.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot, that indeed kind of worked. It runs fine if I do implicitly_convertible<DrawableRectangle,Drawable>, but segfaults on implicitly_convertible<DrawableBase,Drawable>. Oh well, copypasting all Drawables will do it too.
Hmm. As far as I know it ought to work. Maybe the segfault is in the wrapped lib? Or maybe a bad interaction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.