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

Clark foo.Clark at gmail.com
Mon Jul 4 06:07:36 CEST 2005


On Sat, Jul 02, 2005 at 09:53:10PM -0400, David Abrahams wrote:
> "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?
Yes, they are all PySwigObject.
> 
> 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.
Sometimes it's critical. For example, to paint on screen efficiently, we must
use the DC's methods in C++ directly. But because usually the GUI or framework
is written in Python, we can only get the DC as a Python Object.

Maybe we can also emulate the behaviors of SWIG to do error checking and
it may not be very easy. It may not be implemented in Boost.Python
soon. And I can't wait any more for my project has began. 

> 
> -- 
> Dave Abrahams
> Boost Consulting
> www.boost-consulting.com
> 
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig



More information about the Cplusplus-sig mailing list