[C++-sig] Segmentation Fault with Boost.Python and Inheritance

Gabe Rives-Corbett gabe at gaberivescorbett.com
Sat May 19 00:43:39 CEST 2012


Yes I'm using GCC 4.7 on OS X.  Is there any possible workaround to use inheritance with GCC 4.7?  I'm currently using c++11 threads which aren't supported on GCC 4.6 on OS X.  

-- 
Gabe Rives-Corbett
Cell: (805) 570-8395


On Friday, May 18, 2012 at 6:00 AM, cplusplus-sig-request at python.org wrote:

> Send Cplusplus-sig mailing list submissions to
> cplusplus-sig at python.org (mailto:cplusplus-sig at python.org)
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.python.org/mailman/listinfo/cplusplus-sig
> or, via email, send a message with subject or body 'help' to
> cplusplus-sig-request at python.org (mailto:cplusplus-sig-request at python.org)
> 
> You can reach the person managing the list at
> cplusplus-sig-owner at python.org (mailto:cplusplus-sig-owner at python.org)
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Cplusplus-sig digest..."
> 
> 
> Today's Topics:
> 
> 1. Segmentation Fault with Boost.Python and Inheritance
> (Gabe Rives-Corbett)
> 2. Re: Segmentation Fault with Boost.Python and Inheritance
> (Jonas Wielicki)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Thu, 17 May 2012 17:42:52 -0400
> From: Gabe Rives-Corbett <gabe at gaberivescorbett.com (mailto:gabe at gaberivescorbett.com)>
> To: cplusplus-sig at python.org (mailto:cplusplus-sig at python.org)
> Subject: [C++-sig] Segmentation Fault with Boost.Python and
> Inheritance
> Message-ID: <61DAADFBCA6D4C468EF8216B42EBAE48 at gaberivescorbett.com (mailto:61DAADFBCA6D4C468EF8216B42EBAE48 at gaberivescorbett.com)>
> Content-Type: text/plain; charset="utf-8"
> 
> 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
> 
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20120517/c42e81a8/attachment-0001.html>
> 
> ------------------------------
> 
> Message: 2
> Date: Fri, 18 May 2012 10:41:03 +0200
> From: Jonas Wielicki <j.wielicki at sotecware.net (mailto:j.wielicki at sotecware.net)>
> To: cplusplus-sig at python.org (mailto:cplusplus-sig at python.org)
> Subject: Re: [C++-sig] Segmentation Fault with Boost.Python and
> Inheritance
> Message-ID: <4FB60B1F.2050708 at sotecware.net (mailto:4FB60B1F.2050708 at sotecware.net)>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> 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 at python.org (mailto:Cplusplus-sig at python.org)
> http://mail.python.org/mailman/listinfo/cplusplus-sig
> 
> End of Cplusplus-sig Digest, Vol 44, Issue 17
> *********************************************
> 
> 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20120518/8149bf96/attachment-0001.html>


More information about the Cplusplus-sig mailing list