Can someone confirm that this is correct: 1. To get a boost::python::object that wraps an existing PyObject* (when you get a PyObject from a C function not wrapped in boost::python), can someone confirm that this is correct: Either: a) PyObject* c_object = get_the_c_object(); //returns a reference. boost::python::handle<> handle(c_object); boost::python::object cpp_object(handle); or b) PyObject* c_object = get_the_c_object(); //returns no extra reference. boost::python::handle<> handle(boost::python::borrowed(cObject)); boost::python::object cpp_object(handle);
The code for b) can be simplified by doing boost::python::object cpp_object(boost::python::borrowed(cObject)) but I don't see a way to simplify a) I also see allow_null here, but like borrowed, it's not documented: http://www.boost.org/doc/libs/1_41_0/libs/python/doc/v2/handle.html#allow_null-spec so I can only guess at its purpose. In general I wish this was much simpler and stated clearly somewhere. 2. How can I get the underlying PyObject* from a boost::python::object (when I need it to call a C function not wrapped in boost::python)? I guessed at this, but it doesn't seem to be working for me: boost::python::extract<PyObject*> extractor(cpp_object); if(extractor.check()) { PyObject* c_object = extractor; } -- murr...@murrayc.com www.murrayc.com www.openismus.com _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig