[C++-sig] python binding problems

Dusty Leary dleary at ttlc.net
Sat Dec 27 23:17:55 CET 2003


Hello,

I have used boost::python to make python bindings for a rather large
interface at work.  There, we have lots of virtual interfaces, with python
using and invoking them, and in a few cases, extending them, with no
problem.

Now, at home, I am trying to bind another project.  This one is a bit
different.

The root of the problem is that I want python's "held values" for my types
to usually be pointers.  The project I am binding with makes heavy use of
pointer identity (for serializing structs for network comm.)

I am running into some problems.

Basically, I am calling a python function with structure instances...  like
so:

PyObject* func;
foo* foo_instance;
boost::python::call<void>(func, foo_instance);

But, binding foo is problematic...

If I use:  class_<foo>("foo")...;, then copies of foo instances are made,
and used in the python objects, even though I am calling functions and
passing in foo* parameters.

If I use: class_<foo, boost::noncopyable>("foo")...;, then when I pass in my
foo* values, I get boost python errors (when I call the function), "no
to-python (by-value) convertor for struct foo"...

If I wrap my foo*'s in a simple template "smart pointer" class I made, and
use:  class_<foo, simple_wrap<foo>, boost::noncopyable>("foo")...;, then the
object identity works fine, but it still complains about "no to-python"
convertors if I use raw foo*'s in boost::python::call instead of explicitly
wrapping them in simple_wrap<foo>...


I would have thought this pattern at least somewhat common...  For return
values, you can specify reference_existing_object, return_opaque_pointer,
etc...  How do we do this for input values?






More information about the Cplusplus-sig mailing list