[C++-sig] Custom by value type to python type conversion

Niall Douglas s_sourceforge at nedprod.com
Wed Nov 5 07:03:02 CET 2003


This is hopefully the last problem before the v0.4 release, yippee! 
:)

BPL is complaining when I try to access a FXString which I have 
registered a conversion for using to_python_converter:

No Python class registered for C++ class FX::FXString.

The code triggering this is:

txt+=" %s\n" % mapping.path

... where mapping.path is a FXString. My converter is:

struct FXString_to_python_str : public 
to_python_converter<FX::FXString, FXString_to_python_str>
{
	static PyObject *convert(const FX::FXString &str)
	{
		return PyString_FromStringAndSize(str.text(), str.length());
		//return incref(boost::python::object(str).ptr());
	}
};

... and yes, a breakpoint shows it's getting installed. BPL is also 
right that I have not registered FXString as I feel it's superfluous, 
however if I do I get:

..\TestSuite\TestPython\main.py:24: RuntimeWarning: to-Python 
converter for class FX::FXString already registered; second 
conversion method ignored.

... and then it goes to NOT call the 
FXString_to_python_str::convert() anyway (again, according to 
breakpoint). What am I missing? From the examples and list archives, 
I would have appeared to have done everything!

Looking at the internal builtin_converters.hpp, it would seem that 
there's more that needs to be done, but since that's internal there 
must be another way?

Cheers,
Niall




-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 208 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20031105/e72b75a3/attachment.pgp>


More information about the Cplusplus-sig mailing list