Index: libs/python/doc/tutorial/doc/tutorial.qbk =================================================================== --- libs/python/doc/tutorial/doc/tutorial.qbk (revision 76195) +++ libs/python/doc/tutorial/doc/tutorial.qbk (working copy) @@ -1302,6 +1302,23 @@ [def PyModule_GetDict [@http://www.python.org/doc/current/api/moduleObjects.html#l2h-594 PyModule_GetDict]] [endsect] + +[section:creating_python_object Creating `boost::python::object` from `PyObject*`] + +When you want a `boost::python::object` to manage a pointer to `PyObject*` pyobj one does: + + boost::python::object o(boost::python::handle<>(pyobj)); + +In this case, the `o` object, manages the `pyobj`, it won’t increase the reference count on construction. + +Otherwise, to use a borrowed reference: + + boost::python::object o(boost::python::handle<>(boost::python::borrowed(pyobj))); + +In this case, `Py_INCREF` is called, so `pyobj` is not destructed when object o goes out of scope. + +[endsect] [/ creating_python_object ] + [endsect] [/ Object Interface] [section Embedding] Index: libs/python/doc/tutorial/doc/html/python/object.html =================================================================== --- libs/python/doc/tutorial/doc/html/python/object.html (revision 76196) +++ libs/python/doc/tutorial/doc/html/python/object.html (working copy) @@ -30,6 +30,7 @@
Derived Object types
Extracting C++ objects
Enums
+
Creating boost::python::object from PyObject*

Python is dynamically typed, unlike C++ which is statically typed. Python variables @@ -314,7 +315,33 @@ ; +

+

+Creating boost::python::object from PyObject* +

+

+ When you want a boost::python::object to manage a pointer to PyObject* + pyobj one does: +

+
boost::python::object o(boost::python::handle<>(pyobj));
+
+

+ In this case, the o object, + manages the pyobj, it won’t + increase the reference count on construction. +

+

+ Otherwise, to use a borrowed reference: +

+
boost::python::object o(boost::python::handle<>(boost::python::borrowed(pyobj)));
+
+

+ In this case, Py_INCREF is + called, so pyobj is not destructed + when object o goes out of scope. +

+
- +

Last revised: December 26, 2011 at 21:51:27 GMT

Last revised: December 26, 2011 at 21:58:39 GMT