[C++-sig] In a C++ extension, how to use a C++ class exported in another extension

David Abrahams dave at boost-consulting.com
Sun Jul 3 03:53:10 CEST 2005


"Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com> writes:

> Thanks for posting this. It is very interesting!
>
> David, how difficult would it be to provide something like
>
>   boost::python::arg_from_swig_object<Foo>();
>
> so that we could wrap functions taking SWIG-wrapped arguments
> directly?

I don't know enough about what SWIG does to say for sure, but I
presume it is generating a type object for each class you wrap... (**)

> I guess there is no easy way to construct SWIG-wrapped return values without a
> lot of support from SWIG, 

Perhaps not; I don't know what SWIG provides.

> but automatically extracting the pointer to turn it
> into a T*, T&, const T*, const T& argument seems like something that may not be
> too hard... true?
>
> Looking some more, isn't this almost it?
>
>   http://www.boost.org/libs/python/doc/v2/lvalue_from_pytype.html

Yes.

> But we want to do it without having the equivalent of
> noddy_NoddyType, 

(**) ...just like noddy_NoddyType.  Are you sure we don't want to have
the equivalent of that?

> just knowing that ((PySwigObject*)obj.ptr())->ptr gives us the T*.

Oh, I see; all Swig objects have the same type?

Well you need some way to identify the Python objects for which the
above statement is true, unless you want to forego all error checking
and just allow a crash if a Swig-wrapped Foo is passed where a
Swig-wrapped Bar is expected.  

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




More information about the Cplusplus-sig mailing list