diff --git a/doc/tutorial/doc/html/index.html b/doc/tutorial/doc/html/index.html index 175ffe68..c324f065 100644 --- a/doc/tutorial/doc/html/index.html +++ b/doc/tutorial/doc/html/index.html @@ -66,6 +66,7 @@
boost::python::object from PyObject*Last revised: December 26, 2011 at 21:51:27 GMT |
+Last revised: December 26, 2011 at 21:58:39 GMT |
boost::python::object from PyObject*Python is dynamically typed, unlike C++ which is statically typed. Python variables @@ -314,6 +315,32 @@ ; +
+ 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.
+
| diff --git a/doc/tutorial/doc/tutorial.qbk b/doc/tutorial/doc/tutorial.qbk index 94ecc55b..204c5004 100644 --- a/doc/tutorial/doc/tutorial.qbk +++ b/doc/tutorial/doc/tutorial.qbk @@ -1302,6 +1302,23 @@ create a new scope around a class: [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] |