[C++-sig] Re: python binding problems

David Abrahams dave at boost-consulting.com
Sat Dec 27 23:36:22 CET 2003


"Dusty Leary" <dleary at ttlc.net> writes:

> 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"...

Pass ptr(x) instead of x if you don't want the foo copied.

HTH,
-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list