mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 16:32:16 +00:00
This commit was manufactured by cvs2svn to create tag
'merged_to_RC_1_31_0'. [SVN r22369]
This commit is contained in:
@@ -93,7 +93,7 @@ arguments or overloads with a common sequence of initial arguments come
|
||||
into play. Another macro is provided to make this a breeze.</p>
|
||||
<p>
|
||||
Like <tt>BOOST_PYTHON_FUNCTION_OVERLOADS</tt>,
|
||||
<tt>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</tt> may be used to automatically create
|
||||
<tt>BOOST_PYTHON_FUNCTION_OVERLOADS</tt> may be used to automatically create
|
||||
the thin wrappers for wrapping member functions. Let's have an example:</p>
|
||||
<code><pre>
|
||||
<span class=keyword>struct </span><span class=identifier>george
|
||||
|
||||
@@ -63,9 +63,9 @@ Besides bjam, there are of course other ways to get your module built.
|
||||
What's written here should not be taken as "the one and only way".
|
||||
There are of course other build tools apart from [^bjam].
|
||||
|
||||
Take note however that the preferred build tool for Boost.Python is bjam.
|
||||
There are so many ways to set up the build incorrectly. Experience shows
|
||||
that 90% of the "I can't build Boost.Python" problems come from people
|
||||
Take note however that the preferred build tool for Boost.Python is bjam.
|
||||
There are so many ways to set up the build incorrectly. Experience shows
|
||||
that 90% of the "I can't build Boost.Python" problems come from people
|
||||
who had to use a different tool.
|
||||
]
|
||||
|
||||
@@ -1010,7 +1010,7 @@ arguments or overloads with a common sequence of initial arguments come
|
||||
into play. Another macro is provided to make this a breeze.
|
||||
|
||||
Like [^BOOST_PYTHON_FUNCTION_OVERLOADS],
|
||||
[^BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS] may be used to automatically create
|
||||
[^BOOST_PYTHON_FUNCTION_OVERLOADS] may be used to automatically create
|
||||
the thin wrappers for wrapping member functions. Let's have an example:
|
||||
|
||||
struct george
|
||||
@@ -1698,7 +1698,7 @@ with an example.
|
||||
|
||||
We have a C++ library that works with sounds: reading and writing various
|
||||
formats, applying filters to the sound data, etc. It is named (conveniently)
|
||||
[^sounds]. Our library already has a neat C++ namespace hierarchy, like so:
|
||||
[^sounds]. Our library already has a neat C++ namespace hierarchy, like so:
|
||||
|
||||
sounds::core
|
||||
sounds::io
|
||||
@@ -1718,21 +1718,21 @@ separately with Boost.Python, like this:
|
||||
{
|
||||
/* export everything in the sounds::core namespace */
|
||||
...
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* file io.cpp */
|
||||
BOOST_PYTHON_MODULE(io)
|
||||
{
|
||||
/* export everything in the sounds::io namespace */
|
||||
...
|
||||
}
|
||||
}
|
||||
|
||||
/* file filters.cpp */
|
||||
BOOST_PYTHON_MODULE(filters)
|
||||
{
|
||||
/* export everything in the sounds::filters namespace */
|
||||
...
|
||||
}
|
||||
}
|
||||
|
||||
Compiling these files will generate the following Python extensions:
|
||||
[^core.pyd], [^io.pyd] and [^filters.pyd].
|
||||
@@ -1753,7 +1753,7 @@ Now, we create this directory structure for our Python package:
|
||||
|
||||
The file [^__init__.py] is what tells Python that the directory [^sounds/] is
|
||||
actually a Python package. It can be a empty file, but can also perform some
|
||||
magic, that will be shown later.
|
||||
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:
|
||||
@@ -1763,7 +1763,7 @@ Now our package is ready. All the user has to do is put [^sounds] into his
|
||||
>>> sound = sounds.io.open('file.mp3')
|
||||
>>> new_sound = sounds.filters.echo(sound, 1.0)
|
||||
|
||||
Nice heh?
|
||||
Nice heh?
|
||||
|
||||
This is the simplest way to create hierarchies of packages, but it is not very
|
||||
flexible. What if we want to add a ['pure] Python function to the filters
|
||||
@@ -1780,7 +1780,7 @@ little. First, we will have to change the name of the extension modules:
|
||||
{
|
||||
...
|
||||
/* export everything in the sounds::core namespace */
|
||||
}
|
||||
}
|
||||
|
||||
Note that we added an underscore to the module name. The filename will have to
|
||||
be changed to [^_core.pyd] as well, and we do the same to the other extension modules.
|
||||
@@ -1802,7 +1802,7 @@ Now, we change our package hierarchy like so:
|
||||
|
||||
Note that we created a directory for each extension module, and added a
|
||||
__init__.py to each one. But if we leave it that way, the user will have to
|
||||
access the functions in the core module with this syntax:
|
||||
access the functions in the core module with this syntax:
|
||||
|
||||
>>> import sounds.core._core
|
||||
>>> sounds.core._core.foo(...)
|
||||
@@ -1854,7 +1854,7 @@ even after it was already created:
|
||||
>>> def C_str(self): return 'A C instance!'
|
||||
>>>
|
||||
>>> # now we turn it in a member function
|
||||
>>> C.__str__ = C_str
|
||||
>>> C.__str__ = C_str
|
||||
>>>
|
||||
>>> c = C()
|
||||
>>> print c
|
||||
@@ -1874,7 +1874,7 @@ we have a class [^point] in C++:
|
||||
class_<point>("point")...;
|
||||
}
|
||||
|
||||
If we are using the technique from the previous session, [@creating_packages.html
|
||||
If we are using the technique from the previous session, [@creating_packages.html
|
||||
Creating Packages], we can code directly into [^geom/__init__.py]:
|
||||
|
||||
from _geom import *
|
||||
@@ -1882,7 +1882,7 @@ Creating Packages], we can code directly into [^geom/__init__.py]:
|
||||
# a regular function
|
||||
def point_str(self):
|
||||
return str((self.x, self.y))
|
||||
|
||||
|
||||
# now we turn it into a member function
|
||||
point.__str__ = point_str
|
||||
|
||||
@@ -1897,9 +1897,9 @@ This technique has several advantages:
|
||||
You can even add a little syntactic sugar with the use of metaclasses. Let's
|
||||
create a special metaclass that "injects" methods in other classes.
|
||||
|
||||
# The one Boost.Python uses for all wrapped classes.
|
||||
# The one Boost.Python uses for all wrapped classes.
|
||||
# You can use here any class exported by Boost instead of "point"
|
||||
BoostPythonMetaclass = point.__class__
|
||||
BoostPythonMetaclass = point.__class__
|
||||
|
||||
class injector(object):
|
||||
class __metaclass__(BoostPythonMetaclass):
|
||||
@@ -1946,10 +1946,10 @@ class_ definitions in multiple files:
|
||||
/* file point.cpp */
|
||||
#include <point.h>
|
||||
#include <boost/python.hpp>
|
||||
|
||||
|
||||
void export_point()
|
||||
{
|
||||
class_<point>("point")...;
|
||||
class_<point>("point")...;
|
||||
}
|
||||
|
||||
/* file triangle.cpp */
|
||||
@@ -1962,11 +1962,11 @@ class_ definitions in multiple files:
|
||||
}
|
||||
|
||||
Now you create a file [^main.cpp], which contains the [^BOOST_PYTHON_MODULE]
|
||||
macro, and call the various export functions inside it.
|
||||
macro, and call the various export functions inside it.
|
||||
|
||||
void export_point();
|
||||
void export_triangle();
|
||||
|
||||
|
||||
BOOST_PYTHON_MODULE(_geom)
|
||||
{
|
||||
export_point();
|
||||
@@ -1984,15 +1984,15 @@ usual approach:
|
||||
{
|
||||
class_<point>("point")...;
|
||||
class_<triangle>("triangle")...;
|
||||
}
|
||||
}
|
||||
|
||||
but the memory is kept under control.
|
||||
but the memory is kept under control.
|
||||
|
||||
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.]
|
||||
|
||||
|
||||
@@ -278,7 +278,7 @@
|
||||
std::vector interface]) classes (currently, this is the only predefined
|
||||
suite available). It provides all the policies required by the
|
||||
<tt>indexing_suite</tt>.
|
||||
</p>
|
||||
</p>
|
||||
<p>
|
||||
Example usage:
|
||||
</p>
|
||||
@@ -300,16 +300,16 @@
|
||||
<h2>
|
||||
<a name="indexing_suite_class"></a>indexing_suite class
|
||||
</h2>
|
||||
<h3>
|
||||
<br>
|
||||
<tt>indexing_suite<<br>
|
||||
class Container<br>
|
||||
, class DerivedPolicies<font color="#007F00"><br>
|
||||
</font></tt> <tt>,
|
||||
bool NoProxy<br>
|
||||
, class Element<br>
|
||||
, class Key<br>
|
||||
, class Index</tt>
|
||||
<h3>
|
||||
Class template<br>
|
||||
<tt>indexing_suite<<br>
|
||||
class <font color="#007F00">Container</font><br>
|
||||
, class <font color="#007F00">DerivedPolicies<br></font></tt> <tt>,
|
||||
bool <font color="#007F00">NoProxy</font><br>
|
||||
, bool <font color="#007F00">NoProxy</font>,<br>
|
||||
, class <font color="#007F00">Element</font><br>
|
||||
, class <font color="#007F00">Key</font><br>
|
||||
, class <font color="#007F00">Index</font></tt>
|
||||
</h3>
|
||||
<table width="100%" border="1">
|
||||
<tr>
|
||||
|
||||
@@ -136,10 +136,7 @@ void* pointer_holder_back_reference<Pointer, Value>::holds(type_info dst_t)
|
||||
|
||||
/* --------------- pointer_holder --------------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, pointer_holder.hpp)
|
||||
# endif
|
||||
# line BOOST_PP_LINE(__LINE__, pointer_holder.hpp)
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
@@ -156,10 +153,7 @@ void* pointer_holder_back_reference<Pointer, Value>::holds(type_info dst_t)
|
||||
|
||||
/* --------------- pointer_holder_back_reference --------------- */
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, pointer_holder.hpp(pointer_holder_back_reference))
|
||||
# endif
|
||||
# line BOOST_PP_LINE(__LINE__, pointer_holder.hpp(pointer_holder_back_reference))
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
|
||||
@@ -103,10 +103,7 @@ void* value_holder_back_reference<Value,Held>::holds(
|
||||
// --------------- value_holder ---------------
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder))
|
||||
# endif
|
||||
# line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder))
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
@@ -125,10 +122,7 @@ void* value_holder_back_reference<Value,Held>::holds(
|
||||
// --------------- value_holder_back_reference ---------------
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2
|
||||
# if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
|
||||
&& BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
|
||||
# line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder_back_reference))
|
||||
# endif
|
||||
# line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder_back_reference))
|
||||
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
|
||||
@@ -17,9 +17,8 @@
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
|
||||
# ifndef BOOST_PYTHON_HAVE_GCC_CP_DEMANGLE
|
||||
# if defined(__GNUC__) \
|
||||
&& ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) \
|
||||
&& !defined(__EDG_VERSION__)
|
||||
# if defined(__GNUC__) \
|
||||
&& ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
||||
# define BOOST_PYTHON_HAVE_GCC_CP_DEMANGLE
|
||||
# endif
|
||||
# endif
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#if !defined(__GNUC__) || __GNUC__ >= 3 || __SGI_STL_PORT || __EDG_VERSION__
|
||||
#if !defined(__GNUC__) || __GNUC__ >= 3 || __SGI_STL_PORT
|
||||
# include <ostream>
|
||||
#else
|
||||
# include <ostream.h>
|
||||
@@ -33,19 +33,10 @@ namespace boost { namespace python {
|
||||
# if __GNUC__ < 3
|
||||
|
||||
namespace cxxabi = :: ;
|
||||
extern "C" char* __cxa_demangle(char const*, char*, std::size_t*, int*);
|
||||
# else
|
||||
|
||||
# else
|
||||
namespace cxxabi = ::abi; // GCC 3.1 and later
|
||||
|
||||
# if __GNUC__ == 3 && __GNUC_MINOR__ == 0
|
||||
namespace abi
|
||||
{
|
||||
extern "C" char* __cxa_demangle(char const*, char*, std::size_t*, int*);
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
71
test/Jamfile
71
test/Jamfile
@@ -21,13 +21,10 @@ rule turn-off-intel-debug-symbols ( toolset variant : properties * )
|
||||
}
|
||||
return $(properties) ;
|
||||
}
|
||||
|
||||
template py-unit-test
|
||||
:
|
||||
: $(PYTHON_PROPERTIES) <define>BOOST_PYTHON_SUPPRESS_REGISTRY_INITIALIZATION
|
||||
[ difference $(PYTHON_PROPERTIES) : <define>BOOST_PYTHON_DYNAMIC_LIB ] <define>BOOST_PYTHON_STATIC_LIB
|
||||
;
|
||||
|
||||
local UNIT_TEST_PROPERTIES = $(PYTHON_PROPERTIES) <define>BOOST_PYTHON_SUPPRESS_REGISTRY_INITIALIZATION
|
||||
[ difference $(PYTHON_PROPERTIES) : <define>BOOST_PYTHON_DYNAMIC_LIB ] <define>BOOST_PYTHON_STATIC_LIB ;
|
||||
|
||||
# Convenience rule makes declaring tests faster
|
||||
rule bpl-test ( name ? : files * : requirements * )
|
||||
{
|
||||
@@ -64,17 +61,16 @@ rule bpl-test ( name ? : files * : requirements * )
|
||||
m = $(m)_ext ;
|
||||
}
|
||||
}
|
||||
extension $(m) : $(f) <template>../build/extension : $(requirements) ;
|
||||
extension $(m) : $(f) <dll>../build/boost_python : $(requirements) ;
|
||||
modules += $(m) ;
|
||||
}
|
||||
}
|
||||
|
||||
return [ boost-python-runtest $(name) : $(py) <pyd>$(modules) : $(requirements) ] ;
|
||||
return [ boost-python-runtest $(name) : $(py) <pyd>$(modules) ] ;
|
||||
}
|
||||
|
||||
test-suite python
|
||||
:
|
||||
[
|
||||
: [
|
||||
run ../test/embedding.cpp <lib>../build/boost_python
|
||||
: # program args
|
||||
: # input files
|
||||
@@ -86,7 +82,7 @@ test-suite python
|
||||
<$(gcc-compilers)><debug-python><library-path>$(CYGWIN_PYTHON_DEBUG_DLL_PATH)
|
||||
<$(gcc-compilers)><*><library-path>$(CYGWIN_PYTHON_DLL_PATH)
|
||||
<find-library>$(PYTHON_EMBEDDED_LIBRARY)
|
||||
]
|
||||
]
|
||||
|
||||
[
|
||||
bpl-test crossmod_exception
|
||||
@@ -110,7 +106,7 @@ bpl-test crossmod_exception
|
||||
|
||||
[ bpl-test keywords : keywords.cpp keywords_test.py ]
|
||||
|
||||
[ extension builtin_converters : test_builtin_converters.cpp <template>../build/extension ]
|
||||
[ extension builtin_converters : test_builtin_converters.cpp <dll>../build/boost_python ]
|
||||
[ boost-python-runtest builtin_converters : test_builtin_converters.py <pyd>builtin_converters ]
|
||||
|
||||
[ bpl-test test_pointer_adoption ]
|
||||
@@ -168,30 +164,45 @@ bpl-test crossmod_exception
|
||||
|
||||
[ run indirect_traits_test.cpp ]
|
||||
[ run destroy_test.cpp ]
|
||||
[ run pointer_type_id_test.cpp <lib>../../test/build/boost_test_exec_monitor <template>py-unit-test ]
|
||||
[ run bases.cpp <template>py-unit-test ]
|
||||
[ run pointer_type_id_test.cpp <lib>../../test/build/boost_test_exec_monitor : : : $(UNIT_TEST_PROPERTIES) ]
|
||||
[ run bases.cpp : : : $(UNIT_TEST_PROPERTIES) ]
|
||||
[ run if_else.cpp ]
|
||||
[ run pointee.cpp <template>py-unit-test ]
|
||||
[ run pointee.cpp : : : $(UNIT_TEST_PROPERTIES) ]
|
||||
[ run result.cpp ]
|
||||
|
||||
[ compile string_literal.cpp ]
|
||||
[ compile borrowed.cpp <template>py-unit-test ]
|
||||
[ compile object_manager.cpp <template>py-unit-test ]
|
||||
[ compile copy_ctor_mutates_rhs.cpp <template>py-unit-test ]
|
||||
[ compile borrowed.cpp : $(UNIT_TEST_PROPERTIES) ]
|
||||
[ compile object_manager.cpp : $(UNIT_TEST_PROPERTIES) ]
|
||||
[ compile copy_ctor_mutates_rhs.cpp : $(UNIT_TEST_PROPERTIES) ]
|
||||
|
||||
[ run upcast.cpp <lib>../../test/build/boost_test_exec_monitor <template>py-unit-test ]
|
||||
|
||||
[ run select_holder.cpp <lib>../../test/build/boost_test_exec_monitor <template>py-unit-test ]
|
||||
|
||||
[ run select_from_python_test.cpp ../src/converter/type_id.cpp
|
||||
<lib>../../test/build/boost_test_exec_monitor <template>py-unit-test ]
|
||||
[ run upcast.cpp <lib>../../test/build/boost_test_exec_monitor
|
||||
: # command-line args
|
||||
: # input files
|
||||
: $(UNIT_TEST_PROPERTIES)
|
||||
]
|
||||
|
||||
[ run select_arg_to_python_test.cpp ../src/converter/type_id.cpp
|
||||
<lib>../../test/build/boost_test_exec_monitor <template>py-unit-test ]
|
||||
[ run select_holder.cpp <lib>../../test/build/boost_test_exec_monitor
|
||||
: # command-line args
|
||||
: # input files
|
||||
: $(UNIT_TEST_PROPERTIES)
|
||||
]
|
||||
|
||||
[ compile-fail ./raw_pyobject_fail1.cpp <template>py-unit-test ]
|
||||
[ compile-fail ./raw_pyobject_fail2.cpp <template>py-unit-test ]
|
||||
[ compile-fail ./as_to_python_function.cpp <template>py-unit-test ]
|
||||
[ compile-fail ./object_fail1.cpp <template>py-unit-test ]
|
||||
|
||||
[ run select_from_python_test.cpp ../src/converter/type_id.cpp <lib>../../test/build/boost_test_exec_monitor
|
||||
: # command-line args
|
||||
: # input files
|
||||
: $(UNIT_TEST_PROPERTIES)
|
||||
]
|
||||
|
||||
[ run select_arg_to_python_test.cpp ../src/converter/type_id.cpp <lib>../../test/build/boost_test_exec_monitor
|
||||
: # command-line args
|
||||
: # input files
|
||||
: $(UNIT_TEST_PROPERTIES)
|
||||
]
|
||||
|
||||
[ compile-fail ./raw_pyobject_fail1.cpp : $(PYTHON_PROPERTIES) ]
|
||||
[ compile-fail ./raw_pyobject_fail2.cpp : $(PYTHON_PROPERTIES) ]
|
||||
[ compile-fail ./as_to_python_function.cpp : $(PYTHON_PROPERTIES) ]
|
||||
[ compile-fail ./object_fail1.cpp : $(PYTHON_PROPERTIES) ]
|
||||
;
|
||||
}
|
||||
Reference in New Issue
Block a user