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

Compare commits

..

2 Commits

Author SHA1 Message Date
nobody
e32901304d This commit was manufactured by cvs2svn to create tag
'Version_1_22_0'.

[SVN r10239]
2001-05-28 15:01:00 +00:00
Dave Abrahams
9b602d16b4 initial import
[SVN r8327]
2000-11-26 15:49:26 +00:00
79 changed files with 540 additions and 2302 deletions

View File

@@ -1,318 +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.
#
# 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
# 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:
#
# from ../test
#
# comprehensive - a comprehensive test of Boost.Python features
#
# from ../example:
# abstract -
# getting_started1 -
# getting_started2 -
# simple_vector -
# do_it_yourself_convts -
# pickle1 -
# pickle2 -
# pickle3 -
#
# dvect1 -
# dvect2 -
# ivect1 -
# ivect2 -
# noncopyable -
#
# 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.
#
# PYTHON_VECT_ITERATIONS - specifies the number of test iterations to use for
# the dvect and ivect tests above.
# 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 ;
# 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
;
}
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 ;
}
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) ;
#######################
#
# Declare the boost python static link library
#
# standard include requirements for anything using Boost.Python
local 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 ;
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
;
#######################
# boost-python name : sources : requirements : default-BUILD
#
# 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) $(>)
# Requirements
: $(3) # caller-specified requirements
# 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
#
# declare two python module tests: $(<).test which builds when out-of-date, and
# $(<).run which builds unconditionally.
rule boost-python-runtest
{
# tell Jam that the python script is relative to this directory
SEARCH on $(>[1]) = $(SEARCH_SOURCE) ;
# 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 ;
}
# 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.
SUFPYTHON_TEST = .test ;
gGENERATOR_FUNCTION(PYTHON_TEST) = python-test-target ;
rule python-test-target # test-target : sources :
{
python-runtest-aux $(<) : $(>) ;
Clean clean : $(<) ; # remove the test-target as part of any clean operation
local debug = [ SUBST $(<:B) (_d)$ $1 ] ;
debug ?= "" ;
type-DEPENDS test$(debug) : $(<) ;
MakeLocate $(<) : $(LOCATE_TARGET) ;
}
actions python-test-target bind PYTHON
{
$(SHELL_SET)PYTHONPATH=$(PYTHONPATH)
$(SHELL_EXPORT)PYTHONPATH
$(PYTHON) "$(>)" $(ARGS) > "$(<)"
}
SUFPYTHON_RUNTEST = .run ;
gGENERATOR_FUNCTION(PYTHON_RUNTEST) = python-runtest-target ;
rule python-runtest-target # test-target : sources :
{
python-runtest-aux $(<) : $(>) ;
NOTFILE $(<) ;
ALWAYS $(<) ;
}
actions python-runtest-target bind PYTHON
{
$(SHELL_SET)PYTHONPATH=$(PYTHONPATH)
$(SHELL_EXPORT)PYTHONPATH
$(PYTHON) "$(>)" $(ARGS)
}
rule python-runtest-aux # target : sources
{
DEPENDS $(<) : $(>) ;
ARGS on $(<) += $(gPYTHON_TEST_ARGS) ;
# Some tests need an extra command-line arg if built with
# msvc. Checking the target grist is a cheap way to
# find out.
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
# find all of the modules on which it depends.
PYTHONPATH on $(<) = [ join
$(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 ;
############# simple tests from ../example ############
rule boost-python-example-runtest
{
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-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-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 ;
############## 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
{
boost-python-runtest $(<)
: ../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-runtest ivect1 : ivect dvect ;
boost-python-multi-example-runtest ivect2 : ivect dvect ;
boost-python-multi-example-runtest
noncopyable : noncopyable_import noncopyable_export ;

View File

@@ -23,8 +23,7 @@ bpl_exa + "/abstract.cpp",
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 + "/do_it_yourself_converters.cpp",
bpl_exa + "/pickle1.cpp",
bpl_exa + "/pickle2.cpp",
bpl_exa + "/pickle3.cpp",
@@ -32,8 +31,7 @@ bpl_exa + "/test_abstract.py",
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_do_it_yourself_converters.py",
bpl_exa + "/test_pickle1.py",
bpl_exa + "/test_pickle2.py",
bpl_exa + "/test_pickle3.py",
@@ -54,13 +52,6 @@ bpl_exa + "/tst_dvect2.py",
bpl_exa + "/tst_ivect1.py",
bpl_exa + "/tst_ivect2.py",
bpl_exa + "/test_cross_module.py",
bpl_exa + "/vector_wrapper.h",
bpl_exa + "/richcmp1.cpp",
bpl_exa + "/richcmp2.cpp",
bpl_exa + "/richcmp3.cpp",
bpl_exa + "/test_richcmp1.py",
bpl_exa + "/test_richcmp2.py",
bpl_exa + "/test_richcmp3.py",
)
defs = (
@@ -69,8 +60,7 @@ defs = (
"getting_started1",
"getting_started2",
"simple_vector",
"do_it_yourself_convts",
"nested",
"do_it_yourself_converters",
"pickle1",
"pickle2",
"pickle3",
@@ -78,9 +68,6 @@ defs = (
"noncopyable_import",
"ivect",
"dvect",
"richcmp1",
"richcmp2",
"richcmp3",
)
if (__name__ == "__main__"):

View File

@@ -17,10 +17,10 @@
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
#PYINC=-I/usr/local/Python-2.1/include/python2.1
#PYEXE=/usr/local/Python-2.0/bin/python
#PYINC=-I/usr/local/Python-2.0/include/python2.0
STLPORTINC=-I$(BOOST)/boost/compatibility/cpp_c_headers
STDOPTS=
@@ -43,12 +43,10 @@ DEPOBJ=$(OBJ) \
abstract.o \
getting_started1.o getting_started2.o \
simple_vector.o \
do_it_yourself_convts.o \
nested.o \
do_it_yourself_converters.o \
pickle1.o pickle2.o pickle3.o \
noncopyable_export.o noncopyable_import.o \
ivect.o dvect.o \
richcmp1.o richcmp2.o richcmp3.o
ivect.o dvect.o
.SUFFIXES: .o .cpp
@@ -57,12 +55,10 @@ all: libboost_python.a \
abstract.so \
getting_started1.so getting_started2.so \
simple_vector.so \
do_it_yourself_convts.so \
nested.so \
do_it_yourself_converters.so \
pickle1.so pickle2.so pickle3.so \
noncopyable_export.so noncopyable_import.so \
ivect.so dvect.so \
richcmp1.so richcmp2.so richcmp3.so
ivect.so dvect.so
libboost_python.a: $(OBJ)
rm -f libboost_python.a
@@ -83,11 +79,8 @@ getting_started2.so: $(OBJ) getting_started2.o
simple_vector.so: $(OBJ) simple_vector.o
$(LD) $(LDOPTS) $(OBJ) simple_vector.o -o simple_vector.so
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
do_it_yourself_converters.so: $(OBJ) do_it_yourself_converters.o
$(LD) $(LDOPTS) $(OBJ) do_it_yourself_converters.o -o do_it_yourself_converters.so
pickle1.so: $(OBJ) pickle1.o
$(LD) $(LDOPTS) $(OBJ) pickle1.o -o pickle1.so
@@ -112,15 +105,6 @@ ivect.so: $(OBJ) ivect.o
dvect.so: $(OBJ) dvect.o
$(LD) $(LDOPTS) $(OBJ) $(HIDDEN) dvect.o -o dvect.so
richcmp1.so: $(OBJ) richcmp1.o
$(LD) $(LDOPTS) $(OBJ) richcmp1.o -o richcmp1.so
richcmp2.so: $(OBJ) richcmp2.o
$(LD) $(LDOPTS) $(OBJ) richcmp2.o -o richcmp2.so
richcmp3.so: $(OBJ) richcmp3.o
$(LD) $(LDOPTS) $(OBJ) richcmp3.o -o richcmp3.so
.cpp.o:
$(CPP) $(CPPOPTS) -c $*.cpp
@@ -130,15 +114,11 @@ test:
$(PYEXE) test_getting_started1.py
$(PYEXE) test_getting_started2.py
$(PYEXE) test_simple_vector.py
$(PYEXE) test_do_it_yourself_convts.py
$(PYEXE) test_nested.py
$(PYEXE) test_do_it_yourself_converters.py
$(PYEXE) test_pickle1.py
$(PYEXE) test_pickle2.py
$(PYEXE) test_pickle3.py
$(PYEXE) test_cross_module.py
$(PYEXE) test_richcmp1.py
$(PYEXE) test_richcmp2.py
$(PYEXE) test_richcmp3.py
clean:
rm -f $(OBJ) libboost_python.a libboost_python.a.input
@@ -147,8 +127,7 @@ clean:
rm -f getting_started1.o getting_started1.so
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 do_it_yourself_converters.o do_it_yourself_converters.so
rm -f pickle1.o pickle1.so
rm -f pickle2.o pickle2.so
rm -f pickle3.o pickle3.so
@@ -156,9 +135,6 @@ clean:
rm -f noncopyable_import.o noncopyable_import.so
rm -f ivect.o ivect.so
rm -f dvect.o dvect.so
rm -f richcmp1.o richcmp1.so
rm -f richcmp2.o richcmp2.so
rm -f richcmp3.o richcmp3.so
rm -f so_locations *.pyc
rm -rf ii_files

View File

@@ -17,14 +17,14 @@
ROOT=$(HOME)
BOOST=$(ROOT)/boost
PYEXE=PYTHONPATH=. /usr/bin/python
PYEXE=/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
#PYINC=-I/usr/local/Python-2.1/include/python2.1
#PYEXE=/usr/local/Python-2.0/bin/python
#PYINC=-I/usr/local/Python-2.0/include/python2.0
STDOPTS=-fPIC -ftemplate-depth-21
STDOPTS=-ftemplate-depth-21
WARNOPTS=
OPTOPTS=-g
@@ -33,7 +33,7 @@ CPPOPTS=$(STLPORTINC) $(STLPORTOPTS) -I$(BOOST) $(PYINC) \
$(STDOPTS) $(WARNOPTS) $(OPTOPTS)
MAKEDEP=-M
LD=$(CPP)
LD=g++
LDOPTS=-shared
OBJ=classes.o conversions.o extension_class.o functions.o \
@@ -44,12 +44,10 @@ DEPOBJ=$(OBJ) \
abstract.o \
getting_started1.o getting_started2.o \
simple_vector.o \
do_it_yourself_convts.o \
nested.o \
do_it_yourself_converters.o \
pickle1.o pickle2.o pickle3.o \
noncopyable_export.o noncopyable_import.o \
ivect.o dvect.o \
richcmp1.o richcmp2.o richcmp3.o
ivect.o dvect.o
.SUFFIXES: .o .cpp
@@ -58,12 +56,10 @@ all: libboost_python.a \
abstract.so \
getting_started1.so getting_started2.so \
simple_vector.so \
do_it_yourself_convts.so \
nested.so \
do_it_yourself_converters.so \
pickle1.so pickle2.so pickle3.so \
noncopyable_export.so noncopyable_import.so \
ivect.so dvect.so \
richcmp1.so richcmp2.so richcmp3.so
ivect.so dvect.so
libboost_python.a: $(OBJ)
rm -f libboost_python.a
@@ -84,11 +80,8 @@ getting_started2.so: $(OBJ) getting_started2.o
simple_vector.so: $(OBJ) simple_vector.o
$(LD) $(LDOPTS) $(OBJ) simple_vector.o -o simple_vector.so
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
do_it_yourself_converters.so: $(OBJ) do_it_yourself_converters.o
$(LD) $(LDOPTS) $(OBJ) do_it_yourself_converters.o -o do_it_yourself_converters.so
pickle1.so: $(OBJ) pickle1.o
$(LD) $(LDOPTS) $(OBJ) pickle1.o -o pickle1.so
@@ -113,15 +106,6 @@ ivect.so: $(OBJ) ivect.o
dvect.so: $(OBJ) dvect.o
$(LD) $(LDOPTS) $(OBJ) $(HIDDEN) dvect.o -o dvect.so
richcmp1.so: $(OBJ) richcmp1.o
$(LD) $(LDOPTS) $(OBJ) richcmp1.o -o richcmp1.so
richcmp2.so: $(OBJ) richcmp2.o
$(LD) $(LDOPTS) $(OBJ) richcmp2.o -o richcmp2.so
richcmp3.so: $(OBJ) richcmp3.o
$(LD) $(LDOPTS) $(OBJ) richcmp3.o -o richcmp3.so
.cpp.o:
$(CPP) $(CPPOPTS) -c $*.cpp
@@ -131,15 +115,11 @@ test:
$(PYEXE) test_getting_started1.py
$(PYEXE) test_getting_started2.py
$(PYEXE) test_simple_vector.py
$(PYEXE) test_do_it_yourself_convts.py
$(PYEXE) test_nested.py
$(PYEXE) test_do_it_yourself_converters.py
$(PYEXE) test_pickle1.py
$(PYEXE) test_pickle2.py
$(PYEXE) test_pickle3.py
$(PYEXE) test_cross_module.py
$(PYEXE) test_richcmp1.py
$(PYEXE) test_richcmp2.py
$(PYEXE) test_richcmp3.py
clean:
rm -f $(OBJ) libboost_python.a libboost_python.a.input
@@ -148,8 +128,7 @@ clean:
rm -f getting_started1.o getting_started1.so
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 do_it_yourself_converters.o do_it_yourself_converters.so
rm -f pickle1.o pickle1.so
rm -f pickle2.o pickle2.so
rm -f pickle3.o pickle3.so
@@ -157,9 +136,6 @@ clean:
rm -f noncopyable_import.o noncopyable_import.so
rm -f ivect.o ivect.so
rm -f dvect.o dvect.so
rm -f richcmp1.o richcmp1.so
rm -f richcmp2.o richcmp2.so
rm -f richcmp3.o richcmp3.so
rm -f so_locations *.pyc
softlinks:

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=
@@ -62,15 +59,13 @@ all: libboost_python.a \
abstract.pyd \
getting_started1.pyd getting_started2.pyd \
simple_vector.pyd \
do_it_yourself_convts.pyd \
nested.pyd \
do_it_yourself_converters.pyd \
pickle1.pyd pickle2.pyd pickle3.pyd \
noncopyable_export.pyd noncopyable_import.pyd \
ivect.pyd dvect.pyd \
richcmp1.pyd richcmp2.pyd richcmp3.pyd
ivect.pyd dvect.pyd
libboost_python.a: $(OBJ)
-del libboost_python.a
del libboost_python.a
ar r libboost_python.a $(OBJ)
DLLWRAPOPTS=-s --driver-name g++ -s \
@@ -106,17 +101,11 @@ simple_vector.pyd: $(OBJ) simple_vector.o
--def simple_vector.def \
$(OBJ) simple_vector.o $(PYLIB)
do_it_yourself_convts.pyd: $(OBJ) do_it_yourself_convts.o
do_it_yourself_converters.pyd: $(OBJ) do_it_yourself_converters.o
dllwrap $(DLLWRAPOPTS) \
--dllname do_it_yourself_convts.pyd \
--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)
--dllname do_it_yourself_converters.pyd \
--def do_it_yourself_converters.def \
$(OBJ) do_it_yourself_converters.o $(PYLIB)
pickle1.pyd: $(OBJ) pickle1.o
dllwrap $(DLLWRAPOPTS) \
@@ -160,24 +149,6 @@ dvect.pyd: $(OBJ) dvect.o
--def dvect.def \
$(OBJ) dvect.o $(PYLIB)
richcmp1.pyd: $(OBJ) richcmp1.o
dllwrap $(DLLWRAPOPTS) \
--dllname richcmp1.pyd \
--def richcmp1.def \
$(OBJ) richcmp1.o $(PYLIB)
richcmp2.pyd: $(OBJ) richcmp2.o
dllwrap $(DLLWRAPOPTS) \
--dllname richcmp2.pyd \
--def richcmp2.def \
$(OBJ) richcmp2.o $(PYLIB)
richcmp3.pyd: $(OBJ) richcmp3.o
dllwrap $(DLLWRAPOPTS) \
--dllname richcmp3.pyd \
--def richcmp3.def \
$(OBJ) richcmp3.o $(PYLIB)
.cpp.o:
$(CPP) $(CPPOPTS) -c $*.cpp
@@ -187,21 +158,17 @@ test:
$(PYEXE) test_getting_started1.py
$(PYEXE) test_getting_started2.py
$(PYEXE) test_simple_vector.py
$(PYEXE) test_do_it_yourself_convts.py
$(PYEXE) test_nested.py
$(PYEXE) test_do_it_yourself_converters.py
$(PYEXE) test_pickle1.py
$(PYEXE) test_pickle2.py
$(PYEXE) test_pickle3.py
$(PYEXE) test_cross_module.py
$(PYEXE) test_richcmp1.py
$(PYEXE) test_richcmp2.py
$(PYEXE) test_richcmp3.py
clean:
-del *.o
-del *.a
-del *.pyd
-del *.pyc
del *.o
del *.a
del *.pyd
del *.pyc
softlinks:
python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) softlinks

View File

@@ -17,10 +17,10 @@
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
#PYINC=-I/usr/local/Python-2.1/include/python2.1
#PYEXE=/usr/local/Python-2.0/bin/python
#PYINC=-I/usr/local/Python-2.0/include/python2.0
#STLPORTINC=-I/usr/local/STLport-4.1b3/stlport
#STLPORTINC=-I/usr/local/STLport-4.1b4/stlport
#STLPORTOPTS= \
@@ -54,12 +54,10 @@ DEPOBJ=$(OBJ) \
abstract.o \
getting_started1.o getting_started2.o \
simple_vector.o \
do_it_yourself_convts.o \
nested.o \
do_it_yourself_converters.o \
pickle1.o pickle2.o pickle3.o \
noncopyable_export.o noncopyable_import.o \
ivect.o dvect.o \
richcmp1.o richcmp2.o richcmp3.o
ivect.o dvect.o
.SUFFIXES: .o .cpp
@@ -68,12 +66,10 @@ all: libboost_python.a \
abstract.so \
getting_started1.so getting_started2.so \
simple_vector.so \
do_it_yourself_convts.so \
nested.so \
do_it_yourself_converters.so \
pickle1.so pickle2.so pickle3.so \
noncopyable_export.so noncopyable_import.so \
ivect.so dvect.so \
richcmp1.so richcmp2.so richcmp3.so
ivect.so dvect.so
libboost_python.a: $(OBJ)
rm -f libboost_python.a
@@ -98,11 +94,8 @@ getting_started2.so: $(OBJ) getting_started2.o
simple_vector.so: $(OBJ) simple_vector.o
$(LD) $(LDOPTS) $(OBJ) simple_vector.o -o simple_vector.so
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
do_it_yourself_converters.so: $(OBJ) do_it_yourself_converters.o
$(LD) $(LDOPTS) $(OBJ) do_it_yourself_converters.o -o do_it_yourself_converters.so
pickle1.so: $(OBJ) pickle1.o
$(LD) $(LDOPTS) $(OBJ) pickle1.o -o pickle1.so
@@ -127,15 +120,6 @@ ivect.so: $(OBJ) ivect.o
dvect.so: $(OBJ) dvect.o
$(LD) $(LDOPTS) $(OBJ) $(HIDDEN) dvect.o -o dvect.so
richcmp1.so: $(OBJ) richcmp1.o
$(LD) $(LDOPTS) $(OBJ) richcmp1.o -o richcmp1.so
richcmp2.so: $(OBJ) richcmp2.o
$(LD) $(LDOPTS) $(OBJ) richcmp2.o -o richcmp2.so
richcmp3.so: $(OBJ) richcmp3.o
$(LD) $(LDOPTS) $(OBJ) richcmp3.o -o richcmp3.so
.cpp.o:
$(CPP) $(CPPOPTS) -c $*.cpp
@@ -145,15 +129,11 @@ test:
$(PYEXE) test_getting_started1.py
$(PYEXE) test_getting_started2.py
$(PYEXE) test_simple_vector.py
$(PYEXE) test_do_it_yourself_convts.py
$(PYEXE) test_nested.py
$(PYEXE) test_do_it_yourself_converters.py
$(PYEXE) test_pickle1.py
$(PYEXE) test_pickle2.py
$(PYEXE) test_pickle3.py
$(PYEXE) test_cross_module.py
$(PYEXE) test_richcmp1.py
$(PYEXE) test_richcmp2.py
$(PYEXE) test_richcmp3.py
clean:
rm -f $(OBJ) libboost_python.a libboost_python.a.input
@@ -162,8 +142,7 @@ clean:
rm -f getting_started1.o getting_started1.so
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 do_it_yourself_converters.o do_it_yourself_converters.so
rm -f pickle1.o pickle1.so
rm -f pickle2.o pickle2.so
rm -f pickle3.o pickle3.so
@@ -171,9 +150,6 @@ clean:
rm -f noncopyable_import.o noncopyable_import.so
rm -f ivect.o ivect.so
rm -f dvect.o dvect.so
rm -f richcmp1.o richcmp1.so
rm -f richcmp2.o richcmp2.so
rm -f richcmp3.o richcmp3.so
rm -f so_locations *.pyc
rm -rf cxx_repository

View File

@@ -10,16 +10,13 @@
# 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
PYEXE="C:\Program files\Python\python.exe"
PYINC=/I"C:\Program files\Python\include"
PYLIB="C:\Program files\Python\libs\python15.lib"
#PYEXE="C:\Python21\python.exe"
#PYINC=/I"C:\Python21\include"
#PYLIB="C:\Python21\libs\python21.lib"
STDOPTS=/nologo /MD /GR /GX /Zm200
WARNOPTS=
@@ -43,12 +40,10 @@ all: boost_python.lib \
abstract.pyd \
getting_started1.pyd getting_started2.pyd \
simple_vector.pyd \
do_it_yourself_convts.pyd \
nested.pyd \
do_it_yourself_converters.pyd \
pickle1.pyd pickle2.pyd pickle3.pyd \
noncopyable_export.pyd noncopyable_import.pyd \
ivect.pyd dvect.pyd \
richcmp1.pyd richcmp2.pyd richcmp3.pyd
ivect.pyd dvect.pyd
boost_python.lib: $(OBJ)
$(LD) -lib /nologo /out:boost_python.lib $(OBJ)
@@ -68,11 +63,8 @@ getting_started2.pyd: $(OBJ) getting_started2.obj
simple_vector.pyd: $(OBJ) simple_vector.obj
$(LD) $(LDOPTS) $(OBJ) simple_vector.obj $(PYLIB) /export:initsimple_vector /out:"simple_vector.pyd"
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"
do_it_yourself_converters.pyd: $(OBJ) do_it_yourself_converters.obj
$(LD) $(LDOPTS) $(OBJ) do_it_yourself_converters.obj $(PYLIB) /export:initdo_it_yourself_converters /out:"do_it_yourself_converters.pyd"
pickle1.pyd: $(OBJ) pickle1.obj
$(LD) $(LDOPTS) $(OBJ) pickle1.obj $(PYLIB) /export:initpickle1 /out:"pickle1.pyd"
@@ -95,15 +87,6 @@ ivect.pyd: $(OBJ) ivect.obj
dvect.pyd: $(OBJ) dvect.obj
$(LD) $(LDOPTS) $(OBJ) dvect.obj $(PYLIB) /export:initdvect /out:"dvect.pyd"
richcmp1.pyd: $(OBJ) richcmp1.obj
$(LD) $(LDOPTS) $(OBJ) richcmp1.obj $(PYLIB) /export:initrichcmp1 /out:"richcmp1.pyd"
richcmp2.pyd: $(OBJ) richcmp2.obj
$(LD) $(LDOPTS) $(OBJ) richcmp2.obj $(PYLIB) /export:initrichcmp2 /out:"richcmp2.pyd"
richcmp3.pyd: $(OBJ) richcmp3.obj
$(LD) $(LDOPTS) $(OBJ) richcmp3.obj $(PYLIB) /export:initrichcmp3 /out:"richcmp3.pyd"
.cpp.obj:
$(CPP) $(CPPOPTS) /c $*.cpp
@@ -113,23 +96,19 @@ test:
$(PYEXE) test_getting_started1.py
$(PYEXE) test_getting_started2.py
$(PYEXE) test_simple_vector.py
$(PYEXE) test_do_it_yourself_convts.py
$(PYEXE) test_nested.py
$(PYEXE) test_do_it_yourself_converters.py
$(PYEXE) test_pickle1.py
$(PYEXE) test_pickle2.py
$(PYEXE) test_pickle3.py
$(PYEXE) test_cross_module.py --broken-auto-ptr
$(PYEXE) test_richcmp1.py
$(PYEXE) test_richcmp2.py
$(PYEXE) test_richcmp3.py
clean:
-del *.obj
-del *.lib
-del *.exp
-del *.idb
-del *.pyd
-del *.pyc
del *.obj
del *.lib
del *.exp
del *.idb
del *.pyd
del *.pyc
softlinks:
python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) softlinks

View File

@@ -112,10 +112,10 @@ that.''<br><i>-<a href="mailto:dubois1@llnl.gov">Paul Dubois</a></i>
<h2>ILU</h2>
<p>
<a
href="ftp://ftp.parc.xerox.com/pub/ilu/ilu.html">ILU</a>
href="http://www.cl.cam.ac.uk/Research/Rainbow/projects/origami/ilu-1.8-manual">ILU</a>
is a very ambitious project which tries to describe a module's interface
(types and functions) in terms of an <a
href="ftp://ftp.parc.xerox.com/pub/ilu/2.0b1/manual-html/manual_2.html">Interface
href="http://www.cl.cam.ac.uk/Research/Rainbow/projects/origami/ilu-1.8-manual/manual_2.html">Interface
Specification Language</a> (ISL) so that it can be uniformly interfaced
to a wide range of computer languages, including Common Lisp, C++, C,
Modula-3, and Python. ILU can parse the ISL to generate a C++ language

View File

@@ -91,8 +91,8 @@ initialization. These bind the corresponding enum values to the appropriate
names so they can be used from Python:
<blockquote><pre>
mymodule.add(boost::python::make_ref(enum_value_1), "enum_value_1");
mymodule.add(boost::python::make_ref(enum_value_2), "enum_value_2");
mymodule.add(boost::python::to_python(enum_value_1), "enum_value_1");
mymodule.add(boost::python::to_python(enum_value_2), "enum_value_2");
...
</pre></blockquote>

View File

@@ -85,7 +85,7 @@ code before the last Python reference to it disappears:
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround
PyObject* to_python(Foo* p)
{
return boost::python::python_extension_class_converters&lt;Foo&gt;::smart_ptr_to_python(p);
return boost::python::python_extension_class_converters&ltFoo&gt::ptr_to_python(p);
}
PyObject* to_python(const Foo* p)

View File

@@ -1,106 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<title>Rich Comparisons</title>
<div>
<img src="../../../c++boost.gif"
alt="c++boost.gif (8819 bytes)"
align="center"
width="277" height="86">
<hr>
<h1>Rich Comparisons</h1>
<hr>
In Python versions up to and including Python 2.0, support for
implementing comparisons on user-defined classes and extension types
was quite simple. Classes could implement a <tt>__cmp__</tt> method
that was given two instances of a class as arguments, and could only
return <tt>0</tt> if they were equal or <tt>+1</tt> or <tt>-1</tt> if
they were not. The method could not raise an exception or return
anything other than an integer value.
In Python 2.1, <b>Rich Comparisons</b> were added (see
<a href="http://python.sourceforge.net/peps/pep-0207.html">PEP 207</a>).
Python classes can now individually overload each of the &lt;, &lt;=,
&gt;, &gt;=, ==, and != operations.
<p>
For more detailed information, search for "rich comparison"
<a href="http://www.python.org/doc/current/ref/customization.html"
>here</a>.
<p>
Boost.Python supports both automatic overloading and manual overloading
of the Rich Comparison operators. The <b>compile-time</b> support is
independent of the Python version that is used when compiling
Boost.Python extension modules. That is, <tt>op_lt</tt> for example can
always be used, and the C++ <tt>operator&lt;</tt> will always be bound
to the Python method <tt>__lt__</tt>. However, the <b>run-time</b>
behavior will depend on the Python version.
<p>
With Python versions before 2.1, the Rich Comparison operators will not
be called by Python when any of the six comparison operators
(<tt>&lt;</tt>, <tt>&lt;=</tt>, <tt>==</tt>, <tt>!=</tt>,
<tt>&gt;</tt>, <tt>&gt;=</tt>) is used in an expression. The only way
to access the corresponding methods is to call them explicitly, e.g.
<tt>a.__lt__(b)</tt>. Only with Python versions 2.1 or higher will
expressions like <tt>a &lt; b</tt> work as expected.
<p>
To support Rich Comparisions, the Python C API was modified between
Python versions 2.0 and 2.1. A new slot was introduced in the
<tt>PyTypeObject</tt> structure: <tt>tp_richcompare</tt>. For backwards
compatibility, a flag (<tt>Py_TPFLAGS_HAVE_RICHCOMPARE</tt>) has to be
set to signal to the Python interpreter that Rich Comparisions are
supported by a particular type.
There is only one flag for all the six comparison operators.
When any of the six operators is wrapped automatically or
manually, Boost.Python will set this flag. Attempts to use comparison
operators at the Python level that are not defined at the C++ level
will then lead to an <tt>AttributeError</tt> when the Python 2.1
(or higher) interpreter tries, e.g., <tt>a.__lt__(b)</tt>. That
is, in general all six operators should be supplied. Automatically
wrapped operators and manually wrapped operators can be mixed. For
example:<pre>
boost::python::class_builder&lt;code&gt; py_code(this_module, "code");
py_code.def(boost::python::constructor&lt;&gt;());
py_code.def(boost::python::constructor&lt;int&gt;());
py_code.def(boost::python::operators&lt;( boost::python::op_eq
| boost::python::op_ne)&gt;());
py_code.def(NotImplemented, "__lt__");
py_code.def(NotImplemented, "__le__");
py_code.def(NotImplemented, "__gt__");
py_code.def(NotImplemented, "__ge__");
</pre>
<tt>NotImplemented</tt> is a simple free function that (currently) has
to be provided by the user. For example:<pre>
boost::python::ref
NotImplemented(const code&amp;, const code&amp;) {
return
boost::python::ref(Py_NotImplemented, boost::python::ref::increment_count);
}
</pre>
See also:
<ul>
<li><a href="../example/richcmp1.cpp"><tt>../example/richcmp1.cpp</tt></a>
<li><a href="../example/richcmp2.cpp"><tt>../example/richcmp2.cpp</tt></a>
<li><a href="../example/richcmp3.cpp"><tt>../example/richcmp3.cpp</tt></a>
</ul>
<hr>
&copy; Copyright Nicholas K. Sauter &amp; Ralf W. Grosse-Kunstleve 2001.
Permission to copy, use, modify, sell and distribute this document is
granted provided this copyright notice appears in all copies. This
document is provided "as is" without express or implied warranty, and
with no claim as to its suitability for any purpose.
<p>
Updated: July 2001
</div>

View File

@@ -60,27 +60,13 @@
<b><tt class='method'>__str__</tt></b>(<i>self</i>)
<dd>
Create a string representation which is suitable for printing.
<dt>
<b><tt class='method'>__lt__</tt></b>(<i>self, other</i>)
<dt>
<b><tt class='method'>__le__</tt></b>(<i>self, other</i>)
<dt>
<b><tt class='method'>__eq__</tt></b>(<i>self, other</i>)
<dt>
<b><tt class='method'>__ne__</tt></b>(<i>self, other</i>)
<dt>
<b><tt class='method'>__gt__</tt></b>(<i>self, other</i>)
<dt>
<b><tt class='method'>__ge__</tt></b>(<i>self, other</i>)
<dd>
Rich Comparison methods.
New in Python 2.1.
See <a href="richcmp.html">Rich Comparisons</a>.
<dt>
<b><tt class='method'>__cmp__</tt></b>(<i>self, other</i>)
<dd>
Three-way compare function.
See <a href="richcmp.html">Rich Comparisons</a>.
Three-way compare function, used to implement comparison operators
(&lt; etc.) Should return a negative integer if <code> self < other
</code> , zero if <code> self == other </code> , a positive integer if
<code> self > other </code>.
<dt>
<b><tt class='method'>__hash__</tt></b>(<i>self</i>)
<dd>
@@ -558,42 +544,17 @@ Note that "__rrpow__" is an extension not present in plain Python.
<code>__cmp__, __rcmp__</code>
<td>
<code>cmp(left, right)</code><br>
<br>See <a href="richcmp.html">Rich Comparisons</a>.
<code>left &lt; right</code><br>
<code>left &lt;= right</code><br>
<code>left &gt; right</code><br>
<code>left &gt;= right</code><br>
<code>left == right</code><br>
<code>left != right</code>
<td>
<code>op_cmp</code>
<td>
<code>cpp_left &lt; cpp_right </code>
<br><code>cpp_right &lt; cpp_left</code>
<tr>
<td>
<code>__lt__</code>
<br><code>__le__</code>
<br><code>__eq__</code>
<br><code>__ne__</code>
<br><code>__gt__</code>
<br><code>__ge__</code>
<td>
<code>left &lt; right</code>
<br><code>left &lt;= right</code>
<br><code>left == right</code>
<br><code>left != right</code>
<br><code>left &gt; right</code>
<br><code>left &gt;= right</code>
<br>See <a href="richcmp.html">Rich Comparisons</a>
<td>
<code>op_lt</code>
<br><code>op_le</code>
<br><code>op_eq</code>
<br><code>op_ne</code>
<br><code>op_gt</code>
<br><code>op_ge</code>
<td>
<code>cpp_left &lt; cpp_right </code>
<br><code>cpp_left &lt;= cpp_right </code>
<br><code>cpp_left == cpp_right </code>
<br><code>cpp_left != cpp_right </code>
<br><code>cpp_left &gt; cpp_right </code>
<br><code>cpp_left &gt;= cpp_right </code>
<tr>
<td>

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=
"http://www.boost.org/libs/utility/operators.htm">the boost operators
library</a>.
<p>
Because the <code>to_python</code> and <code>from_python</code> functions

View File

@@ -10,7 +10,7 @@ See also: libs/python/doc/pickle.html
Other advanced concepts are introduced by:
abstract.cpp
simple_vector.cpp
do_it_yourself_convts.cpp
do_it_yourself_converters.cpp
Examples for the cross-module support are provided by:
noncopyable_export.cpp

View File

@@ -105,10 +105,12 @@ BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
BOOST_PYTHON_END_CONVERSION_NAMESPACE
BOOST_PYTHON_MODULE_INIT(do_it_yourself_convts)
BOOST_PYTHON_MODULE_INIT(do_it_yourself_converters)
{
try
{
// Create an object representing this extension module.
python::module_builder this_module("do_it_yourself_convts");
python::module_builder this_module("do_it_yourself_converters");
// Create the Python type object for our extension class.
python::class_builder<IndexingSet> ixset_class(this_module, "IndexingSet");
@@ -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

@@ -20,18 +20,10 @@ namespace {
}
}
# ifdef BOOST_MSVC // fixes for JIT debugging
# include <windows.h>
extern "C" void structured_exception_translator(unsigned int, EXCEPTION_POINTERS*)
{
throw;
}
extern "C" void (*old_translator)(unsigned int, EXCEPTION_POINTERS*)
= _set_se_translator(structured_exception_translator);
# endif
BOOST_PYTHON_MODULE_INIT(dvect)
{
try
{
python::module_builder this_module("dvect");
python::class_builder<vects::dvect> dvect_class(this_module, "dvect");
@@ -45,4 +37,9 @@ 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

@@ -20,18 +20,10 @@ namespace {
}
}
# ifdef BOOST_MSVC // fixes for JIT debugging
# include <windows.h>
extern "C" void structured_exception_translator(unsigned int, EXCEPTION_POINTERS*)
{
throw;
}
extern "C" void (*old_translator)(unsigned int, EXCEPTION_POINTERS*)
= _set_se_translator(structured_exception_translator);
# endif
BOOST_PYTHON_MODULE_INIT(ivect)
{
try
{
python::module_builder this_module("ivect");
python::class_builder<vects::ivect> ivect_class(this_module, "ivect");
@@ -45,5 +37,9 @@ 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

@@ -6,18 +6,10 @@ namespace python = boost::python;
#include "noncopyable.h"
# ifdef BOOST_MSVC // fixes for JIT debugging
# include <windows.h>
extern "C" void structured_exception_translator(unsigned int, EXCEPTION_POINTERS*)
{
throw;
}
extern "C" void (*old_translator)(unsigned int, EXCEPTION_POINTERS*)
= _set_se_translator(structured_exception_translator);
# endif
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 +17,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

@@ -19,18 +19,10 @@ namespace { // Avoid cluttering the global namespace.
}
}
# ifdef BOOST_MSVC // fixes for JIT debugging
# include <windows.h>
extern "C" void structured_exception_translator(unsigned int, EXCEPTION_POINTERS*)
{
throw;
}
extern "C" void (*old_translator)(unsigned int, EXCEPTION_POINTERS*)
= _set_se_translator(structured_exception_translator);
# endif
BOOST_PYTHON_MODULE_INIT(noncopyable_import)
{
try
{
python::module_builder this_module("noncopyable_import");
python::import_converters<store>
@@ -42,4 +34,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 {
@@ -99,7 +106,7 @@ namespace {
{
if(args.size() != 1 || keywords.size() != 0) {
PyErr_SetString(PyExc_TypeError, "wrong number of arguments");
throw boost::python::error_already_set();
throw boost::python::argument_error();
}
const world& w = from_python(args[0].get(), type<const world&>());
ref mydict = getattr(args[0], "__dict__");
@@ -115,7 +122,7 @@ namespace {
{
if(args.size() != 2 || keywords.size() != 0) {
PyErr_SetString(PyExc_TypeError, "wrong number of arguments");
throw boost::python::error_already_set();
throw boost::python::argument_error();
}
world& w = from_python(args[0].get(), type<world&>());
ref mydict = getattr(args[0], "__dict__");

View File

@@ -1,84 +0,0 @@
// Example by Ralf W. Grosse-Kunstleve & Nicholas K. Sauter
// This example shows how to use rich comparisons for a vector type.
// It also shows how to template the entire wrapping of a std::vector.
// See vector_wrapper.h.
#include <boost/python/class_builder.hpp>
#include "vector_wrapper.h"
namespace vects {
struct dvect : public std::vector<double>
{
dvect() : std::vector<double>() {}
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();
for (std::size_t i = 0; i < tuple.size(); i++)
v_it[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(),
boost::python::type<double>());
}
boost::python::tuple as_tuple() const
{
boost::python::tuple t(size());
for (std::size_t i = 0; i < size(); i++)
t.set_item(i,
boost::python::ref(BOOST_PYTHON_CONVERSION::to_python((*this)[i])));
return t;
}
# define DVECT_BINARY_OPERATORS(oper) \
friend std::vector<bool> \
operator##oper(const dvect& lhs, const dvect& rhs) \
{ \
if (lhs.size() != rhs.size()) { \
PyErr_SetString(PyExc_ValueError, "vectors have different sizes"); \
throw boost::python::error_already_set(); \
} \
std::vector<bool> result(lhs.size()); \
for (std::size_t i=0; i<lhs.size(); i++) { \
result[i] = (lhs[i] ##oper rhs[i]); \
} \
return result; \
}
DVECT_BINARY_OPERATORS(<)
DVECT_BINARY_OPERATORS(<=)
DVECT_BINARY_OPERATORS(==)
DVECT_BINARY_OPERATORS(!=)
DVECT_BINARY_OPERATORS(>)
DVECT_BINARY_OPERATORS(>=)
# undef VECTOR_BINARY_OPERATORS
};
} // namespace <anonymous>
namespace {
void init_module(boost::python::module_builder& this_module)
{
(void) example::wrap_vector(this_module, "vector_of_bool", bool());
boost::python::class_builder<vects::dvect> py_dvect(this_module, "dvect");
py_dvect.def(boost::python::constructor<boost::python::tuple>());
py_dvect.def(&vects::dvect::as_tuple, "as_tuple");
const long
comp_operators = ( boost::python::op_lt | boost::python::op_le
| boost::python::op_eq | boost::python::op_ne
| boost::python::op_gt | boost::python::op_ge);
py_dvect.def(boost::python::operators<comp_operators>());
}
} // namespace <anonymous>
BOOST_PYTHON_MODULE_INIT(richcmp1)
{
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);
}

View File

@@ -1,62 +0,0 @@
// Example by Ralf W. Grosse-Kunstleve
// This example shows how to use rich comparisons for a type that
// does not support all six operators (<, <=, ==, !=, >, >=).
// To keep the example simple, we are using a "code" type does
// not really require rich comparisons. __cmp__ would be sufficient.
// However, with a more complicated type the main point of this
// example would be in danger of getting lost.
#include <boost/python/class_builder.hpp>
namespace {
// suppose operator< and operator> are not meaningful for code
class code {
public:
code(int c = 0) : m_code(c) {}
inline friend bool operator==(const code& lhs, const code& rhs) {
return lhs.m_code == rhs.m_code;
}
inline friend bool operator!=(const code& lhs, const code& rhs) {
return lhs.m_code != rhs.m_code;
}
private:
int m_code;
};
#if PYTHON_API_VERSION >= 1010
boost::python::ref
NotImplemented(const code&, const code&) {
return
boost::python::ref(Py_NotImplemented, boost::python::ref::increment_count);
}
#endif
}
namespace {
void init_module(boost::python::module_builder& this_module)
{
boost::python::class_builder<code> py_code(this_module, "code");
py_code.def(boost::python::constructor<>());
py_code.def(boost::python::constructor<int>());
py_code.def(boost::python::operators<( boost::python::op_eq
| boost::python::op_ne)>());
#if PYTHON_API_VERSION >= 1010
py_code.def(NotImplemented, "__lt__");
py_code.def(NotImplemented, "__le__");
py_code.def(NotImplemented, "__gt__");
py_code.def(NotImplemented, "__ge__");
#endif
}
} // namespace <anonymous>
BOOST_PYTHON_MODULE_INIT(richcmp2)
{
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);
}

View File

@@ -1,175 +0,0 @@
// Example by Ralf W. Grosse-Kunstleve & Nicholas K. Sauter.
// Comprehensive operator overloading for two vector types and scalars.
#include <boost/python/class_builder.hpp>
#include "vector_wrapper.h"
#include "dvect.h"
#include "ivect.h"
#define VECT_VECT_OPERATORS(result_type, vect_type1, oper, vect_type2) \
namespace vects { \
result_type \
operator##oper (const vect_type1& lhs, const vect_type2& rhs) { \
if (lhs.size() != rhs.size()) { \
PyErr_SetString(PyExc_ValueError, "vectors have different sizes"); \
throw boost::python::error_already_set(); \
} \
result_type result(lhs.size()); \
for (std::size_t i=0; i<lhs.size(); i++) { \
result[i] = (lhs[i] ##oper rhs[i]); \
} \
return result; \
} \
}
#define VECT_SCALAR_OPERATORS(result_type, vect_type, oper, scalar_type) \
namespace vects { \
result_type \
operator##oper (const vect_type& lhs, const scalar_type& rhs) { \
result_type result(lhs.size()); \
for (std::size_t i=0; i<lhs.size(); i++) { \
result[i] = (lhs[i] ##oper rhs ); \
} \
return result; \
} \
}
#define SCALAR_VECT_OPERATORS(result_type, scalar_type, oper, vect_type) \
namespace vects { \
result_type \
operator##oper (const scalar_type& lhs, const vect_type& rhs) { \
result_type result(rhs.size()); \
for (std::size_t i=0; i<rhs.size(); i++) { \
result[i] = (lhs ##oper rhs[i]); \
} \
return result; \
} \
}
#define MATH_VECT_VECT_OPERATORS(result_type, vect_type1, vect_type2) \
VECT_VECT_OPERATORS(result_type, vect_type1, +, vect_type2) \
VECT_VECT_OPERATORS(result_type, vect_type1, -, vect_type2) \
VECT_VECT_OPERATORS(result_type, vect_type1, *, vect_type2) \
VECT_VECT_OPERATORS(result_type, vect_type1, /, vect_type2)
#define COMP_VECT_VECT_OPERATORS(vect_type1, vect_type2) \
VECT_VECT_OPERATORS(std::vector<bool>, vect_type1, <, vect_type2) \
VECT_VECT_OPERATORS(std::vector<bool>, vect_type1, <=, vect_type2) \
VECT_VECT_OPERATORS(std::vector<bool>, vect_type1, ==, vect_type2) \
VECT_VECT_OPERATORS(std::vector<bool>, vect_type1, !=, vect_type2) \
VECT_VECT_OPERATORS(std::vector<bool>, vect_type1, >, vect_type2) \
VECT_VECT_OPERATORS(std::vector<bool>, vect_type1, >=, vect_type2)
#define MATH_VECT_SCALAR_OPERATORS(result_type, vect_type, scalar_type) \
VECT_SCALAR_OPERATORS(result_type, vect_type, +, scalar_type) \
VECT_SCALAR_OPERATORS(result_type, vect_type, -, scalar_type) \
VECT_SCALAR_OPERATORS(result_type, vect_type, *, scalar_type) \
VECT_SCALAR_OPERATORS(result_type, vect_type, /, scalar_type)
#define COMP_VECT_SCALAR_OPERATORS(vect_type, scalar_type) \
VECT_SCALAR_OPERATORS(std::vector<bool>, vect_type, <, scalar_type) \
VECT_SCALAR_OPERATORS(std::vector<bool>, vect_type, <=, scalar_type) \
VECT_SCALAR_OPERATORS(std::vector<bool>, vect_type, ==, scalar_type) \
VECT_SCALAR_OPERATORS(std::vector<bool>, vect_type, !=, scalar_type) \
VECT_SCALAR_OPERATORS(std::vector<bool>, vect_type, >, scalar_type) \
VECT_SCALAR_OPERATORS(std::vector<bool>, vect_type, >=, scalar_type)
#define MATH_SCALAR_VECT_OPERATORS(result_type, scalar_type, vect_type) \
SCALAR_VECT_OPERATORS(result_type, scalar_type, +, vect_type) \
SCALAR_VECT_OPERATORS(result_type, scalar_type, -, vect_type) \
SCALAR_VECT_OPERATORS(result_type, scalar_type, *, vect_type) \
SCALAR_VECT_OPERATORS(result_type, scalar_type, /, vect_type)
MATH_VECT_VECT_OPERATORS(dvect, dvect, dvect)
COMP_VECT_VECT_OPERATORS( dvect, dvect)
MATH_VECT_SCALAR_OPERATORS(dvect, dvect, double)
COMP_VECT_SCALAR_OPERATORS( dvect, double)
MATH_SCALAR_VECT_OPERATORS(dvect, double, dvect)
// comparison operators not needed since Python uses reflection
MATH_VECT_VECT_OPERATORS(ivect, ivect, ivect)
COMP_VECT_VECT_OPERATORS( ivect, ivect)
MATH_VECT_SCALAR_OPERATORS(ivect, ivect, int)
COMP_VECT_SCALAR_OPERATORS( ivect, int)
MATH_SCALAR_VECT_OPERATORS(ivect, int, ivect)
// comparison operators not needed since Python uses reflection
MATH_VECT_VECT_OPERATORS(dvect, dvect, ivect)
COMP_VECT_VECT_OPERATORS( dvect, ivect)
MATH_VECT_VECT_OPERATORS(dvect, ivect, dvect)
COMP_VECT_VECT_OPERATORS( ivect, dvect)
#undef VECT_VECT_OPERATORS
#undef SCALAR_VECT_OPERATORS
#undef VECT_SCALAR_OPERATORS
#undef MATH_VECT_VECT_OPERATORS
#undef COMP_VECT_VECT_OPERATORS
#undef MATH_VECT_SCALAR_OPERATORS
#undef COMP_VECT_SCALAR_OPERATORS
#undef MATH_SCALAR_VECT_OPERATORS
namespace {
void init_module(boost::python::module_builder& this_module)
{
(void) example::wrap_vector(this_module, "vector_of_bool", bool());
const long
math_operators ( boost::python::op_mul | boost::python::op_add
| boost::python::op_div | boost::python::op_sub);
const long
comp_operators = ( boost::python::op_lt | boost::python::op_le
| boost::python::op_eq | boost::python::op_ne
| boost::python::op_gt | boost::python::op_ge);
boost::python::class_builder<vects::dvect>
dvect_class(this_module, "dvect");
boost::python::class_builder<vects::ivect>
ivect_class(this_module, "ivect");
dvect_class.def(boost::python::constructor<boost::python::tuple>());
dvect_class.def(&vects::dvect::as_tuple,"as_tuple");
dvect_class.def(boost::python::operators<math_operators>());
dvect_class.def(boost::python::operators<math_operators>(),
boost::python::right_operand<double>() );
dvect_class.def(boost::python::operators<math_operators>(),
boost::python::left_operand<double>() );
dvect_class.def(boost::python::operators<math_operators>(),
boost::python::right_operand<vects::ivect>() );
dvect_class.def(boost::python::operators<comp_operators>());
dvect_class.def(boost::python::operators<comp_operators>(),
boost::python::right_operand<double>() );
// left_operand not needed since Python uses reflection
dvect_class.def(boost::python::operators<comp_operators>(),
boost::python::right_operand<vects::ivect>() );
ivect_class.def(boost::python::constructor<boost::python::tuple>());
ivect_class.def(&vects::ivect::as_tuple,"as_tuple");
ivect_class.def(boost::python::operators<math_operators>());
ivect_class.def(boost::python::operators<math_operators>(),
boost::python::right_operand<int>() );
ivect_class.def(boost::python::operators<math_operators>(),
boost::python::left_operand<int>() );
ivect_class.def(boost::python::operators<math_operators>(),
boost::python::right_operand<vects::dvect>() );
ivect_class.def(boost::python::operators<comp_operators>());
ivect_class.def(boost::python::operators<comp_operators>(),
boost::python::right_operand<int>() );
// left_operand not needed since Python uses reflection
ivect_class.def(boost::python::operators<comp_operators>(),
boost::python::right_operand<vects::dvect>() );
}
} // namespace <anonymous>
BOOST_PYTHON_MODULE_INIT(richcmp3)
{
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);
}

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

@@ -49,7 +49,7 @@ namespace { // Avoid cluttering the global namespace.
void delitem(std::vector<double>& vd, std::size_t key) {
if (key >= vd.size()) raise_vector_IndexError();
std::vector<double>::iterator vditer = vd.begin();
vd.erase(vditer + key);
vd.erase(&vditer[key]);
}
// Convert vector_double to a regular Python tuple.
@@ -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

@@ -17,8 +17,7 @@ def run(args = None):
import sys
sys.argv = args
import doctest, test_abstract
return doctest.testmod(test_abstract)
doctest.testmod(test_abstract)
if __name__ == '__main__':
import sys
sys.exit(run()[0])
run()

View File

@@ -133,8 +133,7 @@ def run(args = None):
import sys
sys.argv = args
import doctest, test_cross_module
return doctest.testmod(test_cross_module)
doctest.testmod(test_cross_module)
if __name__ == '__main__':
import sys
sys.exit(run()[0])
run()

View File

@@ -1,5 +1,5 @@
r'''>>> import do_it_yourself_convts
>>> ixset = do_it_yourself_convts.IndexingSet()
r'''>>> import do_it_yourself_converters
>>> ixset = do_it_yourself_converters.IndexingSet()
>>> ixset.add((1,2,3))
>>> ixset.add((4,5,6))
>>> ixset.add((7,8,9))
@@ -15,9 +15,8 @@ def run(args = None):
if args is not None:
import sys
sys.argv = args
import doctest, test_do_it_yourself_convts
return doctest.testmod(test_do_it_yourself_convts)
import doctest, test_do_it_yourself_converters
doctest.testmod(test_do_it_yourself_converters)
if __name__ == '__main__':
import sys
sys.exit(run()[0])
run()

View File

@@ -44,8 +44,7 @@ def run(args = None):
import sys
sys.argv = args
import doctest, test_example1
return doctest.testmod(test_example1)
doctest.testmod(test_example1)
if __name__ == '__main__':
import sys
sys.exit(run()[0])
run()

View File

@@ -11,8 +11,7 @@ def run(args = None):
import sys
sys.argv = args
import doctest, test_getting_started1
return doctest.testmod(test_getting_started1)
doctest.testmod(test_getting_started1)
if __name__ == '__main__':
import sys
sys.exit(run()[0])
run()

View File

@@ -23,9 +23,7 @@ def run(args = None):
import sys
sys.argv = args
import doctest, test_getting_started2
return doctest.testmod(test_getting_started2)
doctest.testmod(test_getting_started2)
if __name__ == '__main__':
import sys
sys.exit(run()[0])
run()

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

@@ -25,9 +25,7 @@ def run(args = None):
import sys
sys.argv = args
import doctest, test_pickle1
return doctest.testmod(test_pickle1)
doctest.testmod(test_pickle1)
if __name__ == '__main__':
import sys
sys.exit(run()[0])
run()

View File

@@ -39,9 +39,7 @@ def run(args = None):
import sys
sys.argv = args
import doctest, test_pickle2
return doctest.testmod(test_pickle2)
doctest.testmod(test_pickle2)
if __name__ == '__main__':
import sys
sys.exit(run()[0])
run()

View File

@@ -19,12 +19,12 @@ r'''>>> import pickle3
... wd.z = 3. * number
... pstr = pickle.dumps(wd)
... wl = pickle.loads(pstr)
... print wd.greet(), wd.get_secret_number(), wd.x, wd.y, wd.z
... print wl.greet(), wl.get_secret_number(), wl.x, wl.y, wl.z
Hello from California! 24 48 yyyyyyyyyyyyyyyyyyyyyyyy 72.0
Hello from California! 24 48 yyyyyyyyyyyyyyyyyyyyyyyy 72.0
Hello from California! 42 84 yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 126.0
Hello from California! 0 84 yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 126.0
... print wd.greet(), wd.get_secret_number(), wd.__dict__
... print wl.greet(), wl.get_secret_number(), wl.__dict__
Hello from California! 24 {'z': 72.0, 'x': 48, 'y': 'yyyyyyyyyyyyyyyyyyyyyyyy'}
Hello from California! 24 {'z': 72.0, 'x': 48, 'y': 'yyyyyyyyyyyyyyyyyyyyyyyy'}
Hello from California! 42 {'z': 126.0, 'x': 84, 'y': 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'}
Hello from California! 0 {'z': 126.0, 'x': 84, 'y': 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'}
'''
def run(args = None):
@@ -32,8 +32,7 @@ def run(args = None):
import sys
sys.argv = args
import doctest, test_pickle3
return doctest.testmod(test_pickle3)
doctest.testmod(test_pickle3)
if __name__ == '__main__':
import sys
sys.exit(run()[0])
run()

View File

@@ -1,40 +0,0 @@
r'''>>> import richcmp1
>>> d1 = richcmp1.dvect((0, 1, 3, 3, 6, 7))
>>> d2 = richcmp1.dvect((1, 2, 3, 4, 5, 6))
>>> print d1.as_tuple()
(0.0, 1.0, 3.0, 3.0, 6.0, 7.0)
>>> print d2.as_tuple()
(1.0, 2.0, 3.0, 4.0, 5.0, 6.0)
>>> print (d1 < d2).as_tuple()
(1, 1, 0, 1, 0, 0)
>>> print (d1 <= d2).as_tuple()
(1, 1, 1, 1, 0, 0)
>>> print (d1 == d2).as_tuple()
(0, 0, 1, 0, 0, 0)
>>> print (d1 != d2).as_tuple()
(1, 1, 0, 1, 1, 1)
>>> print (d1 > d2).as_tuple()
(0, 0, 0, 0, 1, 1)
>>> print (d1 >= d2).as_tuple()
(0, 0, 1, 0, 1, 1)
>>> try: d1 == richcmp1.dvect((1, 2, 3, 4, 5))
... except ValueError, e: print str(e)
...
vectors have different sizes
'''
def run(args = None):
if args is not None:
import sys
sys.argv = args
import doctest, test_richcmp1
return doctest.testmod(test_richcmp1)
if __name__ == '__main__':
import sys
if ( hasattr(sys, 'version_info')
and ( (sys.version_info[0] == 2 and sys.version_info[1] >= 1)
or sys.version_info[0] > 2)):
sys.exit(run()[0])
else:
print "Python version 2.1 or higher required. Test skipped."

View File

@@ -1,41 +0,0 @@
r'''>>> import richcmp2
>>> c1 = richcmp2.code(1)
>>> c2 = richcmp2.code(2)
>>> c3 = richcmp2.code(2)
>>> print c1 == c2
0
>>> print c1 != c2
1
>>> print c2 == c3
1
>>> print c2 != c3
0
>>> print c1 < c2
1
>>> print c1 <= c2
1
>>> print c1 == c2
0
>>> print c1 != c2
1
>>> print c1 > c2
0
>>> print c1 >= c2
0
'''
def run(args = None):
if args is not None:
import sys
sys.argv = args
import doctest, test_richcmp1
return doctest.testmod(test_richcmp1)
if __name__ == '__main__':
import sys
if ( hasattr(sys, 'version_info')
and ( (sys.version_info[0] == 2 and sys.version_info[1] >= 1)
or sys.version_info[0] > 2)):
sys.exit(run()[0])
else:
print "Python version 2.1 or higher required. Test skipped."

View File

@@ -1,77 +0,0 @@
r'''>>> import richcmp3
>>>
>>> iv = richcmp3.ivect((1,2,3,4,5))
>>> print iv.as_tuple()
(1, 2, 3, 4, 5)
>>> dv = richcmp3.dvect((2,-2,3,8,-5))
>>> print dv.as_tuple()
(2.0, -2.0, 3.0, 8.0, -5.0)
>>>
>>> print (iv+dv).as_tuple()
(3.0, 0.0, 6.0, 12.0, 0.0)
>>> print (iv+3).as_tuple()
(4, 5, 6, 7, 8)
>>> print (3+iv).as_tuple()
(4, 5, 6, 7, 8)
>>>
>>> print "vect vs. vect Comparisons:"
vect vs. vect Comparisons:
>>> print (iv < dv).as_tuple()
(1, 0, 0, 1, 0)
>>> print (iv <= dv).as_tuple()
(1, 0, 1, 1, 0)
>>> print (iv == dv).as_tuple()
(0, 0, 1, 0, 0)
>>> print (iv != dv).as_tuple()
(1, 1, 0, 1, 1)
>>> print (iv > dv).as_tuple()
(0, 1, 0, 0, 1)
>>> print (iv >= dv).as_tuple()
(0, 1, 1, 0, 1)
>>>
>>> print "vect vs. scalar Comparisons:"
vect vs. scalar Comparisons:
>>> print (iv < 3).as_tuple()
(1, 1, 0, 0, 0)
>>> print (iv <= 3).as_tuple()
(1, 1, 1, 0, 0)
>>> print (iv == 3).as_tuple()
(0, 0, 1, 0, 0)
>>> print (iv != 3).as_tuple()
(1, 1, 0, 1, 1)
>>> print (iv > 3).as_tuple()
(0, 0, 0, 1, 1)
>>> print (iv >= 3).as_tuple()
(0, 0, 1, 1, 1)
>>>
>>> print "scalar vs. vect Comparisons:"
scalar vs. vect Comparisons:
>>> print (3 < iv).as_tuple()
(0, 0, 0, 1, 1)
>>> print (3 <= iv).as_tuple()
(0, 0, 1, 1, 1)
>>> print (3 == iv).as_tuple()
(0, 0, 1, 0, 0)
>>> print (3 != iv).as_tuple()
(1, 1, 0, 1, 1)
>>> print (3 > iv).as_tuple()
(1, 1, 0, 0, 0)
>>> print (3 >= iv).as_tuple()
(1, 1, 1, 0, 0)
'''
def run(args = None):
if args is not None:
import sys
sys.argv = args
import doctest, test_richcmp3
return doctest.testmod(test_richcmp3)
if __name__ == '__main__':
import sys
if ( hasattr(sys, 'version_info')
and ( (sys.version_info[0] == 2 and sys.version_info[1] >= 1)
or sys.version_info[0] > 2)):
sys.exit(run()[0])
else:
print "Python version 2.1 or higher required. Test skipped."

View File

@@ -11,9 +11,7 @@ def run(args = None):
import sys
sys.argv = args
import doctest, test_rwgk1
return doctest.testmod(test_rwgk1)
doctest.testmod(test_rwgk1)
if __name__ == '__main__':
import sys
sys.exit(run()[0])
run()

View File

@@ -34,9 +34,7 @@ def run(args = None):
import sys
sys.argv = args
import doctest, test_simple_vector
return doctest.testmod(test_simple_vector)
doctest.testmod(test_simple_vector)
if __name__ == '__main__':
import sys
sys.exit(run()[0])
run()

View File

@@ -87,18 +87,12 @@ if (__name__ == "__main__"):
import sys, string
broken_auto_ptr = 0
n = 1
if len(sys.argv) > 1:
argv = []
for x in sys.argv:
if x != '--broken-auto-ptr':
argv.append(x)
broken_auto_ptr = argv != sys.argv
sys.argv = argv
if len(sys.argv) > 1:
n = string.atoi(sys.argv[1])
if (len(sys.argv) > 1):
if (sys.argv[1] == "--broken-auto-ptr"):
broken_auto_ptr = 1
if (len(sys.argv) > 2):
n = string.atoi(sys.argv[2])
else:
n = string.atoi(sys.argv[1])
for i in xrange(n):
f(broken_auto_ptr)

View File

@@ -87,18 +87,12 @@ if (__name__ == "__main__"):
import sys, string
broken_auto_ptr = 0
n = 1
if len(sys.argv) > 1:
argv = []
for x in sys.argv:
if x != '--broken-auto-ptr':
argv.append(x)
broken_auto_ptr = argv != sys.argv
sys.argv = argv
if len(sys.argv) > 1:
n = string.atoi(sys.argv[1])
if (len(sys.argv) > 1):
if (sys.argv[1] == "--broken-auto-ptr"):
broken_auto_ptr = 1
if (len(sys.argv) > 2):
n = string.atoi(sys.argv[2])
else:
n = string.atoi(sys.argv[1])
for i in xrange(n):
f(broken_auto_ptr)

View File

@@ -1,117 +0,0 @@
// Based on wrapVector.hh by Mike Owen and Jeff Johnson.
// http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/spheral/src/src/BPLWraps/CXXWraps/
#ifndef BOOST_PYTHON_EXAMPLE_VECTOR_WRAPPER_H
#define BOOST_PYTHON_EXAMPLE_VECTOR_WRAPPER_H
#include <boost/python/class_builder.hpp>
namespace example {
// A wrapper is used to define additional constructors. This wrapper
// is templated on the template parameter for its corresponding vector.
template <typename T>
struct vector_wrapper: std::vector<T>
{
// Tell the compiler how to convert a base class object to
// this wrapper object.
vector_wrapper(PyObject*,
const std::vector<T>& vec):
std::vector<T>(vec) {}
vector_wrapper(PyObject* self):
std::vector<T>() {}
vector_wrapper(PyObject* self,
std::size_t n):
std::vector<T>(n) {}
vector_wrapper(PyObject* self,
boost::python::tuple tuple):
std::vector<T>(tuple.size())
{
std::vector<T>::iterator vec = begin();
for (std::size_t i = 0; i < tuple.size(); i++)
vec[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(),
boost::python::type<T>());
}
};
void raise_vector_IndexError() {
PyErr_SetString(PyExc_IndexError, "vector index out of range");
throw boost::python::error_already_set();
}
template <typename T>
struct vector_access
{
static
T
getitem(const std::vector<T>& vec,
std::size_t key)
{
if (key >= vec.size()) raise_vector_IndexError();
return vec[key];
}
static
void
setitem(std::vector<T>& vec,
std::size_t key,
const T &value)
{
if (key >= vec.size()) raise_vector_IndexError();
vec[key] = value;
}
static
void
delitem(std::vector<T>& vec,
std::size_t key)
{
if (key >= vec.size()) raise_vector_IndexError();
vec.erase(vec.begin() + key);
}
// Convert vector<T> to a regular Python tuple.
static
boost::python::tuple
as_tuple(const std::vector<T>& vec)
{
// Create a python type of size vec.size().
boost::python::tuple t(vec.size());
for (std::size_t i = 0; i < vec.size(); i++) {
t.set_item(i,
boost::python::ref(BOOST_PYTHON_CONVERSION::to_python(vec[i])));
}
return t;
}
};
// This function will build a vector<T> and add it to the given
// module with the given name.
template <typename T>
boost::python::class_builder<std::vector<T>, vector_wrapper<T> >
wrap_vector(boost::python::module_builder& module,
const std::string& vector_name,
const T&)
{
// Add the vector<T> to the module.
boost::python::class_builder<std::vector<T>, vector_wrapper<T> >
py_vector(module, vector_name.c_str());
// Define constructors and methods for the vector<T>.
py_vector.def(boost::python::constructor<>());
py_vector.def(boost::python::constructor<std::size_t>());
py_vector.def(boost::python::constructor<boost::python::tuple>());
py_vector.def(&std::vector<T>::size, "__len__");
py_vector.def(&vector_access<T>::getitem, "__getitem__");
py_vector.def(&vector_access<T>::setitem, "__setitem__");
py_vector.def(&vector_access<T>::delitem, "__delitem__");
py_vector.def(&vector_access<T>::as_tuple, "as_tuple");
return py_vector;
}
}
#endif // BOOST_PYTHON_EXAMPLE_VECTOR_WRAPPER_H

View File

@@ -70,14 +70,6 @@ class instance
PyObject* oct();
PyObject* hex();
// Rich comparisons
PyObject* lt(PyObject* other);
PyObject* le(PyObject* other);
PyObject* eq(PyObject* other);
PyObject* ne(PyObject* other);
PyObject* gt(PyObject* other);
PyObject* ge(PyObject* other);
private: // noncopyable, without the size bloat
instance(const instance&);
void operator=(const instance&);
@@ -177,14 +169,6 @@ class class_t
PyObject* instance_number_float(PyObject*) const;
PyObject* instance_number_oct(PyObject*) const;
PyObject* instance_number_hex(PyObject*) const;
private: // Implement rich comparisons
PyObject* instance_lt(PyObject*, PyObject*) const;
PyObject* instance_le(PyObject*, PyObject*) const;
PyObject* instance_eq(PyObject*, PyObject*) const;
PyObject* instance_ne(PyObject*, PyObject*) const;
PyObject* instance_gt(PyObject*, PyObject*) const;
PyObject* instance_ge(PyObject*, PyObject*) const;
private: // Miscellaneous "special" methods
PyObject* instance_call(PyObject* obj, PyObject* args, PyObject* keywords) const;
@@ -493,42 +477,6 @@ PyObject* class_t<T>::instance_number_hex(PyObject* obj) const
return downcast<T>(obj)->hex();
}
template <class T>
PyObject* class_t<T>::instance_lt(PyObject* obj, PyObject* other) const
{
return downcast<T>(obj)->lt(other);
}
template <class T>
PyObject* class_t<T>::instance_le(PyObject* obj, PyObject* other) const
{
return downcast<T>(obj)->le(other);
}
template <class T>
PyObject* class_t<T>::instance_eq(PyObject* obj, PyObject* other) const
{
return downcast<T>(obj)->eq(other);
}
template <class T>
PyObject* class_t<T>::instance_ne(PyObject* obj, PyObject* other) const
{
return downcast<T>(obj)->ne(other);
}
template <class T>
PyObject* class_t<T>::instance_gt(PyObject* obj, PyObject* other) const
{
return downcast<T>(obj)->gt(other);
}
template <class T>
PyObject* class_t<T>::instance_ge(PyObject* obj, PyObject* other) const
{
return downcast<T>(obj)->ge(other);
}
namespace detail {
inline dictionary& class_base::dict()
{

View File

@@ -7,7 +7,6 @@
// producing this work.
//
// Revision History:
// 31 Jul 01 convert int/double to complex (Peter Bienstman)
// 04 Mar 01 Fixed std::complex<> stuff to work with MSVC (David Abrahams)
// 03 Mar 01 added: converters for [plain] char and std::complex
// (Ralf W. Grosse-Kunstleve)
@@ -74,17 +73,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 {
@@ -94,10 +93,6 @@ namespace detail {
template <class T>
std::complex<T> complex_from_python(PyObject* p, boost::python::type<T>)
{
if (PyInt_Check(p)) return std::complex<T>(PyInt_AS_LONG(p));
if (PyLong_Check(p)) return std::complex<T>(PyLong_AsDouble(p));
if (PyFloat_Check(p)) return std::complex<T>(PyFloat_AS_DOUBLE(p));
expect_complex(p);
return std::complex<T>(
@@ -294,22 +289,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 +314,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);
@@ -39,22 +39,22 @@ typedef base_object<PyTypeObject> python_type;
//
// base_object member function implementations
// class_t template 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);
@@ -43,30 +51,25 @@ inline PyObject* as_object(PyTypeObject* p) { return reinterpret_cast<PyObject*>
// If I didn't have to support stupid MSVC6 we could just use a simple template function:
// template <class T> T* downcast(PyObject*).
template <class T>
struct downcast
struct downcast : boost::dereferenceable<downcast<T>, T*>
{
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; }
// 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& operator*() const { return *m_p; }
private:

View File

@@ -57,10 +57,10 @@
# define BOOST_CSTD_ std
# 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()
#ifdef _WIN32
# 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
@@ -622,12 +616,6 @@ class extension_class
choose_op<(which & op_and)>::template args<Operand>::add(this);
choose_op<(which & op_xor)>::template args<Operand>::add(this);
choose_op<(which & op_or)>::template args<Operand>::add(this);
choose_op<(which & op_gt)>::template args<Operand>::add(this);
choose_op<(which & op_ge)>::template args<Operand>::add(this);
choose_op<(which & op_lt)>::template args<Operand>::add(this);
choose_op<(which & op_le)>::template args<Operand>::add(this);
choose_op<(which & op_eq)>::template args<Operand>::add(this);
choose_op<(which & op_ne)>::template args<Operand>::add(this);
choose_unary_op<(which & op_neg)>::template args<Operand>::add(this);
choose_unary_op<(which & op_pos)>::template args<Operand>::add(this);
choose_unary_op<(which & op_abs)>::template args<Operand>::add(this);
@@ -657,12 +645,6 @@ class extension_class
choose_op<(which & op_xor)>::template args<Left,Right>::add(this);
choose_op<(which & op_or)>::template args<Left,Right>::add(this);
choose_op<(which & op_cmp)>::template args<Left,Right>::add(this);
choose_op<(which & op_gt)>::template args<Left,Right>::add(this);
choose_op<(which & op_ge)>::template args<Left,Right>::add(this);
choose_op<(which & op_lt)>::template args<Left,Right>::add(this);
choose_op<(which & op_le)>::template args<Left,Right>::add(this);
choose_op<(which & op_eq)>::template args<Left,Right>::add(this);
choose_op<(which & op_ne)>::template args<Left,Right>::add(this);
}
template <long which, class Left, class Right>

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

@@ -73,8 +73,7 @@ namespace detail {
struct parameter_traits
{
private:
enum { is_ref = boost::is_reference<T>::value };
typedef const_ref_selector<is_ref> selector;
typedef const_ref_selector<boost::is_reference<T>::value> selector;
public:
typedef typename selector::template const_ref<T>::type const_reference;
};

View File

@@ -45,7 +45,7 @@ class type_object_base : public python_type
public:
enum capability {
hash, call, str, getattr, setattr, compare, repr, richcompare,
hash, call, str, getattr, setattr, compare, repr,
mapping_length, mapping_subscript, mapping_ass_subscript,
@@ -115,14 +115,6 @@ class type_object_base : public python_type
virtual PyObject* instance_number_float(PyObject*) const;
virtual PyObject* instance_number_oct(PyObject*) const;
virtual PyObject* instance_number_hex(PyObject*) const;
public: // Callbacks for rich comparisons
virtual PyObject* instance_lt(PyObject*, PyObject*) const;
virtual PyObject* instance_le(PyObject*, PyObject*) const;
virtual PyObject* instance_eq(PyObject*, PyObject*) const;
virtual PyObject* instance_ne(PyObject*, PyObject*) const;
virtual PyObject* instance_gt(PyObject*, PyObject*) const;
virtual PyObject* instance_ge(PyObject*, PyObject*) const;
};
template <class T>
@@ -383,12 +375,8 @@ PyObject* reprable<Base>::instance_repr(PyObject* obj) const
// This macro gets the length of an array as a compile-time constant, and will
// fail to compile if the parameter is a pointer.
#ifdef __BORLANDC__ // smart implementation doesn't work for borland; maybe someone knows a workaround?
# define PY_ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0]))
#else
# define PY_ARRAY_LENGTH(a) \
(sizeof(::boost::python::detail::countof_validate(a, &(a))) ? sizeof(a) / sizeof((a)[0]) : 0)
#endif
template<typename T>
inline void countof_validate(T* const, T* const*);

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

@@ -65,13 +65,7 @@ enum operator_id
op_long = 0x20000,
op_float = 0x40000,
op_str = 0x80000,
op_cmp = 0x100000,
op_gt = 0x200000,
op_ge = 0x400000,
op_lt = 0x800000,
op_le = 0x1000000,
op_eq = 0x2000000,
op_ne = 0x4000000
op_cmp = 0x100000
};
// Wrap the operators given by "which". Usage:
@@ -307,12 +301,6 @@ namespace detail
PY_DEFINE_BINARY_OPERATORS(and, &);
PY_DEFINE_BINARY_OPERATORS(xor, ^);
PY_DEFINE_BINARY_OPERATORS(or, |);
PY_DEFINE_BINARY_OPERATORS(gt, >);
PY_DEFINE_BINARY_OPERATORS(ge, >=);
PY_DEFINE_BINARY_OPERATORS(lt, <);
PY_DEFINE_BINARY_OPERATORS(le, <=);
PY_DEFINE_BINARY_OPERATORS(eq, ==);
PY_DEFINE_BINARY_OPERATORS(ne, !=);
PY_DEFINE_UNARY_OPERATORS(neg, -);
PY_DEFINE_UNARY_OPERATORS(pos, +);

View File

@@ -20,7 +20,7 @@
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
template <class T, class Value, class Base = boost::detail::empty_base>
template <class T, class Value, class Base>
struct py_ptr_conversions : Base
{
inline friend T from_python(PyObject* x, boost::python::type<const T&>)
@@ -42,31 +42,32 @@ 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,
boost::dereferenceable<reference<T>, T*> > // supplies op->
{
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 +78,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 +86,45 @@ 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);
}
~reference()
{
Py_XDECREF(m_p);
}
T& operator*() const { return *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 +136,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 +144,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 +157,7 @@ private:
inline PyObject* object() const
{ return as_object(m_p); }
T* m_p;
T* m_p;
};
typedef reference<PyObject> ref;

View File

@@ -203,8 +203,7 @@ namespace detail {
}
if (!BOOST_CSTD_::strcmp(name, "__reduce__"))
{
PyObject* self = as_object(this);
ref target(self, ref::increment_count);
ref target(as_object(this), ref::increment_count);
return bound_function::create(target, global_class_reduce());
}
@@ -736,36 +735,6 @@ PyObject* instance::hex()
return callback<PyObject*>::call_method(this, "__hex__");
}
PyObject* instance::lt(PyObject* other)
{
return callback<PyObject*>::call_method(this, "__lt__", other);
}
PyObject* instance::le(PyObject* other)
{
return callback<PyObject*>::call_method(this, "__le__", other);
}
PyObject* instance::eq(PyObject* other)
{
return callback<PyObject*>::call_method(this, "__eq__", other);
}
PyObject* instance::ne(PyObject* other)
{
return callback<PyObject*>::call_method(this, "__ne__", other);
}
PyObject* instance::gt(PyObject* other)
{
return callback<PyObject*>::call_method(this, "__gt__", other);
}
PyObject* instance::ge(PyObject* other)
{
return callback<PyObject*>::call_method(this, "__ge__", other);
}
namespace {
struct named_capability
{
@@ -777,12 +746,6 @@ namespace {
{
{ "__hash__", detail::type_object_base::hash },
{ "__cmp__", detail::type_object_base::compare },
{ "__gt__", detail::type_object_base::richcompare },
{ "__ge__", detail::type_object_base::richcompare },
{ "__lt__", detail::type_object_base::richcompare },
{ "__le__", detail::type_object_base::richcompare },
{ "__eq__", detail::type_object_base::richcompare },
{ "__ne__", detail::type_object_base::richcompare },
{ "__repr__", detail::type_object_base::repr },
{ "__str__", detail::type_object_base::str },
{ "__call__", detail::type_object_base::call },
@@ -845,7 +808,7 @@ namespace detail {
// Enable the special handler for methods of the given name, if any.
void enable_named_method(boost::python::detail::class_base* type_obj, const char* name)
{
const std::size_t num_enablers = PY_ARRAY_LENGTH(enablers);
const std::size_t num_enablers = sizeof(enablers) / sizeof(enablers[0]);
// Make sure this ends with "__" since we'll only compare the head of the
// string. This is done to make the __getattr__<name>__/__setattr__<name>__

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

@@ -15,7 +15,6 @@ def gen_extclass(args):
// gen_extclass.python
// Revision History:
// 17 Apr 01 Comment added with reference to cross_module.hpp (R.W. Grosse-Kunstleve)
// 05 Mar 01 Fixed a bug which prevented auto_ptr values from being converted
// to_python (Dave Abrahams)
@@ -172,14 +171,6 @@ BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
// and U. T is the class the user really intends to wrap. U is a class derived
// from T with some virtual function overriding boilerplate, or if there are no
// virtual functions, U = held_instance<T>.
//
// A look-alike of this class in root/boost/python/cross_module.hpp
// is used for the implementation of the cross-module support
// (export_converters and import_converters). If from_python
// and to_python converters are added or removed from the class
// below, the class python_import_extension_class_converters has
// to be modified accordingly.
//
template <class T, class U = boost::python::detail::held_instance<T> >
class python_extension_class_converters
{
@@ -238,9 +229,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 +257,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
@@ -623,12 +607,6 @@ class extension_class
choose_op<(which & op_and)>::template args<Operand>::add(this);
choose_op<(which & op_xor)>::template args<Operand>::add(this);
choose_op<(which & op_or)>::template args<Operand>::add(this);
choose_op<(which & op_gt)>::template args<Operand>::add(this);
choose_op<(which & op_ge)>::template args<Operand>::add(this);
choose_op<(which & op_lt)>::template args<Operand>::add(this);
choose_op<(which & op_le)>::template args<Operand>::add(this);
choose_op<(which & op_eq)>::template args<Operand>::add(this);
choose_op<(which & op_ne)>::template args<Operand>::add(this);
choose_unary_op<(which & op_neg)>::template args<Operand>::add(this);
choose_unary_op<(which & op_pos)>::template args<Operand>::add(this);
choose_unary_op<(which & op_abs)>::template args<Operand>::add(this);
@@ -658,12 +636,6 @@ class extension_class
choose_op<(which & op_xor)>::template args<Left,Right>::add(this);
choose_op<(which & op_or)>::template args<Left,Right>::add(this);
choose_op<(which & op_cmp)>::template args<Left,Right>::add(this);
choose_op<(which & op_gt)>::template args<Left,Right>::add(this);
choose_op<(which & op_ge)>::template args<Left,Right>::add(this);
choose_op<(which & op_lt)>::template args<Left,Right>::add(this);
choose_op<(which & op_le)>::template args<Left,Right>::add(this);
choose_op<(which & op_eq)>::template args<Left,Right>::add(this);
choose_op<(which & op_ne)>::template args<Left,Right>::add(this);
}
template <long which, class Left, class Right>

View File

@@ -79,8 +79,7 @@ namespace detail {
struct parameter_traits
{
private:
enum { is_ref = boost::is_reference<T>::value };
typedef const_ref_selector<is_ref> selector;
typedef const_ref_selector<boost::is_reference<T>::value> selector;
public:
typedef typename selector::template const_ref<T>::type const_reference;
};

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,202 +24,141 @@ 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);
}
static PyObject* do_instance_richcompare(PyObject* obj, PyObject* other, int d)
{
#if PYTHON_API_VERSION >= 1010
switch(d)
{
case Py_LT:
return call(obj, &type_object_base::instance_lt, other);
case Py_LE:
return call(obj, &type_object_base::instance_le, other);
case Py_EQ:
return call(obj, &type_object_base::instance_eq, other);
case Py_NE:
return call(obj, &type_object_base::instance_ne, other);
case Py_GT:
return call(obj, &type_object_base::instance_gt, other);
case Py_GE:
return call(obj, &type_object_base::instance_ge, other);
}
#endif
return 0;
}
static int do_instance_compare(PyObject* obj, PyObject* other)
{
return call(obj, &type_object_base::instance_compare, other);
@@ -235,7 +171,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 +181,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 +222,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 +366,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)
{
@@ -468,7 +406,7 @@ namespace
bool add_capability_general(type_object_base::capability capability, PyTypeObject* dest)
{
assert(dest != 0);
switch(capability)
{
ENABLE_GENERAL_CAPABILITY(hash);
@@ -497,20 +435,6 @@ void create_method_table_if_null(T*& table)
}
}
bool add_capability_richcompare(type_object_base::capability capability, PyTypeObject* dest)
{
assert(dest != 0);
if (capability == type_object_base::richcompare) {
#if PYTHON_API_VERSION >= 1010
dest->tp_richcompare = &do_instance_richcompare;
dest->tp_flags |= Py_TPFLAGS_HAVE_RICHCOMPARE;
#endif
return true;
}
return false;
}
#define ENABLE_MAPPING_CAPABILITY(field) \
case type_object_base::mapping_##field: \
create_method_table_if_null(dest); \
@@ -624,8 +548,6 @@ namespace detail {
{
if(add_capability_general(capability, dest_))
return;
if(add_capability_richcompare(capability, dest_))
return;
if(add_capability_mapping(capability, dest_->tp_as_mapping))
return;
if(add_capability_sequence(capability, dest_->tp_as_sequence))
@@ -1053,36 +975,6 @@ PyObject* type_object_base::instance_number_hex(PyObject*) const
return unimplemented("instance_number_hex");
}
PyObject* type_object_base::instance_lt(PyObject*, PyObject*) const
{
return unimplemented("instance_lt");
}
PyObject* type_object_base::instance_le(PyObject*, PyObject*) const
{
return unimplemented("instance_le");
}
PyObject* type_object_base::instance_eq(PyObject*, PyObject*) const
{
return unimplemented("instance_eq");
}
PyObject* type_object_base::instance_ne(PyObject*, PyObject*) const
{
return unimplemented("instance_ne");
}
PyObject* type_object_base::instance_gt(PyObject*, PyObject*) const
{
return unimplemented("instance_gt");
}
PyObject* type_object_base::instance_ge(PyObject*, PyObject*) const
{
return unimplemented("instance_ge");
}
}} // namespace boost::python
#ifdef TYPE_OBJECT_BASE_STANDALONE_TEST
@@ -1202,3 +1094,4 @@ int main()
}
#endif

View File

@@ -15,9 +15,7 @@
#include <math.h> // for pow()
#include <boost/rational.hpp>
#if defined(__sgi) \
&& ( (defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730) \
&& !defined(__GNUC__))
#if defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730
inline double pow(int x, int y) { return pow(static_cast<double>(x), y); }
#endif
@@ -157,7 +155,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 +1126,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 +1135,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,21 +8,21 @@ 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.
>>> try:
... ext = Foo()
... except TypeError, err:
... assert re.match(r'function .* exactly 1 argument;? \(?0 given\)?',
... str(err))
... else:
... print 'no exception'
>>> ext = Foo()
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: function requires exactly 1 argument; 0 given
>>> try: ext = Foo('foo')
... except TypeError, err:
@@ -271,12 +271,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 +294,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!'
@@ -409,7 +419,7 @@ Some simple overloading tests:
>>> try: r = Range('yikes')
... except TypeError, e:
... assert re.match(
... 'No overloaded functions match [(]Range, str[a-z]*[)]\. Candidates are:\n.*\n.*',
... 'No overloaded functions match [(]Range, string[)]\. Candidates are:\n.*\n.*',
... str(e))
... else: print 'no exception'
@@ -619,7 +629,7 @@ Testing overloaded free functions
15
>>> try: overloaded(1, 'foo')
... except TypeError, err:
... assert re.match("No overloaded functions match \(int, str[a-z]*\)\. Candidates are:",
... assert re.match("No overloaded functions match \(int, string\)\. Candidates are:",
... str(err))
... else:
... print 'no exception'
@@ -649,7 +659,7 @@ Testing overloaded constructors
5
>>> try: over = OverloadTest(1, 'foo')
... except TypeError, err:
... assert re.match("No overloaded functions match \(OverloadTest, int, str[a-z]*\)\. Candidates are:",
... assert re.match("No overloaded functions match \(OverloadTest, int, string\)\. Candidates are:",
... str(err))
... else:
... print 'no exception'
@@ -671,7 +681,7 @@ Testing overloaded methods
5
>>> try: over.overloaded(1,'foo')
... except TypeError, err:
... assert re.match("No overloaded functions match \(OverloadTest, int, str[a-z]*\)\. Candidates are:",
... assert re.match("No overloaded functions match \(OverloadTest, int, string\)\. Candidates are:",
... str(err))
... else:
... print 'no exception'
@@ -1004,12 +1014,9 @@ test inheritB2
-2
>>> str(i)
'2'
>>> try: j = i/i
... except TypeError, err:
... assert re.match(r'(bad|unsupported) operand type\(s\) for /',
... str(err))
... else: print 'no exception'
>>> j = i/i
Traceback (innermost last):
TypeError: bad operand type(s) for /
>>> j = abs(i)
Traceback (innermost last):
TypeError: bad operand type for abs()
@@ -1162,39 +1169,10 @@ test methodologies for wrapping functions that return a pointer
'2.94'
>>> '%.3g' % (dreal(c))
'6.35'
>>> '%.3g' % (dreal(3))
'3'
>>> '%.3g' % (dreal(3L))
'3'
>>> '%.3g' % (dreal(3.))
'3'
>>> '%.3g' % (freal(3))
'3'
>>> '%.3g' % (freal(3L))
'3'
>>> '%.3g' % (freal(3.))
'3'
'''
#'
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)
@@ -1210,7 +1188,7 @@ def run(args = None):
if args is not None:
sys.argv = args
import doctest, comprehensive
return doctest.testmod(comprehensive)
doctest.testmod(comprehensive)
if __name__ == '__main__':
sys.exit(run()[0])
run()