[C++-sig] Type converter not found for property
Wichert Akkerman
wichert at wiggy.net
Fri May 10 11:26:25 CEST 2013
On May 10, 2013, at 11:10 , Wichert Akkerman <wichert at wiggy.net> wrote:
> On May 9, 2013, at 12:34 , Alex Leach <beamesleach at gmail.com> wrote:
>> On Thu, 09 May 2013 07:55:07 +0100, Wichert Akkerman <wichert at wiggy.net> wrote:
>>
>> On May 8, 2013, at 23:31 , "Alex Leach" <beamesleach at gmail.com> wrote:
>>
>>> That error means the type_id of uuid is not in the bp registry.
>>>
>>> I think you can fix this by deriving uuid_to_python from to_python_converter, as demonstrated in the pytype_function example[1]. This will add the get_pytype function call, and on initialisation, should hopefully add what's missing: a call to `registry::lookup`[2].
>>
>> I'm afraid that doesn't work. To test this I changes my converter struct to derive from bp::converter::wrap_pyttype<&PyStringType> and pass has_get_type=true to the to_python_converter call, but I still get the exact same error.
>>
>> Fair enough. I see your conversion function doesn't use bp::object, but a raw PyObject instead. Using a bp::object might do the registration for you.. Probably not. Alternatively, you could try adding this to your registration code:-
>>
>>
>> converter::registration& uuid_converter
>> = const_cast<converter::registration&>(
>> converter::registry::lookup(type_id<boost::uuids::uuid>()) );
>>
>> uuid_converter.m_class_object =
>> # if PY_VERSION_HEX >= 0x03000000
>> &PyUnicode_Type;
>> #else
>> &PyString_Type;
>> #endif
>>
>>
>> That will get you past the current error, at least, but there's probably an easier solution…
>
> That seems to do something! But still not quite there:
>
> >>> a.uuid
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: cannot create weak reference to 'str' object
> >>> u=a.uuid
> zsh: segmentation fault
Which can be fixed by not using def_readwrite but a property with a getting returning a new value instead of a reference:
.add_property("uuid",
bp::make_getter(&Article::uuid,
bp::return_value_policy<bp::return_by_value>()),
bp::make_setter(&Article::uuid))
After which everything seems to work!
Wichert.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20130510/3bbc0ab8/attachment-0001.html>
More information about the Cplusplus-sig
mailing list