Re: [pygccxml-development] Recent Py++ modifications...
Brought to you by:
mbaas,
roman_yakovenko
From: Matthias B. <ba...@ir...> - 2006-09-18 17:22:34
|
Roman Yakovenko wrote: >> I've checked out Py++ from last week and gradually did updates to check >> which one was responsible for the failure. The problematic modification >> was done in revision 539: >> http://svn.sourceforge.net/viewvc/pygccxml?view=rev&revision=539 >> >> With this modification Py++ generates much more >> implicitly_convertible<>() statements in the main function. For example, >> I now have the following line which I think is responsible for the >> failure: >> >> bp::implicitly_convertible< MFloatVector const &, MVector >(); >> >> I can't say for sure what is going on inside of Boost.Python and why it >> fails, but at least I know that everything has worked before this >> modification. >> What kind of problems was this modification supposed to fix? > > I moved the logic whether to create "implicitly_convertible" code to > decl_wrapper > constructor class, where it should be. > >> And how do >> I get back to the previous behavior? > > This test > http://svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/casting_tester.py?view=markup&pathrev=539 > > shows that it should work by default. Can you modify test case in a > such way it will fail? I created a small test file that demonstrates the problem. While doing so, I noticed that the problem only exists when I manually add the copy constructor to the bindings (which is what I'm doing for the Maya bindings). Here's the C++ code: struct Vector { double val; Vector() : val(0) {} Vector(const Vector& v) : val(v.val) {} Vector(double x) : val(x) {} }; struct FloatVector { double val; FloatVector() : val(0) {} FloatVector(const FloatVector& v) : val(v.val) {} FloatVector(const Vector& v) : val(v.val) {} FloatVector(float x) : val(x) {} }; Py++ doesn't wrap the copy constructor, so I do that manually for the FloatVector class: root.Class("FloatVector").cdef("bp::init< const FloatVector& >()") This adds the line bp::init< const FloatVector& >() to the registration code of the FloatVector class. The generated main function looks like this: BOOST_PYTHON_MODULE(testlib){ register_FloatVector_class(); bp::implicitly_convertible< Vector const &, FloatVector >(); bp::implicitly_convertible< float, FloatVector >(); register_Vector_class(); bp::implicitly_convertible< double, Vector >(); } After compilation I try to create a FloatVector instance like this: fv = FloatVector(5.0) The result of this is the following exception: TypeError: No registered converter was able to extract a C++ reference to type Vector from this Python object of type float When I remove the line bp::implicitly_convertible< Vector const &, FloatVector >(); then the above instantiation works. - Matthias - |