Re: [pygccxml-development] Function adaptors
Brought to you by:
mbaas,
roman_yakovenko
From: Berserker <ber...@ho...> - 2009-08-19 08:51:00
|
> > the problem is related to protected_virtual > > method where Py++ > > only generates Foo_wrapper::protected_virtual code (why?). > > I don't remember. I think there were serious problems in that area. > After all, it is impossible to access protected functions out side of > the class and this is the main problem. Not with wrapper class, right? This is the "problematic" code (actually) generated from Py++ > ::boost::python::class_< Foo_wrapper, ::boost::noncopyable >( "Foo", ::boost::python::init< >() ) > .def( > "public_virtual" > , (void ( ::Foo::* )( ) )(&::Foo::public_virtual) > , (void ( Foo_wrapper::* )( ) )(&Foo_wrapper::default_public_virtual) ) > .def( > "protected_virtual" > , (void ( Foo_wrapper::* )( ) )(&Foo_wrapper::protected_virtual) ) ); I manually added the "Foo_wrapper::default_protected_virtual" like "Foo_wrapper::default_public_virtual": > void Foo_wrapper::default_protected_virtual( ) > { > // my custom code... > ::Foo::protected_virtual( ); > } and I changed the previous code in this way: > ::boost::python::class_< Foo_wrapper, ::boost::noncopyable >( "Foo", ::boost::python::init< >() ) > .def( > "public_virtual" > , (void ( ::Foo::* )( ) )(&::Foo::public_virtual) > , (void ( Foo_wrapper::* )( ) )(&Foo_wrapper::default_public_virtual) ) > .def( > "protected_virtual" > , (void ( ::Foo::* )( ) )(&::Foo_wrapper::protected_virtual) > , (void ( Foo_wrapper::* )( ) )(&Foo_wrapper::default_protected_virtual) ) ); The only "hack" is the bad cast in the line "(void ( ::Foo::* )( ) )(&::Foo_wrapper::protected_virtual)" but I tested the code from Python to C++ and from C++ to Python and now it works as I expected! I absolutely need to call a "base virtual protected method" in Python, what about this solution? Plz this is my "last" obstacle and I really don't know how to change the python scripts... > > In the case of a C++ to Python calls, I would need, as usual, to restore the > > right PyThreadState > > before calling any CPython API (PyErr_SetString in the above's code), but I > > have no options here to customize > > "pure_virtual_called". Probably I'll ovverride in Py++ the identifier > > "::boost::python::pure_virtual" with a > > custom one, but I still need to think/work on this (I love the "override" > > feature in Py++ :) ). > > This one is fixed. I will commit the code soon. Sorry but I didn't understand well what was fixed here. My idea (not yet tested) for this problem doesn't involve any change in Py++, here is a short description of it: - Disable the ::boost::python::pure_virtual exposition overriding the identifier with "" - Create a custom class based on "::boost::python::override" which holds a reference to PyThreadState and don't release it in the case of a pure virtual function call (which raises an exception) _________________________________________________________________ Porta Hotmail in vacanza. Leggi la posta dal cellulare! http://new.windowslivemobile.msn.com/IT-IT/windows-live-hotmail/default.aspx |