diff --git a/doc/tutorial/doc/html/python/embedding.html b/doc/tutorial/doc/html/python/embedding.html index 1bd7f4a0..9069dc13 100644 --- a/doc/tutorial/doc/html/python/embedding.html +++ b/doc/tutorial/doc/html/python/embedding.html @@ -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...

-Building embedded programs

+Building embedded programs

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.

@@ -51,7 +51,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 and Testing on how to do this.

+you probably haven't built Boost.Python yet. See and Testing on how to do this.

Python's static link library can be found in the /libs 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:

<find-library>$(PYTHON_EMBEDDED_LIBRARY) ;

-Getting started

+Getting started

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 by hand. This is messy and especially hard to get right in the presence of C++ exceptions. Fortunately Boost.Python provides the handle and -object class templates to automate the process.

+object class templates to automate the process.

-Reference-counting handles and objects

+Reference-counting handles and objects

There are two ways in which a function in the Python/C API can return a PyObject*: as a borrowed reference or as a new reference. Which of @@ -128,7 +128,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 -borrowed function. Two functions +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 @@ -151,7 +151,7 @@ discuss in the next section.

-Running Python code

+Running Python code

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 start parameter is the start symbol from the Python for interpreting the code. The possible values are:

-Start symbols +Start symbols

@@ -229,12 +229,12 @@ containing a phrase that is well-known in programming circles.

do this, the the returned object would be kept alive unnecessarily. Unless you want to be a Dr. Frankenstein, always wrap PyObject*s in handles.

-Beyond handles

+Beyond handles

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 previous section: the aptly +above, and in the 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:

@@ -271,9 +271,13 @@ int five_squared =< take into account the different functions that object and handle perform.

-Exception handling

+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 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 error_already_set, +so basically, the Python exception is automatically translated into a +C++ exception when using handle:

try
 {
     object result((handle<>(PyRun_String(
@@ -291,7 +295,14 @@ catch(error_already
     // 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 exception handling functions of the PythonC API in your catch-statement. This can be as simple as calling [@http:/www.python.org/doc/apiexceptionHandling.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 +exception handling functions +of the Python/C API in your catch-statement. This can be as simple as calling +PyErr_Print() to +print the exception's traceback to the console, or comparing the type of the +exception with those of the +standard exceptions:

catch(error_already_set)
 {
     if (PyErr_ExceptionMatches(PyExc_ZeroDivisionError))
@@ -305,9 +316,12 @@ The error_already_set exception class doesn't carry any
     }
 }

-(To retrieve even more information from the exception you can use some of the other exception handling functions listed here.)

+(To retrieve even more information from the exception you can use some of the other +exception handling functions listed here.)

-If you'd rather not have handle throw a C++ exception when it is constructed, you can use the 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 allow_null function in the same +way you'd use borrowed:

handle<> result((allow_null(PyRun_String(
     "5/0"
    , Py_eval_input
diff --git a/doc/tutorial/doc/html/python/exposing.html b/doc/tutorial/doc/html/python/exposing.html
index 5b8a6ed4..6bf7a744 100644
--- a/doc/tutorial/doc/html/python/exposing.html
+++ b/doc/tutorial/doc/html/python/exposing.html
@@ -258,7 +258,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 later.

+Boost.Python call policies later.

// Tell Python to take ownership of factory's result
 def("factory", factory,
     return_value_policy<manage_new_object>());
@@ -432,7 +432,7 @@ The overridden virtual function f of previous section, we +Recall that in the 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:

struct Base
@@ -501,7 +501,7 @@ Calling call_f, passing in a derive
 

-Python Operators

+Python Operators

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 other<T>() in place of an actual T instance when writing "self expressions".

-Special Methods

+Special Methods

Python has a few more Special Methods. Boost.Python supports all of the standard special method names supported by real Python class instances. A diff --git a/doc/tutorial/doc/html/python/functions.html b/doc/tutorial/doc/html/python/functions.html index 10a432d7..fb6ac3c8 100644 --- a/doc/tutorial/doc/html/python/functions.html +++ b/doc/tutorial/doc/html/python/functions.html @@ -178,7 +178,7 @@ A reference to y.x is returned

  • BOOM!
  • -Call Policies

    +Call Policies

    Call Policies may be used in situations such as the example detailed above. In our example, return_internal_reference and with_custodian_and_ward @@ -207,7 +207,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 here.

    +these can be found here.

    • with_custodian_and_ward

      @@ -323,7 +323,7 @@ to retrieve the default arguments:

    Because of this, when wrapping C++ code, we had to resort to manual -wrapping as outlined in the previous section, or +wrapping as outlined in the previous section, or writing thin wrappers:

    // write "thin wrappers"
     int f1(int x) { f(x); }
    @@ -347,7 +347,7 @@ are overloaded with a common sequence of initial arguments
     
     
     

    -BOOST_PYTHON_FUNCTION_OVERLOADS

    +BOOST_PYTHON_FUNCTION_OVERLOADS

    Boost.Python now has a way to make it easier. For instance, given a function:

    int foo(int a, char b = 1, unsigned c = 2, double d = 3)
    @@ -366,7 +366,7 @@ and the maximum number of arguments is 4. The def(...)
     automatically add all the foo variants for us:

    def("foo", foo, foo_overloads());

    -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS

    +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS

    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 george_overloads that can then be used as an argument to def(...):

    .def("wack_em", &george::wack_em, george_overloads());

    -See the overloads reference +See the overloads reference for details.

    -init and optional

    +init and optional

    A similar facility is provided for class constructors, again, with default arguments or a sequence of overloads. Remember init<...>? For example, @@ -456,17 +456,17 @@ Then...

    Notice though that we have a situation now where we have a minimum of zero (0) arguments and a maximum of 3 arguments.

    -Manual Wrapping

    +Manual Wrapping

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

    +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 on overloading, since the +presented in the section 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 defs and manually wrap just the last. Here's diff --git a/doc/tutorial/doc/html/python/hello.html b/doc/tutorial/doc/html/python/hello.html index 6b796033..01fa0016 100644 --- a/doc/tutorial/doc/html/python/hello.html +++ b/doc/tutorial/doc/html/python/hello.html @@ -55,7 +55,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 Boost.Python, check out: building.html. After this brief bjam tutorial, we should have built two DLLs:

    • @@ -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 here.

      -Let's Jam!

      -

      +Let's Jam! +

      Here is our minimalist Jamfile:

          subproject libs/python/example/tutorial ;
      diff --git a/doc/tutorial/doc/html/python/object.html b/doc/tutorial/doc/html/python/object.html
      index a9214ec0..08b8a70d 100644
      --- a/doc/tutorial/doc/html/python/object.html
      +++ b/doc/tutorial/doc/html/python/object.html
      @@ -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++ objects are as close as possible to Python. This
       should minimize the learning curve significantly.

      -

      +

      @@ -155,7 +155,7 @@ C++:

      dict d(x.attr("__dict__"));  # copies x.__dict__
       d['whatever'] = 3;           # modifies the copy

      -class_<T> as objects

      +class_<T> as objects

      Due to the dynamic nature of Boost.Python objects, any class_<T> 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.

      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 here. +attributes. Details can be found here.

    You can access those values in Python as

    diff --git a/doc/tutorial/doc/html/python/techniques.html b/doc/tutorial/doc/html/python/techniques.html index a0fb5eb3..bebc6727 100644 --- a/doc/tutorial/doc/html/python/techniques.html +++ b/doc/tutorial/doc/html/python/techniques.html @@ -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.

    Now our package is ready. All the user has to do is put sounds into his -PYTHONPATH and fire up the interpreter:

    +PYTHONPATH +and fire up the interpreter:

    >>> import sounds.io
     >>> import sounds.filters
     >>> sound = sounds.io.open('file.mp3')
    @@ -220,7 +221,8 @@ BOOST_PYTHON_MODULE(

    If we are using the technique from the previous session, -Creating Packages, we can code directly into geom/_init_.py:

    +Creating Packages, we can code directly +into geom/_init_.py:

    from _geom import *
     
     # a regular function
    @@ -346,7 +348,7 @@ the compilation of a single cpp, instead of the entire wrapper code.

    - If you're exporting your classes with Pyste, + If you're exporting your classes with Pyste, take a look at the --multiple option, that generates the wrappers in various files as demonstrated here.
    @@ -355,7 +357,7 @@ various files as demonstrated here. 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 FAQ. +a large source file, as explained in the FAQ. diff --git a/doc/tutorial/doc/tutorial.qbk b/doc/tutorial/doc/tutorial.qbk index 884557ca..e58ccdc8 100644 --- a/doc/tutorial/doc/tutorial.qbk +++ b/doc/tutorial/doc/tutorial.qbk @@ -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] 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 > > 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] diff --git a/doc/tutorial/doc/tutorial.xml b/doc/tutorial/doc/tutorial.xml index ee883900..7b8a5d86 100644 --- a/doc/tutorial/doc/tutorial.xml +++ b/doc/tutorial/doc/tutorial.xml @@ -128,7 +128,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 Boost.Python, check out: building.html. After this brief bjam tutorial, we should have built two DLLs: @@ -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 here. Let's Jam! - + Here is our minimalist Jamfile: subproject libs/python/example/tutorial ; @@ -582,7 +582,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 later. +Boost.Python call policies later. // Tell Python to take ownership of factory's result @@ -794,7 +794,7 @@ The overridden virtual function f of BaseWrap Virtual Functions with Default Implementations -Recall that in the previous section, we +Recall that in the 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: @@ -1178,7 +1178,7 @@ or more policies can be composed by chaining. Here's the general syntax: Here is the list of predefined call policies. A complete reference detailing -these can be found here. +these can be found here. with_custodian_and_ward @@ -1308,7 +1308,7 @@ to retrieve the default arguments: Because of this, when wrapping C++ code, we had to resort to manual -wrapping as outlined in the previous section, or +wrapping as outlined in the previous section, or writing thin wrappers: @@ -1401,7 +1401,7 @@ fourth macro argument). The thin wrappers are all enclosed in a class named -See the overloads reference +See the overloads reference for details. init and optional 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 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 -manually. +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 on overloading, since the +presented in the section 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 defs 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++ objects are as close as possible to Python. This should minimize the learning curve significantly. - +
    Basic Interface @@ -1770,7 +1770,7 @@ associated with the C++ type passed as its first parameter. 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 here. +attributes. Details can be found here. @@ -1823,7 +1823,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 and Testing on how to do this. Python's static link library can be found in the /libs subdirectory of @@ -1881,7 +1881,7 @@ automatic in Python, the Python/C API requires you to do it by hand. This is messy and especially hard to get right in the presence of C++ exceptions. Fortunately Boost.Python provides the handle and -object class templates to automate the process. +object class templates to automate the process. Reference-counting handles and objects There are two ways in which a function in the Python/C API can return a PyObject*: as a borrowed reference or as a new reference. Which of @@ -1891,7 +1891,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 -borrowed function. Two functions +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 @@ -2001,7 +2001,7 @@ you want to be a Dr. Frankenstein, always wrap PyObject*s in 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 previous section: the aptly +above, and in the 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: @@ -2047,7 +2047,11 @@ int five_squaredException 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 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 error_already_set, +so basically, the Python exception is automatically translated into a +C++ exception when using handle: try @@ -2069,7 +2073,14 @@ catch(error_a -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 exception handling functions of the PythonC API in your catch-statement. This can be as simple as calling [@http:/www.python.org/doc/apiexceptionHandling.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 +exception handling functions +of the Python/C API in your catch-statement. This can be as simple as calling +PyErr_Print() to +print the exception's traceback to the console, or comparing the type of the +exception with those of the +standard exceptions: catch(error_already_set) @@ -2087,9 +2098,12 @@ The error_already_set exception class doesn't carry any infor -(To retrieve even more information from the exception you can use some of the other exception handling functions listed here.) +(To retrieve even more information from the exception you can use some of the other +exception handling functions listed here.) -If you'd rather not have handle throw a C++ exception when it is constructed, you can use the 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 allow_null function in the same +way you'd use borrowed: handle<> result((allow_null(PyRun_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. Now our package is ready. All the user has to do is put sounds into his -PYTHONPATH and fire up the interpreter: +PYTHONPATH +and fire up the interpreter: >>> import sounds.io @@ -2478,7 +2493,8 @@ BOOST_PYTHON_MODULE(Creating Packages, we can code directly into geom/_init_.py: +Creating Packages, we can code directly +into geom/_init_.py: from _geom import * @@ -2627,7 +2643,7 @@ the compilation of a single cpp, instead of the entire wrapper code. - If you're exporting your classes with Pyste, + If you're exporting your classes with Pyste, take a look at the --multiple option, that generates the wrappers in various files as demonstrated here. @@ -2642,7 +2658,7 @@ various files as demonstrated here. 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 FAQ. +a large source file, as explained in the FAQ.