Segmentation Fault with Boost.Python and Inheritance
Hello, I'm getting a seg fault when trying to call a virtual method on a base class from python. Code is below: #include <memory> namespace boost { template<class T> const T* get_pointer(const std::shared_ptr<T>& ptr) { return ptr.get(); } template<class T> T* get_pointer(std::shared_ptr<T>& ptr) { return ptr.get(); } } #include <Python.h> #include <boost/python.hpp> namespace bp = boost::python; class MyBase { public: MyBase(){} virtual ~MyBase(){} virtual void baseTest() { printf("base test\n"); } }; class MyDerived : public MyBase { public: MyDerived() {} virtual ~MyDerived(){} void derivedTest() { printf("derived test\n"); } }; BOOST_PYTHON_MODULE(PythonTest) { bp::class_<MyBase, std::shared_ptr<MyBase>>("MyBase") .def("baseTest", &MyBase::baseTest); bp::class_<MyDerived, bp::bases<MyBase>, std::shared_ptr<MyDerived>>("MyDerived") .def("derivedTest", &MyDerived::derivedTest); bp::implicitly_convertible<std::shared_ptr<MyDerived>, std::shared_ptr<MyBase>>(); } Does it have to do with using std::shared_ptr for storage? If so is there a way around this? Any help is appreciated. -- Gabe Rives-Corbett
On 17/05/12 23:42, Gabe Rives-Corbett wrote:
I'm getting a seg fault when trying to call a virtual method on a base class from python. I had a similar problem a few days ago. Which g++ version are you using? I had problems with 4.7.0 (redhat) while 4.6.3 (redhat) was working fine.
-- Jonas
So it was a bug in GCC after all. Useful to know. Niall On 18 May 2012 at 10:41, Jonas Wielicki wrote:
On 17/05/12 23:42, Gabe Rives-Corbett wrote:
I'm getting a seg fault when trying to call a virtual method on a base class from python. I had a similar problem a few days ago. Which g++ version are you using? I had problems with 4.7.0 (redhat) while 4.6.3 (redhat) was working fine.
-- Jonas _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
-- Technology & Consulting Services - ned Productions Limited. http://www.nedproductions.biz/. VAT reg: IE 9708311Q. Work Portfolio: http://careers.stackoverflow.com/nialldouglas/
So it was a bug in GCC after all. Useful to know. Sorry that I forgot to mention. I was pretty sure it was the GCC after I
On 18.05.2012 19:47, Niall Douglas wrote: tried with two different Boost versions and the very same code was running fine on gcc 4.6.3 platforms. It is not 100% bulletproof, but I guess its the GCCs fault. -- Jonas
It's especially useful to know because this list can expect the same problem to be reported as a bug in BPL repeatedly from now on :) Did you submit the bug to GCC's bugzilla, and if you did do you have a link? If you didn't, submitting it and having it rejected is worth doing just so we can link to the bug from here. Niall On 18 May 2012 at 20:28, Jonas Wielicki wrote:
So it was a bug in GCC after all. Useful to know. Sorry that I forgot to mention. I was pretty sure it was the GCC after I
On 18.05.2012 19:47, Niall Douglas wrote: tried with two different Boost versions and the very same code was running fine on gcc 4.6.3 platforms. It is not 100% bulletproof, but I guess its the GCCs fault.
-- Jonas _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
-- Technology & Consulting Services - ned Productions Limited. http://www.nedproductions.biz/. VAT reg: IE 9708311Q. Work Portfolio: http://careers.stackoverflow.com/nialldouglas/
I believe I hit the same bug, using extract on a polymorphic type. In the old code, I used make_constructor, passing object to it, and using extract. In the new code, I don't use make_constructor, just use bp::init. My segfault is gone. Maybe just luck?
participants (4)
-
Gabe Rives-Corbett -
Jonas Wielicki -
Neal Becker -
Niall Douglas