mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 16:32:16 +00:00
Quickbook: Merge to quickbook-dev
[SVN r76630]
This commit is contained in:
@@ -66,6 +66,7 @@
|
||||
<dt><span class="section"><a href="python/object.html#python.derived_object_types">Derived Object types</a></span></dt>
|
||||
<dt><span class="section"><a href="python/object.html#python.extracting_c___objects">Extracting C++ objects</a></span></dt>
|
||||
<dt><span class="section"><a href="python/object.html#python.enums">Enums</a></span></dt>
|
||||
<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>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="python/embedding.html">Embedding</a></span></dt>
|
||||
<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 @@
|
||||
</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>
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
<dt><span class="section"><a href="object.html#python.derived_object_types">Derived Object types</a></span></dt>
|
||||
<dt><span class="section"><a href="object.html#python.extracting_c___objects">Extracting C++ objects</a></span></dt>
|
||||
<dt><span class="section"><a href="object.html#python.enums">Enums</a></span></dt>
|
||||
<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>
|
||||
</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>
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -76,13 +76,13 @@
|
||||
|
||||
# if BOOST_PYTHON_USE_GCC_SYMBOL_VISIBILITY
|
||||
# if defined(BOOST_PYTHON_SOURCE)
|
||||
# define BOOST_PYTHON_DECL __attribute__ ((visibility("default")))
|
||||
# define BOOST_PYTHON_DECL __attribute__ ((__visibility__("default")))
|
||||
# define BOOST_PYTHON_BUILD_DLL
|
||||
# else
|
||||
# define BOOST_PYTHON_DECL
|
||||
# endif
|
||||
# define BOOST_PYTHON_DECL_FORWARD
|
||||
# define BOOST_PYTHON_DECL_EXCEPTION __attribute__ ((visibility("default")))
|
||||
# define BOOST_PYTHON_DECL_EXCEPTION __attribute__ ((__visibility__("default")))
|
||||
# elif (defined(_WIN32) || defined(__CYGWIN__))
|
||||
# if defined(BOOST_PYTHON_SOURCE)
|
||||
# define BOOST_PYTHON_DECL __declspec(dllexport)
|
||||
|
||||
@@ -76,7 +76,7 @@ extern "C" __declspec(dllexport) _BOOST_PYTHON_MODULE_INIT(name)
|
||||
|
||||
# define BOOST_PYTHON_MODULE_INIT(name) \
|
||||
void BOOST_PP_CAT(init_module_,name)(); \
|
||||
extern "C" __attribute__ ((visibility("default"))) _BOOST_PYTHON_MODULE_INIT(name)
|
||||
extern "C" __attribute__ ((__visibility__("default"))) _BOOST_PYTHON_MODULE_INIT(name)
|
||||
|
||||
# else
|
||||
|
||||
|
||||
Reference in New Issue
Block a user