From c33ac6b47ac75579efdfad6345a35592d9079000 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sat, 5 Oct 2002 12:53:06 +0000 Subject: [PATCH] Merge Trunk changes to RC_1_29_0 [SVN r15732] --- Jamfile | 43 - build/Jamfile | 177 +-- build/como.mak | 59 - build/filemgr.py | 146 -- build/gcc.mak | 88 -- build/irix_CC.mak | 184 --- build/linux_gcc.mak | 184 --- build/mingw32.mak | 222 ---- build/tru64_cxx.mak | 199 --- build/vc60.mak | 154 --- build/win32_mwcc.mak | 149 --- build/win32_mwcc_setup.bat | 2 - doc/v2/CallPolicies.html | 242 ++-- doc/v2/call_method.html | 173 +-- doc/v2/class.html | 825 +++++++----- doc/v2/configuration.html | 226 ++-- doc/v2/copy_const_reference.html | 76 +- doc/v2/copy_non_const_reference.html | 72 +- doc/v2/data_members.html | 121 +- doc/v2/definitions.html | 129 +- doc/v2/errors.html | 174 ++- doc/v2/faq.html | 199 ++- doc/v2/has_back_reference.html | 155 ++- doc/v2/implicit.html | 108 +- doc/v2/iterator.html | 407 +++--- doc/v2/lvalue_from_pytype.html | 216 +-- doc/v2/make_function.html | 139 +- doc/v2/manage_new_object.html | 67 +- doc/v2/module.html | 205 +-- doc/v2/operators.html | 1004 +++++++++----- doc/v2/ptr.html | 2 + doc/v2/reference.html | 704 ++++++---- doc/v2/reference_existing_object.html | 83 +- doc/v2/return_internal_reference.html | 177 +-- doc/v2/return_value_policy.html | 119 +- doc/v2/to_python_converter.html | 141 +- example/Attic/project.zip | Bin 1469 -> 0 bytes example/Jamfile | 26 +- example/README | 19 +- example/abstract.cpp | 32 - example/do_it_yourself_convts.cpp | 121 -- example/dvect.cpp | 48 - example/dvect.h | 32 - example/dvect_conversions.cpp | 51 - example/dvect_defs.cpp | 13 - example/getting_started1.cpp | 17 +- example/getting_started2.cpp | 33 +- example/ivect.cpp | 49 - example/ivect.h | 32 - example/ivect_conversions.cpp | 51 - example/ivect_defs.cpp | 13 - example/nested.cpp | 37 - example/noncopyable.h | 14 - example/noncopyable_export.cpp | 28 - example/noncopyable_import.cpp | 45 - example/pickle1.cpp | 57 - example/pickle2.cpp | 93 -- example/pickle3.cpp | 143 -- example/project.zip | Bin 1469 -> 0 bytes example/richcmp1.cpp | 84 -- example/richcmp2.cpp | 62 - example/richcmp3.cpp | 175 --- example/simple_vector.cpp | 104 -- example/test_abstract.py | 24 - example/test_cross_module.py | 140 -- example/test_do_it_yourself_convts.py | 23 - example/test_example1.py | 51 - example/test_getting_started1.py | 18 - example/test_getting_started2.py | 31 - example/test_nested.py | 23 - example/test_pickle1.py | 33 - example/test_pickle2.py | 47 - example/test_pickle3.py | 39 - example/test_richcmp1.py | 40 - example/test_richcmp2.py | 41 - example/test_richcmp3.py | 77 -- example/test_rwgk1.py | 19 - example/test_simple_vector.py | 42 - example/tst_dvect1.py | 20 - example/tst_dvect2.py | 104 -- example/tst_ivect1.py | 20 - example/tst_ivect2.py | 104 -- example/tst_noncopyable.py | 16 - example/vector_wrapper.h | 117 -- include/boost/python/args.hpp | 7 - include/boost/python/args_fwd.hpp | 8 +- include/boost/python/class.hpp | 11 +- include/boost/python/def.hpp | 2 +- include/boost/python/detail/defaults_def.hpp | 2 +- include/boost/python/detail/defaults_gen.hpp | 45 +- include/boost/python/detail/module_base.hpp | 1 + include/boost/python/detail/module_info.hpp | 51 - .../python/detail/type_list_impl_no_pts.hpp | 4 +- include/boost/python/detail/types.hpp | 413 ------ include/boost/python/dict.hpp | 142 +- include/boost/python/init.hpp | 30 +- include/boost/python/list.hpp | 97 +- include/boost/python/long.hpp | 36 +- include/boost/python/module.hpp | 99 +- include/boost/python/object/class.hpp | 5 +- include/boost/python/object/instance.hpp | 2 +- include/boost/python/py_interface.hpp | 700 ---------- include/boost/python/str.hpp | 314 ++--- include/boost/python/tuple.hpp | 31 +- src/aix_init_module.cpp | 2 +- src/dict.cpp | 45 +- src/list.cpp | 38 +- src/long.cpp | 18 +- src/module.cpp | 40 +- src/object/class.cpp | 14 +- src/str.cpp | 214 ++- src/tuple.cpp | 12 +- test/Jamfile | 9 +- test/args.cpp | 5 +- test/back_reference.cpp | 4 +- test/bienstman1.cpp | 4 +- test/bienstman2.cpp | 4 +- test/bienstman3.cpp | 4 +- test/bienstman4.cpp | 4 +- test/bienstman5.cpp | 4 +- test/callbacks.cpp | 4 +- test/cltree.cpp | 4 +- test/comprehensive.cpp | 2 +- test/data_members.cpp | 4 +- test/defaults.cpp | 12 +- test/defaults.py | 2 + test/dict.cpp | 4 +- test/docstring.cpp | 4 +- test/doctest.py | 1173 ----------------- test/enum.cpp | 4 +- test/exception_translator.cpp | 4 +- test/extract.cpp | 4 +- test/implicit.cpp | 4 +- test/input_iterator.cpp | 4 +- test/iterator.cpp | 4 +- test/list.cpp | 4 +- test/long.cpp | 4 +- test/m1.cpp | 4 +- test/m2.cpp | 4 +- test/minimal.cpp | 4 +- test/multi_arg_constructor.cpp | 4 +- test/nested.cpp | 4 +- test/numpy.cpp | 4 +- test/object.cpp | 4 +- test/operators.cpp | 4 +- test/pickle1.cpp | 4 +- test/pickle2.cpp | 4 +- test/pickle3.cpp | 4 +- test/str.cpp | 4 +- test/submod_subclass_api.cpp | 6 +- test/test_builtin_converters.cpp | 4 +- test/test_pointer_adoption.cpp | 4 +- test/tuple.cpp | 4 +- test/virtual_functions.cpp | 4 +- 154 files changed, 4121 insertions(+), 9390 deletions(-) delete mode 100644 Jamfile delete mode 100644 build/como.mak delete mode 100644 build/filemgr.py delete mode 100644 build/gcc.mak delete mode 100644 build/irix_CC.mak delete mode 100644 build/linux_gcc.mak delete mode 100644 build/mingw32.mak delete mode 100644 build/tru64_cxx.mak delete mode 100644 build/vc60.mak delete mode 100755 build/win32_mwcc.mak delete mode 100755 build/win32_mwcc_setup.bat delete mode 100644 example/Attic/project.zip delete mode 100644 example/abstract.cpp delete mode 100644 example/do_it_yourself_convts.cpp delete mode 100644 example/dvect.cpp delete mode 100644 example/dvect.h delete mode 100644 example/dvect_conversions.cpp delete mode 100644 example/dvect_defs.cpp delete mode 100644 example/ivect.cpp delete mode 100644 example/ivect.h delete mode 100644 example/ivect_conversions.cpp delete mode 100644 example/ivect_defs.cpp delete mode 100644 example/nested.cpp delete mode 100644 example/noncopyable.h delete mode 100644 example/noncopyable_export.cpp delete mode 100644 example/noncopyable_import.cpp delete mode 100644 example/pickle1.cpp delete mode 100644 example/pickle2.cpp delete mode 100644 example/pickle3.cpp delete mode 100644 example/project.zip delete mode 100644 example/richcmp1.cpp delete mode 100644 example/richcmp2.cpp delete mode 100644 example/richcmp3.cpp delete mode 100644 example/simple_vector.cpp delete mode 100644 example/test_abstract.py delete mode 100644 example/test_cross_module.py delete mode 100644 example/test_do_it_yourself_convts.py delete mode 100644 example/test_example1.py delete mode 100644 example/test_getting_started1.py delete mode 100644 example/test_getting_started2.py delete mode 100644 example/test_nested.py delete mode 100644 example/test_pickle1.py delete mode 100644 example/test_pickle2.py delete mode 100644 example/test_pickle3.py delete mode 100644 example/test_richcmp1.py delete mode 100644 example/test_richcmp2.py delete mode 100644 example/test_richcmp3.py delete mode 100644 example/test_rwgk1.py delete mode 100644 example/test_simple_vector.py delete mode 100644 example/tst_dvect1.py delete mode 100644 example/tst_dvect2.py delete mode 100644 example/tst_ivect1.py delete mode 100644 example/tst_ivect2.py delete mode 100644 example/tst_noncopyable.py delete mode 100644 example/vector_wrapper.h delete mode 100644 include/boost/python/detail/module_info.hpp delete mode 100644 include/boost/python/detail/types.hpp delete mode 100644 include/boost/python/py_interface.hpp delete mode 100644 test/doctest.py diff --git a/Jamfile b/Jamfile deleted file mode 100644 index d5a9e729..00000000 --- a/Jamfile +++ /dev/null @@ -1,43 +0,0 @@ -subproject libs/python ; - -# bring in the rules for python -SEARCH on python.jam = $(BOOST_BUILD_PATH) ; -include python.jam ; - -local bpl-linkflags ; - -if $(UNIX) && ( $(OS) = AIX ) -{ - bpl-linkflags = "-e initlibbpl" ; -} - -dll bpl - : - src/list.cpp - src/long.cpp - src/dict.cpp - src/tuple.cpp - src/str.cpp - - src/aix_init_module.cpp - src/converter/from_python.cpp - src/converter/registry.cpp - src/converter/type_id.cpp - src/object/enum.cpp - src/object/class.cpp - src/object/function.cpp - src/object/inheritance.cpp - src/object/life_support.cpp - src/object/pickle_support.cpp - src/errors.cpp - src/module.cpp - src/converter/builtin_converters.cpp - src/converter/arg_to_python_base.cpp - src/object/iterator.cpp - src/object_protocol.cpp - src/object_operators.cpp - : - $(BOOST_PYTHON_V2_PROPERTIES) - BOOST_PYTHON_SOURCE - $(bpl-linkflags) - ; diff --git a/build/Jamfile b/build/Jamfile index 2b583d17..97d8222e 100644 --- a/build/Jamfile +++ b/build/Jamfile @@ -3,56 +3,8 @@ # 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.dll/.so, a dynamic library to be linked with all -# Boost.Python modules -# -# 2. pairs of test targets of the form .test and .run -# .test runs the test when it is out-of-date, and the "test" -# pseudotarget depends on it. .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. +# Boost.Python library Jamfile + # declare the location of this subproject relative to the root subproject libs/python/build ; @@ -64,106 +16,51 @@ include python.jam ; if [ check-python-config ] { -local PYTHON_PROPERTIES = $(PYTHON_PROPERTIES) BOOST_PYTHON_DYNAMIC_LIB ; + local bpl-linkflags ; -####################### -rule bpl-test ( test-name : sources + ) -{ - boost-python-test $(test-name) : $(sources) boost_python ; -} + if $(UNIX) && ( $(OS) = AIX ) + { + bpl-linkflags = "-e initlibbpl" ; + } -####################### + dll boost_python + : + ../src/numeric.cpp -# -# Declare the boost python static link library -# + ../src/list.cpp + ../src/long.cpp + ../src/dict.cpp + ../src/tuple.cpp + ../src/str.cpp -# 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 errors - ; - -lib boost_python_static : ../src/$(CPP_SOURCES).cpp - # requirements - : $(BOOST_PYTHON_INCLUDES) - true - BOOST_PYTHON_STATIC_LIB=1 - [ difference $(PYTHON_PROPERTIES) : BOOST_PYTHON_DYNAMIC_LIB ] - : true # don't build this unless the user asks for it by name + ../src/aix_init_module.cpp + ../src/converter/from_python.cpp + ../src/converter/registry.cpp + ../src/converter/type_id.cpp + ../src/object/enum.cpp + ../src/object/class.cpp + ../src/object/function.cpp + ../src/object/inheritance.cpp + ../src/object/life_support.cpp + ../src/object/pickle_support.cpp + ../src/errors.cpp + ../src/module.cpp + ../src/converter/builtin_converters.cpp + ../src/converter/arg_to_python_base.cpp + ../src/object/iterator.cpp + ../src/object_protocol.cpp + ../src/object_operators.cpp + : + $(BOOST_PYTHON_V2_PROPERTIES) + BOOST_PYTHON_SOURCE + $(bpl-linkflags) ; -dll boost_python - # $(SUFDLL[1]) - : ../src/$(CPP_SOURCES).cpp - # requirements - : $(BOOST_PYTHON_INCLUDES) - true - dynamic - $(PYTHON_PROPERTIES) - ; - -stage bin-stage : boost_python + stage bin-stage : boost_python : "_debug" "_pydebug" : debug release ; - -############# comprehensive module and test ########### -bpl-test boost_python_test - : ../test/comprehensive.cpp ; - -boost-python-runtest comprehensive - : ../test/comprehensive.py boost_python_test boost_python ; - -############# simple tests from ../example ############ - -rule boost-python-example-runtest ( name ) -{ - bpl-test $(name) - : ../example/$(name).cpp ; - - boost-python-runtest $(name) - : ../example/test_$(name).py $(name) boost_python ; -} - - -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 ; - - -bpl-test ivect : ../example/ivect.cpp ; -bpl-test dvect : ../example/dvect.cpp ; -bpl-test noncopyable_export : ../example/noncopyable_export.cpp ; -bpl-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 : modules + ) -{ - boost-python-runtest $(test-name) - : ../example/tst_$(test-name).py $(modules) boost_python - : : : $(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 ; - } \ No newline at end of file diff --git a/build/como.mak b/build/como.mak deleted file mode 100644 index edf05f83..00000000 --- a/build/como.mak +++ /dev/null @@ -1,59 +0,0 @@ -# Revision History: -# 17 Apr 01 include cross-module support, compile getting_started1 (R.W. Grosse-Kunstleve) UNTESTED! -# 06 Mar 01 Fixed typo in use of "PYTHON_LIB" (Dave Abrahams) -# 04 Mar 01 Changed library name to libboost_python.a (David Abrahams) - -LIBSRC = \ - classes.cpp \ - conversions.cpp \ - cross_module.cpp \ - errors.cpp \ - extension_class.cpp \ - functions.cpp \ - init_function.cpp \ - module_builder.cpp \ - objects.cpp \ - types.cpp - -LIBOBJ = $(LIBSRC:.cpp=.o) -OBJ = $(LIBOBJ) - - -ifeq "$(OS)" "Windows_NT" -PYTHON_LIB=c:/tools/python/libs/python15.lib -INC = -Ic:/cygnus/usr/include/g++-3 -Ic:/cygnus/usr/include -Ic:/boost -Ic:/tools/python/include -MODULE_EXTENSION=dll -else -INC = -I/usr/local/include/python1.5 -MODULE_EXTENSION=so -endif - -%.o: ../src/%.cpp - como --pic $(INC) -o $*.o -c $< - -%.d: ../src/%.cpp - @echo creating $@ - @set -e; como -M $(INC) -c $< \ - | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \ - [ -s $@ ] || rm -f $@ - -getting_started1: getting_started1.o libboost_python.a - como-dyn-link -o ../example/getting_started1.$(MODULE_EXTENSION) $(PYTHON_LIB) getting_started1.o -L. -lboost_python - ln -s ../test/doctest.py ../example - python ../example/test_getting_started1.py - -getting_started1.o: ../example/getting_started1.cpp - como --pic $(INC) -o $*.o -c $< - -clean: - rm -rf *.o *.$(MODULE_EXTENSION) *.a *.d *.pyc *.bak a.out - -libboost_python.a: $(LIBOBJ) - rm -f libboost_python.a - ar cq libboost_python.a $(LIBOBJ) - -DEP = $(OBJ:.o=.d) - -ifneq "$(MAKECMDGOALS)" "clean" -include $(DEP) -endif diff --git a/build/filemgr.py b/build/filemgr.py deleted file mode 100644 index 93cef1cb..00000000 --- a/build/filemgr.py +++ /dev/null @@ -1,146 +0,0 @@ -# Revision history: -# 12 Apr 01 use os.path, shutil -# Initial version: R.W. Grosse-Kunstleve - -bpl_src = "/libs/python/src" -bpl_tst = "/libs/python/test" -bpl_exa = "/libs/python/example" -files = ( -bpl_src + "/classes.cpp", -bpl_src + "/conversions.cpp", -bpl_src + "/errors.cpp", -bpl_src + "/extension_class.cpp", -bpl_src + "/functions.cpp", -bpl_src + "/init_function.cpp", -bpl_src + "/module_builder.cpp", -bpl_src + "/objects.cpp", -bpl_src + "/types.cpp", -bpl_src + "/cross_module.cpp", -bpl_tst + "/comprehensive.cpp", -bpl_tst + "/comprehensive.hpp", -bpl_tst + "/comprehensive.py", -bpl_tst + "/doctest.py", -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 + "/pickle1.cpp", -bpl_exa + "/pickle2.cpp", -bpl_exa + "/pickle3.cpp", -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_pickle1.py", -bpl_exa + "/test_pickle2.py", -bpl_exa + "/test_pickle3.py", -bpl_exa + "/noncopyable.h", -bpl_exa + "/noncopyable_export.cpp", -bpl_exa + "/noncopyable_import.cpp", -bpl_exa + "/dvect.h", -bpl_exa + "/dvect.cpp", -bpl_exa + "/dvect_conversions.cpp", -bpl_exa + "/dvect_defs.cpp", -bpl_exa + "/ivect.h", -bpl_exa + "/ivect.cpp", -bpl_exa + "/ivect_conversions.cpp", -bpl_exa + "/ivect_defs.cpp", -bpl_exa + "/tst_noncopyable.py", -bpl_exa + "/tst_dvect1.py", -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 = ( -"boost_python_test", -"abstract", -"getting_started1", -"getting_started2", -"simple_vector", -"do_it_yourself_convts", -"nested", -"pickle1", -"pickle2", -"pickle3", -"noncopyable_export", -"noncopyable_import", -"ivect", -"dvect", -"richcmp1", -"richcmp2", -"richcmp3", -) - -if (__name__ == "__main__"): - - import sys, os, shutil - - path = sys.argv[1] - mode = sys.argv[2] - if (not mode in ("softlinks", "unlink", "cp", "rm", "copy", "del")): - raise RuntimeError, \ - "usage: python filemgr.py path " - - if (mode in ("cp", "copy")): - for fn in files: - f = os.path.basename(fn) - print "Copying: " + f - shutil.copy(path + fn, ".") - - elif (mode == "softlinks"): - for fn in files: - f = os.path.basename(fn) - if (os.path.exists(f)): - print "File exists: " + f - else: - print "Linking: " + f - os.symlink(path + fn, f) - - elif (mode in ("rm", "del")): - for fn in files: - f = os.path.basename(fn) - if (os.path.exists(f)): - print "Removing: " + f - try: os.unlink(f) - except: pass - - elif (mode == "unlink"): - for fn in files: - f = os.path.basename(fn) - if (os.path.exists(f)): - if (os.path.islink(f)): - print "Unlinking: " + f - try: os.unlink(f) - except: pass - else: - print "Not a softlink: " + f - - if (mode in ("softlinks", "cp", "copy")): - for d in defs: - fn = d + ".def" - print "Creating: " + fn - f = open(fn, "w") - f.write("EXPORTS\n") - f.write("\tinit" + d + "\n") - f.close() - - if (mode in ("unlink", "rm", "del")): - for d in defs: - fn = d + ".def" - if (os.path.exists(fn)): - print "Removing: " + fn - try: os.unlink(fn) - except: pass diff --git a/build/gcc.mak b/build/gcc.mak deleted file mode 100644 index b818030e..00000000 --- a/build/gcc.mak +++ /dev/null @@ -1,88 +0,0 @@ -# Revision History - -# 17 Apr 01 include cross-module support, compile getting_started1 (R.W. Grosse-Kunstleve) -# 17 Apr 01 build shared library (patch provided by Dan Nuffer) -# 04 Mar 01 Changed library name to libboost_python.a, various cleanups, -# attempted Cygwin compatibility. Still needs testing on Linux -# (David Abrahams) - - -LIBSRC = \ - classes.cpp \ - conversions.cpp \ - cross_module.cpp \ - errors.cpp \ - extension_class.cpp \ - functions.cpp \ - init_function.cpp \ - module_builder.cpp \ - objects.cpp \ - types.cpp - -LIBOBJ = $(LIBSRC:.cpp=.o) -OBJ = $(LIBOBJ) - -LIBNAME = libboost_python -# libpython2.0.dll - -ifeq "$(OS)" "Windows_NT" -ROOT=c:/cygnus -INC = -Ic:/cygnus/usr/include/g++-3 -Ic:/cygnus/usr/include -Ic:/boost -I$(PYTHON_INC) -MODULE_EXTENSION=dll -PYTHON_LIB=c:/cygnus/usr/local/lib/python2.0/config/libpython2.0.dll.a -SHARED_LIB = $(LIBNAME).dll -else -PYTHON_INC=$(ROOT)/usr/local/Python-2.0/include/python2.0 -BOOST_INC=../../.. -INC = -I$(BOOST_INC) -I$(PYTHON_INC) -MODULE_EXTENSION=so -VERSION=1 -SHARED_LIB = $(LIBNAME).so.$(VERSION) -endif - -%.o: ../src/%.cpp - g++ -fPIC -Wall -W $(INC) $(CXXFLAGS) -o $*.o -c $< - -%.d: ../src/%.cpp - @echo creating $@ - @set -e; g++ -M $(INC) -c $< \ - | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \ - [ -s $@ ] || rm -f $@ - - -PYTHON = python - -all: test $(SHARED_LIB) getting_started1 - -test: comprehensive.o $(LIBNAME).a $(SHARED_LIB) - g++ $(CXXFLAGS) -shared -o ../test/boost_python_test.$(MODULE_EXTENSION) comprehensive.o -L. -lboost_python $(PYTHON_LIB) - $(PYTHON) ../test/comprehensive.py - -comprehensive.o: ../test/comprehensive.cpp - g++ $(CXXFLAGS) --template-depth-32 -fPIC -Wall -W $(INC) -o $*.o -c $< - - -getting_started1: getting_started1.o $(LIBNAME).a - g++ $(CXXFLAGS) -shared -o ../example/getting_started1.$(MODULE_EXTENSION) getting_started1.o -L. -lboost_python $(PYTHON_LIB) - ln -s ../test/doctest.py ../example - $(PYTHON) ../example/test_getting_started1.py - -getting_started1.o: ../example/getting_started1.cpp - g++ $(CXXFLAGS) --template-depth-32 -fPIC -Wall -W $(INC) -o $*.o -c $< - - -clean: - rm -rf *.o *.$(MODULE_EXTENSION) *.a *.d *.pyc *.bak a.out - -$(LIBNAME).a: $(LIBOBJ) - rm -f $@ - ar cqs $@ $(LIBOBJ) - -$(SHARED_LIB): $(LIBOBJ) - g++ $(CXXFLAGS) -shared -o $@ -Wl,--soname=$(LIBNAME).$(MODULE_EXTENSION) - -DEP = $(OBJ:.o=.d) - -ifneq "$(MAKECMDGOALS)" "clean" -include $(DEP) -endif diff --git a/build/irix_CC.mak b/build/irix_CC.mak deleted file mode 100644 index f7d6004e..00000000 --- a/build/irix_CC.mak +++ /dev/null @@ -1,184 +0,0 @@ -# Usage: -# -# Create a new empty directory anywhere (preferably not in the boost tree). -# Copy this Makefile to that new directory and rename it to "Makefile" -# Adjust the pathnames below. -# -# make softlinks Create softlinks to source code and tests -# make Compile all sources -# make test Run doctest tests -# make clean Remove all object files -# make unlink Remove softlinks -# -# Revision history: -# 12 Apr 01 new macro ROOT to simplify configuration (R.W. Grosse-Kunstleve) -# Initial version: R.W. Grosse-Kunstleve - -ROOT=$(HOME) -BOOST=$(ROOT)/boost - -#PYEXE=PYTHONPATH=. /usr/local/Python-1.5.2/bin/python -#PYINC=-I/usr/local/Python-1.5.2/include/python1.5 -PYEXE=PYTHONPATH=. /usr/local_cci/Python-2.1.1/bin/python -PYINC=-I/usr/local_cci/Python-2.1.1/include/python2.1 -STLPORTINC=-I$(BOOST)/boost/compatibility/cpp_c_headers - -STDOPTS= -WARNOPTS=-woff 1001,1234,1682 -OPTOPTS=-g - -CPP=CC -LANG:std -n32 -mips4 -CPPOPTS=$(STLPORTINC) $(STLPORTOPTS) -I$(BOOST) $(PYINC) \ - $(STDOPTS) $(WARNOPTS) $(OPTOPTS) -MAKEDEP=-M - -LD=CC -LANG:std -n32 -mips4 -LDOPTS=-shared - -OBJ=classes.o conversions.o errors.o extension_class.o functions.o \ - init_function.o module_builder.o \ - objects.o types.o cross_module.o -DEPOBJ=$(OBJ) \ - comprehensive.o \ - abstract.o \ - getting_started1.o getting_started2.o \ - simple_vector.o \ - do_it_yourself_convts.o \ - nested.o \ - pickle1.o pickle2.o pickle3.o \ - noncopyable_export.o noncopyable_import.o \ - ivect.o dvect.o \ - richcmp1.o richcmp2.o richcmp3.o - -.SUFFIXES: .o .cpp - -all: libboost_python.a \ - boost_python_test.so \ - abstract.so \ - getting_started1.so getting_started2.so \ - simple_vector.so \ - do_it_yourself_convts.so \ - nested.so \ - pickle1.so pickle2.so pickle3.so \ - noncopyable_export.so noncopyable_import.so \ - ivect.so dvect.so \ - richcmp1.so richcmp2.so richcmp3.so - -libboost_python.a: $(OBJ) - rm -f libboost_python.a - $(CPP) -ar -o libboost_python.a $(OBJ) - -boost_python_test.so: $(OBJ) comprehensive.o - $(LD) $(LDOPTS) $(OBJ) comprehensive.o -o boost_python_test.so -lm - -abstract.so: $(OBJ) abstract.o - $(LD) $(LDOPTS) $(OBJ) abstract.o -o abstract.so - -getting_started1.so: $(OBJ) getting_started1.o - $(LD) $(LDOPTS) $(OBJ) getting_started1.o -o getting_started1.so - -getting_started2.so: $(OBJ) getting_started2.o - $(LD) $(LDOPTS) $(OBJ) getting_started2.o -o getting_started2.so - -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 - -pickle1.so: $(OBJ) pickle1.o - $(LD) $(LDOPTS) $(OBJ) pickle1.o -o pickle1.so - -pickle2.so: $(OBJ) pickle2.o - $(LD) $(LDOPTS) $(OBJ) pickle2.o -o pickle2.so - -pickle3.so: $(OBJ) pickle3.o - $(LD) $(LDOPTS) $(OBJ) pickle3.o -o pickle3.so - -noncopyable_export.so: $(OBJ) noncopyable_export.o - $(LD) $(LDOPTS) $(OBJ) $(HIDDEN) \ - noncopyable_export.o -o noncopyable_export.so - -noncopyable_import.so: $(OBJ) noncopyable_import.o - $(LD) $(LDOPTS) $(OBJ) $(HIDDEN) \ - noncopyable_import.o -o noncopyable_import.so - -ivect.so: $(OBJ) ivect.o - $(LD) $(LDOPTS) $(OBJ) $(HIDDEN) ivect.o -o ivect.so - -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 - -test: - $(PYEXE) comprehensive.py - $(PYEXE) test_abstract.py - $(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_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 - rm -f comprehensive.o boost_python_test.so - rm -f abstract.o abstract.so - 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 pickle1.o pickle1.so - rm -f pickle2.o pickle2.so - rm -f pickle3.o pickle3.so - rm -f noncopyable_export.o noncopyable_export.so - 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 - -softlinks: - $(PYEXE) $(BOOST)/libs/python/build/filemgr.py $(BOOST) softlinks - -unlink: - $(PYEXE) $(BOOST)/libs/python/build/filemgr.py $(BOOST) unlink - -cp: - $(PYEXE) $(BOOST)/libs/python/build/filemgr.py $(BOOST) cp - -rm: - $(PYEXE) $(BOOST)/libs/python/build/filemgr.py $(BOOST) rm - -depend: - @ cat Makefile.nodepend; \ - for obj in $(DEPOBJ); \ - do \ - bn=`echo "$$obj" | cut -d. -f1`; \ - $(CPP) $(CPPOPTS) $(MAKEDEP) "$$bn".cpp; \ - done - diff --git a/build/linux_gcc.mak b/build/linux_gcc.mak deleted file mode 100644 index 3b466e7d..00000000 --- a/build/linux_gcc.mak +++ /dev/null @@ -1,184 +0,0 @@ -# Usage: -# -# Create a new empty directory anywhere (preferably not in the boost tree). -# Copy this Makefile to that new directory and rename it to "Makefile" -# Adjust the pathnames below. -# -# make softlinks Create softlinks to source code and tests -# make Compile all sources -# make test Run doctest tests -# make clean Remove all object files -# make unlink Remove softlinks -# -# Revision history: -# 12 Apr 01 new macro ROOT to simplify configuration (R.W. Grosse-Kunstleve) -# Initial version: R.W. Grosse-Kunstleve - -ROOT=$(HOME) -BOOST=$(ROOT)/boost - -#PYEXE=PYTHONPATH=. /usr/bin/python -#PYINC=-I/usr/include/python1.5 -#PYEXE=PYTHONPATH=. /usr/local/Python-1.5.2/bin/python -#PYINC=-I/usr/local/Python-1.5.2/include/python1.5 -PYEXE=PYTHONPATH=. /usr/local_cci/Python-2.1.1/bin/python -PYINC=-I/usr/local_cci/Python-2.1.1/include/python2.1 - -STDOPTS=-fPIC -ftemplate-depth-21 -WARNOPTS= -OPTOPTS=-g - -CPP=g++ -CPPOPTS=$(STLPORTINC) $(STLPORTOPTS) -I$(BOOST) $(PYINC) \ - $(STDOPTS) $(WARNOPTS) $(OPTOPTS) -MAKEDEP=-M - -LD=$(CPP) -LDOPTS=-shared - -OBJ=classes.o conversions.o errors.o extension_class.o functions.o \ - init_function.o module_builder.o \ - objects.o types.o cross_module.o -DEPOBJ=$(OBJ) \ - comprehensive.o \ - abstract.o \ - getting_started1.o getting_started2.o \ - simple_vector.o \ - do_it_yourself_convts.o \ - nested.o \ - pickle1.o pickle2.o pickle3.o \ - noncopyable_export.o noncopyable_import.o \ - ivect.o dvect.o \ - richcmp1.o richcmp2.o richcmp3.o - -.SUFFIXES: .o .cpp - -all: libboost_python.a \ - boost_python_test.so \ - abstract.so \ - getting_started1.so getting_started2.so \ - simple_vector.so \ - do_it_yourself_convts.so \ - nested.so \ - pickle1.so pickle2.so pickle3.so \ - noncopyable_export.so noncopyable_import.so \ - ivect.so dvect.so \ - richcmp1.so richcmp2.so richcmp3.so - -libboost_python.a: $(OBJ) - rm -f libboost_python.a - ar r libboost_python.a $(OBJ) - -boost_python_test.so: $(OBJ) comprehensive.o - $(LD) $(LDOPTS) $(OBJ) comprehensive.o -o boost_python_test.so -lm - -abstract.so: $(OBJ) abstract.o - $(LD) $(LDOPTS) $(OBJ) abstract.o -o abstract.so - -getting_started1.so: $(OBJ) getting_started1.o - $(LD) $(LDOPTS) $(OBJ) getting_started1.o -o getting_started1.so - -getting_started2.so: $(OBJ) getting_started2.o - $(LD) $(LDOPTS) $(OBJ) getting_started2.o -o getting_started2.so - -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 - -pickle1.so: $(OBJ) pickle1.o - $(LD) $(LDOPTS) $(OBJ) pickle1.o -o pickle1.so - -pickle2.so: $(OBJ) pickle2.o - $(LD) $(LDOPTS) $(OBJ) pickle2.o -o pickle2.so - -pickle3.so: $(OBJ) pickle3.o - $(LD) $(LDOPTS) $(OBJ) pickle3.o -o pickle3.so - -noncopyable_export.so: $(OBJ) noncopyable_export.o - $(LD) $(LDOPTS) $(OBJ) $(HIDDEN) \ - noncopyable_export.o -o noncopyable_export.so - -noncopyable_import.so: $(OBJ) noncopyable_import.o - $(LD) $(LDOPTS) $(OBJ) $(HIDDEN) \ - noncopyable_import.o -o noncopyable_import.so - -ivect.so: $(OBJ) ivect.o - $(LD) $(LDOPTS) $(OBJ) $(HIDDEN) ivect.o -o ivect.so - -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 - -test: - $(PYEXE) comprehensive.py - $(PYEXE) test_abstract.py - $(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_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 - rm -f comprehensive.o boost_python_test.so - rm -f abstract.o abstract.so - 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 pickle1.o pickle1.so - rm -f pickle2.o pickle2.so - rm -f pickle3.o pickle3.so - rm -f noncopyable_export.o noncopyable_export.so - 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: - $(PYEXE) $(BOOST)/libs/python/build/filemgr.py $(BOOST) softlinks - -unlink: - $(PYEXE) $(BOOST)/libs/python/build/filemgr.py $(BOOST) unlink - -cp: - $(PYEXE) $(BOOST)/libs/python/build/filemgr.py $(BOOST) cp - -rm: - $(PYEXE) $(BOOST)/libs/python/build/filemgr.py $(BOOST) rm - -depend: - @ cat Makefile.nodepend; \ - for obj in $(DEPOBJ); \ - do \ - bn=`echo "$$obj" | cut -d. -f1`; \ - $(CPP) $(CPPOPTS) $(MAKEDEP) "$$bn".cpp; \ - done - diff --git a/build/mingw32.mak b/build/mingw32.mak deleted file mode 100644 index d8c31b68..00000000 --- a/build/mingw32.mak +++ /dev/null @@ -1,222 +0,0 @@ -# Usage: -# -# make copy Copy the sources and tests -# make Compile all sources -# make test Run doctest tests -# make clean Remove all object files -# make del Remove the sources and tests -# -# Revision history: -# 12 Apr 01 new macro ROOT to simplify configuration (R.W. Grosse-Kunstleve) -# Initial version: R.W. Grosse-Kunstleve - -# To install mingw32, follow instructions at: -# http://starship.python.net/crew/kernr/mingw32/Notes.html -# In particular, install: -# ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/gcc-2.95.2/gcc-2.95.2-msvcrt.exe -# ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/gcc-2.95.2/fixes/quote-fix-msvcrt.exe -# http://starship.python.net/crew/kernr/mingw32/Python-1.5.2-mingw32.zip -# Unpack the first two archives in the default locations and update your PATH. -# Unpack the third archive in \usr. - -# Note: comprehensive.cpp generates compiler errors and later crashes. -# L:\boost\boost\python\detail\extension_class.hpp:643: warning: -# alignment of `vtable for class -# boost::python::detail::held_instance' -# is greater than maximum object file alignment. Using 16. -# Could this be fixed with compiler options? -# -fhuge-objects looks interesting, but requires recompiling the C++ library. -# (what exactly does that mean?) -# -fvtable-thunks eliminates the compiler warning, but -# "import boost_python_test" still causes a crash. - -ROOT=R: -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= -OPTOPTS=-g - -CPP=g++ -CPPOPTS=$(STLPORTINC) $(STLPORTOPTS) -I$(BOOST_WIN) $(PYINC) \ - $(STDOPTS) $(WARNOPTS) $(OPTOPTS) - -LD=g++ -LDOPTS=-shared - -OBJ=classes.o conversions.o errors.o extension_class.o functions.o \ - init_function.o module_builder.o \ - objects.o types.o cross_module.o - -.SUFFIXES: .o .cpp - -all: libboost_python.a \ - abstract.pyd \ - getting_started1.pyd getting_started2.pyd \ - simple_vector.pyd \ - do_it_yourself_convts.pyd \ - nested.pyd \ - pickle1.pyd pickle2.pyd pickle3.pyd \ - noncopyable_export.pyd noncopyable_import.pyd \ - ivect.pyd dvect.pyd \ - richcmp1.pyd richcmp2.pyd richcmp3.pyd - -libboost_python.a: $(OBJ) - -del libboost_python.a - ar r libboost_python.a $(OBJ) - -DLLWRAPOPTS=-s --driver-name g++ -s \ - --entry _DllMainCRTStartup@12 --target=i386-mingw32 - -boost_python_test.pyd: $(OBJ) comprehensive.o - dllwrap $(DLLWRAPOPTS) \ - --dllname boost_python_test.pyd \ - --def boost_python_test.def \ - $(OBJ) comprehensive.o $(PYLIB) - -abstract.pyd: $(OBJ) abstract.o - dllwrap $(DLLWRAPOPTS) \ - --dllname abstract.pyd \ - --def abstract.def \ - $(OBJ) abstract.o $(PYLIB) - -getting_started1.pyd: $(OBJ) getting_started1.o - dllwrap $(DLLWRAPOPTS) \ - --dllname getting_started1.pyd \ - --def getting_started1.def \ - $(OBJ) getting_started1.o $(PYLIB) - -getting_started2.pyd: $(OBJ) getting_started2.o - dllwrap $(DLLWRAPOPTS) \ - --dllname getting_started2.pyd \ - --def getting_started2.def \ - $(OBJ) getting_started2.o $(PYLIB) - -simple_vector.pyd: $(OBJ) simple_vector.o - dllwrap $(DLLWRAPOPTS) \ - --dllname simple_vector.pyd \ - --def simple_vector.def \ - $(OBJ) simple_vector.o $(PYLIB) - -do_it_yourself_convts.pyd: $(OBJ) do_it_yourself_convts.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) - -pickle1.pyd: $(OBJ) pickle1.o - dllwrap $(DLLWRAPOPTS) \ - --dllname pickle1.pyd \ - --def pickle1.def \ - $(OBJ) pickle1.o $(PYLIB) - -pickle2.pyd: $(OBJ) pickle2.o - dllwrap $(DLLWRAPOPTS) \ - --dllname pickle2.pyd \ - --def pickle2.def \ - $(OBJ) pickle2.o $(PYLIB) - -pickle3.pyd: $(OBJ) pickle3.o - dllwrap $(DLLWRAPOPTS) \ - --dllname pickle3.pyd \ - --def pickle3.def \ - $(OBJ) pickle3.o $(PYLIB) - -noncopyable_export.pyd: $(OBJ) noncopyable_export.o - dllwrap $(DLLWRAPOPTS) \ - --dllname noncopyable_export.pyd \ - --def noncopyable_export.def \ - $(OBJ) noncopyable_export.o $(PYLIB) - -noncopyable_import.pyd: $(OBJ) noncopyable_import.o - dllwrap $(DLLWRAPOPTS) \ - --dllname noncopyable_import.pyd \ - --def noncopyable_import.def \ - $(OBJ) noncopyable_import.o $(PYLIB) - -ivect.pyd: $(OBJ) ivect.o - dllwrap $(DLLWRAPOPTS) \ - --dllname ivect.pyd \ - --def ivect.def \ - $(OBJ) ivect.o $(PYLIB) - -dvect.pyd: $(OBJ) dvect.o - dllwrap $(DLLWRAPOPTS) \ - --dllname dvect.pyd \ - --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 - -test: -# $(PYEXE) comprehensive.py - $(PYEXE) test_abstract.py - $(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_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 - -softlinks: - python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) softlinks - -unlink: - python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) unlink - -cp: - python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) cp - -rm: - python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) rm - -copy: - $(PYEXE) $(BOOST_WIN)\libs\python\build\filemgr.py $(BOOST_WIN) copy - -del: - $(PYEXE) $(BOOST_WIN)\libs\python\build\filemgr.py $(BOOST_WIN) del diff --git a/build/tru64_cxx.mak b/build/tru64_cxx.mak deleted file mode 100644 index a64927b1..00000000 --- a/build/tru64_cxx.mak +++ /dev/null @@ -1,199 +0,0 @@ -# Usage: -# -# Create a new empty directory anywhere (preferably not in the boost tree). -# Copy this Makefile to that new directory and rename it to "Makefile" -# Adjust the pathnames below. -# -# make softlinks Create softlinks to source code and tests -# make Compile all sources -# make test Run doctest tests -# make clean Remove all object files -# make unlink Remove softlinks -# -# Revision history: -# 12 Apr 01 new macro ROOT to simplify configuration (R.W. Grosse-Kunstleve) -# Initial version: R.W. Grosse-Kunstleve - -ROOT=$(HOME) -BOOST=$(ROOT)/boost - -#PYEXE=PYTHONPATH=. /usr/local/Python-1.5.2/bin/python -#PYINC=-I/usr/local/Python-1.5.2/include/python1.5 -PYEXE=PYTHONPATH=. /usr/local_cci/Python-2.1.1/bin/python -PYINC=-I/usr/local_cci/Python-2.1.1/include/python2.1 -#STLPORTINC=-I/usr/local/STLport-4.1b3/stlport -#STLPORTINC=-I/usr/local/STLport-4.1b4/stlport -#STLPORTOPTS= \ -# -D__USE_STD_IOSTREAM \ -# -D__STL_NO_SGI_IOSTREAMS \ -# -D__STL_USE_NATIVE_STRING \ -# -D__STL_NO_NEW_C_HEADERS \ -# -D_RWSTD_COMPILE_INSTANTIATE=1 -STLPORTINC=-I$(BOOST)/boost/compatibility/cpp_c_headers - -STDOPTS=-std strict_ansi -# use -msg_display_number to obtain integer tags for -msg_disable -WARNOPTS=-msg_disable 186,450,1115 -OPTOPTS=-g - -CPP=cxx -CPPOPTS=$(STLPORTINC) $(STLPORTOPTS) -I$(BOOST) $(PYINC) \ - $(STDOPTS) $(WARNOPTS) $(OPTOPTS) -MAKEDEP=-Em - -LD=cxx -LDOPTS=-shared -expect_unresolved 'Py*' -expect_unresolved '_Py*' - -#HIDDEN=-hidden - -OBJ=classes.o conversions.o errors.o extension_class.o functions.o \ - init_function.o module_builder.o \ - objects.o types.o cross_module.o -DEPOBJ=$(OBJ) \ - comprehensive.o \ - abstract.o \ - getting_started1.o getting_started2.o \ - simple_vector.o \ - do_it_yourself_convts.o \ - nested.o \ - pickle1.o pickle2.o pickle3.o \ - noncopyable_export.o noncopyable_import.o \ - ivect.o dvect.o \ - richcmp1.o richcmp2.o richcmp3.o - -.SUFFIXES: .o .cpp - -all: libboost_python.a \ - boost_python_test.so \ - abstract.so \ - getting_started1.so getting_started2.so \ - simple_vector.so \ - do_it_yourself_convts.so \ - nested.so \ - pickle1.so pickle2.so pickle3.so \ - noncopyable_export.so noncopyable_import.so \ - ivect.so dvect.so \ - richcmp1.so richcmp2.so richcmp3.so - -libboost_python.a: $(OBJ) - rm -f libboost_python.a - cd cxx_repository; \ - ls -1 > ../libboost_python.a.input; \ - ar r ../libboost_python.a -input ../libboost_python.a.input - rm -f libboost_python.a.input - ar r libboost_python.a $(OBJ) - -boost_python_test.so: $(OBJ) comprehensive.o - $(LD) $(LDOPTS) $(OBJ) comprehensive.o -o boost_python_test.so -lm - -abstract.so: $(OBJ) abstract.o - $(LD) $(LDOPTS) $(OBJ) abstract.o -o abstract.so - -getting_started1.so: $(OBJ) getting_started1.o - $(LD) $(LDOPTS) $(OBJ) getting_started1.o -o getting_started1.so - -getting_started2.so: $(OBJ) getting_started2.o - $(LD) $(LDOPTS) $(OBJ) getting_started2.o -o getting_started2.so - -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 - -pickle1.so: $(OBJ) pickle1.o - $(LD) $(LDOPTS) $(OBJ) pickle1.o -o pickle1.so - -pickle2.so: $(OBJ) pickle2.o - $(LD) $(LDOPTS) $(OBJ) pickle2.o -o pickle2.so - -pickle3.so: $(OBJ) pickle3.o - $(LD) $(LDOPTS) $(OBJ) pickle3.o -o pickle3.so - -noncopyable_export.so: $(OBJ) noncopyable_export.o - $(LD) $(LDOPTS) $(OBJ) $(HIDDEN) \ - noncopyable_export.o -o noncopyable_export.so - -noncopyable_import.so: $(OBJ) noncopyable_import.o - $(LD) $(LDOPTS) $(OBJ) $(HIDDEN) \ - noncopyable_import.o -o noncopyable_import.so - -ivect.so: $(OBJ) ivect.o - $(LD) $(LDOPTS) $(OBJ) $(HIDDEN) ivect.o -o ivect.so - -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 - -test: - $(PYEXE) comprehensive.py - $(PYEXE) test_abstract.py - $(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_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 - rm -f comprehensive.o boost_python_test.so - rm -f abstract.o abstract.so - 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 pickle1.o pickle1.so - rm -f pickle2.o pickle2.so - rm -f pickle3.o pickle3.so - rm -f noncopyable_export.o noncopyable_export.so - 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 - -softlinks: - $(PYEXE) $(BOOST)/libs/python/build/filemgr.py $(BOOST) softlinks - -unlink: - $(PYEXE) $(BOOST)/libs/python/build/filemgr.py $(BOOST) unlink - -cp: - $(PYEXE) $(BOOST)/libs/python/build/filemgr.py $(BOOST) cp - -rm: - $(PYEXE) $(BOOST)/libs/python/build/filemgr.py $(BOOST) rm - -depend: - @ cat Makefile.nodepend; \ - for obj in $(DEPOBJ); \ - do \ - bn=`echo "$$obj" | cut -d. -f1`; \ - $(CPP) $(CPPOPTS) $(MAKEDEP) "$$bn".cpp; \ - done - diff --git a/build/vc60.mak b/build/vc60.mak deleted file mode 100644 index 2903c0c7..00000000 --- a/build/vc60.mak +++ /dev/null @@ -1,154 +0,0 @@ -# Usage: -# -# Create a new empty directory anywhere (preferably not in the boost tree). -# Copy this Makefile to that new directory and rename it to "Makefile" -# Adjust the pathnames below. -# -# make copy Copy the sources and tests -# make Compile all sources -# make test Run doctest tests -# make clean Remove all object files -# make del Remove the sources and tests -# -# Revision history: -# 12 Apr 01 new macro ROOT to simplify configuration (R.W. Grosse-Kunstleve) -# Initial version: R.W. Grosse-Kunstleve - -ROOT=R: -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 /Zm300 /DBOOST_PYTHON_STATIC_LIB -WARNOPTS= -OPTOPTS= - -CPP=cl.exe -CPPOPTS=$(STLPORTINC) $(STLPORTOPTS) /I$(BOOST_WIN) $(PYINC) \ - $(STDOPTS) $(WARNOPTS) $(OPTOPTS) - -LD=link.exe -LDOPTS=/nologo /dll /incremental:no - -OBJ=classes.obj conversions.obj errors.obj extension_class.obj functions.obj \ - init_function.obj module_builder.obj \ - objects.obj types.obj cross_module.obj - -.SUFFIXES: .obj .cpp - -all: boost_python.lib \ - boost_python_test.pyd \ - abstract.pyd \ - getting_started1.pyd getting_started2.pyd \ - simple_vector.pyd \ - do_it_yourself_convts.pyd \ - nested.pyd \ - pickle1.pyd pickle2.pyd pickle3.pyd \ - noncopyable_export.pyd noncopyable_import.pyd \ - ivect.pyd dvect.pyd \ - richcmp1.pyd richcmp2.pyd richcmp3.pyd - -boost_python.lib: $(OBJ) - $(LD) -lib /nologo /out:boost_python.lib $(OBJ) - -boost_python_test.pyd: $(OBJ) comprehensive.obj - $(LD) $(LDOPTS) $(OBJ) comprehensive.obj $(PYLIB) /export:initboost_python_test /out:"boost_python_test.pyd" - -abstract.pyd: $(OBJ) abstract.obj - $(LD) $(LDOPTS) $(OBJ) abstract.obj $(PYLIB) /export:initabstract /out:"abstract.pyd" - -getting_started1.pyd: $(OBJ) getting_started1.obj - $(LD) $(LDOPTS) $(OBJ) getting_started1.obj $(PYLIB) /export:initgetting_started1 /out:"getting_started1.pyd" - -getting_started2.pyd: $(OBJ) getting_started2.obj - $(LD) $(LDOPTS) $(OBJ) getting_started2.obj $(PYLIB) /export:initgetting_started2 /out:"getting_started2.pyd" - -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" - -pickle1.pyd: $(OBJ) pickle1.obj - $(LD) $(LDOPTS) $(OBJ) pickle1.obj $(PYLIB) /export:initpickle1 /out:"pickle1.pyd" - -pickle2.pyd: $(OBJ) pickle2.obj - $(LD) $(LDOPTS) $(OBJ) pickle2.obj $(PYLIB) /export:initpickle2 /out:"pickle2.pyd" - -pickle3.pyd: $(OBJ) pickle3.obj - $(LD) $(LDOPTS) $(OBJ) pickle3.obj $(PYLIB) /export:initpickle3 /out:"pickle3.pyd" - -noncopyable_export.pyd: $(OBJ) noncopyable_export.obj - $(LD) $(LDOPTS) $(OBJ) noncopyable_export.obj $(PYLIB) /export:initnoncopyable_export /out:"noncopyable_export.pyd" - -noncopyable_import.pyd: $(OBJ) noncopyable_import.obj - $(LD) $(LDOPTS) $(OBJ) noncopyable_import.obj $(PYLIB) /export:initnoncopyable_import /out:"noncopyable_import.pyd" - -ivect.pyd: $(OBJ) ivect.obj - $(LD) $(LDOPTS) $(OBJ) ivect.obj $(PYLIB) /export:initivect /out:"ivect.pyd" - -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 - -test: - $(PYEXE) comprehensive.py --broken-auto-ptr - $(PYEXE) test_abstract.py - $(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_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 - -softlinks: - python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) softlinks - -unlink: - python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) unlink - -cp: - python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) cp - -rm: - python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) rm - -copy: - $(PYEXE) $(BOOST_WIN)\libs\python\build\filemgr.py $(BOOST_WIN) copy - -del: - $(PYEXE) $(BOOST_WIN)\libs\python\build\filemgr.py $(BOOST_WIN) del diff --git a/build/win32_mwcc.mak b/build/win32_mwcc.mak deleted file mode 100755 index c49af71c..00000000 --- a/build/win32_mwcc.mak +++ /dev/null @@ -1,149 +0,0 @@ -# Usage: -# -# make copy Copy the sources and tests -# make Compile all sources -# make test Run doctest tests -# make clean Remove all object files -# make del Remove the sources and tests -# -# Revision history: -# 14 Dec 01 derived from vc60.mak (R.W. Grosse-Kunstleve) - -ROOT=R: -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=-gccinc -prefix UseDLLPrefix.h -DBOOST_PYTHON_STATIC_LIB -WARNOPTS=-warn on,nounusedexpr,nounused -OPTOPTS=-O - -CPP=mwcc -CPPOPTS=$(STDOPTS) $(WARNOPTS) $(OPTOPTS) \ - $(STLPORTINC) $(STLPORTOPTS) -I$(BOOST_WIN) $(PYINC) - -LD=mwld -LDOPTS=-export dllexport -shared - -OBJ=classes.obj conversions.obj errors.obj extension_class.obj functions.obj \ - init_function.obj module_builder.obj \ - objects.obj types.obj cross_module.obj - -.SUFFIXES: .obj .cpp - -all: libboost_python.lib \ - boost_python_test.pyd \ - abstract.pyd \ - getting_started1.pyd getting_started2.pyd \ - simple_vector.pyd \ - do_it_yourself_convts.pyd \ - nested.pyd \ - pickle1.pyd pickle2.pyd pickle3.pyd \ - noncopyable_export.pyd noncopyable_import.pyd \ - ivect.pyd dvect.pyd \ - richcmp1.pyd richcmp2.pyd richcmp3.pyd - -libboost_python.lib: $(OBJ) - $(LD) -library -o libboost_python.lib $(OBJ) - -boost_python_test.pyd: $(OBJ) comprehensive.obj - $(LD) $(LDOPTS) $(OBJ) comprehensive.obj $(PYLIB) -o boost_python_test.pyd - -abstract.pyd: $(OBJ) abstract.obj - $(LD) $(LDOPTS) $(OBJ) abstract.obj $(PYLIB) -o abstract.pyd - -getting_started1.pyd: $(OBJ) getting_started1.obj - $(LD) $(LDOPTS) $(OBJ) getting_started1.obj $(PYLIB) -o getting_started1.pyd - -getting_started2.pyd: $(OBJ) getting_started2.obj - $(LD) $(LDOPTS) $(OBJ) getting_started2.obj $(PYLIB) -o getting_started2.pyd - -simple_vector.pyd: $(OBJ) simple_vector.obj - $(LD) $(LDOPTS) $(OBJ) simple_vector.obj $(PYLIB) -o simple_vector.pyd - -do_it_yourself_convts.pyd: $(OBJ) do_it_yourself_convts.obj - $(LD) $(LDOPTS) $(OBJ) do_it_yourself_convts.obj $(PYLIB) -o do_it_yourself_convts.pyd - -nested.pyd: $(OBJ) nested.obj - $(LD) $(LDOPTS) $(OBJ) nested.obj $(PYLIB) -o nested.pyd - -pickle1.pyd: $(OBJ) pickle1.obj - $(LD) $(LDOPTS) $(OBJ) pickle1.obj $(PYLIB) -o pickle1.pyd - -pickle2.pyd: $(OBJ) pickle2.obj - $(LD) $(LDOPTS) $(OBJ) pickle2.obj $(PYLIB) -o pickle2.pyd - -pickle3.pyd: $(OBJ) pickle3.obj - $(LD) $(LDOPTS) $(OBJ) pickle3.obj $(PYLIB) -o pickle3.pyd - -noncopyable_export.pyd: $(OBJ) noncopyable_export.obj - $(LD) $(LDOPTS) $(OBJ) noncopyable_export.obj $(PYLIB) -o noncopyable_export.pyd - -noncopyable_import.pyd: $(OBJ) noncopyable_import.obj - $(LD) $(LDOPTS) $(OBJ) noncopyable_import.obj $(PYLIB) -o noncopyable_import.pyd - -ivect.pyd: $(OBJ) ivect.obj - $(LD) $(LDOPTS) $(OBJ) ivect.obj $(PYLIB) -o ivect.pyd - -dvect.pyd: $(OBJ) dvect.obj - $(LD) $(LDOPTS) $(OBJ) dvect.obj $(PYLIB) -o dvect.pyd - -richcmp1.pyd: $(OBJ) richcmp1.obj - $(LD) $(LDOPTS) $(OBJ) richcmp1.obj $(PYLIB) -o richcmp1.pyd - -richcmp2.pyd: $(OBJ) richcmp2.obj - $(LD) $(LDOPTS) $(OBJ) richcmp2.obj $(PYLIB) -o richcmp2.pyd - -richcmp3.pyd: $(OBJ) richcmp3.obj - $(LD) $(LDOPTS) $(OBJ) richcmp3.obj $(PYLIB) -o richcmp3.pyd - -.cpp.obj: - $(CPP) $(CPPOPTS) -c $*.cpp - -test: - $(PYEXE) comprehensive.py - $(PYEXE) test_abstract.py - $(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_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 *.obj - -del *.lib - -del *.exp - -del *.idb - -del *.pyd - -del *.pyc - -softlinks: - python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) softlinks - -unlink: - python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) unlink - -cp: - python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) cp - -rm: - python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) rm - -copy: - $(PYEXE) $(BOOST_WIN)\libs\python\build\filemgr.py $(BOOST_WIN) copy - -del: - $(PYEXE) $(BOOST_WIN)\libs\python\build\filemgr.py $(BOOST_WIN) del diff --git a/build/win32_mwcc_setup.bat b/build/win32_mwcc_setup.bat deleted file mode 100755 index 30f84be8..00000000 --- a/build/win32_mwcc_setup.bat +++ /dev/null @@ -1,2 +0,0 @@ -call "c:\program files\metrowerks\codewarrior\other metrowerks tools\command line tools\cwenv.bat" -set MWWinx86LibraryFiles=MSL_All-DLL_x86.lib;gdi32.lib;user32.lib;kernel32.lib diff --git a/doc/v2/CallPolicies.html b/doc/v2/CallPolicies.html index 3c2b98fd..9d582e7d 100644 --- a/doc/v2/CallPolicies.html +++ b/doc/v2/CallPolicies.html @@ -1,124 +1,152 @@ + + - - - -Boost.Python - CallPolicies Concept - - - + + + + + Boost.Python - CallPolicies Concept + + + +
- - - - -
-

C++ Boost

-
-

Boost.Python

-

CallPolicies Concept

-
-
-
-
Introduction
-
CallPolicies Composition
-
Concept Requirements
-
-
CallPolicies Concept
-
-
+ + +

C++ Boost

+ -

Introduction

+ +

Boost.Python

-

Models of the CallPolicies concept are used to specialize the -behavior of Python callable objects generated by Boost.Python to -wrapped C++ objects like function and member function -pointers, providing three behaviors: -

    -
  1. precall - Python argument tuple management before -the wrapped object is invoked -
  2. result_converter - C++ return value handling -
  3. postcall - Python argument tuple and result -management after the wrapped object is invoked -
+

CallPolicies Concept

+ + + +
-

CallPolicies Composition

+
+
Introduction
-In order to allow the use of multiple models of CallPolicies in the -same callable object, Boost.Python's CallPolicies class templates -provide a chaining interface which allows them to be recursively -composed. This interface takes the form of an optional template -parameter, Base which defaults to -default_call_policies. By convention, the -precall function of the -Base is invoked after the precall -function supplied by the outer template, and the postcall -function of the Base is invoked before the -postcall function of the outer template. If a -result_converter is supplied by the outer template, it -replaces any result_converter supplied by the -Base. For an example, see -return_internal_reference. +
CallPolicies Composition
-

Concept Requirements

-

CallPolicies Concept

+
Concept Requirements
-

In the table below, x denotes an object whose -type P is a model of CallPolicies, -a denotes a PyObject* pointing to -a Python argument tuple object, and r denotes a -PyObject* referring to a "preliminary" result -object. +

+
+
CallPolicies Concept
+
+
+
- +

Introduction

- - - - - +

Models of the CallPolicies concept are used to specialize the behavior + of Python callable objects generated by Boost.Python to wrapped C++ + objects like function and member function pointers, providing three + behaviors:

- - - - - - -
ExpressionTypeResult/Semantics
x.precall(a)convertible to bool - returns false and PyErr_Occurred() != 0 - upon failure, true otherwise. +
    +
  1. precall - Python argument tuple management before the + wrapped object is invoked
  2. -
P::result_converterA model of ResultConverterGenerator. - An MPL unarymetafunction object used produce the - "preliminary" result object. +
  • result_converter - C++ return value handling
  • -
    x.postcall(a, r)convertible to PyObject* - 0 0 and PyErr_Occurred() != 0 - upon failure. Must "conserve references" even in the - event of an exception. In other words, if r is not - returned, its reference count must be decremented; if another - existing object is returned, its reference count must be - incremented. -
    +
  • postcall - Python argument tuple and result management + after the wrapped object is invoked
  • + -Models of CallPolicies are required to be CopyConstructible. +

    CallPolicies Composition

    + In order to allow the use of multiple models of CallPolicies in the same + callable object, Boost.Python's CallPolicies class templates provide a + chaining interface which allows them to be recursively composed. This + interface takes the form of an optional template parameter, + Base which defaults to default_call_policies. + By convention, the precall function of the Base + is invoked after the precall function supplied by the + outer template, and the postcall function of the + Base is invoked before the postcall + function of the outer template. If a result_converter is + supplied by the outer template, it replaces any + result_converter supplied by the Base. For an + example, see return_internal_reference. + -
    -

    Revised - - 19 May, 2002 - -

    -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    Concept Requirements

    -

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

    CallPolicies Concept

    + +

    In the table below, x denotes an object whose type + P is a model of CallPolicies, a + denotes a PyObject* pointing to a Python argument tuple + object, and r denotes a PyObject* + referring to a "preliminary" result object.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ExpressionTypeResult/Semantics
    x.precall(a)convertible to boolreturns false and PyErr_Occurred() != 0 + upon failure, true otherwise.
    P::result_converterA model of ResultConverterGenerator.An MPL unary Metafunction + Class used produce the "preliminary" result object.
    x.postcall(a, r)convertible to PyObject*0 0 and PyErr_Occurred() != 0 + upon failure. Must "conserve references" even in the event of an + exception. In other words, if r is not returned, its + reference count must be decremented; if another existing object is + returned, its reference count must be incremented.
    + Models of CallPolicies are required to be CopyConstructible. +
    + +

    Revised + + 19 May, 2002 +

    + +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + +

    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.

    + + diff --git a/doc/v2/call_method.html b/doc/v2/call_method.html index f2c52a9b..86f6c9d5 100644 --- a/doc/v2/call_method.html +++ b/doc/v2/call_method.html @@ -1,74 +1,89 @@ + + - - - -Boost.Python - <call_method.hpp> - - - + + + + + Boost.Python - <call_method.hpp> + + + +
    - - - - -
    -

    -

    -
    -

    Boost.Python

    -

    Header <call_method.hpp>

    -
    -
    -

    Contents

    -
    -
    Introduction
    -
    Functions
    -
    -
    call_method
    -
    + + +

    C++ Boost

    + -
    Example(s)
    + +

    Boost.Python

    -
    -
    -

    Introduction

    -

    - <boost/python/call_method.hpp> defines the call_method family of overloaded function - templates, used to invoke callable attributes of Python objects from C++. +

    Header <call_method.hpp>

    + + + +
    -

    Functions

    +

    Contents

    + +
    +
    Introduction
    + +
    Functions
    + +
    +
    +
    call_method
    +
    +
    + +
    Example(s)
    +
    +
    + +

    Introduction

    + +

    <boost/python/call_method.hpp> defines the call_method family of overloaded + function templates, used to invoke callable attributes of Python objects + from C++.

    + +

    Functions

    -template <class R, class A1, class A2, ... class An>
    +template <class R, class A1, class A2, ... class An>
     R call_method(PyObject* self, char const* method, A1 const&, A2 const&, ... An const&)
     
    -
    -
    Requires: R is a pointer type, reference - type, or a complete type with an accessible copy constructor
    -
    Effects: Invokes self.method(a1, a2, ...an) in - Python, where a1...an are the arguments to - call_method(), converted to Python objects. For a - complete semantic description, see this - page. +
    +
    Requires: R is a pointer type, reference type, + or a complete type with an accessible copy constructor
    -
    Returns: The result of the Python call, converted to the - C++ type R.
    +
    Effects: Invokes + self.method(a1, a2, ...an) in + Python, where a1...an are the + arguments to call_method(), converted to Python objects. + For a complete semantic description, see this + page.
    -
    -
    Rationale: call_method is critical to - implementing C++ virtual functions which are overridable in Python, - as shown by the example below. -
    -
    +
    Returns: The result of the Python call, converted to the C++ + type R.
    -

    Example(s)

    +
    Rationale: call_method is critical to + implementing C++ virtual functions which are overridable in Python, as + shown by the example below.
    + -The following C++ illustrates the use of call_method in -wrapping a class with a virtual function that can be overridden in -Python: +

    Example(s)

    + The following C++ illustrates the use of call_method in + wrapping a class with a virtual function that can be overridden in + Python: -

    C++ Module Definition

    +

    C++ Module Definition

     #include <boost/python/module.hpp>
     #include <boost/python/class.hpp>
    @@ -79,13 +94,13 @@ Python:
     class Base
     {
      public:
    -   virtual char const* class_name() const { return "Base"; }
    +   virtual char const* class_name() const { return "Base"; }
        virtual ~Base();
     };
     
     bool is_base(Base* b)
     {
    -   return !std::strcmp(b->class_name(), "Base");
    +   return !std::strcmp(b->class_name(), "Base");
     }
     
     // Wrapper code begins here
    @@ -97,26 +112,25 @@ class Base_callback : public Base
      public:
        Base_callback(PyObject* self) : m_self(self) {}
     
    -   char const* class_name() const { return call_method(m_self, "class_name"); }
    +   char const* class_name() const { return call_method(m_self, "class_name"); }
        char const* Base_name() const { return Base::class_name(); }
      private:
    -   PyObject* m_self;
    +   PyObject* const m_self;
     };
     
     using namespace boost::python;
    -BOOST_PYTHON_MODULE_INIT(my_module)
    +BOOST_PYTHON_MODULE(my_module)
     {
    -   module("my_module")
    -      .def("is_base", is_base)
    -      .add(
    -         class_<Base,Base_callback, noncopyable>("Base")
    -             .def("class_name", Base_callback::Base_name);
    -         )
    -       ;
    +    def("is_base", is_base);
    +
    +    class_<Base,Base_callback, noncopyable>("Base")
    +        .def("class_name", &Base_callback::Base_name)
    +        ;
    +
     }
     
    -

    Python Code

    +

    Python Code

     >>> from my_module import *
     >>> class Derived(Base):
    @@ -130,12 +144,15 @@ BOOST_PYTHON_MODULE_INIT(my_module)
     >>> is_base(Derived())
     0
     
    -

    Revised - - 10 May, 2002 - -

    -

    © Copyright Dave Abrahams - 2002. All Rights Reserved.

    - + +

    Revised + + 28 Sept, 2002 +

    + +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/class.html b/doc/v2/class.html index 0496d2ca..f2fd15c5 100644 --- a/doc/v2/class.html +++ b/doc/v2/class.html @@ -1,70 +1,73 @@ - + + + + Boost.Python - <boost/python/class.hpp>, <boost/python/class_fwd.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    Headers <boost/python/class.hpp>, <boost/python/class_fwd.hpp>

    +

    Contents

    -
    Introduction +
    Introduction
    -
    Classes +
    Classes
    -
    Class template class_ +
    Class template + class_
    Class class_ - synopsis + synopsis
    Class class_ - constructors + constructors
    Class class_ - modifier functions - -
    Class class_ - observer functions + modifier functions
    +
    -
    Class template bases +
    Class template + bases
    -
    Class bases - synopsis -
    - -
    Class template args - -
    -
    -
    Class args - synopsis +
    Class template + bases synopsis
    +
    +
    -
    Example(s) +
    Example(s)

    @@ -72,168 +75,181 @@

    <boost/python/class.hpp> defines the interface through which users expose their C++ classes to Python. It declares the - class_ class template, which is parameterized on the - class type being exposed. It also exposes the args - and bases utility class templates, which are used in - conjunction with class_. + class_ class template, which is parameterized on the class + type being exposed. It also exposes the init, + optional and bases utility class templates, + which are used in conjunction with class_.

    <boost/python/class_fwd.hpp> contains a forward - declaration of the class_ class template. + declaration of the class_ class template.

    -

    Classes

    +

    Classes

    -

    Class template class_<T, Bases, HeldType, NonCopyable>

    +

    Class template + class_<T, Bases, HeldType, + NonCopyable>

    -

    Creates a Python class associated with the C++ type passed as - its first parameter. Although it has four template parameters, - only the first one is required. The three optional arguments can - actually be supplied in any - order; Boost.Python determines the role of the argument - from its type.
    +

    Creates a Python class associated with the C++ type passed as its + first parameter. Although it has four template parameters, only the first + one is required. The three optional arguments can actually be supplied + in any order; Boost.Python determines + the role of the argument from its type.

    +

    - - - - + - - - + - - - - + - - - - + - - - + +
    Template Parameter + Template ParameterRequirements + RequirementsSemantics + SemanticsDefault + Default
    T + TA class type. + A class type.The class being wrapped + The class being wrapped
    Bases + BasesA specialization of bases<...> which - specifies previously-exposed C++ base classes of T[1]. + A specialization of bases<...> which + specifies previously-exposed C++ base classes of T[1].Registers from_python conversions from - wrapped T instances to each of its exposed direct - and indirect bases. For each polymorphic base B, - registers conversions from indirectly-held wrapped - B instances to T. + Registers from_python conversions from wrapped + T instances to each of its exposed direct and indirect + bases. For each polymorphic base B, registers + conversions from indirectly-held wrapped B instances to + T.bases<> + bases<>
    HeldType + HeldTypeMust be T, a class derived - from T, or a Dereferenceable type for which - pointee<HeldType>::type - is T or a class derived from T. - + Must be T, a class derived from T, or a + Dereferenceable type for which + pointee<HeldType>::type + is T or a class derived from T.Specifies the type which is actually embedded in a Python - object wrapping a T instance. More details below. + Specifies the type which is actually embedded in a Python object + wrapping a T instance. More details below.T + T
    NonCopyable + NonCopyableIf supplied, must be boost::noncopyable. + If supplied, must be boost::noncopyable. Suppresses automatic registration of to_python - conversions which copy - T instances. Required when T has no - publicly-accessible copy constructor. - - An unspecified type other than boost::noncopyable. + Suppresses automatic registration of to_python + conversions which copy T instances. Required when + T has no publicly-accessible copy constructor.An unspecified type other than + boost::noncopyable.
    -

    HeldType Semantics

    +

    HeldType Semantics

    -
      -
    1. - If HeldType is derived from T, its - exposed constructor(s) must accept an initial - PyObject* argument which refers back to the Python - object that contains it, as shown in this example. This argument is - not included in the argument list type passed to def_init(), below, nor is - it passed explicitly by users when Python instances of - T are created. This is the idiom which allows C++ virtual - functions to be overridden in Python. Boost.Python automatically - registers additional converters which allow wrapped instances of - T to be passed to wrapped C++ functions expecting - HeldType arguments. +
        +
      1. If HeldType is derived from T, its exposed + constructor(s) must accept an initial PyObject* argument + which refers back to the Python object that contains the + HeldType instance, as shown in this example. This argument is not + included in the init-expression passed to def(init_expr), below, + nor is it passed explicitly by users when Python instances of + T are created. This idiom allows C++ virtual functions + which will be overridden in Python to access the Python object so the + Python method can be invoked. Boost.Python automatically registers + additional converters which allow wrapped instances of T + to be passed to wrapped C++ functions expecting HeldType + arguments.
      2. -
      3. Because Boost.Python will always allow - wrapped instances of T to be passed in place of - HeldType arguments, specifying a smart pointer for - HeldType allows users to pass Python - T instances where a smart pointer-to-T is - expected. Smart pointers such as std::auto_ptr<> - or boost::shared_ptr<> - which contain a nested type element_type designating - the referent type are automatically supported; additional smart - pointer types can be supported by specializing pointee<HeldType>. +
      4. Because Boost.Python will always allow wrapped instances of + T to be passed in place of HeldType + arguments, specifying a smart pointer for HeldType allows + users to pass Python T instances where a smart + pointer-to-T is expected. Smart pointers such as + std::auto_ptr<> or boost::shared_ptr<> + which contain a nested type element_type designating the + referent type are automatically supported; additional smart pointer + types can be supported by specializing pointee<HeldType>.
      5. -
      6. - As in case 1 above, when HeldType is a smart pointer to - a class derived from T, the initial - PyObject* argument must be supplied by all exposed - constructors. +
      7. As in case 1 above, when HeldType is a smart pointer + to a class derived from T, the initial + PyObject* argument must be supplied by all of + HeldType's exposed constructors.
      8. -
      9. - Except in cases 1 and 3, users may optionally specify that T itself - gets initialized with a similar initial PyObject* - argument by specializing has_back_reference. -
      +
    2. Except in cases 1 and 3, users may optionally specify that T itself + gets initialized with a similar initial PyObject* argument + by specializing has_back_reference<T>.
    3. +
    -

    Class template - class_ synopsis

    +

    Class template class_ + synopsis

     namespace boost { namespace python
     {
       template <class T
    -            , class Bases = bases<>
    +          , class Bases = bases<>
                 , class HeldType = T
                 , class NonCopyable = unspecified
                >
    -  class class_
    +  class class_ : public object
       {
    -    class_();
    +    // Constructors with default __init__
         class_(char const* name);
    +    class_(char const* name, char const* docstring);
     
    -    // exposing constructors
    -    class_& def_init();
    +    // Constructors, specifying non-default __init__
    +    template <class Init>
    +    class_(char const* name, Init);
    +    template <class Init>
    +    class_(char const* name, char const* docstring, Init);
     
    -    template <class Args>
    -    class_& def_init(Args const& = Args());
    +    // Exposing additional __init__ functions
    +    template <class Init>
    +    class_& def(Init);
     
    -    template <class Args, class CallPolicy>
    -    class_& def_init(Args const&, CallPolicy policy);
    -
    -    // exposing member functions
    +    // defining methods
         template <class F>
         class_& def(char const* name, F f);
    -
    -    template <class Fn, class CallPolies>
    -    class_& def(char const* name, Fn fn, CallPolies);
    +    template <class Fn, class A1>
    +    class_& def(char const* name, Fn fn, A1 const&);
    +    template <class Fn, class A1, class A2>
    +    class_& def(char const* name, Fn fn, A1 const&, A2 const&);
    +    template <class Fn, class A1, class A2, class A3>
    +    class_& def(char const* name, Fn fn, A1 const&, A2 const&, A3 const&);
     
         // exposing operators
         template <unspecified>
    -    class_& def(detail::operator_<unspecified>);
    +    class_& def(detail::operator_<unspecified>);
    +
    +    // Raw attribute modification
    +    template <class U>
    +    class_& setattr(char const* name, U const&);
     
         // exposing data members
         template <class D>
    @@ -242,287 +258,383 @@ namespace boost { namespace python
         template <class D>
         class_& def_readwrite(char const* name, D T::*pm);
     
    -    // Raw attribute modification
    -    class_& setattr(char const* name, ref const&);
    -
         // property creation
    -    void add_property(char const* name, ref const& fget);
    -    void add_property(char const* name, ref const& fget, ref const& fset);
    +    template <class Get>
    +    void add_property(char const* name, Get const& fget);
    +    template <class Get, class Set>
    +    void add_property(char const* name, Get const& fget, Set const& fset);
     
    -    // accessing the Python class object
    -    ref object() const;
    +    // pickle support
    +    template <typename PickleSuite>
    +    self& def_pickle(PickleSuite const&);
       };
     }}
     
    -

    Class template class_ constructors

    - -
    -class_();
    -
    - -
    -
    Requires: The platform's std::type_info::name() - implementation produces a string which corresponds to the type's - declaration in C++ - -
    Effects: Constructs a class_ object which - generates a Boost.Python extension class with the same name as - T. - -
    Rationale: Many platforms can generate reasonable names for - Python classes without user intervention. -
    +

    Class template class_ + constructors

     class_(char const* name);
    +class_(char const* name, char const* docstring);
    +template <class Init>
    +class_(char const* name, Init init_spec);
    +template <class Init>
    +class_(char const* name, char const* docstring, Init init_spec);
     
    -
    Requires: name is a ntbs which conforms to - Python's identifier - naming rules. +
    Requires: name is an ntbs which conforms to Python's identifier + naming rules. If docstring is supplied, it must be an + ntbs. If init_spec is + supplied, it must be either the special enumeration constant + no_init or an init-expression compatible with + T.
    -
    Effects: Constructs a class_ object which - generates a Boost.Python extension class named name. +
    Effects: Constructs a class_ object holding a + Boost.Python extension class named name. The + named attribute of the current scope is bound to the new + extension class.
    -
    Rationale: Gives the user full control over class naming. +
    +
      +
    • If supplied, the value of docstring is bound to + the __doc__ attribute of the extension class.
    • + +
    • If init_spec is no_init, a special + __init__ function is generated which always raises a + Python exception. Otherwise, this->def(init_spec) + is called.
    • + +
    • If init_spec is not supplied, + this->def(init<>()) is called.
    • +
    +
    + +
    Rationale:Allowing the user to specify constructor arguments + in the class_<> constructor helps her to avoid the + common run-time errors which result from invoking wrapped member + functions without having exposed an __init__ function + which creates the requisite T instance. Types which are + not default-constructible will cause a compile-time error unless + Init is supplied. The user must always supply + name as there is currently no portable method to derive + the text of the class name from its type.
    -

    Class template class_ - modifier functions

    - +

    Class template + class_ modifier functions

    -class_& def_init();
    -
    -template <class Args>
    -class_& def_init(Args const& argument_types);
    -
    -template <class Args, class CallPolicies>
    -class_& def_init(Args const& argument_types, CallPolicies policies);
    +template <class Init>
    +class_& def(Init init_expr);
     
    -
    Requires: Args is an MPL sequence of C++ argument - types (A1, A2,... AN) such that if - a1, a2... aN are objects of type - A1, A2,... AN respectively, the expression - T(a1, a2... aN) is valid. In the first form, - the expression T() must be valid. +
    Requires: init_expr is the result of an init-expression compatible with + T.
    -
    Effects: Adds the result of +
    Effects: For each valid + prefix P of Init, adds an + __init__(...) function overload to the + extension class accepting P as arguments. Each overload + generated constructs an object of HeldType according to + the semantics described above, using a copy of + init_expr's call policies. + If the longest valid prefix of Init contains N + types and init_expr holds M keywords, an initial + sequence of the keywords are used for all but the first + N - M arguments of each overload.
    -make_constructor<args<>,Holder>(), +
    Returns: *this
    -make_constructor<Args,Holder>(), or - -make_constructor<Args,Holder>(policies), - respectively, to the Boost.Python extension class being defined under the name - "__init__". Holder is a concrete subclass of instance_holder - which holds the HeldType. If the extension class - already has an "__init__" attribute, the usual overloading procedure applies. - -
    Returns: *this - -
    Rationale: Allows users to easily expose a class' constructor - to Python. +
    Rationale: Allows users to easily expose a class' + constructor to Python.
    - -
    - +
    +
     template <class F>
    -class_& def(char const* name, F f);
    -
    -template <class Fn, class CallPolicies>
    -class_& def(char const* name, Fn f, CallPolicies policies);
    +class_& def(char const* name, Fn fn);
    +template <class Fn, class A1>
    +class_& def(char const* name, Fn fn, A1 const& a1);
    +template <class Fn, class A1, class A2>
    +class_& def(char const* name, Fn fn, A1 const& a1, A2 const& a2);
    +template <class Fn, class A1, class A2, class A3>
    +class_& def(char const* name, Fn fn, A1 const& a1, A2 const& a2, A3 const& a3);
     
    -
    Requires: f is a non-null - pointer-to-function or pointer-to-member-function, or a callable - Python object passed as a PyObject* or ref. name - is a ntbs which conforms to Python's identifier - naming rules. In the first form, the return type of - f is not a reference and is not a pointer other - than char const* or PyObject*. In the - second form policies is a model of CallPolicies. +
    Requires: name is an ntbs which conforms to Python's identifier + naming rules.
    -
    Effects: Adds the result of make_function(f) or make_function(f, policies) to - the Boost.Python extension class being defined, with the given - name. If the extension class already has an attribute named - name, the usual overloading procedure applies. +
    +
      +
    • + If a1 is the result of an overload-dispatch-expression, + only the second form is allowed and fn must be a pointer + to function or pointer to member function whose arity is the same as A1's maximum arity. -
      Returns: *this +
      +
      Effects: For each prefix P of + Fn's sequence of argument types, beginning + with the one whose length is A1's minimum + arity, adds a + name(...) method + overload to the extension class. Each overload generated + invokes + a1's call-expression with P, using a copy + of a1's call + policies. If the longest valid prefix of A1 + contains N types and a1 holds M + keywords, an initial sequence of the keywords are used for all + but the first N - M arguments of + each overload.
      +
      +
      +
    • + +
    • + Otherwise, a single method overload is built around fn, which + must not be null: + +
        +
      • If fn is a function pointer, its first argument must be of + the form U, cv&, + cv*, or + cv* const&, where + T* is convertible to U*, and + a1-a3, if supplied, may be selected + in any order from the table below.
      • + +
      • Otherwise, if fn is a member function pointer, its target + must be T or one of its public base classes, and + a1-a3, if supplied, may be selected + in any order from the table below.
      • + +
      • Otherwise, Fn must be [derived from] object, and + a1-a2, if supplied, may be selcted in any order + from the first two rows of the table below. To be useful, + fn should be + callable.
      • +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Memnonic NameRequirements/Type propertiesEffects
      docstringAny ntbs.Value will be bound to the __doc__ attribute + of the resulting method overload.
      policiesA model of CallPoliciesA copy will be used as the call policies of the resulting + method overload.
      keywordsThe result of a keyword-expression + specifying no more arguments than the arity of fn.A copy will be used as the call policies of the resulting + method overload.
      +
    • +
    +
    + +
    Returns: *this
    -
     template <unspecified>
    -class_& def(detail::operator_<unspecified>);
    +class_& def(detail::operator_<unspecified>);
     
    -
    Effects: Adds a Python special - method as described here. +
    Effects: Adds a Python special method as + described here.
    -
    Returns: *this +
    Returns: *this
    -
    -template <class F>
    -class_& setattr(char const* name, ref x);
    +template <class U>
    +class_& setattr(char const* name, U const& u);
     
    -
    Requires: name is a ntbs which conforms to - Python's identifier - naming rules. +
    Requires: name is an ntbs which conforms to Python's identifier + naming rules.
    -
    Effects: PyObject_SetAttrString(this->object(), name, x.get()); +
    Effects: Converts u to Python and adds it to the attribute + dictionary of the extension class:
    -
    Returns: *this +
    +
    + PyObject_SetAttrString(this->ptr(), name, object(u).ptr()); +
    +
    + +
    Returns: *this
    - -
    - +
    +
    -void add_property(char const* name, ref const& fget);
    -void add_property(char const* name, ref const& fget, ref const& fset);
    -
    -
    - -
    Requires: name is a ntbs which conforms to - Python's identifier - naming rules. - -
    Effects: Creates a new Python property - class instance, passing fget.get() (and - fset.get() in the second form) to its constructor, - then adds that property to the Python class object under - construction with the given attribute name. - -
    Returns: *this - -
    Rationale: Allows users to easily expose a class' - data member such that it can be inspected from Python with a - natural syntax. -
    - -
    -
    -    template <class D>
    -    class_& def_readonly(char const* name, D T::*pm);
    +template <class Get>
    +void add_property(char const* name, Get const& fget);
    +template <class Get, class Set>
    +void add_property(char const* name, Get const& fget, Set const& fset);
     
    +
    Requires: name is an ntbs which conforms to Python's identifier + naming rules.
    -
    Requires: name is a ntbs which conforms to - Python's identifier - naming rules. +
    Effects: Creates a new Python property + class instance, passing object(fget) (and object(fset) in the + second form) to its constructor, then adds that property to the Python + class object under construction with the given attribute + name.
    -
    Effects: +
    Returns: *this
    + +
    Rationale: Allows users to easily expose functions that can + be invoked from Python with attribute access syntax.
    +
    +
    -this->add_property(name, ref(make_getter(pm)));
    +template <class D>
    +class_& def_readonly(char const* name, D T::*pm);
     
    -
    Returns: *this +
    +
    Requires: name is an ntbs which conforms to Python's identifier + naming rules.
    -
    Rationale: Allows users to easily expose a class' - data member such that it can be inspected from Python with a - natural syntax. +
    Effects:
    + +
    +
    +this->add_property(name, make_getter(pm));
    +
    +
    + +
    Returns: *this
    + +
    Rationale: Allows users to easily expose a class' data + member such that it can be inspected from Python with a natural + syntax.
    - -
    -
     template <class D>
     class_& def_readwrite(char const* name, D T::*pm);
     
    +
    Effects:
    -
    Effects: +
    -ref fget(make_getter(pm));
    -ref fset(make_setter(pm));
    -this->add_property(name, fget, fset);
    +this->add_property(name, make_getter(pm), make_setter(pm));
     
    +
    -
    Returns: *this +
    Returns: *this
    -
    Rationale: Allows users to easily expose a class' - data member such that it can be inspected and set from Python with a - natural syntax. - -

    Class template class_ - observer functions

    +
    Rationale: Allows users to easily expose a class' data + member such that it can be inspected and set from Python with a natural + syntax.
    +
    -ref object() const;
    +template <typename PickleSuite>
    +class_& def_pickle(PickleSuite const&);
     
    -
    Returns: A ref object which holds a reference to - the Boost.Python extension class object created by the - class_ constructor. +
    Requires: PickleSuite must be publically derived from + pickle_suite.
    -
    Rationale: Mostly not needed by users, since module::add() uses this to insert the - extension class in the module. +
    Effects: Defines a legal combination of the special + attributes and methods: + __getinitargs__, + __getstate__, + __setstate__, + __getstate_manages_dict__, + __safe_for_unpickling__, + __reduce__ +
    + +
    Returns: *this
    + +
    Rationale: Provides an + easy to use high-level interface + for establishing complete pickle support for the wrapped class. + The user is protected by compile-time consistency checks.
    - -

    Class template - args<T1, T2,...TN>

    - -

    A conveniently-named MPL sequence which - users pass to def_init calls to make - their code more readable. - -

    Class template args - synopsis

    -
    -namespace boost { namespace python
    -{
    -  template <T1 = unspecified,...TN = unspecified>
    -  struct args
    -  {};
    -}}
    -
    +
    +

    Class template - bases<T1, T2,...TN>

    + bases<T1, T2,...TN> -

    An MPL sequence which - can be used in class_<...> - instantiations indicate a list of base classes. Although users - can pass any MPL sequence in place of args, above, the use of - bases to indicate base classes is mandatory. +

    An MPL sequence + which can be used in class_<...> + instantiations indicate a list of base classes.

    Class template bases synopsis

     namespace boost { namespace python
     {
    -  template <T1 = unspecified,...TN = unspecified>
    +  template <T1 = unspecified,...Tn = unspecified>
       struct bases
       {};
     }}
    @@ -530,12 +642,12 @@ namespace boost { namespace python
     
         

    Example(s)

    -

    Given a C++ class declaration: +

    Given a C++ class declaration:

     class Foo : public Bar, public Baz
     {
      public:
    -   Foo(int, char const*);
    +   Foo(int x, char const* y);
        Foo(double);
     
        std::string const& name() { return m_name; }
    @@ -546,44 +658,39 @@ class Foo : public Bar, public Baz
        ...
     };
     
    - - A corresponding Boost.Python extension class can be created with: + A corresponding Boost.Python extension class can be created with:
     using namespace boost::python;
     
    -ref foo = class_<Foo,bases<Bar,Baz> >()
    -   .def_init(args<int,char const*>())
    -   .def_init(args<double>())
    +class_<Foo,bases<Bar,Baz> >("Foo",
    +          "This is Foo's docstring."
    +          "It describes our Foo extension class",
    +
    +          init<int,char const*>(args("x","y"), "__init__ docstring")
    +          )
    +   .def(init<double>())
        .def("get_name", &Foo::get_name, return_internal_reference<>())
        .def("set_name", &Foo::set_name)
        .def_readwrite("value", &Foo::value)
    -   .object();
    +   ;
     
    - -
    - -[1] By "previously-exposed" we mean that the for each -B in bases, an instance of -class_<B> must have already been -constructed. Ensuring this in a portable manner when a class and its -bases are exposed in the same module entails using separate -full-expressions, rather than chaining consecutive definitions with -".add(...). - +
    + [1] By "previously-exposed" we mean that the for + each B in bases, an instance of + class_<B, ...> must have + already been constructed.
    -module m("module_name");
    -m.add(class_<Base>()
    -        .def_init());
    -m.add(class_<Derived, bases<Base>>()
    -        .def_init());
    +class_<Base>("Base");
    +class_<Derived, bases<Base> >("Derived");
     
    - Revised - 09 May, 2002 - + 29 Sept, 2002 -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/configuration.html b/doc/v2/configuration.html index bb6b7344..d6a1fdef 100644 --- a/doc/v2/configuration.html +++ b/doc/v2/configuration.html @@ -1,91 +1,141 @@ + + - - - -Boost.Python - Configuration - - - + + + + + Boost.Python - Configuration + + + +
    - - - - -
    -

    -

    -
    -

    Boost.Python

    -

    Configuration

    -
    -
    -
    -
    Introduction
    -
    Application Defined Macros
    -
    Public Library Defined Macros
    -
    Library Defined Implementation Macros
    -
    -

    Introduction

    -

    Boost.Python uses several configuration macros in <boost/config.hpp>, - as well as configuration macros meant to be supplied by the application. These - macros are documented here.

    -

    Application Defined Macros

    -

    These are the macros that may be defined by an application using Boost.Python.

    - - - - - - - - - - - - - -
    MacroMeaning
    {{macro}}{{meaning}}
    {{macro}}{{meaning}}
    -

    Public Library Defined Macros

    -

    These macros are defined by Boost.Python but are expected to be used by application - code.

    - - - - - - - - - - - - - -
    MacroMeaning
    {{macro}}{{meaning}}
    {{macro}}{{meaning}}
    -

    Library Defined Implementation Macros

    -

    These macros are defined by Boost.Python and are implementation details of interest - only to implementers.

    - - - - - - - - - - - - - -
    MacroMeaning
    {{macro}}{{meaning}}
    {{macro}}{{meaning}}
    -
    -

    Revised - - 05 November, 2002 - -

    -

    © Copyright Dave Abrahams - 2002. All Rights Reserved.

    - + + +

    C++ Boost

    + + + +

    Boost.Python

    + +

    Configuration

    + + + +
    + +
    +
    Introduction
    + +
    Application Defined Macros
    + +
    Library Defined Implementation + Macros
    +
    + +

    Introduction

    + +

    Boost.Python uses several configuration macros in <boost/config.hpp>, + as well as configuration macros meant to be supplied by the application. + These macros are documented here.

    + +

    Application Defined Macros

    + +

    These are the macros that may be defined by an application using + Boost.Python. Note that if you extend a strict interpretation of the C++ + standard to cover dynamic libraries, using different values of these + macros when compiling different libraries (including extension modules + and the Boost.Python library itself) is a violation of the ODR. However, we know of no C++ + implementations on which this particular violation is detectable or + causes any problems.

    + + + + + + + + + + + + + + + + + + + + +
    Macro + + Default + + Meaning +
    BOOST_PYTHON_MAX_ARITY15The maximum arity of any + function, member function, or constructor to be wrapped, invocation + of a Boost.Python function wich is specified as taking arguments + x1, x2,...Xn. This includes, in + particular, callback mechanisms such as object::operator()(...) + or call_method<R>(... + ).
    BOOST_PYTHON_MAX_BASES10The maximum number of template arguments to the bases<...> + class template, which is used to specify the bases of a wrapped C++ + class..
    + +

    Library Defined Implementation + Macros

    + +

    These macros are defined by Boost.Python and are + implementation details of interest only to implementors and those porting + to new platforms.

    + + + + + + + + + + + + +
    Macro + + Default + + Meaning +
    BOOST_PYTHON_TYPE_ID_NAMEnot definedIf defined, this indicates that the type_info comparison across + shared library boundaries does not work on this platform. In other + words, if shared-lib-1 passes typeid(T) to a function in + shared-lib-2 which compares it to typeid(T), that + comparison may return false. If this macro is #defined, + Boost.Python uses and compares typeid(T).name() instead + of using and comparing the std::type_info objects + directly.
    +
    + +

    Revised + + 04 October, 2002 + +

    + +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/copy_const_reference.html b/doc/v2/copy_const_reference.html index 70da135b..a014ee28 100644 --- a/doc/v2/copy_const_reference.html +++ b/doc/v2/copy_const_reference.html @@ -1,46 +1,58 @@ - + + + + - Boost.Python - <boost/python/copy_const_reference.hpp> + Boost.Python - + <boost/python/copy_const_reference.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    Header <boost/python/copy_const_reference.hpp>

    +

    Contents

    -
    Classes +
    Classes
    Class - copy_const_reference + copy_const_reference
    Class - copy_const_reference synopsis + copy_const_reference synopsis
    Class - copy_const_reference metafunctions + copy_const_reference metafunctions
    +
    +
    -
    Example +
    Example

    @@ -50,9 +62,10 @@ copy_const_reference

    copy_const_reference is a model of ResultConverterGenerator which can be - used to wrap C++ functions returning a reference-to-const type such that - the referenced value is copied into a new Python object. + "ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator + which can be used to wrap C++ functions returning a reference-to-const + type such that the referenced value is copied into a new Python + object.

    Class copy_const_reference synopsis

    @@ -73,17 +86,17 @@ template <class T> struct apply
    -
    Requires: T is U const& for some - U. +
    Requires: T is U const& for + some U.
    Returns: typedef to_python_value<T> - type; + type;

    Example

    -

    C++ Module Definition

    +

    C++ Module Definition

     #include <boost/python/module.hpp>
     #include <boost/python/class.hpp>
    @@ -102,22 +115,18 @@ struct Foo {
     
     // Wrapper code
     using namespace boost::python;
    -BOOST_PYTHON_MODULE_INIT(my_module)
    +BOOST_PYTHON_MODULE(my_module)
     {
    -   module m("my_module")
    -      .add(
    -         class_<Bar>()
    -         )
    -      .add(
    -         class_<Foo>()
    -            .def_init(args<int>())
    -            .def("get_bar", &Foo::get_bar
    -                , return_value_policy<copy_const_reference>())
    -         )
    +    class_<Bar>("Bar");
    +
    +     class_<Foo>("Foo", init<int>())
    +        .def("get_bar", &Foo::get_bar
    +            , return_value_policy<copy_const_reference>())
            ;
     }
     
    -

    Python Code

    + +

    Python Code

     >>> from my_module import *
     >>> f = Foo(3)         # create a Foo object
    @@ -126,10 +135,13 @@ BOOST_PYTHON_MODULE_INIT(my_module)
     
         

    Revised - 15 February, 2002 + 29 September, 2002 +

    - -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/copy_non_const_reference.html b/doc/v2/copy_non_const_reference.html index ffa728db..ac796a21 100644 --- a/doc/v2/copy_non_const_reference.html +++ b/doc/v2/copy_non_const_reference.html @@ -1,47 +1,59 @@ - + + + + Boost.Python - <boost/python/copy_non_const_reference.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    Header <boost/python/copy_non_const_reference.hpp>

    +

    Contents

    -
    Classes +
    Classes
    Class - copy_non_const_reference + copy_non_const_reference
    Class - copy_non_const_reference synopsis + copy_non_const_reference synopsis
    -
    Class - copy_non_const_reference metafunctions +
    Class + copy_non_const_reference metafunctions
    +
    +
    -
    Example +
    Example

    @@ -51,9 +63,10 @@ copy_non_const_reference

    copy_non_const_reference is a model of ResultConverterGenerator which can be - used to wrap C++ functions returning a reference-to-non-const type such - that the referenced value is copied into a new Python object. + "ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator + which can be used to wrap C++ functions returning a + reference-to-non-const type such that the referenced value is copied into + a new Python object.

    Class copy_non_const_reference synopsis

    @@ -75,16 +88,16 @@ template <class T> struct apply
    Requires: T is U& for some - non-const U. + non-const U.
    Returns: typedef to_python_value<T> - type; + type;

    Example

    -

    C++ code: +

    C++ code:

     #include <boost/python/module.hpp>
     #include <boost/python/class.hpp>
    @@ -103,18 +116,14 @@ struct Foo {
     
     // Wrapper code
     using namespace boost::python;
    -BOOST_PYTHON_MODULE_INIT(my_module)
    +BOOST_PYTHON_MODULE(my_module)
     {
    -   module("my_module")
    -      .add(
    -         class_<Bar>()
    -         )
    -      .add(
    -         class_<Foo>()
    -            .def_init(args<int>())
    -            .def("get_bar", &Foo::get_bar
    -                , return_value_policy<copy_non_const_reference>())
    -         );
    +    class_<Bar>("Bar");
    +
    +     class_<Foo>("Foo", init<int>())
    +        .def("get_bar", &Foo::get_bar
    +            , return_value_policy<copy_non_const_reference>())
    +       ;
     }
     
    Python Code: @@ -126,10 +135,13 @@ BOOST_PYTHON_MODULE_INIT(my_module)

    Revised - 05 November, 2001 + 29 September, 2001 +

    - -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/data_members.html b/doc/v2/data_members.html index 820bb1d4..5ec6ff01 100644 --- a/doc/v2/data_members.html +++ b/doc/v2/data_members.html @@ -1,109 +1,118 @@ - + + + + Boost.Python - <boost/python/data_members.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    -

    Header <boost/python/data_members.hpp>

    +

    Header + <boost/python/data_members.hpp>

    +

    Contents

    -
    Introduction +
    Introduction
    -
    Functions +
    Functions
    -
    make_getter +
    make_getter
    -
    make_setter +
    make_setter
    +
    -
    Example +
    Example

    Introduction

    make_getter() and - make_setter() are - the functions used internally by class_<>::make_setter() are the + functions used internally by class_<>::def_readonly and class_<>::def_readwrite to - produce Python callable objects which wrap C++ data members. + "class.html#class_-spec-modifiers">def_readwrite to produce + Python callable objects which wrap C++ data members.

    Functions

    -
     template <class C, class D>
    -objects::function* make_getter(D C::*pm);
    +object make_getter(D C::*pm);
     
     template <class C, class D, class Policies>
    -objects::function* make_getter(D C::*pm, Policies const& policies);
    +object make_getter(D C::*pm, Policies const& policies);
     
    -
    Requires: Policies is a model of CallPolicies. +
    Requires: Policies is a model of CallPolicies.
    -
    Effects: Creates a Python callable object which - accepts a single argument that can be converted - from_python to C*, and returns the - corresponding member D member of the C - object, converted to_python. If - policies is supplied, it will be applied to the - function as described here. +
    Effects: Creates a Python callable object which accepts a + single argument that can be converted from_python to + C*, and returns the corresponding member D + member of the C object, converted to_python. + If policies is supplied, it will be applied to the + function as described here.
    -
    Returns: A pointer convertible to PyObject* which - refers to the new Python callable object. +
    Returns: An instance of object which holds the new Python + callable object.
     template <class C, class D>
    -objects::function* make_setter(D C::*pm);
    +object make_setter(D C::*pm);
     
     template <class C, class D, class Policies>
    -objects::function* make_setter(D C::*pm, Policies const& policies);
    +object make_setter(D C::*pm, Policies const& policies);
     
    -
    Requires: Policies is a model of CallPolicies. +
    Requires: Policies is a model of CallPolicies.
    -
    Effects: Creates a Python callable object which, when - called from Python, expects two arguments which can be converted +
    Effects: Creates a Python callable object which, when called + from Python, expects two arguments which can be converted from_python to C* and D const&, respectively, and sets the - corresponding D member of the C - object. If policies is supplied, it will be applied - to the function as described here. + corresponding D member of the C object. If + policies is supplied, it will be applied to the function + as described here.
    -
    Returns: A pointer convertible to - PyObject* which refers to the new Python callable - object. +
    Returns: An instance of object which holds the new Python + callable object.

    Example

    -

    The code below uses make_getter and make_setter to expose a - data member as functions: - +

    The code below uses make_getter and make_setter to expose a data + member as functions:

     #include <boost/python/data_members.hpp>
     #include <boost/python/module.hpp>
    @@ -119,14 +128,10 @@ using namespace boost::python;
     
     BOOST_PYTHON_MODULE_INIT(data_members_example)
     {
    -    module("data_members_example")
    -        .add(
    -            class_<X>("X")
    -               .def_init(args<int>())
    -               .def("get", make_getter(&X::y))
    -               .def("set", make_setter(&X::y))
    -        )
    -        ;
    +    class_<X>("X", init<int>())
    +       .def("get", make_getter(&X::y))
    +       .def("set", make_setter(&X::y))
    +       ;
     }
     
    It can be used this way in Python: @@ -142,9 +147,13 @@ BOOST_PYTHON_MODULE_INIT(data_members_example)

    - 8 May 2002 + 29 September 2002 + +

    - -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/definitions.html b/doc/v2/definitions.html index 839608bc..5268b9c5 100644 --- a/doc/v2/definitions.html +++ b/doc/v2/definitions.html @@ -1,35 +1,100 @@ + + - - - -Boost.Python - Definitions - - - + + + + + Boost.Python - Definitions + + + +
    - - - - -
    -

    -

    -
    -

    Boost.Python

    -

    Definitions

    -
    -
    -
    -
    {{term}}: {{definition}}
    -
    {{term}}: {{definition}}
    -
    -
    -

    Revised - - 05 November, 2002 - -

    -

    © Copyright Dave Abrahams - 2002. All Rights Reserved.

    - + + +

    C++ Boost

    + + + +

    Boost.Python

    + +

    Definitions

    + + + +
    + +
    +
    arity: The number of arguments accepted + by a function or member function. Unless otherwise specified, the + hidden "this" argument to member functions is not counted + when specifying arity
    + +

    +
    + +
    ntbs: Null-Terminated Byte String, or + `C'-string. C++ string literals are ntbses. An + ntbs must never be null.
    + +

    +
    + +
    raise: Exceptions in Python are + "raised", not "thrown", as they are in C++. When this documentation + says that some Python exception is "raised" in the context of C++ code, + it means that the corresponding Python exception is set via the Python/'C' + API, and throw_error_already_set() + is called.
    + +

    +
    + +
    POD: A technical term from the C++ + standard. Short for "Plain Ol'Data": A POD-struct is an aggregate class + that has no non-static data members of type pointer to member, + non-POD-struct, non-POD-union (or array of such types) or reference, + and has no user-defined copy assign- ment operator and no user-defined + destructor. Similarly, a POD-union is an aggregate union that has no + non-static data members of type pointer to member, non-POD-struct, + non-POD-union (or array of such types) or reference, and has no + user-defined copy assignment operator and no user-defined destructor. A + POD class is a class that is either a POD-struct or a POD-union. An + aggregate is an array or a class (clause 9) with no user-declared + constructors (12.1), no private or protected non-static data members + (clause 11), no base classes (clause 10), and no virtual functions + (10.3).
    + +

    +
    + +
    ODR: The "One Definition + Rule", which says that any entity in a C++ program must have the same definition in all translation units (object files) which make up a program. +
    + +

    +
    + + +
    +
    + +

    Revised + + 03 October, 2002 + +

    + +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/errors.html b/doc/v2/errors.html index 6e364e8f..a87c308d 100644 --- a/doc/v2/errors.html +++ b/doc/v2/errors.html @@ -1,53 +1,68 @@ - + + + + Boost.Python - <boost/python/errors.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    Header <boost/python/errors.hpp>

    +

    Contents

    -
    Introduction +
    Introduction
    -
    Classes +
    Classes
    -
    Class error_already_set +
    Class + error_already_set
    Class - error_already_set synopsis + error_already_set synopsis
    +
    +
    -
    Functions +
    Functions
    -
    handle_exception +
    handle_exception
    -
    expect_non_null -
    throw_error_already_set +
    expect_non_null
    + +
    throw_error_already_set
    +
    -
    Examples +
    Examples

    @@ -56,20 +71,24 @@

    <boost/python/errors.hpp> provides types and functions for managing and translating between Python and C++ exceptions. This is relatively low-level functionality that is mostly used internally - by Boost.Python. Users should seldom need it. + by Boost.Python. Users should seldom need it.

    Classes

    Class error_already_set

    -

    error_already_set is an exception type which can be thrown - to indicate that a Python error has occurred. If thrown, the precondition - is that error_already_set is an exception type which can be + thrown to indicate that a Python error has occurred. If thrown, the + precondition is that PyErr_Occurred() - returns a value convertible to true. + returns a value convertible to true. Portable code shouldn't + throw this exception type directly, but should instead use throw_error_already_set(), + below.

    -

    Class error_already_set synopsis

    +

    Class error_already_set + synopsis

     namespace boost { namespace python
     {
    @@ -86,84 +105,100 @@ void handle_exception() throw();
     
    -
    Requires: The first form requires that the expression Requires: The first form requires that the expression + function0<void>(f) is valid. The second form requires that a C++ exception is currently - being handled (see section 15.1 in the C++ standard). + being handled (see section 15.1 in the C++ standard).
    Effects: The first form calls f() inside a - try block whose catch clauses set an - appropriate Python exception for the C++ exception caught, returning - true if an exception was caught, false - otherwise. The second form passes a function which rethrows the exception - currently being handled to the first form. + try block which first attempts to use all registered exception translators. If none of + those translates the exception, the catch clauses then set + an appropriate Python exception for the C++ exception caught, returning + true if an exception was thrown, false + otherwise. The second form passes a function which rethrows the + exception currently being handled to the first form.
    -
    Postconditions: No exception is being handled +
    Postconditions: No exception is being handled
    -
    Throws: nothing +
    Throws: nothing
    Rationale: At inter-language boundaries it is important to - ensure that no C++ exceptions escape, since the calling language usually - doesn't have the equipment neccessary to properly unwind the stack. Use - handle_exception to manage exception translation whenever - your C++ code is called directly from the Python API. This is done for - you automatically by the usual function wrapping facilities: make_function(), make_constructor(), module::def and class_::def). The second form can be more - convenient to use (see the example below), but - various compilers have problems when exceptions are rethrown from within - an enclosing try block. + ensure that no C++ exceptions escape, since the calling language + usually doesn't have the equipment neccessary to properly unwind the + stack. Use handle_exception to manage exception + translation whenever your C++ code is called directly from the Python + API. This is done for you automatically by the usual function wrapping + facilities: make_function(), + make_constructor(), + def() and class_::def(). The second form can be + more convenient to use (see the example below), + but various compilers have problems when exceptions are rethrown from + within an enclosing try block.
    -template <class T> T* expect_non_null(T* x);
    +template <class T> T* expect_non_null(T* x);
     
    -
    Returns: x +
    Returns: x
    Throws: error_already_set() iff x == - 0. + "#error_already_set-spec">error_already_set() iff x == + 0.
    -
    Rationale: Simplifies error-handling when calling many - functions in the Python/C API, which - return 0 on error. +
    Rationale: Simplifies error-handling when calling functions + in the Python/C + API which return 0 on error.
    -
     void throw_error_already_set();
     
    -
    Effects: throw error_already_set(); + "#error_already_set-spec">error_already_set();
    +
    + +
    +
    Rationale: Many platforms and compilers are not able to + consistently catch exceptions thrown across shared library boundaries. + Using this function from the Boost.Python library ensures that the + appropriate catch block in handle_exception() can catch the + exception.

    Examples

     #include <string>
     #include <boost/python/errors.hpp>
    -#include <boost/python/reference.hpp>
    +#include <boost/python/object.hpp>
    +#include <boost/python/handle.hpp>
     
     // Returns a std::string which has the same value as obj's "__name__"
     // attribute.
    -std::string get_name(boost::python::ref obj)
    +std::string get_name(boost::python::object obj)
     {
        // throws if there's no __name__ attribute
        PyObject* p = boost::python::expect_non_null(
    -      PyObject_GetAttrString(obj.get(), "__name__"));
    +      PyObject_GetAttrString(obj.ptr(), "__name__"));
    +
    +   char const* s = PyString_AsString(p);
    +   if (s != 0) 
    +        Py_DECREF(p);
     
        // throws if it's not a Python string
        std::string result(
           boost::python::expect_non_null(
              PyString_AsString(p)));
     
    -   Py_XDECREF(p); // Done with p
    +   Py_DECREF(p); // Done with p
        
        return result;
     }
    @@ -172,12 +207,19 @@ std::string get_name(boost::python::ref obj)
     // Demonstrate form 1 of handle_exception
     //
     
    -// Place a Python Int object whose value is 1 if a and b have
    +// Place into result a Python Int object whose value is 1 if a and b have
     // identical "__name__" attributes, 0 otherwise.
    -void same_name_impl(PyObject*& result, PyObject* a, PyObject* b)
    +void same_name_impl(PyObject*& result, boost::python::object a, boost::python::object b)
     {
        result = PyInt_FromLong(
    -      get_name(boost::python::ref(a1)) == get_name(boost::python::ref(a2)));
    +      get_name(a) == get_name(a2));
    +}
    +
    +object borrowed_object(PyObject* p)
    +{
    +   return boost::python::object(
    +        boost::python::handle<>(
    +             boost::python::borrowed(a1)));
     }
     
     // This is an example Python 'C' API interface function
    @@ -194,7 +236,7 @@ same_name(PyObject* args, PyObject* keywords)
        // Use boost::bind to make an object compatible with
        // boost::Function0<void>
        if (boost::python::handle_exception(
    -         boost::bind<void>(same_name_impl, boost::ref(result), a1, a2)))
    +         boost::bind<void>(same_name_impl, boost::ref(result), borrowed_object(a1), borrowed_object(a2))))
        {
           // an exception was thrown; the Python error was set by
           // handle_exception()
    @@ -217,9 +259,10 @@ same_name2(PyObject* args, PyObject* keywords)
     
        if (!PyArg_ParseTuple(args, const_cast<char*>("OO"), &a1, &a2))
           return 0;
    +
        try {
           return PyInt_FromLong(
    -         get_name(boost::python::ref(a1)) == get_name(boost::python::ref(a2)));
    +         get_name(borrowed_object(a1)) == get_name(borrowed_object(a2)));
        }
        catch(...)
        {
    @@ -232,10 +275,13 @@ same_name2(PyObject* args, PyObject* keywords)
     
         

    Revised - 17 November, 2002 + 29 September, 2002 +

    - -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/faq.html b/doc/v2/faq.html index 78a3940f..7a2811af 100644 --- a/doc/v2/faq.html +++ b/doc/v2/faq.html @@ -1,39 +1,166 @@ + + - - - -Boost.Python - FAQ - - - + + + + + Boost.Python - FAQ + + + +
    - - - - -
    -

    -

    -
    -

    Boost.Python

    -

    Frequently Asked Questions (FAQs)

    -
    -
    -
    -
    {{question}}
    -
    {{question}}
    -
    -

    {{question}}

    -

    {{answer}}

    -

    {{question}}

    -

    {{answer}}

    -
    -

    Revised - - 05 November, 2002 - -

    -

    © Copyright Dave Abrahams - 2002. All Rights Reserved.

    - + + +

    C++ Boost

    + + + +

    Boost.Python

    + +

    Frequently Asked Questions (FAQs)

    + + + +
    + +
    +
    Is return_internal reference + efficient?
    + +
    How can I which take C++ containers as + arguments?
    +
    + +

    Is return_internal reference efficient?

    + +
    + Q: I have an object composed of 12 doubles. A const& to + this object is returned by a member function of another class. From the + viewpoint of using the returned object in Python I do not care if I get + a copy or a reference to the returned object. In Boost.Python Version 2 + I have the choice of using copy_const_reference or + return_internal_reference. Are there considerations that would lead me + to prefer one over the other, such as size of generated code or memory + overhead? + +

    A: copy_const_reference will make an instance with storage + for one of your objects, size = base_size + 12 * sizeof(double). + return_internal_reference will make an instance with storage for a + pointer to one of your objects, size = base_size + sizeof(void*). + However, it will also create a weak reference object which goes in the + source object's weakreflist and a special callback object to manage the + lifetime of the internally-referenced object. My guess? + copy_const_reference is your friend here, resulting in less overall + memory use and less fragmentation, also probably fewer total + cycles.

    +
    + +

    How can I wrap functions which take C++ + containers as arguments?

    + +

    Ralf W. Grosse-Kunstleve provides these notes:

    + +
      +
    1. + Using the regular class_<> wrapper: +
      +class_<std::vector<double> >("std_vector_double")
      +  .def(...)
      +  ...
      +  ;
      +
      + This can be moved to a template so that several types (double, int, + long, etc.) can be wrapped with the same code. This technique is used + in the file + +
      + scitbx/include/scitbx/array_family/boost_python/flex_wrapper.h +
      + in the "scitbx" package. The file could easily be modified for + wrapping std::vector<> instantiations. + +

      This type of C++/Python binding is most suitable for containers + that may contain a large number of elements (>10000).

      +
    2. + +
    3. + Using custom rvalue converters. Boost.Python "rvalue converters" + match function signatures such as: +
      +void foo(std::vector<double> const& array); // pass by const-reference
      +void foo(std::vector<double> array); // pass by value
      +
      + Some custom rvalue converters are implemented in the file + +
      + scitbx/include/scitbx/boost_python/container_conversions.h +
      + This code can be used to convert from C++ container types such as + std::vector<> or std::list<> to Python tuples and vice + versa. A few simple examples can be found in the file + +
      + scitbx/array_family/boost_python/regression_test_module.cpp +
      + Automatic C++ container <-> Python tuple conversions are most + suitable for containers of moderate size. These converters generate + significantly less object code compared to alternative 1 above. +
    4. +
    + A disadvantage of using alternative 2 is that operators such as + arithmetic +,-,*,/,% are not available. It would be useful to have custom + rvalue converters that convert to a "math_array" type instead of tuples. + This is currently not implemented but is possible within the framework of + Boost.Python V2 as it will be released in the next couple of weeks. [ed.: + this was posted on 2002/03/10] + +

    It would also be useful to also have "custom lvalue converters" such + as std::vector<> <-> Python list. These converters would + support the modification of the Python list from C++. For example:

    + +

    C++:

    +
    +void foo(std::vector<double>& array)
    +{
    +  for(std::size_t i=0;i<array.size();i++) {
    +    array[i] *= 2;
    +  }
    +}
    +
    + Python: +
    +>>> l = [1, 2, 3]
    +>>> foo(l)
    +>>> print l
    +[2, 4, 6]
    +
    + Custom lvalue converters require changes to the Boost.Python core library + and are currently not available. + +

    P.S.:

    + +

    The "scitbx" files referenced above are available via anonymous + CVS:

    +
    +cvs -d:pserver:anonymous@cvs.cctbx.sourceforge.net:/cvsroot/cctbx login
    +cvs -d:pserver:anonymous@cvs.cctbx.sourceforge.net:/cvsroot/cctbx co scitbx
    +
    +
    + +

    Revised + + 05 November, 2002 + +

    + +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/has_back_reference.html b/doc/v2/has_back_reference.html index a31cf448..0a2f54ce 100644 --- a/doc/v2/has_back_reference.html +++ b/doc/v2/has_back_reference.html @@ -1,77 +1,82 @@ - - + + + + - Boost.Python - - <boost/python/has_back_reference.hpp> - + + - + +
    +
    -

    C++ Boost

    +

    C++ Boost

    +

    Boost.Python

    Header <boost/python/has_back_reference.hpp>

    +

    Contents

    -
    Introduction +
    Introduction
    -
    Classes +
    Classes
    Class template - has_back_reference + has_back_reference
    -
    Class template - has_back_reference synopsis +
    Class template + has_back_reference synopsis
    +
    -
    Example(s) +
    Example(s)
    +

    Introduction

    -

    <boost/python/has_back_reference.hpp> - defines the traits class template - has_back_reference<>, which can be - specialized by the user to indicate that a wrapped class - instance holds a PyObject* corresponding to a - Python object. +

    <boost/python/has_back_reference.hpp> defines the + traits class template has_back_reference<>, which can + be specialized by the user to indicate that a wrapped class instance + holds a PyObject* corresponding to a Python object.

    Classes

    Class template has_back_reference

    -

    A unary metafunction whose value is true iff - its argument is a pointer_wrapper<>. +

    A unary metafunction whose value is true iff its argument + is a pointer_wrapper<>.

    -

    Class - template has_back_reference synopsis

    +

    Class template + has_back_reference synopsis

     namespace boost { namespace python
     {
    @@ -82,36 +87,33 @@ namespace boost { namespace python
     }}
     
    -

    A "traits - class" which is inspected by Boost.Python to - determine how wrapped classes can be constructed. +

    A "traits + class" which is inspected by Boost.Python to determine how wrapped + classes can be constructed.

    - -
    value is an integral constant convertible - to bool of unspecified type. +
    value is an integral constant convertible to bool of + unspecified type.
    Specializations may substitute a value convertible to - true for value iff for each invocation of - class_<WrappedClass>::def_init(args<type-sequence...>()), - there exists a corresponding constructor - WrappedClass::WrappedClass(PyObject*, type-sequence...). If - such a specialization exists, the WrappedClass - constructors will be called with a "back reference" pointer - to the corresponding Python object whenever they are invoked from - Python. - + true for value iff for each invocation of + class_<WrappedClass>::def(init<type-sequence... + >()), there exists a corresponding constructor + WrappedClass::WrappedClass(PyObject*, type-sequence... + ). If such a specialization exists, the + WrappedClass constructors will be called with a "back + reference" pointer to the corresponding Python object whenever they are + invoked from Python.

    Example

    -

    C++ module definition

    - +

    C++ module definition

     #include <boost/python/class.hpp>
     #include <boost/python/module.hpp>
     #include <boost/python/has_back_reference.hpp>
    +#include <boost/python/handle.hpp>
     #include <boost/shared_ptr.hpp>
     
     using namespace boost::python;
    @@ -121,7 +123,7 @@ struct X
         X(PyObject* self) : m_self(self), m_x(0) {}
         X(PyObject* self, int x) : m_self(self), m_x(x) {}
         
    -    PyObject* self() { return m_self; }
    +    handle<> self() { return handle<>(borrowed(m_self)); }
         int get() { return m_x; }
         void set(int x) { m_x = x; }
     
    @@ -151,36 +153,29 @@ struct Y
     
     boost::shared_ptr<Y> Y_self(boost::shared_ptr<Y> self) const { return self; }
     
    -BOOST_PYTHON_MODULE_INIT(back_references)
    +BOOST_PYTHON_MODULE(back_references)
     {
    -    module("back_references")
    -        .add(
    -            class_<X>("X")
    -               .def_init()
    -               .def_init(args<int>())
    -               .def("self", &X::self)
    -               .def("get", &X::get)
    -               .def("set", &X::set)
    -            )
    -        .add(
    -            class_<Y, shared_ptr<Y> >("Y")
    -               .def_init()
    -               .def_init(args<int>())
    -               .def("get", &Y::get)
    -               .def("set", &Y::set)
    -               .def("self", Y_self)
    -            )
    -        ;
    +    class_<X>("X")
    +       .def(init<int>())
    +       .def("self", &X::self)
    +       .def("get", &X::get)
    +       .def("set", &X::set)
    +       ;
    +
    +    class_<Y, shared_ptr<Y> >("Y")
    +       .def(init<int>())
    +       .def("get", &Y::get)
    +       .def("set", &Y::set)
    +       .def("self", Y_self)
    +       ;
     }
     
    + The following Python session illustrates that x.self() + returns the same Python object on which it is invoked, while + y.self() must create a new Python object which refers to the + same Y instance. -The following Python session illustrates that x.self() -returns the same Python object on which it is invoked, while -y.self() must create a new Python object which refers to -the same Y instance. - -

    Python code

    - +

    Python code

     >>> from back_references import *
     >>> x = X(1)
    @@ -207,11 +202,13 @@ the same Y instance.
     
         

    Revised - 07 May, 2002 + 29 September, 2002 +

    - -

    © Copyright Dave Abrahams - 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/implicit.html b/doc/v2/implicit.html index 99ce9ad8..ea24c567 100644 --- a/doc/v2/implicit.html +++ b/doc/v2/implicit.html @@ -1,51 +1,60 @@ - + + + + Boost.Python - <boost/python/implicit.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    Header <boost/python/implicit.hpp>

    +

    Contents

    -
    -
    Introduction +
    +
    Introduction
    - -
    Functions +
    Functions
    -
    -
    Function Template implicitly_convertible - +
    +
    Function Template + implicitly_convertible
    +
    -
    Example +
    Example

    Introduction

    - - implicitly_convertible allows Boost.Python to - implicitly take advantage of a C++ implicit or explicit conversion - when matching Python objects to C++ argument types. + implicitly_convertible allows Boost.Python to implicitly + take advantage of a C++ implicit or explicit conversion when matching + Python objects to C++ argument types.

    Functions

    -

    Function template implicitly_convertible

    +

    Function template + implicitly_convertible

     template <class Source, class Target>
     void implicitly_convertible();
    @@ -55,40 +64,42 @@ void implicitly_convertible();
           
             implicitly_convertible template parameters
    - - Parameter - Description - Source - The source type of the implicit conversion + Parameter + + Description + - Target - The target type of the implicit conversion + Source + + The source type of the implicit conversion + + + Target + + The target type of the implicit conversion +
    -
    Requires: The expression Target(s), - where s is of type Source, is valid. +
    Requires: The declaration Target t(s);, where + s is of type Source, is valid.
    Effects: registers an rvalue from_python converter to Target which can succeed for any - PyObject* p iff there exists any registered - converter which can produce Source rvalues + PyObject* p iff there exists any registered converter + which can produce Source rvalues
    -
    Rationale: C++ users expect to be able to take - advantage of the same sort of interoperability in Python as they - do in C++. +
    Rationale: C++ users expect to be able to take advantage of + the same sort of interoperability in Python as they do in C++.
    -

    Example

    - -

    C++ module definition

    - +

    C++ module definition

     #include <boost/python/class.hpp>
     #include <boost/python/implicit.hpp>
    @@ -110,23 +121,21 @@ int x_value(X const& x)
     
     X make_x(int n) { return X(n); }
     
    -BOOST_PYTHON_MODULE_INIT(implicit_ext)
    +BOOST_PYTHON_MODULE(implicit_ext)
     {
    -    module("implicit_ext")
    -        .def("x_value", x_value)
    -        .def("make_x", make_x)
    -        .add(
    -            class_<X>("X")
    -            .def_init(args<int>())
    -            )
    +    def("x_value", x_value);
    +    def("make_x", make_x);
    +
    +    class_<X>("X", 
    +        init<int>())
             ;
    +
         implicitly_convertible<X,int>();
         implicitly_convertible<int,X>();
     }
     
    -

    Python code

    - +

    Python code

     >>> from implicit_ext import *
     >>> x_value(X(42))
    @@ -140,10 +149,13 @@ BOOST_PYTHON_MODULE_INIT(implicit_ext)
     
         

    Revised - 08 May, 2002 + 29 September, 2002 +

    - -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/iterator.html b/doc/v2/iterator.html index 1e367cce..03d0cb00 100644 --- a/doc/v2/iterator.html +++ b/doc/v2/iterator.html @@ -1,216 +1,239 @@ - + + + + Boost.Python - <boost/python/iterator.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    Header <boost/python/iterator.hpp>

    +

    Contents

    -
    Introduction +
    Introduction
    -
    Classes +
    Classes
    -
    Class template iterator +
    Class template + iterator
    Class - iterator synopsis + iterator synopsis
    -
    Class template iterator - constructor +
    Class template + iterator constructor
    -
    +
    +
    -
    Class template iterators +
    Class template + iterators
    Class - iterators synopsis -
    Class template - iterators nested types -
    Class template - iterators static functions -
    -
    + iterators synopsis
    -
    Functions +
    Class template + iterators nested types
    + +
    Class template + iterators static functions
    +
    + + + + +
    Functions
    -
    range +
    range
    +
    -
    Examples +
    Examples

    Introduction

    -

    <boost/python/iterator.hpp> provides types - and functions for creating Python - iterators from C++ - Containers and <boost/python/iterator.hpp> provides types and + functions for creating Python + iterators from C++ Containers and Iterators. Note that if your class_ supports random-access iterators, - implementing - __getitem__ - (also known as the Sequence Protocol) may serve you better than - using this facility: Python will automatically create an iterator - type for you (see iter()), - and each access can be range-checked, leaving no possiblity of - accessing through an invalidated C++ iterator. + implementing __getitem__ + (also known as the Sequence Protocol) may serve you better than using + this facility: Python will automatically create an iterator type for you + (see iter()), + and each access can be range-checked, leaving no possiblity of accessing + through an invalidated C++ iterator.

    Classes

    Class Template iterator

    -

    Instances of iterator<C,P> hold a reference - to a callable Python object which, when invoked from Python, - expects a single argument c convertible to - C and creates a Python iterator that traverses - [c.begin(), - c.end()). The optional CallPolicies - P can be used to control how elements are returned - during iteration. +

    Instances of iterator<C,P> hold a reference to a + callable Python object which, when invoked from Python, expects a single + argument c convertible to C and creates a + Python iterator that traverses [c.begin(), + c.end()). The optional CallPolicies P can be used to + control how elements are returned during iteration.

    -

    In the table below, c is an instance of Container. +

    In the table below, c is an instance of + Container.

    - - - - + - - + + - - - + +
    Template Parameter + Template ParameterRequirements + RequirementsSemantics + SemanticsDefault + Default
    Container + Container[c.begin(),c.end()) is a valid Iterator - range. - - The result will convert its argument to - c and call - c.begin() and c.end() to acquire - iterators. To invoke Container's - const begin() and end() - functions, make it const. + [c.begin(),c.end()) is a valid Iterator range.The result will convert its argument to c and call + c.begin() and c.end() to acquire iterators. + To invoke Container's const + begin() and end() functions, make it + const.
    NextPolicies + NextPoliciesA default-constructible model of CallPolicies. + A default-constructible model of CallPolicies.Applied to the resulting iterators' next() method. - - An unspecified model of CallPolicies - which always makes a copy of the - result of deferencing the underlying C++ iterator + Applied to the resulting iterators' next() + method.An unspecified model of CallPolicies which + always makes a copy of the result of deferencing the underlying C++ + iterator
    -

    Class Template iterator synopsis

    +

    Class Template iterator + synopsis

     namespace boost { namespace python
     {
       template <class Container
                  , class NextPolicies = unspecified>
    -  struct iterator : reference<PyObject*>
    +  struct iterator : object
       {
           iterator();
       };
     }}
     
    -

    Class Template - iterator constructor

    +

    Class Template iterator + constructor

     iterator()
     
    -
    Effects: Initializes its base class with the result - of: +
    Effects:
    + +
    + Initializes its base class with the result of:
     range<NextPolicies>(&iterators<Container>::begin, &iterators<Container>::end)
     
    +
    -
    Postconditions: this->get() points to - a Python callable object which creates a Python iterator as - described above. +
    Postconditions: this->get() points to a + Python callable object which creates a Python iterator as described + above.
    -
    Rationale: Provides an easy way to create iterators - for the common case where a C++ class being wrapped provides - begin() and end(). +
    Rationale: Provides an easy way to create iterators for the + common case where a C++ class being wrapped provides + begin() and end().
    + - +

    Class Template + iterators

    -

    Class Template iterators

    +

    A utility class template which provides a way to reliably call its + argument's begin() and end() member functions. + Note that there is no portable way to take the address of a member + function of a C++ standard library container, so + iterators<> can be particularly helpful when wrapping + them.

    -

    A utility class template which provides a way to reliably call - its argument's begin() and end() member - functions. Note that there is no portable way to take the address - of a member function of a C++ standard library container, so - iterators<> can be particularly helpful when - wrapping them. - - -

    In the table below, x is an instance of C. +

    In the table below, x is an instance of + C.

    - - + - + + + - + +
    Required Valid Expression + Required Valid ExpressionType + Type
    x.begin() - - Convertible to C::const_iterator if C is a - const type; convertible to C::iterator otherwise. + x.begin()Convertible to C::const_iterator if C + is a const type; convertible to C::iterator + otherwise.
    x.end() - - Convertible to C::const_iterator if C is a - const type; convertible to C::iterator otherwise. + x.end()Convertible to C::const_iterator if C + is a const type; convertible to C::iterator + otherwise.
    -

    Class Template iterators synopsis

    +

    Class Template iterators + synopsis

     namespace boost { namespace python
     {
    @@ -224,141 +247,151 @@ namespace boost { namespace python
     }}
     
     
    -

    Class Template - iterators nested types

    -If C is a const type, +

    Class Template iterators nested + types

    + If C is a const type,
     typedef typename C::const_iterator iterator;
     
    -Otherwise: + Otherwise:
     typedef typename C::iterator iterator;
     
    -

    Class Template - iterators static functions

    - +

    Class Template iterators static + functions

     static iterator begin(C&);
     
    -
    Returns: x.begin() +
    Returns: x.begin()
    -
     static iterator end(C&);
     
    -
    Returns: x.end() +
    Returns: x.end()
    - - +

    Functions

     template <class NextPolicies, class Target, class Accessor1, class Accessor2>
    -reference<PyObject*> range(Accessor1 start, Accessor2 finish);
    +object range(Accessor1 start, Accessor2 finish);
     
     template <class NextPolicies, class Accessor1, class Accessor2>
    -reference<PyObject*> range(Accessor1 start, Accessor2 finish);
    +object range(Accessor1 start, Accessor2 finish);
     
     template <class Accessor1, class Accessor2>
    -reference<PyObject*> range(Accessor1 start, Accessor2 finish);
    +object range(Accessor1 start, Accessor2 finish);
     
    Requires: NextPolicies is a - default-constructible model of CallPolicies. + default-constructible model of CallPolicies.
    -
    Effects:
    +
    Effects:
    -The first form creates a Python callable - object which, when invoked, converts its argument to a - Target object - x, and creates a Python iterator which traverses - [bind(start,_1)(x)bind(finish,_1)(x)), - applying NextPolicies to the iterator's - next() function. -
    -
    The second form is identical to - the first, except that Target is deduced from - Accessor1 as follows: -
      -
    1. If Accessor1 is a function type, - Target is the type of its first argument. -
    2. If Accessor1 is a data member pointer of the - form R (T::*), Target is - identical to T. -
    3. If Accessor1 is a member function pointer of - the form - R (T::*)(arguments...) cv-opt, - where cv-opt is an optional cv-qualifier, - Target is identical to T. -
    -
    +
    +
    +
    The first form creates a Python callable object which, when + invoked, converts its argument to a Target object + x, and creates a Python iterator which traverses + [bind(start,_1)(x)bind(finish,_1)(x)), + applying NextPolicies to the iterator's + next() function.
    -
    The third form is identical to the second, except that - NextPolicies is an unspecified model of CallPolicies - which always makes a copy of the - result of deferencing the underlying C++ iterator
    -
    +
    The second form is identical to the first, except that + Target is deduced from Accessor1 as + follows:
    +
    +
      +
    1. If Accessor1 is a function type, + Target is the type of its first argument.
    2. -
      Rationale: The use of boost::bind() allows - C++ iterators to be accessed through functions, member functions - or data member pointers. Customization of - NextPolicies (e.g. using return_internal_reference) is useful when it is - expensive to copy sequence elements of a wrapped class - type. Customization of Target is useful when - Accessor1 is a function object, or when a base - class of the intended target type would otherwise be deduced. +
    3. If Accessor1 is a data member pointer of the + form R (T::*), Target is + identical to T.
    4. + +
    5. If Accessor1 is a member function pointer of + the form + R (T::*)(arguments...)  + cv-opt, where cv-opt is an optional + cv-qualifier, Target is identical to + T.
    6. +
    +
    + +
    The third form is identical to the second, except that + NextPolicies is an unspecified model of CallPolicies which + always makes a copy of the result of deferencing the underlying C++ + iterator
    +
    + + +
    Rationale: The use of boost::bind() allows C++ iterators + to be accessed through functions, member functions or data member + pointers. Customization of NextPolicies (e.g. using + return_internal_reference) + is useful when it is expensive to copy sequence elements of a wrapped + class type. Customization of Target is useful when + Accessor1 is a function object, or when a base class of + the intended target type would otherwise be deduced.

    Examples

    -
     #include <boost/python/module.hpp>
     #include <boost/python/class.hpp>
    -#include <boost/python/return_internal_reference.hpp>
    +
     #include <vector>
     
     using namespace boost::python;
    -BOOST_PYTHON_MODULE_INIT(demo)
    +BOOST_PYTHON_MODULE(demo)
     {
    -   module("demo")
    -      .add(
    -         class_<std::vector<double> >("dvec")
    -            .def("__iter__", iterator<std::vector<double> >())
    -            ...
    -         )
    -      ;
    +    class_<std::vector<double> >("dvec")
    +        .def("__iter__", iterator<std::vector<double> >())
    +        ;
     }
     
    + A more comprehensive example can be found in: -A more comprehensive example can be found in: -
    -
    libs/python/test/iterator.cpp
    -
    libs/python/test/input_iterator.cpp
    -
    libs/python/test/input_iterator.py
    - +
    +
    libs/python/test/iterator.cpp
    -

    Revised - - 17 May, 2002 - +

    libs/python/test/input_iterator.cpp
    +
    libs/python/test/input_iterator.py
    -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    +

    Revised + + 29 September, 2002 + +

    + +

    © Copyright Dave Abrahams 2002. All + Rights Reserved.

    +
    +
    + + diff --git a/doc/v2/lvalue_from_pytype.html b/doc/v2/lvalue_from_pytype.html index 8b3cb49e..74b18f06 100755 --- a/doc/v2/lvalue_from_pytype.html +++ b/doc/v2/lvalue_from_pytype.html @@ -1,128 +1,145 @@ - + + + + Boost.Python - <boost/python/lvalue_from_python.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    -

    Header <boost/python/lvalue_from_pytype.hpp>

    +

    Header + <boost/python/lvalue_from_pytype.hpp>

    +

    Contents

    -
    Introduction +
    Introduction
    - -
    Classes +
    Classes
    -
    Class Template lvalue_from_pytype +
    Class Template + lvalue_from_pytype
    -
    Class Template - lvalue_from_pytype synopsis + lvalue_from_pytype synopsis
    Class Template - lvalue_from_pytype constructor + lvalue_from_pytype constructor
    +
    -
    Class Template extract_identity +
    Class Template + extract_identity
    +
    -
    Class Template - extract_identity synopsis + extract_identity synopsis
    Class Template - extract_identity static functions + extract_identity static functions
    -
    Class Template extract_member +
    + +
    Class Template + extract_member
    +
    -
    Class Template - extract_member synopsis + extract_member synopsis
    Class Template - extract_member static functions + extract_member static functions
    +
    +
    -
    Example +
    Example

    Introduction

    - - <boost/python/lvalue_from_pytype.hpp> supplies - a facility for extracting C++ objects from within Python instances - of a given type. This is typically useful for dealing with - "traditional" Python extension types. + <boost/python/lvalue_from_pytype.hpp> supplies a + facility for extracting C++ objects from within Python instances of a + given type. This is typically useful for dealing with "traditional" + Python extension types.

    Classes

    -

    Class template lvalue_from_pytype

    +

    Class template + lvalue_from_pytype

    Class template lvalue_from_pytype will register - from_python converters which, given an object of the given Python - type, can extract references and pointers to a particular C++ - type. Its template arguments are: - -

    - + from_python converters which, given an object of the given Python type, + can extract references and pointers to a particular C++ type. Its + template arguments are:

    - - - - - + - - - + + + + + + + +
    lvalue_from_pytype Requirements
    - - In the table below, x denotes an object of type PythonObject& - + In the table below, x denotes an object of type + PythonObject&
    Parameter - - Requirements - - Semantics
    Extractor + Parametera model of Extractor whose - execute function returns a reference type. + RequirementsExtracts the lvalue from the Python object once its type has been confirmed + Semantics
    python_type + ExtractorA compile-time constant PyTypeObject* + a model of Extractor whose execute + function returns a reference type.The Python type of instances convertible by this - converter. Python subtypes are also convertible. + Extracts the lvalue from the Python object once its type has been + confirmed
    python_typeA compile-time constant PyTypeObject*The Python type of instances convertible by this converter. + Python subtypes are also convertible.
    -

    Class template lvalue_from_pytype synopsis

    +

    Class template + lvalue_from_pytype synopsis

     namespace boost { namespace python
     {
    @@ -134,25 +151,25 @@ namespace boost { namespace python
     }}
     
    -

    Class template lvalue_from_pytype constructor

    +

    Class template + lvalue_from_pytype constructor

     lvalue_from_pytype();
     
    - -
    Effects: Registers converters which can convert - Python objects of the given type to lvalues of the type returned - by Extractor::execute. - +
    Effects: Registers converters which can convert Python + objects of the given type to lvalues of the type returned by + Extractor::execute.
    -

    Class template extract_identity

    +

    Class template + extract_identity

    -

    extract_identity is a model of Extractor which can be - used in the common case where the C++ type to be extracted is the - same as the Python object type. +

    extract_identity is a model of Extractor which can be used in the + common case where the C++ type to be extracted is the same as the Python + object type.

    Class template extract_identity synopsis

    @@ -167,26 +184,26 @@ namespace boost { namespace python }}
    -

    Class template extract_identity static functions

    +

    Class template + extract_identity static functions

     InstanceType& execute(InstanceType& c);
     
    - -
    Returns: c - +
    Returns: c
    +

    Class template + extract_member

    -

    Class template extract_member

    +

    extract_member is a model of Extractor which can be used in the + common case in the common case where the C++ type to be extracted is a + member of the Python object.

    -

    extract_member is a model of Extractor which can be - used in the common case in the common case where the C++ - type to be extracted is a member of the Python object. - -

    Class template extract_member synopsis

    +

    Class template + extract_member synopsis

     namespace boost { namespace python
     {
    @@ -198,31 +215,28 @@ namespace boost { namespace python
     }}
     
    -

    Class template extract_member static functions

    +

    Class template + extract_member static functions

     static MemberType& execute(InstanceType& c);
     
    - -
    Returns: c.*member - +
    Returns: c.*member

    Example

    + This example presumes that someone has implemented the standard noddy example + module from the Python documentation, and we want to build a module + which manipulates Noddys. Since + noddy_NoddyObject is so simple that it carries no + interesting information, the example is a bit contrived: it assumes you + want to keep track of one particular object for some reason. This module + would have to be dynamically linked to the module which defines + noddy_NoddyType. -This example presumes that someone has implemented the standard noddy -example module from the Python documentation, and we want to build -a module which manipulates Noddys. Since -noddy_NoddyObject is so simple that it carries no -interesting information, the example is a bit contrived: it assumes -you want to keep track of one particular object for some reason. This -module would have to be dynamically linked to the module which defines -noddy_NoddyType. - -

    C++ module definition

    - +

    C++ module definition

     #include <boost/python/reference.hpp>
     #include <boost/python/module.hpp>
    @@ -245,20 +259,17 @@ void set_cache(noddy_NoddyObject* x)
        cache.reset((PyObject*)x, ref::increment_count);
     }
     
    -BOOST_PYTHON_MODULE_INIT(noddy_cache)
    +BOOST_PYTHON_MODULE(noddy_cache)
     {
    -   module noddy_cache("noddy_cache")
    -      .def("is_cached", is_cached)
    -      .def("set_cache", set_cache)
    -      ;
    +   def("is_cached", is_cached);
    +   def("set_cache", set_cache);
     
        // register Noddy lvalue converter
        lvalue_from_pytype<extract_identity<noddy_NoddyObject>,&noddy_NoddyType>();
     }
     
    -

    Python code

    - +

    Python code

     >>> import noddy
     >>> n = noddy.new_noddy()
    @@ -274,10 +285,13 @@ BOOST_PYTHON_MODULE_INIT(noddy_cache)
     
         

    Revised - 05 November, 2001 + 29 September, 2001 +

    - -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/make_function.html b/doc/v2/make_function.html index c31144c9..080f95c7 100644 --- a/doc/v2/make_function.html +++ b/doc/v2/make_function.html @@ -1,39 +1,50 @@ - + + + + Boost.Python - <boost/python/make_function.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    -

    Header <boost/python/make_function.hpp>

    +

    Header + <boost/python/make_function.hpp>

    +

    Contents

    -
    Introduction +
    Introduction
    -
    Functions +
    Functions
    -
    make_function +
    make_function
    -
    make_constructor +
    make_constructor
    +
    -
    Example +
    Example

    @@ -41,78 +52,90 @@

    make_function() and make_constructor() are - the functions used internally by class_<>::def, class_<>::def, and - class_<>::def_init to produce Python - callable objects which wrap C++ functions and member functions. + the functions used internally by def() and class_<>::def() to produce Python + callable objects which wrap C++ functions and member functions.

    Functions

     template <class F>
    -objects::function* make_function(F f)
    +object make_function(F f)
     
     template <class F, class Policies>
    -objects::function* make_function(F f, Policies const& policies)
    +object make_function(F f, Policies const& policies)
    +
    +template <class F, class Policies, class Keywords>
    +object make_function(F f, Policies const& policies, Keywords const& keywords)
     
    Requires: F is a function pointer or member - function pointer type + function pointer type. If policies are supplied, it must + be a model of CallPolicies. If + kewords are supplied, it must be the result of a keyword-expression + specifying no more arguments than the arity of f.
    Effects: Creates a Python callable object which, when called from Python, converts its arguments to C++ and calls f. If - F is a pointer-to-member-function type, the target object of - the function call (*this) will be taken from the first + F is a pointer-to-member-function type, the target object + of the function call (*this) will be taken from the first Python argument, and subsequent Python arguments will be used as the arguments to f. If policies are supplied, it - must be a model of CallPolicies, and will - be applied to the function as described here. + will be applied to the function as described here. If keywords are + supplied, the keywords will be applied in order to the final + arguments of the resulting function.
    -
    Returns: A pointer convertible to PyObject* which - refers to the new Python callable object. +
    Returns: An instance of object which holds the new Python + callable object.
     template <class T, class ArgList, class Generator>
    -objects::function* make_constructor();
    -
    +"make_constructor-spec">template <class T, class ArgList, class Generator>
    +object make_constructor();
    + 
     template <class ArgList, class Generator, class Policies>
    -objects::function* make_constructor(Policies const& policies)
    +object make_constructor(Policies const& policies)
     
    -
    Requires: T is a class - type. Policies is a model of CallPolicies. ArgList - is an MPL sequence - of C++ argument types (A1, A2,... AN) such that if - a1, a2... aN are objects of type - A1, A2,... AN respectively, the expression new - Generator::apply<T>::type(a1, a2... aN) is - valid. Generator is a model of HolderGenerator. +
    Requires: T is a class type. + Policies is a model of CallPolicies. ArgList is an MPL sequence of C++ argument + types (A1, A2,... AN) such that if + a1, a2... aN are objects of type + A1, A2,... AN respectively, the expression new + Generator::apply<T>::type(a1, a2... aN) + is valid. Generator is a model of HolderGenerator.
    Effects: Creates a Python callable object which, when called from Python, expects its first argument to be a Boost.Python extension class object. It converts its remaining its arguments to C++ and passes them to the constructor of a dynamically-allocated - Generator::apply<T>::type object, which is - then installed in the extension class object. In the second - form, the policies are applied to the arguments and - result (None) - of the Python callable object + Generator::apply<T>::type object, which is then + installed in the extension class object. In the second form, the + policies are applied to the arguments and result (None) + of the Python callable object
    -
    Returns: The new Python callable object +
    Returns: An instance of object which holds the new Python + callable object.

    Example

    -

    C++ function exposed below returns a callable object wrapping one of two - functions. +

    C++ function exposed below returns a callable object wrapping one of + two functions.

     #include <boost/python/make_function.hpp>
     #include <boost/python/module.hpp>
    @@ -120,7 +143,8 @@ objects::function* make_constructor(Policies const& policies)
     char const* foo() { return "foo"; }
     char const* bar() { return "bar"; }
     
    -PyObject* choose_function(bool selector)
    +using namespace boost::python;
    +object choose_function(bool selector)
     {
         if (selector)
             return boost::python::make_function(foo);
    @@ -128,10 +152,9 @@ PyObject* choose_function(bool selector)
             return boost::python::make_function(bar);
     }
     
    -BOOST_PYTHON_MODULE_INIT(make_function_test)
    +BOOST_PYTHON_MODULE(make_function_test)
     {
    -    module("make_function_test")
    -        .def("choose_function", choose_function);
    +    def("choose_function", choose_function);
     }
     
    It can be used this way in Python: @@ -147,9 +170,13 @@ BOOST_PYTHON_MODULE_INIT(make_function_test)

    - 14 February 2002 + 29 September 2002 + +

    - -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/manage_new_object.html b/doc/v2/manage_new_object.html index 8630dfa5..c76a3a4d 100644 --- a/doc/v2/manage_new_object.html +++ b/doc/v2/manage_new_object.html @@ -1,46 +1,57 @@ - + + + + Boost.Python - <boost/python/manage_new_object.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    Header <boost/python/manage_new_object.hpp>

    +

    Contents

    -
    Classes +
    Classes
    Class - manage_new_object + manage_new_object
    Class - manage_new_object synopsis + manage_new_object synopsis
    Class - manage_new_object metafunctions + manage_new_object metafunctions
    +
    +
    -
    Example +
    Example

    @@ -50,10 +61,10 @@ manage_new_object

    manage_new_object is a model of ResultConverterGenerator which can be - used to wrap C++ functions which return a pointer to an object allocated - with a new-expression, and expect the caller to take responsibility - for deleting that object. + "ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator + which can be used to wrap C++ functions which return a pointer to an + object allocated with a new-expression, and expect the caller to + take responsibility for deleting that object.

    Class manage_new_object synopsis

    @@ -75,16 +86,16 @@ template <class T> struct apply
    Requires: T is U* for some - U. + U.
    Returns: typedef to_python_indirect<T> - type; + type;

    Example

    -

    In C++: +

    In C++:

     #include <boost/python/module.hpp>
     #include <boost/python/class.hpp>
    @@ -102,17 +113,15 @@ Foo* make_foo(int x) { return new Foo(x); }
     
     // Wrapper code
     using namespace boost::python;
    -BOOST_PYTHON_MODULE_INIT(my_module)
    +BOOST_PYTHON_MODULE(my_module)
     {
    -   module("my_module")
    -      .def("make_foo", make_foo, return_value_policy<manage_new_object>)
    -      .add(
    -         class_<Foo>()
    -            .def("get_x", &Foo::get_x)
    -         )
    +    def("make_foo", make_foo, return_value_policy<manage_new_object>())
    +    class_<Foo>("Foo")
    +        .def("get_x", &Foo::get_x)
    +        ;
     }
     
    -In Python: + In Python:
     >>> from my_module import *
     >>> f = make_foo(3)     # create a Foo object
    @@ -122,9 +131,13 @@ In Python:
     
         

    Revised - 14 February 2002 + 29 September 2002 + +

    - -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/module.html b/doc/v2/module.html index 3685934c..e6b170b3 100644 --- a/doc/v2/module.html +++ b/doc/v2/module.html @@ -29,29 +29,7 @@
    BOOST_PYTHON_MODULE_INIT -
    - -
    Classes - -
    -
    -
    Class module - -
    -
    -
    Class module - synopsis - -
    Class module - constructor - -
    Class module - modifier functions - -
    Class module - observer functions -
    + "#BOOST_PYTHON_MODULE-spec">BOOST_PYTHON_MODULE
    Example(s) @@ -60,13 +38,13 @@

    Introduction

    -

    This header provides the basic facilities needed to create an - extension module. +

    This header provides the basic facilities needed to create a + Boost.Python extension module.

    Macros

    BOOST_PYTHON_MODULE_INIT(name) + "BOOST_PYTHON_MODULE-spec">BOOST_PYTHON_MODULE(name) is used to declare Python module initialization functions. The name argument must @@ -75,157 +53,29 @@ "http://www.python.org/doc/2.2/ref/identifiers.html">identifier naming rules. Where you would normally write

    -void initname()
    +extern "C" void initname()
     {
        ...
    +}
     
    Boost.Python modules should be initialized with
    -BOOST_PYTHON_MODULE_INIT(name)
    +BOOST_PYTHON_MODULE(name)
     {
        ...
    +}
     
    -

    Classes

    - -

    Class module

    - -

    This class represents the Python extension module under construction. It - provides functions for adding attributes and for retrieving the underlying - Python module object. - -

    Class module - synopsis

    -
    -namespace boost { namespace python
    -{
    -  class module : public module_base
    -  {
    -   public:
    -      module(const char* name);
    -
    -      // modifier functions
    -      module& setattr(const char* name, PyObject*);
    -      module& setattr(const char* name, PyTypeObject*);
    -      module& setattr(const char* name, ref const&);
    -
    -      module& add(PyTypeObject* x);
    -      template <class T, class Bases, class HolderGenerator>
    -      module& add(class_<T,Bases,HolderGenerator> const& c);
    -
    -      template <class Fn>
    -      module& def(char const* name, Fn fn);
    -      template <class Fn, class ResultHandler>
    -      module& def(char const* name, Fn fn, ResultHandler handler);
    -
    -      // observer function
    -      ref object() const;
    -  };
    -
    -}}
    -
    - -

    Class module - constructor

    -
    -module(const char* name);
    -
    - -
    -
    Requires: name is a ntbs whose value matches the - argument passed to BOOST_PYTHON_MODULE_INIT. - -
    Effects: Creates a module object representing a - Python module named name. -
    - -

    Class module modifier - functions

    -
    -module& setattr(const char* name, PyObject* obj);
    -module& setattr(const char* name, PyTypeObject* obj);
    -module& setattr(const char* name, ref const& r);
    -
    - -
    -
    Requires: name is a ntbs which conforms to - Python's identifier - naming rules. In the first two forms, obj is non-null. - In the third form, r.get() is non-null. - -
    Effects: Adds the given Python object to the module. If the - object is a product of make_function(), the - usual overloading procedure applies. - In the first two forms, ownership of a reference to obj is transferred - from caller to callee, even if an exception is thrown. - -
    Returns: *this -
    -
    -module& add(PyTypeObject* x);
    -
    -template <class T, class Bases, class HolderGenerator>
    -module& add(class_<T,Bases,HolderGenerator> const& c);
    -
    - -
    -
    Requires: In the first form, x is non-null - -
    Effects: The first form adds the Python type object named by - x to the Python module under construction, with the name - given by the type's tp_name - field. The second form adds the extension class object being constructed - by c to the module, with the same name that was passed to - c's constructor. - -
    Returns: *this - -
    Rationale: Provides a way to set type attributes in the module - without having to explicitly specify the name. -
    -
    -template <class Fn>
    -module& def(char const* name, Fn f);
    -
    -template <class Fn, class ResultHandler>
    -module& def(char const* name, Fn f, ResultHandler handler);
    -
    - -
    - -
    Requires: f is a non-null pointer-to-function or - pointer-to-member-function. name is a ntbs which conforms to - Python's identifier - naming rules. In the first form, the return type of - f is not a reference and is not a pointer other - than char const* or PyObject*. In the - second form policy is a model of CallPolicy. - -
    Effects: Adds the result of make_function(f) to - the extension module being defined, with the given name. If - the module already has an attribute named name, the - usual overloading procedure applies. - -
    Returns: *this -
    - -

    Class module observer - functions

    -
    -ref object() const;
    -
    - -
    -
    Returns: A ref object which holds a reference to - the Python module object created by the module constructor. -
    +This macro generates two functions in the scope where it is used: +extern "C" void initname(), +and void init_module_name(), whose body must +follow the macro invocation. init_name passes +init_module_name to handle_exception() so +that any C++ exceptions generated are safely processeed. During the +body of init_name, the current scope refers to the module +being initialized.

    Example(s)

    @@ -233,28 +83,23 @@ ref object() const;
     #include <boost/python/module.hpp>
     
    -char const* greet()
    +BOOST_PYTHON_MODULE(xxx)
     {
    -    return "hello, Boost.Python!";
    -}
    -
    -BOOST_PYTHON_MODULE_INIT(boost_greet)
    -{
    -    module("boost_greet")
    -        .def("greet", greet);
    +    throw "something bad happened"
     }
     
    Interactive Python:
    ->>> import boost_greet
    ->>> boost_greet.greet()
    -'hello, Boost.Python!'
    +>>> import xxx
    +Traceback (most recent call last):
    +  File "", line 1, in ?
    +RuntimeError: Unidentifiable C++ Exception
     

    Revised - 14 February, 2002 + 2 October, 2002 diff --git a/doc/v2/operators.html b/doc/v2/operators.html index a43df858..ea642321 100755 --- a/doc/v2/operators.html +++ b/doc/v2/operators.html @@ -1,407 +1,767 @@ - + + + + Boost.Python - <boost/python/operators.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    Header <boost/python/operators.hpp>

    +


    Contents

    -
    Introduction +
    Introduction
    + +
    Classes
    -
    Classes
    +
    Class + self_ns::self_t
    -
    Class self_ns::self_t
    -
    Class self_t synopsis +
    Class self_t + synopsis
    -
    Class self_t inplace operators +
    Class self_t + inplace operators
    -
    Class self_t comparison functions +
    Class + self_t comparison functions
    -
    Class self_t non-member operations +
    Class self_t + non-member operations
    -
    Class self_t unary operations +
    Class + self_t unary operations
    -
    Class self_t value operations +
    Class + self_t value operations
    +
    + +
    Class template + other
    -
    Class template other
    -
    Class other synopsis +
    Class other + synopsis
    +
    + +
    Class template + operator_
    -
    Class template operator_
    -
    Class operator_ synopsis +
    Class + operator_ synopsis
    - -
    - -
    Objects -
    -
    -
    self +
    + -
    Examples +
    Objects
    + +
    +
    +
    self
    +
    +
    + +
    Examples

    Introduction

    -

    <boost/python/operators.hpp> provides types - and functions for automatically generating Python special - methods from the corresponding C++ constructs. Most of these - constructs are operator expressions, hence the name. To use the - facility, substitute the self object for an object of the - class type being wrapped in the expression to be exposed, and pass - the result to class_<>::def(). Much - of what is exposed in this header should be considered part of the - implementation, so is not documented in detail here. +

    <boost/python/operators.hpp> provides types and + functions for automatically generating Python special methods + from the corresponding C++ constructs. Most of these constructs are + operator expressions, hence the name. To use the facility, substitute the + self object for an object of the + class type being wrapped in the expression to be exposed, and pass the + result to class_<>::def(). Much of + what is exposed in this header should be considered part of the + implementation, so is not documented in detail here.

    Classes

    Class self_ns::self_t

    -

    self_ns::self_t is the actual type of the self object. The library - isolates self_t in its own namespace, - self_ns, in order to prevent the generalized operator - templates which operate on it from being found by - argument-dependent lookup in other contexts. This should be - considered an implementation detail, since users should never have - to mention self_t directly. +

    self_ns::self_t is the actual type of the self object. The library isolates + self_t in its own namespace, self_ns, in order + to prevent the generalized operator templates which operate on it from + being found by argument-dependent lookup in other contexts. This should + be considered an implementation detail, since users should never have to + mention self_t directly.

    -

    Class self_ns::self_t synopsis

    +

    Class self_ns::self_t + synopsis

     namespace boost { namespace python { namespace self_ns {
     {
    -   class self_t {};
    +   unspecified-type-declaration self_t;
     
        // inplace operators
    -   template <class T> operator_<unspecified> operator+=(self_t, T);
    -   template <class T> operator_<unspecified> operator-=(self_t, T);
    -   template <class T> operator_<unspecified> operator*=(self_t, T);
    -   template <class T> operator_<unspecified> operator/=(self_t, T);
    -   template <class T> operator_<unspecified> operator%=(self_t, T);
    -   template <class T> operator_<unspecified> operator>>=(self_t, T);
    -   template <class T> operator_<unspecified> operator<<=(self_t, T);
    -   template <class T> operator_<unspecified> operator&=(self_t, T);
    -   template <class T> operator_<unspecified> operator^=(self_t, T);
    -   template <class T> operator_<unspecified> operator|=(self_t, T);
    +   template <class T> operator_<unspecified> operator+=(self_t, T);
    +   template <class T> operator_<unspecified> operator-=(self_t, T);
    +   template <class T> operator_<unspecified> operator*=(self_t, T);
    +   template <class T> operator_<unspecified> operator/=(self_t, T);
    +   template <class T> operator_<unspecified> operator%=(self_t, T);
    +   template <class T> operator_<unspecified> operator>>=(self_t, T);
    +   template <class T> operator_<unspecified> operator<<=(self_t, T);
    +   template <class T> operator_<unspecified> operator&=(self_t, T);
    +   template <class T> operator_<unspecified> operator^=(self_t, T);
    +   template <class T> operator_<unspecified> operator|=(self_t, T);
     
        // comparisons
    -   template <class L, class R> operator_<unspecified> operator==(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> operator!=(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> operator<(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> operator>(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> operator<=(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> operator>=(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator==(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator!=(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator<(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator>(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator<=(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator>=(L const&, R const&);
     
        // non-member operations
    -   template <class L, class R> operator_<unspecified> operator+(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> operator-(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> operator*(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> operator/(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> operator%(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> operator>>(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> operator<<(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> operator&(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> operator^(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> operator|(L const&, R const&);
    -   template <class L, class R> operator_<unspecified> pow(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator+(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator-(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator*(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator/(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator%(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator>>(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator<<(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator&(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator^(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> operator|(L const&, R const&);
    +   template <class L, class R> operator_<unspecified> pow(L const&, R const&);
     
        // unary operations
    -   operator_<unspecified> operator-(self_t);
    -   operator_<unspecified> operator+(self_t);
    -   operator_<unspecified> operator~(self_t);
    +   operator_<unspecified> operator-(self_t);
    +   operator_<unspecified> operator+(self_t);
    +   operator_<unspecified> operator~(self_t);
     
        // value operations
    -   operator_<unspecified> int_(self_t);
    -   operator_<unspecified> long_(self_t);
    -   operator_<unspecified> float_(self_t);
    -   operator_<unspecified> complex_(self_t);
    -   operator_<unspecified> str(self_t);
    +   operator_<unspecified> int_(self_t);
    +   operator_<unspecified> long_(self_t);
    +   operator_<unspecified> float_(self_t);
    +   operator_<unspecified> complex_(self_t);
    +   operator_<unspecified> str(self_t);
     
     }}};
     
    + The tables below describe the methods generated when the results of the + expressions described are passed as arguments to class_<>::def(). + x is an object of the class type being wrapped. -The tables below describe the methods generated when the results of -the expressions described are passed as arguments to class_<>::def(). -x is an object of the class type being wrapped. +

    Class self_t inplace + operators

    + In the table below, If r is an object of type + other<T>, + y is an object of type T; otherwise, + y is an object of the same type as + r. + + + -

    Class self_t inplace operators

    + + + + + -In the table below, If r is an object of type -other<T>, -y is an object of type T; otherwise, -y is an object of the same type as -r. + -
    C++ ExpressionPython Method NameC++ Implementation
    self += r__iadd__
    - - + - + - - + - + - - + - + - - + -
    C++ Expression - Python Method Name - C++ Implementation + x += y
    self += r -__iadd__ -x += y +
    self -= r
    self -= r -__isub__ -x -= y + __isub__
    self *= r -__imul__ -x *= y + x -= y
    self /= r -__idiv__ -x /= y +
    self *= r
    self %= r -__imod__ -x %= y + __imul__
    self >>= r -__irshift__ -x >>= y + x *= y
    self <<= r -__ilshift__ -x <<= y +
    self /= r
    self &= r -__iand__ -x &= y + __idiv__
    self ^= r -__ixor__ -x ^= y + x /= y
    self |= r -__ior__ -x |= y -
    + + self %= r -

    Class self_t comparison - functions

    + __imod__ -In the tables below, if r is of type self_t, y is an object -of the same type as x; -
    -if l or r is an object of type other<T>, -y is an object of type T; -
    -otherwise, y is an object of the same type as -l or r.
    -l -is never of type self_t. + x %= y + -

    -The column of Python Expressions illustrates the expressions -that will be supported in Python for objects convertible to the types -of x and y. The secondary operation arises -due to Python's reflection -rules for rich comparison operators, and are only used when the -corresponding operation is not defined as a method of the -y object. + + self >>= r - - - + - + - - + - + - - + - + - - + - + - - -
    C++ Expression Python Method Name C++ Implementation -Python Expressions
    (primary, secondary) - +
    __irshift__
    self == r __eq__ x == y -x == y, y == x + x >>= y
    l == self __eq__ y == x -y == x, x == y +
    self <<= r
    self != r __ne__ x != y -x != y, y != x + __ilshift__
    l != self __ne__ y != x -y != x, x != y + x <<= y
    self < r __lt__ x < y -x < y, y > x +
    self &= r
    l < self __gt__ y < x -y > x, x < y + __iand__
    self > r __gt__ x > y -x > y, y < x + x &= y
    l > self __lt__ y > x -y < x, x > y +
    self ^= r
    self <= r __le__ x <= y -x <= y, y >= x + __ixor__
    l <= self __ge__ y <= x -y >= x, x <= y + x ^= y
    self >= r __ge__ x >= y -x >= y, y <= x +
    self |= r
    l >= self __le__ y >= x -y <= x, x >= y + __ior__
    + x |= y + + +

    Class self_t + comparison functions

    + In the tables below, if r is of type self_t, y is an object of + the same type as x;
    + if l or r is an object of type + other<T>, + y is an object of type T;
    + otherwise, y is an object of the same type as + l or r.
    + l is never of type self_t. -

    Class - self_t non-member operations

    +

    The column of Python Expressions illustrates the expressions + that will be supported in Python for objects convertible to the types of + x and y. The secondary operation arises due to + Python's reflection + rules for rich comparison operators, and are only used when the + corresponding operation is not defined as a method of the y + object.

    -The operations whose names begin with "__r" -below will only be called if the left-hand operand does not already -support the given operation, as described here. + + + -
    C++ Expression
    - - - + - + - - - + - + - - - + - + - -
    C++ Expression Python Method Name C++ Implementation - + Python Method Name
    self + r __add__ x + y -
    l + self __radd__ y + x + C++ Implementation
    self - r __sub__ x - y -
    l - self __rsub__ y - x + Python Expressions
    + (primary, secondary)
    self * r __mul__ x * y -
    l * self __rmul__ y * x +
    self == r
    self / r __div__ x / y -
    l / self __rdiv__ y / x + __eq__
    self % r __mod__ x % y -
    l % self __rmod__ y % x + x == y
    self >> r __rshift__ x >> y -
    l >> self __rrshift__ y >> x + x == y, y == x
    self << r __lshift__ x << y -
    l << self __rlshift__ y << x +
    l == self
    self & r __and__ x & y -
    l & self __rand__ y & x + __eq__
    self ^ r __xor__ x ^ y -
    l ^ self __rxor__ y ^ x + y == x
    self | r __or__ x | y -
    l | self __ror__ y | x + y == x, x == y
    pow(self, r) __pow__ pow(x, y) -
    pow(l, self) __rpow__ pow(y, x) +
    self != r
    + __ne__ + x != y -

    Class - self_t unary operations

    + x != y, y != x + - - + - - -
    C++ Expression Python Method Name C++ Implementation - +
    l != self
    -self __neg__ -x -
    +self__pos__ +x -
    ~self__invert__ ~x + __ne__
    + y != x + y != x, x != y + -

    Class - self_t value operations

    + + self < r - - - - -
    C++ Expression Python Method Name C++ Implementation - + __lt__
    int_(self)__int__ long(x) -
    long___long__ PyLong_FromLong(x) -
    float___float__ double(x) -
    complex___complex__ std::complex<double>(x) -
    str__str__ lexical_cast<std::string>(x) + x < y
    + x < y, y > x + + + l < self + __gt__ + + y < x + + y > x, x < y + + + + self > r + + __gt__ + + x > y + + x > y, y < x + + + + l > self + + __lt__ + + y > x + + y < x, x > y + + + + self <= r + + __le__ + + x <= y + + x <= y, y >= x + + + + l <= self + + __ge__ + + y <= x + + y >= x, x <= y + + + + self >= r + + __ge__ + + x >= y + + x >= y, y <= x + + + + l >= self + + __le__ + + y >= x + + y <= x, x >= y + + + +

    Class self_t non-member + operations

    + The operations whose names begin with "__r" below will only + be called if the left-hand operand does not already support the given + operation, as described here. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    C++ ExpressionPython Method NameC++ Implementation
    self + r__add__x + y
    l + self__radd__y + x
    self - r__sub__x - y
    l - self__rsub__y - x
    self * r__mul__x * y
    l * self__rmul__y * x
    self / r__div__x / y
    l / self__rdiv__y / x
    self % r__mod__x % y
    l % self__rmod__y % x
    self >> r__rshift__x >> y
    l >> self__rrshift__y >> x
    self << r__lshift__x << y
    l << self__rlshift__y << x
    self & r__and__x & y
    l & self__rand__y & x
    self ^ r__xor__x ^ y
    l ^ self__rxor__y ^ x
    self | r__or__x | y
    l | self__ror__y | x
    pow(self, r)__pow__pow(x, y)
    pow(l, self)__rpow__pow(y, x)
    + +

    Class self_t unary + operations

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    C++ ExpressionPython Method NameC++ Implementation
    -self__neg__-x
    +self__pos__+x
    ~self__invert__~x
    + +

    Class self_t value + operations

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    C++ ExpressionPython Method NameC++ Implementation
    int_(self)__int__long(x)
    long___long__PyLong_FromLong(x)
    float___float__double(x)
    complex___complex__std::complex<double>(x)
    str__str__lexical_cast<std::string>(x)

    Class Template other

    -

    Instances of other<T> can be used in - operator expressions with self; the - result is equivalent to the same expression with a T - object in place of other<T>. Use - other<T> to prevent construction of a - T object in case it is heavyweight, when no - constructor is available, or simply for clarity. +

    Instances of other<T> can be used in operator + expressions with self; the result is equivalent + to the same expression with a T object in place of + other<T>. Use other<T> to prevent + construction of a T object in case it is heavyweight, when + no constructor is available, or simply for clarity.

    Class Template other synopsis

    @@ -413,19 +773,18 @@ namespace boost { namespace python
       };
     }}
     
    + - +

    Class Template + detail::operator_

    -

    Class Template detail::operator_

    +

    Instantiations of detail::operator_<> are used as + the return type of operator expressions involving self. This should be considered an implementation + detail and is only documented here as a way of showing how the result of + self-expressions match calls to class_<>::def().

    -

    Instantiations of detail::operator_<> are - used as the return type of operator expressions involving self. This should be considered an - implementation detail and is only documented here as a way of - showing how the result of self-expressions match - calls to class_<>::def(). -

    Class Template detail::operator_ synopsis

    @@ -440,17 +799,15 @@ namespace boost { namespace python { namespace detail
     
         

    Objects

    -

    self - +

    self

     namespace boost { namespace python
     {
    -  extern self_ns self;
    +  using self_ns::self;
     }}
     

    Example

    -
     #include <boost/python/module.hpp>
     #include <boost/python/class.hpp>
    @@ -458,7 +815,8 @@ namespace boost { namespace python
     #include <boost/operators.hpp>
     
     struct number
    -   : boost::integer_arithmetic<number>
    +   : boost::integer_arithmetic<number>
     {
        number(long x_) : x(x_) {}
        operator long() const { return x; }
    @@ -478,54 +836,52 @@ struct number
     };
     
     using namespace boost::python;
    -BOOST_PYTHON_MODULE_INIT(demo)
    +BOOST_PYTHON_MODULE(demo)
     {
    -   module("demo")
    -      .add(
    -         class_<number>("number")
    -            // interoperate with self
    -            .def(self += self)
    -            .def(self + self)
    -            .def(self -= self)
    -            .def(self - self)
    -            .def(self *= self)
    -            .def(self * self)
    -            .def(self /= self)
    -            .def(self / self)
    -            .def(self %= self)
    -            .def(self % self)
    -            
    -            // Convert to Python int
    -            .def(int_(self))
    +   class_<number>("number")
    +      // interoperate with self
    +      .def(self += self)
    +      .def(self + self)
    +      .def(self -= self)
    +      .def(self - self)
    +      .def(self *= self)
    +      .def(self * self)
    +      .def(self /= self)
    +      .def(self / self)
    +      .def(self %= self)
    +      .def(self % self)
     
    -            // interoperate with long
    -            .def(self += long())
    -            .def(self + long())
    -            .def(long() + self)
    -            .def(self -= long())
    -            .def(self - long())
    -            .def(long() - self)
    -            .def(self *= long())
    -            .def(self * long())
    -            .def(long() * self)
    -            .def(self /= long())
    -            .def(self / long())
    -            .def(long() / self)
    -            .def(self %= long())
    -            .def(self % long())
    -            .def(long() % self)
    +      // Convert to Python int
    +      .def(int_(self))
     
    -         )
    +      // interoperate with long
    +      .def(self += long())
    +      .def(self + long())
    +      .def(long() + self)
    +      .def(self -= long())
    +      .def(self - long())
    +      .def(long() - self)
    +      .def(self *= long())
    +      .def(self * long())
    +      .def(long() * self)
    +      .def(self /= long())
    +      .def(self / long())
    +      .def(long() / self)
    +      .def(self %= long())
    +      .def(self % long())
    +      .def(long() % self)
           ;
     }
     

    Revised - 3 June, 2002 - + 29 Sept, 2002 +

    - -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/ptr.html b/doc/v2/ptr.html index 71cc6975..98bfd195 100644 --- a/doc/v2/ptr.html +++ b/doc/v2/ptr.html @@ -175,6 +175,8 @@ Ptr get() const; better to have an explicit way to retrieve the pointer. +

    Metafunctions

    +

    Class template is_pointer_wrapper

    A unary metafunction whose value is true iff its diff --git a/doc/v2/reference.html b/doc/v2/reference.html index 9db8240b..0923a434 100644 --- a/doc/v2/reference.html +++ b/doc/v2/reference.html @@ -1,56 +1,66 @@ - - + + + + Boost.Python - Reference - + + - + +
    +
    -

    C++ Boost

    +

    C++ Boost

    +

    Boost.Python

    Reference

    +


    Contents

    -
    Concepts +
    Concepts
    -
    High Level Components +
    High Level Components
    -
    Function Invocation and Creation +
    Object Wrappers
    + +
    Function Invocation and Creation
    Models of - CallPolicies + CallPolicies
    Models of - ResultConverter + ResultConverter
    Models of - ResultConverterGenerator + ResultConverterGenerator
    +
    -
    To/From Python Type Conversion +
    To/From Python Type Conversion
    -
    Utility and Infrastructure +
    Utility and Infrastructure

    @@ -59,220 +69,397 @@
    CallPolicies + "CallPolicies.html#CallPolicies-concept">CallPolicies
    Dereferenceable + "Dereferenceable.html#Dereferenceable-concept">Dereferenceable
    + +
    Extractor
    Extractor + "HolderGenerator.html#HolderGenerator-concept">HolderGenerator
    HolderGenerator + "ResultConverter.html#ResultConverter-concept">ResultConverter
    ResultConverter + "ResultConverter.html#ResultConverterGenerator-concept">ResultConverterGenerator
    ResultConverterGenerator + "ObjectWrapper.html#ObjectWrapper-concept">ObjectWrapper
    + +
    TypeWrapper

    High Level Components

    -
    class.hpp/class_fwd.hpp +
    class.hpp/class_fwd.hpp
    -
    Classes +
    Classes
    -
    class_ +
    class_
    -
    bases - -
    args +
    bases
    +
    +
    -
    errors.hpp +
    errors.hpp
    -
    Classes +
    Classes
    error_already_set + "errors.html#error_already_set-spec">error_already_set
    +
    -
    Functions +
    Functions
    handle_exception + "errors.html#handle_exception-spec">handle_exception
    expect_non_null -
    -
    + "errors.html#expect_non_null-spec">expect_non_null
    -
    iterator.hpp +
    throw_error_already_set
    + + + + + + +
    exception_translator.hpp
    - -
    Classes -
    -
    -
    iterator - -
    iterators -
    - -
    Functions +
    Functions
    -
    range +
    register_exception_translator
    +
    +
    + +
    init.hpp
    -
    module.hpp
    -
    Classes +
    Classes
    -
    module -
    -
    +
    init
    + +
    optional
    + + + + + +
    iterator.hpp
    -
    objects.hpp
    -
    Classes +
    Classes
    -
    not yet - documented -
    -
    +
    iterator
    + +
    iterators
    + + + +
    Functions
    + +
    +
    +
    range
    +
    +
    + + + +
    module.hpp
    -
    operators.hpp
    -
    Classes +
    Macros
    +
    -
    self_t -
    other -
    operator_ +
    BOOST_PYTHON_MODULE
    - -
    Objects -
    -
    -
    self -
    - +
    +
    +
    operators.hpp
    + +
    +
    +
    Classes
    + +
    +
    +
    self_t
    + +
    other
    + +
    operator_
    +
    +
    + +
    Objects
    + +
    +
    +
    self
    +
    +
    +
    +
    + + +

    Object Wrappers

    + +
    +
    dict.hpp
    + +
    +
    +
    Classes
    + +
    +
    +
    dict
    +
    +
    +
    +
    + +
    list.hpp
    + +
    +
    +
    Classes
    + +
    +
    +
    list
    +
    +
    +
    +
    + +
    long.hpp
    + +
    +
    +
    Classes
    + +
    +
    +
    long_
    +
    +
    +
    +
    + +
    numeric.hpp
    + +
    +
    +
    Classes
    + +
    +
    +
    numeric::array
    +
    +
    +
    +
    + +
    object.hpp
    + +
    +
    +
    Classes
    + +
    +
    +
    object
    +
    +
    +
    +
    + +
    str.hpp
    + +
    +
    +
    Classes
    + +
    +
    +
    str
    +
    +
    +
    +

    Function Invocation and Creation

    -
    call.hpp +
    args.hpp
    -
    Functions +
    Functions
    +
    -
    call +
    args
    +
    +
    -
    call_method.hpp +
    call.hpp
    -
    Functions +
    Functions
    -
    call_method +
    call
    +
    +
    -
    data_members.hpp +
    call_method.hpp
    -
    Functions +
    Functions
    make_getter - -
    make_setter + "call_method.html#call_method-spec">call_method
    +
    +
    -
    make_function.hpp +
    data_members.hpp
    -
    Functions +
    Functions
    make_function + "data_members.html#make_getter-spec">make_getter
    make_constructor + "data_members.html#make_setter-spec">make_setter
    +
    +
    -
    ptr.hpp +
    make_function.hpp
    -
    Functions - -
    -
    -
    ptr -
    - -
    Classes +
    Functions
    pointer_wrapper -
    + "make_function.html#make_function-spec">make_function -
    MetaFunctions +
    make_constructor
    +
    +
    +
    + + +
    overloads.hpp
    + +
    +
    +
    macros
    is_pointer_wrapper + "overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec">BOOST_PYTHON_FUNCTION_OVERLOADS
    unwrap_pointer + "overloads.html#BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS-spec">BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS
    +
    +
    +
    + +
    ptr.hpp
    + +
    +
    +
    Functions
    + +
    +
    +
    ptr
    +
    +
    + +
    Classes
    + +
    +
    +
    pointer_wrapper
    +
    +
    + +
    MetaFunctions
    + +
    +
    +
    is_pointer_wrapper
    + +
    unwrap_pointer
    +
    +
    @@ -280,75 +467,80 @@
    default_call_policies.hpp + "default_call_policies.html">default_call_policies.hpp
    Classes + "default_call_policies.html#classes">Classes
    -
    - default_call_policies +
    default_call_policies
    -
    - default_result_converter +
    default_result_converter
    +
    +
    return_internal_reference.hpp + "return_internal_reference.html">return_internal_reference.hpp
    Classes + "return_internal_reference.html#classes">Classes
    -
    - return_internal_reference + return_internal_reference
    +
    +
    return_value_policy.hpp + "return_value_policy.html">return_value_policy.hpp
    + +
    +
    +
    Classes
    + +
    +
    +
    return_value_policy
    +
    +
    +
    +
    + +
    with_custodian_and_ward.hpp
    Classes + "with_custodian_and_ward.html#classes">Classes
    -
    return_value_policy -
    -
    - -
    with_custodian_and_ward.hpp - -
    -
    -
    Classes - -
    -
    -
    - with_custodian_and_ward + with_custodian_and_ward
    -
    - with_custodian_and_ward_postcall + with_custodian_and_ward_postcall
    +
    +
    @@ -356,31 +548,35 @@
    to_python_indirect.hpp + "to_python_indirect.html">to_python_indirect.hpp
    -
    Classes - -
    -
    -
    to_python_indirect -
    -
    - -
    to_python_value.hpp - -
    -
    -
    Classes +
    Classes
    to_python_value + "to_python_indirect.html#to_python_indirect-spec">to_python_indirect
    +
    +
    + +
    to_python_value.hpp
    + +
    +
    +
    Classes
    + +
    +
    +
    to_python_value
    +
    +
    +
    +
    @@ -388,224 +584,250 @@
    copy_const_reference.hpp + "copy_const_reference.html">copy_const_reference.hpp
    Classes + "copy_const_reference.html#classes">Classes
    -
    - copy_const_reference +
    copy_const_reference
    +
    +
    copy_non_const_reference.hpp + "copy_non_const_reference.html">copy_non_const_reference.hpp
    Classes + "copy_non_const_reference.html#classes">Classes
    -
    - copy_non_const_reference + copy_non_const_reference
    +
    +
    -
    manage_new_object.hpp +
    manage_new_object.hpp
    -
    Classes +
    Classes
    -
    manage_new_object +
    manage_new_object
    +
    +
    reference_existing_object.hpp + "reference_existing_object.html">reference_existing_object.hpp
    Classes + "reference_existing_object.html#classes">Classes
    -
    - reference_existing_object + reference_existing_object
    +
    +
    +
    -

    To/From Python Type - Conversion

    +

    To/From Python Type Conversion

    -
    from_python.hpp +
    extract.hpp
    -
    Classes +
    Classes
    + +
    +
    +
    extract
    +
    +
    +
    +
    + +
    implicit.hpp
    + +
    +
    +
    Functions
    from_python + "implicit.html#implicitly_convertible-spec">implicitly_convertible
    +
    +
    -
    implicit.hpp +
    lvalue_from_pytype.hpp
    -
    Functions +
    Classes
    implicitly_convertible -
    -
    + "lvalue_from_pytype.html#lvalue_from_pytype-spec">lvalue_from_pytype -
    lvalue_from_pytype.hpp +
    extract_identity
    + +
    extract_member
    +
    + + + + +
    to_python_converter.hpp
    -
    Classes +
    Classes
    -
    lvalue_from_pytype -
    extract_identity - -
    extract_member + "to_python_converter.html#to_python_converter-spec">to_python_converter
    +
    - -
    to_python_converter.hpp - -
    -
    -
    Classes - -
    -
    -
    to_python_converter -
    -
    - +

    Utility and Infrastructure

    -
    has_back_reference.hpp +
    has_back_reference.hpp
    -
    Classes - -
    -
    -
    has_back_reference -
    -
    - -
    instance_holder.hpp - -
    -
    -
    Classes +
    Classes
    instance_holder + "has_back_reference.html#has_back_reference-spec">has_back_reference
    +
    +
    -
    pointee.hpp +
    instance_holder.hpp
    -
    Classes +
    Classes
    + +
    +
    +
    instance_holder
    +
    +
    +
    +
    + +
    pointee.hpp
    + +
    +
    +
    Classes
    class template pointee + "pointee.html#pointee">pointee
    +
    +
    -
    reference.hpp +
    handle.hpp
    -
    Classes +
    Classes
    reference + "handle.html#handle-spec">handle
    - -
    Types +
    +
    Functions
    -
    ref +
    borrowed
    +
    allow_null
    +
    + -
    type_id.hpp +
    type_id.hpp
    -
    Functions +
    Functions
    -
    type_id +
    type_id
    +
    -
    Classes +
    Classes
    -
    type_info +
    type_info
    +
    +

    Revised - 3 June, 2002 - + 3 June, 2002 +

    - -

    © Copyright Dave Abrahams 2002. All - Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/reference_existing_object.html b/doc/v2/reference_existing_object.html index dbb7a983..88016dd8 100644 --- a/doc/v2/reference_existing_object.html +++ b/doc/v2/reference_existing_object.html @@ -1,47 +1,59 @@ - + + + + Boost.Python - <boost/python/reference_existing_object.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    Header <boost/python/reference_existing_object.hpp>

    +

    Contents

    -
    Classes +
    Classes
    Class - reference_existing_object + reference_existing_object
    Class - reference_existing_object synopsis + reference_existing_object synopsis
    -
    Class - reference_existing_object metafunctions +
    Class + reference_existing_object metafunctions
    +
    +
    -
    Example +
    Example

    @@ -51,19 +63,20 @@ reference_existing_object

    reference_existing_object is a model of ResultConverterGenerator which can be - used to wrap C++ functions which return a reference or pointer to a C++ - object. When the wrapped function is called, the value referenced by its - return value is not copied. A new Python object is created which contains a - pointer to the referent, and no attempt is made to ensure that the lifetime - of the referent is at least as long as that of the corresponding Python - object. Thus, it can be highly - dangerous to use reference_existing_object without - additional lifetime management from such models of ResultConverterGenerator + which can be used to wrap C++ functions which return a reference or + pointer to a C++ object. When the wrapped function is called, the value + referenced by its return value is not copied. A new Python object is + created which contains a pointer to the referent, and no attempt is made + to ensure that the lifetime of the referent is at least as long as that + of the corresponding Python object. Thus, it can be highly dangerous to use + reference_existing_object without additional lifetime + management from such models of CallPolicies as with_custodian_and_ward. This class is used in the implementation of return_internal_reference. + "return_internal_reference.html#return_internal_reference-spec">return_internal_reference.

    Class reference_existing_object synopsis

    @@ -85,20 +98,20 @@ template <class T> struct apply
    Requires: T is U& or - U*for some U. + U*for some U.
    Returns: typedef to_python_indirect<T,V> type, where V is a HolderObjectGenerator which constructs an instance holder containing an unowned - U* pointing to the referent of the wrapped function's return - value. + U* pointing to the referent of the wrapped function's + return value.

    Example

    -

    In C++: +

    In C++:

     #include <boost/python/module.hpp>
     #include <boost/python/class.hpp>
    @@ -128,14 +141,12 @@ Singleton& get_it()
     
     // Wrapper code
     using namespace boost::python;
    -BOOST_PYTHON_MODULE_INIT(singleton)
    +BOOST_PYTHON_MODULE(singleton)
     {
    -   module("singleton")
    -      .def("get_it", get_it)
    -      .add(
    -         class_<Singleton>()
    -            .def("exchange", &Singleton::exchange)
    -         );
    +    def("get_it", get_it, reference_existing_object());
    +    class_<Singleton>("Singleton")
    +       .def("exchange", &Singleton::exchange)
    +       ;
     }
     
    In Python: @@ -153,9 +164,13 @@ BOOST_PYTHON_MODULE_INIT(singleton)

    Revised - 14 February 2002 + 29 September 2002 + +

    - -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/return_internal_reference.html b/doc/v2/return_internal_reference.html index 347db88c..79c60abb 100644 --- a/doc/v2/return_internal_reference.html +++ b/doc/v2/return_internal_reference.html @@ -1,114 +1,129 @@ - + + + + - Boost.Python - <boost/python/return_internal_reference.hpp> + Boost.Python - + <boost/python/return_internal_reference.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    -

    Header <boost/python/return_internal_reference.hpp>

    +

    Header + <boost/python/return_internal_reference.hpp>

    +

    Contents

    -
    Introduction +
    Introduction
    - -
    Classes +
    Classes
    -
    Class Template return_internal_reference +
    Class Template + return_internal_reference
    - -
    Class Template - return_internal_reference synopsis +
    Class + Template return_internal_reference + synopsis
    Class - return_internal_reference static functions + return_internal_reference static + functions
    +
    +
    - -
    Example +
    Example

    Introduction

    - - return_internal_reference instantiations are models of CallPolicies which allow pointers and + return_internal_reference instantiations are models of CallPolicies which allow pointers and references to objects held internally by a free or member function - argument or from the target of a member function to be returned - safely without making a copy of the referent. The default for its - first template argument handles the common case where the - containing object is the target (*this) of a wrapped - member function. + argument or from the target of a member function to be returned safely + without making a copy of the referent. The default for its first template + argument handles the common case where the containing object is the + target (*this) of a wrapped member function.

    Classes

    -

    Class template return_internal_reference

    +

    Class template + return_internal_reference

    - - +
    - - - + + + + + + + + + + - - + - - - + +
    return_internal_reference template parameters
    Parameter - - Requirements - - Description - - Default
    owner_arg + ParameterRequirementsDescriptionDefault
    owner_arg A positive compile-time constant of type - std::size_t. + std::size_t.The index of the parameter which contains the object to - which the reference or pointer is being returned. If used to - wrap a member function, parameter 1 is the target object - (*this). Note that if the target Python object - type doesn't support weak references, a Python - TypeError exception will be raised when the - function being wrapped is called. + The index of the parameter which contains the object to which the + reference or pointer is being returned. If used to wrap a member + function, parameter 1 is the target object (*this). Note + that if the target Python object type doesn't support weak + references, a Python TypeError exception will be raised + when the function being wrapped is called.1 + 1
    Base + BaseA model of CallPolicies + A model of CallPoliciesUsed for policy composition. Any - result_converter it supplies will be overridden by - return_internal_reference, but its - precall and postcall policies are - composed as described here CallPolicies. - - default_call_policies + Used for policy composition. Any result_converter it + supplies will be overridden by + return_internal_reference, but its precall + and postcall policies are composed as described here CallPolicies.default_call_policies
    -

    Class template return_internal_reference synopsis

    +

    Class template + return_internal_reference synopsis

     namespace boost { namespace python
     {
    @@ -116,29 +131,32 @@ namespace boost { namespace python
        struct return_internal_reference : Base
        {
           static PyObject* postcall(PyObject*, PyObject* result);
    -      typedef reference_existing_object result_converter;
    +      typedef reference_existing_object result_converter;
        };
     }}
     

    Class default_call_policies static functions

    -
     PyObject* postcall(PyObject* args, PyObject* result);
     
    -
    Requires: PyTuple_Check(args) != 0 +
    Requires: PyTuple_Check(args) + != 0
    -
    Returns: with_custodian_and_ward_postcall::postcall(args, result) +
    Returns: + with_custodian_and_ward_postcall::postcall(args, + result)
    -

    Example

    -

    C++ module definition

    - +

    C++ module definition

     #include <boost/python/module.hpp>
     #include <boost/python/class.hpp>
    @@ -166,26 +184,21 @@ class Foo
     };
     
     using namespace boost::python;
    -BOOST_PYTHON_MODULE_INIT(internal_refs)
    +BOOST_PYTHON_MODULE(internal_refs)
     {
    -   module m("internal_refs")
    -      .add(
    -         class_<Bar>()
    -            .def("get_x", &Bar::get_x)
    -            .def("set_x", &Bar::set_x)
    -         )
    -      .add(
    -         class_<Foo>()
    -            .def_init(args<int>())
    -            .def("get_bar", &Foo::get_bar
    -                , return_internal_reference<>())
    -         )
    +   class_<Bar>("Bar")
    +      .def("get_x", &Bar::get_x)
    +      .def("set_x", &Bar::set_x)
    +      ;
    +
    +   class_<Foo>("Foo", init<int>())
    +      .def("get_bar", &Foo::get_bar
    +          , return_internal_reference<>())
           ;
     }
     
    -

    Python code

    - +

    Python code

     >>> from internal_refs import *
     >>> f = Foo(3)
    @@ -202,9 +215,13 @@ BOOST_PYTHON_MODULE_INIT(internal_refs)
     
         

    Revised - 15 February, 2002 + 15 February, 2002 +

    -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/return_value_policy.html b/doc/v2/return_value_policy.html index 88a72a0c..1482d6e8 100644 --- a/doc/v2/return_value_policy.html +++ b/doc/v2/return_value_policy.html @@ -1,89 +1,106 @@ - + + + + - Boost.Python - <boost/python/return_value_policy.hpp> + Boost.Python - + <boost/python/return_value_policy.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    -

    Header <boost/python/return_value_policy.hpp>

    +

    Header + <boost/python/return_value_policy.hpp>

    +

    Contents

    -
    Introduction +
    Introduction
    - -
    Classes +
    Classes
    -
    Class Template return_value_policy +
    Class Template + return_value_policy
    -
    Class Template - return_value_policy synopsis + return_value_policy synopsis
    +
    +
    - -
    Example +
    Example

    Introduction

    - - return_value_policy instantiations are simply models - of CallPolicies which are composed of a ResultConverterGenerator and optional Base CallPolicies. + return_value_policy instantiations are simply models of CallPolicies which are composed of a ResultConverterGenerator + and optional Base CallPolicies.

    Classes

    -

    Class template return_value_policy

    - +

    Class template + return_value_policy

    - - - + + + + + + + + + - - + +
    return_value_policy template parameters
    Parameter - - Requirements - - Default
    ResultConverterGenerator + ParameterRequirementsDefault
    ResultConverterGenerator A model of ResultConverterGenerator. + "ResultConverterGenerator.html">ResultConverterGenerator.
    Base + BaseA model of CallPolicies - - default_call_policies + A model of CallPoliciesdefault_call_policies
    -

    Class template return_value_policy synopsis

    +

    Class template + return_value_policy synopsis

     namespace boost { namespace python
     {
    @@ -97,7 +114,7 @@ namespace boost { namespace python
     
         

    Example

    -

    C++ Module Definition

    +

    C++ Module Definition

     #include <boost/python/module.hpp>
     #include <boost/python/class.hpp>
    @@ -116,22 +133,18 @@ struct Foo {
     
     // Wrapper code
     using namespace boost::python;
    -BOOST_PYTHON_MODULE_INIT(my_module)
    +BOOST_PYTHON_MODULE(my_module)
     {
    -   module("my_module")
    -      .add(
    -         class_<Bar>()
    -         )
    -      .add(
    -         class_<Foo>()
    -            .def_init(args<int>())
    -            .def("get_bar", &Foo::get_bar
    -                , return_value_policy<copy_const_reference>())
    -         )
    -       ;
    +   class_<Bar>("Bar");
    +
    +   class_<Foo>("Foo", init<int>())
    +      .def("get_bar", &Foo::get_bar
    +          , return_value_policy<copy_const_reference>())
    +      ;
     }
     
    -

    Python Code

    + +

    Python Code

     >>> from my_module import *
     >>> f = Foo(3)         # create a Foo object
    @@ -140,9 +153,13 @@ BOOST_PYTHON_MODULE_INIT(my_module)
     
         

    Revised - 15 February, 2002 + 15 February, 2002 +

    -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/doc/v2/to_python_converter.html b/doc/v2/to_python_converter.html index a2a985d8..757d9f0e 100644 --- a/doc/v2/to_python_converter.html +++ b/doc/v2/to_python_converter.html @@ -1,96 +1,114 @@ - + + + + - Boost.Python - <boost/python/to_python_converter.hpp> + Boost.Python - + <boost/python/to_python_converter.hpp> + + +
    -

    -

    +

    C++ Boost

    +

    Boost.Python

    -

    Header <boost/python/to_python_converter.hpp>

    +

    Header + <boost/python/to_python_converter.hpp>

    +

    Contents

    -
    Introduction +
    Introduction
    - -
    Classes +
    Classes
    -
    Class Template to_python_converter +
    Class Template + to_python_converter
    -
    Class Template - to_python_converter synopsis + to_python_converter synopsis
    Class Template - to_python_converter constructor + to_python_converter constructor
    +
    +
    -
    Example +
    Example

    Introduction

    - - to_python_converter registers a conversion from - objects of a given C++ type into a Python object. + to_python_converter registers a conversion from objects of a + given C++ type into a Python object.

    Classes

    -

    Class template to_python_converter

    - - to_python_converter adds a wrapper around a static - member function of its second template parameter, handling - low-level details such as insertion into the converter registry. +

    Class template + to_python_converter

    + to_python_converter adds a wrapper around a static member + function of its second template parameter, handling low-level details + such as insertion into the converter registry. - - - + + + + + + + + - + - - - + +
    to_python_converter template parameters
    -In the table below, x denotes an object of type T + In the table below, x denotes an object of type + T
    Parameter - - Requirements - - Description
    T + ParameterRequirementsDescription
    T + The C++ type of the source object in the conversion + The C++ type of the source object in the conversion
    Conversion + ConversionPyObject* p = Conversion::convert(x),
    - if p == 0, PyErr_Occurred() != 0. +
    + PyObject* p = Conversion::convert(x),
    + if p == 0, PyErr_Occurred() != 0.
    A class type whose static member function - convert does the real work of the conversion. - -
    A class type whose static member function convert + does the real work of the conversion.
    -

    Class template to_python_converter synopsis

    +

    Class template + to_python_converter synopsis

     namespace boost { namespace python
     {
    @@ -102,34 +120,31 @@ namespace boost { namespace python
     }}
     
    -

    Class template to_python_converter constructor

    +

    Class template + to_python_converter constructor

     to_python_converter();
     
    -
    Effects: Registers a to_python converter which uses - Conversion::convert() to do its work. - + Conversion::convert() to do its work.

    Example

    + This example presumes that someone has implemented the standard noddy example + module from the Python documentation, and placed the corresponding + declarations in "noddy.h". Because + noddy_NoddyObject is the ultimate trivial extension type, + the example is a bit contrived: it wraps a function for which all + information is contained in the type of its return value. -This example presumes that someone has implemented the standard noddy example -module from the Python documentation, and placed the corresponding -declarations in "noddy.h". Because -noddy_NoddyObject is the ultimate trivial extension type, -the example is a bit contrived: it wraps a function for which all -information is contained in the type of its return value. - -

    C++ module definition

    - +

    C++ module definition

     #include <boost/python/reference.hpp>
     #include <boost/python/module.hpp>
    -#include "noddy.h"
    +#include "noddy.h"
     
     struct tag {};
     tag make_tag() { return tag(); }
    @@ -144,17 +159,14 @@ struct tag_to_noddy
         }
     };
     
    -BOOST_PYTHON_MODULE_INIT(to_python_converter)
    +BOOST_PYTHON_MODULE(to_python_converter)
     {
    -    module("to_python_converter")
    -        .def("make_tag", make_tag)
    -        ;
    +    def("make_tag", make_tag);
         to_python_converter<tag, tag_to_noddy>();
     }
     
    -

    Python code

    - +

    Python code

     >>> import to_python_converter
     >>> def always_none():
    @@ -180,10 +192,13 @@ BOOST_PYTHON_MODULE_INIT(to_python_converter)
     
         

    Revised - 05 November, 2001 + 29 September, 2002 +

    - -

    © Copyright Dave - Abrahams 2002. All Rights Reserved. +

    © Copyright Dave Abrahams 2002. All Rights + Reserved.

    + + diff --git a/example/Attic/project.zip b/example/Attic/project.zip deleted file mode 100644 index d863defdb784ca6864f83a6ca22443b65259bda6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1469 zcmWIWW@Zs#U|`^2aL-z=bNJRCn;-@ThExUy25|-khJvE}tkmQZ{iOW-;u77Y(#)I` zy{yFC;4lt758rb>t3xzAbWR3noDA1E=@II2>b$;QpoiAkGoFDO>vZ%y&pv%x^yxc4 zUnl>k@BD!qLN8pt%&yFu9jCV;DYheN#*RAAx;np&b}kpB7!c0*nYCVr<@xLNO-u|7 zuB;3U{7BC5O3Y2m%t>txiS@tjAW+jk<^Kk+Ul+V?bbRY|TC!w8Q-~ekh-xlMm~)Kl=XCCX%Bmwa zJ??+)J&)AN_8(iU8IzDV_4v92v(_w~TPV$OD&OGBa;Aste>_*2dg_PFg{y5cQ!%Rh;e%O!zHU z=F3kDH@6Qzefsy)th(=i|JmH!B-`b*$vxC-=A2VOmUAN>{}8zTWaDk!$KUtun%1&q|%IrgyH9vOj*qP|t9e>?k zFKqkgr&rZ)=3f@CZ~a^S+L2c_Zrg(XKX1?Vxa&_iygRr-^U9SUF(ID>E`5=h9~v2H z^Y8j1ZnYwte|bH}C*99faoZGAP~-2sW!0nU(Uph0k3XLozOVP?ksFmeq_%bC&wZlx z#<*WBw0E;HU#Oa(=H{Lbd1rAq{wp&~XO}0e=BVKH+tvNuB6N59$@3-acLx1=R(1St z&C%39I}|HonO-?@wsdOR1YDk~87f`weBlK5xqm--J!ejv{Cw-PmbIaqT=qWNSE$sR zZZk>ZT47qup$oiRUE+`U5y^FB)_R@1rIH!yj0_A985tM^P?Kv>X-;afYk+U|VFRAM z;=knOQZ{_O@MYg!w%t5#$7cO55ZZdNU`dkp%U|!))is&pb@uA-W!f6|AXBNo+`Q#t z@SVJEvzgqLW~}OOPfNKk8)5ZJw_4i9PwGOZHJ{3}p3qa)M+Hh1J``L`@Z(8e-}`w+ zOu}`Q+z*`BF7xi4?IFi|j=ktEFYiPJwZ>=D7$fs~L>5fipHV6?r=xoH_8i&c}HD)t{a<}NprJAG4!c6I;i(?P6q^Ws*&im0y- z4c#04)?z_I=HDBFdgp!#ah9!HeV(ObbNh~xzpu*oTdv+ZYgSUC<@wb<$24CU{Etw} zeeUqWA|P8Th<%qr^S>o0Ydo?ng}-Mn|NryDoT4?JW$l|{4{>p_9a#Q*{V+3R&c zGz@bf1!{mdBa;XN?jj4Mhmk>nVOt}Jg`)sNHUwLN1JVjHq#em>Xz_!r8C&!tG@CIa ticqh_TySE5=*I0&kZw>i`tR7yg3uk{&B_LnVPRll_{PA%u#pAC0|1J>SqlIF diff --git a/example/Jamfile b/example/Jamfile index 05b97e14..83664cc2 100644 --- a/example/Jamfile +++ b/example/Jamfile @@ -22,6 +22,8 @@ subproject libs/python/example ; SEARCH on python.jam = $(BOOST_BUILD_PATH) ; include python.jam ; +# ----- getting_started1 ------- + # Declare a Python extension called getting_started1 extension getting_started1 : # sources @@ -32,8 +34,28 @@ extension getting_started1 ; # Declare a test for the extension module -boost-python-runtest my-test +boost-python-runtest test1 : # Python test driver test_getting_started1.py # extension modules to use - getting_started1 ; \ No newline at end of file + getting_started1 ; + + + +# ----- getting_started2 ------- + +# Declare a Python extension called getting_started2 +extension getting_started2 +: # sources + getting_started2.cpp + + # dependencies + ../build/boost_python + ; + +# Declare a test for the extension module +boost-python-runtest test2 + : # Python test driver + test_getting_started2.py + # extension modules to use + getting_started2 ; \ No newline at end of file diff --git a/example/README b/example/README index ef7dc78f..ab22de54 100644 --- a/example/README +++ b/example/README @@ -1,21 +1,6 @@ To get started with the Boost Python Library, use the examples getting_started1.cpp and getting_started2.cpp. -Examples for providing pickle support can be found in: - pickle1.cpp - pickle2.cpp - pickle3.cpp -See also: libs/python/doc/pickle.html - -Other advanced concepts are introduced by: - abstract.cpp - simple_vector.cpp - do_it_yourself_convts.cpp - -Examples for the cross-module support are provided by: - noncopyable_export.cpp - noncopyable_import.cpp - dvect.cpp - ivect.cpp -See also: libs/python/doc/cross_module.html + bjam -sTOOLS=your-toolset test +in this directory will build and run the examples. diff --git a/example/abstract.cpp b/example/abstract.cpp deleted file mode 100644 index 97e38c2e..00000000 --- a/example/abstract.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Example by Ullrich Koethe -#include "boost/python/class_builder.hpp" -#include - -struct Abstract -{ - virtual std::string test() = 0; -}; - -struct Abstract_callback: Abstract -{ - Abstract_callback(PyObject * self) - : m_self(self) - {} - - std::string test() - { - return boost::python::callback::call_method(m_self, "test"); - } - - PyObject * m_self; -}; - -BOOST_PYTHON_MODULE_INIT(abstract) -{ - boost::python::module_builder a("abstract"); - - boost::python::class_builder - a_class(a, "Abstract"); - a_class.def(boost::python::constructor<>()); // wrap a constructor - a_class.def(&Abstract::test, "test"); -} diff --git a/example/do_it_yourself_convts.cpp b/example/do_it_yourself_convts.cpp deleted file mode 100644 index 427e7688..00000000 --- a/example/do_it_yourself_convts.cpp +++ /dev/null @@ -1,121 +0,0 @@ -// Example by Ralf W. Grosse-Kunstleve -/* - - This example shows how to convert a class from and to native - Python objects, such as tuples. - - We do not want to expose the helper class MillerIndex as an - Extension Class. However, in order to simplify the wrapper code, - we want to define from_python() and to_python() functions for - class MillerIndex. - - Consider the alternatives: - - - Expose MillerIndex as an Extension Class. - We need a constructor MillerIndex(python::tuple). - Python function calls become more complex: - foo(MillerIndex((1,2,3)) instead of foo((1,2,3)) - We need a method such as MillerIndex().as_tuple(). - - - Define a wrapper function for each function that we - want to expose, e.g.: - void add(const IndexingSet& ixset, const python::tuple PyMIx) - - The first alternative introduces a new type that the user has to - deal with. Other modules using Miller indices might organize them in - different ways, for example to increase runtime efficiency for - important procedures. This means, the user has to know how to - convert between the different kinds of Miller index representations. - This can quickly become a nuisance. Relying on native Python data - structures minimizes the number of special types the user has to - learn and convert. Of course, this argument is only valid for - small and relatively simply classes. - - If there are many member functions with MillerIndex arguments, the - second alternative is impractical, and concentrating the conversion - mechanism in one central place is essential for code - maintainability. An added benefit is that more convenient (smarter) - conversion functions can be provided without cluttering the rest of - the wrapper code. - - */ - -#include -#include -#include -namespace python = boost::python; - -namespace { // Avoid cluttering the global namespace. - - // The helper class. - // - class MillerIndex { - public: - int v[3]; - }; - - // The main class. Imagine that there are MANY member functions - // like add() and get(). - // - class IndexingSet { - private: - std::vector VMIx; - public: - void add(const MillerIndex& MIx) { VMIx.push_back(MIx); } - MillerIndex get(std::size_t i) const { return VMIx[i]; } - }; -} - -BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE - - // Convert a Python tuple to a MillerIndex object. - // - MillerIndex from_python(PyObject* p, python::type) - { - python::tuple tup - = python::tuple(python::ref(p, python::ref::increment_count)); - if (tup.size() != 3) { - PyErr_SetString(PyExc_ValueError, - "expecting exactly 3 values in tuple."); - python::throw_error_already_set(); - } - MillerIndex result; - for (int i = 0; i < 3; i++) - result.v[i] = from_python(tup[i].get(), python::type()); - return result; - } - - // Similar conversion for MillerIndex objects passed by value. - // Not actually used, but included to show the principle. - // - MillerIndex from_python(PyObject* p, python::type) - { - return from_python(p, python::type()); - } - - // Convert a MillerIndex object to a Python tuple. - // - PyObject* to_python(const MillerIndex& hkl) - { - python::tuple result(3); - for (int i = 0; i < 3; i++) - result.set_item(i, python::ref(to_python(hkl.v[i]))); - return result.reference().release(); - } - -BOOST_PYTHON_END_CONVERSION_NAMESPACE - -BOOST_PYTHON_MODULE_INIT(do_it_yourself_convts) -{ - // Create an object representing this extension module. - python::module_builder this_module("do_it_yourself_convts"); - - // Create the Python type object for our extension class. - python::class_builder ixset_class(this_module, "IndexingSet"); - - // Add the __init__ function. - ixset_class.def(python::constructor<>()); - // Add the member functions. - ixset_class.def(&IndexingSet::add, "add"); - ixset_class.def(&IndexingSet::get, "get"); -} diff --git a/example/dvect.cpp b/example/dvect.cpp deleted file mode 100644 index fa1506fe..00000000 --- a/example/dvect.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// Example by Ralf W. Grosse-Kunstleve -// See root/libs/python/doc/cross_module.html for an introduction. - -#include "dvect.h" -#include "ivect.h" -#include -namespace python = boost::python; - -namespace { - -# include "dvect_conversions.cpp" -# include "ivect_conversions.cpp" - - vects::ivect dvect_as_ivect(const vects::dvect& dv) - { - vects::ivect iv(dv.size()); - vects::ivect::iterator iviter = iv.begin(); - for (int i = 0; i < dv.size(); i++) iviter[i] = static_cast(dv[i]); - return iv; - } -} - -# ifdef BOOST_MSVC // fixes for JIT debugging -# include -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) -{ - python::module_builder this_module("dvect"); - - python::class_builder dvect_class(this_module, "dvect"); - python::export_converters(dvect_class); - - python::import_converters ivect_converters("ivect", "ivect"); - - dvect_class.def(python::constructor()); - dvect_class.def(&vects::dvect::as_tuple, "as_tuple"); - dvect_class.def(dvect_as_ivect, "as_ivect"); - -# include "dvect_defs.cpp" -# include "ivect_defs.cpp" -} diff --git a/example/dvect.h b/example/dvect.h deleted file mode 100644 index d059f04d..00000000 --- a/example/dvect.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef DVECT_H -#define DVECT_H - -#include -#include - -namespace vects { - - struct dvect : public std::vector - { - dvect() : std::vector() {} - dvect(std::size_t n) : std::vector(n) {} - dvect(boost::python::tuple tuple) : std::vector(tuple.size()) - { - std::vector::iterator v_it = begin(); - for (int i = 0; i < tuple.size(); i++) - v_it[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(), - boost::python::type()); - } - - boost::python::tuple as_tuple() const - { - boost::python::tuple t(size()); - for (int i = 0; i < size(); i++) - t.set_item(i, - boost::python::ref(BOOST_PYTHON_CONVERSION::to_python((*this)[i]))); - return t; - } - }; -} - -#endif // DVECT_H diff --git a/example/dvect_conversions.cpp b/example/dvect_conversions.cpp deleted file mode 100644 index 21527243..00000000 --- a/example/dvect_conversions.cpp +++ /dev/null @@ -1,51 +0,0 @@ - // basics first: const reference converters - boost::python::tuple const_dvect_reference_as_tuple(const vects::dvect& dv) - { - return dv.as_tuple(); - } - - // to_python smart pointer conversions - std::auto_ptr dvect_as_auto_ptr(const vects::dvect& dv) - { - return std::auto_ptr(new vects::dvect(dv)); - } - boost::shared_ptr dvect_as_shared_ptr(const vects::dvect& dv) - { - return boost::shared_ptr(new vects::dvect(dv)); - } - - // smart pointers passed by value - boost::python::ref auto_ptr_value_dvect_as_tuple(std::auto_ptr dv) - { - if (dv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); - return dv->as_tuple().reference(); - } - boost::python::ref shared_ptr_value_dvect_as_tuple(boost::shared_ptr dv) - { - if (dv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); - return dv->as_tuple().reference(); - } - - // smart pointers passed by reference - boost::python::ref auto_ptr_reference_dvect_as_tuple(std::auto_ptr& dv) - { - if (dv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); - return dv->as_tuple().reference(); - } - boost::python::ref shared_ptr_reference_dvect_as_tuple(boost::shared_ptr& dv) - { - if (dv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); - return dv->as_tuple().reference(); - } - - // smart pointers passed by const reference - boost::python::ref auto_ptr_const_reference_dvect_as_tuple(const std::auto_ptr& dv) - { - if (dv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); - return dv->as_tuple().reference(); - } - boost::python::ref shared_ptr_const_reference_dvect_as_tuple(const boost::shared_ptr& dv) - { - if (dv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); - return dv->as_tuple().reference(); - } diff --git a/example/dvect_defs.cpp b/example/dvect_defs.cpp deleted file mode 100644 index 2739b219..00000000 --- a/example/dvect_defs.cpp +++ /dev/null @@ -1,13 +0,0 @@ - this_module.def(dvect_as_auto_ptr, "dvect_as_auto_ptr"); - this_module.def(dvect_as_shared_ptr, "dvect_as_shared_ptr"); - - this_module.def(const_dvect_reference_as_tuple, "const_dvect_reference_as_tuple"); - - this_module.def(auto_ptr_value_dvect_as_tuple, "auto_ptr_value_dvect_as_tuple"); - this_module.def(shared_ptr_value_dvect_as_tuple, "shared_ptr_value_dvect_as_tuple"); - - this_module.def(auto_ptr_reference_dvect_as_tuple, "auto_ptr_reference_dvect_as_tuple"); - this_module.def(shared_ptr_reference_dvect_as_tuple, "shared_ptr_reference_dvect_as_tuple"); - - this_module.def(auto_ptr_const_reference_dvect_as_tuple, "auto_ptr_const_reference_dvect_as_tuple"); - this_module.def(shared_ptr_const_reference_dvect_as_tuple, "shared_ptr_const_reference_dvect_as_tuple"); diff --git a/example/getting_started1.cpp b/example/getting_started1.cpp index 91a1f551..bdb79edc 100644 --- a/example/getting_started1.cpp +++ b/example/getting_started1.cpp @@ -9,22 +9,15 @@ namespace { // Avoid cluttering the global namespace. int square(int number) { return number * number; } } -#include +#include +#include namespace python = boost::python; // Python requires an exported function called init in every // extension module. This is where we build the module contents. -BOOST_PYTHON_MODULE_INIT(getting_started1) +BOOST_PYTHON_MODULE(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(...) { - boost::python::handle_exception(); - } + python::def("greet", greet); + python::def("square", square); } diff --git a/example/getting_started2.cpp b/example/getting_started2.cpp index 04fbcc29..bec7447e 100644 --- a/example/getting_started2.cpp +++ b/example/getting_started2.cpp @@ -21,25 +21,20 @@ namespace { // Avoid cluttering the global namespace. } } -#include -namespace python = boost::python; +#include +#include +#include -BOOST_PYTHON_MODULE_INIT(getting_started2) +BOOST_PYTHON_MODULE(getting_started2) { - // Create an object representing this extension module. - python::module_builder this_module("getting_started2"); - - // Create the Python type object for our extension class. - python::class_builder hello_class(this_module, "hello"); - - // Add the __init__ function. - hello_class.def(python::constructor()); - // Add a regular member function. - hello_class.def(&hello::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 hello_class!!! - hello_class.def(invite, "invite"); + using namespace boost::python; + class_("hello", init()) + // Add a regular member function. + .def("greet", &hello::greet) + // Add invite() as a member of hello! + .def("invite", invite) + ; + + // Also add invite() as a regular function to the module. + def("invite", invite); } diff --git a/example/ivect.cpp b/example/ivect.cpp deleted file mode 100644 index 35662b10..00000000 --- a/example/ivect.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// Example by Ralf W. Grosse-Kunstleve -// See root/libs/python/doc/cross_module.html for an introduction. - -#include "dvect.h" -#include "ivect.h" -#include -namespace python = boost::python; - -namespace { - -# include "dvect_conversions.cpp" -# include "ivect_conversions.cpp" - - vects::dvect ivect_as_dvect(const vects::ivect& iv) - { - vects::dvect dv(iv.size()); - vects::dvect::iterator dviter = dv.begin(); - for (int i = 0; i < iv.size(); i++) dviter[i] = static_cast(iv[i]); - return dv; - } -} - -# ifdef BOOST_MSVC // fixes for JIT debugging -# include -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) -{ - python::module_builder this_module("ivect"); - - python::class_builder ivect_class(this_module, "ivect"); - python::export_converters(ivect_class); - - python::import_converters dvect_converters("dvect", "dvect"); - - ivect_class.def(python::constructor()); - ivect_class.def(&vects::ivect::as_tuple, "as_tuple"); - ivect_class.def(ivect_as_dvect, "as_dvect"); - -# include "dvect_defs.cpp" -# include "ivect_defs.cpp" -} - diff --git a/example/ivect.h b/example/ivect.h deleted file mode 100644 index b8d52246..00000000 --- a/example/ivect.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef IVECT_H -#define IVECT_H - -#include -#include - -namespace vects { - - struct ivect : public std::vector - { - ivect() : std::vector() {} - ivect(std::size_t n) : std::vector(n) {} - ivect(boost::python::tuple tuple) : std::vector(tuple.size()) - { - std::vector::iterator v_it = begin(); - for (int i = 0; i < tuple.size(); i++) - v_it[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(), - boost::python::type()); - } - - boost::python::tuple as_tuple() const - { - boost::python::tuple t(size()); - for (int i = 0; i < size(); i++) - t.set_item(i, - boost::python::ref(BOOST_PYTHON_CONVERSION::to_python((*this)[i]))); - return t; - } - }; -} - -#endif // IVECT_H diff --git a/example/ivect_conversions.cpp b/example/ivect_conversions.cpp deleted file mode 100644 index 4f59573d..00000000 --- a/example/ivect_conversions.cpp +++ /dev/null @@ -1,51 +0,0 @@ - // basics first: const reference converters - boost::python::tuple const_ivect_reference_as_tuple(const vects::ivect& iv) - { - return iv.as_tuple(); - } - - // to_python smart pointer conversions - std::auto_ptr ivect_as_auto_ptr(const vects::ivect& iv) - { - return std::auto_ptr(new vects::ivect(iv)); - } - boost::shared_ptr ivect_as_shared_ptr(const vects::ivect& iv) - { - return boost::shared_ptr(new vects::ivect(iv)); - } - - // smart pointers passed by value - boost::python::ref auto_ptr_value_ivect_as_tuple(std::auto_ptr iv) - { - if (iv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); - return iv->as_tuple().reference(); - } - boost::python::ref shared_ptr_value_ivect_as_tuple(boost::shared_ptr iv) - { - if (iv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); - return iv->as_tuple().reference(); - } - - // smart pointers passed by reference - boost::python::ref auto_ptr_reference_ivect_as_tuple(std::auto_ptr& iv) - { - if (iv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); - return iv->as_tuple().reference(); - } - boost::python::ref shared_ptr_reference_ivect_as_tuple(boost::shared_ptr& iv) - { - if (iv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); - return iv->as_tuple().reference(); - } - - // smart pointers passed by const reference - boost::python::ref auto_ptr_const_reference_ivect_as_tuple(const std::auto_ptr& iv) - { - if (iv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); - return iv->as_tuple().reference(); - } - boost::python::ref shared_ptr_const_reference_ivect_as_tuple(const boost::shared_ptr& iv) - { - if (iv.get() == 0) return boost::python::ref(Py_None, boost::python::ref::increment_count); - return iv->as_tuple().reference(); - } diff --git a/example/ivect_defs.cpp b/example/ivect_defs.cpp deleted file mode 100644 index 811c243d..00000000 --- a/example/ivect_defs.cpp +++ /dev/null @@ -1,13 +0,0 @@ - this_module.def(ivect_as_auto_ptr, "ivect_as_auto_ptr"); - this_module.def(ivect_as_shared_ptr, "ivect_as_shared_ptr"); - - this_module.def(const_ivect_reference_as_tuple, "const_ivect_reference_as_tuple"); - - this_module.def(auto_ptr_value_ivect_as_tuple, "auto_ptr_value_ivect_as_tuple"); - this_module.def(shared_ptr_value_ivect_as_tuple, "shared_ptr_value_ivect_as_tuple"); - - this_module.def(auto_ptr_reference_ivect_as_tuple, "auto_ptr_reference_ivect_as_tuple"); - this_module.def(shared_ptr_reference_ivect_as_tuple, "shared_ptr_reference_ivect_as_tuple"); - - this_module.def(auto_ptr_const_reference_ivect_as_tuple, "auto_ptr_const_reference_ivect_as_tuple"); - this_module.def(shared_ptr_const_reference_ivect_as_tuple, "shared_ptr_const_reference_ivect_as_tuple"); diff --git a/example/nested.cpp b/example/nested.cpp deleted file mode 100644 index a5632d16..00000000 --- a/example/nested.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Example by Ralf W. Grosse-Kunstleve - -/* - This example shows how convert a nested Python tuple. - */ - -#include -#include - -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())); - for (int j = 0; j < inner.size(); j++) { - double x = BOOST_PYTHON_CONVERSION::from_python(inner[j].get(), - boost::python::type()); - 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"); -} diff --git a/example/noncopyable.h b/example/noncopyable.h deleted file mode 100644 index de7b3672..00000000 --- a/example/noncopyable.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef NONCOPYABLE_H -#define NONCOPYABLE_H - -class store -{ - private: - store(const store&) { } // Disable the copy constructor. - int number; - public: - store(const int i) : number(i) { } - int recall() const { return number; } -}; - -#endif // NONCOPYABLE_H diff --git a/example/noncopyable_export.cpp b/example/noncopyable_export.cpp deleted file mode 100644 index 3a81db75..00000000 --- a/example/noncopyable_export.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Example by Ralf W. Grosse-Kunstleve -// See root/libs/python/doc/cross_module.html for an introduction. - -#include -namespace python = boost::python; - -#include "noncopyable.h" - -# ifdef BOOST_MSVC // fixes for JIT debugging -# include -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) -{ - python::module_builder this_module("noncopyable_export"); - - python::class_builder store_class(this_module, "store"); - python::export_converters_noncopyable(store_class); - - store_class.def(python::constructor()); - store_class.def(&store::recall, "recall"); -} diff --git a/example/noncopyable_import.cpp b/example/noncopyable_import.cpp deleted file mode 100644 index d4227642..00000000 --- a/example/noncopyable_import.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Example by Ralf W. Grosse-Kunstleve -// See root/libs/python/doc/cross_module.html for an introduction. - -#include -namespace python = boost::python; - -#include "noncopyable.h" - -namespace { // Avoid cluttering the global namespace. - - // A function with store objects as both input and output parameters. - // Because the copy constructor is disabled, we cannot pass a store - // object by value. Instead, we pass a smart pointer. - std::auto_ptr add_stores(const store& s1, const store& s2) - { - int sum = s1.recall() + s2.recall(); - std::auto_ptr ss = std::auto_ptr(new store(sum)); - return ss; - } -} - -# ifdef BOOST_MSVC // fixes for JIT debugging -# include -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) -{ - python::module_builder this_module("noncopyable_import"); - - python::import_converters - dvect_converters("noncopyable_export", "store"); - - // Imagine all the additional classes with member functions - // that have store objects as input and output parameters. - // Lots and lots of them. - // However, to keep this example simple, we only define a - // module-level function. - this_module.def(add_stores, "add_stores"); -} diff --git a/example/pickle1.cpp b/example/pickle1.cpp deleted file mode 100644 index af041e72..00000000 --- a/example/pickle1.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Example by Ralf W. Grosse-Kunstleve - -/* - This example shows how to make an Extension Class "pickleable". - - The world class below can be fully restored by passing the - appropriate argument to the constructor. Therefore it is sufficient - to define the pickle interface method __getinitargs__. - - For more information refer to boost/libs/python/doc/pickle.html. - */ - -#include - -#include -namespace python = boost::python; - -namespace { // Avoid cluttering the global namespace. - - // A friendly class. - class world - { - private: - std::string country; - int secret_number; - public: - world(const std::string& country) : secret_number(0) { - this->country = country; - } - std::string greet() const { return "Hello from " + country + "!"; } - std::string get_country() const { return country; } - }; - - // Support for pickle. - python::ref world_getinitargs(const world& w) { - python::tuple result(1); - result.set_item(0, w.get_country()); - return result.reference(); - } -} - -BOOST_PYTHON_MODULE_INIT(pickle1) -{ - // Create an object representing this extension module. - python::module_builder this_module("pickle1"); - - // Create the Python type object for our extension class. - python::class_builder world_class(this_module, "world"); - - // Add the __init__ function. - world_class.def(python::constructor()); - // Add a regular member function. - world_class.def(&world::greet, "greet"); - - // Support for pickle. - world_class.def(world_getinitargs, "__getinitargs__"); -} diff --git a/example/pickle2.cpp b/example/pickle2.cpp deleted file mode 100644 index 781615cd..00000000 --- a/example/pickle2.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// Example by Ralf W. Grosse-Kunstleve - -/* - This example shows how to make an Extension Class "pickleable". - - The world class below contains member data (secret_number) that - cannot be restored by any of the constructors. Therefore it is - necessary to provide the __getstate__/__setstate__ pair of pickle - interface methods. - - For simplicity, the __dict__ is not included in the result of - __getstate__. This is not generally recommended, but a valid - approach if it is anticipated that the object's __dict__ will - always be empty. Note that safety guard are provided to catch the - cases where this assumption is not true. - - pickle3.cpp shows how to include the object's __dict__ in the - result of __getstate__. - - For more information refer to boost/libs/python/doc/pickle.html. - */ - -#include - -#include -namespace python = boost::python; - -namespace { // Avoid cluttering the global namespace. - - // A friendly class. - class world - { - public: - world(const std::string& country) : secret_number(0) { - this->country = country; - } - std::string greet() const { return "Hello from " + country + "!"; } - std::string get_country() const { return country; } - void set_secret_number(int number) { secret_number = number; } - int get_secret_number() const { return secret_number; } - private: - std::string country; - int secret_number; - }; - - // Support for pickle. - - using BOOST_PYTHON_CONVERSION::from_python; - - python::ref world_getinitargs(const world& w) { - python::tuple result(1); - result.set_item(0, w.get_country()); - return result.reference(); // returning the reference avoids the copying. - } - - python::ref world_getstate(const world& w) { - python::tuple result(1); - result.set_item(0, w.get_secret_number()); - return result.reference(); // returning the reference avoids the copying. - } - - void world_setstate(world& w, python::tuple state) { - if (state.size() != 1) { - PyErr_SetString(PyExc_ValueError, - "Unexpected argument in call to __setstate__."); - python::throw_error_already_set(); - } - int number = from_python(state[0].get(), python::type()); - if (number != 42) - w.set_secret_number(number); - } -} - -BOOST_PYTHON_MODULE_INIT(pickle2) -{ - // Create an object representing this extension module. - python::module_builder this_module("pickle2"); - - // Create the Python type object for our extension class. - python::class_builder world_class(this_module, "world"); - - // Add the __init__ function. - world_class.def(python::constructor()); - // Add a regular member function. - world_class.def(&world::greet, "greet"); - world_class.def(&world::get_secret_number, "get_secret_number"); - world_class.def(&world::set_secret_number, "set_secret_number"); - - // Support for pickle. - world_class.def(world_getinitargs, "__getinitargs__"); - world_class.def(world_getstate, "__getstate__"); - world_class.def(world_setstate, "__setstate__"); -} diff --git a/example/pickle3.cpp b/example/pickle3.cpp deleted file mode 100644 index 5f32b1f3..00000000 --- a/example/pickle3.cpp +++ /dev/null @@ -1,143 +0,0 @@ -// Example by Ralf W. Grosse-Kunstleve - -/* - This example shows how to make an Extension Class "pickleable". - - The world class below contains member data (secret_number) that - cannot be restored by any of the constructors. Therefore it is - necessary to provide the __getstate__/__setstate__ pair of pickle - interface methods. - - The object's __dict__ is included in the result of __getstate__. - This requires more code (compare with pickle2.cpp), but is - unavoidable if the object's __dict__ is not always empty. - - For more information refer to boost/libs/python/doc/pickle.html. - */ - -#include - -#include -namespace python = boost::python; - -namespace boost { namespace python { - - ref getattr(PyObject* o, const std::string& attr_name) { - return ref(PyObject_GetAttrString(o, const_cast(attr_name.c_str()))); - } - ref getattr(const ref& r, const std::string& attr_name) { - return getattr(r.get(), attr_name); - } - -}} - -namespace { // Avoid cluttering the global namespace. - - // A friendly class. - class world - { - public: - world(const std::string& country) : secret_number(0) { - this->country = country; - } - std::string greet() const { return "Hello from " + country + "!"; } - std::string get_country() const { return country; } - void set_secret_number(int number) { secret_number = number; } - int get_secret_number() const { return secret_number; } - private: - std::string country; - int secret_number; - }; - - // Support for pickle. - python::ref world_getinitargs(const world& w) { - python::tuple result(1); - result.set_item(0, w.get_country()); - return result.reference(); // returning the reference avoids the copying. - } - - python::ref world_getstate(python::tuple const & args, - python::dictionary const & keywords); - - PyObject* world_setstate(python::tuple const & args, - python::dictionary const & keywords); -} - -BOOST_PYTHON_MODULE_INIT(pickle3) -{ - // Create an object representing this extension module. - python::module_builder this_module("pickle3"); - - // Create the Python type object for our extension class. - python::class_builder world_class(this_module, "world"); - - // Add the __init__ function. - world_class.def(python::constructor()); - // Add a regular member function. - world_class.def(&world::greet, "greet"); - world_class.def(&world::get_secret_number, "get_secret_number"); - world_class.def(&world::set_secret_number, "set_secret_number"); - - // Support for pickle. - world_class.def(world_getinitargs, "__getinitargs__"); - world_class.def_raw(world_getstate, "__getstate__"); - world_class.def_raw(world_setstate, "__setstate__"); - world_class.getstate_manages_dict(); -} - -namespace { - - using BOOST_PYTHON_CONVERSION::from_python; - using boost::python::type; - using boost::python::ref; - using boost::python::tuple; - using boost::python::list; - using boost::python::dictionary; - using boost::python::getattr; - - ref world_getstate(tuple const & args, dictionary const & keywords) - { - if(args.size() != 1 || keywords.size() != 0) { - PyErr_SetString(PyExc_TypeError, "wrong number of arguments"); - boost::python::throw_error_already_set(); - } - const world& w = from_python(args[0].get(), type()); - ref mydict = getattr(args[0], "__dict__"); - tuple result(2); - // store the object's __dict__ - result.set_item(0, mydict); - // store the internal state of the C++ object - result.set_item(1, w.get_secret_number()); - return result.reference(); // returning the reference avoids the copying. - } - - PyObject* world_setstate(tuple const & args, dictionary const & keywords) - { - if(args.size() != 2 || keywords.size() != 0) { - PyErr_SetString(PyExc_TypeError, "wrong number of arguments"); - boost::python::throw_error_already_set(); - } - world& w = from_python(args[0].get(), type()); - ref mydict = getattr(args[0], "__dict__"); - tuple state = from_python(args[1].get(), type()); - if (state.size() != 2) { - PyErr_SetString(PyExc_ValueError, - "Unexpected argument in call to __setstate__."); - python::throw_error_already_set(); - } - // restore the object's __dict__ - dictionary odict = from_python(mydict.get(), type()); - const dictionary& pdict = from_python(state[0].get(), type()); - list pkeys(pdict.keys()); - for (int i = 0; i < pkeys.size(); i++) { - ref k(pkeys[i]); - //odict[k] = pdict[k]; // XXX memory leak! - odict[k] = pdict.get_item(k); // this does not leak. - } - // restore the internal state of the C++ object - int number = from_python(state[1].get(), type()); - if (number != 42) - w.set_secret_number(number); - return python::detail::none(); - } -} diff --git a/example/project.zip b/example/project.zip deleted file mode 100644 index d863defdb784ca6864f83a6ca22443b65259bda6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1469 zcmWIWW@Zs#U|`^2aL-z=bNJRCn;-@ThExUy25|-khJvE}tkmQZ{iOW-;u77Y(#)I` zy{yFC;4lt758rb>t3xzAbWR3noDA1E=@II2>b$;QpoiAkGoFDO>vZ%y&pv%x^yxc4 zUnl>k@BD!qLN8pt%&yFu9jCV;DYheN#*RAAx;np&b}kpB7!c0*nYCVr<@xLNO-u|7 zuB;3U{7BC5O3Y2m%t>txiS@tjAW+jk<^Kk+Ul+V?bbRY|TC!w8Q-~ekh-xlMm~)Kl=XCCX%Bmwa zJ??+)J&)AN_8(iU8IzDV_4v92v(_w~TPV$OD&OGBa;Aste>_*2dg_PFg{y5cQ!%Rh;e%O!zHU z=F3kDH@6Qzefsy)th(=i|JmH!B-`b*$vxC-=A2VOmUAN>{}8zTWaDk!$KUtun%1&q|%IrgyH9vOj*qP|t9e>?k zFKqkgr&rZ)=3f@CZ~a^S+L2c_Zrg(XKX1?Vxa&_iygRr-^U9SUF(ID>E`5=h9~v2H z^Y8j1ZnYwte|bH}C*99faoZGAP~-2sW!0nU(Uph0k3XLozOVP?ksFmeq_%bC&wZlx z#<*WBw0E;HU#Oa(=H{Lbd1rAq{wp&~XO}0e=BVKH+tvNuB6N59$@3-acLx1=R(1St z&C%39I}|HonO-?@wsdOR1YDk~87f`weBlK5xqm--J!ejv{Cw-PmbIaqT=qWNSE$sR zZZk>ZT47qup$oiRUE+`U5y^FB)_R@1rIH!yj0_A985tM^P?Kv>X-;afYk+U|VFRAM z;=knOQZ{_O@MYg!w%t5#$7cO55ZZdNU`dkp%U|!))is&pb@uA-W!f6|AXBNo+`Q#t z@SVJEvzgqLW~}OOPfNKk8)5ZJw_4i9PwGOZHJ{3}p3qa)M+Hh1J``L`@Z(8e-}`w+ zOu}`Q+z*`BF7xi4?IFi|j=ktEFYiPJwZ>=D7$fs~L>5fipHV6?r=xoH_8i&c}HD)t{a<}NprJAG4!c6I;i(?P6q^Ws*&im0y- z4c#04)?z_I=HDBFdgp!#ah9!HeV(ObbNh~xzpu*oTdv+ZYgSUC<@wb<$24CU{Etw} zeeUqWA|P8Th<%qr^S>o0Ydo?ng}-Mn|NryDoT4?JW$l|{4{>p_9a#Q*{V+3R&c zGz@bf1!{mdBa;XN?jj4Mhmk>nVOt}Jg`)sNHUwLN1JVjHq#em>Xz_!r8C&!tG@CIa ticqh_TySE5=*I0&kZw>i`tR7yg3uk{&B_LnVPRll_{PA%u#pAC0|1J>SqlIF diff --git a/example/richcmp1.cpp b/example/richcmp1.cpp deleted file mode 100644 index 884fdfda..00000000 --- a/example/richcmp1.cpp +++ /dev/null @@ -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 -#include "vector_wrapper.h" - -namespace vects { - - struct dvect : public std::vector - { - dvect() : std::vector() {} - dvect(size_t n) : std::vector(n) {} - dvect(boost::python::tuple tuple) : std::vector(tuple.size()) - { - std::vector::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()); - } - - 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 \ - operator##oper(const dvect& lhs, const dvect& rhs) \ - { \ - if (lhs.size() != rhs.size()) { \ - PyErr_SetString(PyExc_ValueError, "vectors have different sizes"); \ - boost::python::throw_error_already_set(); \ - } \ - std::vector result(lhs.size()); \ - for (std::size_t i=0; i) - DVECT_BINARY_OPERATORS(>=) -# undef VECTOR_BINARY_OPERATORS - }; - -} // namespace - - -namespace { - - void init_module(boost::python::module_builder& this_module) - { - (void) example::wrap_vector(this_module, "vector_of_bool", bool()); - - boost::python::class_builder py_dvect(this_module, "dvect"); - - py_dvect.def(boost::python::constructor()); - 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()); - } - -} // namespace - -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); -} diff --git a/example/richcmp2.cpp b/example/richcmp2.cpp deleted file mode 100644 index 993c6800..00000000 --- a/example/richcmp2.cpp +++ /dev/null @@ -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 - -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 py_code(this_module, "code"); - - py_code.def(boost::python::constructor<>()); - py_code.def(boost::python::constructor()); - 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 - -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); -} diff --git a/example/richcmp3.cpp b/example/richcmp3.cpp deleted file mode 100644 index 02a2ebcb..00000000 --- a/example/richcmp3.cpp +++ /dev/null @@ -1,175 +0,0 @@ -// Example by Ralf W. Grosse-Kunstleve & Nicholas K. Sauter. -// Comprehensive operator overloading for two vector types and scalars. - -#include -#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"); \ - boost::python::throw_error_already_set(); \ - } \ - result_type result(lhs.size()); \ - for (std::size_t i=0; i, vect_type1, <, vect_type2) \ - VECT_VECT_OPERATORS(std::vector, vect_type1, <=, vect_type2) \ - VECT_VECT_OPERATORS(std::vector, vect_type1, ==, vect_type2) \ - VECT_VECT_OPERATORS(std::vector, vect_type1, !=, vect_type2) \ - VECT_VECT_OPERATORS(std::vector, vect_type1, >, vect_type2) \ - VECT_VECT_OPERATORS(std::vector, 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, vect_type, <, scalar_type) \ - VECT_SCALAR_OPERATORS(std::vector, vect_type, <=, scalar_type) \ - VECT_SCALAR_OPERATORS(std::vector, vect_type, ==, scalar_type) \ - VECT_SCALAR_OPERATORS(std::vector, vect_type, !=, scalar_type) \ - VECT_SCALAR_OPERATORS(std::vector, vect_type, >, scalar_type) \ - VECT_SCALAR_OPERATORS(std::vector, 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 - dvect_class(this_module, "dvect"); - boost::python::class_builder - ivect_class(this_module, "ivect"); - - dvect_class.def(boost::python::constructor()); - dvect_class.def(&vects::dvect::as_tuple,"as_tuple"); - - dvect_class.def(boost::python::operators()); - dvect_class.def(boost::python::operators(), - boost::python::right_operand() ); - dvect_class.def(boost::python::operators(), - boost::python::left_operand() ); - dvect_class.def(boost::python::operators(), - boost::python::right_operand() ); - - dvect_class.def(boost::python::operators()); - dvect_class.def(boost::python::operators(), - boost::python::right_operand() ); - // left_operand not needed since Python uses reflection - dvect_class.def(boost::python::operators(), - boost::python::right_operand() ); - - ivect_class.def(boost::python::constructor()); - ivect_class.def(&vects::ivect::as_tuple,"as_tuple"); - - ivect_class.def(boost::python::operators()); - ivect_class.def(boost::python::operators(), - boost::python::right_operand() ); - ivect_class.def(boost::python::operators(), - boost::python::left_operand() ); - ivect_class.def(boost::python::operators(), - boost::python::right_operand() ); - - ivect_class.def(boost::python::operators()); - ivect_class.def(boost::python::operators(), - boost::python::right_operand() ); - // left_operand not needed since Python uses reflection - ivect_class.def(boost::python::operators(), - boost::python::right_operand() ); - } - -} // namespace - -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); -} diff --git a/example/simple_vector.cpp b/example/simple_vector.cpp deleted file mode 100644 index bc6e3408..00000000 --- a/example/simple_vector.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// Example by Ralf W. Grosse-Kunstleve - -#include -namespace python = boost::python; - -namespace { // Avoid cluttering the global namespace. - - // A wrapper is used to define additional constructors. - // - struct vector_double_wrapper: std::vector - { - // Tell the compiler how to convert a base class object to - // this wrapper object. - vector_double_wrapper(PyObject*, const std::vector& vd) - : std::vector(vd) {} - - vector_double_wrapper(PyObject* self) - : std::vector() {} - - vector_double_wrapper(PyObject* self, int n) - : std::vector(n) {} - - vector_double_wrapper(PyObject* self, python::tuple tuple) - : std::vector(tuple.size()) - { - std::vector::iterator vd = begin(); - for (int i = 0; i < tuple.size(); i++) - vd[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(), - python::type()); - } - }; - - void raise_vector_IndexError() { - PyErr_SetString(PyExc_IndexError, "vector index out of range"); - python::throw_error_already_set(); - } - - double getitem(const std::vector& vd, std::size_t key) { - if (key >= vd.size()) raise_vector_IndexError(); - return vd[key]; - } - - void setitem(std::vector& vd, std::size_t key, double d) { - if (key >= vd.size()) raise_vector_IndexError(); - std::vector::iterator vditer = vd.begin(); - vditer[key] = d; - } - - void delitem(std::vector& vd, std::size_t key) { - if (key >= vd.size()) raise_vector_IndexError(); - std::vector::iterator vditer = vd.begin(); - vd.erase(vditer + key); - } - - // Convert vector_double to a regular Python tuple. - // - python::tuple as_tuple(const std::vector& vd) - { - python::tuple t(vd.size()); - for (int i = 0; i < vd.size(); i++) t.set_item(i, - python::ref(BOOST_PYTHON_CONVERSION::to_python(vd[i]))); - return t; - } - - // Function returning a vector_double object to Python. - // - std::vector foo(int n) - { - std::vector vd(n); - std::vector::iterator vditer = vd.begin(); - for (int i = 0; i < n; i++) vditer[i] = double(i); - return vd; - } - - // Same as foo(), but avoid copying on return. - // - std::auto_ptr > bar(int n) - { - std::auto_ptr > vdptr(new std::vector(n)); - std::vector::iterator vditer = vdptr->begin(); - for (int i = 0; i < n; i++) vditer[i] = double(10 * i); - return vdptr; - } -} - -BOOST_PYTHON_MODULE_INIT(simple_vector) -{ - python::module_builder this_module("simple_vector"); - - python::class_builder, vector_double_wrapper> - vector_double(this_module, "vector_double"); - - vector_double.def(python::constructor()); - vector_double.def(python::constructor<>()); - vector_double.def(python::constructor()); - vector_double.def(&std::vector::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"); -} diff --git a/example/test_abstract.py b/example/test_abstract.py deleted file mode 100644 index a48aff1b..00000000 --- a/example/test_abstract.py +++ /dev/null @@ -1,24 +0,0 @@ -# Example by Ullrich Koethe -r'''>>> from abstract import * - >>> class A(Abstract): - ... def __init__(self, text): - ... Abstract.__init__(self) # call the base class constructor - ... self.text = text - ... def test(self): # implement abstract function - ... return self.text - ... - >>> a = A("Hello") - >>> a.test() - 'Hello' -''' - -def run(args = None): - if args is not None: - import sys - sys.argv = args - import doctest, test_abstract - return doctest.testmod(test_abstract) - -if __name__ == '__main__': - import sys - sys.exit(run()[0]) diff --git a/example/test_cross_module.py b/example/test_cross_module.py deleted file mode 100644 index c5e2bef6..00000000 --- a/example/test_cross_module.py +++ /dev/null @@ -1,140 +0,0 @@ -r'''>>> import tst_noncopyable - >>> tst_noncopyable.f() - 1 - 2 - 3 - >>> import tst_dvect1 - >>> tst_dvect1.f() - (1.0, 2.0, 3.0, 4.0, 5.0) - (1, 2, 3, 4, 5) - (1, 2, 3, 4, 5) - (1, 2, 3, 4, 5) - (1, 2, 3, 4, 5) - (1, 2, 3, 4, 5) - (1, 2, 3, 4, 5) - >>> import tst_ivect1 - >>> tst_ivect1.f() - (1, 2, 3, 4, 5) - (1.0, 2.0, 3.0, 4.0, 5.0) - (1.0, 2.0, 3.0, 4.0, 5.0) - (1.0, 2.0, 3.0, 4.0, 5.0) - (1.0, 2.0, 3.0, 4.0, 5.0) - (1.0, 2.0, 3.0, 4.0, 5.0) - (1.0, 2.0, 3.0, 4.0, 5.0) - >>> import sys - >>> if ("--broken-auto-ptr" in sys.argv): - ... broken_auto_ptr = 1 - ... else: - ... broken_auto_ptr = 0 - >>> import tst_dvect2 - >>> tst_dvect2.f(broken_auto_ptr) - 1. auto_ptr_value_ivect_as_tuple - (1, 2, 3, 4, 5) - 2. auto_ptr_value_ivect_as_tuple - None - 1. auto_ptr_value_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 2. auto_ptr_value_dvect_as_tuple - None - 1. shared_ptr_value_ivect_as_tuple - (1, 2, 3, 4, 5) - 2. shared_ptr_value_ivect_as_tuple - (1, 2, 3, 4, 5) - 1. shared_ptr_value_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 2. shared_ptr_value_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 1. auto_ptr_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 2. auto_ptr_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 1. auto_ptr_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 2. auto_ptr_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 1. shared_ptr_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 2. shared_ptr_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 1. shared_ptr_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 2. shared_ptr_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 1. auto_ptr_const_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 2. auto_ptr_const_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 1. auto_ptr_const_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 2. auto_ptr_const_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 1. shared_ptr_const_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 2. shared_ptr_const_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 1. shared_ptr_const_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 2. shared_ptr_const_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - >>> import tst_ivect2 - >>> tst_ivect2.f(broken_auto_ptr) - 1. auto_ptr_value_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 2. auto_ptr_value_dvect_as_tuple - None - 1. auto_ptr_value_ivect_as_tuple - (1, 2, 3, 4, 5) - 2. auto_ptr_value_ivect_as_tuple - None - 1. shared_ptr_value_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 2. shared_ptr_value_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 1. shared_ptr_value_ivect_as_tuple - (1, 2, 3, 4, 5) - 2. shared_ptr_value_ivect_as_tuple - (1, 2, 3, 4, 5) - 1. auto_ptr_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 2. auto_ptr_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 1. auto_ptr_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 2. auto_ptr_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 1. shared_ptr_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 2. shared_ptr_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 1. shared_ptr_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 2. shared_ptr_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 1. auto_ptr_const_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 2. auto_ptr_const_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 1. auto_ptr_const_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 2. auto_ptr_const_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 1. shared_ptr_const_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 2. shared_ptr_const_reference_dvect_as_tuple - (1.0, 2.0, 3.0, 4.0, 5.0) - 1. shared_ptr_const_reference_ivect_as_tuple - (1, 2, 3, 4, 5) - 2. shared_ptr_const_reference_ivect_as_tuple - (1, 2, 3, 4, 5) -''' - -def run(args = None): - if args is not None: - import sys - sys.argv = args - import doctest, test_cross_module - return doctest.testmod(test_cross_module) - -if __name__ == '__main__': - import sys - sys.exit(run()[0]) diff --git a/example/test_do_it_yourself_convts.py b/example/test_do_it_yourself_convts.py deleted file mode 100644 index 6f5fa5a0..00000000 --- a/example/test_do_it_yourself_convts.py +++ /dev/null @@ -1,23 +0,0 @@ -r'''>>> import do_it_yourself_convts - >>> ixset = do_it_yourself_convts.IndexingSet() - >>> ixset.add((1,2,3)) - >>> ixset.add((4,5,6)) - >>> ixset.add((7,8,9)) - >>> print ixset.get(0) - (1, 2, 3) - >>> print ixset.get(1) - (4, 5, 6) - >>> print ixset.get(2) - (7, 8, 9) -''' - -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) - -if __name__ == '__main__': - import sys - sys.exit(run()[0]) diff --git a/example/test_example1.py b/example/test_example1.py deleted file mode 100644 index 3a30cb5b..00000000 --- a/example/test_example1.py +++ /dev/null @@ -1,51 +0,0 @@ -r''' -// (C) Copyright David Abrahams 2000. 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. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -That's it! If we build this shared library and put it on our PYTHONPATH we can -now access our C++ class and function from Python. - - >>> import hello - >>> hi_world = hello.world(3) - >>> hi_world.get() - 'hi, world' - >>> hello.length(hi_world) - 9 - -We can even make a subclass of hello.world: - - - >>> class my_subclass(hello.world): - ... def get(self): - ... return 'hello, world' - ... - >>> y = my_subclass(2) - >>> y.get() - 'hello, world' - -Pretty cool! You can't do that with an ordinary Python extension type! - - >>> hello.length(y) - 9 - -Of course, you may now have a slightly empty feeling in the pit of your little -pythonic stomach. Perhaps you feel your subclass deserves to have a length() of -12? If so, read on... -''' -from hello import * - -def run(args = None): - if args is not None: - import sys - sys.argv = args - import doctest, test_example1 - return doctest.testmod(test_example1) - -if __name__ == '__main__': - import sys - sys.exit(run()[0]) diff --git a/example/test_getting_started1.py b/example/test_getting_started1.py deleted file mode 100644 index cd8fb59e..00000000 --- a/example/test_getting_started1.py +++ /dev/null @@ -1,18 +0,0 @@ -r'''>>> import getting_started1 - >>> print getting_started1.greet() - hello, world - >>> number = 11 - >>> print number, '*', number, '=', getting_started1.square(number) - 11 * 11 = 121 -''' - -def run(args = None): - if args is not None: - import sys - sys.argv = args - import doctest, test_getting_started1 - return doctest.testmod(test_getting_started1) - -if __name__ == '__main__': - import sys - sys.exit(run()[0]) diff --git a/example/test_getting_started2.py b/example/test_getting_started2.py deleted file mode 100644 index ccfaa4f1..00000000 --- a/example/test_getting_started2.py +++ /dev/null @@ -1,31 +0,0 @@ -r'''>>> from getting_started2 import * - >>> hi = hello('California') - >>> hi.greet() - 'Hello from California' - >>> invite(hi) - 'Hello from California! Please come soon!' - >>> hi.invite() - 'Hello from California! Please come soon!' - - >>> class wordy(hello): - ... def greet(self): - ... return hello.greet(self) + ', where the weather is fine' - ... - >>> hi2 = wordy('Florida') - >>> hi2.greet() - 'Hello from Florida, where the weather is fine' - >>> invite(hi2) - 'Hello from Florida! Please come soon!' -''' - -def run(args = None): - if args is not None: - import sys - sys.argv = args - import doctest, test_getting_started2 - return doctest.testmod(test_getting_started2) - -if __name__ == '__main__': - import sys - sys.exit(run()[0]) - diff --git a/example/test_nested.py b/example/test_nested.py deleted file mode 100644 index e9abbf0f..00000000 --- a/example/test_nested.py +++ /dev/null @@ -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]) diff --git a/example/test_pickle1.py b/example/test_pickle1.py deleted file mode 100644 index 48c76a5f..00000000 --- a/example/test_pickle1.py +++ /dev/null @@ -1,33 +0,0 @@ -r'''>>> import pickle1 - >>> import re - >>> import pickle - >>> pickle1.world.__module__ - 'pickle1' - >>> pickle1.world.__safe_for_unpickling__ - 1 - >>> pickle1.world.__reduce__() - 'world' - >>> assert re.match( - ... "\(, \('Hello',\)\)", - ... repr(pickle1.world('Hello').__reduce__())) - >>> - >>> wd = pickle1.world('California') - >>> pstr = pickle.dumps(wd) - >>> wl = pickle.loads(pstr) - >>> print wd.greet() - Hello from California! - >>> print wl.greet() - Hello from California! -''' - -def run(args = None): - if args is not None: - import sys - sys.argv = args - import doctest, test_pickle1 - return doctest.testmod(test_pickle1) - -if __name__ == '__main__': - import sys - sys.exit(run()[0]) - diff --git a/example/test_pickle2.py b/example/test_pickle2.py deleted file mode 100644 index bafa9875..00000000 --- a/example/test_pickle2.py +++ /dev/null @@ -1,47 +0,0 @@ -r'''>>> import pickle2 - >>> import re - >>> import pickle - >>> pickle2.world.__module__ - 'pickle2' - >>> pickle2.world.__safe_for_unpickling__ - 1 - >>> pickle2.world.__reduce__() - 'world' - >>> assert re.match( - ... "\(, \('Hello',\), \(0,\)\)", - ... repr(pickle2.world('Hello').__reduce__())) - >>> - >>> for number in (24, 42): - ... wd = pickle2.world('California') - ... wd.set_secret_number(number) - ... pstr = pickle.dumps(wd) - ... wl = pickle.loads(pstr) - ... print wd.greet(), wd.get_secret_number() - ... print wl.greet(), wl.get_secret_number() - Hello from California! 24 - Hello from California! 24 - Hello from California! 42 - Hello from California! 0 - -# Now show that the __dict__ is not taken care of. - >>> wd = pickle2.world('California') - >>> wd.x = 1 - >>> wd.__dict__ - {'x': 1} - >>> try: pstr = pickle.dumps(wd) - ... except RuntimeError, err: print err[0] - ... - Incomplete pickle support (__getstate_manages_dict__ not set) -''' - -def run(args = None): - if args is not None: - import sys - sys.argv = args - import doctest, test_pickle2 - return doctest.testmod(test_pickle2) - -if __name__ == '__main__': - import sys - sys.exit(run()[0]) - diff --git a/example/test_pickle3.py b/example/test_pickle3.py deleted file mode 100644 index 6ac83b18..00000000 --- a/example/test_pickle3.py +++ /dev/null @@ -1,39 +0,0 @@ -r'''>>> import pickle3 - >>> import re - >>> import pickle - >>> pickle3.world.__module__ - 'pickle3' - >>> pickle3.world.__safe_for_unpickling__ - 1 - >>> pickle3.world.__reduce__() - 'world' - >>> assert re.match( - ... "\(, \('Hello',\), \(\{\}, 0\)\)", - ... repr(pickle3.world('Hello').__reduce__())) - >>> - >>> for number in (24, 42): - ... wd = pickle3.world('California') - ... wd.set_secret_number(number) - ... wd.x = 2 * number - ... wd.y = 'y' * number - ... 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 -''' - -def run(args = None): - if args is not None: - import sys - sys.argv = args - import doctest, test_pickle3 - return doctest.testmod(test_pickle3) - -if __name__ == '__main__': - import sys - sys.exit(run()[0]) diff --git a/example/test_richcmp1.py b/example/test_richcmp1.py deleted file mode 100644 index d25fcc9c..00000000 --- a/example/test_richcmp1.py +++ /dev/null @@ -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." diff --git a/example/test_richcmp2.py b/example/test_richcmp2.py deleted file mode 100644 index 859928c3..00000000 --- a/example/test_richcmp2.py +++ /dev/null @@ -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." diff --git a/example/test_richcmp3.py b/example/test_richcmp3.py deleted file mode 100644 index a769af17..00000000 --- a/example/test_richcmp3.py +++ /dev/null @@ -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." diff --git a/example/test_rwgk1.py b/example/test_rwgk1.py deleted file mode 100644 index 631eea3e..00000000 --- a/example/test_rwgk1.py +++ /dev/null @@ -1,19 +0,0 @@ -r'''>>> import rwgk1 - >>> print rwgk1.greet() - hello, world - >>> number = 11 - >>> print number, '*', number, '=', rwgk1.square(number) - 11 * 11 = 121 -''' - -def run(args = None): - if args is not None: - import sys - sys.argv = args - import doctest, test_rwgk1 - return doctest.testmod(test_rwgk1) - -if __name__ == '__main__': - import sys - sys.exit(run()[0]) - diff --git a/example/test_simple_vector.py b/example/test_simple_vector.py deleted file mode 100644 index c6a2cd59..00000000 --- a/example/test_simple_vector.py +++ /dev/null @@ -1,42 +0,0 @@ -r'''>>> import simple_vector - >>> v=simple_vector.vector_double() - >>> print v.as_tuple() - () - >>> v=simple_vector.vector_double(5) - >>> print v.as_tuple() - (0.0, 0.0, 0.0, 0.0, 0.0) - >>> print len(v) - 5 - >>> v=simple_vector.vector_double((3,4,5)) - >>> print v.as_tuple() - (3.0, 4.0, 5.0) - >>> print v[1] - 4.0 - >>> v[1] = 40 - >>> print v.as_tuple() - (3.0, 40.0, 5.0) - >>> for e in v: - ... print e - 3.0 - 40.0 - 5.0 - >>> del v[1] - >>> print v.as_tuple() - (3.0, 5.0) - >>> print simple_vector.foo(11).as_tuple() - (0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0) - >>> print simple_vector.bar(12).as_tuple() - (0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 110.0) -''' - -def run(args = None): - if args is not None: - import sys - sys.argv = args - import doctest, test_simple_vector - return doctest.testmod(test_simple_vector) - -if __name__ == '__main__': - import sys - sys.exit(run()[0]) - diff --git a/example/tst_dvect1.py b/example/tst_dvect1.py deleted file mode 100644 index 22315528..00000000 --- a/example/tst_dvect1.py +++ /dev/null @@ -1,20 +0,0 @@ -def f(): - import dvect - dv = dvect.dvect((1,2,3,4,5)) - print dv.as_tuple() - iv = dv.as_ivect() - print iv.as_tuple() - print dvect.const_ivect_reference_as_tuple(iv) - aiv = dvect.ivect_as_auto_ptr(iv) - print dvect.const_ivect_reference_as_tuple(aiv) - siv = dvect.ivect_as_shared_ptr(iv) - print dvect.const_ivect_reference_as_tuple(siv) - print aiv.as_tuple() - print siv.as_tuple() - -if (__name__ == "__main__"): - import sys, string - n = 1 - if (len(sys.argv) > 1): n = string.atoi(sys.argv[1]) - for i in xrange(n): - f() diff --git a/example/tst_dvect2.py b/example/tst_dvect2.py deleted file mode 100644 index 90d381a7..00000000 --- a/example/tst_dvect2.py +++ /dev/null @@ -1,104 +0,0 @@ -def f(broken_auto_ptr): - import dvect - import ivect - # - dv = dvect.dvect((1,2,3,4,5)) - iv = dv.as_ivect() - # - aiv = dvect.ivect_as_auto_ptr(iv) - print '1. auto_ptr_value_ivect_as_tuple' - print ivect.auto_ptr_value_ivect_as_tuple(aiv) - print '2. auto_ptr_value_ivect_as_tuple' - if (not broken_auto_ptr): - print ivect.auto_ptr_value_ivect_as_tuple(aiv) - else: - print None - # - adv = dvect.dvect_as_auto_ptr(dv) - print '1. auto_ptr_value_dvect_as_tuple' - print ivect.auto_ptr_value_dvect_as_tuple(adv) - print '2. auto_ptr_value_dvect_as_tuple' - if (not broken_auto_ptr): - print ivect.auto_ptr_value_dvect_as_tuple(adv) - else: - print None - # - siv = dvect.ivect_as_shared_ptr(iv) - print '1. shared_ptr_value_ivect_as_tuple' - print ivect.shared_ptr_value_ivect_as_tuple(siv) - print '2. shared_ptr_value_ivect_as_tuple' - print ivect.shared_ptr_value_ivect_as_tuple(siv) - # - sdv = dvect.dvect_as_shared_ptr(dv) - print '1. shared_ptr_value_dvect_as_tuple' - print ivect.shared_ptr_value_dvect_as_tuple(sdv) - print '2. shared_ptr_value_dvect_as_tuple' - print ivect.shared_ptr_value_dvect_as_tuple(sdv) - # - aiv = dvect.ivect_as_auto_ptr(iv) - print '1. auto_ptr_reference_ivect_as_tuple' - print ivect.auto_ptr_reference_ivect_as_tuple(aiv) - print '2. auto_ptr_reference_ivect_as_tuple' - print ivect.auto_ptr_reference_ivect_as_tuple(aiv) - # - adv = dvect.dvect_as_auto_ptr(dv) - print '1. auto_ptr_reference_dvect_as_tuple' - print ivect.auto_ptr_reference_dvect_as_tuple(adv) - print '2. auto_ptr_reference_dvect_as_tuple' - print ivect.auto_ptr_reference_dvect_as_tuple(adv) - # - siv = dvect.ivect_as_shared_ptr(iv) - print '1. shared_ptr_reference_ivect_as_tuple' - print ivect.shared_ptr_reference_ivect_as_tuple(siv) - print '2. shared_ptr_reference_ivect_as_tuple' - print ivect.shared_ptr_reference_ivect_as_tuple(siv) - # - sdv = dvect.dvect_as_shared_ptr(dv) - print '1. shared_ptr_reference_dvect_as_tuple' - print ivect.shared_ptr_reference_dvect_as_tuple(sdv) - print '2. shared_ptr_reference_dvect_as_tuple' - print ivect.shared_ptr_reference_dvect_as_tuple(sdv) - # - aiv = dvect.ivect_as_auto_ptr(iv) - print '1. auto_ptr_const_reference_ivect_as_tuple' - print ivect.auto_ptr_const_reference_ivect_as_tuple(aiv) - print '2. auto_ptr_const_reference_ivect_as_tuple' - print ivect.auto_ptr_const_reference_ivect_as_tuple(aiv) - # - adv = dvect.dvect_as_auto_ptr(dv) - print '1. auto_ptr_const_reference_dvect_as_tuple' - print ivect.auto_ptr_const_reference_dvect_as_tuple(adv) - print '2. auto_ptr_const_reference_dvect_as_tuple' - print ivect.auto_ptr_const_reference_dvect_as_tuple(adv) - # - siv = dvect.ivect_as_shared_ptr(iv) - print '1. shared_ptr_const_reference_ivect_as_tuple' - print ivect.shared_ptr_const_reference_ivect_as_tuple(siv) - print '2. shared_ptr_const_reference_ivect_as_tuple' - print ivect.shared_ptr_const_reference_ivect_as_tuple(siv) - # - sdv = dvect.dvect_as_shared_ptr(dv) - print '1. shared_ptr_const_reference_dvect_as_tuple' - print ivect.shared_ptr_const_reference_dvect_as_tuple(sdv) - print '2. shared_ptr_const_reference_dvect_as_tuple' - print ivect.shared_ptr_const_reference_dvect_as_tuple(sdv) - -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]) - - for i in xrange(n): - f(broken_auto_ptr) diff --git a/example/tst_ivect1.py b/example/tst_ivect1.py deleted file mode 100644 index 7369fdbf..00000000 --- a/example/tst_ivect1.py +++ /dev/null @@ -1,20 +0,0 @@ -def f(): - import ivect - iv = ivect.ivect((1,2,3,4,5)) - print iv.as_tuple() - dv = iv.as_dvect() - print dv.as_tuple() - print ivect.const_dvect_reference_as_tuple(dv) - adv = ivect.dvect_as_auto_ptr(dv) - print ivect.const_dvect_reference_as_tuple(adv) - sdv = ivect.dvect_as_shared_ptr(dv) - print ivect.const_dvect_reference_as_tuple(sdv) - print adv.as_tuple() - print sdv.as_tuple() - -if (__name__ == "__main__"): - import sys, string - n = 1 - if (len(sys.argv) > 1): n = string.atoi(sys.argv[1]) - for i in xrange(n): - f() diff --git a/example/tst_ivect2.py b/example/tst_ivect2.py deleted file mode 100644 index a9e6aeef..00000000 --- a/example/tst_ivect2.py +++ /dev/null @@ -1,104 +0,0 @@ -def f(broken_auto_ptr): - import ivect - import dvect - # - iv = ivect.ivect((1,2,3,4,5)) - dv = iv.as_dvect() - # - adv = ivect.dvect_as_auto_ptr(dv) - print '1. auto_ptr_value_dvect_as_tuple' - print dvect.auto_ptr_value_dvect_as_tuple(adv) - print '2. auto_ptr_value_dvect_as_tuple' - if (not broken_auto_ptr): - print dvect.auto_ptr_value_dvect_as_tuple(adv) - else: - print None - # - aiv = ivect.ivect_as_auto_ptr(iv) - print '1. auto_ptr_value_ivect_as_tuple' - print dvect.auto_ptr_value_ivect_as_tuple(aiv) - print '2. auto_ptr_value_ivect_as_tuple' - if (not broken_auto_ptr): - print dvect.auto_ptr_value_ivect_as_tuple(aiv) - else: - print None - # - sdv = ivect.dvect_as_shared_ptr(dv) - print '1. shared_ptr_value_dvect_as_tuple' - print dvect.shared_ptr_value_dvect_as_tuple(sdv) - print '2. shared_ptr_value_dvect_as_tuple' - print dvect.shared_ptr_value_dvect_as_tuple(sdv) - # - siv = ivect.ivect_as_shared_ptr(iv) - print '1. shared_ptr_value_ivect_as_tuple' - print dvect.shared_ptr_value_ivect_as_tuple(siv) - print '2. shared_ptr_value_ivect_as_tuple' - print dvect.shared_ptr_value_ivect_as_tuple(siv) - # - adv = ivect.dvect_as_auto_ptr(dv) - print '1. auto_ptr_reference_dvect_as_tuple' - print dvect.auto_ptr_reference_dvect_as_tuple(adv) - print '2. auto_ptr_reference_dvect_as_tuple' - print dvect.auto_ptr_reference_dvect_as_tuple(adv) - # - aiv = ivect.ivect_as_auto_ptr(iv) - print '1. auto_ptr_reference_ivect_as_tuple' - print dvect.auto_ptr_reference_ivect_as_tuple(aiv) - print '2. auto_ptr_reference_ivect_as_tuple' - print dvect.auto_ptr_reference_ivect_as_tuple(aiv) - # - sdv = ivect.dvect_as_shared_ptr(dv) - print '1. shared_ptr_reference_dvect_as_tuple' - print dvect.shared_ptr_reference_dvect_as_tuple(sdv) - print '2. shared_ptr_reference_dvect_as_tuple' - print dvect.shared_ptr_reference_dvect_as_tuple(sdv) - # - siv = ivect.ivect_as_shared_ptr(iv) - print '1. shared_ptr_reference_ivect_as_tuple' - print dvect.shared_ptr_reference_ivect_as_tuple(siv) - print '2. shared_ptr_reference_ivect_as_tuple' - print dvect.shared_ptr_reference_ivect_as_tuple(siv) - # - adv = ivect.dvect_as_auto_ptr(dv) - print '1. auto_ptr_const_reference_dvect_as_tuple' - print dvect.auto_ptr_const_reference_dvect_as_tuple(adv) - print '2. auto_ptr_const_reference_dvect_as_tuple' - print dvect.auto_ptr_const_reference_dvect_as_tuple(adv) - # - aiv = ivect.ivect_as_auto_ptr(iv) - print '1. auto_ptr_const_reference_ivect_as_tuple' - print dvect.auto_ptr_const_reference_ivect_as_tuple(aiv) - print '2. auto_ptr_const_reference_ivect_as_tuple' - print dvect.auto_ptr_const_reference_ivect_as_tuple(aiv) - # - sdv = ivect.dvect_as_shared_ptr(dv) - print '1. shared_ptr_const_reference_dvect_as_tuple' - print dvect.shared_ptr_const_reference_dvect_as_tuple(sdv) - print '2. shared_ptr_const_reference_dvect_as_tuple' - print dvect.shared_ptr_const_reference_dvect_as_tuple(sdv) - # - siv = ivect.ivect_as_shared_ptr(iv) - print '1. shared_ptr_const_reference_ivect_as_tuple' - print dvect.shared_ptr_const_reference_ivect_as_tuple(siv) - print '2. shared_ptr_const_reference_ivect_as_tuple' - print dvect.shared_ptr_const_reference_ivect_as_tuple(siv) - -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]) - - for i in xrange(n): - f(broken_auto_ptr) diff --git a/example/tst_noncopyable.py b/example/tst_noncopyable.py deleted file mode 100644 index 155910a5..00000000 --- a/example/tst_noncopyable.py +++ /dev/null @@ -1,16 +0,0 @@ -def f(): - import noncopyable_export - import noncopyable_import - s1 = noncopyable_export.store(1) - print s1.recall() - s2 = noncopyable_export.store(2) - print s2.recall() - s3 = noncopyable_import.add_stores(s1, s2) - print s3.recall() - -if (__name__ == "__main__"): - import sys, string - n = 1 - if (len(sys.argv) > 1): n = string.atoi(sys.argv[1]) - for i in xrange(n): - f() diff --git a/example/vector_wrapper.h b/example/vector_wrapper.h deleted file mode 100644 index 6a571343..00000000 --- a/example/vector_wrapper.h +++ /dev/null @@ -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 - -namespace example { - - // A wrapper is used to define additional constructors. This wrapper - // is templated on the template parameter for its corresponding vector. - template - struct vector_wrapper: std::vector - { - // Tell the compiler how to convert a base class object to - // this wrapper object. - vector_wrapper(PyObject*, - const std::vector& vec): - std::vector(vec) {} - - vector_wrapper(PyObject* self): - std::vector() {} - - vector_wrapper(PyObject* self, - std::size_t n): - std::vector(n) {} - - vector_wrapper(PyObject* self, - boost::python::tuple tuple): - std::vector(tuple.size()) - { - std::vector::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()); - } - }; - - void raise_vector_IndexError() { - PyErr_SetString(PyExc_IndexError, "vector index out of range"); - boost::python::throw_error_already_set(); - } - - template - struct vector_access - { - static - T - getitem(const std::vector& vec, - std::size_t key) - { - if (key >= vec.size()) raise_vector_IndexError(); - return vec[key]; - } - - static - void - setitem(std::vector& vec, - std::size_t key, - const T &value) - { - if (key >= vec.size()) raise_vector_IndexError(); - vec[key] = value; - } - - static - void - delitem(std::vector& vec, - std::size_t key) - { - if (key >= vec.size()) raise_vector_IndexError(); - vec.erase(vec.begin() + key); - } - - // Convert vector to a regular Python tuple. - static - boost::python::tuple - as_tuple(const std::vector& 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 and add it to the given - // module with the given name. - template - boost::python::class_builder, vector_wrapper > - wrap_vector(boost::python::module_builder& module, - const std::string& vector_name, - const T&) - { - // Add the vector to the module. - boost::python::class_builder, vector_wrapper > - py_vector(module, vector_name.c_str()); - - // Define constructors and methods for the vector. - py_vector.def(boost::python::constructor<>()); - py_vector.def(boost::python::constructor()); - py_vector.def(boost::python::constructor()); - py_vector.def(&std::vector::size, "__len__"); - py_vector.def(&vector_access::getitem, "__getitem__"); - py_vector.def(&vector_access::setitem, "__setitem__"); - py_vector.def(&vector_access::delitem, "__delitem__"); - py_vector.def(&vector_access::as_tuple, "as_tuple"); - - return py_vector; - } -} - -#endif // BOOST_PYTHON_EXAMPLE_VECTOR_WRAPPER_H diff --git a/include/boost/python/args.hpp b/include/boost/python/args.hpp index 4e2e922b..9a5902ae 100644 --- a/include/boost/python/args.hpp +++ b/include/boost/python/args.hpp @@ -7,7 +7,6 @@ # define KEYWORDS_DWA2002323_HPP # include -# include # include # include # include @@ -32,12 +31,6 @@ namespace boost { namespace python { namespace detail { - struct keyword - { - char const* name; - handle<> default_value; - }; - template struct keywords { diff --git a/include/boost/python/args_fwd.hpp b/include/boost/python/args_fwd.hpp index b8ca0c7d..e310f761 100644 --- a/include/boost/python/args_fwd.hpp +++ b/include/boost/python/args_fwd.hpp @@ -6,6 +6,7 @@ #ifndef ARGS_FWD_DWA2002927_HPP # define ARGS_FWD_DWA2002927_HPP +# include # include # include # include @@ -14,7 +15,12 @@ namespace boost { namespace python { namespace detail { - struct keyword; + struct keyword + { + char const* name; + handle<> default_value; + }; + template struct keywords; typedef std::pair keyword_range; diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index 2e0840b3..3ec153b4 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -13,7 +13,6 @@ # include # include -# include # include # include # include @@ -25,17 +24,19 @@ # include # include # include -# include # include # include # include -# include -# include -# include # include # include # include +# include +# include +# include +# include +# include + namespace boost { namespace python { enum no_init_t { no_init }; diff --git a/include/boost/python/def.hpp b/include/boost/python/def.hpp index f6218886..5631fb56 100644 --- a/include/boost/python/def.hpp +++ b/include/boost/python/def.hpp @@ -9,7 +9,7 @@ # include # include # include -# include +# include # include # include # include diff --git a/include/boost/python/detail/defaults_def.hpp b/include/boost/python/detail/defaults_def.hpp index 6321247e..d6444044 100644 --- a/include/boost/python/detail/defaults_def.hpp +++ b/include/boost/python/detail/defaults_def.hpp @@ -219,7 +219,7 @@ namespace detail char const* name, OverloadsT const& overloads, NameSpaceT& name_space, - SigT sig) + SigT const& sig) { typedef typename mpl::front::type return_type; typedef typename OverloadsT::void_return_type void_return_type; diff --git a/include/boost/python/detail/defaults_gen.hpp b/include/boost/python/detail/defaults_gen.hpp index 2e560488..4c4bf217 100644 --- a/include/boost/python/detail/defaults_gen.hpp +++ b/include/boost/python/detail/defaults_gen.hpp @@ -24,8 +24,7 @@ #include #include #include -#include -#include +#include namespace boost { namespace python { @@ -211,7 +210,7 @@ namespace detail { \ typedef typename ::boost::python::detail:: \ error::more_keywords_than_function_arguments< \ - Keywords::size,(n_args+n_dflts)>::too_many_keywords assertion; \ + Keywords::size,n_args>::too_many_keywords assertion; \ } \ template \ fstubs_name(Keywords const& keywords, char const* doc = 0) \ @@ -220,59 +219,57 @@ namespace detail { \ typedef typename ::boost::python::detail:: \ error::more_keywords_than_function_arguments< \ - Keywords::size,(n_args+n_dflts)>::too_many_keywords assertion; \ + Keywords::size,n_args>::too_many_keywords assertion; \ } # if defined(BOOST_NO_VOID_RETURNS) # define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ - BOOST_PYTHON_GEN_FUNCTION( \ - fname, BOOST_PP_CAT(fstubs_name, NonVoid), n_args, n_dflts, return) \ - BOOST_PYTHON_GEN_FUNCTION( \ - fname, BOOST_PP_CAT(fstubs_name, Void), n_args, n_dflts, ;) \ struct fstubs_name \ : public ::boost::python::detail::overloads_common \ { \ - typedef BOOST_PP_CAT(fstubs_name, NonVoid) non_void_return_type; \ - typedef BOOST_PP_CAT(fstubs_name, Void) void_return_type; \ + BOOST_PYTHON_GEN_FUNCTION( \ + fname, non_void_return_type, n_args, n_dflts, return) \ + BOOST_PYTHON_GEN_FUNCTION( \ + fname, void_return_type, n_args, n_dflts, ;) \ + \ BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \ }; # define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ - BOOST_PYTHON_GEN_MEM_FUNCTION( \ - fname, BOOST_PP_CAT(fstubs_name, NonVoid), n_args, n_dflts, return) \ - BOOST_PYTHON_GEN_MEM_FUNCTION( \ - fname, BOOST_PP_CAT(fstubs_name, Void), n_args, n_dflts, ;) \ struct fstubs_name \ : public ::boost::python::detail::overloads_common \ { \ - typedef BOOST_PP_CAT(fstubs_name, NonVoid) non_void_return_type; \ - typedef BOOST_PP_CAT(fstubs_name, Void) void_return_type; \ + BOOST_PYTHON_GEN_MEM_FUNCTION( \ + fname, non_void_return_type, n_args, n_dflts, return) \ + BOOST_PYTHON_GEN_MEM_FUNCTION( \ + fname, void_return_type, n_args, n_dflts, ;) \ + \ BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \ }; # else // !defined(BOOST_NO_VOID_RETURNS) # define BOOST_PYTHON_GEN_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ - BOOST_PYTHON_GEN_FUNCTION( \ - fname, BOOST_PP_CAT(fstubs_name, NonVoid), n_args, n_dflts, return) \ struct fstubs_name \ : public ::boost::python::detail::overloads_common \ { \ - typedef BOOST_PP_CAT(fstubs_name, NonVoid) non_void_return_type; \ - typedef BOOST_PP_CAT(fstubs_name, NonVoid) void_return_type; \ + BOOST_PYTHON_GEN_FUNCTION( \ + fname, non_void_return_type, n_args, n_dflts, return) \ + \ + typedef non_void_return_type void_return_type; \ BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \ }; # define BOOST_PYTHON_GEN_MEM_FUNCTION_STUB(fname, fstubs_name, n_args, n_dflts) \ - BOOST_PYTHON_GEN_MEM_FUNCTION( \ - fname, BOOST_PP_CAT(fstubs_name, NonVoid), n_args, n_dflts, return) \ struct fstubs_name \ : public ::boost::python::detail::overloads_common \ { \ - typedef BOOST_PP_CAT(fstubs_name, NonVoid) non_void_return_type; \ - typedef BOOST_PP_CAT(fstubs_name, NonVoid) void_return_type; \ + BOOST_PYTHON_GEN_MEM_FUNCTION( \ + fname, non_void_return_type, n_args, n_dflts, return) \ + \ + typedef non_void_return_type void_return_type; \ BOOST_PYTHON_OVERLOAD_CONSTRUCTORS(fstubs_name, n_args, n_dflts) \ }; diff --git a/include/boost/python/detail/module_base.hpp b/include/boost/python/detail/module_base.hpp index 144c1d93..39056d63 100644 --- a/include/boost/python/detail/module_base.hpp +++ b/include/boost/python/detail/module_base.hpp @@ -1,3 +1,4 @@ +#error obsolete // Copyright David Abrahams 2002. Permission to copy, use, // modify, sell and distribute this software is granted provided this // copyright notice appears in all copies. This software is provided diff --git a/include/boost/python/detail/module_info.hpp b/include/boost/python/detail/module_info.hpp deleted file mode 100644 index ba3f91cc..00000000 --- a/include/boost/python/detail/module_info.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright David Hawkes 2002. -// Permission is hereby granted to copy, use and modify this software -// for any purpose, including commercial distribution, provided this -// copyright notice is not removed. No warranty WHATSOEVER is provided with this -// software. Any user(s) accepts this software "as is" and as such they will not -// bind the author(s) to any claim of suitabilty for any purpose. - -#ifndef MODULE_INFO -# define MODULE_INFO - -#include - -namespace boost { namespace python { namespace detail { - -class module_info -{ -public: - module_info(const char *name) - { - m_module_name = name; - } - void set_module(object const& m) - { - if(!m_primary_module) - m_primary_module = m; - } - object const& get_module() const - { - return m_primary_module; - } - void set_prior_module(object const& m) - { - m_prior_module = m; - } - object const& get_prior_module() const - { - return m_prior_module; - } - const char* get_module_name() const - { - return m_module_name; - } -private: - object m_primary_module; - object m_prior_module; - const char* m_module_name; -}; - -}}} - -#endif // MODULE_INFO diff --git a/include/boost/python/detail/type_list_impl_no_pts.hpp b/include/boost/python/detail/type_list_impl_no_pts.hpp index be537793..d4d282aa 100644 --- a/include/boost/python/detail/type_list_impl_no_pts.hpp +++ b/include/boost/python/detail/type_list_impl_no_pts.hpp @@ -95,9 +95,9 @@ struct type_list_impl_chooser > struct result_ { - typedef BOOST_PP_CAT(mpl::list,N)< + typedef typename BOOST_PP_CAT(mpl::list,N)< BOOST_PP_ENUM_PARAMS(N, T) - > type; + >::type type; }; }; diff --git a/include/boost/python/detail/types.hpp b/include/boost/python/detail/types.hpp deleted file mode 100644 index 2e69d24e..00000000 --- a/include/boost/python/detail/types.hpp +++ /dev/null @@ -1,413 +0,0 @@ -// (C) Copyright David Abrahams 2000. 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. -// -// The author gratefully acknowleges the support of Dragon Systems, Inc., in -// producing this work. - -#ifndef TYPES_DWA051800_H_ -# define TYPES_DWA051800_H_ - -// Usage: -// class X : public -// boost::python::callable< -// boost::python::getattrable < -// boost::python::setattrable > > -// { -// public: -// ref call(args, kw); -// ref getattr(args, kw); -// ref setattr(args, kw); -// }; - -# include -# include // really just for type<> -# include -# include -# include -# include -# include - -namespace boost { namespace python { - -namespace detail { - -class BOOST_PYTHON_DECL type_object_base : public python_type -{ - public: - explicit type_object_base(PyTypeObject* type_type); - virtual ~type_object_base(); - - public: - enum capability { - hash, call, str, getattr, setattr, compare, repr, richcompare, - - mapping_length, mapping_subscript, mapping_ass_subscript, - - sequence_length, sequence_item, sequence_ass_item, - sequence_concat, sequence_repeat, sequence_slice, sequence_ass_slice, - - number_add, number_subtract, number_multiply, number_divide, - number_remainder, number_divmod, number_power, number_negative, - number_positive, number_absolute, number_nonzero, number_invert, - number_lshift, number_rshift, number_and, number_xor, number_or, - number_coerce, number_int, number_long, number_float, number_oct, - number_hex, number_inplace_add, number_inplace_subtract, - number_inplace_multiply, number_inplace_divide, - number_inplace_remainder, number_inplace_power, - number_inplace_lshift, number_inplace_rshift, - number_inplace_and, number_inplace_or, number_inplace_xor - }; - - void enable(capability); - - // - // type behaviors - // - public: // Callbacks for basic type functionality. - virtual PyObject* instance_repr(PyObject*) const; - virtual int instance_compare(PyObject*, PyObject* other) const; - virtual PyObject* instance_str(PyObject*) const; - virtual long instance_hash(PyObject*) const; - virtual PyObject* instance_call(PyObject* obj, PyObject* args, PyObject* kw) const; - virtual PyObject* instance_getattr(PyObject* obj, const char* name) const; - virtual int instance_setattr(PyObject* obj, const char* name, PyObject* value) const; - - // Dealloc is a special case, since every type needs a nonzero tp_dealloc slot. - virtual void instance_dealloc(PyObject*) const = 0; - - public: // Callbacks for mapping methods - virtual int instance_mapping_length(PyObject*) const; - virtual PyObject* instance_mapping_subscript(PyObject*, PyObject*) const ; - virtual int instance_mapping_ass_subscript(PyObject*, PyObject*, PyObject*) const; - - public: // Callbacks for sequence methods - virtual int instance_sequence_length(PyObject* obj) const; - virtual PyObject* instance_sequence_concat(PyObject* obj, PyObject* other) const; - virtual PyObject* instance_sequence_repeat(PyObject* obj, int n) const; - virtual PyObject* instance_sequence_item(PyObject* obj, int n) const; - virtual PyObject* instance_sequence_slice(PyObject* obj, int start, int finish) const; - virtual int instance_sequence_ass_item(PyObject* obj, int n, PyObject* value) const; - virtual int instance_sequence_ass_slice(PyObject* obj, int start, int finish, PyObject* value) const; - - public: // Callbacks for number methods - virtual PyObject* instance_number_add(PyObject*, PyObject*) const; - virtual PyObject* instance_number_subtract(PyObject*, PyObject*) const; - virtual PyObject* instance_number_multiply(PyObject*, PyObject*) const; - virtual PyObject* instance_number_divide(PyObject*, PyObject*) const; - virtual PyObject* instance_number_remainder(PyObject*, PyObject*) const; - virtual PyObject* instance_number_divmod(PyObject*, PyObject*) const; - virtual PyObject* instance_number_power(PyObject*, PyObject*, PyObject*) const; - virtual PyObject* instance_number_negative(PyObject*) const; - virtual PyObject* instance_number_positive(PyObject*) const; - virtual PyObject* instance_number_absolute(PyObject*) const; - virtual int instance_number_nonzero(PyObject*) const; - virtual PyObject* instance_number_invert(PyObject*) const; - virtual PyObject* instance_number_lshift(PyObject*, PyObject*) const; - virtual PyObject* instance_number_rshift(PyObject*, PyObject*) const; - virtual PyObject* instance_number_and(PyObject*, PyObject*) const; - virtual PyObject* instance_number_xor(PyObject*, PyObject*) const; - virtual PyObject* instance_number_or(PyObject*, PyObject*) const; - virtual int instance_number_coerce(PyObject*, PyObject**, PyObject**) const; - virtual PyObject* instance_number_int(PyObject*) const; - virtual PyObject* instance_number_long(PyObject*) const; - virtual PyObject* instance_number_float(PyObject*) const; - virtual PyObject* instance_number_oct(PyObject*) const; - virtual PyObject* instance_number_hex(PyObject*) const; - - virtual PyObject* instance_number_inplace_add(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_subtract(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_multiply(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_divide(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_remainder(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_power(PyObject*, PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_lshift(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_rshift(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_and(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_or(PyObject*, PyObject*) const; - virtual PyObject* instance_number_inplace_xor(PyObject*, 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 type_object : public type_object_base -{ - public: - typedef T instance; - - type_object(PyTypeObject* type_type, const char* name) - : type_object_base(type_type) - { - assert(name != 0); - this->tp_name = const_cast(name); - } - - type_object(PyTypeObject* type_type) - : type_object_base(type_type) - { - this->tp_name = const_cast(typeid(instance).name()); - } - - private: // Overridable behaviors. - // Called when the reference count goes to zero. The default implementation - // is "delete p". If you have not allocated your object with operator new or - // you have other constraints, you'll need to override this - virtual void dealloc(T* p) const; - - private: // Implementation of type_object_base hooks. Do not reimplement in derived classes. - void instance_dealloc(PyObject*) const; -}; - -// -// type objects -// -template -class callable : public Base -{ - public: - typedef callable properties; // Convenience for derived class construction - typedef typename Base::instance instance; - callable(PyTypeObject* type_type, const char* name); - callable(PyTypeObject* type_type); - private: - PyObject* instance_call(PyObject* obj, PyObject* args, PyObject* kw) const; -}; - -template -class getattrable : public Base -{ - public: - typedef getattrable properties; // Convenience for derived class construction - typedef typename Base::instance instance; - getattrable(PyTypeObject* type_type, const char* name); - getattrable(PyTypeObject* type_type); - private: - PyObject* instance_getattr(PyObject* obj, const char* name) const; -}; - -template -class setattrable : public Base -{ - public: - typedef setattrable properties; // Convenience for derived class construction - typedef typename Base::instance instance; - setattrable(PyTypeObject* type_type, const char* name); - setattrable(PyTypeObject* type_type); - private: - int instance_setattr(PyObject* obj, const char* name, PyObject* value) const; -}; - -template -class reprable : public Base -{ - public: - typedef reprable properties; // Convenience for derived class construction - typedef typename Base::instance instance; - reprable(PyTypeObject* type_type, const char* name); - reprable(PyTypeObject* type_type); - private: - PyObject* instance_repr(PyObject* obj) const; -}; - -// -// Member function definitions -// - -// type_object<> -template -void type_object::instance_dealloc(PyObject* obj) const -{ - this->dealloc(downcast(obj).get()); -} - -template -void type_object::dealloc(T* obj) const -{ - delete obj; -} - -// callable -template -callable::callable(PyTypeObject* type_type, const char* name) - : Base(type_type, name) -{ - this->enable(call); -} - -template -callable::callable(PyTypeObject* type_type) - : Base(type_type) -{ - this->enable(call); -} - -template -PyObject* callable::instance_call(PyObject* obj, PyObject* args, PyObject* kw) const -{ - return downcast(obj)->call(args, kw); -} - -// getattrable -template -getattrable::getattrable(PyTypeObject* type_type, const char* name) - : Base(type_type, name) -{ - this->enable(getattr); -} - -template -getattrable::getattrable(PyTypeObject* type_type) - : Base(type_type) -{ - this->enable(getattr); -} - -template -PyObject* getattrable::instance_getattr(PyObject* obj, const char* name) const -{ - return downcast(obj)->getattr(name); -} - -// setattrable -template -setattrable::setattrable(PyTypeObject* type_type, const char* name) - : Base(type_type, name) -{ - this->enable(setattr); -} - -template -setattrable::setattrable(PyTypeObject* type_type) - : Base(type_type) -{ - this->enable(setattr); -} - -template -int setattrable::instance_setattr(PyObject* obj, const char* name, PyObject* value) const -{ - return downcast(obj)->setattr(name, value); -} - -// reprable -template -reprable::reprable(PyTypeObject* type_type, const char* name) - : Base(type_type, name) -{ - this->enable(repr); -} - -template -reprable::reprable(PyTypeObject* type_type) - : Base(type_type) -{ - this->enable(repr); -} - -template -PyObject* reprable::instance_repr(PyObject* obj) const -{ - return downcast(obj)->repr(); -} - - // Helper class for optimized allocation of PODs: If two PODs - // happen to contain identical byte patterns, they may share their - // memory. Reference counting is used to free unused memory. - // This is useful because method tables of related extension classes tend - // to be identical, so less memory is needed for them. - class BOOST_PYTHON_DECL shared_pod_manager - { - typedef std::pair holder; - typedef std::vector storage; - - public: - static shared_pod_manager& obj(); - ~shared_pod_manager(); - - // Allocate memory for POD T and fill it with zeros. - // This memory is initially not shared. - template - static void create(T*& t) - { - t = reinterpret_cast(obj().create(sizeof(T))); - } - - // Decrement the refcount for the memory t points to. If the count - // goes to zero, the memory is freed. - template - static void dispose(T* t) - { - obj().dec_ref(t, sizeof(T)); - } - - // Attempt to share the memory t points to. If memory with the same - // contents already exists, t is replaced by a pointer to this memory, - // and t's old memory is disposed. Otherwise, t will be registered for - // potential future sharing. - template - static void replace_if_equal(T*& t) - { - t = reinterpret_cast(obj().replace_if_equal(t, sizeof(T))); - } - - // Create a copy of t's memory that is guaranteed to be private to t. - // Afterwards t points to the new memory, unless it was already private, in - // which case there is no change (except that t's memory will no longer - // be considered for future sharing - see raplade_if_equal()) - // This function *must* be called before the contents of (*t) can - // be overwritten. Otherwise, inconsistencies and crashes may result. - template - static void make_unique_copy(T*& t) - { - t = reinterpret_cast(obj().make_unique_copy(t, sizeof(T))); - } - - private: - void* replace_if_equal(void* pod, std::size_t size); - void* make_unique_copy(void* pod, std::size_t size); - void* create(std::size_t size); - void dec_ref(void* pod, std::size_t size); - void erase_from_list(void* pod); - - struct compare; - struct identical; - - private: - shared_pod_manager() {} // instance - -#ifdef TYPE_OBJECT_BASE_STANDALONE_TEST - public: -#endif - storage m_storage; - }; - - - BOOST_PYTHON_DECL void add_capability(type_object_base::capability capability, - PyTypeObject* dest); - -// 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 - inline void countof_validate(T* const, T* const*); - - template - inline int countof_validate(const void*, T); - -}}} // namespace boost::python::detail - -#endif // TYPES_DWA051800_H_ diff --git a/include/boost/python/dict.hpp b/include/boost/python/dict.hpp index d78ccaf8..6bda6e2c 100644 --- a/include/boost/python/dict.hpp +++ b/include/boost/python/dict.hpp @@ -8,110 +8,126 @@ namespace boost { namespace python { -class dict : public object +class dict; + +namespace detail { - public: + struct BOOST_PYTHON_DECL dict_base : object + { + // D.clear() -> None. Remove all items from D. + void clear(); + + // D.copy() -> a shallow copy of D + dict copy(); + + // D.get(k[,d]) -> D[k] if D.has_key(k), else d. d defaults to None. + object get(object_cref k) const; + + object get(object_cref k, object_cref d) const; + + // D.has_key(k) -> 1 if D has a key k, else 0 + bool has_key(object_cref k) const; + + // D.items() -> list of D's (key, value) pairs, as 2-tuples + list items() const; + + // D.iteritems() -> an iterator over the (key, value) items of D + object iteritems() const; + + // D.iterkeys() -> an iterator over the keys of D + object iterkeys() const; + + // D.itervalues() -> an iterator over the values of D + object itervalues() const; + + // D.keys() -> list of D's keys + list keys() const; + + // D.popitem() -> (k, v), remove and return some (key, value) pair as a + // 2-tuple; but raise KeyError if D is empty + tuple popitem(); + + // D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if not D.has_key(k) + object setdefault(object_cref k); + + object setdefault(object_cref k, object_cref d); + + // D.update(E) -> None. Update D from E: for k in E.keys(): D[k] = E[k] + void update(object_cref E); + + // D.values() -> list of D's values + list values() const; + + protected: + // dict() -> new empty dictionary. + // dict(mapping) -> new dictionary initialized from a mapping object's + // (key, value) pairs. + // dict(seq) -> new dictionary initialized as if via: + dict_base(); // new dict + explicit dict_base(object_cref data); + + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict_base, object) + private: + static detail::new_reference call(object const&); + }; +} + +class dict : public detail::dict_base +{ + typedef detail::dict_base base; + public: // dict() -> new empty dictionary. // dict(mapping) -> new dictionary initialized from a mapping object's // (key, value) pairs. // dict(seq) -> new dictionary initialized as if via: - BOOST_PYTHON_DECL dict(); // new dict - explicit BOOST_PYTHON_DECL dict(object_cref data); + dict() {} // new dict template explicit dict(T const& data) - : object(dict::call(object(data))) + : base(object(data)) { } - // D.clear() -> None. Remove all items from D. - BOOST_PYTHON_DECL void clear(); - - // D.copy() -> a shallow copy of D - BOOST_PYTHON_DECL dict copy(); - - // D.get(k[,d]) -> D[k] if D.has_key(k), else d. d defaults to None. - BOOST_PYTHON_DECL object get(object_cref k) const; - template object get(T const& k) const { - return this->get(object(k)); + return base::get(object(k)); } - BOOST_PYTHON_DECL object get(object_cref k, object_cref d) const; - template object get(T1 const& k, T2 const& d) const { - return this->get(object(k),object(d)); + return base::get(object(k),object(d)); } - - // D.has_key(k) -> 1 if D has a key k, else 0 - BOOST_PYTHON_DECL bool has_key(object_cref k) const; - + template bool has_key(T const& k) const { - return this->has_key(object(k)); + return base::has_key(object(k)); } - - // D.items() -> list of D's (key, value) pairs, as 2-tuples - BOOST_PYTHON_DECL list items() const; - - // D.iteritems() -> an iterator over the (key, value) items of D - BOOST_PYTHON_DECL object iteritems() const; - - // D.iterkeys() -> an iterator over the keys of D - BOOST_PYTHON_DECL object iterkeys() const; - - // D.itervalues() -> an iterator over the values of D - BOOST_PYTHON_DECL object itervalues() const; - - // D.keys() -> list of D's keys - BOOST_PYTHON_DECL list keys() const; - - // D.popitem() -> (k, v), remove and return some (key, value) pair as a - // 2-tuple; but raise KeyError if D is empty - BOOST_PYTHON_DECL tuple popitem(); - - // D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if not D.has_key(k) - BOOST_PYTHON_DECL object setdefault(object_cref k); - + template object setdefault(T const& k) { - return this->setdefault(object(k)); + return base::setdefault(object(k)); } - - BOOST_PYTHON_DECL object setdefault(object_cref k, object_cref d); - + template object setdefault(T1 const& k, T2 const& d) { - return this->setdefault(object(k),object(d)); + return base::setdefault(object(k),object(d)); } - // D.update(E) -> None. Update D from E: for k in E.keys(): D[k] = E[k] - BOOST_PYTHON_DECL void update(object_cref E); - template void update(T const& E) { - this->update(object(E)); + base::update(object(E)); } - // D.values() -> list of D's values - BOOST_PYTHON_DECL list values() const; - public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict, object) - - private: - static BOOST_PYTHON_DECL detail::new_reference call(object const&); + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(dict, base) }; - // // Converter Specializations // diff --git a/include/boost/python/init.hpp b/include/boost/python/init.hpp index 1022706f..589f8ac0 100644 --- a/include/boost/python/init.hpp +++ b/include/boost/python/init.hpp @@ -12,6 +12,8 @@ #include #include +#include + #include #include #include @@ -281,34 +283,6 @@ class init : public init_base > BOOST_STATIC_CONSTANT(int, n_arguments = mpl::size::value); }; -# if 1 -template <> // specialization for zero args -class init<> : public init_base > -{ - typedef init_base > base; - public: - typedef init<> self_t; - - init(char const* doc_ = 0) - : base(doc_) - { - } - - template - init_with_call_policies - operator[](CallPoliciesT const& policies) const - { - return init_with_call_policies( - policies, this->doc_string(), this->keywords()); - } - - BOOST_STATIC_CONSTANT(int, n_defaults = 0); - BOOST_STATIC_CONSTANT(int, n_arguments = 0); - - typedef detail::type_list<> reversed_args; -}; -# endif - /////////////////////////////////////////////////////////////////////////////// // // optional diff --git a/include/boost/python/list.hpp b/include/boost/python/list.hpp index e6696878..ce6cfab4 100644 --- a/include/boost/python/list.hpp +++ b/include/boost/python/list.hpp @@ -11,93 +11,116 @@ namespace boost { namespace python { -class list : public object +namespace detail { + struct BOOST_PYTHON_DECL list_base : object + { + void append(object_cref); // append object to end + + long count(object_cref value) const; // return number of occurrences of value + + void extend(object_cref sequence); // extend list by appending sequence elements + + long index(object_cref value) const; // return index of first occurrence of value + + void insert(int index, object_cref); // insert object before index + void insert(object const& index, object_cref); + + object pop(); // remove and return item at index (default last) + object pop(long index); + object pop(object const& index); + + void remove(object_cref value); // remove first occurrence of value + + void reverse(); // reverse *IN PLACE* + + void sort(); // sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1 + void sort(object_cref cmpfunc); + + + protected: + list_base(); // new list + explicit list_base(object_cref sequence); // new list initialized from sequence's items + + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list_base, object) + private: + static detail::new_non_null_reference call(object const&); + }; +} + +class list : public detail::list_base +{ + typedef detail::list_base base; public: - BOOST_PYTHON_DECL list(); // new list - explicit BOOST_PYTHON_DECL list(object_cref sequence); // new list initialized from sequence's items + list() {} // new list template explicit list(T const& sequence) - : object(list::call(object(sequence))) + : base(object(sequence)) { } - BOOST_PYTHON_DECL void append(object_cref); // append object to end - template void append(T const& x) { - this->append(object(x)); + base::append(object(x)); } - BOOST_PYTHON_DECL long count(object_cref value) const; // return number of occurrences of value - template long count(T const& value) const { - return this->count(object(value)); + return base::count(object(value)); } - BOOST_PYTHON_DECL void extend(object_cref sequence); // extend list by appending sequence elements - template void extend(T const& x) { - this->extend(object(x)); + base::extend(object(x)); } - BOOST_PYTHON_DECL long index(object_cref value) const; // return index of first occurrence of value - template long index(T const& x) const { - return this->index(object(x)); + return base::index(object(x)); } - BOOST_PYTHON_DECL void insert(int index, object_cref); // insert object before index - BOOST_PYTHON_DECL void insert(object const& index, object_cref); - template void insert(int index, T const& x) // insert object before index { - this->insert(index, object(x)); + base::insert(index, object(x)); } template void insert(object const& index, T const& x) // insert object before index { - this->insert(index, object(x)); + base::insert(index, object(x)); } - - BOOST_PYTHON_DECL object pop(); // remove and return item at index (default last) - BOOST_PYTHON_DECL object pop(long index); - BOOST_PYTHON_DECL object pop(object const& index); - BOOST_PYTHON_DECL void remove(object_cref value); // remove first occurrence of value + object pop() { return base::pop(); } + object pop(long index) { return base::pop(index); } + template + object pop(T const& index) + { + return base::pop(object(index)); + } + template void remove(T const& value) { - this->remove(object(value)); + base::remove(object(value)); } + + void sort() { base::sort(); } - BOOST_PYTHON_DECL void reverse(); // reverse *IN PLACE* - - BOOST_PYTHON_DECL void sort(); // sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1 - BOOST_PYTHON_DECL void sort(object_cref cmpfunc); - template void sort(T const& value) { - this->sort(object(value)); + base::sort(object(value)); } public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list, object) - - private: - static BOOST_PYTHON_DECL detail::new_non_null_reference call(object const&); + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list, base) }; // diff --git a/include/boost/python/long.hpp b/include/boost/python/long.hpp index b0cc6417..284296be 100644 --- a/include/boost/python/long.hpp +++ b/include/boost/python/long.hpp @@ -11,31 +11,43 @@ namespace boost { namespace python { -class long_ : public object +namespace detail { + struct BOOST_PYTHON_DECL long_base : object + { + protected: + long_base(); // new long_ + explicit long_base(object_cref rhs); + explicit long_base(object_cref rhs, object_cref base); + + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(long_base, object) + + private: + static detail::new_non_null_reference call(object const&); + static detail::new_non_null_reference call(object const&, object const&); + }; +} + +class long_ : public detail::long_base +{ + typedef detail::long_base base; public: - BOOST_PYTHON_DECL long_(); // new long_ - explicit BOOST_PYTHON_DECL long_(object_cref rhs); + long_() {} // new long_ template explicit long_(T const& rhs) - : object(long_::call(object(rhs))) + : base(object(rhs)) { } - explicit BOOST_PYTHON_DECL long_(object_cref rhs, object_cref base); - template explicit long_(T const& rhs, U const& base) - : object(long_::call(object(rhs), object(base))) + : base(object(rhs), object(base)) { } - public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(long_, object) - private: - static BOOST_PYTHON_DECL detail::new_non_null_reference call(object const&); - static BOOST_PYTHON_DECL detail::new_non_null_reference call(object const&, object const&); + public: // implementation detail -- for internal use only + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(long_, base) }; // diff --git a/include/boost/python/module.hpp b/include/boost/python/module.hpp index 69e9001d..d259d2da 100644 --- a/include/boost/python/module.hpp +++ b/include/boost/python/module.hpp @@ -6,104 +6,7 @@ #ifndef MODULE_DWA2001128_HPP # define MODULE_DWA2001128_HPP -# include -# include -# include -# include -# include # include -# include -# include -# include -# include - -namespace boost { namespace python { - -class module : public detail::module_base -{ - public: - typedef detail::module_base base; - - module(char const* name, char const* doc = 0) - : base(name, doc) {} - - // Add elements to the module - template - module& setattr(const char* name, T const& x) - { - this->base::setattr_doc(name, python::object(x), 0); - return *this; - } - - module& add(type_handle x); // just use the type's name - - template - module& add(class_ const& c) - { - // Soon to disappear... - return *this; - } - - template - module& def(char const* name, Fn fn) - { - this->setattr_doc( - name, boost::python::make_function(fn), 0); - - return *this; - } - - template - module& def(char const* name, Arg1T arg1, Arg2T const& arg2, char const* doc = 0) - { - dispatch_def(name, arg1, arg2, doc, &arg2); - return *this; - } - - private: - - template - void - dispatch_def( - char const* name, - Fn fn, - CallPolicyOrDoc const& policy_or_doc, - char const* doc, - void const*) - { - detail::def_helper helper(policy_or_doc, doc); - - this->setattr_doc( - name - , boost::python::make_function(fn, helper.policies()) - , helper.doc()); - } - - template - void - dispatch_def( - char const* name, - SigT sig, - StubsT const& stubs, - char const* doc, - detail::overloads_base const*) - { - // convert sig to a type_list (see detail::get_signature in signature.hpp) - // before calling detail::define_with_defaults. - detail::define_with_defaults( - name, stubs, *this, detail::get_signature(sig)); - } -}; - -// -// inline implementations -// -inline module& module::add(type_handle x) -{ - this->base::add(x); - return *this; -} - -}} // namespace boost::python +# define BOOST_PYTHON_MODULE BOOST_PYTHON_MODULE_INIT #endif // MODULE_DWA20011221_HPP diff --git a/include/boost/python/object/class.hpp b/include/boost/python/object/class.hpp index e97f8edd..f551c29c 100644 --- a/include/boost/python/object/class.hpp +++ b/include/boost/python/object/class.hpp @@ -35,7 +35,6 @@ struct BOOST_PYTHON_DECL class_base : python::api::object void add_property(char const* name, object const& fget); void add_property(char const* name, object const& fget, object const& fset); void setattr(char const* name, object const&); - void enable_pickling(bool getstate_manages_dict); // Set a special attribute in the class which tells Boost.Python // to allocate extra bytes for embedded C++ objects in Python @@ -45,6 +44,10 @@ struct BOOST_PYTHON_DECL class_base : python::api::object // Set an __init__ function which throws an appropriate exception // for abstract classes. void def_no_init(); + + // Implementation detail. Hiding this in the private section would + // require use of template friend declarations. + void enable_pickling(bool getstate_manages_dict); }; }}} // namespace boost::python::objects diff --git a/include/boost/python/object/instance.hpp b/include/boost/python/object/instance.hpp index 4cddcc99..b258a2a0 100644 --- a/include/boost/python/object/instance.hpp +++ b/include/boost/python/object/instance.hpp @@ -12,7 +12,7 @@ namespace boost { namespace python { - struct instance_holder; + struct BOOST_PYTHON_DECL instance_holder; }} // namespace boost::python namespace boost { namespace python { namespace objects { diff --git a/include/boost/python/py_interface.hpp b/include/boost/python/py_interface.hpp deleted file mode 100644 index c1416d5c..00000000 --- a/include/boost/python/py_interface.hpp +++ /dev/null @@ -1,700 +0,0 @@ -// Automatically generated from py_api_gen.py -#ifndef PY_INTERFACE_HPP -#define PY_INTERFACE_HPP - -#include -#include - -namespace boost { namespace python { namespace api { - -enum call_dict_usage { use_new_dict, use_local_dict, use_global_dict }; - -namespace api_detail { - -BOOST_PYTHON_DECL object get_func(const char* name); -BOOST_PYTHON_DECL object call_statement(const char *stmt, int n, ...); -BOOST_PYTHON_DECL object call_statement_du(const char *stmt, call_dict_usage cdu, int n, ...); - -template -struct get_arg -{ - get_arg(A const &a) : h(a) {} - object h; - operator object const& () { return h; } - operator object const* () { return &h; } -}; - -template<> -struct get_arg -{ - get_arg(object const &a) : h(a) {} - object const &h; - operator object const& () { return h; } - operator object const* () { return &h; } -}; - -template<> -struct get_arg -{ - get_arg(PyObject* a) : h((python::detail::borrowed_reference)a) {} - object h; - operator object const& () { return h; } - operator object const* () { return &h; } -}; - -} - -BOOST_PYTHON_DECL object locals(); - - -template -object abs(A0 const& a0) -{ - return api_detail::get_func("abs")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object abs(object const& a0); -BOOST_PYTHON_DECL object abs(short a0); -BOOST_PYTHON_DECL object abs(int a0); -BOOST_PYTHON_DECL object abs(long a0); -BOOST_PYTHON_DECL object abs(double const & a0); -BOOST_PYTHON_DECL object apply(object const& a0, object const& a1); -BOOST_PYTHON_DECL object apply(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL bool callable(object const& a0); -template -object chr(A0 const& a0) -{ - return api_detail::get_func("chr")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object chr(object const& a0); -BOOST_PYTHON_DECL object chr(short a0); -BOOST_PYTHON_DECL object chr(int a0); -BOOST_PYTHON_DECL object chr(long a0); -template -int cmp(A0 const& a0, A1 const& a1) -{ - int rslt; - int r = ::PyObject_Cmp(api_detail::get_arg(a0), api_detail::get_arg(a1), &rslt); - if(r == -1) - throw_error_already_set(); - return rslt; -} -BOOST_PYTHON_DECL int cmp(object const& a0, object const& a1); -BOOST_PYTHON_DECL object coerce(object const& a0, object const& a1); -BOOST_PYTHON_DECL object compile(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object compile(const char* a0, const char* a1, const char* a2); -BOOST_PYTHON_DECL object compile(object const& a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object compile(const char* a0, const char* a1, const char* a2, int a3); -BOOST_PYTHON_DECL object compile(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object compile(const char* a0, const char* a1, const char* a2, int a3, int a4); -template -object complex(A0 const& a0) -{ - return api_detail::get_func("complex")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object complex(object const& a0); -BOOST_PYTHON_DECL object complex(double const& a0); -template -object complex(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("complex")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -BOOST_PYTHON_DECL object complex(object const& a0, object const& a1); -BOOST_PYTHON_DECL object complex(double const& a0, double const& a1); -BOOST_PYTHON_DECL object dict(); -BOOST_PYTHON_DECL object dict(object const& a0); -BOOST_PYTHON_DECL object dir(); -BOOST_PYTHON_DECL object dir(object const& a0); -template -object divmod(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("divmod")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -BOOST_PYTHON_DECL object divmod(object const& a0, object const& a1); -BOOST_PYTHON_DECL object divmod(int a0, int a1); -BOOST_PYTHON_DECL object divmod(long a0, long a1); -BOOST_PYTHON_DECL object divmod(double const& a0, double const& a1); -BOOST_PYTHON_DECL object eval(const char* a0); -BOOST_PYTHON_DECL object eval(const char* a0, object const& a2); -BOOST_PYTHON_DECL object eval(const char* a0, object const& a2, object const& a3); -BOOST_PYTHON_DECL object exec(const char* a0); -BOOST_PYTHON_DECL object exec(const char* a0, object const& a2); -BOOST_PYTHON_DECL object exec(const char* a0, object const& a2, object const& a3); -BOOST_PYTHON_DECL object execfile(object const& a0); -BOOST_PYTHON_DECL object execfile(object const& a0, object const& a1); -BOOST_PYTHON_DECL object execfile(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object file(object const& a0); -BOOST_PYTHON_DECL object file(const char* a0); -BOOST_PYTHON_DECL object file(object const& a0, object const& a1); -BOOST_PYTHON_DECL object file(const char* a0, const char* a1); -BOOST_PYTHON_DECL object file(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object file(const char* a0, const char* a1, int a2); -BOOST_PYTHON_DECL object filter(object const& a0, object const& a1); -BOOST_PYTHON_DECL object float_(object const& a0); -BOOST_PYTHON_DECL object float_(const char* a0); -BOOST_PYTHON_DECL object float_(double const& a0); -BOOST_PYTHON_DECL object getattr(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object getattr(object const& a0, const char * a1, object const& a2); -BOOST_PYTHON_DECL object globals(); -BOOST_PYTHON_DECL bool hasattr(object const& a0, object const& a1); -BOOST_PYTHON_DECL bool hasattr(object const& a0, const char* a1); -BOOST_PYTHON_DECL long hash(object const& a0); -template -object hex(A0 const& a0) -{ - return api_detail::get_func("hex")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object hex(object const& a0); -BOOST_PYTHON_DECL object hex(char a0); -BOOST_PYTHON_DECL object hex(short a0); -BOOST_PYTHON_DECL object hex(int a0); -BOOST_PYTHON_DECL object hex(long a0); -BOOST_PYTHON_DECL long id(object const& a0); -BOOST_PYTHON_DECL object input(); -BOOST_PYTHON_DECL object input(object const& a0); -BOOST_PYTHON_DECL object input(const char* a0); -BOOST_PYTHON_DECL object int_(object const& a0); -BOOST_PYTHON_DECL object int_(long a0); -BOOST_PYTHON_DECL object int_(const char* a0); -BOOST_PYTHON_DECL object intern(object const& a0); -BOOST_PYTHON_DECL object intern(const char* a0); -BOOST_PYTHON_DECL bool isinstance(object const& a0, object const& a1); -BOOST_PYTHON_DECL bool issubclass(object const& a0, object const& a1); -BOOST_PYTHON_DECL object iter(object const& a0); -BOOST_PYTHON_DECL object iter(object const& a0, object const& a1); -BOOST_PYTHON_DECL long len(object const& a0); -BOOST_PYTHON_DECL object list(); -BOOST_PYTHON_DECL object list(object const& a0); -BOOST_PYTHON_DECL object long_(object const& a0); -BOOST_PYTHON_DECL object long_(long a0); -BOOST_PYTHON_DECL object long_(const char* a0); -BOOST_PYTHON_DECL object map(object const& a0); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object map(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -template -object max(A0 const& a0) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0)); -} -template -object max(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6), api_detail::get_arg(a7)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6), api_detail::get_arg(a7), api_detail::get_arg(a8)); -} -template -object max(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9) -{ - return api_detail::get_func("max")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6), api_detail::get_arg(a7), api_detail::get_arg(a8), api_detail::get_arg(a9)); -} -BOOST_PYTHON_DECL object max(object const& a0); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object max(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -template -object min(A0 const& a0) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0)); -} -template -object min(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6), api_detail::get_arg(a7)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6), api_detail::get_arg(a7), api_detail::get_arg(a8)); -} -template -object min(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9) -{ - return api_detail::get_func("min")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2), api_detail::get_arg(a3), api_detail::get_arg(a4), api_detail::get_arg(a5), api_detail::get_arg(a6), api_detail::get_arg(a7), api_detail::get_arg(a8), api_detail::get_arg(a9)); -} -BOOST_PYTHON_DECL object min(object const& a0); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object min(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -template -object oct(A0 const& a0) -{ - return api_detail::get_func("oct")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object oct(object const& a0); -BOOST_PYTHON_DECL object oct(char a0); -BOOST_PYTHON_DECL object oct(short a0); -BOOST_PYTHON_DECL object oct(int a0); -BOOST_PYTHON_DECL object oct(long a0); -BOOST_PYTHON_DECL object open(object const& a0); -BOOST_PYTHON_DECL object open(const char* a0); -BOOST_PYTHON_DECL object open(object const& a0, object const& a1); -BOOST_PYTHON_DECL object open(const char* a0, const char* a1); -BOOST_PYTHON_DECL object open(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object open(const char* a0, const char* a1, int a2); -BOOST_PYTHON_DECL long ord(object const& a0); -BOOST_PYTHON_DECL long ord(const char* a0); -template -object pow(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("pow")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -BOOST_PYTHON_DECL object pow(object const& a0, object const& a1); -BOOST_PYTHON_DECL object pow(double const& a0, double const& a1); -BOOST_PYTHON_DECL object pow(double const& a0, double const& a1, double const& a2); -template -object print(A0 const& a0) -{ - return api_detail::call_statement_du("print _1", use_new_dict, 1, (object const*)api_detail::get_arg(a0)); -} -template -object print(A0 const& a0, A1 const& a1) -{ - return api_detail::call_statement_du("print _1, _2", use_new_dict, 2, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2) -{ - return api_detail::call_statement_du("print _1, _2, _3", use_new_dict, 3, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3) -{ - return api_detail::call_statement_du("print _1, _2, _3, _4", use_new_dict, 4, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4) -{ - return api_detail::call_statement_du("print _1, _2, _3, _4, _5", use_new_dict, 5, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5) -{ - return api_detail::call_statement_du("print _1, _2, _3, _4, _5, _6", use_new_dict, 6, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6) -{ - return api_detail::call_statement_du("print _1, _2, _3, _4, _5, _6, _7", use_new_dict, 7, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7) -{ - return api_detail::call_statement_du("print _1, _2, _3, _4, _5, _6, _7, _8", use_new_dict, 8, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8) -{ - return api_detail::call_statement_du("print _1, _2, _3, _4, _5, _6, _7, _8, _9", use_new_dict, 9, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8)); -} -template -object print(A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9) -{ - return api_detail::call_statement_du("print _1, _2, _3, _4, _5, _6, _7, _8, _9, _10", use_new_dict, 10, (object const*)api_detail::get_arg(a0), (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9)); -} -BOOST_PYTHON_DECL object print(object const& a0); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object print(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -template -object print_file(object const& a0, A1 const& a1) -{ - return api_detail::call_statement_du("print >>_1, _2", use_new_dict, 2, a0, (object const*)api_detail::get_arg(a1)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2) -{ - return api_detail::call_statement_du("print >>_1, _2, _3", use_new_dict, 3, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4", use_new_dict, 4, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4, _5", use_new_dict, 5, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4, _5, _6", use_new_dict, 6, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4, _5, _6, _7", use_new_dict, 7, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4, _5, _6, _7, _8", use_new_dict, 8, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4, _5, _6, _7, _8, _9", use_new_dict, 9, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4, _5, _6, _7, _8, _9, _10", use_new_dict, 10, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9)); -} -template -object print_file(object const& a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9, A10 const& a10) -{ - return api_detail::call_statement_du("print >>_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11", use_new_dict, 11, a0, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9), (object const*)api_detail::get_arg(a10)); -} -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -BOOST_PYTHON_DECL object print_file(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9, object const& a10); -template -object range(A0 const& a0) -{ - return api_detail::get_func("range")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object range(object const& a0); -BOOST_PYTHON_DECL object range(int a0); -template -object range(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("range")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -BOOST_PYTHON_DECL object range(object const& a0, object const& a1); -BOOST_PYTHON_DECL object range(int a0, int a1); -template -object range(A0 const& a0, A1 const& a1, A2 const& a2) -{ - return api_detail::get_func("range")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2)); -} -BOOST_PYTHON_DECL object range(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object range(int a0, int a1, int a2); -BOOST_PYTHON_DECL object raw_input(); -BOOST_PYTHON_DECL object raw_input(object const& a0); -BOOST_PYTHON_DECL object raw_input(const char* a0); -BOOST_PYTHON_DECL object reduce(object const& a0, object const& a1); -BOOST_PYTHON_DECL object reduce(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object reload(object const& a0); -BOOST_PYTHON_DECL object repr(object const& a0); -template -object round(A0 const& a0) -{ - return api_detail::get_func("round")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object round(object const& a0); -BOOST_PYTHON_DECL object round(double const& a0); -template -object round(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("round")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -BOOST_PYTHON_DECL object round(object const& a0, object const& a1); -BOOST_PYTHON_DECL object round(double const& a0, double const& a1); -template -object slice(A0 const& a0) -{ - return api_detail::get_func("slice")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object slice(object const& a0); -BOOST_PYTHON_DECL object slice(int a0); -template -object slice(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("slice")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -BOOST_PYTHON_DECL object slice(object const& a0, object const& a1); -BOOST_PYTHON_DECL object slice(int a0, int a1); -template -object slice(A0 const& a0, A1 const& a1, A2 const& a2) -{ - return api_detail::get_func("slice")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2)); -} -BOOST_PYTHON_DECL object slice(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object slice(int a0, int a1, int a2); -BOOST_PYTHON_DECL object str(object const& a0); -BOOST_PYTHON_DECL object tuple(); -BOOST_PYTHON_DECL object tuple(object const& a0); -BOOST_PYTHON_DECL object type_(object const& a0); -template -object unichr(A0 const& a0) -{ - return api_detail::get_func("unichr")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object unichr(object const& a0); -BOOST_PYTHON_DECL object unichr(short a0); -BOOST_PYTHON_DECL object unichr(int a0); -BOOST_PYTHON_DECL object unichr(long a0); -BOOST_PYTHON_DECL object unicode(object const& a0); -BOOST_PYTHON_DECL object unicode(object const& a0, object const& a1); -BOOST_PYTHON_DECL object unicode(object const& a0, const char* a1); -BOOST_PYTHON_DECL object unicode(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object unicode(object const& a0, const char* a1, const char* a2); -BOOST_PYTHON_DECL object vars(); -BOOST_PYTHON_DECL object vars(object const& a0); -template -object xrange(A0 const& a0) -{ - return api_detail::get_func("xrange")(api_detail::get_arg(a0)); -} -BOOST_PYTHON_DECL object xrange(object const& a0); -BOOST_PYTHON_DECL object xrange(int a0); -template -object xrange(A0 const& a0, A1 const& a1) -{ - return api_detail::get_func("xrange")(api_detail::get_arg(a0), api_detail::get_arg(a1)); -} -BOOST_PYTHON_DECL object xrange(object const& a0, object const& a1); -BOOST_PYTHON_DECL object xrange(int a0, int a1); -template -object xrange(A0 const& a0, A1 const& a1, A2 const& a2) -{ - return api_detail::get_func("xrange")(api_detail::get_arg(a0), api_detail::get_arg(a1), api_detail::get_arg(a2)); -} -BOOST_PYTHON_DECL object xrange(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object xrange(int a0, int a1, int a2); -BOOST_PYTHON_DECL object zip(object const& a0); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object zip(object const& a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -BOOST_PYTHON_DECL object compile_string(const char* a0, const char* a1, int a2); -BOOST_PYTHON_DECL int import_append_inittab(const char* a0, void(*a1)(void)); -BOOST_PYTHON_DECL object import_add_module(const char* a0); -BOOST_PYTHON_DECL object import_get_module_dict(); -BOOST_PYTHON_DECL object import_import(object const& a0); -BOOST_PYTHON_DECL object import_import(const char* a0); -BOOST_PYTHON_DECL object import_import_module(const char* a0); -BOOST_PYTHON_DECL object import_import_module_ex(const char* a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object module_get_dict(object const& a0); -BOOST_PYTHON_DECL int object_print(object const& a0, FILE* a1, int a2); -BOOST_PYTHON_DECL object run_file(FILE* a0, const char* a1, int a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL int run_simple_file(FILE* a0, const char* a1); -BOOST_PYTHON_DECL int run_simple_string(const char* a0); -BOOST_PYTHON_DECL object run_string(const char* a0, int a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object call_statement(const char* a0); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1); -template -object call_statement(const char* a0, A1 const& a1) -{ - return api_detail::call_statement(a0, 1, (object const*)api_detail::get_arg(a1)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2) -{ - return api_detail::call_statement(a0, 2, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3) -{ - return api_detail::call_statement(a0, 3, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4) -{ - return api_detail::call_statement(a0, 4, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5) -{ - return api_detail::call_statement(a0, 5, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6) -{ - return api_detail::call_statement(a0, 6, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7) -{ - return api_detail::call_statement(a0, 7, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8) -{ - return api_detail::call_statement(a0, 8, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9) -{ - return api_detail::call_statement(a0, 9, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9)); -} -template -object call_statement(const char* a0, A1 const& a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9, A10 const& a10) -{ - return api_detail::call_statement(a0, 10, (object const*)api_detail::get_arg(a1), (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9), (object const*)api_detail::get_arg(a10)); -} -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -BOOST_PYTHON_DECL object call_statement(const char* a0, object const& a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9, object const& a10); -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2) -{ - return api_detail::call_statement_du(a0, a1, 1, (object const*)api_detail::get_arg(a2)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3) -{ - return api_detail::call_statement_du(a0, a1, 2, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4) -{ - return api_detail::call_statement_du(a0, a1, 3, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5) -{ - return api_detail::call_statement_du(a0, a1, 4, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6) -{ - return api_detail::call_statement_du(a0, a1, 5, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7) -{ - return api_detail::call_statement_du(a0, a1, 6, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8) -{ - return api_detail::call_statement_du(a0, a1, 7, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9) -{ - return api_detail::call_statement_du(a0, a1, 8, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9, A10 const& a10) -{ - return api_detail::call_statement_du(a0, a1, 9, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9), (object const*)api_detail::get_arg(a10)); -} -template -object call_statement(const char* a0, call_dict_usage a1, A2 const& a2, A3 const& a3, A4 const& a4, A5 const& a5, A6 const& a6, A7 const& a7, A8 const& a8, A9 const& a9, A10 const& a10, A11 const& a11) -{ - return api_detail::call_statement_du(a0, a1, 10, (object const*)api_detail::get_arg(a2), (object const*)api_detail::get_arg(a3), (object const*)api_detail::get_arg(a4), (object const*)api_detail::get_arg(a5), (object const*)api_detail::get_arg(a6), (object const*)api_detail::get_arg(a7), (object const*)api_detail::get_arg(a8), (object const*)api_detail::get_arg(a9), (object const*)api_detail::get_arg(a10), (object const*)api_detail::get_arg(a11)); -} -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4, object const& a5); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9, object const& a10); -BOOST_PYTHON_DECL object call_statement(const char* a0, call_dict_usage a1, object const& a2, object const& a3, object const& a4, object const& a5, object const& a6, object const& a7, object const& a8, object const& a9, object const& a10, object const& a11); - -}}} - -#endif // PY_INTERFACE_HPP - diff --git a/include/boost/python/str.hpp b/include/boost/python/str.hpp index ffb3c362..d283fe8a 100644 --- a/include/boost/python/str.hpp +++ b/include/boost/python/str.hpp @@ -15,347 +15,367 @@ namespace boost { namespace python { -class str : public object -{ - public: - BOOST_PYTHON_DECL str(); // new str - - BOOST_PYTHON_DECL str(const char* s); // new str - explicit BOOST_PYTHON_DECL str(object_cref other); +class str; +namespace detail +{ + struct BOOST_PYTHON_DECL str_base : object + { + str capitalize() const; + + str center(object_cref width) const; + + long count(object_cref sub) const; + + long count(object_cref sub, object_cref start) const; + + long count(object_cref sub, object_cref start, object_cref end) const; + + object decode() const; + object decode(object_cref encoding) const; + + object decode(object_cref encoding, object_cref errors) const; + + object encode() const; + object encode(object_cref encoding) const; + object encode(object_cref encoding, object_cref errors) const; + + bool endswith(object_cref suffix) const; + + bool endswith(object_cref suffix, object_cref start) const; + bool endswith(object_cref suffix, object_cref start, object_cref end) const; + + str expandtabs() const; + str expandtabs(object_cref tabsize) const; + + long find(object_cref sub) const; + long find(object_cref sub, object_cref start) const; + + long find(object_cref sub, object_cref start, object_cref end) const; + + long index(object_cref sub) const; + + long index(object_cref sub, object_cref start) const; + long index(object_cref sub, object_cref start, object_cref end) const; + + bool isalnum() const; + bool isalpha() const; + bool isdigit() const; + bool islower() const; + bool isspace() const; + bool istitle() const; + bool isupper() const; + + str join(object_cref sequence) const; + + str ljust(object_cref width) const; + str lower() const; + str lstrip() const; + + str replace(object_cref old, object_cref new_) const; + str replace(object_cref old, object_cref new_, object_cref maxsplit) const; + long rfind(object_cref sub) const; + + long rfind(object_cref sub, object_cref start) const; + + long rfind(object_cref sub, object_cref start, object_cref end) const; + long rindex(object_cref sub) const; + long rindex(object_cref sub, object_cref start) const; + + + long rindex(object_cref sub, object_cref start, object_cref end) const; + + str rjust(object_cref width) const; + + str rstrip() const; + + list split() const; + list split(object_cref sep) const; + + list split(object_cref sep, object_cref maxsplit) const; + + + list splitlines() const; + list splitlines(object_cref keepends) const; + + bool startswith(object_cref prefix) const; + + + bool startswith(object_cref prefix, object_cref start) const; + bool startswith(object_cref prefix, object_cref start, object_cref end) const; + + str strip() const; + str swapcase() const; + str title() const; + + str translate(object_cref table) const; + + str translate(object_cref table, object_cref deletechars) const; + + + str upper() const; + + protected: + str_base(); // new str + + str_base(const char* s); // new str + explicit str_base(object_cref other); + + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str_base, object) + private: + static new_reference call(object const&); + }; +} + + +class str : public detail::str_base +{ + typedef detail::str_base base; + public: + str() {} // new str + + str(const char* s) : base(s) {} // new str + template explicit str(T const& other) - : object(str::call(object(other))) + : base(object(other)) { } - BOOST_PYTHON_DECL str capitalize() const ; - - BOOST_PYTHON_DECL str center(object_cref width) const ; - template str center(T const& width) const { - return this->center(object(width)); + return base::center(object(width)); } - BOOST_PYTHON_DECL long count(object_cref sub) const; - template long count(T const& sub) const { - return this->count(object(sub)); + return base::count(object(sub)); } - BOOST_PYTHON_DECL long count(object_cref sub, object_cref start) const; - template long count(T1 const& sub,T2 const& start) const { - return this->count(object(sub), object(start)); + return base::count(object(sub), object(start)); } - BOOST_PYTHON_DECL long count(object_cref sub, object_cref start, object_cref end) const; - template long count(T1 const& sub,T2 const& start, T3 const& end) const { - return this->count(object(sub), object(start)); + return base::count(object(sub), object(start)); } - BOOST_PYTHON_DECL object decode() const; - BOOST_PYTHON_DECL object decode(object_cref encoding) const; - + object decode() const { return base::decode(); } + template object decode(T const& encoding) const { - return this->decode(object(encoding)); + return base::decode(object(encoding)); } - BOOST_PYTHON_DECL object decode(object_cref encoding, object_cref errors) const; - template object decode(T1 const& encoding, T2 const& errors) const { - return this->decode(object(encoding),object(errors)); + return base::decode(object(encoding),object(errors)); } - BOOST_PYTHON_DECL object encode() const; - BOOST_PYTHON_DECL object encode(object_cref encoding) const; + object encode() const { return base::encode(); } template object encode(T const& encoding) const { - return this->encode(object(encoding)); + return base::encode(object(encoding)); } - BOOST_PYTHON_DECL object encode(object_cref encoding, object_cref errors) const; - template object encode(T1 const& encoding, T2 const& errors) const { - return this->encode(object(encoding),object(errors)); + return base::encode(object(encoding),object(errors)); } - BOOST_PYTHON_DECL bool endswith(object_cref suffix) const; - template bool endswith(T const& suffix) const { - return this->endswith(object(suffix)); + return base::endswith(object(suffix)); } - BOOST_PYTHON_DECL bool endswith(object_cref suffix, object_cref start) const; - template bool endswith(T1 const& suffix, T2 const& start) const { - return this->endswith(object(suffix), object(start)); + return base::endswith(object(suffix), object(start)); } - BOOST_PYTHON_DECL bool endswith(object_cref suffix, object_cref start, object_cref end) const; - template bool endswith(T1 const& suffix, T2 const& start, T3 const& end) const { - return this->endswith(object(suffix), object(start), object(end)); + return base::endswith(object(suffix), object(start), object(end)); } - BOOST_PYTHON_DECL str expandtabs() const; - BOOST_PYTHON_DECL str expandtabs(object_cref tabsize) const; + str expandtabs() const { return base::expandtabs(); } template str expandtabs(T const& tabsize) const { - return this->expandtabs(object(tabsize)); + return base::expandtabs(object(tabsize)); } - BOOST_PYTHON_DECL long find(object_cref sub) const; - template long find(T const& sub) const { - return this->find(object(sub)); + return base::find(object(sub)); } - BOOST_PYTHON_DECL long find(object_cref sub, object_cref start) const; - template long find(T1 const& sub, T2 const& start) const { - return this->find(object(sub), object(start)); + return base::find(object(sub), object(start)); } - BOOST_PYTHON_DECL long find(object_cref sub, object_cref start, object_cref end) const; - template long find(T1 const& sub, T2 const& start, T3 const& end) const { - return this->find(object(sub), object(start), object(end)); + return base::find(object(sub), object(start), object(end)); } - BOOST_PYTHON_DECL long index(object_cref sub) const; - template long index(T const& sub) const { - return this->index(object(sub)); + return base::index(object(sub)); } - BOOST_PYTHON_DECL long index(object_cref sub, object_cref start) const; - template long index(T1 const& sub, T2 const& start) const { - return this->index(object(sub), object(start)); + return base::index(object(sub), object(start)); } - BOOST_PYTHON_DECL long index(object_cref sub, object_cref start, object_cref end) const; - template long index(T1 const& sub, T2 const& start, T3 const& end) const { - return this->index(object(sub), object(start), object(end)); + return base::index(object(sub), object(start), object(end)); } - BOOST_PYTHON_DECL bool isalnum() const; - BOOST_PYTHON_DECL bool isalpha() const; - BOOST_PYTHON_DECL bool isdigit() const; - BOOST_PYTHON_DECL bool islower() const; - BOOST_PYTHON_DECL bool isspace() const; - BOOST_PYTHON_DECL bool istitle() const; - BOOST_PYTHON_DECL bool isupper() const; - - BOOST_PYTHON_DECL str join(object_cref sequence) const; - template str join(T const& sequence) const { - return this->join(object(sequence)); + return base::join(object(sequence)); } - BOOST_PYTHON_DECL str ljust(object_cref width) const; - template str ljust(T const& width) const { - return this->ljust(object(width)); + return base::ljust(object(width)); } - BOOST_PYTHON_DECL str lower() const; - BOOST_PYTHON_DECL str lstrip() const; - - BOOST_PYTHON_DECL str replace(object_cref old, object_cref new_) const ; - template str replace(T1 const& old, T2 const& new_) const { - return this->replace(object(old),object(new_)); + return base::replace(object(old),object(new_)); } - BOOST_PYTHON_DECL str replace(object_cref old, object_cref new_, object_cref maxsplit) const ; - template str replace(T1 const& old, T2 const& new_, T3 const& maxsplit) const { - return this->replace(object(old),object(new_),object(maxsplit)); + return base::replace(object(old),object(new_), object(maxsplit)); } - BOOST_PYTHON_DECL long rfind(object_cref sub) const; - template long rfind(T const& sub) const { - return this->rfind(object(sub)); + return base::rfind(object(sub)); } - BOOST_PYTHON_DECL long rfind(object_cref sub, object_cref start) const; - template long rfind(T1 const& sub, T2 const& start) const { - return this->rfind(object(sub), object(start)); + return base::rfind(object(sub), object(start)); } - BOOST_PYTHON_DECL long rfind(object_cref sub, object_cref start, object_cref end) const; - template long rfind(T1 const& sub, T2 const& start, T3 const& end) const { - return this->rfind(object(sub), object(start), object(end)); + return base::rfind(object(sub), object(start), object(end)); } - BOOST_PYTHON_DECL long rindex(object_cref sub) const; - template long rindex(T const& sub) const { - return this->rindex(object(sub)); + return base::rindex(object(sub)); } - BOOST_PYTHON_DECL long rindex(object_cref sub, object_cref start) const; - template long rindex(T1 const& sub, T2 const& start) const { - return this->rindex(object(sub), object(start)); + return base::rindex(object(sub), object(start)); } - BOOST_PYTHON_DECL long rindex(object_cref sub, object_cref start, object_cref end) const; - template long rindex(T1 const& sub, T2 const& start, T3 const& end) const { - return this->rindex(object(sub), object(start), object(end)); + return base::rindex(object(sub), object(start), object(end)); } - BOOST_PYTHON_DECL str rjust(object_cref width) const; - template str rjust(T const& width) const { - return this->rjust(object(width)); + return base::rjust(object(width)); } - BOOST_PYTHON_DECL str rstrip() const; - - BOOST_PYTHON_DECL list split() const; - BOOST_PYTHON_DECL list split(object_cref sep) const; + list split() const { return base::split(); } template list split(T const& sep) const { - return this->split(object(sep)); + return base::split(object(sep)); } - BOOST_PYTHON_DECL list split(object_cref sep, object_cref maxsplit) const; - template list split(T1 const& sep, T2 const& maxsplit) const { - return this->split(object(sep), object(maxsplit)); + return base::split(object(sep), object(maxsplit)); } - BOOST_PYTHON_DECL list splitlines() const; - BOOST_PYTHON_DECL list splitlines(object_cref keepends) const; + list splitlines() const { return base::splitlines(); } template list splitlines(T const& keepends) const { - return this->splitlines(object(keepends)); + return base::splitlines(object(keepends)); } - BOOST_PYTHON_DECL bool startswith(object_cref prefix) const ; - template bool startswith(T const& prefix) const { - return this->startswith(object(prefix)); + return base::startswith(object(prefix)); } - BOOST_PYTHON_DECL bool startswith(object_cref prefix, object_cref start) const ; - template - bool startswidth(T1 const& prefix, T2 const& start) const + bool startswith(T1 const& prefix, T2 const& start) const { - return this->startswidth(object(prefix), object(start)); + return base::startswith(object(prefix), object(start)); } - BOOST_PYTHON_DECL bool startswith(object_cref prefix, object_cref start, object_cref end) const ; - template - bool startswidth(T1 const& prefix, T2 const& start, T3 const& end) const + bool startswith(T1 const& prefix, T2 const& start, T3 const& end) const { - return this->startswidth(object(prefix), object(start), object(end)); + return base::startswith(object(prefix), object(start), object(end)); } - BOOST_PYTHON_DECL str strip() const ; - BOOST_PYTHON_DECL str swapcase() const ; - BOOST_PYTHON_DECL str title() const ; - - BOOST_PYTHON_DECL str translate(object_cref table) const; - template str translate(T const& table) const { - return this->translate(object(table)); + return base::translate(object(table)); } - BOOST_PYTHON_DECL str translate(object_cref table, object_cref deletechars) const; - template str translate(T1 const& table, T2 const& deletechars) const { - return this->translate(object(table), object(deletechars)); + return base::translate(object(table), object(deletechars)); } - BOOST_PYTHON_DECL str upper() const; - public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str, object) - - private: - static BOOST_PYTHON_DECL detail::new_reference call(object const&); + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str, base) }; // diff --git a/include/boost/python/tuple.hpp b/include/boost/python/tuple.hpp index 77c5e67c..af5bbf8a 100644 --- a/include/boost/python/tuple.hpp +++ b/include/boost/python/tuple.hpp @@ -8,26 +8,35 @@ namespace boost { namespace python { -class tuple : public object +namespace detail { - public: - // tuple() -> an empty tuple - BOOST_PYTHON_DECL tuple(); + struct BOOST_PYTHON_DECL tuple_base : object + { + protected: + tuple_base(); + tuple_base(object_cref sequence); + + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(tuple_base, object) - // tuple(sequence) -> tuple initialized from sequence's items - BOOST_PYTHON_DECL tuple(object_cref sequence); + private: + static detail::new_reference call(object const&); + }; +} + +class tuple : public detail::tuple_base +{ + typedef detail::tuple_base base; + public: + tuple() {} template explicit tuple(T const& sequence) - : object(tuple::call(object(sequence))) + : base(object(sequence)) { } public: // implementation detail -- for internal use only - BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(tuple, object) - - private: - static BOOST_PYTHON_DECL detail::new_reference call(object const&); + BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(tuple, base) }; // diff --git a/src/aix_init_module.cpp b/src/aix_init_module.cpp index 3d74596e..2345aa4f 100644 --- a/src/aix_init_module.cpp +++ b/src/aix_init_module.cpp @@ -17,7 +17,7 @@ extern "C" # include # include # include -# include +# include namespace boost { namespace python { namespace detail { diff --git a/src/dict.cpp b/src/dict.cpp index e24145d0..847d2182 100644 --- a/src/dict.cpp +++ b/src/dict.cpp @@ -1,8 +1,7 @@ #include #include -namespace boost { namespace python { - +namespace boost { namespace python { namespace detail { namespace { // When returning list objects from methods, it may turn out that the @@ -18,28 +17,28 @@ namespace } // No PyDict_CheckExact; roll our own. - inline bool check_exact(dict const* p) + inline bool check_exact(dict_base const* p) { return p->ptr()->ob_type == &PyDict_Type; } } -detail::new_reference dict::call(object const& arg_) +detail::new_reference dict_base::call(object const& arg_) { return (detail::new_reference)PyObject_CallFunction( (PyObject*)&PyDict_Type, "(O)", arg_.ptr()); } -dict::dict() +dict_base::dict_base() : object(detail::new_reference(PyDict_New())) {} -dict::dict(object_cref data) - : object(dict::call(data)) +dict_base::dict_base(object_cref data) + : object(call(data)) {} -void dict::clear() +void dict_base::clear() { if (check_exact(this)) PyDict_Clear(this->ptr()); @@ -47,7 +46,7 @@ void dict::clear() this->attr("clear")(); } -dict dict::copy() +dict dict_base::copy() { if (check_exact(this)) { @@ -62,7 +61,7 @@ dict dict::copy() } } -object dict::get(object_cref k) const +object dict_base::get(object_cref k) const { if (check_exact(this)) { @@ -75,17 +74,17 @@ object dict::get(object_cref k) const } } -object dict::get(object_cref k, object_cref d) const +object dict_base::get(object_cref k, object_cref d) const { return this->attr("get")(k,d); } -bool dict::has_key(object_cref k) const +bool dict_base::has_key(object_cref k) const { return extract(this->attr("has_key")(k)); } -list dict::items() const +list dict_base::items() const { if (check_exact(this)) { @@ -98,22 +97,22 @@ list dict::items() const } } -object dict::iteritems() const +object dict_base::iteritems() const { return this->attr("iteritems")(); } -object dict::iterkeys() const +object dict_base::iterkeys() const { return this->attr("iterkeys")(); } -object dict::itervalues() const +object dict_base::itervalues() const { return this->attr("itervalues")(); } -list dict::keys() const +list dict_base::keys() const { if (check_exact(this)) { @@ -126,24 +125,24 @@ list dict::keys() const } } -tuple dict::popitem() +tuple dict_base::popitem() { return tuple(detail::borrowed_reference( this->attr("popitem")().ptr() )); } -object dict::setdefault(object_cref k) +object dict_base::setdefault(object_cref k) { return this->attr("setdefault")(k); } -object dict::setdefault(object_cref k, object_cref d) +object dict_base::setdefault(object_cref k, object_cref d) { return this->attr("setdefault")(k,d); } -void dict::update(object_cref other) +void dict_base::update(object_cref other) { if (check_exact(this)) { @@ -156,7 +155,7 @@ void dict::update(object_cref other) } } -list dict::values() const +list dict_base::values() const { if (check_exact(this)) { @@ -169,4 +168,4 @@ list dict::values() const } } -}} // namespace boost::python +}}} // namespace boost::python diff --git a/src/list.cpp b/src/list.cpp index 1f434320..aab01bc3 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -5,9 +5,9 @@ // to its suitability for any purpose. #include -namespace boost { namespace python { +namespace boost { namespace python { namespace detail { -detail::new_non_null_reference list::call(object const& arg_) +detail::new_non_null_reference list_base::call(object const& arg_) { return (detail::new_non_null_reference) (expect_non_null)( @@ -16,15 +16,15 @@ detail::new_non_null_reference list::call(object const& arg_) arg_.ptr())); } -list::list() +list_base::list_base() : object(detail::new_reference(PyList_New(0))) {} -list::list(object_cref sequence) - : object(list::call(sequence)) +list_base::list_base(object_cref sequence) + : object(list_base::call(sequence)) {} -void list::append(object_cref x) +void list_base::append(object_cref x) { if (PyList_CheckExact(this->ptr())) { @@ -37,7 +37,7 @@ void list::append(object_cref x) } } -long list::count(object_cref value) const +long list_base::count(object_cref value) const { object result_obj(this->attr("count")(value)); long result = PyInt_AsLong(result_obj.ptr()); @@ -46,12 +46,12 @@ long list::count(object_cref value) const return result; } -void list::extend(object_cref sequence) +void list_base::extend(object_cref sequence) { this->attr("extend")(sequence); } -long list::index(object_cref value) const +long list_base::index(object_cref value) const { object result_obj(this->attr("index")(value)); long result = PyInt_AsLong(result_obj.ptr()); @@ -60,7 +60,7 @@ long list::index(object_cref value) const return result; } -void list::insert(int index, object_cref item) +void list_base::insert(int index, object_cref item) { if (PyList_CheckExact(this->ptr())) { @@ -73,7 +73,7 @@ void list::insert(int index, object_cref item) } } -void list::insert(object const& index, object_cref x) +void list_base::insert(object const& index, object_cref x) { long index_ = PyInt_AsLong(index.ptr()); if (index_ == -1 && PyErr_Occurred()) @@ -81,27 +81,27 @@ void list::insert(object const& index, object_cref x) this->insert(index_, x); } -object list::pop() +object list_base::pop() { return this->attr("pop")(); } -object list::pop(long index) +object list_base::pop(long index) { return this->pop(object(index)); } -object list::pop(object const& index) +object list_base::pop(object const& index) { return this->attr("pop")(index); } -void list::remove(object_cref value) +void list_base::remove(object_cref value) { this->attr("remove")(value); } -void list::reverse() +void list_base::reverse() { if (PyList_CheckExact(this->ptr())) { @@ -114,7 +114,7 @@ void list::reverse() } } -void list::sort() +void list_base::sort() { if (PyList_CheckExact(this->ptr())) { @@ -127,9 +127,9 @@ void list::sort() } } -void list::sort(object_cref cmpfunc) +void list_base::sort(object_cref cmpfunc) { this->attr("sort")(cmpfunc); } -}} // namespace boost::python +}}} // namespace boost::python diff --git a/src/long.cpp b/src/long.cpp index e66d4bdd..bfc09257 100644 --- a/src/long.cpp +++ b/src/long.cpp @@ -5,36 +5,36 @@ // to its suitability for any purpose. #include -namespace boost { namespace python { +namespace boost { namespace python { namespace detail { -detail::new_non_null_reference long_::call(object const& arg_) +new_non_null_reference long_base::call(object const& arg_) { return (detail::new_non_null_reference)PyObject_CallFunction( (PyObject*)&PyLong_Type, "(O)", arg_.ptr()); } -detail::new_non_null_reference long_::call(object const& arg_, object const& base) +new_non_null_reference long_base::call(object const& arg_, object const& base) { return (detail::new_non_null_reference)PyObject_CallFunction( (PyObject*)&PyLong_Type, "(OO)", arg_.ptr(), base.ptr()); } -long_::long_() +long_base::long_base() : object( detail::new_reference( PyObject_CallFunction((PyObject*)&PyLong_Type, "()")) ) {} -long_::long_(object_cref arg) - : object(long_::call(arg)) +long_base::long_base(object_cref arg) + : object(long_base::call(arg)) {} -long_::long_(object_cref arg, object_cref base) - : object(long_::call(arg, base)) +long_base::long_base(object_cref arg, object_cref base) + : object(long_base::call(arg, base)) {} -}} // namespace boost::python +}}} // namespace boost::python diff --git a/src/module.cpp b/src/module.cpp index d81e626a..42bb7a8c 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -6,39 +6,12 @@ // The author gratefully acknowleges the support of Dragon Systems, Inc., in // producing this work. -#include -#include -#include -#include -#include -#include -#include #include +#include namespace boost { namespace python { namespace detail { -module_base::module_base(char const* name, char const* doc) - : m_module( - allow_null(python::borrowed( - scope().ptr() - ))) -{ - if (doc != 0) - scope().attr("__doc__") = doc; -} - -module_base::~module_base() -{ -} - -void module_base::setattr_doc(const char* name, python::object const& x, char const* doc) -{ - // Use function::add_to_namespace to achieve overloading if - // appropriate. - objects::add_to_namespace(python::object(m_module), name, x, doc); -} - -void BOOST_PYTHON_DECL scope_setattr_doc(char const* name, object const& x, char const* doc) +BOOST_PYTHON_DECL void scope_setattr_doc(char const* name, object const& x, char const* doc) { // Use function::add_to_namespace to achieve overloading if // appropriate. @@ -46,13 +19,6 @@ void BOOST_PYTHON_DECL scope_setattr_doc(char const* name, object const& x, char objects::add_to_namespace(current, name, x, doc); } -void module_base::add(type_handle const& x) -{ - this->setattr_doc(x->tp_name, python::object(x), 0); -} - -PyMethodDef module_base::initial_methods[] = { { 0, 0, 0, 0 } }; - namespace { PyMethodDef initial_methods[] = { { 0, 0, 0, 0 } }; @@ -66,8 +32,6 @@ BOOST_PYTHON_DECL void init_module(char const* name, void(*init_function)()) if (m != 0) { - ; - // Create the current module scope scope current_module( (object( diff --git a/src/object/class.cpp b/src/object/class.cpp index 3cd62a37..201499e2 100644 --- a/src/object/class.cpp +++ b/src/object/class.cpp @@ -330,7 +330,7 @@ namespace objects // rest corresponding to its declared bases. // inline object - new_class(char const* name, std::size_t num_types, class_id const* const types) + new_class(char const* name, std::size_t num_types, class_id const* const types, char const* doc) { assert(num_types >= 1); @@ -348,7 +348,12 @@ namespace objects } // Call the class metatype to create a new class - object result = object(class_metatype())(module_prefix() + name, bases, dict()); + dict d; + + if (doc != 0) + d["__doc__"] = doc; + + object result = object(class_metatype())(module_prefix() + name, bases, d); assert(PyType_IsSubtype(result.ptr()->ob_type, &PyType_Type)); if (scope().ptr() != Py_None) @@ -360,7 +365,7 @@ namespace objects class_base::class_base( char const* name, std::size_t num_types, class_id const* const types, char const* doc) - : object(new_class(name, num_types, types)) + : object(new_class(name, num_types, types, doc)) { // Insert the new class object in the registry converter::registration& converters = const_cast( @@ -368,9 +373,6 @@ namespace objects // Class object is leaked, for now converters.class_object = (PyTypeObject*)incref(this->ptr()); - - if (doc) - this->attr("__doc__") = doc; } void class_base::set_instance_size(std::size_t instance_size) diff --git a/src/str.cpp b/src/str.cpp index fff18221..a8a2383f 100644 --- a/src/str.cpp +++ b/src/str.cpp @@ -1,99 +1,98 @@ #include #include -namespace boost { namespace python { +namespace boost { namespace python { namespace detail { -detail::new_reference str::call(object const& arg_) +detail::new_reference str_base::call(object const& arg_) { return (detail::new_reference)PyObject_CallFunction( (PyObject*)&PyString_Type, "(O)", arg_.ptr()); } -str::str() +str_base::str_base() : object(detail::new_reference(PyString_FromString(""))) {} -str::str(const char* s) +str_base::str_base(const char* s) : object(detail::new_reference(PyString_FromString(s))) {} -str::str(object_cref other) - : object(str::call(other)) +str_base::str_base(object_cref other) + : object(str_base::call(other)) {} namespace { - // When returning str objects from methods, it may turn out that the - // derived class is returning something else, perhaps something not - // even derived from str. Since it is generally harmless for a - // Boost.Python wrapper object to hold an object of a different - // type, and because calling str() with an object may in fact - // perform a conversion, the least-bad alternative is to assume that - // we have a Python str object and stuff it into the str result. - str assume_str(object const& o) + new_reference new_attr_reference(object const* obj, char const* name) { - return str(detail::borrowed_reference(o.ptr())); + return new_reference(incref(object(obj->attr(name)).ptr())); } } -str str::capitalize() const -{ - return assume_str(this->attr("capitalize")()); + +#define BOOST_PYTHON_FORMAT_OBJECT(z, n, data) "O" +#define BOOST_PYTHON_OBJECT_PTR(z, n, data) , x##n .ptr() + +#define BOOST_PYTHON_DEFINE_STR_METHOD(name, arity) \ +str str_base:: name ( BOOST_PP_ENUM_PARAMS(arity, object_cref x) ) const \ +{ \ + return str(new_reference( \ + expect_non_null( \ + PyObject_CallMethod( \ + this->ptr(), #name, \ + "(" BOOST_PP_REPEAT(arity, BOOST_PYTHON_FORMAT_OBJECT, _) ")" \ + BOOST_PP_REPEAT_1(arity, BOOST_PYTHON_OBJECT_PTR, _))))); \ } -str str::center(object_cref width) const -{ - return assume_str( - this->attr("center")(width) - ); -} +BOOST_PYTHON_DEFINE_STR_METHOD(capitalize, 0) +BOOST_PYTHON_DEFINE_STR_METHOD(center, 1) -long str::count(object_cref sub) const +long str_base::count(object_cref sub) const { return extract(this->attr("count")(sub)); } -long str::count(object_cref sub, object_cref start) const +long str_base::count(object_cref sub, object_cref start) const { return extract(this->attr("count")(sub,start)); } -long str::count(object_cref sub, object_cref start, object_cref end) const +long str_base::count(object_cref sub, object_cref start, object_cref end) const { return extract(this->attr("count")(sub,start,end)); } -object str::decode() const +object str_base::decode() const { return this->attr("decode")(); } -object str::decode(object_cref encoding) const +object str_base::decode(object_cref encoding) const { return this->attr("decode")(encoding); } -object str::decode(object_cref encoding, object_cref errors) const +object str_base::decode(object_cref encoding, object_cref errors) const { return this->attr("decode")(encoding,errors); } -object str::encode() const +object str_base::encode() const { return this->attr("encode")(); } -object str::encode(object_cref encoding) const +object str_base::encode(object_cref encoding) const { return this->attr("encode")(encoding); } -object str::encode(object_cref encoding, object_cref errors) const +object str_base::encode(object_cref encoding, object_cref errors) const { return this->attr("encode")(encoding,errors); } -bool str::endswith(object_cref suffix) const +bool str_base::endswith(object_cref suffix) const { bool result = PyInt_AsLong(this->attr("endswith")(suffix).ptr()); if (PyErr_Occurred()) @@ -101,17 +100,10 @@ bool str::endswith(object_cref suffix) const return result; } -str str::expandtabs() const -{ - return assume_str(this->attr("expandtabs")()); -} +BOOST_PYTHON_DEFINE_STR_METHOD(expandtabs, 0) +BOOST_PYTHON_DEFINE_STR_METHOD(expandtabs, 1) -str str::expandtabs(object_cref tabsize) const -{ - return assume_str(this->attr("expandtabs")(tabsize)); -} - -long str::find(object_cref sub) const +long str_base::find(object_cref sub) const { long result = PyInt_AsLong(this->attr("find")(sub).ptr()); if (PyErr_Occurred()) @@ -119,7 +111,7 @@ long str::find(object_cref sub) const return result; } -long str::find(object_cref sub, object_cref start) const +long str_base::find(object_cref sub, object_cref start) const { long result = PyInt_AsLong(this->attr("find")(sub,start).ptr()); if (PyErr_Occurred()) @@ -127,7 +119,7 @@ long str::find(object_cref sub, object_cref start) const return result; } -long str::find(object_cref sub, object_cref start, object_cref end) const +long str_base::find(object_cref sub, object_cref start, object_cref end) const { long result = PyInt_AsLong(this->attr("find")(sub,start,end).ptr()); if (PyErr_Occurred()) @@ -135,7 +127,7 @@ long str::find(object_cref sub, object_cref start, object_cref end) const return result; } -long str::index(object_cref sub) const +long str_base::index(object_cref sub) const { long result = PyInt_AsLong(this->attr("index")(sub).ptr()); if (PyErr_Occurred()) @@ -143,7 +135,7 @@ long str::index(object_cref sub) const return result; } -long str::index(object_cref sub, object_cref start) const +long str_base::index(object_cref sub, object_cref start) const { long result = PyInt_AsLong(this->attr("index")(sub,start).ptr()); if (PyErr_Occurred()) @@ -151,7 +143,7 @@ long str::index(object_cref sub, object_cref start) const return result; } -long str::index(object_cref sub, object_cref start, object_cref end) const +long str_base::index(object_cref sub, object_cref start, object_cref end) const { long result = PyInt_AsLong(this->attr("index")(sub,start,end).ptr()); if (PyErr_Occurred()) @@ -159,7 +151,7 @@ long str::index(object_cref sub, object_cref start, object_cref end) const return result; } -bool str::isalnum() const +bool str_base::isalnum() const { bool result = PyInt_AsLong(this->attr("isalnum")().ptr()); if (PyErr_Occurred()) @@ -167,7 +159,7 @@ bool str::isalnum() const return result; } -bool str::isalpha() const +bool str_base::isalpha() const { bool result = PyInt_AsLong(this->attr("isalpha")().ptr()); if (PyErr_Occurred()) @@ -175,7 +167,7 @@ bool str::isalpha() const return result; } -bool str::isdigit() const +bool str_base::isdigit() const { bool result = PyInt_AsLong(this->attr("isdigit")().ptr()); if (PyErr_Occurred()) @@ -183,7 +175,7 @@ bool str::isdigit() const return result; } -bool str::islower() const +bool str_base::islower() const { bool result = PyInt_AsLong(this->attr("islower")().ptr()); if (PyErr_Occurred()) @@ -191,7 +183,7 @@ bool str::islower() const return result; } -bool str::isspace() const +bool str_base::isspace() const { bool result = PyInt_AsLong(this->attr("isspace")().ptr()); if (PyErr_Occurred()) @@ -199,7 +191,7 @@ bool str::isspace() const return result; } -bool str::istitle() const +bool str_base::istitle() const { bool result = PyInt_AsLong(this->attr("istitle")().ptr()); if (PyErr_Occurred()) @@ -207,7 +199,7 @@ bool str::istitle() const return result; } -bool str::isupper() const +bool str_base::isupper() const { bool result = PyInt_AsLong(this->attr("isupper")().ptr()); if (PyErr_Occurred()) @@ -215,36 +207,14 @@ bool str::isupper() const return result; } -str str::join(object_cref sequence) const -{ - return assume_str(this->attr("join")(sequence)); -} +BOOST_PYTHON_DEFINE_STR_METHOD(join, 1) +BOOST_PYTHON_DEFINE_STR_METHOD(ljust, 1) +BOOST_PYTHON_DEFINE_STR_METHOD(lower, 0) +BOOST_PYTHON_DEFINE_STR_METHOD(lstrip, 0) +BOOST_PYTHON_DEFINE_STR_METHOD(replace, 2) +BOOST_PYTHON_DEFINE_STR_METHOD(replace, 3) -str str::ljust(object_cref width) const -{ - return assume_str(this->attr("ljust")(width)); -} - -str str::lower() const -{ - return assume_str(this->attr("lower")()); -} - -str str::lstrip() const -{ - return assume_str(this->attr("lstrip")()); -} - -str str::replace(object_cref old, object_cref new_) const -{ - return assume_str(this->attr("replace")(old,new_)); -} - -str str::replace(object_cref old, object_cref new_, object_cref maxsplit) const { - return assume_str(this->attr("replace")(old,new_,maxsplit)); -} - -long str::rfind(object_cref sub) const +long str_base::rfind(object_cref sub) const { long result = PyInt_AsLong(this->attr("rfind")(sub).ptr()); if (PyErr_Occurred()) @@ -252,7 +222,7 @@ long str::rfind(object_cref sub) const return result; } -long str::rfind(object_cref sub, object_cref start) const +long str_base::rfind(object_cref sub, object_cref start) const { long result = PyInt_AsLong(this->attr("rfind")(sub,start).ptr()); if (PyErr_Occurred()) @@ -260,7 +230,7 @@ long str::rfind(object_cref sub, object_cref start) const return result; } -long str::rfind(object_cref sub, object_cref start, object_cref end) const +long str_base::rfind(object_cref sub, object_cref start, object_cref end) const { long result = PyInt_AsLong(this->attr("rfind")(sub,start,end).ptr()); if (PyErr_Occurred()) @@ -268,7 +238,7 @@ long str::rfind(object_cref sub, object_cref start, object_cref end) const return result; } -long str::rindex(object_cref sub) const +long str_base::rindex(object_cref sub) const { long result = PyInt_AsLong(this->attr("rindex")(sub).ptr()); if (PyErr_Occurred()) @@ -276,7 +246,7 @@ long str::rindex(object_cref sub) const return result; } -long str::rindex(object_cref sub, object_cref start) const +long str_base::rindex(object_cref sub, object_cref start) const { long result = PyInt_AsLong(this->attr("rindex")(sub,start).ptr()); if (PyErr_Occurred()) @@ -284,7 +254,7 @@ long str::rindex(object_cref sub, object_cref start) const return result; } -long str::rindex(object_cref sub, object_cref start, object_cref end) const +long str_base::rindex(object_cref sub, object_cref start, object_cref end) const { long result = PyInt_AsLong(this->attr("rindex")(sub,start,end).ptr()); if (PyErr_Occurred()) @@ -292,42 +262,35 @@ long str::rindex(object_cref sub, object_cref start, object_cref end) const return result; } -str str::rjust(object_cref width) const -{ - return assume_str(this->attr("rjust")(width)); -} +BOOST_PYTHON_DEFINE_STR_METHOD(rjust, 1) +BOOST_PYTHON_DEFINE_STR_METHOD(rstrip, 0) -str str::rstrip() const -{ - return assume_str(this->attr("rstrip")()); -} - -list str::split() const +list str_base::split() const { return list(this->attr("split")()); } -list str::split(object_cref sep) const +list str_base::split(object_cref sep) const { return list(this->attr("split")(sep)); } -list str::split(object_cref sep, object_cref maxsplit) const +list str_base::split(object_cref sep, object_cref maxsplit) const { return list(this->attr("split")(sep,maxsplit)); } -list str::splitlines() const +list str_base::splitlines() const { return list(this->attr("splitlines")()); } -list str::splitlines(object_cref keepends) const +list str_base::splitlines(object_cref keepends) const { return list(this->attr("splitlines")(keepends)); } -bool str::startswith(object_cref prefix) const +bool str_base::startswith(object_cref prefix) const { bool result = PyInt_AsLong(this->attr("startswith")(prefix).ptr()); if (PyErr_Occurred()) @@ -335,7 +298,7 @@ bool str::startswith(object_cref prefix) const return result; } -bool str::startswith(object_cref prefix, object_cref start) const +bool str_base::startswith(object_cref prefix, object_cref start) const { bool result = PyInt_AsLong(this->attr("startswith")(prefix,start).ptr()); if (PyErr_Occurred()) @@ -343,7 +306,7 @@ bool str::startswith(object_cref prefix, object_cref start) const return result; } -bool str::startswith(object_cref prefix, object_cref start, object_cref end) const +bool str_base::startswith(object_cref prefix, object_cref start, object_cref end) const { bool result = PyInt_AsLong(this->attr("startswith")(prefix,start,end).ptr()); if (PyErr_Occurred()) @@ -351,34 +314,11 @@ bool str::startswith(object_cref prefix, object_cref start, object_cref end) con return result; } -str str::strip() const -{ - return assume_str(this->attr("strip")()); -} +BOOST_PYTHON_DEFINE_STR_METHOD(strip, 0) +BOOST_PYTHON_DEFINE_STR_METHOD(swapcase, 0) +BOOST_PYTHON_DEFINE_STR_METHOD(title, 0) +BOOST_PYTHON_DEFINE_STR_METHOD(translate, 1) +BOOST_PYTHON_DEFINE_STR_METHOD(translate, 2) +BOOST_PYTHON_DEFINE_STR_METHOD(upper, 0) -str str::swapcase() const -{ - return assume_str(this->attr("swapcase")()); -} - -str str::title() const -{ - return assume_str(this->attr("title")()); -} - -str str::translate(object_cref table) const -{ - return assume_str(this->attr("translate")(table)); -} - -str str::translate(object_cref table, object_cref deletechars) const -{ - return assume_str(this->attr("translate")(table,deletechars)); -} - -str str::upper() const -{ - return assume_str(this->attr("upper")()); -} - -}} // namespace boost::python +}}} // namespace boost::python diff --git a/src/tuple.cpp b/src/tuple.cpp index 16b8e773..2762ab27 100644 --- a/src/tuple.cpp +++ b/src/tuple.cpp @@ -1,20 +1,20 @@ #include -namespace boost { namespace python { +namespace boost { namespace python { namespace detail { -detail::new_reference tuple::call(object const& arg_) +detail::new_reference tuple_base::call(object const& arg_) { return (detail::new_reference)PyObject_CallFunction( (PyObject*)&PyTuple_Type, "(O)", arg_.ptr()); } -tuple::tuple() +tuple_base::tuple_base() : object(detail::new_reference(PyTuple_New(0))) {} -tuple::tuple(object_cref sequence) - : object(tuple::call(sequence)) +tuple_base::tuple_base(object_cref sequence) + : object(call(sequence)) {} -}} // namespace boost::python +}}} // namespace boost::python diff --git a/test/Jamfile b/test/Jamfile index 6e305b42..de63e575 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -1,3 +1,7 @@ +# +# To run all tests quietly: jam test +# To run all tests with verbose output: jam -sPYTHON_TEST_ARGS=-v test +# subproject libs/python/test ; # bring in the rules for python @@ -7,9 +11,6 @@ include python.jam ; SEARCH on testing.jam = $(BOOST_BUILD_PATH) ; include testing.jam ; -local PYTHON_V1_PROPERTIES = $(PYTHON_PROPERTIES) ; -local PYTHON_PROPERTIES = $(BOOST_PYTHON_V2_PROPERTIES) ; - # Convenience rule makes declaring tests faster rule bpl-test ( name ? : files * : requirements * ) { @@ -46,7 +47,7 @@ rule bpl-test ( name ? : files * : requirements * ) m = $(m)_ext ; } } - extension $(m) : $(f) ../bpl : $(requirements) ; + extension $(m) : $(f) ../build/boost_python : $(requirements) ; modules += $(m) ; } } diff --git a/test/args.cpp b/test/args.cpp index ee79fcfa..281ca236 100644 --- a/test/args.cpp +++ b/test/args.cpp @@ -3,11 +3,12 @@ // 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. -#include +#include #include #include #include #include +#include #include #include "test_class.hpp" @@ -38,7 +39,7 @@ struct X BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_f_overloads, X::f, 0, 3) -BOOST_PYTHON_MODULE_INIT(args_ext) +BOOST_PYTHON_MODULE(args_ext) { def("f", f, args("x", "y", "z") , "This is f's docstring" diff --git a/test/back_reference.cpp b/test/back_reference.cpp index d5ae5ece..75233c6b 100644 --- a/test/back_reference.cpp +++ b/test/back_reference.cpp @@ -4,7 +4,7 @@ // "as is" without express or implied warranty, and with no claim as // to its suitability for any purpose. #include -#include +#include #include #include #include @@ -87,7 +87,7 @@ bool y_equality(back_reference y1, Y const& y2) return &y1.get() == &y2; } -BOOST_PYTHON_MODULE_INIT(back_reference_ext) +BOOST_PYTHON_MODULE(back_reference_ext) { def("copy_Y", copy_Y, return_value_policy()); def("copy_Z", copy_Z, return_value_policy()); diff --git a/test/bienstman1.cpp b/test/bienstman1.cpp index b4acf059..7f1736e0 100644 --- a/test/bienstman1.cpp +++ b/test/bienstman1.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -18,7 +18,7 @@ struct V const A* outside(const V& v) {return &v.a;} -BOOST_PYTHON_MODULE_INIT(bienstman1_ext) +BOOST_PYTHON_MODULE(bienstman1_ext) { using namespace boost::python; using boost::shared_ptr; diff --git a/test/bienstman2.cpp b/test/bienstman2.cpp index 7e4f951c..94f2a8c3 100644 --- a/test/bienstman2.cpp +++ b/test/bienstman2.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -15,7 +15,7 @@ struct E const D fe2(const C&, const C&) {return D();} }; -BOOST_PYTHON_MODULE_INIT(bienstman2_ext) +BOOST_PYTHON_MODULE(bienstman2_ext) { using namespace boost::python; diff --git a/test/bienstman3.cpp b/test/bienstman3.cpp index 22c7638e..9248ef8f 100644 --- a/test/bienstman3.cpp +++ b/test/bienstman3.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -12,7 +12,7 @@ struct B B(const V&) {} }; -BOOST_PYTHON_MODULE_INIT(bienstman3_ext) +BOOST_PYTHON_MODULE(bienstman3_ext) { using namespace boost::python; diff --git a/test/bienstman4.cpp b/test/bienstman4.cpp index ee510f2d..124d76a5 100644 --- a/test/bienstman4.cpp +++ b/test/bienstman4.cpp @@ -4,7 +4,7 @@ // "as is" without express or implied warranty, and with no claim as // to its suitability for any purpose. -#include +#include #include #include #include @@ -16,7 +16,7 @@ struct Term {Term(Type1 const&) {} }; struct Expression {void add(Term const&) {} }; -BOOST_PYTHON_MODULE_INIT(bienstman4_ext) +BOOST_PYTHON_MODULE(bienstman4_ext) { using namespace boost::python; using boost::mpl::list; diff --git a/test/bienstman5.cpp b/test/bienstman5.cpp index 75fbd8da..72875663 100644 --- a/test/bienstman5.cpp +++ b/test/bienstman5.cpp @@ -4,7 +4,7 @@ // "as is" without express or implied warranty, and with no claim as // to its suitability for any purpose. -#include +#include #include #include #include @@ -13,7 +13,7 @@ struct M {M(const std::complex&) {} }; -BOOST_PYTHON_MODULE_INIT(bienstman5_ext) +BOOST_PYTHON_MODULE(bienstman5_ext) { using namespace boost::python; diff --git a/test/callbacks.cpp b/test/callbacks.cpp index 763dcda8..036c532a 100644 --- a/test/callbacks.cpp +++ b/test/callbacks.cpp @@ -3,7 +3,7 @@ // 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. -#include +#include #include //#include #include @@ -113,7 +113,7 @@ object apply_object_object(PyObject* f, object x) int X::counter; -BOOST_PYTHON_MODULE_INIT(callbacks_ext) +BOOST_PYTHON_MODULE(callbacks_ext) { def("apply_object_object", apply_object_object); def("apply_to_own_type", apply_to_own_type); diff --git a/test/cltree.cpp b/test/cltree.cpp index f7ea9eeb..099d5cb7 100755 --- a/test/cltree.cpp +++ b/test/cltree.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -49,7 +49,7 @@ public: }; -BOOST_PYTHON_MODULE_INIT(cltree) +BOOST_PYTHON_MODULE(cltree) { boost::python::class_("basic") .def("__repr__",&basic::repr) diff --git a/test/comprehensive.cpp b/test/comprehensive.cpp index be638066..e3a756b9 100644 --- a/test/comprehensive.cpp +++ b/test/comprehensive.cpp @@ -1196,7 +1196,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) +BOOST_PYTHON_MODULE(boost_python_test) { boost::python::module_builder boost_python_test("boost_python_test"); init_module(boost_python_test); diff --git a/test/data_members.cpp b/test/data_members.cpp index 7a05d359..2345634a 100644 --- a/test/data_members.cpp +++ b/test/data_members.cpp @@ -4,7 +4,7 @@ // "as is" without express or implied warranty, and with no claim as // to its suitability for any purpose. #include -#include +#include #include "test_class.hpp" #if defined(_AIX) && defined(__EDG_VERSION__) && __EDG_VERSION__ < 245 @@ -20,7 +20,7 @@ typedef test_class<1> Y; double get_fair_value(X const& x) { return x.value(); } -BOOST_PYTHON_MODULE_INIT(data_members_ext) +BOOST_PYTHON_MODULE(data_members_ext) { class_("X", init()) .def("value", &X::value) diff --git a/test/defaults.cpp b/test/defaults.cpp index 41341e72..1c173a79 100644 --- a/test/defaults.cpp +++ b/test/defaults.cpp @@ -5,11 +5,11 @@ // to its suitability for any purpose. #include -#include +#include #include #include #include -#include +#include #include #if defined(_AIX) && defined(__EDG_VERSION__) && __EDG_VERSION__ < 245 @@ -147,17 +147,11 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_foo_3_stubs, foo, 2, 3) /////////////////////////////////////////////////////////////////////////////// -BOOST_PYTHON_MODULE_INIT(defaults_ext) +BOOST_PYTHON_MODULE(defaults_ext) { def("foo", foo, foo_stubs()); def("bar", (object(*)(int, char, std::string, double))0, bar_stubs()); - // Show that this works with the old obsolete module version of def(). - module("defaults_ext") - .def("foobar", foo, foo_stubs()) - .def("barfoo", (object(*)(int, char, std::string, double))0, bar_stubs()) - ; - class_("Y", init<>("doc of Y init")) // this should work .def("get_state", &Y::get_state) ; diff --git a/test/defaults.py b/test/defaults.py index ee7a6588..168c5de3 100644 --- a/test/defaults.py +++ b/test/defaults.py @@ -1,4 +1,6 @@ """ +>>> False = 0 # Python 2.2 needs these +>>> True = 1 >>> from defaults_ext import * >>> bar(1) diff --git a/test/dict.cpp b/test/dict.cpp index 0850c6be..538c7930 100644 --- a/test/dict.cpp +++ b/test/dict.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -68,7 +68,7 @@ void test_templates(object print) //print(tmp[3]); } -BOOST_PYTHON_MODULE_INIT(dict_ext) +BOOST_PYTHON_MODULE(dict_ext) { def("new_dict", new_dict); def("data_dict", data_dict); diff --git a/test/docstring.cpp b/test/docstring.cpp index 417a6635..65893d02 100644 --- a/test/docstring.cpp +++ b/test/docstring.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -30,7 +30,7 @@ unsigned long fact(unsigned long n) return n <= 1 ? n : n * fact(n - 1); } -BOOST_PYTHON_MODULE_INIT(docstring_ext) +BOOST_PYTHON_MODULE(docstring_ext) { scope().attr("__doc__") = "A simple test module for documentation strings\n" diff --git a/test/doctest.py b/test/doctest.py deleted file mode 100644 index 2829f1e6..00000000 --- a/test/doctest.py +++ /dev/null @@ -1,1173 +0,0 @@ -# Module doctest. -# Released to the public domain 16-Jan-2001, -# by Tim Peters (tim.one@home.com). - -# Provided as-is; use at your own risk; no warranty; no promises; enjoy! - -"""Module doctest -- a framework for running examples in docstrings. - -NORMAL USAGE - -In normal use, end each module M with: - -def _test(): - import doctest, M # replace M with your module's name - return doctest.testmod(M) # ditto - -if __name__ == "__main__": - _test() - -Then running the module as a script will cause the examples in the -docstrings to get executed and verified: - -python M.py - -This won't display anything unless an example fails, in which case the -failing example(s) and the cause(s) of the failure(s) are printed to stdout -(why not stderr? because stderr is a lame hack <0.2 wink>), and the final -line of output is "Test failed.". - -Run it with the -v switch instead: - -python M.py -v - -and a detailed report of all examples tried is printed to stdout, along -with assorted summaries at the end. - -You can force verbose mode by passing "verbose=1" to testmod, or prohibit -it by passing "verbose=0". In either of those cases, sys.argv is not -examined by testmod. - -In any case, testmod returns a 2-tuple of ints (f, t), where f is the -number of docstring examples that failed and t is the total number of -docstring examples attempted. - - -WHICH DOCSTRINGS ARE EXAMINED? - -+ M.__doc__. - -+ f.__doc__ for all functions f in M.__dict__.values(), except those - with private names and those defined in other modules. - -+ C.__doc__ for all classes C in M.__dict__.values(), except those with - private names and those defined in other modules. - -+ If M.__test__ exists and "is true", it must be a dict, and - each entry maps a (string) name to a function object, class object, or - string. Function and class object docstrings found from M.__test__ - are searched even if the name is private, and strings are searched - directly as if they were docstrings. In output, a key K in M.__test__ - appears with name - .__test__.K - -Any classes found are recursively searched similarly, to test docstrings in -their contained methods and nested classes. Private names reached from M's -globals are skipped, but all names reached from M.__test__ are searched. - -By default, a name is considered to be private if it begins with an -underscore (like "_my_func") but doesn't both begin and end with (at least) -two underscores (like "__init__"). You can change the default by passing -your own "isprivate" function to testmod. - -If you want to test docstrings in objects with private names too, stuff -them into an M.__test__ dict, or see ADVANCED USAGE below (e.g., pass your -own isprivate function to Tester's constructor, or call the rundoc method -of a Tester instance). - -WHAT'S THE EXECUTION CONTEXT? - -By default, each time testmod finds a docstring to test, it uses a *copy* -of M's globals (so that running tests on a module doesn't change the -module's real globals, and so that one test in M can't leave behind crumbs -that accidentally allow another test to work). This means examples can -freely use any names defined at top-level in M. It also means that sloppy -imports (see above) can cause examples in external docstrings to use -globals inappropriate for them. - -You can force use of your own dict as the execution context by passing -"globs=your_dict" to testmod instead. Presumably this would be a copy of -M.__dict__ merged with the globals from other imported modules. - - -WHAT IF I WANT TO TEST A WHOLE PACKAGE? - -Piece o' cake, provided the modules do their testing from docstrings. -Here's the test.py I use for the world's most elaborate Rational/ -floating-base-conversion pkg (which I'll distribute some day): - -from Rational import Cvt -from Rational import Format -from Rational import machprec -from Rational import Rat -from Rational import Round -from Rational import utils - -modules = (Cvt, - Format, - machprec, - Rat, - Round, - utils) - -def _test(): - import doctest - import sys - verbose = "-v" in sys.argv - for mod in modules: - doctest.testmod(mod, verbose=verbose, report=0) - doctest.master.summarize() - -if __name__ == "__main__": - _test() - -IOW, it just runs testmod on all the pkg modules. testmod remembers the -names and outcomes (# of failures, # of tries) for each item it's seen, and -passing "report=0" prevents it from printing a summary in verbose mode. -Instead, the summary is delayed until all modules have been tested, and -then "doctest.master.summarize()" forces the summary at the end. - -So this is very nice in practice: each module can be tested individually -with almost no work beyond writing up docstring examples, and collections -of modules can be tested too as a unit with no more work than the above. - - -WHAT ABOUT EXCEPTIONS? - -No problem, as long as the only output generated by the example is the -traceback itself. For example: - - >>> [1, 2, 3].remove(42) - Traceback (most recent call last): - File "", line 1, in ? - ValueError: list.remove(x): x not in list - >>> - -Note that only the exception type and value are compared (specifically, -only the last line in the traceback). - - -ADVANCED USAGE - -doctest.testmod() captures the testing policy I find most useful most -often. You may want other policies. - -testmod() actually creates a local instance of class doctest.Tester, runs -appropriate methods of that class, and merges the results into global -Tester instance doctest.master. - -You can create your own instances of doctest.Tester, and so build your own -policies, or even run methods of doctest.master directly. See -doctest.Tester.__doc__ for details. - - -SO WHAT DOES A DOCSTRING EXAMPLE LOOK LIKE ALREADY!? - -Oh ya. It's easy! In most cases a copy-and-paste of an interactive -console session works fine -- just make sure the leading whitespace is -rigidly consistent (you can mix tabs and spaces if you're too lazy to do it -right, but doctest is not in the business of guessing what you think a tab -means). - - >>> # comments are ignored - >>> x = 12 - >>> x - 12 - >>> if x == 13: - ... print "yes" - ... else: - ... print "no" - ... print "NO" - ... print "NO!!!" - ... - no - NO - NO!!! - >>> - -Any expected output must immediately follow the final ">>>" or "..." line -containing the code, and the expected output (if any) extends to the next -">>>" or all-whitespace line. That's it. - -Bummers: - -+ Expected output cannot contain an all-whitespace line, since such a line - is taken to signal the end of expected output. - -+ Output to stdout is captured, but not output to stderr (exception - tracebacks are captured via a different means). - -+ If you continue a line via backslashing in an interactive session, or for - any other reason use a backslash, you need to double the backslash in the - docstring version. This is simply because you're in a string, and so the - backslash must be escaped for it to survive intact. Like: - ->>> if "yes" == \\ -... "y" + \\ -... "es": # in the source code you'll see the doubled backslashes -... print 'yes' -yes - -The starting column doesn't matter: - ->>> assert "Easy!" - >>> import math - >>> math.floor(1.9) - 1.0 - -and as many leading whitespace characters are stripped from the expected -output as appeared in the initial ">>>" line that triggered it. - -If you execute this very file, the examples above will be found and -executed, leading to this output in verbose mode: - -Running doctest.__doc__ -Trying: [1, 2, 3].remove(42) -Expecting: -Traceback (most recent call last): - File "", line 1, in ? -ValueError: list.remove(x): x not in list -ok -Trying: x = 12 -Expecting: nothing -ok -Trying: x -Expecting: 12 -ok -Trying: -if x == 13: - print "yes" -else: - print "no" - print "NO" - print "NO!!!" -Expecting: -no -NO -NO!!! -ok -... and a bunch more like that, with this summary at the end: - -5 items had no tests: - doctest.Tester.__init__ - doctest.Tester.run__test__ - doctest.Tester.summarize - doctest.run_docstring_examples - doctest.testmod -12 items passed all tests: - 8 tests in doctest - 6 tests in doctest.Tester - 10 tests in doctest.Tester.merge - 14 tests in doctest.Tester.rundict - 3 tests in doctest.Tester.rundoc - 3 tests in doctest.Tester.runstring - 2 tests in doctest.__test__._TestClass - 2 tests in doctest.__test__._TestClass.__init__ - 2 tests in doctest.__test__._TestClass.get - 1 tests in doctest.__test__._TestClass.square - 2 tests in doctest.__test__.string - 7 tests in doctest.is_private -60 tests in 17 items. -60 passed and 0 failed. -Test passed. -""" - -__all__ = [ - 'testmod', - 'run_docstring_examples', - 'is_private', - 'Tester', -] - -import __future__ - -import re -PS1 = ">>>" -PS2 = "..." -_isPS1 = re.compile(r"(\s*)" + re.escape(PS1)).match -_isPS2 = re.compile(r"(\s*)" + re.escape(PS2)).match -_isEmpty = re.compile(r"\s*$").match -_isComment = re.compile(r"\s*#").match -del re - -from types import StringTypes as _StringTypes - -from inspect import isclass as _isclass -from inspect import isfunction as _isfunction -from inspect import ismodule as _ismodule -from inspect import classify_class_attrs as _classify_class_attrs - -# Extract interactive examples from a string. Return a list of triples, -# (source, outcome, lineno). "source" is the source code, and ends -# with a newline iff the source spans more than one line. "outcome" is -# the expected output if any, else an empty string. When not empty, -# outcome always ends with a newline. "lineno" is the line number, -# 0-based wrt the start of the string, of the first source line. - -def _extract_examples(s): - isPS1, isPS2 = _isPS1, _isPS2 - isEmpty, isComment = _isEmpty, _isComment - examples = [] - lines = s.split("\n") - i, n = 0, len(lines) - while i < n: - line = lines[i] - i = i + 1 - m = isPS1(line) - if m is None: - continue - j = m.end(0) # beyond the prompt - if isEmpty(line, j) or isComment(line, j): - # a bare prompt or comment -- not interesting - continue - lineno = i - 1 - if line[j] != " ": - raise ValueError("line " + `lineno` + " of docstring lacks " - "blank after " + PS1 + ": " + line) - j = j + 1 - blanks = m.group(1) - nblanks = len(blanks) - # suck up this and following PS2 lines - source = [] - while 1: - source.append(line[j:]) - line = lines[i] - m = isPS2(line) - if m: - if m.group(1) != blanks: - raise ValueError("inconsistent leading whitespace " - "in line " + `i` + " of docstring: " + line) - i = i + 1 - else: - break - if len(source) == 1: - source = source[0] - else: - # get rid of useless null line from trailing empty "..." - if source[-1] == "": - del source[-1] - source = "\n".join(source) + "\n" - # suck up response - if isPS1(line) or isEmpty(line): - expect = "" - else: - expect = [] - while 1: - if line[:nblanks] != blanks: - raise ValueError("inconsistent leading whitespace " - "in line " + `i` + " of docstring: " + line) - expect.append(line[nblanks:]) - i = i + 1 - line = lines[i] - if isPS1(line) or isEmpty(line): - break - expect = "\n".join(expect) + "\n" - examples.append( (source, expect, lineno) ) - return examples - -# Capture stdout when running examples. - -class _SpoofOut: - def __init__(self): - self.clear() - def write(self, s): - self.buf.append(s) - def get(self): - guts = "".join(self.buf) - # If anything at all was written, make sure there's a trailing - # newline. There's no way for the expected output to indicate - # that a trailing newline is missing. - if guts and not guts.endswith("\n"): - guts = guts + "\n" - # Prevent softspace from screwing up the next test case, in - # case they used print with a trailing comma in an example. - if hasattr(self, "softspace"): - del self.softspace - return guts - def clear(self): - self.buf = [] - if hasattr(self, "softspace"): - del self.softspace - def flush(self): - # JPython calls flush - pass - -# Display some tag-and-msg pairs nicely, keeping the tag and its msg -# on the same line when that makes sense. - -def _tag_out(printer, *tag_msg_pairs): - for tag, msg in tag_msg_pairs: - printer(tag + ":") - msg_has_nl = msg[-1:] == "\n" - msg_has_two_nl = msg_has_nl and \ - msg.find("\n") < len(msg) - 1 - if len(tag) + len(msg) < 76 and not msg_has_two_nl: - printer(" ") - else: - printer("\n") - printer(msg) - if not msg_has_nl: - printer("\n") - -# Run list of examples, in context globs. "out" can be used to display -# stuff to "the real" stdout, and fakeout is an instance of _SpoofOut -# that captures the examples' std output. Return (#failures, #tries). - -def _run_examples_inner(out, fakeout, examples, globs, verbose, name, - compileflags): - import sys, traceback - OK, BOOM, FAIL = range(3) - NADA = "nothing" - stderr = _SpoofOut() - failures = 0 - for source, want, lineno in examples: - if verbose: - _tag_out(out, ("Trying", source), - ("Expecting", want or NADA)) - fakeout.clear() - try: - exec compile(source, "", "single", - compileflags, 1) in globs - got = fakeout.get() - state = OK - except: - # See whether the exception was expected. - if want.find("Traceback (innermost last):\n") == 0 or \ - want.find("Traceback (most recent call last):\n") == 0: - # Only compare exception type and value - the rest of - # the traceback isn't necessary. - want = want.split('\n')[-2] + '\n' - exc_type, exc_val = sys.exc_info()[:2] - got = traceback.format_exception_only(exc_type, exc_val)[-1] - state = OK - else: - # unexpected exception - stderr.clear() - traceback.print_exc(file=stderr) - state = BOOM - - if state == OK: - if got == want: - if verbose: - out("ok\n") - continue - state = FAIL - - assert state in (FAIL, BOOM) - failures = failures + 1 - out("*" * 65 + "\n") - _tag_out(out, ("Failure in example", source)) - out("from line #" + `lineno` + " of " + name + "\n") - if state == FAIL: - _tag_out(out, ("Expected", want or NADA), ("Got", got)) - else: - assert state == BOOM - _tag_out(out, ("Exception raised", stderr.get())) - - return failures, len(examples) - -# Get the future-flags associated with the future features that have been -# imported into globs. - -def _extract_future_flags(globs): - flags = 0 - for fname in __future__.all_feature_names: - feature = globs.get(fname, None) - if feature is getattr(__future__, fname): - flags |= feature.compiler_flag - return flags - -# Run list of examples, in a shallow copy of context (dict) globs. -# Return (#failures, #tries). - -def _run_examples(examples, globs, verbose, name, compileflags): - import sys - saveout = sys.stdout - globs = globs.copy() - try: - sys.stdout = fakeout = _SpoofOut() - x = _run_examples_inner(saveout.write, fakeout, examples, - globs, verbose, name, compileflags) - finally: - sys.stdout = saveout - # While Python gc can clean up most cycles on its own, it doesn't - # chase frame objects. This is especially irksome when running - # generator tests that raise exceptions, because a named generator- - # iterator gets an entry in globs, and the generator-iterator - # object's frame's traceback info points back to globs. This is - # easy to break just by clearing the namespace. This can also - # help to break other kinds of cycles, and even for cycles that - # gc can break itself it's better to break them ASAP. - globs.clear() - return x - -def run_docstring_examples(f, globs, verbose=0, name="NoName", - compileflags=None): - """f, globs, verbose=0, name="NoName" -> run examples from f.__doc__. - - Use (a shallow copy of) dict globs as the globals for execution. - Return (#failures, #tries). - - If optional arg verbose is true, print stuff even if there are no - failures. - Use string name in failure msgs. - """ - - try: - doc = f.__doc__ - if not doc: - # docstring empty or None - return 0, 0 - # just in case CT invents a doc object that has to be forced - # to look like a string <0.9 wink> - doc = str(doc) - except: - return 0, 0 - - e = _extract_examples(doc) - if not e: - return 0, 0 - if compileflags is None: - compileflags = _extract_future_flags(globs) - return _run_examples(e, globs, verbose, name, compileflags) - -def is_private(prefix, base): - """prefix, base -> true iff name prefix + "." + base is "private". - - Prefix may be an empty string, and base does not contain a period. - Prefix is ignored (although functions you write conforming to this - protocol may make use of it). - Return true iff base begins with an (at least one) underscore, but - does not both begin and end with (at least) two underscores. - - >>> is_private("a.b", "my_func") - 0 - >>> is_private("____", "_my_func") - 1 - >>> is_private("someclass", "__init__") - 0 - >>> is_private("sometypo", "__init_") - 1 - >>> is_private("x.y.z", "_") - 1 - >>> is_private("_x.y.z", "__") - 0 - >>> is_private("", "") # senseless but consistent - 0 - """ - - return base[:1] == "_" and not base[:2] == "__" == base[-2:] - -# Determine if a class of function was defined in the given module. - -def _from_module(module, object): - if _isfunction(object): - return module.__dict__ is object.func_globals - if _isclass(object): - return module.__name__ == object.__module__ - raise ValueError("object must be a class or function") - -class Tester: - """Class Tester -- runs docstring examples and accumulates stats. - -In normal use, function doctest.testmod() hides all this from you, -so use that if you can. Create your own instances of Tester to do -fancier things. - -Methods: - runstring(s, name) - Search string s for examples to run; use name for logging. - Return (#failures, #tries). - - rundoc(object, name=None) - Search object.__doc__ for examples to run; use name (or - object.__name__) for logging. Return (#failures, #tries). - - rundict(d, name, module=None) - Search for examples in docstrings in all of d.values(); use name - for logging. Exclude functions and classes not defined in module - if specified. Return (#failures, #tries). - - run__test__(d, name) - Treat dict d like module.__test__. Return (#failures, #tries). - - summarize(verbose=None) - Display summary of testing results, to stdout. Return - (#failures, #tries). - - merge(other) - Merge in the test results from Tester instance "other". - ->>> from doctest import Tester ->>> t = Tester(globs={'x': 42}, verbose=0) ->>> t.runstring(r''' -... >>> x = x * 2 -... >>> print x -... 42 -... ''', 'XYZ') -***************************************************************** -Failure in example: print x -from line #2 of XYZ -Expected: 42 -Got: 84 -(1, 2) ->>> t.runstring(">>> x = x * 2\\n>>> print x\\n84\\n", 'example2') -(0, 2) ->>> t.summarize() -***************************************************************** -1 items had failures: - 1 of 2 in XYZ -***Test Failed*** 1 failures. -(1, 4) ->>> t.summarize(verbose=1) -1 items passed all tests: - 2 tests in example2 -***************************************************************** -1 items had failures: - 1 of 2 in XYZ -4 tests in 2 items. -3 passed and 1 failed. -***Test Failed*** 1 failures. -(1, 4) ->>> -""" - - def __init__(self, mod=None, globs=None, verbose=None, - isprivate=None): - """mod=None, globs=None, verbose=None, isprivate=None - -See doctest.__doc__ for an overview. - -Optional keyword arg "mod" is a module, whose globals are used for -executing examples. If not specified, globs must be specified. - -Optional keyword arg "globs" gives a dict to be used as the globals -when executing examples; if not specified, use the globals from -module mod. - -In either case, a copy of the dict is used for each docstring -examined. - -Optional keyword arg "verbose" prints lots of stuff if true, only -failures if false; by default, it's true iff "-v" is in sys.argv. - -Optional keyword arg "isprivate" specifies a function used to determine -whether a name is private. The default function is doctest.is_private; -see its docs for details. -""" - - if mod is None and globs is None: - raise TypeError("Tester.__init__: must specify mod or globs") - if mod is not None and not _ismodule(mod): - raise TypeError("Tester.__init__: mod must be a module; " + - `mod`) - if globs is None: - globs = mod.__dict__ - self.globs = globs - - if verbose is None: - import sys - verbose = "-v" in sys.argv - self.verbose = verbose - - if isprivate is None: - isprivate = is_private - self.isprivate = isprivate - - self.name2ft = {} # map name to (#failures, #trials) pair - - self.compileflags = _extract_future_flags(globs) - - def runstring(self, s, name): - """ - s, name -> search string s for examples to run, logging as name. - - Use string name as the key for logging the outcome. - Return (#failures, #examples). - - >>> t = Tester(globs={}, verbose=1) - >>> test = r''' - ... # just an example - ... >>> x = 1 + 2 - ... >>> x - ... 3 - ... ''' - >>> t.runstring(test, "Example") - Running string Example - Trying: x = 1 + 2 - Expecting: nothing - ok - Trying: x - Expecting: 3 - ok - 0 of 2 examples failed in string Example - (0, 2) - """ - - if self.verbose: - print "Running string", name - f = t = 0 - e = _extract_examples(s) - if e: - f, t = _run_examples(e, self.globs, self.verbose, name, - self.compileflags) - if self.verbose: - print f, "of", t, "examples failed in string", name - self.__record_outcome(name, f, t) - return f, t - - def rundoc(self, object, name=None): - """ - object, name=None -> search object.__doc__ for examples to run. - - Use optional string name as the key for logging the outcome; - by default use object.__name__. - Return (#failures, #examples). - If object is a class object, search recursively for method - docstrings too. - object.__doc__ is examined regardless of name, but if object is - a class, whether private names reached from object are searched - depends on the constructor's "isprivate" argument. - - >>> t = Tester(globs={}, verbose=0) - >>> def _f(): - ... '''Trivial docstring example. - ... >>> assert 2 == 2 - ... ''' - ... return 32 - ... - >>> t.rundoc(_f) # expect 0 failures in 1 example - (0, 1) - """ - - if name is None: - try: - name = object.__name__ - except AttributeError: - raise ValueError("Tester.rundoc: name must be given " - "when object.__name__ doesn't exist; " + `object`) - if self.verbose: - print "Running", name + ".__doc__" - f, t = run_docstring_examples(object, self.globs, self.verbose, name, - self.compileflags) - if self.verbose: - print f, "of", t, "examples failed in", name + ".__doc__" - self.__record_outcome(name, f, t) - if _isclass(object): - # In 2.2, class and static methods complicate life. Build - # a dict "that works", by hook or by crook. - d = {} - for tag, kind, homecls, value in _classify_class_attrs(object): - - if homecls is not object: - # Only look at names defined immediately by the class. - continue - - elif self.isprivate(name, tag): - continue - - elif kind == "method": - # value is already a function - d[tag] = value - - elif kind == "static method": - # value isn't a function, but getattr reveals one - d[tag] = getattr(object, tag) - - elif kind == "class method": - # Hmm. A classmethod object doesn't seem to reveal - # enough. But getattr turns it into a bound method, - # and from there .im_func retrieves the underlying - # function. - d[tag] = getattr(object, tag).im_func - - elif kind == "property": - # The methods implementing the property have their - # own docstrings -- but the property may have one too. - if value.__doc__ is not None: - d[tag] = str(value.__doc__) - - elif kind == "data": - # Grab nested classes. - if _isclass(value): - d[tag] = value - - else: - raise ValueError("teach doctest about %r" % kind) - - f2, t2 = self.run__test__(d, name) - f += f2 - t += t2 - - return f, t - - def rundict(self, d, name, module=None): - """ - d, name, module=None -> search for docstring examples in d.values(). - - For k, v in d.items() such that v is a function or class, - do self.rundoc(v, name + "." + k). Whether this includes - objects with private names depends on the constructor's - "isprivate" argument. If module is specified, functions and - classes that are not defined in module are excluded. - Return aggregate (#failures, #examples). - - Build and populate two modules with sample functions to test that - exclusion of external functions and classes works. - - >>> import new - >>> m1 = new.module('_m1') - >>> m2 = new.module('_m2') - >>> test_data = \""" - ... def _f(): - ... '''>>> assert 1 == 1 - ... ''' - ... def g(): - ... '''>>> assert 2 != 1 - ... ''' - ... class H: - ... '''>>> assert 2 > 1 - ... ''' - ... def bar(self): - ... '''>>> assert 1 < 2 - ... ''' - ... \""" - >>> exec test_data in m1.__dict__ - >>> exec test_data in m2.__dict__ - >>> m1.__dict__.update({"f2": m2._f, "g2": m2.g, "h2": m2.H}) - - Tests that objects outside m1 are excluded: - - >>> t = Tester(globs={}, verbose=0) - >>> t.rundict(m1.__dict__, "rundict_test", m1) # _f, f2 and g2 and h2 skipped - (0, 3) - - Again, but with a custom isprivate function allowing _f: - - >>> t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0) - >>> t.rundict(m1.__dict__, "rundict_test_pvt", m1) # Only f2, g2 and h2 skipped - (0, 4) - - And once more, not excluding stuff outside m1: - - >>> t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0) - >>> t.rundict(m1.__dict__, "rundict_test_pvt") # None are skipped. - (0, 8) - - The exclusion of objects from outside the designated module is - meant to be invoked automagically by testmod. - - >>> testmod(m1) - (0, 3) - - """ - - if not hasattr(d, "items"): - raise TypeError("Tester.rundict: d must support .items(); " + - `d`) - f = t = 0 - # Run the tests by alpha order of names, for consistency in - # verbose-mode output. - names = d.keys() - names.sort() - for thisname in names: - value = d[thisname] - if _isfunction(value) or _isclass(value): - if module and not _from_module(module, value): - continue - f2, t2 = self.__runone(value, name + "." + thisname) - f = f + f2 - t = t + t2 - return f, t - - def run__test__(self, d, name): - """d, name -> Treat dict d like module.__test__. - - Return (#failures, #tries). - See testmod.__doc__ for details. - """ - - failures = tries = 0 - prefix = name + "." - savepvt = self.isprivate - try: - self.isprivate = lambda *args: 0 - # Run the tests by alpha order of names, for consistency in - # verbose-mode output. - keys = d.keys() - keys.sort() - for k in keys: - v = d[k] - thisname = prefix + k - if type(v) in _StringTypes: - f, t = self.runstring(v, thisname) - elif _isfunction(v) or _isclass(v): - f, t = self.rundoc(v, thisname) - else: - raise TypeError("Tester.run__test__: values in " - "dict must be strings, functions " - "or classes; " + `v`) - failures = failures + f - tries = tries + t - finally: - self.isprivate = savepvt - return failures, tries - - def summarize(self, verbose=None): - """ - verbose=None -> summarize results, return (#failures, #tests). - - Print summary of test results to stdout. - Optional arg 'verbose' controls how wordy this is. By - default, use the verbose setting established by the - constructor. - """ - - if verbose is None: - verbose = self.verbose - notests = [] - passed = [] - failed = [] - totalt = totalf = 0 - for x in self.name2ft.items(): - name, (f, t) = x - assert f <= t - totalt = totalt + t - totalf = totalf + f - if t == 0: - notests.append(name) - elif f == 0: - passed.append( (name, t) ) - else: - failed.append(x) - if verbose: - if notests: - print len(notests), "items had no tests:" - notests.sort() - for thing in notests: - print " ", thing - if passed: - print len(passed), "items passed all tests:" - passed.sort() - for thing, count in passed: - print " %3d tests in %s" % (count, thing) - if failed: - print "*" * 65 - print len(failed), "items had failures:" - failed.sort() - for thing, (f, t) in failed: - print " %3d of %3d in %s" % (f, t, thing) - if verbose: - print totalt, "tests in", len(self.name2ft), "items." - print totalt - totalf, "passed and", totalf, "failed." - if totalf: - print "***Test Failed***", totalf, "failures." - elif verbose: - print "Test passed." - return totalf, totalt - - def merge(self, other): - """ - other -> merge in test results from the other Tester instance. - - If self and other both have a test result for something - with the same name, the (#failures, #tests) results are - summed, and a warning is printed to stdout. - - >>> from doctest import Tester - >>> t1 = Tester(globs={}, verbose=0) - >>> t1.runstring(''' - ... >>> x = 12 - ... >>> print x - ... 12 - ... ''', "t1example") - (0, 2) - >>> - >>> t2 = Tester(globs={}, verbose=0) - >>> t2.runstring(''' - ... >>> x = 13 - ... >>> print x - ... 13 - ... ''', "t2example") - (0, 2) - >>> common = ">>> assert 1 + 2 == 3\\n" - >>> t1.runstring(common, "common") - (0, 1) - >>> t2.runstring(common, "common") - (0, 1) - >>> t1.merge(t2) - *** Tester.merge: 'common' in both testers; summing outcomes. - >>> t1.summarize(1) - 3 items passed all tests: - 2 tests in common - 2 tests in t1example - 2 tests in t2example - 6 tests in 3 items. - 6 passed and 0 failed. - Test passed. - (0, 6) - >>> - """ - - d = self.name2ft - for name, (f, t) in other.name2ft.items(): - if d.has_key(name): - print "*** Tester.merge: '" + name + "' in both" \ - " testers; summing outcomes." - f2, t2 = d[name] - f = f + f2 - t = t + t2 - d[name] = f, t - - def __record_outcome(self, name, f, t): - if self.name2ft.has_key(name): - print "*** Warning: '" + name + "' was tested before;", \ - "summing outcomes." - f2, t2 = self.name2ft[name] - f = f + f2 - t = t + t2 - self.name2ft[name] = f, t - - def __runone(self, target, name): - if "." in name: - i = name.rindex(".") - prefix, base = name[:i], name[i+1:] - else: - prefix, base = "", base - if self.isprivate(prefix, base): - return 0, 0 - return self.rundoc(target, name) - -master = None - -def testmod(m, name=None, globs=None, verbose=None, isprivate=None, - report=1): - """m, name=None, globs=None, verbose=None, isprivate=None, report=1 - - Test examples in docstrings in functions and classes reachable from - module m, starting with m.__doc__. Private names are skipped. - - Also test examples reachable from dict m.__test__ if it exists and is - not None. m.__dict__ maps names to functions, classes and strings; - function and class docstrings are tested even if the name is private; - strings are tested directly, as if they were docstrings. - - Return (#failures, #tests). - - See doctest.__doc__ for an overview. - - Optional keyword arg "name" gives the name of the module; by default - use m.__name__. - - Optional keyword arg "globs" gives a dict to be used as the globals - when executing examples; by default, use m.__dict__. A copy of this - dict is actually used for each docstring, so that each docstring's - examples start with a clean slate. - - Optional keyword arg "verbose" prints lots of stuff if true, prints - only failures if false; by default, it's true iff "-v" is in sys.argv. - - Optional keyword arg "isprivate" specifies a function used to - determine whether a name is private. The default function is - doctest.is_private; see its docs for details. - - Optional keyword arg "report" prints a summary at the end when true, - else prints nothing at the end. In verbose mode, the summary is - detailed, else very brief (in fact, empty if all tests passed). - - Advanced tomfoolery: testmod runs methods of a local instance of - class doctest.Tester, then merges the results into (or creates) - global Tester instance doctest.master. Methods of doctest.master - can be called directly too, if you want to do something unusual. - Passing report=0 to testmod is especially useful then, to delay - displaying a summary. Invoke doctest.master.summarize(verbose) - when you're done fiddling. - """ - - global master - - if not _ismodule(m): - raise TypeError("testmod: module required; " + `m`) - if name is None: - name = m.__name__ - tester = Tester(m, globs=globs, verbose=verbose, isprivate=isprivate) - failures, tries = tester.rundoc(m, name) - f, t = tester.rundict(m.__dict__, name, m) - failures = failures + f - tries = tries + t - if hasattr(m, "__test__"): - testdict = m.__test__ - if testdict: - if not hasattr(testdict, "items"): - raise TypeError("testmod: module.__test__ must support " - ".items(); " + `testdict`) - f, t = tester.run__test__(testdict, name + ".__test__") - failures = failures + f - tries = tries + t - if report: - tester.summarize() - if master is None: - master = tester - else: - master.merge(tester) - return failures, tries - -class _TestClass: - """ - A pointless class, for sanity-checking of docstring testing. - - Methods: - square() - get() - - >>> _TestClass(13).get() + _TestClass(-12).get() - 1 - >>> hex(_TestClass(13).square().get()) - '0xa9' - """ - - def __init__(self, val): - """val -> _TestClass object with associated value val. - - >>> t = _TestClass(123) - >>> print t.get() - 123 - """ - - self.val = val - - def square(self): - """square() -> square TestClass's associated value - - >>> _TestClass(13).square().get() - 169 - """ - - self.val = self.val ** 2 - return self - - def get(self): - """get() -> return TestClass's associated value. - - >>> x = _TestClass(-42) - >>> print x.get() - -42 - """ - - return self.val - -__test__ = {"_TestClass": _TestClass, - "string": r""" - Example of a string object, searched as-is. - >>> x = 1; y = 2 - >>> x + y, x * y - (3, 2) - """ - } - -def _test(): - import doctest - return doctest.testmod(doctest) - -if __name__ == "__main__": - _test() diff --git a/test/enum.cpp b/test/enum.cpp index d6147bc0..b0dd02ae 100644 --- a/test/enum.cpp +++ b/test/enum.cpp @@ -5,7 +5,7 @@ // to its suitability for any purpose. #include #include -#include +#include using namespace boost::python; @@ -13,7 +13,7 @@ enum color { red = 1, green = 2, blue = 4 }; color identity_(color x) { return x; } -BOOST_PYTHON_MODULE_INIT(enum_ext) +BOOST_PYTHON_MODULE(enum_ext) { enum_("color") .value("red", red) diff --git a/test/exception_translator.cpp b/test/exception_translator.cpp index 8a6428fd..f9c38ab9 100644 --- a/test/exception_translator.cpp +++ b/test/exception_translator.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -15,7 +15,7 @@ void throw_error() } -BOOST_PYTHON_MODULE_INIT(exception_translator_ext) +BOOST_PYTHON_MODULE(exception_translator_ext) { using namespace boost::python; register_exception_translator(&translate); diff --git a/test/extract.cpp b/test/extract.cpp index 2faa27e9..a7749043 100644 --- a/test/extract.cpp +++ b/test/extract.cpp @@ -7,7 +7,7 @@ #include "test_class.hpp" #include #include -#include +#include #include #include #include @@ -96,7 +96,7 @@ std::string x_rep(X const& x) return "X(" + boost::lexical_cast(x.value()) + ")"; } -BOOST_PYTHON_MODULE_INIT(extract_ext) +BOOST_PYTHON_MODULE(extract_ext) { implicitly_convertible(); diff --git a/test/implicit.cpp b/test/implicit.cpp index 2637f5ca..b56e6b10 100644 --- a/test/implicit.cpp +++ b/test/implicit.cpp @@ -5,7 +5,7 @@ // to its suitability for any purpose. #include #include -#include +#include #include #include "test_class.hpp" @@ -20,7 +20,7 @@ int x_value(X const& x) X make_x(int n) { return X(n); } -BOOST_PYTHON_MODULE_INIT(implicit_ext) +BOOST_PYTHON_MODULE(implicit_ext) { implicitly_convertible(); diff --git a/test/input_iterator.cpp b/test/input_iterator.cpp index 19b50f77..eacae455 100644 --- a/test/input_iterator.cpp +++ b/test/input_iterator.cpp @@ -3,7 +3,7 @@ // 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. -#include +#include #include #include #include @@ -35,7 +35,7 @@ list_range2 range2(list_int& x) // to work around an MSVC6 linker bug, which causes it to complain // about a "duplicate comdat" if the input iterator is instantiated in // the same module with the others. -BOOST_PYTHON_MODULE_INIT(input_iterator) +BOOST_PYTHON_MODULE(input_iterator) { def("range2", &::range2); diff --git a/test/iterator.cpp b/test/iterator.cpp index 02e67546..93d4c009 100644 --- a/test/iterator.cpp +++ b/test/iterator.cpp @@ -3,7 +3,7 @@ // 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. -#include +#include #include #include #include @@ -77,7 +77,7 @@ private: list_int two; }; -BOOST_PYTHON_MODULE_INIT(iterator_ext) +BOOST_PYTHON_MODULE(iterator_ext) { def("range", &::range); diff --git a/test/list.cpp b/test/list.cpp index 83ea063b..15871e6a 100644 --- a/test/list.cpp +++ b/test/list.cpp @@ -4,7 +4,7 @@ // "as is" without express or implied warranty, and with no claim as // to its suitability for any purpose. -#include +#include #include #include #include @@ -125,7 +125,7 @@ void exercise(list x, object y, object print) assert(w[3] == 'i'); } -BOOST_PYTHON_MODULE_INIT(list_ext) +BOOST_PYTHON_MODULE(list_ext) { def("new_list", new_list); def("listify", listify); diff --git a/test/long.cpp b/test/long.cpp index 32d3164a..cc619987 100644 --- a/test/long.cpp +++ b/test/long.cpp @@ -4,7 +4,7 @@ // "as is" without express or implied warranty, and with no claim as // to its suitability for any purpose. -#include +#include #include #include #include @@ -39,7 +39,7 @@ int is_long2(char const*) return 0; } -BOOST_PYTHON_MODULE_INIT(long_ext) +BOOST_PYTHON_MODULE(long_ext) { def("new_long", new_long); def("longify", longify); diff --git a/test/m1.cpp b/test/m1.cpp index 122ad04d..60498d2a 100644 --- a/test/m1.cpp +++ b/test/m1.cpp @@ -8,7 +8,7 @@ #include "simple_type.hpp" #include "complicated.hpp" #include -#include +#include #include #include #include @@ -199,7 +199,7 @@ D take_d_shared_ptr(boost::shared_ptr d) { return *d; } boost::shared_ptr d_factory() { return boost::shared_ptr(new D); } -BOOST_PYTHON_MODULE_INIT(m1) +BOOST_PYTHON_MODULE(m1) { using namespace boost::python; using boost::shared_ptr; diff --git a/test/m2.cpp b/test/m2.cpp index 5eee1a89..3108b2de 100644 --- a/test/m2.cpp +++ b/test/m2.cpp @@ -7,7 +7,7 @@ // This module exercises the converters exposed in m1 at a low level // by exposing raw Python extension functions that use wrap<> and // unwrap<> objects. -#include +#include #include #include #include @@ -61,7 +61,7 @@ struct rewrap static T f(T x) { return x; } }; -BOOST_PYTHON_MODULE_INIT(m2) +BOOST_PYTHON_MODULE(m2) { using boost::python::return_value_policy; using boost::python::copy_const_reference; diff --git a/test/minimal.cpp b/test/minimal.cpp index be0fe6ec..ac6fb4ae 100644 --- a/test/minimal.cpp +++ b/test/minimal.cpp @@ -3,14 +3,14 @@ // 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. -#include +#include #include #if defined(_AIX) && defined(__EDG_VERSION__) && __EDG_VERSION__ < 245 # include // works around a KCC intermediate code generation bug #endif -BOOST_PYTHON_MODULE_INIT(minimal_ext) +BOOST_PYTHON_MODULE(minimal_ext) { } diff --git a/test/multi_arg_constructor.cpp b/test/multi_arg_constructor.cpp index 24bc4d9a..d80f57ab 100644 --- a/test/multi_arg_constructor.cpp +++ b/test/multi_arg_constructor.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -10,7 +10,7 @@ struct A ) {} }; -BOOST_PYTHON_MODULE_INIT(multi_arg_constructor_ext) +BOOST_PYTHON_MODULE(multi_arg_constructor_ext) { using namespace boost::python; using boost::shared_ptr; diff --git a/test/nested.cpp b/test/nested.cpp index 8cbe3d79..12fd7bb1 100644 --- a/test/nested.cpp +++ b/test/nested.cpp @@ -3,7 +3,7 @@ // 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. -#include +#include #include #include #include @@ -28,7 +28,7 @@ std::ostream& operator<<(std::ostream& s, Y const& x) } -BOOST_PYTHON_MODULE_INIT(nested_ext) +BOOST_PYTHON_MODULE(nested_ext) { using namespace boost::python; diff --git a/test/numpy.cpp b/test/numpy.cpp index 36b9e070..8a02f6ee 100644 --- a/test/numpy.cpp +++ b/test/numpy.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include using namespace boost::python; @@ -92,7 +92,7 @@ void exercise_numarray(numeric::array& y, object check) check(y.factory(make_tuple(1.2, 3.4), "Double", make_tuple(2), true, true)); } -BOOST_PYTHON_MODULE_INIT(numpy_ext) +BOOST_PYTHON_MODULE(numpy_ext) { def("new_array", new_array); def("take_array", take_array); diff --git a/test/object.cpp b/test/object.cpp index 6a76aeb3..bf702099 100755 --- a/test/object.cpp +++ b/test/object.cpp @@ -3,7 +3,7 @@ // 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. -#include +#include #include #include @@ -279,7 +279,7 @@ bool check_inplace(object l, object o) return true; } -BOOST_PYTHON_MODULE_INIT(object_ext) +BOOST_PYTHON_MODULE(object_ext) { def("call_object_3", call_object_3); def("message", message); diff --git a/test/operators.cpp b/test/operators.cpp index dc2313df..e4ac1e07 100755 --- a/test/operators.cpp +++ b/test/operators.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include "test_class.hpp" #if __GNUC__ != 2 @@ -57,7 +57,7 @@ std::ostream& operator<<(std::ostream& s, X const& x) return s << x.value(); } -BOOST_PYTHON_MODULE_INIT(operators_ext) +BOOST_PYTHON_MODULE(operators_ext) { class_("X", init()) .def("value", &X::value) diff --git a/test/pickle1.cpp b/test/pickle1.cpp index 1f9e5139..794799f8 100644 --- a/test/pickle1.cpp +++ b/test/pickle1.cpp @@ -10,7 +10,7 @@ For more information refer to boost/libs/python/doc/pickle.html. */ -#include +#include #include #include #include @@ -45,7 +45,7 @@ namespace { } -BOOST_PYTHON_MODULE_INIT(pickle1_ext) +BOOST_PYTHON_MODULE(pickle1_ext) { using namespace boost::python; class_("world", init()) diff --git a/test/pickle2.cpp b/test/pickle2.cpp index b8aacbd7..99401973 100644 --- a/test/pickle2.cpp +++ b/test/pickle2.cpp @@ -22,7 +22,7 @@ #include -#include +#include #include #include #include @@ -87,7 +87,7 @@ namespace { // Avoid cluttering the global namespace. } -BOOST_PYTHON_MODULE_INIT(pickle2_ext) +BOOST_PYTHON_MODULE(pickle2_ext) { boost::python::class_( "world", boost::python::init()) diff --git a/test/pickle3.cpp b/test/pickle3.cpp index 5fae9e6c..8f243d39 100644 --- a/test/pickle3.cpp +++ b/test/pickle3.cpp @@ -17,7 +17,7 @@ #include -#include +#include #include #include #include @@ -95,7 +95,7 @@ namespace { // Avoid cluttering the global namespace. } -BOOST_PYTHON_MODULE_INIT(pickle3_ext) +BOOST_PYTHON_MODULE(pickle3_ext) { boost::python::class_( "world", boost::python::init()) diff --git a/test/str.cpp b/test/str.cpp index 646f8676..e0252a17 100644 --- a/test/str.cpp +++ b/test/str.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -59,7 +59,7 @@ void work_with_string(object print) } -BOOST_PYTHON_MODULE_INIT(str_ext) +BOOST_PYTHON_MODULE(str_ext) { def("convert_to_string",convert_to_string); def("work_with_string",work_with_string); diff --git a/test/submod_subclass_api.cpp b/test/submod_subclass_api.cpp index b2c5293e..e716aaf0 100644 --- a/test/submod_subclass_api.cpp +++ b/test/submod_subclass_api.cpp @@ -110,7 +110,7 @@ struct main_args { int python_main(main_args const &ma); // python module init -BOOST_PYTHON_MODULE_INIT(python_main) +BOOST_PYTHON_MODULE(python_main) { DEF(python_main); CLASS(main_args); @@ -121,7 +121,7 @@ namespace sm { int test_func() { return 7; } -BOOST_PYTHON_MODULE_INIT(sm_test) +BOOST_PYTHON_MODULE(sm_test) { // define a submodule boost::python::module(".sm"); @@ -160,7 +160,7 @@ c1::c2 test_func() { return c1().t; } -BOOST_PYTHON_MODULE_INIT(sc_test) +BOOST_PYTHON_MODULE(sc_test) { class_("c1.c2") .def_init() diff --git a/test/test_builtin_converters.cpp b/test/test_builtin_converters.cpp index 912f2dc5..917a468a 100644 --- a/test/test_builtin_converters.cpp +++ b/test/test_builtin_converters.cpp @@ -4,7 +4,7 @@ // "as is" without express or implied warranty, and with no claim as // to its suitability for any purpose. #include -#include +#include #include #include #include @@ -57,7 +57,7 @@ handle<> return_null_handle() char const* rewrap_value_mutable_cstring(char* x) { return x; } -BOOST_PYTHON_MODULE_INIT(builtin_converters) +BOOST_PYTHON_MODULE(builtin_converters) { def("get_type", get_type); def("return_null_handle", return_null_handle); diff --git a/test/test_pointer_adoption.cpp b/test/test_pointer_adoption.cpp index 90b39ea7..6631d8ea 100644 --- a/test/test_pointer_adoption.cpp +++ b/test/test_pointer_adoption.cpp @@ -3,7 +3,7 @@ // 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. -#include +#include #include #include #include @@ -87,7 +87,7 @@ A* as_A(Base* b) return dynamic_cast(b); } -BOOST_PYTHON_MODULE_INIT(test_pointer_adoption_ext) +BOOST_PYTHON_MODULE(test_pointer_adoption_ext) { def("num_a_instances", num_a_instances); diff --git a/test/tuple.cpp b/test/tuple.cpp index d5569185..fce3da85 100644 --- a/test/tuple.cpp +++ b/test/tuple.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -19,7 +19,7 @@ tuple mktuple0() { return make_tuple(); } tuple mktuple1(int x) { return make_tuple(x); } tuple mktuple2(char const* a1, int x) { return make_tuple(a1, x); } -BOOST_PYTHON_MODULE_INIT(tuple_ext) +BOOST_PYTHON_MODULE(tuple_ext) { def("convert_to_tuple",convert_to_tuple); def("test_operators",test_operators); diff --git a/test/virtual_functions.cpp b/test/virtual_functions.cpp index f0bfd787..92a6e78c 100644 --- a/test/virtual_functions.cpp +++ b/test/virtual_functions.cpp @@ -4,7 +4,7 @@ // "as is" without express or implied warranty, and with no claim as // to its suitability for any purpose. #include -#include +#include #include #include #include @@ -87,7 +87,7 @@ struct concrete_callback : concrete int X::counter; -BOOST_PYTHON_MODULE_INIT(virtual_functions_ext) +BOOST_PYTHON_MODULE(virtual_functions_ext) { class_("concrete", init()) .def("value", &concrete::value)