|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r76422 - in branches/release: boost/python libs/python libs/python/doc/tutorial/doc libs/python/doc/tutorial/doc/html libs/python/doc/tutorial/doc/html/python
From: rwgk_at_[hidden]
Date: 2012-01-11 18:48:19
Author: rwgk
Date: 2012-01-11 18:48:18 EST (Wed, 11 Jan 2012)
New Revision: 76422
URL: http://svn.boost.org/trac/boost/changeset/76422
Log:
merging current boost/python and libs/python from trunk into release branch
Properties modified:
branches/release/boost/python/ (props changed)
branches/release/libs/python/ (props changed)
Text files modified:
branches/release/libs/python/doc/tutorial/doc/html/index.html | 3 ++-
branches/release/libs/python/doc/tutorial/doc/html/python/object.html | 27 +++++++++++++++++++++++++++
branches/release/libs/python/doc/tutorial/doc/tutorial.qbk | 17 +++++++++++++++++
3 files changed, 46 insertions(+), 1 deletions(-)
Modified: branches/release/libs/python/doc/tutorial/doc/html/index.html
==============================================================================
--- branches/release/libs/python/doc/tutorial/doc/html/index.html (original)
+++ branches/release/libs/python/doc/tutorial/doc/html/index.html 2012-01-11 18:48:18 EST (Wed, 11 Jan 2012)
@@ -66,6 +66,7 @@
<dt><span class="section">Derived Object types</span></dt>
<dt><span class="section">Extracting C++ objects</span></dt>
<dt><span class="section">Enums</span></dt>
+<dt><span class="section">Creating boost::python::object
from PyObject*
</span></dt>
</dl></dd>
<dt><span class="section">Embedding</span></dt>
<dd><dl><dt><span class="section">Using the interpreter</span></dt></dl></dd>
@@ -132,7 +133,7 @@
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
-<td align="left"><p><small>Last revised: December 26, 2011 at 21:51:27 GMT</small></p></td>
+<td align="left"><p><small>Last revised: December 26, 2011 at 21:58:39 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>
Modified: branches/release/libs/python/doc/tutorial/doc/html/python/object.html
==============================================================================
--- branches/release/libs/python/doc/tutorial/doc/html/python/object.html (original)
+++ branches/release/libs/python/doc/tutorial/doc/html/python/object.html 2012-01-11 18:48:18 EST (Wed, 11 Jan 2012)
@@ -30,6 +30,7 @@
<dt><span class="section">Derived Object types</span></dt>
<dt><span class="section">Extracting C++ objects</span></dt>
<dt><span class="section">Enums</span></dt>
+<dt><span class="section">Creating boost::python::object
from PyObject*
</span></dt>
</dl></div>
<p>
Python is dynamically typed, unlike C++ which is statically typed. Python variables
@@ -314,6 +315,32 @@
<span class="special">;</span>
</pre>
</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="python.creating_python_object"></a>Creating <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span></code> from <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code>
+</h3></div></div></div>
+<p>
+ When you want a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span></code> to manage a pointer to <code class="computeroutput"><span class="identifier">PyObject</span><span class="special">*</span></code>
+ pyobj one does:
+ </p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span> <span class="identifier">o</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">handle</span><span class="special"><>(</span><span class="identifier">pyobj</span><span class="special">));</span>
+</pre>
+<p>
+ In this case, the <code class="computeroutput"><span class="identifier">o</span></code> object,
+ manages the <code class="computeroutput"><span class="identifier">pyobj</span></code>, it won’t
+ increase the reference count on construction.
+ </p>
+<p>
+ Otherwise, to use a borrowed reference:
+ </p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">object</span> <span class="identifier">o</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">handle</span><span class="special"><>(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">borrowed</span><span class="special">(</span><span class="identifier">pyobj</span><span class="special">)));</span>
+</pre>
+<p>
+ In this case, <code class="computeroutput"><span class="identifier">Py_INCREF</span></code> is
+ called, so <code class="computeroutput"><span class="identifier">pyobj</span></code> is not destructed
+ when object o goes out of scope.
+ </p>
+</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
Modified: branches/release/libs/python/doc/tutorial/doc/tutorial.qbk
==============================================================================
--- branches/release/libs/python/doc/tutorial/doc/tutorial.qbk (original)
+++ branches/release/libs/python/doc/tutorial/doc/tutorial.qbk 2012-01-11 18:48:18 EST (Wed, 11 Jan 2012)
@@ -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]
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk