[C++-sig] more problems with python::return_internal_reference<>
Stefan Seefeld
stefan.seefeld at orthosoft.ca
Mon Jul 14 23:11:09 CEST 2003
hi there,
I'm compiling the following code with gcc 3.2:
#include <boost/python.hpp>
namespace python = boost::python;
namespace
{
class Bar {};
Bar *BarFactory()
{
static Bar bar;
return &bar;
}
}
BOOST_PYTHON_MODULE(Sandbox)
{
python::class_<Foo, boost::noncopyable> foo("Foo", python::no_init);
python::class_<Bar, boost::noncopyable> bar("Bar", python::no_init);
bar.def("foo", &Bar::foo, python::return_internal_reference<>());
python::def("Bar", BarFactory,
python::return_internal_reference<>());
//python::return_value_policy<python::manage_new_object>());
}
That compiles fine, but when I call the 'Bar' constructor from python,
I get
>>> from Sandbox import *
>>> bar = Bar()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
IndexError: tuple index out of range
What is going on here ? What does the boost::python runtime do with the
returned value that involves a tuple ?
When I replace the 'return_internal_reference<>' policy by
'return_value_policy<manage_new_object>' the function call
returns successfully. But of course, that would crash at the end of
the application...
Thanks again,
Stefan
More information about the Cplusplus-sig
mailing list