2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-19 16:32:16 +00:00

fixed some links

[SVN r25772]
This commit is contained in:
Joel de Guzman
2004-10-18 11:58:55 +00:00
parent 0d6ac67c04
commit 11daf8dde8
8 changed files with 133 additions and 85 deletions

View File

@@ -42,7 +42,7 @@ the gaps. However, Boost.Python already makes embedding a lot easier and,
in a future version, it may become unnecessary to touch the Python/C API at
all. So stay tuned... <span class="inlinemediaobject"><img src="../images/smiley.png"></span></p>
<a name="embedding.building_embedded_programs"></a><h2>
<a name="id428758"></a>Building embedded programs</h2>
<a name="id428755"></a>Building embedded programs</h2>
<p>
To be able to use embedding in your programs, they have to be linked to
both Boost.Python's and Python's static link library.</p>
@@ -51,7 +51,7 @@ Boost.Python's static link library comes in two variants. Both are located
in Boost's <tt class="literal">/libs/python/build/bin-stage</tt> subdirectory. On Windows, the
variants are called <tt class="literal">boost_python.lib</tt> (for release builds) and
<tt class="literal">boost_python_debug.lib</tt> (for debugging). If you can't find the libraries,
you probably haven't built Boost.Python yet. See <a href="../../building.html%20Building" target="_top">and Testing</a> on how to do this.</p>
you probably haven't built Boost.Python yet. See <a href="../../../../building.html%20Building" target="_top">and Testing</a> on how to do this.</p>
<p>
Python's static link library can be found in the <tt class="literal">/libs</tt> subdirectory of
your Python directory. On Windows it is called pythonXY.lib where X.Y is
@@ -77,7 +77,7 @@ In a Jamfile, all the above boils down to:</p>
&lt;find-library&gt;$(PYTHON_EMBEDDED_LIBRARY) ;
</tt></pre>
<a name="embedding.getting_started"></a><h2>
<a name="id428849"></a>Getting started</h2>
<a name="id428846"></a>Getting started</h2>
<p>
Being able to build is nice, but there is nothing to build yet. Embedding
the Python interpreter into one of your C++ programs requires these 4
@@ -116,9 +116,9 @@ automatic in Python, the Python/C API requires you to do it
<a href="http://www.python.org/doc/current/api/refcounts.html" target="_top">by hand</a>. This is
messy and especially hard to get right in the presence of C++ exceptions.
Fortunately Boost.Python provides the <a href="../../v2/handle.html" target="_top">handle</a> and
<a href="../../v2/object.html" target="_top">object</a> class templates to automate the process.</p>
<a href="../../../../v2/object.html" target="_top">object</a> class templates to automate the process.</p>
<a name="using_the_interpreter.reference_counting_handles_and_objects"></a><h2>
<a name="id428981"></a>Reference-counting handles and objects</h2>
<a name="id428977"></a>Reference-counting handles and objects</h2>
<p>
There are two ways in which a function in the Python/C API can return a
<tt class="literal">PyObject*</tt>: as a <span class="emphasis"><em>borrowed reference</em></span> or as a <span class="emphasis"><em>new reference</em></span>. Which of
@@ -128,7 +128,7 @@ be 'handled' by Boost.Python.</p>
<p>
For a function returning a <span class="emphasis"><em>borrowed reference</em></span> we'll have to tell the
<tt class="literal">handle</tt> that the <tt class="literal">PyObject*</tt> is borrowed with the aptly named
<a href="../../v2/handle.html#borrowed-spec" target="_top">borrowed</a> function. Two functions
<a href="../../../../v2/handle.html#borrowed-spec" target="_top">borrowed</a> function. Two functions
returning borrowed references are <a href="http://www.python.org/doc/current/api/importing.html#l2h-125" target="_top">PyImport_AddModule</a> and <a href="http://www.python.org/doc/current/api/moduleObjects.html#l2h-594" target="_top">PyModule_GetDict</a>.
The former returns a reference to an already imported module, the latter
retrieves a module's namespace dictionary. Let's use them to retrieve the
@@ -151,7 +151,7 @@ discuss in the next section.</p>
</td></tr></tbody>
</table></div>
<a name="using_the_interpreter.running_python_code"></a><h2>
<a name="id429283"></a>Running Python code</h2>
<a name="id429281"></a>Running Python code</h2>
<p>
To run Python code from C++ there is a family of functions in the API
starting with the PyRun prefix. You can find the full list of these
@@ -166,7 +166,7 @@ The <tt class="literal">start</tt> parameter is the start symbol from the Python
for interpreting the code. The possible values are:</p>
<div class="informaltable">
<h4>
<a name="id429445"></a><span class="table-title">Start symbols</span>
<a name="id429442"></a><span class="table-title">Start symbols</span>
</h4>
<table class="table">
<colgroup>
@@ -229,12 +229,12 @@ containing a phrase that is well-known in programming circles.</p>
do this, the the returned object would be kept alive unnecessarily. Unless
you want to be a Dr. Frankenstein, always wrap <tt class="literal">PyObject*</tt>s in <tt class="literal">handle</tt>s.</p>
<a name="using_the_interpreter.beyond_handles"></a><h2>
<a name="id429884"></a>Beyond handles</h2>
<a name="id429881"></a>Beyond handles</h2>
<p>
It's nice that <tt class="literal">handle</tt> manages the reference counting details for us, but
other than that it doesn't do much. Often we'd like to have a more useful
class to manipulate Python objects. But we have already seen such a class
above, and in the <a href="object_interface.html" target="_top">previous section</a>: the aptly
above, and in the <a href="object.html" target="_top">previous section</a>: the aptly
named <tt class="literal">object</tt> class and it's derivatives. We've already seen that they
can be constructed from a <tt class="literal">handle</tt>. The following examples should further
illustrate this fact:</p>
@@ -271,9 +271,13 @@ int</span><span class="identifier"> five_squared</span><span class="special"> =<
take into account the different functions that <tt class="literal">object</tt> and <tt class="literal">handle</tt>
perform.</p>
<a name="using_the_interpreter.exception_handling"></a><h2>
<a name="id430454"></a>Exception handling</h2>
<a name="id430451"></a>Exception handling</h2>
<p>
If an exception occurs in the execution of some Python code, the <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a> function returns a null pointer. Constructing a <tt class="literal">handle</tt> out of this null pointer throws <a href="../../v2/errors.html#error_already_set-spec" target="_top">error_already_set</a>, so basically, the Python exception is automatically translated into a C++ exception when using <tt class="literal">handle</tt>:</p>
If an exception occurs in the execution of some Python code, the <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a>
function returns a null pointer. Constructing a <tt class="literal">handle</tt> out of this null
pointer throws <a href="../../../../v2/errors.html#error_already_set-spec" target="_top">error_already_set</a>,
so basically, the Python exception is automatically translated into a
C++ exception when using <tt class="literal">handle</tt>:</p>
<pre class="programlisting"><tt class="literal"><span class="keyword">try</span><span class="special">
{</span><span class="identifier">
object</span><span class="identifier"> result</span><span class="special">((</span><span class="identifier">handle</span><span class="special">&lt;&gt;(</span><a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a><span class="special">(</span><span class="string">
@@ -291,7 +295,14 @@ catch</span><span class="special">(</span><span class="identifier">error_already
// handle the exception in some way
</span><span class="special">}</span></tt></pre>
<p>
The <tt class="literal">error_already_set</tt> exception class doesn't carry any information in itself. To find out more about the Python exception that occurred, you need to use the <a href="http://www.python.org/doc/api/exceptionHandling.html" target="_top">exception handling functions</a> of the Python<span class="emphasis"><em>C API in your catch-statement. This can be as simple as calling [@http:</em></span>/www.python.org/doc/api<span class="emphasis"><em>exceptionHandling.html#l2h-70 PyErr_Print()] to print the exception's traceback to the console, or comparing the type of the exception with those of the [@http:</em></span>/www.python.org/doc/api/standardExceptions.html standard exceptions]:</p>
The <tt class="literal">error_already_set</tt> exception class doesn't carry any information in itself.
To find out more about the Python exception that occurred, you need to use the
<a href="http://www.python.org/doc/api/exceptionHandling.html" target="_top">exception handling functions</a>
of the Python/C API in your catch-statement. This can be as simple as calling
<a href="http://www.python.org/doc/api/exceptionHandling.html#l2h-70" target="_top">PyErr_Print()</a> to
print the exception's traceback to the console, or comparing the type of the
exception with those of the <a href="http://www.python.org/doc/api/standardExceptions.html" target="_top">
standard exceptions</a>:</p>
<pre class="programlisting"><tt class="literal"><span class="keyword">catch</span><span class="special">(</span><span class="identifier">error_already_set</span><span class="special">)</span><span class="special">
{</span><span class="keyword">
if</span><span class="special"> (</span><span class="identifier">PyErr_ExceptionMatches</span><span class="special">(</span><span class="identifier">PyExc_ZeroDivisionError</span><span class="special">))</span><span class="special">
@@ -305,9 +316,12 @@ The <tt class="literal">error_already_set</tt> exception class doesn't carry any
}</span><span class="special">
}</span></tt></pre>
<p>
(To retrieve even more information from the exception you can use some of the other exception handling functions listed <a href="http://www.python.org/doc/api/exceptionHandling.html" target="_top">here</a>.)</p>
(To retrieve even more information from the exception you can use some of the other
exception handling functions listed <a href="http://www.python.org/doc/api/exceptionHandling.html" target="_top">here</a>.)</p>
<p>
If you'd rather not have <tt class="literal">handle</tt> throw a C++ exception when it is constructed, you can use the <a href="../../v2/handle.html#allow_null-spec" target="_top">allow_null</a> function in the same way you'd use borrowed:</p>
If you'd rather not have <tt class="literal">handle</tt> throw a C++ exception when it is constructed, you
can use the <a href="../../v2/handle.html#allow_null-spec" target="_top">allow_null</a> function in the same
way you'd use borrowed:</p>
<pre class="programlisting"><tt class="literal"><span class="identifier">handle</span><span class="special">&lt;&gt;</span><span class="identifier"> result</span><span class="special">((</span><span class="identifier">allow_null</span><span class="special">(</span><a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-55" target="_top">PyRun_String</a><span class="special">(</span><span class="string">
"5/0"</span><span class="special">
,</span> <a href="http://www.python.org/doc/current/api/veryhigh.html#l2h-58" target="_top">Py_eval_input</a><span class="special">

View File

@@ -258,7 +258,7 @@ instances of class <tt class="literal">Derived</tt>. In such cases, we use
<tt class="literal">return_value_policy&lt;manage_new_object&gt;</tt> to instruct Python to adopt
the pointer to <tt class="literal">Base</tt> and hold the instance in a new Python <tt class="literal">Base</tt>
object until the the Python object is destroyed. We shall see more of
Boost.Python <a href="call_policies.html" target="_top">call policies</a> later.</p>
Boost.Python <a href="functions.html#python.call_policies" target="_top">call policies</a> later.</p>
<pre class="programlisting"><tt class="literal"><span class="comment">// Tell Python to take ownership of factory's result
</span><span class="identifier">def</span><span class="special">(</span><span class="string">"factory"</span><span class="special">,</span><span class="identifier"> factory</span><span class="special">,</span><span class="identifier">
return_value_policy</span><span class="special">&lt;</span><span class="identifier">manage_new_object</span><span class="special">&gt;());</span></tt></pre>
@@ -432,7 +432,7 @@ The overridden virtual function <tt class="literal">f</tt> of <tt class="literal
<div></div>
</div>
<p>
Recall that in the <a href="class_virtual_functions.html" target="_top">previous section</a>, we
Recall that in the <a href="exposing.html#class_virtual_functions" target="_top">previous section</a>, we
wrapped a class with a pure virtual function that we then implemented in
C++ or Python classes derived from it. Our base class:</p>
<pre class="programlisting"><tt class="literal"><span class="keyword">struct</span><span class="identifier"> Base</span><span class="special">
@@ -501,7 +501,7 @@ Calling <tt class="literal">call_f</tt>, passing in a <tt class="literal">derive
<div></div>
</div>
<a name="class_operators_special_functions.python_operators"></a><h2>
<a name="id420104"></a>Python Operators</h2>
<a name="id420103"></a>Python Operators</h2>
<p>
C is well known for the abundance of operators. C++ extends this to the
extremes by allowing operator overloading. Boost.Python takes advantage of
@@ -538,7 +538,7 @@ you might need to interact with in an operator expression is (cheaply)
default-constructible. You can use <tt class="literal">other&lt;T&gt;()</tt> in place of an actual
<tt class="literal">T</tt> instance when writing "self expressions".</p>
<a name="class_operators_special_functions.special_methods"></a><h2>
<a name="id420790"></a>Special Methods</h2>
<a name="id420789"></a>Special Methods</h2>
<p>
Python has a few more <span class="emphasis"><em>Special Methods</em></span>. Boost.Python supports all of the
standard special method names supported by real Python class instances. A

View File

@@ -178,7 +178,7 @@ A reference to <tt class="literal">y.x</tt> is returned
<li><span class="bold"><b>BOOM!</b></span></li>
</ol></div>
<a name="call_policies.call_policies"></a><h2>
<a name="id422413"></a>Call Policies</h2>
<a name="id422411"></a>Call Policies</h2>
<p>
Call Policies may be used in situations such as the example detailed above.
In our example, <tt class="literal">return_internal_reference</tt> and <tt class="literal">with_custodian_and_ward</tt>
@@ -207,7 +207,7 @@ or more policies can be composed by chaining. Here's the general syntax:</p>
policy3</span><span class="special">&lt;</span><span class="identifier">args</span><span class="special">...&gt;</span><span class="special"> &gt;</span><span class="special"> &gt;</span></tt></pre>
<p>
Here is the list of predefined call policies. A complete reference detailing
these can be found <a href="../../v2/reference.html#models_of_call_policies" target="_top">here</a>.</p>
these can be found <a href="../../../../v2/reference.html#models_of_call_policies" target="_top">here</a>.</p>
<div class="itemizedlist"><ul type="disc">
<li>
<span class="bold"><b>with_custodian_and_ward</b></span><p></p>
@@ -323,7 +323,7 @@ to retrieve the default arguments:</p>
</span></tt></pre>
<p>
Because of this, when wrapping C++ code, we had to resort to manual
wrapping as outlined in the <a href="overloading.html" target="_top">previous section</a>, or
wrapping as outlined in the <a href="functions.html#overloading" target="_top">previous section</a>, or
writing thin wrappers:</p>
<pre class="programlisting"><tt class="literal"><span class="comment">// write "thin wrappers"
</span><span class="keyword">int</span><span class="identifier"> f1</span><span class="special">(</span><span class="keyword">int</span><span class="identifier"> x</span><span class="special">)</span><span class="special"> {</span><span class="identifier"> f</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span><span class="special"> }</span><span class="keyword">
@@ -347,7 +347,7 @@ are overloaded with a common sequence of initial arguments
</li>
</ul></div>
<a name="default_arguments.boost_python_function_overloads"></a><h2>
<a name="id424227"></a>BOOST_PYTHON_FUNCTION_OVERLOADS</h2>
<a name="id424225"></a>BOOST_PYTHON_FUNCTION_OVERLOADS</h2>
<p>
Boost.Python now has a way to make it easier. For instance, given a function:</p>
<pre class="programlisting"><tt class="literal"><span class="keyword">int</span><span class="identifier"> foo</span><span class="special">(</span><span class="keyword">int</span><span class="identifier"> a</span><span class="special">,</span><span class="keyword"> char</span><span class="identifier"> b</span><span class="special"> =</span><span class="number"> 1</span><span class="special">,</span><span class="keyword"> unsigned</span><span class="identifier"> c</span><span class="special"> =</span><span class="number"> 2</span><span class="special">,</span><span class="keyword"> double</span><span class="identifier"> d</span><span class="special"> =</span><span class="number"> 3</span><span class="special">)</span><span class="special">
@@ -366,7 +366,7 @@ and the maximum number of arguments is 4. The <tt class="literal">def(...)</tt>
automatically add all the foo variants for us:</p>
<pre class="programlisting"><tt class="literal"><span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span><span class="identifier"> foo</span><span class="special">,</span><span class="identifier"> foo_overloads</span><span class="special">());</span></tt></pre>
<a name="default_arguments.boost_python_member_function_overloads"></a><h2>
<a name="id424506"></a>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</h2>
<a name="id424504"></a>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</h2>
<p>
Objects here, objects there, objects here there everywhere. More frequently
than anything else, we need to expose member functions of our classes to
@@ -395,10 +395,10 @@ fourth macro argument). The thin wrappers are all enclosed in a class named
<tt class="literal">george_overloads</tt> that can then be used as an argument to <tt class="literal">def(...)</tt>:</p>
<pre class="programlisting"><tt class="literal"><span class="special">.</span><span class="identifier">def</span><span class="special">(</span><span class="string">"wack_em"</span><span class="special">,</span><span class="special"> &amp;</span><span class="identifier">george</span><span class="special">::</span><span class="identifier">wack_em</span><span class="special">,</span><span class="identifier"> george_overloads</span><span class="special">());</span></tt></pre>
<p>
See the <a href="../../v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec" target="_top">overloads reference</a>
See the <a href="../../../../v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec" target="_top">overloads reference</a>
for details.</p>
<a name="default_arguments.init_and_optional"></a><h2>
<a name="id424834"></a>init and optional</h2>
<a name="id424831"></a>init and optional</h2>
<p>
A similar facility is provided for class constructors, again, with
default arguments or a sequence of overloads. Remember <tt class="literal">init&lt;...&gt;</tt>? For example,
@@ -456,17 +456,17 @@ Then...</p>
Notice though that we have a situation now where we have a minimum of zero
(0) arguments and a maximum of 3 arguments.</p>
<a name="auto_overloading.manual_wrapping"></a><h2>
<a name="id425481"></a>Manual Wrapping</h2>
<a name="id425478"></a>Manual Wrapping</h2>
<p>
It is important to emphasize however that <span class="bold"><b>the overloaded functions must
have a common sequence of initial arguments</b></span>. Otherwise, our scheme above
will not work. If this is not the case, we have to wrap our functions
<a href="overloading.html" target="_top">manually</a>.</p>
<a href="functions.html#overloading" target="_top">manually</a>.</p>
<p>
Actually, we can mix and match manual wrapping of overloaded functions and
automatic wrapping through <tt class="literal">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</tt> and
its sister, <tt class="literal">BOOST_PYTHON_FUNCTION_OVERLOADS</tt>. Following up on our example
presented in the section <a href="overloading.html" target="_top">on overloading</a>, since the
presented in the section <a href="functions.html#overloading" target="_top">on overloading</a>, since the
first 4 overload functins have a common sequence of initial arguments, we
can use <tt class="literal">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</tt> to automatically wrap the
first three of the <tt class="literal">def</tt>s and manually wrap just the last. Here's

View File

@@ -55,7 +55,7 @@ with every boost distribution: <span class="bold"><b>bjam</b></span>.</p>
<p>
We shall skip over the details. Our objective will be to simply create the
hello world module and run it in Python. For a complete reference to
building Boost.Python, check out: <a href="../../building.html" target="_top">building.html</a>.
building Boost.Python, check out: <a href="../../../../building.html" target="_top">building.html</a>.
After this brief <span class="emphasis"><em>bjam</em></span> tutorial, we should have built two DLLs:</p>
<div class="itemizedlist"><ul type="disc">
<li>
@@ -98,8 +98,8 @@ the command line. Pre-built Boost.Jam executables are available for most
platforms. The complete list of Bjam executables can be found
<a href="http://sourceforge.net/project/showfiles.php?group_id=7586" target="_top">here</a>.</p>
<a name="hello.let_s_jam_"></a><h2>
<a name="id343870"></a>Let's Jam!</h2>
<p><span class="inlinemediaobject"><img src="images/jam.png"></span></p>
<a name="id343869"></a>Let's Jam!</h2>
<p><span class="inlinemediaobject"><img src="../images/jam.png"></span></p>
<p>
Here is our minimalist Jamfile:</p>
<pre class="programlisting"><tt class="literal"> subproject libs/python/example/tutorial ;

View File

@@ -45,7 +45,7 @@ As mentioned, one of the goals of Boost.Python is to provide a
bidirectional mapping between C++ and Python while maintaining the Python
feel. Boost.Python C++ <tt class="literal">object</tt>s are as close as possible to Python. This
should minimize the learning curve significantly.</p>
<p><span class="inlinemediaobject"><img src="images/python.png"></span></p>
<p><span class="inlinemediaobject"><img src="../images/python.png"></span></p>
<div class="section" lang="en">
<div class="titlepage">
<div><div><h3 class="title">
@@ -155,7 +155,7 @@ C++:</p>
<pre class="programlisting"><tt class="literal"><span class="identifier">dict</span><span class="identifier"> d</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">attr</span><span class="special">(</span><span class="string">"__dict__"</span><span class="special">));</span>  #<span class="identifier"> copies</span><span class="identifier"> x</span><span class="special">.</span><span class="identifier">__dict__</span><span class="identifier">
d</span><span class="special">[</span><span class="char">'whatever'</span><span class="special">]</span><span class="special"> =</span><span class="number"> 3</span><span class="special">;</span>           #<span class="identifier"> modifies</span><span class="identifier"> the</span><span class="identifier"> copy</span></tt></pre>
<a name="derived_object_types.class__lt_t_gt__as_objects"></a><h2>
<a name="id427287"></a>class_&lt;T&gt; as objects</h2>
<a name="id427284"></a>class_&lt;T&gt; as objects</h2>
<p>
Due to the dynamic nature of Boost.Python objects, any <tt class="literal">class_&lt;T&gt;</tt> may
also be one of these types! The following code snippet wraps the class
@@ -240,7 +240,7 @@ associated with the C++ type passed as its first parameter.</p>
The scope is a class that has an
associated global Python object which controls the Python namespace in
which new extension classes and wrapped functions will be defined as
attributes. Details can be found <a href="../../v2/scope.html" target="_top">here</a>.</td></tr></tbody>
attributes. Details can be found <a href="../../../../v2/scope.html" target="_top">here</a>.</td></tr></tbody>
</table></div>
<p>
You can access those values in Python as</p>

View File

@@ -108,7 +108,8 @@ actually a Python package. It can be a empty file, but can also perform some
magic, that will be shown later.</p>
<p>
Now our package is ready. All the user has to do is put <tt class="literal">sounds</tt> into his
<a href="http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000" target="_top">PYTHONPATH</a> and fire up the interpreter:</p>
<a href="http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000" target="_top">PYTHONPATH</a>
and fire up the interpreter:</p>
<pre class="programlisting"><tt class="literal"><span class="special">&gt;&gt;&gt;</span><span class="identifier"> import</span><span class="identifier"> sounds</span><span class="special">.</span><span class="identifier">io</span><span class="special">
&gt;&gt;&gt;</span><span class="identifier"> import</span><span class="identifier"> sounds</span><span class="special">.</span><span class="identifier">filters</span><span class="special">
&gt;&gt;&gt;</span><span class="identifier"> sound</span><span class="special"> =</span><span class="identifier"> sounds</span><span class="special">.</span><span class="identifier">io</span><span class="special">.</span><span class="identifier">open</span><span class="special">(</span><span class="char">'file.mp3'</span><span class="special">)</span><span class="special">
@@ -220,7 +221,8 @@ BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier"
}</span></tt></pre>
<p>
If we are using the technique from the previous session,
<a href="creating_packages.html" target="_top">Creating Packages</a>, we can code directly into <tt class="literal">geom/<span class="underline">_init</span>_.py</tt>:</p>
<a href="techniques.html#creating_packages" target="_top">Creating Packages</a>, we can code directly
into <tt class="literal">geom/<span class="underline">_init</span>_.py</tt>:</p>
<pre class="programlisting"><tt class="literal"><span class="identifier">from</span><span class="identifier"> _geom</span><span class="identifier"> import</span><span class="special"> *</span>
#<span class="identifier"> a</span><span class="identifier"> regular</span><span class="identifier"> function</span><span class="identifier">
@@ -346,7 +348,7 @@ the compilation of a single cpp, instead of the entire wrapper code.</p>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<tbody><tr><td>
<span class="inlinemediaobject"><img src="../images/note.png"></span> If you're exporting your classes with <a href="../../../pyste/index.html" target="_top">Pyste</a>,
<span class="inlinemediaobject"><img src="../images/note.png"></span> If you're exporting your classes with <a href="../../../../../pyste/index.html" target="_top">Pyste</a>,
take a look at the <tt class="literal">--multiple</tt> option, that generates the wrappers in
various files as demonstrated here.</td></tr></tbody>
</table></div>
@@ -355,7 +357,7 @@ various files as demonstrated here.</td></tr></tbody>
<tbody><tr><td>
<span class="inlinemediaobject"><img src="../images/note.png"></span> This method is useful too if you are getting the error message
<span class="emphasis"><em>"fatal error C1204:Compiler limit:internal structure overflow"</em></span> when compiling
a large source file, as explained in the <a href="../../v2/faq.html#c1204" target="_top">FAQ</a>.</td></tr></tbody>
a large source file, as explained in the <a href="../../../../v2/faq.html#c1204" target="_top">FAQ</a>.</td></tr></tbody>
</table></div>
</div>
</div>

View File

@@ -86,7 +86,7 @@ with every boost distribution: [*bjam].
We shall skip over the details. Our objective will be to simply create the
hello world module and run it in Python. For a complete reference to
building Boost.Python, check out: [@../../building.html building.html].
building Boost.Python, check out: [@../../../../building.html building.html].
After this brief ['bjam] tutorial, we should have built two DLLs:
* boost_python.dll
@@ -115,7 +115,7 @@ platforms. The complete list of Bjam executables can be found
[@http://sourceforge.net/project/showfiles.php?group_id=7586 here].
[h2 Let's Jam!]
[$images/jam.png]
[$../images/jam.png]
Here is our minimalist Jamfile:
@@ -468,7 +468,7 @@ instances of class [^Derived]. In such cases, we use
[^return_value_policy<manage_new_object>] to instruct Python to adopt
the pointer to [^Base] and hold the instance in a new Python [^Base]
object until the the Python object is destroyed. We shall see more of
Boost.Python [@call_policies.html call policies] later.
Boost.Python [@functions.html#python.call_policies call policies] later.
// Tell Python to take ownership of factory's result
def("factory", factory,
@@ -614,7 +614,7 @@ Here's what's happening:
[endsect]
[section Virtual Functions with Default Implementations]
Recall that in the [@class_virtual_functions.html previous section], we
Recall that in the [@exposing.html#class_virtual_functions previous section], we
wrapped a class with a pure virtual function that we then implemented in
C++ or Python classes derived from it. Our base class:
@@ -918,7 +918,7 @@ or more policies can be composed by chaining. Here's the general syntax:
policy3<args...> > >
Here is the list of predefined call policies. A complete reference detailing
these can be found [@../../v2/reference.html#models_of_call_policies here].
these can be found [@../../../../v2/reference.html#models_of_call_policies here].
* [*with_custodian_and_ward]\n Ties lifetimes of the arguments
* [*with_custodian_and_ward_postcall]\n Ties lifetimes of the arguments and results
@@ -1000,7 +1000,7 @@ to retrieve the default arguments:
def("f", f); // defaults lost!
Because of this, when wrapping C++ code, we had to resort to manual
wrapping as outlined in the [@overloading.html previous section], or
wrapping as outlined in the [@functions.html#overloading previous section], or
writing thin wrappers:
// write "thin wrappers"
@@ -1073,7 +1073,7 @@ fourth macro argument). The thin wrappers are all enclosed in a class named
.def("wack_em", &george::wack_em, george_overloads());
See the [@../../v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec overloads reference]
See the [@../../../../v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec overloads reference]
for details.
[h2 init and optional]
@@ -1140,12 +1140,12 @@ Notice though that we have a situation now where we have a minimum of zero
It is important to emphasize however that [*the overloaded functions must
have a common sequence of initial arguments]. Otherwise, our scheme above
will not work. If this is not the case, we have to wrap our functions
[@overloading.html manually].
[@functions.html#overloading manually].
Actually, we can mix and match manual wrapping of overloaded functions and
automatic wrapping through [^BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS] and
its sister, [^BOOST_PYTHON_FUNCTION_OVERLOADS]. Following up on our example
presented in the section [@overloading.html on overloading], since the
presented in the section [@functions.html#overloading on overloading], since the
first 4 overload functins have a common sequence of initial arguments, we
can use [^BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS] to automatically wrap the
first three of the [^def]s and manually wrap just the last. Here's
@@ -1179,7 +1179,7 @@ bidirectional mapping between C++ and Python while maintaining the Python
feel. Boost.Python C++ [^object]s are as close as possible to Python. This
should minimize the learning curve significantly.
[$images/python.png]
[$../images/python.png]
[section Basic Interface]
@@ -1361,7 +1361,7 @@ associated with the C++ type passed as its first parameter.
[blurb __note__ [*what is a scope?]\n\n The scope is a class that has an
associated global Python object which controls the Python namespace in
which new extension classes and wrapped functions will be defined as
attributes. Details can be found [@../../v2/scope.html here].]
attributes. Details can be found [@../../../../v2/scope.html here].]
You can access those values in Python as
@@ -1422,7 +1422,7 @@ Boost.Python's static link library comes in two variants. Both are located
in Boost's [^/libs/python/build/bin-stage] subdirectory. On Windows, the
variants are called [^boost_python.lib] (for release builds) and
[^boost_python_debug.lib] (for debugging). If you can't find the libraries,
you probably haven't built Boost.Python yet. See [@../../building.html
you probably haven't built Boost.Python yet. See [@../../../../building.html
Building and Testing] on how to do this.
Python's static link library can be found in the [^/libs] subdirectory of
@@ -1478,7 +1478,7 @@ automatic in Python, the Python/C API requires you to do it
[@http://www.python.org/doc/current/api/refcounts.html by hand]. This is
messy and especially hard to get right in the presence of C++ exceptions.
Fortunately Boost.Python provides the [@../../v2/handle.html handle] and
[@../../v2/object.html object] class templates to automate the process.
[@../../../../v2/object.html object] class templates to automate the process.
[h2 Reference-counting handles and objects]
@@ -1490,7 +1490,7 @@ be 'handled' by Boost.Python.
For a function returning a ['borrowed reference] we'll have to tell the
[^handle] that the [^PyObject*] is borrowed with the aptly named
[@../../v2/handle.html#borrowed-spec borrowed] function. Two functions
[@../../../../v2/handle.html#borrowed-spec borrowed] function. Two functions
returning borrowed references are PyImport_AddModule and PyModule_GetDict.
The former returns a reference to an already imported module, the latter
retrieves a module's namespace dictionary. Let's use them to retrieve the
@@ -1580,7 +1580,7 @@ you want to be a Dr. Frankenstein, always wrap [^PyObject*]s in [^handle]s.
It's nice that [^handle] manages the reference counting details for us, but
other than that it doesn't do much. Often we'd like to have a more useful
class to manipulate Python objects. But we have already seen such a class
above, and in the [@object_interface.html previous section]: the aptly
above, and in the [@object.html previous section]: the aptly
named [^object] class and it's derivatives. We've already seen that they
can be constructed from a [^handle]. The following examples should further
illustrate this fact:
@@ -1622,7 +1622,11 @@ perform.
[h2 Exception handling]
If an exception occurs in the execution of some Python code, the PyRun_String function returns a null pointer. Constructing a [^handle] out of this null pointer throws [@../../v2/errors.html#error_already_set-spec error_already_set], so basically, the Python exception is automatically translated into a C++ exception when using [^handle]:
If an exception occurs in the execution of some Python code, the PyRun_String
function returns a null pointer. Constructing a [^handle] out of this null
pointer throws [@../../../../v2/errors.html#error_already_set-spec error_already_set],
so basically, the Python exception is automatically translated into a
C++ exception when using [^handle]:
try
{
@@ -1641,7 +1645,14 @@ If an exception occurs in the execution of some Python code, the PyRun_String fu
// handle the exception in some way
}
The [^error_already_set] exception class doesn't carry any information in itself. To find out more about the Python exception that occurred, you need to use the [@http://www.python.org/doc/api/exceptionHandling.html exception handling functions] of the Python/C API in your catch-statement. This can be as simple as calling [@http://www.python.org/doc/api/exceptionHandling.html#l2h-70 PyErr_Print()] to print the exception's traceback to the console, or comparing the type of the exception with those of the [@http://www.python.org/doc/api/standardExceptions.html standard exceptions]:
The [^error_already_set] exception class doesn't carry any information in itself.
To find out more about the Python exception that occurred, you need to use the
[@http://www.python.org/doc/api/exceptionHandling.html exception handling functions]
of the Python/C API in your catch-statement. This can be as simple as calling
[@http://www.python.org/doc/api/exceptionHandling.html#l2h-70 PyErr_Print()] to
print the exception's traceback to the console, or comparing the type of the
exception with those of the [@http://www.python.org/doc/api/standardExceptions.html
standard exceptions]:
catch(error_already_set)
{
@@ -1656,9 +1667,12 @@ The [^error_already_set] exception class doesn't carry any information in itself
}
}
(To retrieve even more information from the exception you can use some of the other exception handling functions listed [@http://www.python.org/doc/api/exceptionHandling.html here].)
(To retrieve even more information from the exception you can use some of the other
exception handling functions listed [@http://www.python.org/doc/api/exceptionHandling.html here].)
If you'd rather not have [^handle] throw a C++ exception when it is constructed, you can use the [@../../v2/handle.html#allow_null-spec allow_null] function in the same way you'd use borrowed:
If you'd rather not have [^handle] throw a C++ exception when it is constructed, you
can use the [@../../v2/handle.html#allow_null-spec allow_null] function in the same
way you'd use borrowed:
handle<> result((allow_null(PyRun_String(
"5/0"
@@ -1845,7 +1859,8 @@ actually a Python package. It can be a empty file, but can also perform some
magic, that will be shown later.
Now our package is ready. All the user has to do is put [^sounds] into his
[@http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000 PYTHONPATH] and fire up the interpreter:
[@http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000 PYTHONPATH]
and fire up the interpreter:
>>> import sounds.io
>>> import sounds.filters
@@ -1965,7 +1980,8 @@ we have a class [^point] in C++:
}
If we are using the technique from the previous session,
[@creating_packages.html Creating Packages], we can code directly into [^geom/__init__.py]:
[@techniques.html#creating_packages Creating Packages], we can code directly
into [^geom/__init__.py]:
from _geom import *
@@ -2083,13 +2099,13 @@ This method is recommended too if you are developing the C++ library and
exporting it to Python at the same time: changes in a class will only demand
the compilation of a single cpp, instead of the entire wrapper code.
[blurb __note__ If you're exporting your classes with [@../../../pyste/index.html Pyste],
[blurb __note__ If you're exporting your classes with [@../../../../../pyste/index.html Pyste],
take a look at the [^--multiple] option, that generates the wrappers in
various files as demonstrated here.]
[blurb __note__ This method is useful too if you are getting the error message
['"fatal error C1204:Compiler limit:internal structure overflow"] when compiling
a large source file, as explained in the [@../../v2/faq.html#c1204 FAQ].]
a large source file, as explained in the [@../../../../v2/faq.html#c1204 FAQ].]
[endsect]
[endsect] [/ General Techniques]

View File

@@ -128,7 +128,7 @@ with every boost distribution: <emphasis role="bold">bjam</emphasis>.</para>
<para>
We shall skip over the details. Our objective will be to simply create the
hello world module and run it in Python. For a complete reference to
building Boost.Python, check out: <ulink url="../../building.html">building.html</ulink>.
building Boost.Python, check out: <ulink url="../../../../building.html">building.html</ulink>.
After this brief <emphasis>bjam</emphasis> tutorial, we should have built two DLLs:</para>
<itemizedlist>
<listitem>
@@ -165,7 +165,7 @@ the command line. Pre-built Boost.Jam executables are available for most
platforms. The complete list of Bjam executables can be found
<ulink url="http://sourceforge.net/project/showfiles.php?group_id=7586">here</ulink>.</para>
<anchor id="hello.let_s_jam_" /><bridgehead renderas="sect2">Let's Jam!</bridgehead><para>
<inlinemediaobject><imageobject><imagedata fileref="images/jam.png"></imagedata></imageobject></inlinemediaobject></para>
<inlinemediaobject><imageobject><imagedata fileref="../images/jam.png"></imagedata></imageobject></inlinemediaobject></para>
<para>
Here is our minimalist Jamfile:</para>
<programlisting><literal> subproject libs/python/example/tutorial ;
@@ -582,7 +582,7 @@ instances of class <literal>Derived</literal>. In such cases, we use
<literal>return_value_policy&lt;manage_new_object&gt;</literal> to instruct Python to adopt
the pointer to <literal>Base</literal> and hold the instance in a new Python <literal>Base</literal>
object until the the Python object is destroyed. We shall see more of
Boost.Python <ulink url="call_policies.html">call policies</ulink> later.</para>
Boost.Python <ulink url="functions.html#python.call_policies">call policies</ulink> later.</para>
<programlisting>
<literal>
<phrase role="comment">// Tell Python to take ownership of factory's result
@@ -794,7 +794,7 @@ The overridden virtual function <literal>f</literal> of <literal>BaseWrap</liter
<section id="python.virtual_functions_with_default_implementations">
<title>Virtual Functions with Default Implementations</title>
<para>
Recall that in the <ulink url="class_virtual_functions.html">previous section</ulink>, we
Recall that in the <ulink url="exposing.html#class_virtual_functions">previous section</ulink>, we
wrapped a class with a pure virtual function that we then implemented in
C++ or Python classes derived from it. Our base class:</para>
<programlisting>
@@ -1178,7 +1178,7 @@ or more policies can be composed by chaining. Here's the general syntax:</para>
</programlisting>
<para>
Here is the list of predefined call policies. A complete reference detailing
these can be found <ulink url="../../v2/reference.html#models_of_call_policies">here</ulink>.</para>
these can be found <ulink url="../../../../v2/reference.html#models_of_call_policies">here</ulink>.</para>
<itemizedlist>
<listitem>
<emphasis role="bold">with_custodian_and_ward</emphasis><para/>
@@ -1308,7 +1308,7 @@ to retrieve the default arguments:</para>
</programlisting>
<para>
Because of this, when wrapping C++ code, we had to resort to manual
wrapping as outlined in the <ulink url="overloading.html">previous section</ulink>, or
wrapping as outlined in the <ulink url="functions.html#overloading">previous section</ulink>, or
writing thin wrappers:</para>
<programlisting>
<literal>
@@ -1401,7 +1401,7 @@ fourth macro argument). The thin wrappers are all enclosed in a class named
</literal>
</programlisting>
<para>
See the <ulink url="../../v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec">overloads reference</ulink>
See the <ulink url="../../../../v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec">overloads reference</ulink>
for details.</para>
<anchor id="default_arguments.init_and_optional" /><bridgehead renderas="sect2">init and optional</bridgehead><para>
A similar facility is provided for class constructors, again, with
@@ -1479,12 +1479,12 @@ Notice though that we have a situation now where we have a minimum of zero
It is important to emphasize however that <emphasis role="bold">the overloaded functions must
have a common sequence of initial arguments</emphasis>. Otherwise, our scheme above
will not work. If this is not the case, we have to wrap our functions
<ulink url="overloading.html">manually</ulink>.</para>
<ulink url="functions.html#overloading">manually</ulink>.</para>
<para>
Actually, we can mix and match manual wrapping of overloaded functions and
automatic wrapping through <literal>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</literal> and
its sister, <literal>BOOST_PYTHON_FUNCTION_OVERLOADS</literal>. Following up on our example
presented in the section <ulink url="overloading.html">on overloading</ulink>, since the
presented in the section <ulink url="functions.html#overloading">on overloading</ulink>, since the
first 4 overload functins have a common sequence of initial arguments, we
can use <literal>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</literal> to automatically wrap the
first three of the <literal>def</literal>s and manually wrap just the last. Here's
@@ -1525,7 +1525,7 @@ bidirectional mapping between C++ and Python while maintaining the Python
feel. Boost.Python C++ <literal>object</literal>s are as close as possible to Python. This
should minimize the learning curve significantly.</para>
<para>
<inlinemediaobject><imageobject><imagedata fileref="images/python.png"></imagedata></imageobject></inlinemediaobject></para>
<inlinemediaobject><imageobject><imagedata fileref="../images/python.png"></imagedata></imageobject></inlinemediaobject></para>
<section id="python.basic_interface">
<title>Basic Interface</title>
@@ -1770,7 +1770,7 @@ associated with the C++ type passed as its first parameter.</para>
The scope is a class that has an
associated global Python object which controls the Python namespace in
which new extension classes and wrapped functions will be defined as
attributes. Details can be found <ulink url="../../v2/scope.html">here</ulink>.</entry>
attributes. Details can be found <ulink url="../../../../v2/scope.html">here</ulink>.</entry>
</row>
</tbody>
</tgroup>
@@ -1823,7 +1823,7 @@ Boost.Python's static link library comes in two variants. Both are located
in Boost's <literal>/libs/python/build/bin-stage</literal> subdirectory. On Windows, the
variants are called <literal>boost_python.lib</literal> (for release builds) and
<literal>boost_python_debug.lib</literal> (for debugging). If you can't find the libraries,
you probably haven't built Boost.Python yet. See <ulink url="../../building.html
you probably haven't built Boost.Python yet. See <ulink url="../../../../building.html
Building">and Testing</ulink> on how to do this.</para>
<para>
Python's static link library can be found in the <literal>/libs</literal> subdirectory of
@@ -1881,7 +1881,7 @@ automatic in Python, the Python/C API requires you to do it
<ulink url="http://www.python.org/doc/current/api/refcounts.html">by hand</ulink>. This is
messy and especially hard to get right in the presence of C++ exceptions.
Fortunately Boost.Python provides the <ulink url="../../v2/handle.html">handle</ulink> and
<ulink url="../../v2/object.html">object</ulink> class templates to automate the process.</para>
<ulink url="../../../../v2/object.html">object</ulink> class templates to automate the process.</para>
<anchor id="using_the_interpreter.reference_counting_handles_and_objects" /><bridgehead renderas="sect2">Reference-counting handles and objects</bridgehead><para>
There are two ways in which a function in the Python/C API can return a
<literal>PyObject*</literal>: as a <emphasis>borrowed reference</emphasis> or as a <emphasis>new reference</emphasis>. Which of
@@ -1891,7 +1891,7 @@ be 'handled' by Boost.Python.</para>
<para>
For a function returning a <emphasis>borrowed reference</emphasis> we'll have to tell the
<literal>handle</literal> that the <literal>PyObject*</literal> is borrowed with the aptly named
<ulink url="../../v2/handle.html#borrowed-spec">borrowed</ulink> function. Two functions
<ulink url="../../../../v2/handle.html#borrowed-spec">borrowed</ulink> function. Two functions
returning borrowed references are <ulink url="http://www.python.org/doc/current/api/importing.html#l2h-125">PyImport_AddModule</ulink> and <ulink url="http://www.python.org/doc/current/api/moduleObjects.html#l2h-594">PyModule_GetDict</ulink>.
The former returns a reference to an already imported module, the latter
retrieves a module's namespace dictionary. Let's use them to retrieve the
@@ -2001,7 +2001,7 @@ you want to be a Dr. Frankenstein, always wrap <literal>PyObject*</literal>s in
It's nice that <literal>handle</literal> manages the reference counting details for us, but
other than that it doesn't do much. Often we'd like to have a more useful
class to manipulate Python objects. But we have already seen such a class
above, and in the <ulink url="object_interface.html">previous section</ulink>: the aptly
above, and in the <ulink url="object.html">previous section</ulink>: the aptly
named <literal>object</literal> class and it's derivatives. We've already seen that they
can be constructed from a <literal>handle</literal>. The following examples should further
illustrate this fact:</para>
@@ -2047,7 +2047,11 @@ int</phrase><phrase role="identifier"> five_squared</phrase><phrase role="specia
take into account the different functions that <literal>object</literal> and <literal>handle</literal>
perform.</para>
<anchor id="using_the_interpreter.exception_handling" /><bridgehead renderas="sect2">Exception handling</bridgehead><para>
If an exception occurs in the execution of some Python code, the <ulink url="http://www.python.org/doc/current/api/veryhigh.html#l2h-55">PyRun_String</ulink> function returns a null pointer. Constructing a <literal>handle</literal> out of this null pointer throws <ulink url="../../v2/errors.html#error_already_set-spec">error_already_set</ulink>, so basically, the Python exception is automatically translated into a C++ exception when using <literal>handle</literal>:</para>
If an exception occurs in the execution of some Python code, the <ulink url="http://www.python.org/doc/current/api/veryhigh.html#l2h-55">PyRun_String</ulink>
function returns a null pointer. Constructing a <literal>handle</literal> out of this null
pointer throws <ulink url="../../../../v2/errors.html#error_already_set-spec">error_already_set</ulink>,
so basically, the Python exception is automatically translated into a
C++ exception when using <literal>handle</literal>:</para>
<programlisting>
<literal>
<phrase role="keyword">try</phrase><phrase role="special">
@@ -2069,7 +2073,14 @@ catch</phrase><phrase role="special">(</phrase><phrase role="identifier">error_a
</literal>
</programlisting>
<para>
The <literal>error_already_set</literal> exception class doesn't carry any information in itself. To find out more about the Python exception that occurred, you need to use the <ulink url="http://www.python.org/doc/api/exceptionHandling.html">exception handling functions</ulink> of the Python<emphasis>C API in your catch-statement. This can be as simple as calling [@http:</emphasis>/www.python.org/doc/api<emphasis>exceptionHandling.html#l2h-70 PyErr_Print()] to print the exception's traceback to the console, or comparing the type of the exception with those of the [@http:</emphasis>/www.python.org/doc/api/standardExceptions.html standard exceptions]:</para>
The <literal>error_already_set</literal> exception class doesn't carry any information in itself.
To find out more about the Python exception that occurred, you need to use the
<ulink url="http://www.python.org/doc/api/exceptionHandling.html">exception handling functions</ulink>
of the Python/C API in your catch-statement. This can be as simple as calling
<ulink url="http://www.python.org/doc/api/exceptionHandling.html#l2h-70">PyErr_Print()</ulink> to
print the exception's traceback to the console, or comparing the type of the
exception with those of the <ulink url="http://www.python.org/doc/api/standardExceptions.html">
standard exceptions</ulink>:</para>
<programlisting>
<literal>
<phrase role="keyword">catch</phrase><phrase role="special">(</phrase><phrase role="identifier">error_already_set</phrase><phrase role="special">)</phrase><phrase role="special">
@@ -2087,9 +2098,12 @@ The <literal>error_already_set</literal> exception class doesn't carry any infor
</literal>
</programlisting>
<para>
(To retrieve even more information from the exception you can use some of the other exception handling functions listed <ulink url="http://www.python.org/doc/api/exceptionHandling.html">here</ulink>.)</para>
(To retrieve even more information from the exception you can use some of the other
exception handling functions listed <ulink url="http://www.python.org/doc/api/exceptionHandling.html">here</ulink>.)</para>
<para>
If you'd rather not have <literal>handle</literal> throw a C++ exception when it is constructed, you can use the <ulink url="../../v2/handle.html#allow_null-spec">allow_null</ulink> function in the same way you'd use borrowed:</para>
If you'd rather not have <literal>handle</literal> throw a C++ exception when it is constructed, you
can use the <ulink url="../../v2/handle.html#allow_null-spec">allow_null</ulink> function in the same
way you'd use borrowed:</para>
<programlisting>
<literal>
<phrase role="identifier">handle</phrase><phrase role="special">&lt;&gt;</phrase><phrase role="identifier"> result</phrase><phrase role="special">((</phrase><phrase role="identifier">allow_null</phrase><phrase role="special">(</phrase><ulink url="http://www.python.org/doc/current/api/veryhigh.html#l2h-55">PyRun_String</ulink><phrase role="special">(</phrase><phrase role="string">
@@ -2331,7 +2345,8 @@ actually a Python package. It can be a empty file, but can also perform some
magic, that will be shown later.</para>
<para>
Now our package is ready. All the user has to do is put <literal>sounds</literal> into his
<ulink url="http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000">PYTHONPATH</ulink> and fire up the interpreter:</para>
<ulink url="http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000">PYTHONPATH</ulink>
and fire up the interpreter:</para>
<programlisting>
<literal>
<phrase role="special">&gt;&gt;&gt;</phrase><phrase role="identifier"> import</phrase><phrase role="identifier"> sounds</phrase><phrase role="special">.</phrase><phrase role="identifier">io</phrase><phrase role="special">
@@ -2478,7 +2493,8 @@ BOOST_PYTHON_MODULE</phrase><phrase role="special">(</phrase><phrase role="ident
</programlisting>
<para>
If we are using the technique from the previous session,
<ulink url="creating_packages.html">Creating Packages</ulink>, we can code directly into <literal>geom/<emphasis role="underline">_init</emphasis>_.py</literal>:</para>
<ulink url="techniques.html#creating_packages">Creating Packages</ulink>, we can code directly
into <literal>geom/<emphasis role="underline">_init</emphasis>_.py</literal>:</para>
<programlisting>
<literal>
<phrase role="identifier">from</phrase><phrase role="identifier"> _geom</phrase><phrase role="identifier"> import</phrase><phrase role="special"> *</phrase>
@@ -2627,7 +2643,7 @@ the compilation of a single cpp, instead of the entire wrapper code.</para>
<tbody>
<row>
<entry>
<inlinemediaobject><imageobject><imagedata fileref="../images/note.png"></imagedata></imageobject></inlinemediaobject> If you're exporting your classes with <ulink url="../../../pyste/index.html">Pyste</ulink>,
<inlinemediaobject><imageobject><imagedata fileref="../images/note.png"></imagedata></imageobject></inlinemediaobject> If you're exporting your classes with <ulink url="../../../../../pyste/index.html">Pyste</ulink>,
take a look at the <literal>--multiple</literal> option, that generates the wrappers in
various files as demonstrated here.</entry>
</row>
@@ -2642,7 +2658,7 @@ various files as demonstrated here.</entry>
<entry>
<inlinemediaobject><imageobject><imagedata fileref="../images/note.png"></imagedata></imageobject></inlinemediaobject> This method is useful too if you are getting the error message
<emphasis>&quot;fatal error C1204:Compiler limit:internal structure overflow&quot;</emphasis> when compiling
a large source file, as explained in the <ulink url="../../v2/faq.html#c1204">FAQ</ulink>.</entry>
a large source file, as explained in the <ulink url="../../../../v2/faq.html#c1204">FAQ</ulink>.</entry>
</row>
</tbody>
</tgroup>