[C++-sig] Re: creating an instance of a class_<> object in c+ + an d exporting it to python
Francois Ostiguy
ostiguy at fnal.gov
Sat Aug 14 00:51:04 CEST 2004
Dave and Max -
Many thanks. With your suggestions, I am getting much closer ... but it is
not quite working yet.
Here is what I tried (in slightly simplified form):
...
class A;
class_<A, A*, boost::noncopyable> PythonTypeA;
A* aptr = new A();
A* get_existing() { return aptr; }
object py_get_existing =
make_function( &get_existing,
return_value_policy<reference_existing_object>() );
object PythonInstanceOfA = PythonTypeA( py_get_existing() );
...
The code compiles cleanly. Unfortunately, I get a core dump when the last
line is executed. The debugger tells me that the problem originates from
line 154 in return_from_python.hpp
151 inline T return_object_manager_from_python<T>::operator()(PyObject* obj) const
152 {
153 return T(
154 object_manager_traits<T>::adopt(expect_non_null(obj))
155 );
156 }
157 }
158
159 }}} // namespace boost::python::converter
160
obj is null and expect_non_null(obj) throws an exception. This function is
called from line 20 in object_call.cpp
13
14 template <BOOST_PP_ENUM_PARAMS_Z(1, N, class A)>
15 typename detail::dependent<object, A0>::type
16 operator()(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a)) const
17 {
18 typedef typename detail::dependent<object, A0>::type obj;
19 U const& self = *static_cast<U const*>(this);
20 return call<obj>(get_managed_object(self, tag), BOOST_PP_ENUM_PARAMS_Z(1, N, a));
21 }
22
so somehow, calling the object returned by py_get_existing appears
to return a null pointer.
-Francois
----------------------------------------------------------------------------
Dr. Jean-Francois OSTIGUY voice: (630) 840-2231
Beam Physics Dept MS220 FAX: (630) 840-6039
Fermi National Accelerator Laboratory email: ostiguy at fnal.gov
Batavia IL 60510-0500 WWW:www-ap.fnal.gov/~ostiguy
More information about the Cplusplus-sig
mailing list