Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#6919 closed Bugs (invalid)

g++ -std=c++11 breaks class inheritance with boost::shared_ptr

Reported by: altan@… Owned by: Ralf W. Grosse-Kunstleve
Milestone: To Be Determined Component: python USE GITHUB
Version: Boost 1.49.0 Severity: Problem
Keywords: boost python class inheritance c++11 Cc: altan@…

Description

This simple program was developed to test sharing a C++ class with inheritance to Python. Output crashes inside boost::python when it is compiled by -std=c++11 flag in g++ 4.7.0 (NOTE: It works ok with g++ 4.4.6 -std=c++0x)

Compiler: GNU 4.7.0 Platforms: Centos 6.2, Mac OS X Lion Boost: 1.49.0 Python: 2.7.3

Crash when running test3 produced by: g++ test3.cc -I../../ext/boost/Linux/include -I../../ext/python/Linux/include ../../ext/boost/Linux/lib/libboost_python.a ../../ext/python/Linux/lib/libpython.so -o test3 -std=c++11 No crash when running test3 produced by: g++ test3.cc -I../../ext/boost/Linux/include -I../../ext/python/Linux/include ../../ext/boost/Linux/lib/libboost_python.a ../../ext/python/Linux/lib/libpython.so -o test3 #include <boost/python.hpp> #include <boost/shared_ptr.hpp> #include <boost/make_shared.hpp> #include <iostream>

using namespace std;

namespace bp = boost::python;

struct Foo{

virtual void doSomething() {

cout << "Foo" << endl;

}

};

struct Goo : Foo {

virtual void doSomething() {

cout << "Goo" << endl;

}

};

BOOST_PYTHON_MODULE(hello) {

bp::class_<Foo, boost::shared_ptr<Foo> >("Foo")

.def("doSomething", &Foo::doSomething);

bp::class_<Goo, bp::bases<Foo>, boost::shared_ptr<Goo> >("Goo");

}; NOTE: Output works allright when there is no shared_ptr in bp::class_ above

int main(int argc, char argv) {

Py_Initialize(); bp::object main = bp::import("main"); bp::object main_namespace = main.attr("dict"); inithello(); main_namespacehello = bp::import("hello"); bp::exec("a = hello.Goo(); a.doSomething()", main_namespace); Py_Main(argc, argv); Py_Finalize(); return 0;

}

Change History (4)

comment:1 by anonymous, 10 years ago

After recompiling boost::python library using gcc 4.7 (using flags -std=c++11 -fno-strict-aliasing), the crash is not present anymore. This bug can be closed.

comment:2 by Ralf W. Grosse-Kunstleve, 10 years ago

Resolution: invalid
Status: newclosed

comment:3 by Rob Stewart, 10 years ago

According to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53455#c11, this issue should not have been closed. -fno-strict-aliasing enables non-conforming behavior.

comment:4 by Ralf W. Grosse-Kunstleve, 10 years ago

Any code including Python.h needs to be compiled with -fno-strict-aliasing (because of the way PyObject is implemented IIUC).

Note: See TracTickets for help on using tickets.