[C++-sig] Help with custom converters

Lloyd Weehuizen lloyd at fusion.net.nz
Sat Jan 5 01:44:24 CET 2008


Hi

I've done more research into the problem and it appears that when 
passing an Interface* object into a bp::object's constructor, boost 
looks up a converter for type Interface, not Interface* (which the 
converter is registered against).

Registering a converter for an abstract interface seems impossible at 
the moment due to the compile time checks in as_to_python_function which 
cause the compiler to attempt to instance the class.

template <class U>
static void convert_function_must_take_value_or_const_reference(U(*)(T), 
int, T* = 0) {}
template <class U>

static void convert_function_must_take_value_or_const_reference(U(*)(T 
const&), long ...) {}

Commenting out the above checks and registering the converter directly 
makes everything work correctly.

Is there a cleaner solution to my abstract interface/converter problem?

Thanks,
Lloyd

Lloyd Weehuizen wrote:
 > Hi
 >
 > I'm having a strange problem when using custom converters, they seem
 > to work fine when I have a function/method that returns an object 
type > but fails if I try use the object as a boost::python::object.
 >
 > The error I get is:
 >
 > TypeError: No to_python (by-value) converter found for C++ type: class
 > Interface
 >
 > For example:
 >
 > Interface* TestConverter(Interface* interface)
 > {
 >     return interface;
 > }
 >
 > Works correctly, the python class instance that inherits from
 > Interface passes correctly through the TestConverter method when
 > called from python.
 >
 > However, if I try this:
 > Interface* TestConverter(Interface* interface)
 > {
 >     boost::python::object obj(interface);
 >     return interface;
 > }
 >
 > Then the TypeError is thrown. I would have thought the converter would
 > be called for this case as well?
 >
 > Here's the converter code:
 >



More information about the Cplusplus-sig mailing list