Subject: [Boost-bugs] [Boost C++ Libraries] #2049: extracting c++ pointer from python object with multiple parents
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-06-25 15:50:06
#2049: extracting c++ pointer from python object with multiple parents
----------------------------------+-----------------------------------------
Reporter: bloodyfanatic_at_[hidden] | Owner: dave
Type: Bugs | Status: new
Milestone: Boost 1.35.1 | Component: Python
Version: Boost 1.35.0 | Severity: Problem
Keywords: |
----------------------------------+-----------------------------------------
Extracting a C++ pointer from a python object which inherited two base
classes form C++ doesn't work correctly.
Only the first base can be extracted, the second cannot be extracted under
all circumstances.
The script runs within an embedded python interpreter.
CPP code:
{{{
#define BOOST_PYTHON_STATIC_LIB
#include <boost/python.hpp>
using namespace boost::python;
class Base1
{
public:
virtual ~Base1() {}
};
class Base2
{
public:
virtual ~Base2() {}
};
void extractBase1( boost::python::object& obj)
{
Base1* ex1 = extract<Base1*>(obj) BOOST_EXTRACT_WORKAROUND;
Base1& ex2 = extract<Base1&>(obj) BOOST_EXTRACT_WORKAROUND;
}
void extractBase2( boost::python::object& obj)
{
Base2* ex1 = extract<Base2*>(obj) BOOST_EXTRACT_WORKAROUND;
Base2& ex2 = extract<Base2&>(obj) BOOST_EXTRACT_WORKAROUND;
}
BOOST_PYTHON_MODULE(Test_ext)
{
class_<Base1, boost::noncopyable>("Base1");
class_<Base2, boost::noncopyable>("Base2");
def("extractBase1", extractBase1);
def("extractBase2", extractBase2);
}
int main(int, char **)
{
try
{
Py_Initialize();
initTest_ext();
object main = import("__main__");
object dictionary(main.attr("__dict__"));
object result = exec_file("test.py", dictionary,
dictionary );
}
catch (error_already_set)
{
PyErr_Print();
}
return 0;
}
}}}
test.py:
{{{
from Test_ext import *
class both1(Base1, Base2):
def foo(self):
print "foo!"
class both2(Base2, Base1):
def foo(self):
print "foo2!"
obj1 = both1()
extractBase1(obj1)
extractBase2(obj1) # doesn't work
obj2 = both()
extractBase1(obj2) # doesn't work
extractBase2(obj2)
}}}
--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/2049>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:58 UTC