Skip to content

Commit 7acb544

Browse files
author
Ralf W. Grosse-Kunstleve
committed
merging current boost/python and libs/python from trunk into release branch
[SVN r76422]
1 parent f054b64 commit 7acb544

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

doc/tutorial/doc/html/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
<dt><span class="section"><a href="python/object.html#python.derived_object_types">Derived Object types</a></span></dt>
6767
<dt><span class="section"><a href="python/object.html#python.extracting_c___objects">Extracting C++ objects</a></span></dt>
6868
<dt><span class="section"><a href="python/object.html#python.enums">Enums</a></span></dt>
69+
<dt><span class="section"><a href="python/object.html#python.creating_python_object">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></a></span></dt>
6970
</dl></dd>
7071
<dt><span class="section"><a href="python/embedding.html">Embedding</a></span></dt>
7172
<dd><dl><dt><span class="section"><a href="python/embedding.html#python.using_the_interpreter">Using the interpreter</a></span></dt></dl></dd>
@@ -132,7 +133,7 @@ <h3>
132133
</div>
133134
</div>
134135
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
135-
<td align="left"><p><small>Last revised: December 26, 2011 at 21:51:27 GMT</small></p></td>
136+
<td align="left"><p><small>Last revised: December 26, 2011 at 21:58:39 GMT</small></p></td>
136137
<td align="right"><div class="copyright-footer"></div></td>
137138
</tr></table>
138139
<hr>

doc/tutorial/doc/html/python/object.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<dt><span class="section"><a href="object.html#python.derived_object_types">Derived Object types</a></span></dt>
3131
<dt><span class="section"><a href="object.html#python.extracting_c___objects">Extracting C++ objects</a></span></dt>
3232
<dt><span class="section"><a href="object.html#python.enums">Enums</a></span></dt>
33+
<dt><span class="section"><a href="object.html#python.creating_python_object">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></a></span></dt>
3334
</dl></div>
3435
<p>
3536
Python is dynamically typed, unlike C++ which is statically typed. Python variables
@@ -314,6 +315,32 @@ <h3>
314315
<span class="special">;</span>
315316
</pre>
316317
</div>
318+
<div class="section">
319+
<div class="titlepage"><div><div><h3 class="title">
320+
<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>
321+
</h3></div></div></div>
322+
<p>
323+
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>
324+
pyobj one does:
325+
</p>
326+
<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">&lt;&gt;(</span><span class="identifier">pyobj</span><span class="special">));</span>
327+
</pre>
328+
<p>
329+
In this case, the <code class="computeroutput"><span class="identifier">o</span></code> object,
330+
manages the <code class="computeroutput"><span class="identifier">pyobj</span></code>, it won&#8217;t
331+
increase the reference count on construction.
332+
</p>
333+
<p>
334+
Otherwise, to use a borrowed reference:
335+
</p>
336+
<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">&lt;&gt;(</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>
337+
</pre>
338+
<p>
339+
In this case, <code class="computeroutput"><span class="identifier">Py_INCREF</span></code> is
340+
called, so <code class="computeroutput"><span class="identifier">pyobj</span></code> is not destructed
341+
when object o goes out of scope.
342+
</p>
343+
</div>
317344
</div>
318345
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
319346
<td align="left"></td>

doc/tutorial/doc/tutorial.qbk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,23 @@ create a new scope around a class:
13021302
[def PyModule_GetDict [@http://www.python.org/doc/current/api/moduleObjects.html#l2h-594 PyModule_GetDict]]
13031303

13041304
[endsect]
1305+
1306+
[section:creating_python_object Creating `boost::python::object` from `PyObject*`]
1307+
1308+
When you want a `boost::python::object` to manage a pointer to `PyObject*` pyobj one does:
1309+
1310+
boost::python::object o(boost::python::handle<>(pyobj));
1311+
1312+
In this case, the `o` object, manages the `pyobj`, it won’t increase the reference count on construction.
1313+
1314+
Otherwise, to use a borrowed reference:
1315+
1316+
boost::python::object o(boost::python::handle<>(boost::python::borrowed(pyobj)));
1317+
1318+
In this case, `Py_INCREF` is called, so `pyobj` is not destructed when object o goes out of scope.
1319+
1320+
[endsect] [/ creating_python_object ]
1321+
13051322
[endsect] [/ Object Interface]
13061323

13071324
[section Embedding]

0 commit comments

Comments
 (0)