From 7acb544b47877c65d46786a9e67a97760d760323 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 11 Jan 2012 23:48:18 +0000 Subject: [PATCH] merging current boost/python and libs/python from trunk into release branch [SVN r76422] --- doc/tutorial/doc/html/index.html | 3 ++- doc/tutorial/doc/html/python/object.html | 27 ++++++++++++++++++++++++ doc/tutorial/doc/tutorial.qbk | 17 +++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) 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 @@
Derived Object types
Extracting C++ objects
Enums
+
Creating boost::python::object from PyObject*
Embedding
Using the interpreter
@@ -132,7 +133,7 @@ - +

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

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


diff --git a/doc/tutorial/doc/html/python/object.html b/doc/tutorial/doc/html/python/object.html index e05c47ec..7bc2aa25 100644 --- a/doc/tutorial/doc/html/python/object.html +++ b/doc/tutorial/doc/html/python/object.html @@ -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,6 +315,32 @@ ; +

+

+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. +

+
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]