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

Compare commits

...

13 Commits

Author SHA1 Message Date
nobody
81e4c87688 This commit was manufactured by cvs2svn to create tag
'Version_1_26_0'.

[SVN r11842]
2001-11-30 18:24:42 +00:00
Dave Abrahams
0dbb780a2f * Updated to new handle_exception() idiom for boost::python
* Made Cygwin archiving reliable, even when the user supplies a path with backslashes

----------------------------------------------------------------------

Modified Files:
	tools/build/gcc-tools.jam tools/build/new/boost-build.jam
	boost/python/detail/config.hpp libs/python/build/Jamfile
	libs/python/example/do_it_yourself_convts.cpp
	libs/python/example/dvect.cpp libs/python/example/example1.cpp
	libs/python/example/getting_started1.cpp
	libs/python/example/getting_started2.cpp
	libs/python/example/ivect.cpp libs/python/example/nested.cpp
	libs/python/example/noncopyable_export.cpp
	libs/python/example/noncopyable_import.cpp
	libs/python/example/pickle1.cpp
	libs/python/example/pickle2.cpp
	libs/python/example/pickle3.cpp
	libs/python/example/richcmp1.cpp
	libs/python/example/richcmp2.cpp
	libs/python/example/richcmp3.cpp libs/python/example/rwgk1.cpp
	libs/python/example/simple_vector.cpp
	libs/python/test/comprehensive.cpp
Added Files:
	libs/python/example/rwgk2.cpp libs/python/example/rwgk3.cpp
----------------------------------------------------------------------


[SVN r11705]
2001-11-15 05:29:22 +00:00
Dave Abrahams
e6efa6e13e Fix minor gcc bug
[SVN r11704]
2001-11-15 00:51:33 +00:00
Dave Abrahams
76768120d4 use the new "no-rethrow" way of handling exceptions.
[SVN r11692]
2001-11-14 20:36:14 +00:00
Dave Abrahams
7d6ff83760 use the new "no-rethrow" way of handling exceptions.
[SVN r11691]
2001-11-14 20:07:38 +00:00
Dave Abrahams
5bec0d2d98 fixes for intel
[SVN r11690]
2001-11-14 20:06:18 +00:00
Dave Abrahams
aad05325a6 Pro7 compatibility
use the new "no-rethrow" way of handling exceptions.


[SVN r11682]
2001-11-14 19:50:35 +00:00
Dave Abrahams
6e7f1bc257 Pro7 compatibility
[SVN r11681]
2001-11-14 17:41:17 +00:00
Dave Abrahams
634d0848c8 got rid of the "rethrow error reporting" mechanism
[SVN r11680]
2001-11-14 17:37:07 +00:00
Dave Abrahams
b7e1059227 initial checkin
[SVN r11679]
2001-11-14 17:35:18 +00:00
Dave Abrahams
e7904fa67a add _d targets for debugging
[SVN r11678]
2001-11-14 17:32:08 +00:00
Dave Abrahams
e38bc7cbce Pro7 compatibility
[SVN r11677]
2001-11-14 17:26:11 +00:00
Dave Abrahams
b211f8a096 Modified Files:
index.htm - fixed reference to CVS repository
	libs/python/build/Jamfile - first stab at metrowerks Pro7 support
	status/Jamfile - added RUN_ALL_TESTS variables to force tests to run
	tools/build/boost-build.jam - fix BOOST_BUILD_INSTALLATION setting
	tools/build/metrowerks-tools.jam - command file support
	tools/build/msvc-tools.jam - permanent command file support
	tools/build/intel-win32-tools.jam - made it an extension of msvc-tools.jam
	tools/build/gcc-tools.jam  - made FINDLIBS change submitted by Toon Knapen
	tools/build/jam_src/variable.c - changed command-line/env. variable
					interpretation so that
					surrounding them with quotes causes
					no breaking at spaces.

These files were converted from tabs to spaces:

	boost/python/conversions.hpp
	boost/python/reference.hpp boost/python/detail/base_object.hpp
	boost/python/detail/functions.hpp
	boost/python/detail/wrap_python.hpp libs/python/test/comprehensive.cpp
	tools/build/boost-base.jam
	tools/build/como-tools.jam


[SVN r11652]
2001-11-10 22:16:01 +00:00
35 changed files with 545 additions and 359 deletions

View File

@@ -73,12 +73,13 @@ if $(NT)
PYTHON_ROOT ?= c:/tools/python ;
PYTHON_INCLUDES ?= <include>$(PYTHON_ROOT)/include <gcc><*><include>/usr/include/python$(PYTHON_VERSION) ;
PYTHON_LIBS ?= c:/cygnus/lib/python$(PYTHON_VERSION)/config/libpython$(PYTHON_VERSION).dll.a ;
PYTHON_LIB_PATH = $(PYTHON_ROOT)/libs ;
PYTHON_LIB_PATH ?= $(PYTHON_ROOT)/libs ;
# common properties required for compiling any Python module.
PYTHON_PROPERTIES ?=
<gcc><*><define>SIZEOF_LONG=4
<gcc><*><define>USE_DL_IMPORT
<debug><define>_DEBUG
<runtime-link>dynamic
;
@@ -90,6 +91,10 @@ else if $(UNIX)
PYTHON_LIBS ?= /usr/lib/python$(PYTHON_VERSION)/config/libpython$(PYTHON_VERSION).a ;
}
local PYTHON_VERSION_NODOT
= [ SUBST $(PYTHON_VERSION) ([0-9]*)\.([0-9]*) $1$2 ]
;
# how do we invoke python?
local PYTHON = $(PYTHON) ;
PYTHON ?= python ;
@@ -107,14 +112,22 @@ local BOOST_PYTHON_INCLUDES = <include>$(BOOST_ROOT) $(PYTHON_INCLUDES) ;
# Base names of the source files for libboost_python
local CPP_SOURCES =
classes conversions extension_class functions
init_function module_builder objects types cross_module ;
types classes conversions extension_class functions
init_function module_builder objects cross_module ;
lib libboost_python : ../src/$(CPP_SOURCES).cpp
# requirements
: $(BOOST_PYTHON_INCLUDES)
<shared-linkable>true
$(PYTHON_PROPERTIES) ;
lib libboost_python_d : ../src/$(CPP_SOURCES).cpp
# requirements
: $(BOOST_PYTHON_INCLUDES)
<shared-linkable>true
$(PYTHON_PROPERTIES)
<define>BOOST_DEBUG_PYTHON
;
#######################
@@ -123,8 +136,14 @@ lib libboost_python : ../src/$(CPP_SOURCES).cpp
# Declare a boost python module. Return a list of the DLL files generated.
rule boost-python
{
local debug = "" ;
if ( <define>BOOST_DEBUG_PYTHON in $(3) ) || ( debug-python in $(BUILD) )
{
debug = _d ;
}
# declare a DLL; add the boost python library to sources
dll $(<) : <lib>libboost_python $(>)
dll $(<) : <lib>libboost_python$(debug) $(>)
# Requirements
: $(3) # caller-specified requirements
@@ -132,6 +151,8 @@ rule boost-python
# standard requirements
$(BOOST_PYTHON_INCLUDES)
<msvc><*><library-path>$(PYTHON_LIB_PATH)
<intel-win32><*><library-path>$(PYTHON_LIB_PATH)
<metrowerks><*><library-file>$(PYTHON_LIB_PATH)/python$(PYTHON_VERSION_NODOT)$(debug).lib
<gcc><*><library-file>$(PYTHON_LIBS)
$(PYTHON_PROPERTIES)
@@ -145,9 +166,12 @@ rule boost-python
rule boost-python-test
{
type-DEPENDS test : $(<) ;
type-DEPENDS test_d : $(<)_d ;
NOTFILE test_d ;
local gSUPPRESS_FAKE_TARGETS = true ;
boost-python $(1) : $(2) : $(3) : $(4) ;
boost-python $(1)_d : $(2) : $(3) <define>BOOST_DEBUG_PYTHON : $(4) ;
}
#######################
@@ -179,7 +203,9 @@ rule python-test-target # test-target : sources :
{
python-runtest-aux $(<) : $(>) ;
Clean clean : $(<) ; # remove the test-target as part of any clean operation
type-DEPENDS test : $(<) ;
local debug = [ SUBST $(<:B) (_d)$ $1 ] ;
debug ?= "" ;
type-DEPENDS test$(debug) : $(<) ;
MakeLocate $(<) : $(LOCATE_TARGET) ;
}
actions python-test-target bind PYTHON
@@ -216,6 +242,7 @@ rule python-runtest-aux # target : sources
switch $(<)
{
case <*\\\\msvc\\\\*>* : ARGS on $(<) += --broken-auto-ptr ;
case <*\\\\intel-win32\\\\*>* : ARGS on $(<) += --broken-auto-ptr ;
}
# compute the PYTHONPATH environment variable that will allow the test to
@@ -224,6 +251,7 @@ rule python-runtest-aux # target : sources
$(gLOCATE($(>[1]))) # location of python test file
$(gRUN_PATH($(<))) # location of module dependencies
[ join-path $(TOP) libs python test ] # location of doctest
$(>:D) # directory of python driver file(s)
$(PYTHONPATH) # base PYTHONPATH from environment
: $(SPLITPATH) ] ; # platform path separator
@@ -238,12 +266,17 @@ boost-python-runtest comprehensive
: [ join-path $(DOTDOT) test comprehensive.py ]
<lib>boost_python_test ;
boost-python-runtest comprehensive_d
: [ join-path $(DOTDOT) test comprehensive.py ]
<lib>boost_python_test_d ;
############# simple tests from ../example ############
rule boost-python-example-runtest
{
boost-python-test $(<) : ../example/$(<).cpp ;
boost-python-runtest $(<) : [ join-path $(DOTDOT) example test_$(<).py ] <lib>$(<) ;
boost-python-runtest $(<)_d : [ join-path $(DOTDOT) example test_$(<).py ] <lib>$(<)_d ;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -32,13 +32,6 @@ namespace {
BOOST_PYTHON_MODULE_INIT(nested)
{
try
{
boost::python::module_builder this_module("nested");
this_module.def(show_nested_tuples, "show_nested_tuples");
}
catch(...)
{
boost::python::handle_exception();
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

50
example/rwgk2.cpp Normal file
View File

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

101
example/rwgk3.cpp Normal file
View File

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

View File

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

View File

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

View File

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

View File

@@ -48,7 +48,7 @@ base_object<PythonType>::base_object(PyTypeObject* type_obj)
#if !defined(_MSC_VER) || defined(__STLPORT)
std::
#endif
memset(bp, 0, sizeof(base_python_type));
memset(bp, 0, sizeof(base_python_type));
Py_INCREF(type_obj);
PyObject_INIT(bp, type_obj);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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