Re: [pygccxml-development] Bug in virtual function wrapping with pyplusplus
Brought to you by:
mbaas,
roman_yakovenko
From: Allen B. <al...@vr...> - 2006-05-23 19:30:09
|
I should also have mentioned that as of yet I have not found a work around for this bug. I tried to work around it by "finalizing" the Son class, but I can't find a reliable way to finalize a class with pyplusplus. Until then I think I am at an impass. :( -Allen Allen Bierbaum wrote: > I think I have found a bug in the handling of virtual methods with > pyplusplus. > > I have attached a set of test classes and the generated bindings. > > The problem seems to be that when you have 3 classes derived from each > other as: > > class Grandpa > class Father : public Grandpa > class Son : public Father > > And Grandpa declares a pure virtual method that is defined in Father > but just used in Son, the wrapper for Son still thinks it is a pure > virtual and doesn't know to generate code with the default > implementation in Father. (See the attached code, it really makes > more sense with an example) > > -Allen > >------------------------------------------------------------------------ > >// This file has been generated by pyplusplus. > >#include "boost/python.hpp" > >#include "/home/allenb/temp/pypp_test/Classes.h" > >namespace bp = boost::python; > >struct Grandpa_wrapper : test_ns::Grandpa, bp::wrapper< test_ns::Grandpa > { > > Grandpa_wrapper() > : test_ns::Grandpa() > , bp::wrapper< test_ns::Grandpa >() > {} > > virtual int gp_pure( int i ){ > bp::override func_gp_pure = this->get_override( "gp_pure" ); > return func_gp_pure( i ); > } > >}; > >struct Father_wrapper : test_ns::Father, bp::wrapper< test_ns::Father > { > > Father_wrapper(test_ns::Father const & arg ) > : test_ns::Father( arg ) > , bp::wrapper< test_ns::Father >() > {} > > Father_wrapper() > : test_ns::Father() > , bp::wrapper< test_ns::Father >() > {} > > virtual int gp_pure( int i ) { > if( bp::override func_gp_pure = this->get_override( "gp_pure" ) ) > return func_gp_pure( i ); > else > return test_ns::Father::gp_pure( i ); > } > > > virtual int default_gp_pure( int i ) { > return test_ns::Father::gp_pure( i ); > } > >}; > >struct Son_wrapper : test_ns::Son, bp::wrapper< test_ns::Son > { > > Son_wrapper(test_ns::Son const & arg ) > : test_ns::Son( arg ) > , bp::wrapper< test_ns::Son >() > {} > > Son_wrapper() > : test_ns::Son() > , bp::wrapper< test_ns::Son >() > {} > > virtual int gp_pure( int i ){ > bp::override func_gp_pure = this->get_override( "gp_pure" ); > return func_gp_pure( i ); > } > >}; > >BOOST_PYTHON_MODULE(_test){ > bp::class_< Grandpa_wrapper, boost::noncopyable >( "Grandpa" ) > .def("gp_pure" > , bp::pure_virtual( &::test_ns::Grandpa::gp_pure ) > , ( bp::arg("i") ) > , bp::default_call_policies() ); > > bp::class_< Father_wrapper, bp::bases< test_ns::Grandpa > >( "Father" ) > .def("gp_pure" > , &::test_ns::Father::gp_pure > , &Father_wrapper::default_gp_pure > , ( bp::arg("i") ) > , bp::default_call_policies() ); > > bp::class_< Son_wrapper, bp::bases< test_ns::Father > >( "Son" ) > .def("gp_pure" > , bp::pure_virtual( &::test_ns::Grandpa::gp_pure ) > , ( bp::arg("i") ) > , bp::default_call_policies() ); >} > > >------------------------------------------------------------------------ > > >namespace test_ns >{ >class Grandpa >{ >public: > virtual int gp_pure(int i) = 0; >}; > >class Father : public Grandpa >{ >public: > virtual int gp_pure(int i); >}; > >class Son : public Father >{ >public: >}; > >} // namespace test_ns > > |