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

Compare commits

..

1 Commits

Author SHA1 Message Date
nobody
6b477f5813 This commit was manufactured by cvs2svn to create branch 'split-config'.
[SVN r10742]
2001-08-04 14:31:38 +00:00
50 changed files with 455 additions and 804 deletions

View File

@@ -5,16 +5,13 @@
#
# Boost.Python build and test Jamfile
#
# To run all tests quietly: jam test
# To run all tests with verbose output: jam -sPYTHON_TEST_ARGS=-v test
#
# Declares the following targets:
# 1. libboost_python, a static link library to be linked with all
# Boost.Python modules
#
# 2. pairs of test targets of the form <name>.test and <name>.run
# <name>.test runs the test when it is out-of-date, and the "test"
# pseudotarget depends on it. <name>.run runs
# <name>.test runs the test when it is out-of-date, and the "all" target
# depends on it so that it it is built by default. <name>.run runs
# a test unconditionally, and can be used to force a test to run.. Each
# test target builds one or more Boost.Python modules and runs a Python
# script to test them. The test names are:
@@ -41,12 +38,6 @@
#
# subproject-specific environment/command-line variables:
#
# PYTHON - How to invoke the Python interpreter. Defaults to "python"
#
# PYTHON_ROOT - Windows only: where Python is installed. Defaults to "c:/tools/python"
#
# PYTHON_VERSION - Version of Python. Defaults to "2.1" on Windows, "1.5" on Unix
#
# PYTHON_TEST_ARGS - specifies arguments to be passed to test scripts on
# the command line. "-v" can be useful if you want to
# see the output of successful tests.
@@ -58,49 +49,32 @@
# declare the location of this subproject relative to the root
subproject libs/python/build ;
# grab variables from command-line or environment.
local PYTHON_VERSION = $(PYTHON_VERSION) ;
local PYTHON_ROOT = $(PYTHON_ROOT) ;
local PYTHON_INCLUDES = $(PYTHON_INCLUDES) ;
local PYTHON_LIBS = $(PYTHON_LIBS) ;
local PYTHON_LIB_PATH = $(PYTHON_LIB_PATH) ;
local PYTHON_PROPERTIES = $(PYTHON_PROPERTIES) ;
# Do some OS-specific setup
if $(NT)
{
PYTHON_VERSION ?= 2.1 ;
PYTHON_ROOT ?= c:/tools/python ;
PYTHON_INCLUDES ?= <include>$(PYTHON_ROOT)/include <gcc><*><include>/usr/include/python$(PYTHON_VERSION) ;
PYTHON_LIBS ?= c:/cygnus/lib/python$(PYTHON_VERSION)/config/libpython$(PYTHON_VERSION).dll.a ;
PYTHON_LIB_PATH ?= $(PYTHON_ROOT)/libs ;
PYTHON_INCLUDES ?= <include>$(PYTHON_ROOT)/include <gcc><*><include>/usr/include/python2.1 ;
PYTHON_LIBS ?= c:/cygnus/lib/python2.1/config/libpython2.1.dll.a ;
PYTHON_LIB_PATH = $(PYTHON_ROOT)/libs ;
# common properties required for compiling any Python module.
PYTHON_PROPERTIES ?=
<gcc><*><define>SIZEOF_LONG=4
<gcc><*><define>USE_DL_IMPORT
<debug><define>_DEBUG
<runtime-link>dynamic
;
SHELL_SET ?= "set " ;
SHELL_EXPORT ?= ; # shell variables are exported by default
}
else if $(UNIX)
{
PYTHON_VERSION ?= 1.5 ;
PYTHON_INCLUDES ?= <include>/usr/include/python$(PYTHON_VERSION) ;
PYTHON_LIBS ?= /usr/lib/python$(PYTHON_VERSION)/config/libpython$(PYTHON_VERSION).a ;
PYTHON_INCLUDES ?= <include>/usr/include/python1.5 ;
PYTHON_LIBS ?= /usr/lib/python1.5/config/libpython1.5.a ;
SHELL_SET ?= "" ;
SHELL_EXPORT ?= "export " ;
}
local PYTHON_VERSION_NODOT
= [ SUBST $(PYTHON_VERSION) ([0-9]*)\.([0-9]*) $1$2 ]
;
# how do we invoke python?
local PYTHON = $(PYTHON) ;
PYTHON ?= python ;
PYTHON = [ FAppendSuffix $(PYTHON:G=<executable-grist>) : $(SUFEXE) ] ;
SEARCH on $(PYTHON) = $(PATH) ;
#######################
#
@@ -108,26 +82,18 @@ SEARCH on $(PYTHON) = $(PATH) ;
#
# standard include requirements for anything using Boost.Python
local BOOST_PYTHON_INCLUDES = <include>$(BOOST_ROOT) $(PYTHON_INCLUDES) ;
BOOST_PYTHON_INCLUDES = <include>$(BOOST_ROOT) $(PYTHON_INCLUDES) ;
# Base names of the source files for libboost_python
local CPP_SOURCES =
types classes conversions extension_class functions
init_function module_builder objects cross_module ;
CPP_SOURCES =
classes conversions extension_class functions
init_function module_builder objects types cross_module ;
lib libboost_python : ../src/$(CPP_SOURCES).cpp
# requirements
: $(BOOST_PYTHON_INCLUDES)
<shared-linkable>true
$(PYTHON_PROPERTIES) ;
lib libboost_python_d : ../src/$(CPP_SOURCES).cpp
# requirements
: $(BOOST_PYTHON_INCLUDES)
<shared-linkable>true
$(PYTHON_PROPERTIES)
<define>BOOST_DEBUG_PYTHON
;
#######################
@@ -136,14 +102,8 @@ lib libboost_python_d : ../src/$(CPP_SOURCES).cpp
# Declare a boost python module. Return a list of the DLL files generated.
rule boost-python
{
local debug = "" ;
if ( <define>BOOST_DEBUG_PYTHON in $(3) ) || ( debug-python in $(BUILD) )
{
debug = _d ;
}
# declare a DLL; add the boost python library to sources
dll $(<) : <lib>libboost_python$(debug) $(>)
dll $(<) : <lib>libboost_python $(>)
# Requirements
: $(3) # caller-specified requirements
@@ -151,36 +111,19 @@ rule boost-python
# standard requirements
$(BOOST_PYTHON_INCLUDES)
<msvc><*><library-path>$(PYTHON_LIB_PATH)
<intel-win32><*><library-path>$(PYTHON_LIB_PATH)
<metrowerks><*><library-file>$(PYTHON_LIB_PATH)/python$(PYTHON_VERSION_NODOT)$(debug).lib
<gcc><*><library-file>$(PYTHON_LIBS)
$(PYTHON_PROPERTIES)
: $(4) ; # pass on the default-BUILD, if any
}
# boost-python-test name : sources : requirements : default-BUILD
#
# Just like boost-python, but the result becomes part of the test pseudotarget
# instead of being built by 'all'
rule boost-python-test
{
type-DEPENDS test : $(<) ;
type-DEPENDS test_d : $(<)_d ;
NOTFILE test_d ;
local gSUPPRESS_FAKE_TARGETS = true ;
boost-python $(1) : $(2) : $(3) : $(4) ;
boost-python $(1)_d : $(2) : $(3) <define>BOOST_DEBUG_PYTHON : $(4) ;
}
#######################
# boost-python-runtest target : python-script sources : requirements : local-build : args
# boost-python-test target : python-script sources : requirements : local-build : args
#
# declare two python module tests: $(<).test which builds when out-of-date, and
# $(<).run which builds unconditionally.
rule boost-python-runtest
rule boost-python-test
{
# tell Jam that the python script is relative to this directory
SEARCH on $(>[1]) = $(SEARCH_SOURCE) ;
@@ -188,27 +131,28 @@ rule boost-python-runtest
# required command-line args can be specified in argument 5
# The user can add additional arguments in PYTHON_TEST_ARGS.
local gPYTHON_TEST_ARGS = $(5) $(PYTHON_TEST_ARGS) ;
# declare the two subsidiary tests.
declare-local-target $(<:S=.test) : $(>) : $(PYTHON_PROPERTIES) : $(4) : PYTHON_TEST ;
declare-local-target $(<:S=.run) : $(>) : $(PYTHON_PROPERTIES) : $(4) : PYTHON_RUNTEST ;
}
# how do we invoke python?
PYTHON ?= python ;
# special rules for two new target types: PYTHON_TEST and PYTHON_RUNTEST.
# These are identical except that PYTHON_TEST runs the test when out-of-date, and
# PYTHON_RUNTEST runs the test unconditionally. These are used by boost-python-runtest.
# PYTHON_RUNTEST runs the test unconditionally. These are used by boost-python-test.
SUFPYTHON_TEST = .test ;
gGENERATOR_FUNCTION(PYTHON_TEST) = python-test-target ;
rule python-test-target # test-target : sources :
{
python-runtest-aux $(<) : $(>) ;
python-test-aux $(<) : $(>) ;
Clean clean : $(<) ; # remove the test-target as part of any clean operation
local debug = [ SUBST $(<:B) (_d)$ $1 ] ;
debug ?= "" ;
type-DEPENDS test$(debug) : $(<) ;
type-DEPENDS test : $(<) ;
MakeLocate $(<) : $(LOCATE_TARGET) ;
}
actions python-test-target bind PYTHON
actions python-test-target
{
$(SHELL_SET)PYTHONPATH=$(PYTHONPATH)
$(SHELL_EXPORT)PYTHONPATH
@@ -219,18 +163,18 @@ SUFPYTHON_RUNTEST = .run ;
gGENERATOR_FUNCTION(PYTHON_RUNTEST) = python-runtest-target ;
rule python-runtest-target # test-target : sources :
{
python-runtest-aux $(<) : $(>) ;
python-test-aux $(<) : $(>) ;
NOTFILE $(<) ;
ALWAYS $(<) ;
}
actions python-runtest-target bind PYTHON
actions python-runtest-target
{
$(SHELL_SET)PYTHONPATH=$(PYTHONPATH)
$(SHELL_EXPORT)PYTHONPATH
$(PYTHON) "$(>)" $(ARGS)
}
rule python-runtest-aux # target : sources
rule python-test-aux # target : sources
{
DEPENDS $(<) : $(>) ;
@@ -242,7 +186,6 @@ rule python-runtest-aux # target : sources
switch $(<)
{
case <*\\\\msvc\\\\*>* : ARGS on $(<) += --broken-auto-ptr ;
case <*\\\\intel-win32\\\\*>* : ARGS on $(<) += --broken-auto-ptr ;
}
# compute the PYTHONPATH environment variable that will allow the test to
@@ -251,68 +194,52 @@ rule python-runtest-aux # target : sources
$(gLOCATE($(>[1]))) # location of python test file
$(gRUN_PATH($(<))) # location of module dependencies
[ join-path $(TOP) libs python test ] # location of doctest
$(>:D) # directory of python driver file(s)
$(PYTHONPATH) # base PYTHONPATH from environment
: $(SPLITPATH) ] ; # platform path separator
PYTHON on $(<) = $(PYTHON) ;
DEPENDS $(<) : $(PYTHON) ;
}
############# comprehensive module and test ###########
boost-python-test boost_python_test : ../test/comprehensive.cpp ;
boost-python-runtest comprehensive
: [ join-path $(DOTDOT) test comprehensive.py ]
<lib>boost_python_test ;
boost-python-runtest comprehensive_d
: [ join-path $(DOTDOT) test comprehensive.py ]
<lib>boost_python_test_d ;
boost-python boost_python_test : ../test/comprehensive.cpp ;
boost-python-test comprehensive : [ join-path $(DOTDOT) test comprehensive.py ] <lib>boost_python_test ;
############# simple tests from ../example ############
rule boost-python-example-runtest
rule boost-python-example-test
{
boost-python-test $(<) : ../example/$(<).cpp ;
boost-python-runtest $(<) : [ join-path $(DOTDOT) example test_$(<).py ] <lib>$(<) ;
boost-python-runtest $(<)_d : [ join-path $(DOTDOT) example test_$(<).py ] <lib>$(<)_d ;
boost-python $(<) : ../example/$(<).cpp ;
boost-python-test $(<) : [ join-path $(DOTDOT) example test_$(<).py ] <lib>$(<) ;
}
boost-python-example-runtest abstract ;
boost-python-example-runtest getting_started1 ;
boost-python-example-runtest getting_started2 ;
boost-python-example-runtest simple_vector ;
boost-python-example-runtest do_it_yourself_convts ;
boost-python-example-runtest pickle1 ;
boost-python-example-runtest pickle2 ;
boost-python-example-runtest pickle3 ;
boost-python-example-test abstract ;
boost-python-example-test getting_started1 ;
boost-python-example-test getting_started2 ;
boost-python-example-test simple_vector ;
boost-python-example-test do_it_yourself_convts ;
boost-python-example-test pickle1 ;
boost-python-example-test pickle2 ;
boost-python-example-test pickle3 ;
boost-python-test ivect : ../example/ivect.cpp ;
boost-python-test dvect : ../example/dvect.cpp ;
boost-python-test noncopyable_export : ../example/noncopyable_export.cpp ;
boost-python-test noncopyable_import : ../example/noncopyable_import.cpp ;
boost-python ivect : ../example/ivect.cpp ;
boost-python dvect : ../example/dvect.cpp ;
boost-python noncopyable_export : ../example/noncopyable_export.cpp ;
boost-python noncopyable_import : ../example/noncopyable_import.cpp ;
############## cross-module tests from ../example ##########
# A simple rule to build a test which depends on multiple modules in the PYTHONPATH
rule boost-python-multi-example-runtest # test-name : python-file libs
rule boost-python-multi-example-test # test-name : python-file libs
{
boost-python-runtest $(<)
: ../example/tst_$(<).py <lib>$(>)
: : : $(PYTHON_VECT_ITERATIONS) ;
boost-python-test $(<) : ../example/tst_$(<).py <lib>$(>) : : : $(PYTHON_VECT_ITERATIONS) ;
}
PYTHON_VECT_ITERATIONS ?= 10 ;
boost-python-multi-example-runtest dvect1 : ivect dvect ;
boost-python-multi-example-runtest dvect2 : ivect dvect ;
boost-python-multi-example-test dvect1 : ivect dvect ;
boost-python-multi-example-test dvect2 : ivect dvect ;
boost-python-multi-example-runtest ivect1 : ivect dvect ;
boost-python-multi-example-runtest ivect2 : ivect dvect ;
boost-python-multi-example-test ivect1 : ivect dvect ;
boost-python-multi-example-test ivect2 : ivect dvect ;
boost-python-multi-example-runtest
noncopyable : noncopyable_import noncopyable_export ;
boost-python-multi-example-test noncopyable : noncopyable_import noncopyable_export ;

View File

@@ -24,7 +24,6 @@ bpl_exa + "/getting_started1.cpp",
bpl_exa + "/getting_started2.cpp",
bpl_exa + "/simple_vector.cpp",
bpl_exa + "/do_it_yourself_convts.cpp",
bpl_exa + "/nested.cpp",
bpl_exa + "/pickle1.cpp",
bpl_exa + "/pickle2.cpp",
bpl_exa + "/pickle3.cpp",
@@ -33,7 +32,6 @@ bpl_exa + "/test_getting_started1.py",
bpl_exa + "/test_getting_started2.py",
bpl_exa + "/test_simple_vector.py",
bpl_exa + "/test_do_it_yourself_convts.py",
bpl_exa + "/test_nested.py",
bpl_exa + "/test_pickle1.py",
bpl_exa + "/test_pickle2.py",
bpl_exa + "/test_pickle3.py",
@@ -70,7 +68,6 @@ defs = (
"getting_started2",
"simple_vector",
"do_it_yourself_convts",
"nested",
"pickle1",
"pickle2",
"pickle3",

View File

@@ -17,9 +17,9 @@
ROOT=$(HOME)
BOOST=$(ROOT)/boost
PYEXE=PYTHONPATH=. /usr/local/Python-1.5.2/bin/python
PYEXE=/usr/local/Python-1.5.2/bin/python
PYINC=-I/usr/local/Python-1.5.2/include/python1.5
#PYEXE=PYTHONPATH=. /usr/local/Python-2.1/bin/python
#PYEXE=/usr/local/Python-2.1/bin/python
#PYINC=-I/usr/local/Python-2.1/include/python2.1
STLPORTINC=-I$(BOOST)/boost/compatibility/cpp_c_headers
@@ -44,7 +44,6 @@ DEPOBJ=$(OBJ) \
getting_started1.o getting_started2.o \
simple_vector.o \
do_it_yourself_convts.o \
nested.o \
pickle1.o pickle2.o pickle3.o \
noncopyable_export.o noncopyable_import.o \
ivect.o dvect.o \
@@ -58,7 +57,6 @@ all: libboost_python.a \
getting_started1.so getting_started2.so \
simple_vector.so \
do_it_yourself_convts.so \
nested.so \
pickle1.so pickle2.so pickle3.so \
noncopyable_export.so noncopyable_import.so \
ivect.so dvect.so \
@@ -86,9 +84,6 @@ simple_vector.so: $(OBJ) simple_vector.o
do_it_yourself_convts.so: $(OBJ) do_it_yourself_convts.o
$(LD) $(LDOPTS) $(OBJ) do_it_yourself_convts.o -o do_it_yourself_convts.so
nested.so: $(OBJ) nested.o
$(LD) $(LDOPTS) $(OBJ) nested.o -o nested.so
pickle1.so: $(OBJ) pickle1.o
$(LD) $(LDOPTS) $(OBJ) pickle1.o -o pickle1.so
@@ -131,7 +126,6 @@ test:
$(PYEXE) test_getting_started2.py
$(PYEXE) test_simple_vector.py
$(PYEXE) test_do_it_yourself_convts.py
$(PYEXE) test_nested.py
$(PYEXE) test_pickle1.py
$(PYEXE) test_pickle2.py
$(PYEXE) test_pickle3.py
@@ -148,7 +142,6 @@ clean:
rm -f getting_started2.o getting_started2.so
rm -f simple_vector.o simple_vector.so
rm -f do_it_yourself_convts.o do_it_yourself_convts.so
rm -f nested.o nested.so
rm -f pickle1.o pickle1.so
rm -f pickle2.o pickle2.so
rm -f pickle3.o pickle3.so

View File

@@ -19,9 +19,9 @@ BOOST=$(ROOT)/boost
PYEXE=PYTHONPATH=. /usr/bin/python
PYINC=-I/usr/include/python1.5
#PYEXE=PYTHONPATH=. /usr/local/Python-1.5.2/bin/python
#PYEXE=/usr/local/Python-1.5.2/bin/python
#PYINC=-I/usr/local/Python-1.5.2/include/python1.5
#PYEXE=PYTHONPATH=. /usr/local/Python-2.1/bin/python
#PYEXE=/usr/local/Python-2.1/bin/python
#PYINC=-I/usr/local/Python-2.1/include/python2.1
STDOPTS=-fPIC -ftemplate-depth-21
@@ -45,7 +45,6 @@ DEPOBJ=$(OBJ) \
getting_started1.o getting_started2.o \
simple_vector.o \
do_it_yourself_convts.o \
nested.o \
pickle1.o pickle2.o pickle3.o \
noncopyable_export.o noncopyable_import.o \
ivect.o dvect.o \
@@ -59,7 +58,6 @@ all: libboost_python.a \
getting_started1.so getting_started2.so \
simple_vector.so \
do_it_yourself_convts.so \
nested.so \
pickle1.so pickle2.so pickle3.so \
noncopyable_export.so noncopyable_import.so \
ivect.so dvect.so \
@@ -87,9 +85,6 @@ simple_vector.so: $(OBJ) simple_vector.o
do_it_yourself_convts.so: $(OBJ) do_it_yourself_convts.o
$(LD) $(LDOPTS) $(OBJ) do_it_yourself_convts.o -o do_it_yourself_convts.so
nested.so: $(OBJ) nested.o
$(LD) $(LDOPTS) $(OBJ) nested.o -o nested.so
pickle1.so: $(OBJ) pickle1.o
$(LD) $(LDOPTS) $(OBJ) pickle1.o -o pickle1.so
@@ -132,7 +127,6 @@ test:
$(PYEXE) test_getting_started2.py
$(PYEXE) test_simple_vector.py
$(PYEXE) test_do_it_yourself_convts.py
$(PYEXE) test_nested.py
$(PYEXE) test_pickle1.py
$(PYEXE) test_pickle2.py
$(PYEXE) test_pickle3.py
@@ -149,7 +143,6 @@ clean:
rm -f getting_started2.o getting_started2.so
rm -f simple_vector.o simple_vector.so
rm -f do_it_yourself_convts.o do_it_yourself_convts.so
rm -f nested.o nested.so
rm -f pickle1.o pickle1.so
rm -f pickle2.o pickle2.so
rm -f pickle3.o pickle3.so

View File

@@ -30,16 +30,13 @@
# -fvtable-thunks eliminates the compiler warning, but
# "import boost_python_test" still causes a crash.
ROOT=R:
ROOT=L:
BOOST_WIN="$(ROOT)\boost"
BOOST_UNIX=$(HOME)/boost
PYEXE="C:\Program files\Python\python.exe"
PYINC=-I"C:\usr\include\python1.5"
PYLIB="C:\usr\lib\libpython15.a"
#PYEXE="C:\Python21\python.exe"
#PYINC=-I"C:\usr\include\python2.1"
#PYLIB="C:\usr\lib\libpython21.a"
STDOPTS=-ftemplate-depth-21
WARNOPTS=
@@ -63,7 +60,6 @@ all: libboost_python.a \
getting_started1.pyd getting_started2.pyd \
simple_vector.pyd \
do_it_yourself_convts.pyd \
nested.pyd \
pickle1.pyd pickle2.pyd pickle3.pyd \
noncopyable_export.pyd noncopyable_import.pyd \
ivect.pyd dvect.pyd \
@@ -112,12 +108,6 @@ do_it_yourself_convts.pyd: $(OBJ) do_it_yourself_convts.o
--def do_it_yourself_convts.def \
$(OBJ) do_it_yourself_convts.o $(PYLIB)
nested.pyd: $(OBJ) nested.o
dllwrap $(DLLWRAPOPTS) \
--dllname nested.pyd \
--def nested.def \
$(OBJ) nested.o $(PYLIB)
pickle1.pyd: $(OBJ) pickle1.o
dllwrap $(DLLWRAPOPTS) \
--dllname pickle1.pyd \
@@ -188,7 +178,6 @@ test:
$(PYEXE) test_getting_started2.py
$(PYEXE) test_simple_vector.py
$(PYEXE) test_do_it_yourself_convts.py
$(PYEXE) test_nested.py
$(PYEXE) test_pickle1.py
$(PYEXE) test_pickle2.py
$(PYEXE) test_pickle3.py

View File

@@ -17,9 +17,9 @@
ROOT=$(HOME)
BOOST=$(ROOT)/boost
PYEXE=PYTHONPATH=. /usr/local/Python-1.5.2/bin/python
PYEXE=/usr/local/Python-1.5.2/bin/python
PYINC=-I/usr/local/Python-1.5.2/include/python1.5
#PYEXE=PYTHONPATH=. /usr/local/Python-2.1/bin/python
#PYEXE=/usr/local/Python-2.1/bin/python
#PYINC=-I/usr/local/Python-2.1/include/python2.1
#STLPORTINC=-I/usr/local/STLport-4.1b3/stlport
#STLPORTINC=-I/usr/local/STLport-4.1b4/stlport
@@ -55,7 +55,6 @@ DEPOBJ=$(OBJ) \
getting_started1.o getting_started2.o \
simple_vector.o \
do_it_yourself_convts.o \
nested.o \
pickle1.o pickle2.o pickle3.o \
noncopyable_export.o noncopyable_import.o \
ivect.o dvect.o \
@@ -69,7 +68,6 @@ all: libboost_python.a \
getting_started1.so getting_started2.so \
simple_vector.so \
do_it_yourself_convts.so \
nested.so \
pickle1.so pickle2.so pickle3.so \
noncopyable_export.so noncopyable_import.so \
ivect.so dvect.so \
@@ -101,9 +99,6 @@ simple_vector.so: $(OBJ) simple_vector.o
do_it_yourself_convts.so: $(OBJ) do_it_yourself_convts.o
$(LD) $(LDOPTS) $(OBJ) do_it_yourself_convts.o -o do_it_yourself_convts.so
nested.so: $(OBJ) nested.o
$(LD) $(LDOPTS) $(OBJ) nested.o -o nested.so
pickle1.so: $(OBJ) pickle1.o
$(LD) $(LDOPTS) $(OBJ) pickle1.o -o pickle1.so
@@ -146,7 +141,6 @@ test:
$(PYEXE) test_getting_started2.py
$(PYEXE) test_simple_vector.py
$(PYEXE) test_do_it_yourself_convts.py
$(PYEXE) test_nested.py
$(PYEXE) test_pickle1.py
$(PYEXE) test_pickle2.py
$(PYEXE) test_pickle3.py
@@ -163,7 +157,6 @@ clean:
rm -f getting_started2.o getting_started2.so
rm -f simple_vector.o simple_vector.so
rm -f do_it_yourself_convts.o do_it_yourself_convts.so
rm -f nested.o nested.so
rm -f pickle1.o pickle1.so
rm -f pickle2.o pickle2.so
rm -f pickle3.o pickle3.so

View File

@@ -10,7 +10,7 @@
# 12 Apr 01 new macro ROOT to simplify configuration (R.W. Grosse-Kunstleve)
# Initial version: R.W. Grosse-Kunstleve
ROOT=R:
ROOT=L:
BOOST_WIN="$(ROOT)\boost"
BOOST_UNIX=$(HOME)/boost
@@ -44,7 +44,6 @@ all: boost_python.lib \
getting_started1.pyd getting_started2.pyd \
simple_vector.pyd \
do_it_yourself_convts.pyd \
nested.pyd \
pickle1.pyd pickle2.pyd pickle3.pyd \
noncopyable_export.pyd noncopyable_import.pyd \
ivect.pyd dvect.pyd \
@@ -71,9 +70,6 @@ simple_vector.pyd: $(OBJ) simple_vector.obj
do_it_yourself_convts.pyd: $(OBJ) do_it_yourself_convts.obj
$(LD) $(LDOPTS) $(OBJ) do_it_yourself_convts.obj $(PYLIB) /export:initdo_it_yourself_convts /out:"do_it_yourself_convts.pyd"
nested.pyd: $(OBJ) nested.obj
$(LD) $(LDOPTS) $(OBJ) nested.obj $(PYLIB) /export:initnested /out:"nested.pyd"
pickle1.pyd: $(OBJ) pickle1.obj
$(LD) $(LDOPTS) $(OBJ) pickle1.obj $(PYLIB) /export:initpickle1 /out:"pickle1.pyd"
@@ -114,7 +110,6 @@ test:
$(PYEXE) test_getting_started2.py
$(PYEXE) test_simple_vector.py
$(PYEXE) test_do_it_yourself_convts.py
$(PYEXE) test_nested.py
$(PYEXE) test_pickle1.py
$(PYEXE) test_pickle2.py
$(PYEXE) test_pickle3.py

View File

@@ -35,7 +35,8 @@
"example1.html#world_class"><code>extension_class&lt;T&gt;</code></a>
template defines a whole raft of these conversions (for <code>T, T*,
T&amp;, std::auto_ptr&lt;T&gt;</code>, etc.), using the same inline
friend function technique employed by <a href="../../utility/operators.htm">the boost operators
friend function technique employed by <a href=
"file:///c:/boost/site/libs/utility/operators.htm">the boost operators
library</a>.
<p>
Because the <code>to_python</code> and <code>from_python</code> functions

View File

@@ -107,6 +107,8 @@ BOOST_PYTHON_END_CONVERSION_NAMESPACE
BOOST_PYTHON_MODULE_INIT(do_it_yourself_convts)
{
try
{
// Create an object representing this extension module.
python::module_builder this_module("do_it_yourself_convts");
@@ -118,4 +120,9 @@ BOOST_PYTHON_MODULE_INIT(do_it_yourself_convts)
// Add the member functions.
ixset_class.def(&IndexingSet::add, "add");
ixset_class.def(&IndexingSet::get, "get");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -32,6 +32,8 @@ extern "C" void (*old_translator)(unsigned int, EXCEPTION_POINTERS*)
BOOST_PYTHON_MODULE_INIT(dvect)
{
try
{
python::module_builder this_module("dvect");
python::class_builder<vects::dvect> dvect_class(this_module, "dvect");
@@ -45,4 +47,10 @@ BOOST_PYTHON_MODULE_INIT(dvect)
# include "dvect_defs.cpp"
# include "ivect_defs.cpp"
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -9,7 +9,7 @@ namespace vects {
struct dvect : public std::vector<double>
{
dvect() : std::vector<double>() {}
dvect(std::size_t n) : std::vector<double>(n) {}
dvect(size_t n) : std::vector<double>(n) {}
dvect(boost::python::tuple tuple) : std::vector<double>(tuple.size())
{
std::vector<double>::iterator v_it = begin();

View File

@@ -16,21 +16,32 @@ namespace hello {
// Python requires an exported function called init<module-name> in every
// extension module. This is where we build the module contents.
BOOST_PYTHON_MODULE_INIT(hello)
extern "C"
#ifdef _WIN32
__declspec(dllexport)
#endif
void inithello()
{
// create an object representing this extension module
boost::python::module_builder hello("hello");
try
{
// create an object representing this extension module
boost::python::module_builder hello("hello");
// Create the Python type object for our extension class
boost::python::class_builder<hello::world> world_class(hello, "world");
// Create the Python type object for our extension class
boost::python::class_builder<hello::world> world_class(hello, "world");
// Add the __init__ function
world_class.def(boost::python::constructor<int>());
// Add a regular member function
world_class.def(&hello::world::get, "get");
// Add the __init__ function
world_class.def(boost::python::constructor<int>());
// Add a regular member function
world_class.def(&hello::world::get, "get");
// Add a regular function to the module
hello.def(hello::length, "length");
// Add a regular function to the module
hello.def(hello::length, "length");
}
catch(...)
{
boost::python::handle_exception(); // Deal with the exception for Python
}
}
// Win32 DLL boilerplate

View File

@@ -16,10 +16,17 @@ namespace python = boost::python;
// extension module. This is where we build the module contents.
BOOST_PYTHON_MODULE_INIT(getting_started1)
{
try
{
// Create an object representing this extension module.
python::module_builder this_module("getting_started1");
// Add regular functions to the module.
this_module.def(greet, "greet");
this_module.def(square, "square");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -26,6 +26,8 @@ namespace python = boost::python;
BOOST_PYTHON_MODULE_INIT(getting_started2)
{
try
{
// Create an object representing this extension module.
python::module_builder this_module("getting_started2");
@@ -42,4 +44,9 @@ BOOST_PYTHON_MODULE_INIT(getting_started2)
// Even better, invite() can also be made a member of hello_class!!!
hello_class.def(invite, "invite");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -32,6 +32,8 @@ extern "C" void (*old_translator)(unsigned int, EXCEPTION_POINTERS*)
BOOST_PYTHON_MODULE_INIT(ivect)
{
try
{
python::module_builder this_module("ivect");
python::class_builder<vects::ivect> ivect_class(this_module, "ivect");
@@ -45,5 +47,10 @@ BOOST_PYTHON_MODULE_INIT(ivect)
# include "dvect_defs.cpp"
# include "ivect_defs.cpp"
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -9,7 +9,7 @@ namespace vects {
struct ivect : public std::vector<int>
{
ivect() : std::vector<int>() {}
ivect(std::size_t n) : std::vector<int>(n) {}
ivect(size_t n) : std::vector<int>(n) {}
ivect(boost::python::tuple tuple) : std::vector<int>(tuple.size())
{
std::vector<int>::iterator v_it = begin();

View File

@@ -1,37 +0,0 @@
// Example by Ralf W. Grosse-Kunstleve
/*
This example shows how convert a nested Python tuple.
*/
#include <boost/python/class_builder.hpp>
#include <stdio.h>
namespace {
boost::python::list
show_nested_tuples(boost::python::tuple outer)
{
boost::python::list result;
for (int i = 0; i < outer.size(); i++) {
boost::python::tuple inner(
BOOST_PYTHON_CONVERSION::from_python(outer[i].get(),
boost::python::type<boost::python::tuple>()));
for (int j = 0; j < inner.size(); j++) {
double x = BOOST_PYTHON_CONVERSION::from_python(inner[j].get(),
boost::python::type<double>());
char buf[128];
sprintf(buf, "(%d,%d) %.6g", i, j, x);
result.append(BOOST_PYTHON_CONVERSION::to_python(std::string(buf)));
}
}
return result;
}
}
BOOST_PYTHON_MODULE_INIT(nested)
{
boost::python::module_builder this_module("nested");
this_module.def(show_nested_tuples, "show_nested_tuples");
}

View File

@@ -18,6 +18,8 @@ extern "C" void (*old_translator)(unsigned int, EXCEPTION_POINTERS*)
BOOST_PYTHON_MODULE_INIT(noncopyable_export)
{
try
{
python::module_builder this_module("noncopyable_export");
python::class_builder<store> store_class(this_module, "store");
@@ -25,4 +27,9 @@ BOOST_PYTHON_MODULE_INIT(noncopyable_export)
store_class.def(python::constructor<int>());
store_class.def(&store::recall, "recall");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -31,6 +31,8 @@ extern "C" void (*old_translator)(unsigned int, EXCEPTION_POINTERS*)
BOOST_PYTHON_MODULE_INIT(noncopyable_import)
{
try
{
python::module_builder this_module("noncopyable_import");
python::import_converters<store>
@@ -42,4 +44,9 @@ BOOST_PYTHON_MODULE_INIT(noncopyable_import)
// However, to keep this example simple, we only define a
// module-level function.
this_module.def(add_stores, "add_stores");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -41,6 +41,8 @@ namespace { // Avoid cluttering the global namespace.
BOOST_PYTHON_MODULE_INIT(pickle1)
{
try
{
// Create an object representing this extension module.
python::module_builder this_module("pickle1");
@@ -54,4 +56,9 @@ BOOST_PYTHON_MODULE_INIT(pickle1)
// Support for pickle.
world_class.def(world_getinitargs, "__getinitargs__");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -73,6 +73,8 @@ namespace { // Avoid cluttering the global namespace.
BOOST_PYTHON_MODULE_INIT(pickle2)
{
try
{
// Create an object representing this extension module.
python::module_builder this_module("pickle2");
@@ -90,4 +92,9 @@ BOOST_PYTHON_MODULE_INIT(pickle2)
world_class.def(world_getinitargs, "__getinitargs__");
world_class.def(world_getstate, "__getstate__");
world_class.def(world_setstate, "__setstate__");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -65,6 +65,8 @@ namespace { // Avoid cluttering the global namespace.
BOOST_PYTHON_MODULE_INIT(pickle3)
{
try
{
// Create an object representing this extension module.
python::module_builder this_module("pickle3");
@@ -83,6 +85,11 @@ BOOST_PYTHON_MODULE_INIT(pickle3)
world_class.def_raw(world_getstate, "__getstate__");
world_class.def_raw(world_setstate, "__setstate__");
world_class.getstate_manages_dict();
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}
namespace {

View File

@@ -77,8 +77,11 @@ namespace {
BOOST_PYTHON_MODULE_INIT(richcmp1)
{
try {
boost::python::module_builder this_module("richcmp1");
// The actual work is done in a separate function in order
// to suppress a bogus VC60 warning.
init_module(this_module);
}
catch (...) { boost::python::handle_exception(); }
}

View File

@@ -55,8 +55,11 @@ namespace {
BOOST_PYTHON_MODULE_INIT(richcmp2)
{
try {
boost::python::module_builder this_module("richcmp2");
// The actual work is done in a separate function in order
// to suppress a bogus VC60 warning.
init_module(this_module);
}
catch (...) { boost::python::handle_exception(); }
}

View File

@@ -168,8 +168,11 @@ namespace {
BOOST_PYTHON_MODULE_INIT(richcmp3)
{
try {
boost::python::module_builder this_module("richcmp3");
// The actual work is done in a separate function in order
// to suppress a bogus VC60 warning.
init_module(this_module);
}
catch (...) { boost::python::handle_exception(); }
}

View File

@@ -13,12 +13,29 @@ namespace python = boost::python;
// Python requires an exported function called init<module-name> in every
// extension module. This is where we build the module contents.
BOOST_PYTHON_MODULE_INIT(rwgk1)
extern "C"
#ifdef _WIN32
__declspec(dllexport)
#endif
void initrwgk1()
{
try
{
// Create an object representing this extension module.
python::module_builder this_module("rwgk1");
// Add regular functions to the module.
this_module.def(greet, "greet");
this_module.def(square, "square");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}
// Win32 DLL boilerplate
#if defined(_WIN32)
#include <windows.h>
extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID) { return 1; }
#endif // _WIN32

View File

@@ -1,50 +0,0 @@
#include <iostream>
#include <string>
namespace { // Avoid cluttering the global namespace.
// A friendly class.
class world
{
private:
std::string country;
public:
world(const std::string& country) { this->country = country; }
std::string greet() const { return "Hello from " + country + "!"; }
};
// A function taking a world object as an argument.
std::string invite(const world& w) {
return w.greet() + " Please come soon!";
}
}
#include <py_cpp/class_wrapper.h>
// Python requires an exported function called init<module-name> in every
// extension module. This is where we build the module contents.
BOOST_PYTHON_MODULE_INIT(example2)
{
// Create an object representing this extension module.
py::Module this_module("example2");
// Create the Python type object for our extension class.
py::ClassWrapper<world> world_class(this_module, "world");
// Add the __init__ function.
world_class.def(py::Constructor<std::string>());
// Add a regular member function.
world_class.def(&world::greet, "greet");
// Add invite() as a regular function to the module.
this_module.def(invite, "invite");
// Even better, invite() can also be made a member of world_class!!!
world_class.def(invite, "invite");
}
// Win32 DLL boilerplate
#if defined(_WIN32)
#include <windows.h>
extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID) { return 1; }
#endif // _WIN32

View File

@@ -1,101 +0,0 @@
#include <py_cpp/class_wrapper.h>
#include <py_cpp/objects.h>
#define rangei(n) for (int i = 0; i < n; i++)
namespace { // Avoid cluttering the global namespace.
// A wrapper is used to define additional constructors.
//
struct vector_double_wrapper: std::vector<double>
{
// Tell the compiler how to convert a base class object to
// this wrapper object.
vector_double_wrapper(PyObject*, const std::vector<double>& vd)
: std::vector<double>(vd) {}
vector_double_wrapper(PyObject* self)
: std::vector<double>() {}
vector_double_wrapper(PyObject* self, const int n)
: std::vector<double>(n) {}
vector_double_wrapper(PyObject* self, py::Tuple tuple)
: std::vector<double>(tuple.size())
{
std::vector<double>::iterator vd = begin();
rangei(tuple.size())
vd[i] = from_python(tuple[i].get(), py::Type<double>()); // GCC BUG
}
};
double getitem(const std::vector<double>& vd, const std::size_t key) {
return vd[key];
}
void setitem(std::vector<double>& vd, const std::size_t key,
const double &d) {
std::vector<double>::iterator vditer = vd.begin();
vditer[key] = d;
}
void delitem(std::vector<double>& vd, const std::size_t key) {
std::vector<double>::iterator vditer = vd.begin();
vd.erase(&vditer[key]);
}
// Convert vector_double to a regular Python tuple.
//
py::Tuple as_tuple(const std::vector<double>& vd)
{
py::Tuple t(vd.size());
rangei(vd.size()) t.set_item(i, py::Ptr(py::to_python(vd[i]))); // GCC BUG
return t;
}
// Function returning a vector_double object to Python.
//
std::vector<double> foo(const int n)
{
std::vector<double> vd(n);
std::vector<double>::iterator vditer = vd.begin();
rangei(n) vditer[i] = double(i);
return vd;
}
// Same as foo(), but avoid copying on return.
//
std::auto_ptr<std::vector<double> > bar(const int n)
{
std::auto_ptr<std::vector<double> > vdptr(new std::vector<double>(n));
std::vector<double>::iterator vditer = vdptr->begin();
rangei(n) vditer[i] = double(10 * i);
return vdptr;
}
}
BOOST_PYTHON_MODULE_INIT(example3)
{
py::Module this_module("example3");
py::ClassWrapper<std::vector<double>, vector_double_wrapper>
vector_double(this_module, "vector_double");
vector_double.def(py::Constructor<>());
vector_double.def(py::Constructor<const int>());
vector_double.def(py::Constructor<py::Tuple>());
vector_double.def(&std::vector<double>::size, "__len__");
vector_double.def(getitem, "__getitem__");
vector_double.def(setitem, "__setitem__");
vector_double.def(delitem, "__delitem__");
vector_double.def(as_tuple, "as_tuple");
this_module.def(foo, "foo");
this_module.def(bar, "bar");
}
// Win32 DLL boilerplate
#if defined(_WIN32)
#include <windows.h>
extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID) { return 1; }
#endif // _WIN32

View File

@@ -85,6 +85,8 @@ namespace { // Avoid cluttering the global namespace.
BOOST_PYTHON_MODULE_INIT(simple_vector)
{
try
{
python::module_builder this_module("simple_vector");
python::class_builder<std::vector<double>, vector_double_wrapper>
@@ -101,4 +103,9 @@ BOOST_PYTHON_MODULE_INIT(simple_vector)
this_module.def(foo, "foo");
this_module.def(bar, "bar");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -1,23 +0,0 @@
r'''>>> import nested
>>> s = nested.show_nested_tuples(((1,2,3), (4,5,6,7)))
>>> for l in s:
... print l
(0,0) 1
(0,1) 2
(0,2) 3
(1,0) 4
(1,1) 5
(1,2) 6
(1,3) 7
'''
def run(args = None):
if args is not None:
import sys
sys.argv = args
import doctest, test_nested
return doctest.testmod(test_nested)
if __name__ == '__main__':
import sys
sys.exit(run()[0])

View File

@@ -74,17 +74,17 @@ inline void xdecref_impl(PyObject* p) { Py_XDECREF(p); }
template <class T>
inline void decref(T* p)
{
char* const raw_p = reinterpret_cast<char*>(p);
char* const p_base = raw_p - offsetof(PyObject, ob_refcnt);
decref_impl(reinterpret_cast<PyObject*>(p_base));
char* const raw_p = reinterpret_cast<char*>(p);
char* const p_base = raw_p - offsetof(PyObject, ob_refcnt);
decref_impl(reinterpret_cast<PyObject*>(p_base));
}
template <class T>
inline void xdecref(T* p)
{
char* const raw_p = reinterpret_cast<char*>(p);
char* const p_base = raw_p - offsetof(PyObject, ob_refcnt);
xdecref_impl(reinterpret_cast<PyObject*>(p_base));
char* const raw_p = reinterpret_cast<char*>(p);
char* const p_base = raw_p - offsetof(PyObject, ob_refcnt);
xdecref_impl(reinterpret_cast<PyObject*>(p_base));
}
namespace detail {
@@ -294,22 +294,22 @@ inline PyObject* to_python(float f)
inline PyObject* to_python(long l)
{
return PyInt_FromLong(l);
return PyInt_FromLong(l);
}
inline PyObject* to_python(int x)
{
return PyInt_FromLong(x);
return PyInt_FromLong(x);
}
inline PyObject* to_python(short x)
{
return PyInt_FromLong(x);
return PyInt_FromLong(x);
}
inline PyObject* to_python(bool b)
{
return PyInt_FromLong(b);
return PyInt_FromLong(b);
}
inline PyObject* to_python(void)
@@ -319,7 +319,7 @@ inline PyObject* to_python(void)
inline PyObject* to_python(const char* s)
{
return PyString_FromString(s);
return PyString_FromString(s);
}
inline std::string from_python(PyObject* p, boost::python::type<const std::string&>)

View File

@@ -169,9 +169,6 @@ struct export_converter_object_noncopyable : export_converter_object_base<T>
PyErr_SetString(PyExc_RuntimeError,
"to_python(const T&) converter not exported");
throw import_error();
#if defined(__MWERKS__) && __MWERKS__ <= 0x2406
return 0;
#endif
}
virtual T* from_python_Ts(PyObject* p, boost::python::type<T*> t) {

View File

@@ -21,10 +21,10 @@ namespace boost { namespace python { namespace detail {
// base_object - adds a constructor and non-virtual destructor to a
// base Python type (e.g. PyObject, PyTypeObject).
template <class PythonType>
struct base_object : PythonType
template <class python_type>
struct base_object : python_type
{
typedef PythonType base_python_type;
typedef python_type base_python_type;
// Initializes type and reference count. All other fields of base_python_type are 0
base_object(PyTypeObject* type_obj);
@@ -41,20 +41,20 @@ typedef base_object<PyTypeObject> python_type;
//
// base_object member function implementations
//
template <class PythonType>
base_object<PythonType>::base_object(PyTypeObject* type_obj)
template <class python_type>
base_object<python_type>::base_object(PyTypeObject* type_obj)
{
base_python_type* bp = this;
#if !defined(_MSC_VER) || defined(__STLPORT)
std::
#endif
memset(bp, 0, sizeof(base_python_type));
memset(bp, 0, sizeof(base_python_type));
Py_INCREF(type_obj);
PyObject_INIT(bp, type_obj);
}
template <class PythonType>
inline base_object<PythonType>::~base_object()
template <class python_type>
inline base_object<python_type>::~base_object()
{
Py_DECREF(ob_type);
}

View File

@@ -15,6 +15,14 @@
namespace boost { namespace python {
namespace detail {
// The default way of converting a PyObject* or PyTypeObject* to a T*
template <class T>
struct downcast_traits
{
template <class U>
static T* cast(U* p) { return static_cast<T*>(p); }
};
inline PyTypeObject* as_base_object(const PyTypeObject*, PyObject* p)
{
return reinterpret_cast<PyTypeObject*>(p);
@@ -46,19 +54,19 @@ template <class T>
struct downcast
{
downcast(PyObject* p)
: m_p(static_cast<T*>(detail::as_base_object((T*)0, p)))
: m_p(detail::downcast_traits<T>::cast(detail::as_base_object((T*)0, p)))
{}
downcast(const PyObject* p)
: m_p(static_cast<T*>(detail::as_base_object((const T*)0, p)))
: m_p(detail::downcast_traits<T>::cast(detail::as_base_object((const T*)0, p)))
{}
downcast(PyTypeObject* p)
: m_p(static_cast<T*>(p))
: m_p(detail::downcast_traits<T>::cast(p))
{}
downcast(const PyTypeObject* p)
: m_p(static_cast<T*>(p))
: m_p(detail::downcast_traits<T>::cast(p))
{}
operator T*() const { return m_p; }

View File

@@ -58,9 +58,9 @@
# endif
#if defined(_WIN32) || defined(__CYGWIN__)
# define BOOST_PYTHON_MODULE_INIT(name) void init_module_##name(); extern "C" __declspec(dllexport) void init##name() { boost::python::handle_exception(init_module_##name); } void init_module_##name()
# define BOOST_PYTHON_MODULE_INIT(name) extern "C" __declspec(dllexport) void init##name()
#else
# define BOOST_PYTHON_MODULE_INIT(name) void init_module_##name(); extern "C" void init##name() { boost::python::handle_exception(init_module_##name); } void init_module_##name()
# define BOOST_PYTHON_MODULE_INIT(name) extern "C" void init##name()
#endif
#endif // CONFIG_DWA052200_H_

View File

@@ -233,9 +233,6 @@ class python_extension_class_converters
}
boost::python::detail::report_missing_instance_data(self, boost::python::detail::class_registry<T>::class_object(), typeid(T));
throw boost::python::argument_error();
#if defined(__MWERKS__) && __MWERKS__ <= 0x2406
return 0;
#endif
}
// Convert to T*
@@ -264,9 +261,6 @@ class python_extension_class_converters
}
boost::python::detail::report_missing_ptr_data(self, boost::python::detail::class_registry<T>::class_object(), typeid(T));
throw boost::python::argument_error();
#if defined(__MWERKS__) && __MWERKS__ <= 0x2406
return *(PtrType*)0;
#endif
}
// Extract from obj a reference to the PtrType object which is holding a

View File

@@ -46,7 +46,7 @@ class function : public python_object
private:
struct type_object;
private:
reference<function> m_overloads; // A linked list of the function overloads
reference<function> m_overloads;
};
// wrapped_function_pointer<> --
@@ -59,25 +59,20 @@ class function : public python_object
template <class R, class F>
struct wrapped_function_pointer : function
{
typedef F ptr_fun; // pointer-to--function or pointer-to-member-function
wrapped_function_pointer(ptr_fun pf)
typedef F ptr_fun; // pointer-to--function or pointer-to-member-function
wrapped_function_pointer(ptr_fun pf)
: m_pf(pf) {}
private:
PyObject* do_call(PyObject* args, PyObject* keywords) const
{
// This is where the boundary between the uniform Python function
// interface and the statically-checked C++ function interface is
// crossed.
return caller<R>::call(m_pf, args, keywords);
}
PyObject* do_call(PyObject* args, PyObject* keywords) const
{ return caller<R>::call(m_pf, args, keywords); }
const char* description() const
{ return typeid(F).name(); }
private:
const ptr_fun m_pf;
const ptr_fun m_pf;
};
// raw_arguments_function
@@ -87,13 +82,13 @@ struct wrapped_function_pointer : function
template <class Ret, class Args, class Keywords>
struct raw_arguments_function : function
{
typedef Ret (*ptr_fun)(Args, Keywords);
raw_arguments_function(ptr_fun pf)
typedef Ret (*ptr_fun)(Args, Keywords);
raw_arguments_function(ptr_fun pf)
: m_pf(pf) {}
private:
PyObject* do_call(PyObject* args, PyObject* keywords) const
PyObject* do_call(PyObject* args, PyObject* keywords) const
{
ref dict(keywords ?
ref(keywords, ref::increment_count) :
@@ -108,7 +103,7 @@ struct raw_arguments_function : function
{ return typeid(ptr_fun).name(); }
private:
const ptr_fun m_pf;
const ptr_fun m_pf;
};
// virtual_function<> --
@@ -127,19 +122,19 @@ template <class T, class R, class V, class D>
class virtual_function : public function
{
public:
virtual_function(V virtual_function_ptr, D default_implementation)
virtual_function(V virtual_function_ptr, D default_implementation)
: m_virtual_function_ptr(virtual_function_ptr),
m_default_implementation(default_implementation)
{}
private:
PyObject* do_call(PyObject* args, PyObject* keywords) const;
PyObject* do_call(PyObject* args, PyObject* keywords) const;
const char* description() const
{ return typeid(V).name(); }
private:
const V m_virtual_function_ptr;
const V m_virtual_function_ptr;
const D m_default_implementation;
};
@@ -160,7 +155,7 @@ template <class F>
inline function* new_wrapped_function(F pmf)
{
// Deduce the return type and pass it off to the helper function above
return new_wrapped_function_aux(return_value(pmf), pmf);
return new_wrapped_function_aux(return_value(pmf), pmf);
}
template <class R, class Args, class keywords>
@@ -220,7 +215,7 @@ class bound_function : public python_object
private: // data members for allocation/deallocation optimization
bound_function* m_free_list_link;
static bound_function* free_list;
static bound_function* free_list;
};
// Special functions designed to access data members of a wrapped C++ object.

View File

@@ -1,39 +0,0 @@
// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and
// distribute this software is granted provided this copyright notice appears
// in all copies. This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
#ifndef VOID_ADAPTOR_DWA20011112_HPP
# define VOID_ADAPTOR_DWA20011112_HPP
namespace boost { namespace python { namespace detail {
extern PyObject arbitrary_object;
template <class T>
struct void_adaptor
{
typedef PyObject* result_type;
void_adaptor(T const& f)
: m_f(f)
{}
PyObject* operator()() const
{
m_f();
return &arbitrary_object;
}
private:
T m_f;
};
template <class T>
void_adaptor<T> make_void_adaptor(T const& f)
{
return void_adaptor<T>(f);
}
}}} // namespace boost::python::detail
#endif // VOID_ADAPTOR_DWA20011112_HPP

View File

@@ -90,9 +90,5 @@ typedef int pid_t;
#if !defined(PY_MAJOR_VERSION) || PY_MAJOR_VERSION < 2
# define PyObject_INIT(op, typeobj) \
( (op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
#endif
#ifdef __MWERKS__
# pragma warn_possunwant off
( (op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
#endif

View File

@@ -9,50 +9,13 @@
#ifndef ERRORS_DWA052500_H_
# define ERRORS_DWA052500_H_
# include <boost/python/detail/wrap_python.hpp>
namespace boost { namespace python {
struct error_already_set {};
struct argument_error : error_already_set {};
struct object_functor_base
{
typedef PyObject* result_type;
virtual PyObject* operator()() const = 0;
private:
static void* operator new(std::size_t); // don't allow dynamic allocation
void operator delete(void*);
void operator delete(void*, size_t);
};
template <class T>
struct object_functor : object_functor_base
{
object_functor(T const& f)
: m_f(f)
{
}
PyObject* operator()() const
{
return m_f();
}
private:
T const& m_f;
};
// Handles exceptions caught just before returning to Python code.
PyObject* handle_exception_impl(object_functor_base const& f);
template <class T>
PyObject* handle_exception(T const& f)
{
return handle_exception_impl(object_functor<T>(f));
}
void handle_exception(void (*)());
void handle_exception();
template <class T>
T* expect_non_null(T* x)

View File

@@ -101,7 +101,7 @@ class list : public object
explicit list(std::size_t sz = 0);
static PyTypeObject* type_obj();
static bool accepts(ref p);
std::size_t size() const;
std::size_t size();
ref operator[](std::size_t pos) const;
proxy operator[](std::size_t pos);
ref get_item(std::size_t pos) const;
@@ -283,7 +283,7 @@ struct list::slice_proxy
const list& operator=(const list& rhs);
operator ref() const;
operator list() const;
std::size_t size() const;
std::size_t size();
ref operator[](std::size_t pos) const;
private:
friend class list;

View File

@@ -42,31 +42,31 @@ BOOST_PYTHON_IMPORT_CONVERSION(py_ptr_conversions);
template <class T>
class reference
: public py_ptr_conversions<reference<T>, T>
: public py_ptr_conversions<reference<T>, T>
{
public:
typedef T value_type;
reference(const reference& rhs)
: m_p(rhs.m_p)
{
Py_XINCREF(object());
}
reference(const reference& rhs)
: m_p(rhs.m_p)
{
Py_XINCREF(object());
}
#if !defined(BOOST_MSVC6_OR_EARLIER)
template <class T2>
reference(const reference<T2>& rhs)
: m_p(rhs.object())
{
Py_XINCREF(object());
}
template <class T2>
reference(const reference<T2>& rhs)
: m_p(rhs.object())
{
Py_XINCREF(object());
}
#endif
reference() : m_p(0) {}
reference() : m_p(0) {}
// These are two ways of spelling the same thing, that we need to increment
// the reference count on the pointer when we're initialized.
enum increment_count_t { increment_count };
enum increment_count_t { increment_count };
enum allow_null { null_ok };
@@ -77,7 +77,7 @@ public:
template <class T2>
reference(T2* x, increment_count_t)
: m_p(expect_non_null(x)) { Py_INCREF(object()); }
template <class T2>
reference(T2* x, allow_null)
: m_p(x) {}
@@ -85,49 +85,49 @@ public:
template <class T2>
reference(T2* x, allow_null, increment_count_t)
: m_p(x) { Py_XINCREF(object()); }
template <class T2>
reference(T2* x, increment_count_t, allow_null)
: m_p(x) { Py_XINCREF(object()); }
#if !defined(BOOST_MSVC6_OR_EARLIER)
template <class T2>
reference& operator=(const reference<T2>& rhs)
{
Py_XDECREF(object());
m_p = rhs.m_p;
Py_XINCREF(object());
return *this;
}
template <class T2>
reference& operator=(const reference<T2>& rhs)
{
Py_XDECREF(object());
m_p = rhs.m_p;
Py_XINCREF(object());
return *this;
}
#endif
reference& operator=(const reference& rhs)
{
Py_XINCREF(static_cast<PyObject*>(rhs.m_p));
Py_XDECREF(object());
m_p = rhs.m_p;
return *this;
}
reference& operator=(const reference& rhs)
{
Py_XINCREF(static_cast<PyObject*>(rhs.m_p));
Py_XDECREF(object());
m_p = rhs.m_p;
return *this;
}
~reference()
{
Py_XDECREF(m_p);
}
T& operator*() const { return *m_p; }
~reference()
{
Py_XDECREF(m_p);
}
T& operator*() const { return *m_p; }
// MSVC doesn't like boost::dereferencable unless T has a default
// constructor, so operator-> must be defined by hand :(
T* operator->() const { return &**this; }
T* get() const { return m_p; }
T* get() const { return m_p; }
T* release()
{
T* p = m_p;
m_p = 0;
return p;
}
T* release()
{
T* p = m_p;
m_p = 0;
return p;
}
void reset()
{ Py_XDECREF(m_p); m_p = 0; }
@@ -139,7 +139,7 @@ public:
template <class T2>
void reset(T2* x, increment_count_t)
{ Py_XDECREF(m_p); m_p = expect_non_null(x); Py_INCREF(object()); }
template <class T2>
void reset(T2* x, allow_null)
{ Py_XDECREF(m_p); m_p = x;}
@@ -147,11 +147,11 @@ public:
template <class T2>
void reset(T2* x, allow_null, increment_count_t)
{ Py_XDECREF(m_p); m_p = x; Py_XINCREF(object()); }
template <class T2>
void reset(T2* x, increment_count_t, allow_null)
{ Py_XDECREF(m_p); m_p = x; Py_XINCREF(object()); }
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
private:
template<typename Y> friend class shared_ptr;
@@ -160,7 +160,7 @@ private:
inline PyObject* object() const
{ return as_object(m_p); }
T* m_p;
T* m_p;
};
typedef reference<PyObject> ref;

View File

@@ -14,7 +14,6 @@
// 03 Mar 01 added: converters for [plain] char (Ralf W. Grosse-Kunstleve)
#include <boost/python/conversions.hpp>
#include <boost/python/detail/void_adaptor.hpp>
#include <typeinfo>
#include <exception>
#ifndef BOOST_NO_LIMITS
@@ -24,11 +23,15 @@
namespace boost { namespace python {
// IMPORTANT: this function may only be called from within a catch block!
PyObject* handle_exception_impl(object_functor_base const& f)
void handle_exception()
{
try
{
return f();
try {
// re-toss the current exception so we can find out what type it is.
// NOTE: a heinous bug in MSVC6 causes exception objects re-thrown in
// this way to be double-destroyed. Thus, you must only use objects that
// can tolerate double-destruction with that compiler. Metrowerks
// Codewarrior doesn't suffer from this problem.
throw;
}
catch(const boost::python::error_already_set&)
{
@@ -46,13 +49,6 @@ PyObject* handle_exception_impl(object_functor_base const& f)
{
PyErr_SetString(PyExc_RuntimeError, "unidentifiable C++ exception");
}
return 0;
}
void handle_exception(void (*f)())
{
handle_exception(
boost::python::detail::make_void_adaptor(f));
}
namespace detail {
@@ -120,7 +116,7 @@ T integer_from_python(PyObject* p, boost::python::type<T>)
PyErr_SetString(PyExc_ValueError, buffer);
throw boost::python::argument_error();
}
#if defined(__MWERKS__) && __MWERKS__ <= 0x2406
#if defined(__MWERKS__) && __MWERKS__ <= 0x2400
return 0; // Not smart enough to know that the catch clause always rethrows
#endif
}

View File

@@ -10,9 +10,8 @@
// 04 Mar 01 Use PyObject_INIT() instead of trying to hand-initialize (David Abrahams)
#include <boost/python/detail/extension_class.hpp>
#include <boost/utility.hpp>
#include <boost/bind.hpp>
#include <cstring>
#include <boost/utility.hpp>
namespace boost { namespace python {
namespace detail {
@@ -485,19 +484,16 @@ void operator_dispatcher_dealloc(PyObject* self)
int operator_dispatcher_coerce(PyObject** l, PyObject** r)
{
Py_INCREF(*l);
PyObject* new_r = handle_exception(
bind(operator_dispatcher::create,
ref(*r, ref::increment_count),
ref()));
if (new_r)
try
{
*r = new_r;
return 0;
*r = operator_dispatcher::create(ref(*r, ref::increment_count), ref());
}
else
catch(...)
{
handle_exception();
return -1;
}
return 0;
}

View File

@@ -61,8 +61,6 @@ function::function()
PyObject* function::call(PyObject* args, PyObject* keywords) const
{
// Traverse the linked list of function overloads until we find one that
// matches.
for (const function* f = this; f != 0; f = f->m_overloads.get())
{
PyErr_Clear();
@@ -77,14 +75,9 @@ PyObject* function::call(PyObject* args, PyObject* keywords) const
}
}
// If we get here, no overloads matched the arguments
// Allow the single-function error-reporting to take effect unless there was
// an overload
if (m_overloads.get() == 0)
return 0;
// Synthesize a more-explicit error message
PyErr_Clear();
string message("No overloaded functions match (");
tuple arguments(ref(args, ref::increment_count));

View File

@@ -238,9 +238,6 @@ class python_extension_class_converters
}
boost::python::detail::report_missing_instance_data(self, boost::python::detail::class_registry<T>::class_object(), typeid(T));
throw boost::python::argument_error();
#if defined(__MWERKS__) && __MWERKS__ <= 0x2406
return 0;
#endif
}
// Convert to T*
@@ -269,10 +266,6 @@ class python_extension_class_converters
}
boost::python::detail::report_missing_ptr_data(self, boost::python::detail::class_registry<T>::class_object(), typeid(T));
throw boost::python::argument_error();
#if defined(__MWERKS__) && __MWERKS__ <= 0x2406
PtrType x;
return x;
#endif
}
// Extract from obj a reference to the PtrType object which is holding a

View File

@@ -362,7 +362,7 @@ bool list::accepts(ref p)
return PyList_Check(p.get());
}
std::size_t list::size() const
std::size_t list::size()
{
return PyList_Size(get());
}
@@ -467,7 +467,7 @@ list::slice_proxy::operator list() const
return list(this->operator ref());
}
std::size_t list::slice_proxy::size() const
std::size_t list::slice_proxy::size()
{
return this->operator list().size();
}

View File

@@ -8,18 +8,15 @@
#include <boost/python/detail/types.hpp>
#include <boost/python/reference.hpp> // for handle_exception()
#include <boost/python/conversions.hpp>
#include <boost/python/module_builder.hpp>
#include <boost/python/detail/none.hpp>
#include <boost/python/detail/void_adaptor.hpp>
#include <cstring>
#include <vector>
#include <cstddef>
#include <stdexcept>
#include <boost/smart_ptr.hpp>
#include <boost/python/objects.hpp>
#include <boost/type_traits/alignment_traits.hpp>
#include <boost/bind.hpp>
#include <boost/type_traits.hpp>
namespace boost { namespace python {
@@ -27,175 +24,136 @@ namespace {
using detail::type_object_base;
// Define a family of forwarding functions that can be called from a
// PyTypeObject's slots. These functions dispatch through a (virtual) member
// function pointer in the type_object_base, and handle exceptions in a
// uniform way, preventing us from having to rewrite the dispatching code over
// and over.
// Given a function object f with signature
//
// PyObject* f(PyTypeObject*,PyObject*)
//
// calls f inside of handle_exception, and returns the result. If an exception
// is thrown by f, returns 0.
template <class F>
PyObject* obj_call(PyObject* obj, F const& f)
{
return handle_exception(
boost::bind<PyObject*>(f, static_cast<type_object_base*>(obj->ob_type), obj));
}
// int_converter<T>/value_holder<T>
//
// A simple function object which converts its argument to a PyObject*. We
// need this because handle_exception needs to return a PyObject*, even if the
// function being called is supposed to return int. It has two parts...
// holds the value actually returned by the underlying function
template <class T>
struct value_holder : PyObject
{
value_holder() : is_set(false), value(-1) {}
// Tricky constructor allows us to grab the result even if rhs == 0.
explicit value_holder(value_holder const* rhs)
: is_set(rhs ? rhs->is_set : false), value(rhs ? rhs->value : -1) {}
// true if the function object was ever called (false if an exception occurred)
bool is_set;
// The returned value
T value;
};
// The function object
template <class R>
struct int_converter
{
typedef PyObject* result_type;
PyObject* operator()(R const& x)
{
m_holder.is_set = true;
m_holder.value = x;
return &m_holder; // returns
}
value_holder<R> m_holder;
};
// Call the given int-returning function object inside of handle_exception,
// returning a value_holder. F is a function object with "signature"
//
// R F(PyTypeObject*, PyObject*)
//
// where R is an integer type.
template <class R, class F>
value_holder<R> int_call_holder(PyObject* obj, F f)
{
return value_holder<R>(
// The int_converter object containing the value_holder is valid
// through the life of the full-expression, so we can construct from
// the pointer
static_cast<value_holder<R>*>(
handle_exception(
boost::bind<PyObject*>(
// Add an int_converter back-end to f
int_converter<R>()
// Bind the object's type and the object itself into f
, boost::bind<R>(f, static_cast<type_object_base*>(obj->ob_type), obj)
)
)
)
);
}
// Just like int_call_holder (above), but returns the integer directly. If F
// throws an exception, returns -1
template <class R, class F>
R int_call(PyObject* obj, F f)
{
value_holder<R> const v(int_call_holder<R>(obj, f));
return v.value;
}
// Implemented in terms of obj_call, above
PyObject* call(PyObject* obj, PyObject* (type_object_base::*f)(PyObject*) const)
{
return obj_call(obj, bind(f, _1, _2));
try
{
return (static_cast<type_object_base*>(obj->ob_type)->*f)(obj);
}
catch(...)
{
handle_exception();
return 0;
}
}
// Naming this differently allows us to use it for functions returning long on
// compilers without partial ordering
template <class R>
R int_call(PyObject* obj, R (type_object_base::*f)(PyObject*) const)
{
try
{
return (static_cast<type_object_base*>(obj->ob_type)->*f)(obj);
}
catch(...)
{
handle_exception();
return -1;
}
}
// Implemented in terms of int_call, above
int call(PyObject* obj, int (type_object_base::*f)(PyObject*) const)
{
return int_call<int>(obj, bind(f, _1, _2));
return int_call(obj, f);
}
template <class A1>
PyObject* call(PyObject* obj, PyObject* (type_object_base::*f)(PyObject*, A1) const, A1 a1)
{
return obj_call(obj, bind(f, _1, _2, a1));
try
{
return (static_cast<type_object_base*>(obj->ob_type)->*f)(obj, a1);
}
catch(...)
{
handle_exception();
return 0;
}
}
template <class A1>
int call(PyObject* obj, int (type_object_base::*f)(PyObject*, A1) const, A1 a1)
{
return int_call<int>(obj, bind(f, _1, _2, a1));
try
{
return (static_cast<type_object_base*>(obj->ob_type)->*f)(obj, a1);
}
catch(...)
{
handle_exception();
return -1;
}
}
template <class A1, class A2>
PyObject* call(PyObject* obj, PyObject* (type_object_base::*f)(PyObject*, A1, A2) const, A1 a1, A2 a2)
{
return obj_call(obj, bind(f, _1, _2, a1, a2));
try
{
return (static_cast<type_object_base*>(obj->ob_type)->*f)(obj, a1, a2);
}
catch(...)
{
handle_exception();
return 0;
}
}
template <class A1, class A2>
int call(PyObject* obj, int (type_object_base::*f)(PyObject*, A1, A2) const, A1 a1, A2 a2)
{
return int_call<int>(obj, bind(f, _1, _2, a1, a2));
try
{
return (static_cast<type_object_base*>(obj->ob_type)->*f)(obj, a1, a2);
}
catch(...)
{
handle_exception();
return -1;
}
}
template <class A1, class A2, class A3>
int call(PyObject* obj, int (type_object_base::*f)(PyObject*, A1, A2, A3) const, A1 a1, A2 a2, A3 a3)
{
return int_call<int>(obj, bind(f, _1, _2, a1, a2, a3));
try
{
return (static_cast<type_object_base*>(obj->ob_type)->*f)(obj, a1, a2, a3);
}
catch(...)
{
handle_exception();
return -1;
}
}
int call_length_function(PyObject* obj, int (type_object_base::*f)(PyObject*) const)
{
value_holder<int> const r(int_call_holder<int>(obj, bind(f, _1, _2)));
if (!r.is_set)
try
{
const int outcome =
(static_cast<type_object_base*>(obj->ob_type)->*f)(obj);
if (outcome < 0)
{
PyErr_SetString(PyExc_ValueError, "__len__() should return >= 0");
return -1;
}
return outcome;
}
catch(...)
{
handle_exception();
return -1;
}
const int outcome = r.value;
if (outcome >= 0)
return outcome;
PyErr_SetString(PyExc_ValueError, "__len__() should return >= 0");
return -1;
}
} // anonymous namespace
namespace detail {
// needed by void_adaptor (see void_adaptor.hpp)
PyObject arbitrary_object;
}
} // anonymous namespace
extern "C" {
//
// These functions actually go into the type object's slots, and dispatch to the
// "call" wrappers defined above.
//
static PyObject* do_instance_repr(PyObject* obj)
{
return call(obj, &type_object_base::instance_repr);
@@ -235,7 +193,7 @@ static PyObject* do_instance_str(PyObject* obj)
static long do_instance_hash(PyObject* obj)
{
return int_call<long>(obj, bind(&type_object_base::instance_hash, _1, _2));
return int_call(obj, &type_object_base::instance_hash);
}
static PyObject* do_instance_call(PyObject* obj, PyObject* args, PyObject* keywords)
@@ -245,16 +203,15 @@ static PyObject* do_instance_call(PyObject* obj, PyObject* args, PyObject* keywo
static void do_instance_dealloc(PyObject* obj)
{
PyObject* success = handle_exception(
// translate the void return value of instance_dealloc into a PyObject*
// that can indicate no error.
detail::make_void_adaptor(
bind(&type_object_base::instance_dealloc
, static_cast<type_object_base*>(obj->ob_type)
, obj)));
if (!success)
try
{
static_cast<type_object_base*>(obj->ob_type)
->instance_dealloc(obj);
}
catch(...)
{
assert(!"exception during destruction!");
handle_exception();
}
}
@@ -287,22 +244,28 @@ static PyObject* do_instance_mp_subscript(PyObject* obj, PyObject* index)
static PyObject* do_instance_sq_item(PyObject* obj, int index)
{
// This is an extension to standard class behavior. If sequence_length
// is implemented and n >= sequence_length(), raise an IndexError. That
// keeps users from having to worry about raising it themselves
const PyTypeObject* const type = obj->ob_type;
if (type->tp_as_sequence != 0 && type->tp_as_sequence->sq_length != 0
&& index >= type->tp_as_sequence->sq_length(obj))
try
{
PyErr_SetString(PyExc_IndexError, type->tp_name);
const PyTypeObject* const type = obj->ob_type;
// This is an extension to standard class behavior. If sequence_length
// is implemented and n >= sequence_length(), raise an IndexError. That
// keeps users from having to worry about raising it themselves
if (type->tp_as_sequence != 0 && type->tp_as_sequence->sq_length != 0
&& index >= type->tp_as_sequence->sq_length(obj))
{
PyErr_SetString(PyExc_IndexError, type->tp_name);
return 0;
}
return static_cast<type_object_base*>(obj->ob_type)
->instance_sequence_item(obj, index);
}
catch(...)
{
handle_exception();
return 0;
}
return handle_exception(
bind(&type_object_base::instance_sequence_item
, static_cast<type_object_base*>(obj->ob_type)
, obj
, index));
}
static int do_instance_mp_ass_subscript(PyObject* obj, PyObject* index, PyObject* value)
@@ -425,10 +388,7 @@ static PyObject* do_instance_nb_or(PyObject* obj, PyObject* other)
static int do_instance_nb_coerce(PyObject**obj, PyObject**other)
{
// no call() overload for this oddball function, so we'll do it manually
return int_call<int>(
*obj, bind(
&type_object_base::instance_number_coerce, _1, _2, obj, other));
return call(*obj, &type_object_base::instance_number_coerce, obj, other);
}
static PyObject* do_instance_nb_int(PyObject* obj)
{
@@ -1202,3 +1162,4 @@ int main()
}
#endif

View File

@@ -157,7 +157,7 @@ int IntPairPythonClass::getattr(const IntPair& p, const std::string& s)
PyErr_SetString(PyExc_AttributeError, s.c_str());
throw boost::python::error_already_set();
}
#if defined(__MWERKS__) && __MWERKS__ <= 0x2406
#if defined(__MWERKS__) && __MWERKS__ <= 0x2400
return 0;
#endif
}
@@ -1128,7 +1128,7 @@ PyObject* raw(const boost::python::tuple& args, const boost::python::dictionary&
return BOOST_PYTHON_CONVERSION::to_python(first->i_ + second + third + fourth);
}
BOOST_PYTHON_MODULE_INIT(boost_python_test)
void init_module()
{
boost::python::module_builder boost_python_test("boost_python_test");
init_module(boost_python_test);
@@ -1137,6 +1137,16 @@ BOOST_PYTHON_MODULE_INIT(boost_python_test)
boost_python_test.add(new boost::python::meta_class<boost::python::instance>);
}
BOOST_PYTHON_MODULE_INIT(boost_python_test)
{
try {
bpl_test::init_module();
}
catch(...) {
boost::python::handle_exception();
} // Need a way to report other errors here
}
CompareIntPairPythonClass::CompareIntPairPythonClass(boost::python::module_builder& m)
: boost::python::class_builder<CompareIntPair>(m, "CompareIntPair")
{

View File

@@ -8,11 +8,14 @@ r'''
// producing this work.
// Revision History:
// 2001 Nov 01 Python 2.2 pickle problems fixed (rwgk)
// 04 Mar 01 Changed name of extension module so it would work with DebugPython,
// fixed exception message checking to work with Python 2.0
// (Dave Abrahams)
Load up the extension module
>>> from boost_python_test import *
Automatic checking of the number and type of arguments. Foo's constructor takes
a single long parameter.
@@ -271,12 +274,19 @@ Pickle safety measures:
... except RuntimeError, err: print err[0]
...
Incomplete pickle support (__dict_defines_state__ not set)
>>> class myrational(Rational):
... __dict_defines_state__ = 1 # this is a lie but good enough for testing.
...
>>> r=myrational(3, 4)
>>> r
Rational(3, 4)
>>> s=pickle.dumps(r)
>>> u=pickle.loads(s)
>>> class myworld(world):
... def __init__(self):
... world.__init__(self, 'anywhere')
... self.x = 1
...
>>> w = myworld()
>>> w.greet()
'Hello from anywhere!'
@@ -287,6 +297,9 @@ Pickle safety measures:
...
Incomplete pickle support (__getstate_manages_dict__ not set)
>>> class myunsafeworld(myworld):
... __getstate_manages_dict__ = 1 # this is a lie but good enough for testing.
...
>>> w = myunsafeworld()
>>> w.greet()
'Hello from anywhere!'
@@ -1178,23 +1191,6 @@ test methodologies for wrapping functions that return a pointer
'''
#'
from boost_python_test import *
# pickle requires these derived classes to be
# at the global scope of the module
class myrational(Rational):
__dict_defines_state__ = 1 # this is a lie but good enough for testing.
class myworld(world):
def __init__(self):
world.__init__(self, 'anywhere')
self.x = 1
class myunsafeworld(myworld):
__getstate_manages_dict__ = 1 # this is a lie but good enough for testing.
def assert_integer_expected(err):
"""Handle a common error report which appears differently in Python 1.5.x and 2.0"""
assert isinstance(err, TypeError)