Re: [pygccxml-development] Function adaptors
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2009-08-19 17:52:11
|
2009/8/19 Berserker <ber...@ho...>: >> > 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 am pretty sure this is illegal. Today, Py++ generates valid code for wide range of compilers and os. I think this change will break some of them. > 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... Sorry, I don't want such hacks in Py++. I believe that the generated code quality should be very very high, otherwise people will not trust the code and will not use Py++. I am not going to change this policy. As an alternative I propose you to use other Py++ feature: http://language-binding.net/pyplusplus/documentation/inserting_code.html Replace code generated by Py++ with your own one. >> > 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. I attached the generated file - please take a look on it. I hope it will clarify my answer. > My idea (not yet tested) for this problem doesn't involve any change in > Py++, Please test your ideas :-) > 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) Without changing\replacing some internal code you will not be able to do this :-(. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |