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

Compare commits

..

10 Commits

Author SHA1 Message Date
Ralf W. Grosse-Kunstleve
7dcb0b1996 struct lookup_tag {}; to_python(x, lookup_tag());
[SVN r10226]
2001-05-25 17:07:07 +00:00
Ralf W. Grosse-Kunstleve
de57613c7e gen_extension_class.py script updated.
[SVN r10223]
2001-05-24 20:28:34 +00:00
Ralf W. Grosse-Kunstleve
ade195b9ac BOOST_NO_FRIEND_KOENIG_LOOKUP for vc60, tru64_cxx, irix_CC, linux_gcc
[SVN r10219]
2001-05-24 17:55:28 +00:00
Jens Maurer
daf0865cdf add -fPIC
[SVN r10216]
2001-05-24 10:45:38 +00:00
Jens Maurer
2fa4bb7410 std::vector<> iterators are not necessarily pointers
[SVN r10215]
2001-05-24 10:42:37 +00:00
Ralf W. Grosse-Kunstleve
6db04861ed fixes tested with vc60, tru64cxx, irixCC, gcc2952
[SVN r10211]
2001-05-24 09:02:13 +00:00
Ralf W. Grosse-Kunstleve
dac8e861c8 fixes tested with vc60, tru64cxx, irixCC, gcc2952
[SVN r10208]
2001-05-24 08:28:46 +00:00
Ralf W. Grosse-Kunstleve
f0a0e9ec02 fixes tested with vc60, tru64cxx, irixCC, gcc2952
[SVN r10207]
2001-05-24 07:50:00 +00:00
Dave Abrahams
4d3079293d Initial attempt to fix problems
[SVN r10158]
2001-05-19 23:29:04 +00:00
nobody
9261e2a3d9 This commit was manufactured by cvs2svn to create branch
'boost_python_friend_fixes'.

[SVN r10123]
2001-05-18 15:12:31 +00:00
68 changed files with 734 additions and 1861 deletions

View File

@@ -52,13 +52,6 @@ bpl_exa + "/tst_dvect2.py",
bpl_exa + "/tst_ivect1.py",
bpl_exa + "/tst_ivect2.py",
bpl_exa + "/test_cross_module.py",
bpl_exa + "/vector_wrapper.h",
bpl_exa + "/richcmp1.cpp",
bpl_exa + "/richcmp2.cpp",
bpl_exa + "/richcmp3.cpp",
bpl_exa + "/test_richcmp1.py",
bpl_exa + "/test_richcmp2.py",
bpl_exa + "/test_richcmp3.py",
)
defs = (
@@ -75,9 +68,6 @@ defs = (
"noncopyable_import",
"ivect",
"dvect",
"richcmp1",
"richcmp2",
"richcmp3",
)
if (__name__ == "__main__"):

View File

@@ -19,8 +19,8 @@ BOOST=$(ROOT)/boost
PYEXE=/usr/local/Python-1.5.2/bin/python
PYINC=-I/usr/local/Python-1.5.2/include/python1.5
#PYEXE=/usr/local/Python-2.1/bin/python
#PYINC=-I/usr/local/Python-2.1/include/python2.1
#PYEXE=/usr/local/Python-2.0/bin/python
#PYINC=-I/usr/local/Python-2.0/include/python2.0
STLPORTINC=-I$(BOOST)/boost/compatibility/cpp_c_headers
STDOPTS=
@@ -46,8 +46,7 @@ DEPOBJ=$(OBJ) \
do_it_yourself_converters.o \
pickle1.o pickle2.o pickle3.o \
noncopyable_export.o noncopyable_import.o \
ivect.o dvect.o \
richcmp1.o richcmp2.o richcmp3.o
ivect.o dvect.o
.SUFFIXES: .o .cpp
@@ -59,8 +58,7 @@ all: libboost_python.a \
do_it_yourself_converters.so \
pickle1.so pickle2.so pickle3.so \
noncopyable_export.so noncopyable_import.so \
ivect.so dvect.so \
richcmp1.so richcmp2.so richcmp3.so
ivect.so dvect.so
libboost_python.a: $(OBJ)
rm -f libboost_python.a
@@ -107,15 +105,6 @@ ivect.so: $(OBJ) ivect.o
dvect.so: $(OBJ) dvect.o
$(LD) $(LDOPTS) $(OBJ) $(HIDDEN) dvect.o -o dvect.so
richcmp1.so: $(OBJ) richcmp1.o
$(LD) $(LDOPTS) $(OBJ) richcmp1.o -o richcmp1.so
richcmp2.so: $(OBJ) richcmp2.o
$(LD) $(LDOPTS) $(OBJ) richcmp2.o -o richcmp2.so
richcmp3.so: $(OBJ) richcmp3.o
$(LD) $(LDOPTS) $(OBJ) richcmp3.o -o richcmp3.so
.cpp.o:
$(CPP) $(CPPOPTS) -c $*.cpp
@@ -130,9 +119,6 @@ test:
$(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
@@ -149,9 +135,6 @@ clean:
rm -f noncopyable_import.o noncopyable_import.so
rm -f ivect.o ivect.so
rm -f dvect.o dvect.so
rm -f richcmp1.o richcmp1.so
rm -f richcmp2.o richcmp2.so
rm -f richcmp3.o richcmp3.so
rm -f so_locations *.pyc
rm -rf ii_files

View File

@@ -21,10 +21,10 @@ PYEXE=PYTHONPATH=. /usr/bin/python
PYINC=-I/usr/include/python1.5
#PYEXE=/usr/local/Python-1.5.2/bin/python
#PYINC=-I/usr/local/Python-1.5.2/include/python1.5
#PYEXE=/usr/local/Python-2.1/bin/python
#PYINC=-I/usr/local/Python-2.1/include/python2.1
#PYEXE=/usr/local/Python-2.0/bin/python
#PYINC=-I/usr/local/Python-2.0/include/python2.0
STDOPTS=-fPIC -ftemplate-depth-21
STDOPTS=-ftemplate-depth-21 -fPIC
WARNOPTS=
OPTOPTS=-g
@@ -47,8 +47,7 @@ DEPOBJ=$(OBJ) \
do_it_yourself_converters.o \
pickle1.o pickle2.o pickle3.o \
noncopyable_export.o noncopyable_import.o \
ivect.o dvect.o \
richcmp1.o richcmp2.o richcmp3.o
ivect.o dvect.o
.SUFFIXES: .o .cpp
@@ -60,8 +59,7 @@ all: libboost_python.a \
do_it_yourself_converters.so \
pickle1.so pickle2.so pickle3.so \
noncopyable_export.so noncopyable_import.so \
ivect.so dvect.so \
richcmp1.so richcmp2.so richcmp3.so
ivect.so dvect.so
libboost_python.a: $(OBJ)
rm -f libboost_python.a
@@ -108,15 +106,6 @@ ivect.so: $(OBJ) ivect.o
dvect.so: $(OBJ) dvect.o
$(LD) $(LDOPTS) $(OBJ) $(HIDDEN) dvect.o -o dvect.so
richcmp1.so: $(OBJ) richcmp1.o
$(LD) $(LDOPTS) $(OBJ) richcmp1.o -o richcmp1.so
richcmp2.so: $(OBJ) richcmp2.o
$(LD) $(LDOPTS) $(OBJ) richcmp2.o -o richcmp2.so
richcmp3.so: $(OBJ) richcmp3.o
$(LD) $(LDOPTS) $(OBJ) richcmp3.o -o richcmp3.so
.cpp.o:
$(CPP) $(CPPOPTS) -c $*.cpp
@@ -131,9 +120,6 @@ test:
$(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
@@ -150,9 +136,6 @@ clean:
rm -f noncopyable_import.o noncopyable_import.so
rm -f ivect.o ivect.so
rm -f dvect.o dvect.so
rm -f richcmp1.o richcmp1.so
rm -f richcmp2.o richcmp2.so
rm -f richcmp3.o richcmp3.so
rm -f so_locations *.pyc
softlinks:

View File

@@ -62,11 +62,10 @@ all: libboost_python.a \
do_it_yourself_converters.pyd \
pickle1.pyd pickle2.pyd pickle3.pyd \
noncopyable_export.pyd noncopyable_import.pyd \
ivect.pyd dvect.pyd \
richcmp1.pyd richcmp2.pyd richcmp3.pyd
ivect.pyd dvect.pyd
libboost_python.a: $(OBJ)
-del libboost_python.a
del libboost_python.a
ar r libboost_python.a $(OBJ)
DLLWRAPOPTS=-s --driver-name g++ -s \
@@ -150,24 +149,6 @@ dvect.pyd: $(OBJ) dvect.o
--def dvect.def \
$(OBJ) dvect.o $(PYLIB)
richcmp1.pyd: $(OBJ) richcmp1.o
dllwrap $(DLLWRAPOPTS) \
--dllname richcmp1.pyd \
--def richcmp1.def \
$(OBJ) richcmp1.o $(PYLIB)
richcmp2.pyd: $(OBJ) richcmp2.o
dllwrap $(DLLWRAPOPTS) \
--dllname richcmp2.pyd \
--def richcmp2.def \
$(OBJ) richcmp2.o $(PYLIB)
richcmp3.pyd: $(OBJ) richcmp3.o
dllwrap $(DLLWRAPOPTS) \
--dllname richcmp3.pyd \
--def richcmp3.def \
$(OBJ) richcmp3.o $(PYLIB)
.cpp.o:
$(CPP) $(CPPOPTS) -c $*.cpp
@@ -182,15 +163,12 @@ test:
$(PYEXE) test_pickle2.py
$(PYEXE) test_pickle3.py
$(PYEXE) test_cross_module.py
$(PYEXE) test_richcmp1.py
$(PYEXE) test_richcmp2.py
$(PYEXE) test_richcmp3.py
clean:
-del *.o
-del *.a
-del *.pyd
-del *.pyc
del *.o
del *.a
del *.pyd
del *.pyc
softlinks:
python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) softlinks

View File

@@ -19,8 +19,8 @@ BOOST=$(ROOT)/boost
PYEXE=/usr/local/Python-1.5.2/bin/python
PYINC=-I/usr/local/Python-1.5.2/include/python1.5
#PYEXE=/usr/local/Python-2.1/bin/python
#PYINC=-I/usr/local/Python-2.1/include/python2.1
#PYEXE=/usr/local/Python-2.0/bin/python
#PYINC=-I/usr/local/Python-2.0/include/python2.0
#STLPORTINC=-I/usr/local/STLport-4.1b3/stlport
#STLPORTINC=-I/usr/local/STLport-4.1b4/stlport
#STLPORTOPTS= \
@@ -57,8 +57,7 @@ DEPOBJ=$(OBJ) \
do_it_yourself_converters.o \
pickle1.o pickle2.o pickle3.o \
noncopyable_export.o noncopyable_import.o \
ivect.o dvect.o \
richcmp1.o richcmp2.o richcmp3.o
ivect.o dvect.o
.SUFFIXES: .o .cpp
@@ -70,8 +69,7 @@ all: libboost_python.a \
do_it_yourself_converters.so \
pickle1.so pickle2.so pickle3.so \
noncopyable_export.so noncopyable_import.so \
ivect.so dvect.so \
richcmp1.so richcmp2.so richcmp3.so
ivect.so dvect.so
libboost_python.a: $(OBJ)
rm -f libboost_python.a
@@ -122,15 +120,6 @@ ivect.so: $(OBJ) ivect.o
dvect.so: $(OBJ) dvect.o
$(LD) $(LDOPTS) $(OBJ) $(HIDDEN) dvect.o -o dvect.so
richcmp1.so: $(OBJ) richcmp1.o
$(LD) $(LDOPTS) $(OBJ) richcmp1.o -o richcmp1.so
richcmp2.so: $(OBJ) richcmp2.o
$(LD) $(LDOPTS) $(OBJ) richcmp2.o -o richcmp2.so
richcmp3.so: $(OBJ) richcmp3.o
$(LD) $(LDOPTS) $(OBJ) richcmp3.o -o richcmp3.so
.cpp.o:
$(CPP) $(CPPOPTS) -c $*.cpp
@@ -145,9 +134,6 @@ test:
$(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
@@ -164,9 +150,6 @@ clean:
rm -f noncopyable_import.o noncopyable_import.so
rm -f ivect.o ivect.so
rm -f dvect.o dvect.so
rm -f richcmp1.o richcmp1.so
rm -f richcmp2.o richcmp2.so
rm -f richcmp3.o richcmp3.so
rm -f so_locations *.pyc
rm -rf cxx_repository

View File

@@ -17,9 +17,6 @@ BOOST_UNIX=$(HOME)/boost
PYEXE="C:\Program files\Python\python.exe"
PYINC=/I"C:\Program files\Python\include"
PYLIB="C:\Program files\Python\libs\python15.lib"
#PYEXE="C:\Python21\python.exe"
#PYINC=/I"C:\Python21\include"
#PYLIB="C:\Python21\libs\python21.lib"
STDOPTS=/nologo /MD /GR /GX /Zm200
WARNOPTS=
@@ -46,8 +43,7 @@ all: boost_python.lib \
do_it_yourself_converters.pyd \
pickle1.pyd pickle2.pyd pickle3.pyd \
noncopyable_export.pyd noncopyable_import.pyd \
ivect.pyd dvect.pyd \
richcmp1.pyd richcmp2.pyd richcmp3.pyd
ivect.pyd dvect.pyd
boost_python.lib: $(OBJ)
$(LD) -lib /nologo /out:boost_python.lib $(OBJ)
@@ -91,15 +87,6 @@ ivect.pyd: $(OBJ) ivect.obj
dvect.pyd: $(OBJ) dvect.obj
$(LD) $(LDOPTS) $(OBJ) dvect.obj $(PYLIB) /export:initdvect /out:"dvect.pyd"
richcmp1.pyd: $(OBJ) richcmp1.obj
$(LD) $(LDOPTS) $(OBJ) richcmp1.obj $(PYLIB) /export:initrichcmp1 /out:"richcmp1.pyd"
richcmp2.pyd: $(OBJ) richcmp2.obj
$(LD) $(LDOPTS) $(OBJ) richcmp2.obj $(PYLIB) /export:initrichcmp2 /out:"richcmp2.pyd"
richcmp3.pyd: $(OBJ) richcmp3.obj
$(LD) $(LDOPTS) $(OBJ) richcmp3.obj $(PYLIB) /export:initrichcmp3 /out:"richcmp3.pyd"
.cpp.obj:
$(CPP) $(CPPOPTS) /c $*.cpp
@@ -114,17 +101,14 @@ test:
$(PYEXE) test_pickle2.py
$(PYEXE) test_pickle3.py
$(PYEXE) test_cross_module.py --broken-auto-ptr
$(PYEXE) test_richcmp1.py
$(PYEXE) test_richcmp2.py
$(PYEXE) test_richcmp3.py
clean:
-del *.obj
-del *.lib
-del *.exp
-del *.idb
-del *.pyd
-del *.pyc
del *.obj
del *.lib
del *.exp
del *.idb
del *.pyd
del *.pyc
softlinks:
python $(BOOST_UNIX)/libs/python/build/filemgr.py $(BOOST_UNIX) softlinks

View File

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

View File

@@ -75,7 +75,7 @@ BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround
from_python(x, boost::python::type&lt;long&gt;()));
}
PyObject* to_python(MyEnumType x)
PyObject* to_python(boost::python::semantics, MyEnumType x)
{
return to_python(static_cast&lt;long&gt;(x));
}
@@ -91,8 +91,8 @@ initialization. These bind the corresponding enum values to the appropriate
names so they can be used from Python:
<blockquote><pre>
mymodule.add(boost::python::make_ref(enum_value_1), "enum_value_1");
mymodule.add(boost::python::make_ref(enum_value_2), "enum_value_2");
mymodule.add(boost::python::to_python(boost::python::search_namespace, enum_value_1), "enum_value_1");
mymodule.add(boost::python::to_python(boost::python::search_namespace, enum_value_2), "enum_value_2");
...
</pre></blockquote>
@@ -100,8 +100,8 @@ You can also add these to an extension class definition, if your enum happens to
be local to a class and you want the analogous interface in Python:
<blockquote><pre>
my_class_builder.add(boost::python::to_python(enum_value_1), "enum_value_1");
my_class_builder.add(boost::python::to_python(enum_value_2), "enum_value_2");
my_class_builder.add(boost::python::to_python(boost::python::search_namespace, enum_value_1), "enum_value_1");
my_class_builder.add(boost::python::to_python(boost::python::search_namespace, enum_value_2), "enum_value_2");
...
</pre></blockquote>
<p>

View File

@@ -65,9 +65,9 @@ wrapped <code>T</code>, you may want to provide an automatic
thin wrappers. You can do this simply as follows:
<blockquote><pre>
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround
PyObject* to_python(const Foo* p) {
return to_python(*p); // convert const Foo* in terms of const Foo&
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is an MSVC / gcc 2.95.2 bug workaround
PyObject* to_python(boost::python::semantics, const Foo* p) {
return to_python(boost::python::search_namespace, *p); // convert const Foo* in terms of const Foo&
}
BOOST_PYTHON_END_CONVERSION_NAMESPACE
</pre></blockquote>
@@ -83,12 +83,12 @@ code before the last Python reference to it disappears:
<blockquote><pre>
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround
PyObject* to_python(Foo* p)
PyObject* to_python(boost::python::semantics, Foo* p)
{
return boost::python::python_extension_class_converters&lt;Foo&gt;::smart_ptr_to_python(p);
return boost::python::python_extension_class_converters&ltFoo&gt::ptr_to_python(p);
}
PyObject* to_python(const Foo* p)
PyObject* to_python(boost::python::semantics, const Foo* p)
{
return to_python(const_cast&lt;Foo*&gt;(p));
}

View File

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

View File

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

View File

@@ -27,7 +27,7 @@
<a href="example1.html#Constructor_example">provide an argument list</a>
because they can't be named in C++). Then, it calls the appropriate
overloaded functions <code>PyObject*
to_python(</code><em>S</em><code>)</code> and <em>
to_python(boost::python::semantics, </code><em>S</em><code>)</code> and <em>
S'</em><code>from_python(PyObject*,
type&lt;</code><em>S</em><code>&gt;)</code> which convert between any C++
type <em>S</em> and a <code>PyObject*</code>, the type which represents a
@@ -36,7 +36,7 @@
template defines a whole raft of these conversions (for <code>T, T*,
T&amp;, std::auto_ptr&lt;T&gt;</code>, etc.), using the same inline
friend function technique employed by <a href=
"file:///c:/boost/site/libs/utility/operators.htm">the boost operators
"http://www.boost.org/libs/utility/operators.htm">the boost operators
library</a>.
<p>
Because the <code>to_python</code> and <code>from_python</code> functions

View File

@@ -95,11 +95,11 @@ BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
// Convert a MillerIndex object to a Python tuple.
//
PyObject* to_python(const MillerIndex& hkl)
PyObject* to_python(const MillerIndex& hkl, python::lookup_tag)
{
python::tuple result(3);
for (int i = 0; i < 3; i++)
result.set_item(i, python::ref(to_python(hkl.v[i])));
result.set_item(i, hkl.v[i]);
return result.reference().release();
}

View File

@@ -20,16 +20,6 @@ namespace {
}
}
# ifdef BOOST_MSVC // fixes for JIT debugging
# include <windows.h>
extern "C" void structured_exception_translator(unsigned int, EXCEPTION_POINTERS*)
{
throw;
}
extern "C" void (*old_translator)(unsigned int, EXCEPTION_POINTERS*)
= _set_se_translator(structured_exception_translator);
# endif
BOOST_PYTHON_MODULE_INIT(dvect)
{
try
@@ -53,4 +43,3 @@ BOOST_PYTHON_MODULE_INIT(dvect)
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -14,16 +14,14 @@ namespace vects {
{
std::vector<double>::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<double>());
v_it[i] = from_python(tuple[i].get(), boost::python::type<double>());
}
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])));
t.set_item(i, (*this)[i]);
return t;
}
};

View File

@@ -20,16 +20,6 @@ namespace {
}
}
# ifdef BOOST_MSVC // fixes for JIT debugging
# include <windows.h>
extern "C" void structured_exception_translator(unsigned int, EXCEPTION_POINTERS*)
{
throw;
}
extern "C" void (*old_translator)(unsigned int, EXCEPTION_POINTERS*)
= _set_se_translator(structured_exception_translator);
# endif
BOOST_PYTHON_MODULE_INIT(ivect)
{
try
@@ -53,4 +43,3 @@ BOOST_PYTHON_MODULE_INIT(ivect)
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -14,16 +14,14 @@ namespace vects {
{
std::vector<int>::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<int>());
v_it[i] = from_python(tuple[i].get(), boost::python::type<int>());
}
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])));
t.set_item(i, (*this)[i]);
return t;
}
};

View File

@@ -6,16 +6,6 @@ namespace python = boost::python;
#include "noncopyable.h"
# ifdef BOOST_MSVC // fixes for JIT debugging
# include <windows.h>
extern "C" void structured_exception_translator(unsigned int, EXCEPTION_POINTERS*)
{
throw;
}
extern "C" void (*old_translator)(unsigned int, EXCEPTION_POINTERS*)
= _set_se_translator(structured_exception_translator);
# endif
BOOST_PYTHON_MODULE_INIT(noncopyable_export)
{
try

View File

@@ -19,16 +19,6 @@ namespace { // Avoid cluttering the global namespace.
}
}
# ifdef BOOST_MSVC // fixes for JIT debugging
# include <windows.h>
extern "C" void structured_exception_translator(unsigned int, EXCEPTION_POINTERS*)
{
throw;
}
extern "C" void (*old_translator)(unsigned int, EXCEPTION_POINTERS*)
= _set_se_translator(structured_exception_translator);
# endif
BOOST_PYTHON_MODULE_INIT(noncopyable_import)
{
try

View File

@@ -45,8 +45,6 @@ namespace { // Avoid cluttering the global namespace.
// 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());

View File

@@ -94,7 +94,6 @@ BOOST_PYTHON_MODULE_INIT(pickle3)
namespace {
using BOOST_PYTHON_CONVERSION::from_python;
using boost::python::type;
using boost::python::ref;
using boost::python::tuple;
@@ -106,7 +105,7 @@ namespace {
{
if(args.size() != 1 || keywords.size() != 0) {
PyErr_SetString(PyExc_TypeError, "wrong number of arguments");
throw boost::python::error_already_set();
throw boost::python::argument_error();
}
const world& w = from_python(args[0].get(), type<const world&>());
ref mydict = getattr(args[0], "__dict__");
@@ -122,7 +121,7 @@ namespace {
{
if(args.size() != 2 || keywords.size() != 0) {
PyErr_SetString(PyExc_TypeError, "wrong number of arguments");
throw boost::python::error_already_set();
throw boost::python::argument_error();
}
world& w = from_python(args[0].get(), type<world&>());
ref mydict = getattr(args[0], "__dict__");

View File

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

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

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

@@ -25,8 +25,7 @@ namespace { // Avoid cluttering the global namespace.
{
std::vector<double>::iterator vd = begin();
for (int i = 0; i < tuple.size(); i++)
vd[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(),
python::type<double>());
vd[i] = from_python(tuple[i].get(), python::type<double>());
}
};
@@ -57,8 +56,8 @@ namespace { // Avoid cluttering the global namespace.
python::tuple as_tuple(const std::vector<double>& 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])));
for (int i = 0; i < vd.size(); i++)
t.set_item(i, vd[i]);
return t;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -46,7 +46,7 @@ struct callback
template <class A1>
static R call_method(PyObject* self, const char* name, const A1& a1)
{
ref p1(to_python(a1));
ref p1(to_python(a1, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(O)"),
p1.get()));
@@ -57,7 +57,7 @@ struct callback
template <class A1>
static R call(PyObject* self, const A1& a1)
{
ref p1(to_python(a1));
ref p1(to_python(a1, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(O)"),
p1.get()));
detail::callback_adjust_refcount(result.get(), type<R>());
@@ -67,8 +67,8 @@ struct callback
template <class A1, class A2>
static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OO)"),
p1.get(),
@@ -80,8 +80,8 @@ struct callback
template <class A1, class A2>
static R call(PyObject* self, const A1& a1, const A2& a2)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OO)"),
p1.get(),
p2.get()));
@@ -92,9 +92,9 @@ struct callback
template <class A1, class A2, class A3>
static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOO)"),
p1.get(),
@@ -107,9 +107,9 @@ struct callback
template <class A1, class A2, class A3>
static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOO)"),
p1.get(),
p2.get(),
@@ -121,10 +121,10 @@ struct callback
template <class A1, class A2, class A3, class A4>
static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOOO)"),
p1.get(),
@@ -138,10 +138,10 @@ struct callback
template <class A1, class A2, class A3, class A4>
static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOOO)"),
p1.get(),
p2.get(),
@@ -154,11 +154,11 @@ struct callback
template <class A1, class A2, class A3, class A4, class A5>
static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOOOO)"),
p1.get(),
@@ -173,11 +173,11 @@ struct callback
template <class A1, class A2, class A3, class A4, class A5>
static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOOOO)"),
p1.get(),
p2.get(),
@@ -191,12 +191,12 @@ struct callback
template <class A1, class A2, class A3, class A4, class A5, class A6>
static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOOOOO)"),
p1.get(),
@@ -212,12 +212,12 @@ struct callback
template <class A1, class A2, class A3, class A4, class A5, class A6>
static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOOOOO)"),
p1.get(),
p2.get(),
@@ -232,13 +232,13 @@ struct callback
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOOOOOO)"),
p1.get(),
@@ -255,13 +255,13 @@ struct callback
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOOOOOO)"),
p1.get(),
p2.get(),
@@ -277,14 +277,14 @@ struct callback
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p8(to_python(a8));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref p8(to_python(a8, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOOOOOOO)"),
p1.get(),
@@ -302,14 +302,14 @@ struct callback
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p8(to_python(a8));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref p8(to_python(a8, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOOOOOOO)"),
p1.get(),
p2.get(),
@@ -326,15 +326,15 @@ struct callback
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p8(to_python(a8));
ref p9(to_python(a9));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref p8(to_python(a8, lookup_tag()));
ref p9(to_python(a9, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOOOOOOOO)"),
p1.get(),
@@ -353,15 +353,15 @@ struct callback
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p8(to_python(a8));
ref p9(to_python(a9));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref p8(to_python(a8, lookup_tag()));
ref p9(to_python(a9, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOOOOOOOO)"),
p1.get(),
p2.get(),
@@ -379,16 +379,16 @@ struct callback
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
static R call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p8(to_python(a8));
ref p9(to_python(a9));
ref p10(to_python(a10));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref p8(to_python(a8, lookup_tag()));
ref p9(to_python(a9, lookup_tag()));
ref p10(to_python(a10, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOOOOOOOOO)"),
p1.get(),
@@ -408,16 +408,16 @@ struct callback
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
static R call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p8(to_python(a8));
ref p9(to_python(a9));
ref p10(to_python(a10));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref p8(to_python(a8, lookup_tag()));
ref p9(to_python(a9, lookup_tag()));
ref p10(to_python(a10, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOOOOOOOOO)"),
p1.get(),
p2.get(),
@@ -455,7 +455,7 @@ struct callback<void>
template <class A1>
static void call_method(PyObject* self, const char* name, const A1& a1)
{
ref p1(to_python(a1));
ref p1(to_python(a1, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(O)"),
p1.get()));
@@ -464,7 +464,7 @@ struct callback<void>
template <class A1>
static void call(PyObject* self, const A1& a1)
{
ref p1(to_python(a1));
ref p1(to_python(a1, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(O)"),
p1.get()));
}
@@ -472,8 +472,8 @@ struct callback<void>
template <class A1, class A2>
static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OO)"),
p1.get(),
@@ -483,8 +483,8 @@ struct callback<void>
template <class A1, class A2>
static void call(PyObject* self, const A1& a1, const A2& a2)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OO)"),
p1.get(),
p2.get()));
@@ -493,9 +493,9 @@ struct callback<void>
template <class A1, class A2, class A3>
static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOO)"),
p1.get(),
@@ -506,9 +506,9 @@ struct callback<void>
template <class A1, class A2, class A3>
static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOO)"),
p1.get(),
p2.get(),
@@ -518,10 +518,10 @@ struct callback<void>
template <class A1, class A2, class A3, class A4>
static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOOO)"),
p1.get(),
@@ -533,10 +533,10 @@ struct callback<void>
template <class A1, class A2, class A3, class A4>
static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOOO)"),
p1.get(),
p2.get(),
@@ -547,11 +547,11 @@ struct callback<void>
template <class A1, class A2, class A3, class A4, class A5>
static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOOOO)"),
p1.get(),
@@ -564,11 +564,11 @@ struct callback<void>
template <class A1, class A2, class A3, class A4, class A5>
static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOOOO)"),
p1.get(),
p2.get(),
@@ -580,12 +580,12 @@ struct callback<void>
template <class A1, class A2, class A3, class A4, class A5, class A6>
static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOOOOO)"),
p1.get(),
@@ -599,12 +599,12 @@ struct callback<void>
template <class A1, class A2, class A3, class A4, class A5, class A6>
static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOOOOO)"),
p1.get(),
p2.get(),
@@ -617,13 +617,13 @@ struct callback<void>
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOOOOOO)"),
p1.get(),
@@ -638,13 +638,13 @@ struct callback<void>
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOOOOOO)"),
p1.get(),
p2.get(),
@@ -658,14 +658,14 @@ struct callback<void>
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p8(to_python(a8));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref p8(to_python(a8, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOOOOOOO)"),
p1.get(),
@@ -681,14 +681,14 @@ struct callback<void>
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p8(to_python(a8));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref p8(to_python(a8, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOOOOOOO)"),
p1.get(),
p2.get(),
@@ -703,15 +703,15 @@ struct callback<void>
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p8(to_python(a8));
ref p9(to_python(a9));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref p8(to_python(a8, lookup_tag()));
ref p9(to_python(a9, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOOOOOOOO)"),
p1.get(),
@@ -728,15 +728,15 @@ struct callback<void>
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p8(to_python(a8));
ref p9(to_python(a9));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref p8(to_python(a8, lookup_tag()));
ref p9(to_python(a9, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOOOOOOOO)"),
p1.get(),
p2.get(),
@@ -752,16 +752,16 @@ struct callback<void>
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
static void call_method(PyObject* self, const char* name, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p8(to_python(a8));
ref p9(to_python(a9));
ref p10(to_python(a10));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref p8(to_python(a8, lookup_tag()));
ref p9(to_python(a9, lookup_tag()));
ref p10(to_python(a10, lookup_tag()));
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(OOOOOOOOOO)"),
p1.get(),
@@ -779,16 +779,16 @@ struct callback<void>
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
static void call(PyObject* self, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10)
{
ref p1(to_python(a1));
ref p2(to_python(a2));
ref p3(to_python(a3));
ref p4(to_python(a4));
ref p5(to_python(a5));
ref p6(to_python(a6));
ref p7(to_python(a7));
ref p8(to_python(a8));
ref p9(to_python(a9));
ref p10(to_python(a10));
ref p1(to_python(a1, lookup_tag()));
ref p2(to_python(a2, lookup_tag()));
ref p3(to_python(a3, lookup_tag()));
ref p4(to_python(a4, lookup_tag()));
ref p5(to_python(a5, lookup_tag()));
ref p6(to_python(a6, lookup_tag()));
ref p7(to_python(a7, lookup_tag()));
ref p8(to_python(a8, lookup_tag()));
ref p9(to_python(a9, lookup_tag()));
ref p10(to_python(a10, lookup_tag()));
ref result(PyEval_CallFunction(self, const_cast<char*>("(OOOOOOOOOO)"),
p1.get(),
p2.get(),

View File

@@ -30,7 +30,7 @@ struct caller
if (!PyArg_ParseTuple(args, const_cast<char*>("O"), &self))
return 0;
T& target = from_python(self, type<T&>());
return to_python((target.*pmf)());
return to_python((target.*pmf)(), lookup_tag());
}
template <class T, class A1>
@@ -40,7 +40,7 @@ struct caller
if (!PyArg_ParseTuple(args, const_cast<char*>("OO"), &self, &a1))
return 0;
T& target = from_python(self, type<T&>());
return to_python((target.*pmf)(from_python(a1, type<A1>())));
return to_python((target.*pmf)(from_python(a1, type<A1>())), lookup_tag());
}
template <class T, class A1, class A2>
@@ -52,7 +52,7 @@ struct caller
return 0;
T& target = from_python(self, type<T&>());
return to_python((target.*pmf)(from_python(a1, type<A1>()),
from_python(a2, type<A2>())));
from_python(a2, type<A2>())), lookup_tag());
}
template <class T, class A1, class A2, class A3>
@@ -66,7 +66,7 @@ struct caller
T& target = from_python(self, type<T&>());
return to_python((target.*pmf)(from_python(a1, type<A1>()),
from_python(a2, type<A2>()),
from_python(a3, type<A3>())));
from_python(a3, type<A3>())), lookup_tag());
}
template <class T, class A1, class A2, class A3, class A4>
@@ -82,7 +82,7 @@ struct caller
return to_python((target.*pmf)(from_python(a1, type<A1>()),
from_python(a2, type<A2>()),
from_python(a3, type<A3>()),
from_python(a4, type<A4>())));
from_python(a4, type<A4>())), lookup_tag());
}
template <class T, class A1, class A2, class A3, class A4, class A5>
@@ -100,7 +100,7 @@ struct caller
from_python(a2, type<A2>()),
from_python(a3, type<A3>()),
from_python(a4, type<A4>()),
from_python(a5, type<A5>())));
from_python(a5, type<A5>())), lookup_tag());
}
template <class T, class A1, class A2, class A3, class A4, class A5, class A6>
@@ -120,7 +120,7 @@ struct caller
from_python(a3, type<A3>()),
from_python(a4, type<A4>()),
from_python(a5, type<A5>()),
from_python(a6, type<A6>())));
from_python(a6, type<A6>())), lookup_tag());
}
template <class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
@@ -142,7 +142,7 @@ struct caller
from_python(a4, type<A4>()),
from_python(a5, type<A5>()),
from_python(a6, type<A6>()),
from_python(a7, type<A7>())));
from_python(a7, type<A7>())), lookup_tag());
}
template <class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
@@ -166,7 +166,7 @@ struct caller
from_python(a5, type<A5>()),
from_python(a6, type<A6>()),
from_python(a7, type<A7>()),
from_python(a8, type<A8>())));
from_python(a8, type<A8>())), lookup_tag());
}
template <class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
@@ -192,7 +192,7 @@ struct caller
from_python(a6, type<A6>()),
from_python(a7, type<A7>()),
from_python(a8, type<A8>()),
from_python(a9, type<A9>())));
from_python(a9, type<A9>())), lookup_tag());
}
template <class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
@@ -220,7 +220,7 @@ struct caller
from_python(a7, type<A7>()),
from_python(a8, type<A8>()),
from_python(a9, type<A9>()),
from_python(a10, type<A10>())));
from_python(a10, type<A10>())), lookup_tag());
}
@@ -230,7 +230,7 @@ struct caller
if (!PyArg_ParseTuple(args, const_cast<char*>("O"), &self))
return 0;
T& target = from_python(self, type<T&>());
return to_python((target.*pmf)());
return to_python((target.*pmf)(), lookup_tag());
}
template <class T, class A1>
@@ -240,7 +240,7 @@ struct caller
if (!PyArg_ParseTuple(args, const_cast<char*>("OO"), &self, &a1))
return 0;
T& target = from_python(self, type<T&>());
return to_python((target.*pmf)(from_python(a1, type<A1>())));
return to_python((target.*pmf)(from_python(a1, type<A1>())), lookup_tag());
}
template <class T, class A1, class A2>
@@ -252,7 +252,7 @@ struct caller
return 0;
T& target = from_python(self, type<T&>());
return to_python((target.*pmf)(from_python(a1, type<A1>()),
from_python(a2, type<A2>())));
from_python(a2, type<A2>())), lookup_tag());
}
template <class T, class A1, class A2, class A3>
@@ -266,7 +266,7 @@ struct caller
T& target = from_python(self, type<T&>());
return to_python((target.*pmf)(from_python(a1, type<A1>()),
from_python(a2, type<A2>()),
from_python(a3, type<A3>())));
from_python(a3, type<A3>())), lookup_tag());
}
template <class T, class A1, class A2, class A3, class A4>
@@ -282,7 +282,7 @@ struct caller
return to_python((target.*pmf)(from_python(a1, type<A1>()),
from_python(a2, type<A2>()),
from_python(a3, type<A3>()),
from_python(a4, type<A4>())));
from_python(a4, type<A4>())), lookup_tag());
}
template <class T, class A1, class A2, class A3, class A4, class A5>
@@ -300,7 +300,7 @@ struct caller
from_python(a2, type<A2>()),
from_python(a3, type<A3>()),
from_python(a4, type<A4>()),
from_python(a5, type<A5>())));
from_python(a5, type<A5>())), lookup_tag());
}
template <class T, class A1, class A2, class A3, class A4, class A5, class A6>
@@ -320,7 +320,7 @@ struct caller
from_python(a3, type<A3>()),
from_python(a4, type<A4>()),
from_python(a5, type<A5>()),
from_python(a6, type<A6>())));
from_python(a6, type<A6>())), lookup_tag());
}
template <class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
@@ -342,7 +342,7 @@ struct caller
from_python(a4, type<A4>()),
from_python(a5, type<A5>()),
from_python(a6, type<A6>()),
from_python(a7, type<A7>())));
from_python(a7, type<A7>())), lookup_tag());
}
template <class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
@@ -366,7 +366,7 @@ struct caller
from_python(a5, type<A5>()),
from_python(a6, type<A6>()),
from_python(a7, type<A7>()),
from_python(a8, type<A8>())));
from_python(a8, type<A8>())), lookup_tag());
}
template <class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
@@ -392,7 +392,7 @@ struct caller
from_python(a6, type<A6>()),
from_python(a7, type<A7>()),
from_python(a8, type<A8>()),
from_python(a9, type<A9>())));
from_python(a9, type<A9>())), lookup_tag());
}
template <class T, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
@@ -420,14 +420,14 @@ struct caller
from_python(a7, type<A7>()),
from_python(a8, type<A8>()),
from_python(a9, type<A9>()),
from_python(a10, type<A10>())));
from_python(a10, type<A10>())), lookup_tag());
}
// Free functions
static PyObject* call(R (*f)(), PyObject* args, PyObject* /* keywords */ ) {
if (!PyArg_ParseTuple(args, const_cast<char*>("")))
return 0;
return to_python(f());
return to_python(f(), lookup_tag());
}
template <class A1>
@@ -435,7 +435,7 @@ struct caller
PyObject* a1;
if (!PyArg_ParseTuple(args, const_cast<char*>("O"), &a1))
return 0;
return to_python(f(from_python(a1, type<A1>())));
return to_python(f(from_python(a1, type<A1>())), lookup_tag());
}
template <class A1, class A2>
@@ -445,7 +445,7 @@ struct caller
if (!PyArg_ParseTuple(args, const_cast<char*>("OO"), &a1, &a2))
return 0;
return to_python(f(from_python(a1, type<A1>()),
from_python(a2, type<A2>())));
from_python(a2, type<A2>())), lookup_tag());
}
template <class A1, class A2, class A3>
@@ -457,7 +457,7 @@ struct caller
return 0;
return to_python(f(from_python(a1, type<A1>()),
from_python(a2, type<A2>()),
from_python(a3, type<A3>())));
from_python(a3, type<A3>())), lookup_tag());
}
template <class A1, class A2, class A3, class A4>
@@ -471,7 +471,7 @@ struct caller
return to_python(f(from_python(a1, type<A1>()),
from_python(a2, type<A2>()),
from_python(a3, type<A3>()),
from_python(a4, type<A4>())));
from_python(a4, type<A4>())), lookup_tag());
}
template <class A1, class A2, class A3, class A4, class A5>
@@ -487,7 +487,7 @@ struct caller
from_python(a2, type<A2>()),
from_python(a3, type<A3>()),
from_python(a4, type<A4>()),
from_python(a5, type<A5>())));
from_python(a5, type<A5>())), lookup_tag());
}
template <class A1, class A2, class A3, class A4, class A5, class A6>
@@ -505,7 +505,7 @@ struct caller
from_python(a3, type<A3>()),
from_python(a4, type<A4>()),
from_python(a5, type<A5>()),
from_python(a6, type<A6>())));
from_python(a6, type<A6>())), lookup_tag());
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
@@ -525,7 +525,7 @@ struct caller
from_python(a4, type<A4>()),
from_python(a5, type<A5>()),
from_python(a6, type<A6>()),
from_python(a7, type<A7>())));
from_python(a7, type<A7>())), lookup_tag());
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
@@ -547,7 +547,7 @@ struct caller
from_python(a5, type<A5>()),
from_python(a6, type<A6>()),
from_python(a7, type<A7>()),
from_python(a8, type<A8>())));
from_python(a8, type<A8>())), lookup_tag());
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
@@ -571,7 +571,7 @@ struct caller
from_python(a6, type<A6>()),
from_python(a7, type<A7>()),
from_python(a8, type<A8>()),
from_python(a9, type<A9>())));
from_python(a9, type<A9>())), lookup_tag());
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
@@ -597,7 +597,7 @@ struct caller
from_python(a7, type<A7>()),
from_python(a8, type<A8>()),
from_python(a9, type<A9>()),
from_python(a10, type<A10>())));
from_python(a10, type<A10>())), lookup_tag());
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11>
@@ -625,7 +625,7 @@ struct caller
from_python(a8, type<A8>()),
from_python(a9, type<A9>()),
from_python(a10, type<A10>()),
from_python(a11, type<A11>())));
from_python(a11, type<A11>())), lookup_tag());
}
};

View File

@@ -19,117 +19,118 @@ class class_builder
: python_extension_class_converters<T, U> // Works around MSVC6.x/GCC2.95.2 bug described below
{
public:
/// Construct a class named name in the given module
class_builder(module_builder& module, const char* name)
: m_class(new detail::extension_class<T, U>(name))
{
module.add(ref(as_object(m_class.get()), ref::increment_count), name);
}
~class_builder()
{}
/// Tell Boost.Python that for the purposes of pickling, the state is
/// completely captured in the object's __dict__.
inline void dict_defines_state() {
add(ref(BOOST_PYTHON_CONVERSION::to_python(1)), "__dict_defines_state__");
}
inline void getstate_manages_dict() {
add(ref(BOOST_PYTHON_CONVERSION::to_python(1)), "__getstate_manages_dict__");
add(ref(to_python(1, lookup_tag())), "__dict_defines_state__");
}
// define constructors
inline void getstate_manages_dict() {
add(ref(to_python(1, lookup_tag())), "__getstate_manages_dict__");
}
/// define constructors
template <class signature>
void def(const signature& s)
{ m_class->def(s); }
// export heterogeneous reverse-argument operators
// (type of lhs: 'left', of rhs: 'right')
// usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(),
// boost::python::left_operand<int const &>());
/// export heterogeneous reverse-argument operators
/// (type of lhs: 'left', of rhs: 'right')
/// usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(),
/// boost::python::left_operand<int const &>());
template <long which, class left, class right>
void def(operators<which, right> o1, left_operand<left> o2)
{ m_class->def(o1, o2); }
// export heterogeneous operators (type of lhs: 'left', of rhs: 'right')
// usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(),
// boost::python::right_operand<int const &>());
/// export heterogeneous operators (type of lhs: 'left', of rhs: 'right')
/// usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(),
/// boost::python::right_operand<int const &>());
template <long which, class left, class right>
void def(operators<which, left> o1, right_operand<right> o2)
{ m_class->def(o1, o2); }
// define a function that passes Python arguments and keywords
// to C++ verbatim (as a 'tuple const &' and 'dictionary const &'
// respectively). This is useful for manual argument passing.
// It's also the only possibility to pass keyword arguments to C++.
// Fn must have a signatur that is compatible to
// PyObject * (*)(PyObject * aTuple, PyObject * aDictionary)
/// define a function that passes Python arguments and keywords
/// to C++ verbatim (as a 'tuple const &' and 'dictionary const &'
/// respectively). This is useful for manual argument passing.
/// It's also the only way to pass keyword arguments to C++.
/// Fn must have a signature that is compatible with
/// PyObject * (*)(PyObject * aTuple, PyObject * aDictionary)
template <class Fn>
void def_raw(Fn fn, const char* name)
{ m_class->def_raw(fn, name); }
// define member functions. In fact this works for free functions, too -
// they act like static member functions, or if they start with the
// appropriate self argument (as a pointer or reference), they can be used
// just like ordinary member functions -- just like Python!
/// define member functions. In fact this works for free functions, too -
/// they act like static member functions, or if they start with the
/// appropriate self argument (as a pointer or reference), they can be used
/// just like ordinary member functions -- just like Python!
template <class Fn>
void def(Fn fn, const char* name)
{ m_class->def(fn, name); }
// Define a virtual member function with a default implementation.
// default_fn should be a function which provides the default implementation.
// Be careful that default_fn does not in fact call fn virtually!
/// Define a virtual member function with a default implementation.
/// default_fn should be a function which provides the default implementation.
/// Be careful that default_fn does not in fact call fn virtually!
template <class Fn, class DefaultFn>
void def(Fn fn, const char* name, DefaultFn default_fn)
{ m_class->def(fn, name, default_fn); }
// Provide a function which implements x.<name>, reading from the given
// member (pm) of the T obj
/// Provide a function which implements x.<name>, reading from the given
/// member (pm) of the T obj
template <class MemberType>
void def_getter(MemberType T::*pm, const char* name)
{ m_class->def_getter(pm, name); }
// Provide a function which implements assignment to x.<name>, writing to
// the given member (pm) of the T obj
/// Provide a function which implements assignment to x.<name>, writing to
/// the given member (pm) of the T obj
template <class MemberType>
void def_setter(MemberType T::*pm, const char* name)
{ m_class->def_getter(pm, name); }
// Expose the given member (pm) of the T obj as a read-only attribute
/// Expose the given member (pm) of the T obj as a read-only attribute
template <class MemberType>
void def_readonly(MemberType T::*pm, const char* name)
{ m_class->def_readonly(pm, name); }
// Expose the given member (pm) of the T obj as a read/write attribute
/// Expose the given member (pm) of the T obj as a read/write attribute
template <class MemberType>
void def_read_write(MemberType T::*pm, const char* name)
{ m_class->def_read_write(pm, name); }
// define the standard coercion needed for operator overloading
/// define the standard coercion needed for operator overloading
void def_standard_coerce()
{ m_class->def_standard_coerce(); }
// declare the given class a base class of this one and register
// conversion functions
/// declare the given class a base class of this one and register
/// conversion functions
template <class S, class V>
void declare_base(class_builder<S, V> const & base)
{
m_class->declare_base(base.get_extension_class());
}
// declare the given class a base class of this one and register
// upcast conversion function
/// declare the given class a base class of this one and register
/// upcast conversion function
template <class S, class V>
void declare_base(class_builder<S, V> const & base, without_downcast_t)
{
m_class->declare_base(base.get_extension_class(), without_downcast);
}
// get the embedded ExtensioClass object
/// get the embedded ExtensioClass object
detail::extension_class<T, U> * get_extension_class() const
{
return m_class.get();
}
// set an arbitrary attribute. Useful for non-function class data members,
// e.g. enums
/// set an arbitrary attribute. Useful for non-function class data members,
/// e.g. enums
void add(PyObject* x, const char* name)
{ m_class->set_attribute(name, x); }
void add(ref x, const char* name)
@@ -143,8 +144,8 @@ class class_builder
m_class->declare_base(base);
}
// declare the given class a base class of this one and register
// upcast conversion function
/// declare the given class a base class of this one and register
/// upcast conversion function
template <class S, class V>
void declare_base(detail::extension_class<S, V> * base, without_downcast_t)
{

View File

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

View File

@@ -33,6 +33,10 @@
# pragma warning(pop)
# endif
namespace boost { namespace python {
struct lookup_tag {}; // Used to find to_python functions via Koenig lookup.
}}
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround
// This can be instantiated on an enum to provide the to_python/from_python
@@ -52,16 +56,16 @@ class py_enum_as_int_converters
from_python(x, boost::python::type<long>()));
}
friend PyObject* to_python(EnumType x)
friend PyObject* to_python(EnumType x, boost::python::lookup_tag)
{
return to_python(static_cast<long>(x));
return to_python(static_cast<long>(x), boost::python::lookup_tag());
}
};
BOOST_PYTHON_END_CONVERSION_NAMESPACE
namespace boost { namespace python {
template <class EnumType> class enum_as_int_converters
: public BOOST_PYTHON_CONVERSION::py_enum_as_int_converters<EnumType> {};
: public py_enum_as_int_converters<EnumType> {};
template <class P, class T> class wrapped_pointer;
@@ -116,70 +120,70 @@ BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
//
// Converters
//
PyObject* to_python(long);
PyObject* to_python(long, boost::python::lookup_tag);
long from_python(PyObject* p, boost::python::type<long>);
long from_python(PyObject* p, boost::python::type<const long&>);
PyObject* to_python(unsigned long);
PyObject* to_python(unsigned long, boost::python::lookup_tag);
unsigned long from_python(PyObject* p, boost::python::type<unsigned long>);
unsigned long from_python(PyObject* p, boost::python::type<const unsigned long&>);
PyObject* to_python(int);
PyObject* to_python(int, boost::python::lookup_tag);
int from_python(PyObject*, boost::python::type<int>);
int from_python(PyObject*, boost::python::type<const int&>);
PyObject* to_python(unsigned int);
PyObject* to_python(unsigned int, boost::python::lookup_tag);
unsigned int from_python(PyObject*, boost::python::type<unsigned int>);
unsigned int from_python(PyObject*, boost::python::type<const unsigned int&>);
PyObject* to_python(short);
PyObject* to_python(short, boost::python::lookup_tag);
short from_python(PyObject*, boost::python::type<short>);
short from_python(PyObject*, boost::python::type<const short&>);
PyObject* to_python(unsigned short);
PyObject* to_python(unsigned short, boost::python::lookup_tag);
unsigned short from_python(PyObject*, boost::python::type<unsigned short>);
unsigned short from_python(PyObject*, boost::python::type<const unsigned short&>);
PyObject* to_python(char);
PyObject* to_python(char, boost::python::lookup_tag);
char from_python(PyObject*, boost::python::type<char>);
char from_python(PyObject*, boost::python::type<const char&>);
PyObject* to_python(signed char);
PyObject* to_python(signed char, boost::python::lookup_tag);
signed char from_python(PyObject*, boost::python::type<signed char>);
signed char from_python(PyObject*, boost::python::type<const signed char&>);
PyObject* to_python(unsigned char);
PyObject* to_python(unsigned char, boost::python::lookup_tag);
unsigned char from_python(PyObject*, boost::python::type<unsigned char>);
unsigned char from_python(PyObject*, boost::python::type<const unsigned char&>);
PyObject* to_python(float);
PyObject* to_python(float, boost::python::lookup_tag);
float from_python(PyObject*, boost::python::type<float>);
float from_python(PyObject*, boost::python::type<const float&>);
PyObject* to_python(double);
PyObject* to_python(double, boost::python::lookup_tag);
double from_python(PyObject*, boost::python::type<double>);
double from_python(PyObject*, boost::python::type<const double&>);
PyObject* to_python(bool);
PyObject* to_python(bool, boost::python::lookup_tag);
bool from_python(PyObject*, boost::python::type<bool>);
bool from_python(PyObject*, boost::python::type<const bool&>);
PyObject* to_python(void);
PyObject* to_python(boost::python::lookup_tag);
void from_python(PyObject*, boost::python::type<void>);
PyObject* to_python(const char* s);
PyObject* to_python(const char* s, boost::python::lookup_tag);
const char* from_python(PyObject*, boost::python::type<const char*>);
PyObject* to_python(const std::string& s);
PyObject* to_python(const std::string& s, boost::python::lookup_tag);
std::string from_python(PyObject*, boost::python::type<std::string>);
std::string from_python(PyObject*, boost::python::type<const std::string&>);
inline PyObject* to_python(const std::complex<float>& x)
inline PyObject* to_python(const std::complex<float>& x, boost::python::lookup_tag)
{
return boost::python::detail::complex_to_python<float>(x);
}
inline PyObject* to_python(const std::complex<double>& x)
inline PyObject* to_python(const std::complex<double>& x, boost::python::lookup_tag)
{
return boost::python::detail::complex_to_python<double>(x);
}
@@ -205,7 +209,7 @@ inline std::complex<float> from_python(PyObject* p,
}
// For when your C++ function really wants to pass/return a PyObject*
PyObject* to_python(PyObject*);
PyObject* to_python(PyObject*, boost::python::lookup_tag);
PyObject* from_python(PyObject*, boost::python::type<PyObject*>);
// Some standard conversions to/from smart pointer types. You can add your own
@@ -259,13 +263,13 @@ boost::shared_ptr<T> from_python(PyObject*p, boost::python::type<boost::shared_p
#if 0
template <class T>
PyObject* to_python(std::auto_ptr<T> p)
PyObject* to_python(std::auto_ptr<T> p, boost::python::lookup_tag)
{
return new boost::python::wrapped_pointer<std::auto_ptr<T>, T>(p);
}
template <class T>
PyObject* to_python(boost::shared_ptr<T> p)
PyObject* to_python(boost::shared_ptr<T> p, boost::python::lookup_tag)
{
return new boost::python::wrapped_pointer<boost::shared_ptr<T>, T>(p);
}
@@ -276,43 +280,43 @@ PyObject* to_python(boost::shared_ptr<T> p)
//
#ifndef BOOST_MSVC6_OR_EARLIER
inline PyObject* to_python(double d)
inline PyObject* to_python(double d, boost::python::lookup_tag)
{
return PyFloat_FromDouble(d);
}
inline PyObject* to_python(float f)
inline PyObject* to_python(float f, boost::python::lookup_tag)
{
return PyFloat_FromDouble(f);
}
#endif // BOOST_MSVC6_OR_EARLIER
inline PyObject* to_python(long l)
inline PyObject* to_python(long l, boost::python::lookup_tag)
{
return PyInt_FromLong(l);
}
inline PyObject* to_python(int x)
inline PyObject* to_python(int x, boost::python::lookup_tag)
{
return PyInt_FromLong(x);
}
inline PyObject* to_python(short x)
inline PyObject* to_python(short x, boost::python::lookup_tag)
{
return PyInt_FromLong(x);
}
inline PyObject* to_python(bool b)
inline PyObject* to_python(bool b, boost::python::lookup_tag)
{
return PyInt_FromLong(b);
}
inline PyObject* to_python(void)
inline PyObject* to_python(boost::python::lookup_tag)
{
return boost::python::detail::none();
}
inline PyObject* to_python(const char* s)
inline PyObject* to_python(const char* s, boost::python::lookup_tag)
{
return PyString_FromString(s);
}
@@ -322,7 +326,7 @@ inline std::string from_python(PyObject* p, boost::python::type<const std::strin
return from_python(p, boost::python::type<std::string>());
}
inline PyObject* to_python(PyObject* p)
inline PyObject* to_python(PyObject* p, boost::python::lookup_tag)
{
Py_INCREF(p);
return p;

View File

@@ -66,8 +66,8 @@ class python_import_extension_class_converters
return python_import_extension_class_converters();
}
PyObject* to_python(const T& x) const {
return boost::python::detail::import_extension_class<T>::get_converters()->to_python(x);
PyObject* m_to_python(const T& x) const {
return boost::python::detail::import_extension_class<T>::get_converters()->dispatcher_to_python(x);
}
friend T* from_python(PyObject* p, boost::python::type<T*> t, bool sig = false) {
@@ -101,8 +101,8 @@ class python_import_extension_class_converters
friend const std::auto_ptr<T>& from_python(PyObject* p, boost::python::type<const std::auto_ptr<T>&> t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_caTr(p, t);
}
friend PyObject* to_python(std::auto_ptr<T> x, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->to_python(x);
friend PyObject* to_python(std::auto_ptr<T> x, boost::python::lookup_tag, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->dispatcher_to_python(x);
}
friend boost::shared_ptr<T>& from_python(PyObject* p, boost::python::type<boost::shared_ptr<T>&> t, bool sig = false) {
@@ -114,8 +114,8 @@ class python_import_extension_class_converters
friend const boost::shared_ptr<T>& from_python(PyObject* p, boost::python::type<const boost::shared_ptr<T>&> t, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->from_python_csTr(p, t);
}
friend PyObject* to_python(boost::shared_ptr<T> x, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->to_python(x);
friend PyObject* to_python(boost::shared_ptr<T> x, boost::python::lookup_tag, bool sig = false) {
return boost::python::detail::import_extension_class<T>::get_converters()->dispatcher_to_python(x);
}
};
@@ -123,8 +123,6 @@ BOOST_PYTHON_END_CONVERSION_NAMESPACE
namespace boost { namespace python {
BOOST_PYTHON_IMPORT_CONVERSION(python_import_extension_class_converters);
/* This class template is instantiated by export_converters().
A pointer to this class is exported/imported via the Python API.
Using the Python API ensures maximum portability.
@@ -140,83 +138,83 @@ struct export_converter_object_base
virtual int get_api_major() const { return detail::export_converters_api_major; }
virtual int get_api_minor() const { return detail::export_converters_api_minor; }
virtual PyObject* to_python(const T& x) = 0;
virtual PyObject* dispatcher_to_python(const T& x) = 0;
virtual T* from_python_Ts(PyObject* p, boost::python::type<T*> t) = 0;
virtual const T* from_python_cTs(PyObject* p, boost::python::type<const T*> t) = 0;
virtual const T* from_python_cTscr(PyObject* p, boost::python::type<const T*const&> t) = 0;
virtual T* from_python_Tscr(PyObject* p, boost::python::type<T* const&> t) = 0;
virtual T& from_python_Tr(PyObject* p, boost::python::type<T&> t) = 0;
virtual const T& from_python_cTr(PyObject* p, boost::python::type<const T&> t) = 0;
virtual const T& from_python_T(PyObject* p, boost::python::type<T> t) = 0;
virtual T* from_python_Ts(PyObject* p, type<T*> t) = 0;
virtual const T* from_python_cTs(PyObject* p, type<const T*> t) = 0;
virtual const T* from_python_cTscr(PyObject* p, type<const T*const&> t) = 0;
virtual T* from_python_Tscr(PyObject* p, type<T* const&> t) = 0;
virtual T& from_python_Tr(PyObject* p, type<T&> t) = 0;
virtual const T& from_python_cTr(PyObject* p, type<const T&> t) = 0;
virtual const T& from_python_T(PyObject* p, type<T> t) = 0;
virtual std::auto_ptr<T>& from_python_aTr(PyObject* p, boost::python::type<std::auto_ptr<T>&> t) = 0;
virtual std::auto_ptr<T> from_python_aT(PyObject* p, boost::python::type<std::auto_ptr<T> > t) = 0;
virtual const std::auto_ptr<T>& from_python_caTr(PyObject* p, boost::python::type<const std::auto_ptr<T>&> t) = 0;
virtual PyObject* to_python(std::auto_ptr<T> x) = 0;
virtual std::auto_ptr<T>& from_python_aTr(PyObject* p, type<std::auto_ptr<T>&> t) = 0;
virtual std::auto_ptr<T> from_python_aT(PyObject* p, type<std::auto_ptr<T> > t) = 0;
virtual const std::auto_ptr<T>& from_python_caTr(PyObject* p, type<const std::auto_ptr<T>&> t) = 0;
virtual PyObject* dispatcher_to_python(std::auto_ptr<T> x) = 0;
virtual boost::shared_ptr<T>& from_python_sTr(PyObject* p, boost::python::type<boost::shared_ptr<T>&> t) = 0;
virtual const boost::shared_ptr<T>& from_python_sT(PyObject* p, boost::python::type<boost::shared_ptr<T> > t) = 0;
virtual const boost::shared_ptr<T>& from_python_csTr(PyObject* p, boost::python::type<const boost::shared_ptr<T>&> t) = 0;
virtual PyObject* to_python(boost::shared_ptr<T> x) = 0;
virtual boost::shared_ptr<T>& from_python_sTr(PyObject* p, type<boost::shared_ptr<T>&> t) = 0;
virtual const boost::shared_ptr<T>& from_python_sT(PyObject* p, type<boost::shared_ptr<T> > t) = 0;
virtual const boost::shared_ptr<T>& from_python_csTr(PyObject* p, type<const boost::shared_ptr<T>&> t) = 0;
virtual PyObject* dispatcher_to_python(boost::shared_ptr<T> x) = 0;
};
// Converters to be used if T is not copyable.
template <class T>
struct export_converter_object_noncopyable : export_converter_object_base<T>
{
virtual PyObject* to_python(const T& x) {
virtual PyObject* dispatcher_to_python(const T& x) {
PyErr_SetString(PyExc_RuntimeError,
"to_python(const T&) converter not exported");
"to_python(const T&, boost::python::lookup_tag) converter not exported");
throw import_error();
}
virtual T* from_python_Ts(PyObject* p, boost::python::type<T*> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
virtual T* from_python_Ts(PyObject* p, type<T*> t) {
return from_python(p, t);
}
virtual const T* from_python_cTs(PyObject* p, boost::python::type<const T*> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
virtual const T* from_python_cTs(PyObject* p, type<const T*> t) {
return from_python(p, t);
}
virtual const T* from_python_cTscr(PyObject* p, boost::python::type<const T*const&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
virtual const T* from_python_cTscr(PyObject* p, type<const T*const&> t) {
return from_python(p, t);
}
virtual T* from_python_Tscr(PyObject* p, boost::python::type<T* const&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
virtual T* from_python_Tscr(PyObject* p, type<T* const&> t) {
return from_python(p, t);
}
virtual T& from_python_Tr(PyObject* p, boost::python::type<T&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
virtual T& from_python_Tr(PyObject* p, type<T&> t) {
return from_python(p, t);
}
virtual const T& from_python_cTr(PyObject* p, boost::python::type<const T&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
virtual const T& from_python_cTr(PyObject* p, type<const T&> t) {
return from_python(p, t);
}
virtual const T& from_python_T(PyObject* p, boost::python::type<T> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
virtual const T& from_python_T(PyObject* p, type<T> t) {
return from_python(p, t);
}
virtual std::auto_ptr<T>& from_python_aTr(PyObject* p, boost::python::type<std::auto_ptr<T>&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
virtual std::auto_ptr<T>& from_python_aTr(PyObject* p, type<std::auto_ptr<T>&> t) {
return from_python(p, t);
}
virtual std::auto_ptr<T> from_python_aT(PyObject* p, boost::python::type<std::auto_ptr<T> > t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
virtual std::auto_ptr<T> from_python_aT(PyObject* p, type<std::auto_ptr<T> > t) {
return from_python(p, t);
}
virtual const std::auto_ptr<T>& from_python_caTr(PyObject* p, boost::python::type<const std::auto_ptr<T>&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
virtual const std::auto_ptr<T>& from_python_caTr(PyObject* p, type<const std::auto_ptr<T>&> t) {
return from_python(p, t);
}
virtual PyObject* to_python(std::auto_ptr<T> x) {
return BOOST_PYTHON_CONVERSION::to_python(x);
virtual PyObject* dispatcher_to_python(std::auto_ptr<T> x) {
return to_python(x, lookup_tag());
}
virtual boost::shared_ptr<T>& from_python_sTr(PyObject* p, boost::python::type<boost::shared_ptr<T>&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
virtual boost::shared_ptr<T>& from_python_sTr(PyObject* p, type<boost::shared_ptr<T>&> t) {
return from_python(p, t);
}
virtual const boost::shared_ptr<T>& from_python_sT(PyObject* p, boost::python::type<boost::shared_ptr<T> > t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
virtual const boost::shared_ptr<T>& from_python_sT(PyObject* p, type<boost::shared_ptr<T> > t) {
return from_python(p, t);
}
virtual const boost::shared_ptr<T>& from_python_csTr(PyObject* p, boost::python::type<const boost::shared_ptr<T>&> t) {
return BOOST_PYTHON_CONVERSION::from_python(p, t);
virtual const boost::shared_ptr<T>& from_python_csTr(PyObject* p, type<const boost::shared_ptr<T>&> t) {
return from_python(p, t);
}
virtual PyObject* to_python(boost::shared_ptr<T> x) {
return BOOST_PYTHON_CONVERSION::to_python(x);
virtual PyObject* dispatcher_to_python(boost::shared_ptr<T> x) {
return to_python(x, lookup_tag());
}
};
@@ -224,8 +222,8 @@ struct export_converter_object_noncopyable : export_converter_object_base<T>
template <class T>
struct export_converter_object : export_converter_object_noncopyable<T>
{
virtual PyObject* to_python(const T& x) {
return BOOST_PYTHON_CONVERSION::py_extension_class_converters(boost::python::type<T>()).to_python(x);
virtual PyObject* dispatcher_to_python(const T& x) {
return py_extension_class_converters(type<T>()).m_to_python(x);
}
};
@@ -247,29 +245,29 @@ class import_extension_class
m_py_class = py_class;
}
static boost::python::export_converter_object_base<T>* get_converters();
static export_converter_object_base<T>* get_converters();
private:
static std::string m_module;
static std::string m_py_class;
static boost::python::export_converter_object_base<T>* imported_converters;
static export_converter_object_base<T>* imported_converters;
};
template <class T> std::string import_extension_class<T>::m_module;
template <class T> std::string import_extension_class<T>::m_py_class;
template <class T>
boost::python::export_converter_object_base<T>*
export_converter_object_base<T>*
import_extension_class<T>::imported_converters = 0;
template <class T>
boost::python::export_converter_object_base<T>*
export_converter_object_base<T>*
import_extension_class<T>::get_converters() {
if (imported_converters == 0) {
void* cobject
= import_converter_object(m_module, m_py_class,
converters_attribute_name);
imported_converters
= static_cast<boost::python::export_converter_object_base<T>*>(cobject);
= static_cast<export_converter_object_base<T>*>(cobject);
check_export_converters_api(
export_converters_api_major,
export_converters_api_minor,

View File

@@ -39,7 +39,7 @@ typedef base_object<PyTypeObject> python_type;
//
// base_object member function implementations
// class_t template member function implementations
//
template <class python_type>
base_object<python_type>::base_object(PyTypeObject* type_obj)

View File

@@ -7,6 +7,7 @@
// producing this work.
// Revision History:
// 24 May 01 friend lookup fixes (Ralf W. Grosse-Kunstleve)
// 04 Mar 01 Some fixes so it will compile with Intel C++ (Dave Abrahams)
#ifndef CONFIG_DWA052200_H_
@@ -15,19 +16,6 @@
# include <boost/config.hpp>
# include <cstddef>
# ifdef BOOST_NO_OPERATORS_IN_NAMESPACE
// A gcc bug forces some symbols into the global namespace
# define BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
# define BOOST_PYTHON_END_CONVERSION_NAMESPACE
# define BOOST_PYTHON_CONVERSION
# define BOOST_PYTHON_IMPORT_CONVERSION(x) using ::x
# else
# define BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE namespace boost { namespace python {
# define BOOST_PYTHON_END_CONVERSION_NAMESPACE }} // namespace boost::python
# define BOOST_PYTHON_CONVERSION boost::python
# define BOOST_PYTHON_IMPORT_CONVERSION(x) void never_defined() // so we can follow the macro with a ';'
# endif
# if defined(BOOST_MSVC)
# if _MSC_VER <= 1200
# define BOOST_MSVC6_OR_EARLIER 1
@@ -37,6 +25,29 @@
# endif
# if defined(__GNUC__) && __GNUC__ < 3
# define BOOST_NO_FRIEND_KOENIG_LOOKUP
# endif
# if defined(BOOST_MSVC) && BOOST_MSVC <= 1200
# define BOOST_NO_FRIEND_KOENIG_LOOKUP
# endif
# if defined(__DECCXX_VER) && __DECCXX_VER <= 60290024
# define BOOST_NO_FRIEND_KOENIG_LOOKUP
# endif
#if defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730
# define BOOST_NO_FRIEND_KOENIG_LOOKUP
# endif
# if defined(BOOST_NO_FRIEND_KOENIG_LOOKUP)
// for compilers that do not support Koenig lookup for friend functions
# define BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
# define BOOST_PYTHON_END_CONVERSION_NAMESPACE
# else
// for compilers that support Koenig lookup
# define BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE namespace boost { namespace python {
# define BOOST_PYTHON_END_CONVERSION_NAMESPACE }} // namespace boost::python
# endif
// Work around the broken library implementation/strict ansi checking on some
// EDG-based compilers (e.g. alpha), which incorrectly warn that the result of
// offsetof() is not an integer constant expression.
@@ -57,7 +68,7 @@
# define BOOST_CSTD_ std
# endif
#if defined(_WIN32) || defined(__CYGWIN__)
#ifdef _WIN32
# define BOOST_PYTHON_MODULE_INIT(name) extern "C" __declspec(dllexport) void init##name()
#else
# define BOOST_PYTHON_MODULE_INIT(name) extern "C" void init##name()

View File

@@ -1,4 +1,4 @@
// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and
// (C) Copyright David Abrahams 2000-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.
@@ -179,32 +179,33 @@ template <class T, class U = boost::python::detail::held_instance<T> >
class python_extension_class_converters
{
public:
// Get an object which can be used to convert T to/from python. This is used
// as a kind of concept check by the global template
//
// PyObject* to_python(const T& x)
//
// below this class, to prevent the confusing messages that would otherwise
// pop up. Now, if T hasn't been wrapped as an extension class, the user
// will see an error message about the lack of an eligible
// py_extension_class_converters() function.
friend python_extension_class_converters py_extension_class_converters(boost::python::type<T>)
/// Get an object which can be used to convert T to/from python. This is used
/// as a kind of concept check by the free template function
///
/// PyObject* to_python(const T& x, boost::python::lookup_tag)
///
/// below this class, to prevent the confusing messages that would otherwise
/// pop up. Now, if T hasn't been wrapped as an extension class, the user
/// will see an error message about the lack of an eligible
/// py_extension_class_converters() function.
friend python_extension_class_converters py_extension_class_converters(
boost::python::type<T>)
{
return python_extension_class_converters();
}
// This is a member function because in a conforming implementation, friend
// funcitons defined inline in the class body are all instantiated as soon
// as the enclosing class is instantiated. If T is not copyable, that causes
// a compiler error. Instead, we access this function through the global
// template
//
// PyObject* to_python(const T& x)
//
// defined below this class. Since template functions are instantiated only
// on demand, errors will be avoided unless T is noncopyable and the user
// writes code which causes us to try to copy a T.
PyObject* to_python(const T& x) const
/// This is a member function because in a conforming implementation, friend
/// functions defined inline in the class body are all instantiated as soon
/// as the enclosing class is instantiated. If T is not copyable, that causes
/// a compiler error. Instead, we access this function through the global
/// template
///
/// PyObject* to_python(const T& x, boost::python::lookup_tag)
///
/// defined below this class. Since template functions are instantiated only
/// on demand, errors will be avoided unless T is noncopyable and the user
/// writes code which causes us to try to copy a T.
PyObject* m_to_python(const T& x) const
{
boost::python::reference<boost::python::detail::extension_instance> result(create_instance());
result->add_implementation(
@@ -213,6 +214,7 @@ class python_extension_class_converters
return result.release();
}
/// Extract a pointer to T from the given PyObject. Will throw argument_error if obj == None.
friend
T* non_null_from_python(PyObject* obj, boost::python::type<T*>)
{
@@ -235,16 +237,14 @@ class python_extension_class_converters
throw boost::python::argument_error();
}
// Convert to T*
/// Convert obj to T*. If obj == None, returns 0.
friend T* from_python(PyObject* obj, boost::python::type<T*>)
{
if (obj == Py_None)
return 0;
else
return non_null_from_python(obj, boost::python::type<T*>());
if (obj == Py_None) return 0;
return non_null_from_python(obj, boost::python::type<T*>());
}
// Extract from obj a mutable reference to the PtrType object which is holding a T.
/// Extract from obj a mutable reference to the PtrType object which is holding a T.
template <class PtrType>
static PtrType& smart_ptr_reference(PyObject* obj, boost::python::type<PtrType>)
{
@@ -263,10 +263,10 @@ class python_extension_class_converters
throw boost::python::argument_error();
}
// Extract from obj a reference to the PtrType object which is holding a
// T. If it weren't for auto_ptr, it would be a constant reference. Do not
// modify the referent except by copying an auto_ptr! If obj is None, the
// reference denotes a default-constructed PtrType
/// Extract from obj a reference to the PtrType object which is holding a
/// T. If it weren't for auto_ptr, it would be a constant reference. Do not
/// modify the referent except by copying an auto_ptr! If obj is None, the
/// reference denotes a default-constructed PtrType
template <class PtrType>
static PtrType& smart_ptr_value(PyObject* obj, boost::python::type<PtrType>)
{
@@ -277,7 +277,9 @@ class python_extension_class_converters
}
return smart_ptr_reference(obj, boost::python::type<PtrType>());
}
/// Wrap x in a Python object which implements the functionality of a
/// regular wrapped T by dereferencing a copy of x.
template <class PtrType>
static PyObject* smart_ptr_to_python(PtrType x)
{
@@ -293,6 +295,9 @@ class python_extension_class_converters
return result.release();
}
/// Create a Python object which is an instance of the Python type wrapper
/// for T. The result does not actually contain the neccessary instance of
/// T. This function is an implementation detail.
static boost::python::reference<boost::python::detail::extension_instance> create_instance()
{
PyTypeObject* class_object = boost::python::detail::class_registry<T>::class_object();
@@ -303,15 +308,15 @@ class python_extension_class_converters
new boost::python::detail::extension_instance(class_object));
}
// Convert to const T*
/// Convert p to const T*
friend const T* from_python(PyObject* p, boost::python::type<const T*>)
{ return from_python(p, boost::python::type<T*>()); }
// Convert to const T* const&
/// Convert p to const T* const&
friend const T* from_python(PyObject* p, boost::python::type<const T*const&>)
{ return from_python(p, boost::python::type<const T*>()); }
// Convert to T* const&
/// Convert p to T* const&
friend T* from_python(PyObject* p, boost::python::type<T* const&>)
{ return from_python(p, boost::python::type<T*>()); }
@@ -319,11 +324,11 @@ class python_extension_class_converters
friend T& from_python(PyObject* p, boost::python::type<T&>)
{ return *boost::python::detail::check_non_null(non_null_from_python(p, boost::python::type<T*>())); }
// Convert to const T&
// Convert p to const T&
friend const T& from_python(PyObject* p, boost::python::type<const T&>)
{ return from_python(p, boost::python::type<T&>()); }
// Convert to T
/// Convert p to T
friend const T& from_python(PyObject* p, boost::python::type<T>)
{ return from_python(p, boost::python::type<T&>()); }
@@ -336,7 +341,7 @@ class python_extension_class_converters
friend const std::auto_ptr<T>& from_python(PyObject* p, boost::python::type<const std::auto_ptr<T>&>)
{ return smart_ptr_value(p, boost::python::type<std::auto_ptr<T> >()); }
friend PyObject* to_python(std::auto_ptr<T> x)
friend PyObject* to_python(std::auto_ptr<T> x, boost::python::lookup_tag)
{ return smart_ptr_to_python(x); }
friend boost::shared_ptr<T>& from_python(PyObject* p, boost::python::type<boost::shared_ptr<T>&>)
@@ -348,7 +353,7 @@ class python_extension_class_converters
friend const boost::shared_ptr<T>& from_python(PyObject* p, boost::python::type<const boost::shared_ptr<T>&>)
{ return smart_ptr_value(p, boost::python::type<boost::shared_ptr<T> >()); }
friend PyObject* to_python(boost::shared_ptr<T> x)
friend PyObject* to_python(boost::shared_ptr<T> x, boost::python::lookup_tag)
{ return smart_ptr_to_python(x); }
};
@@ -357,17 +362,15 @@ class python_extension_class_converters
// T is a wrapped class. See the first 2 functions declared in
// python_extension_class_converters above for more info.
template <class T>
PyObject* to_python(const T& x)
PyObject* to_python(const T& x, boost::python::lookup_tag)
{
return py_extension_class_converters(boost::python::type<T>()).to_python(x);
return py_extension_class_converters(boost::python::type<T>()).m_to_python(x);
}
BOOST_PYTHON_END_CONVERSION_NAMESPACE
namespace boost { namespace python {
BOOST_PYTHON_IMPORT_CONVERSION(python_extension_class_converters);
namespace detail {
template <class T> class instance_holder;
@@ -616,12 +619,6 @@ class extension_class
choose_op<(which & op_and)>::template args<Operand>::add(this);
choose_op<(which & op_xor)>::template args<Operand>::add(this);
choose_op<(which & op_or)>::template args<Operand>::add(this);
choose_op<(which & op_gt)>::template args<Operand>::add(this);
choose_op<(which & op_ge)>::template args<Operand>::add(this);
choose_op<(which & op_lt)>::template args<Operand>::add(this);
choose_op<(which & op_le)>::template args<Operand>::add(this);
choose_op<(which & op_eq)>::template args<Operand>::add(this);
choose_op<(which & op_ne)>::template args<Operand>::add(this);
choose_unary_op<(which & op_neg)>::template args<Operand>::add(this);
choose_unary_op<(which & op_pos)>::template args<Operand>::add(this);
choose_unary_op<(which & op_abs)>::template args<Operand>::add(this);
@@ -651,12 +648,6 @@ class extension_class
choose_op<(which & op_xor)>::template args<Left,Right>::add(this);
choose_op<(which & op_or)>::template args<Left,Right>::add(this);
choose_op<(which & op_cmp)>::template args<Left,Right>::add(this);
choose_op<(which & op_gt)>::template args<Left,Right>::add(this);
choose_op<(which & op_ge)>::template args<Left,Right>::add(this);
choose_op<(which & op_lt)>::template args<Left,Right>::add(this);
choose_op<(which & op_le)>::template args<Left,Right>::add(this);
choose_op<(which & op_eq)>::template args<Left,Right>::add(this);
choose_op<(which & op_ne)>::template args<Left,Right>::add(this);
}
template <long which, class Left, class Right>

View File

@@ -95,8 +95,9 @@ struct raw_arguments_function : function
ref(PyDict_New()));
return to_python(
(*m_pf)(from_python(args, boost::python::type<Args>()),
from_python(dict.get(), boost::python::type<Keywords>())));
(*m_pf)(from_python(args, type<Args>()),
from_python(dict.get(), type<Keywords>())),
lookup_tag());
}
const char* description() const
@@ -263,8 +264,8 @@ PyObject* getter_function<ClassType, MemberType>::do_call(
if (!PyArg_ParseTuple(args, const_cast<char*>("O"), &self))
return 0;
return to_python(
from_python(self, type<const ClassType*>())->*m_pm);
return to_python(from_python(self, type<const ClassType*>())->*m_pm,
lookup_tag());
}
template <class ClassType, class MemberType>

View File

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

View File

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

View File

@@ -297,7 +297,7 @@ struct list::slice_proxy
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
PyObject* to_python(const boost::python::tuple&);
PyObject* to_python(const boost::python::tuple&, boost::python::lookup_tag);
boost::python::tuple from_python(PyObject* p, boost::python::type<boost::python::tuple>);
inline boost::python::tuple from_python(PyObject* p, boost::python::type<const boost::python::tuple&>)
@@ -305,7 +305,7 @@ inline boost::python::tuple from_python(PyObject* p, boost::python::type<const b
return from_python(p, boost::python::type<boost::python::tuple>());
}
PyObject* to_python(const boost::python::list&);
PyObject* to_python(const boost::python::list&, boost::python::lookup_tag);
boost::python::list from_python(PyObject* p, boost::python::type<boost::python::list>);
inline boost::python::list from_python(PyObject* p, boost::python::type<const boost::python::list&>)
@@ -313,7 +313,7 @@ inline boost::python::list from_python(PyObject* p, boost::python::type<const bo
return from_python(p, boost::python::type<boost::python::list>());
}
PyObject* to_python(const boost::python::string&);
PyObject* to_python(const boost::python::string&, boost::python::lookup_tag);
boost::python::string from_python(PyObject* p, boost::python::type<boost::python::string>);
inline boost::python::string from_python(PyObject* p, boost::python::type<const boost::python::string&>)
@@ -321,7 +321,7 @@ inline boost::python::string from_python(PyObject* p, boost::python::type<const
return from_python(p, boost::python::type<boost::python::string>());
}
PyObject* to_python(const boost::python::dictionary&);
PyObject* to_python(const boost::python::dictionary&, boost::python::lookup_tag);
boost::python::dictionary from_python(PyObject* p, boost::python::type<boost::python::dictionary>);
inline boost::python::dictionary from_python(PyObject* p, boost::python::type<const boost::python::dictionary&>)

View File

@@ -65,13 +65,7 @@ enum operator_id
op_long = 0x20000,
op_float = 0x40000,
op_str = 0x80000,
op_cmp = 0x100000,
op_gt = 0x200000,
op_ge = 0x400000,
op_lt = 0x800000,
op_le = 0x1000000,
op_eq = 0x2000000,
op_ne = 0x4000000
op_cmp = 0x100000
};
// Wrap the operators given by "which". Usage:
@@ -243,11 +237,11 @@ namespace detail
{ \
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const \
{ \
tuple args(ref(arguments, ref::increment_count)); \
tuple args(ref(arguments, ref::increment_count)); \
\
return BOOST_PYTHON_CONVERSION::to_python( \
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Left>()) oper \
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Right>())); \
return to_python( \
from_python(args[0].get(), type<Left>()) oper \
from_python(args[1].get(), type<Right>()), lookup_tag()); \
} \
\
const char* description() const \
@@ -259,11 +253,11 @@ namespace detail
{ \
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const \
{ \
tuple args(ref(arguments, ref::increment_count)); \
tuple args(ref(arguments, ref::increment_count)); \
\
return BOOST_PYTHON_CONVERSION::to_python( \
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Left>()) oper \
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Right>())); \
return to_python( \
from_python(args[1].get(), type<Left>()) oper \
from_python(args[0].get(), type<Right>()), lookup_tag()); \
} \
\
const char* description() const \
@@ -284,10 +278,10 @@ namespace detail
{ \
PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const \
{ \
tuple args(ref(arguments, ref::increment_count)); \
tuple args(ref(arguments, ref::increment_count)); \
\
return BOOST_PYTHON_CONVERSION::to_python( \
oper(BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<operand>()))); \
return to_python( \
oper(from_python(args[0].get(), type<operand>())), lookup_tag()); \
} \
\
const char* description() const \
@@ -307,12 +301,6 @@ namespace detail
PY_DEFINE_BINARY_OPERATORS(and, &);
PY_DEFINE_BINARY_OPERATORS(xor, ^);
PY_DEFINE_BINARY_OPERATORS(or, |);
PY_DEFINE_BINARY_OPERATORS(gt, >);
PY_DEFINE_BINARY_OPERATORS(ge, >=);
PY_DEFINE_BINARY_OPERATORS(lt, <);
PY_DEFINE_BINARY_OPERATORS(le, <=);
PY_DEFINE_BINARY_OPERATORS(eq, ==);
PY_DEFINE_BINARY_OPERATORS(ne, !=);
PY_DEFINE_UNARY_OPERATORS(neg, -);
PY_DEFINE_UNARY_OPERATORS(pos, +);
@@ -347,9 +335,9 @@ namespace detail
throw argument_error();
}
return BOOST_PYTHON_CONVERSION::to_python(
pow(BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Left>()),
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Right>())));
return to_python(
pow(from_python(args[0].get(), type<Left>()),
from_python(args[1].get(), type<Right>())), lookup_tag());
}
const char* description() const
@@ -370,9 +358,9 @@ namespace detail
throw argument_error();
}
return BOOST_PYTHON_CONVERSION::to_python(
pow(BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Left>()),
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Right>())));
return to_python(
pow(from_python(args[1].get(), type<Left>()),
from_python(args[0].get(), type<Right>())), lookup_tag());
}
const char* description() const
@@ -398,13 +386,11 @@ namespace detail
PyObject * res = PyTuple_New(2);
PyTuple_SET_ITEM(res, 0,
BOOST_PYTHON_CONVERSION::to_python(
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Left>()) /
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Right>())));
to_python(from_python(args[0].get(), type<Left>()) /
from_python(args[1].get(), type<Right>()), lookup_tag()));
PyTuple_SET_ITEM(res, 1,
BOOST_PYTHON_CONVERSION::to_python(
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Left>()) %
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Right>())));
to_python(from_python(args[0].get(), type<Left>()) %
from_python(args[1].get(), type<Right>()), lookup_tag()));
return res;
}
@@ -423,13 +409,11 @@ namespace detail
PyObject * res = PyTuple_New(2);
PyTuple_SET_ITEM(res, 0,
BOOST_PYTHON_CONVERSION::to_python(
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Left>()) /
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Right>())));
to_python(from_python(args[1].get(), type<Left>()) /
from_python(args[0].get(), type<Right>()), lookup_tag()));
PyTuple_SET_ITEM(res, 1,
BOOST_PYTHON_CONVERSION::to_python(
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Left>()) %
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Right>())));
to_python(from_python(args[1].get(), type<Left>()) %
from_python(args[0].get(), type<Right>()), lookup_tag()));
return res;
}
@@ -455,14 +439,14 @@ namespace detail
{
tuple args(ref(arguments, ref::increment_count));
return BOOST_PYTHON_CONVERSION::to_python(
(BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Left>()) <
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Right>())) ?
return to_python(
(from_python(args[0].get(), type<Left>()) <
from_python(args[1].get(), type<Right>())) ?
- 1 :
(BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Right>()) <
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Left>())) ?
(from_python(args[1].get(), type<Right>()) <
from_python(args[0].get(), type<Left>())) ?
1 :
0) ;
0, lookup_tag()) ;
}
const char* description() const
@@ -477,14 +461,14 @@ namespace detail
{
tuple args(ref(arguments, ref::increment_count));
return BOOST_PYTHON_CONVERSION::to_python(
(BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Left>()) <
BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Right>())) ?
return to_python(
(from_python(args[1].get(), type<Left>()) <
from_python(args[0].get(), type<Right>())) ?
- 1 :
(BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<Right>()) <
BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<Left>())) ?
(from_python(args[0].get(), type<Right>()) <
from_python(args[1].get(), type<Left>())) ?
1 :
0) ;
0, lookup_tag()) ;
}
const char* description() const
@@ -522,13 +506,13 @@ namespace detail
// _STL::string, but std::string.
# ifdef BOOST_PYTHON_USE_SSTREAM
std::ostringstream s;
s << BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<operand>());
return BOOST_PYTHON_CONVERSION::to_python(s.str());
s << from_python(args[0].get(), type<operand>());
return to_python(s.str(), lookup_tag());
# else
std::ostrstream s;
s << BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<operand>()) << char();
s << from_python(args[0].get(), type<operand>()) << char();
auto unfreezer unfreeze(s);
return BOOST_PYTHON_CONVERSION::to_python(const_cast<char const *>(s.str()));
return to_python(const_cast<char const *>(s.str()), lookup_tag());
# endif
}

View File

@@ -29,7 +29,7 @@ struct py_ptr_conversions : Base
inline friend T from_python(PyObject* x, boost::python::type<T>)
{ return T(boost::python::downcast<Value>(x).get(), T::increment_count); }
inline friend PyObject* to_python(T x)
inline friend PyObject* to_python(T x, boost::python::lookup_tag)
{ return boost::python::as_object(x.release()); }
};
@@ -38,8 +38,6 @@ BOOST_PYTHON_END_CONVERSION_NAMESPACE
namespace boost { namespace python {
BOOST_PYTHON_IMPORT_CONVERSION(py_ptr_conversions);
template <class T>
class reference
: public py_ptr_conversions<reference<T>, T,
@@ -165,7 +163,7 @@ typedef reference<PyObject> ref;
template <class T>
ref make_ref(const T& x)
{
return ref(to_python(x));
return ref(to_python(x, lookup_tag()));
}
}} // namespace boost::python

View File

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

View File

@@ -142,7 +142,7 @@ PyObject* integer_to_python(T value)
throw boost::python::error_already_set();
}
return to_python(value_as_long);
return to_python(value_as_long, boost::python::lookup_tag());
}
int from_python(PyObject* p, boost::python::type<int> type)
@@ -150,7 +150,7 @@ int from_python(PyObject* p, boost::python::type<int> type)
return integer_from_python(p, type);
}
PyObject* to_python(unsigned int i)
PyObject* to_python(unsigned int i, boost::python::lookup_tag)
{
return integer_to_python(i);
}
@@ -170,7 +170,7 @@ float from_python(PyObject* p, boost::python::type<float>)
return static_cast<float>(from_python(p, boost::python::type<double>()));
}
PyObject* to_python(unsigned short i)
PyObject* to_python(unsigned short i, boost::python::lookup_tag)
{
return integer_to_python(i);
}
@@ -180,7 +180,7 @@ unsigned short from_python(PyObject* p, boost::python::type<unsigned short> type
return integer_from_python(p, type);
}
PyObject* to_python(char c)
PyObject* to_python(char c, boost::python::lookup_tag)
{
if (c == '\0') return PyString_FromString("");
return PyString_FromStringAndSize(&c, 1);
@@ -198,7 +198,7 @@ char from_python(PyObject* p, boost::python::type<char>)
return PyString_AsString(p)[0];
}
PyObject* to_python(unsigned char i)
PyObject* to_python(unsigned char i, boost::python::lookup_tag)
{
return integer_to_python(i);
}
@@ -208,7 +208,7 @@ unsigned char from_python(PyObject* p, boost::python::type<unsigned char> type)
return integer_from_python(p, type);
}
PyObject* to_python(signed char i)
PyObject* to_python(signed char i, boost::python::lookup_tag)
{
return integer_to_python(i);
}
@@ -218,7 +218,7 @@ signed char from_python(PyObject* p, boost::python::type<signed char> type)
return integer_from_python(p, type);
}
PyObject* to_python(unsigned long x)
PyObject* to_python(unsigned long x, boost::python::lookup_tag)
{
return integer_to_python(x);
}
@@ -244,7 +244,7 @@ const char* from_python(PyObject* p, boost::python::type<const char*>)
return s;
}
PyObject* to_python(const std::string& s)
PyObject* to_python(const std::string& s, boost::python::lookup_tag)
{
return PyString_FromStringAndSize(s.data(), s.size());
}
@@ -268,12 +268,12 @@ bool from_python(PyObject* p, boost::python::type<bool>)
#ifdef BOOST_MSVC6_OR_EARLIER
// An optimizer bug prevents these from being inlined.
PyObject* to_python(double d)
PyObject* to_python(double d, boost::python::lookup_tag)
{
return PyFloat_FromDouble(d);
}
PyObject* to_python(float f)
PyObject* to_python(float f, boost::python::lookup_tag)
{
return PyFloat_FromDouble(f);
}

View File

@@ -42,7 +42,7 @@ namespace detail {
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
inline PyObject* to_python(boost::python::detail::operator_dispatcher* n) { return n; }
inline PyObject* to_python(boost::python::detail::operator_dispatcher* n, boost::python::lookup_tag) { return n; }
BOOST_PYTHON_END_CONVERSION_NAMESPACE
@@ -608,7 +608,7 @@ int operator_dispatcher_call_cmp(PyObject* left, PyObject* right)
{
try
{
return BOOST_PYTHON_CONVERSION::from_python(result, type<int>());
return from_python(result, type<int>());
}
catch(...)
{

View File

@@ -38,7 +38,7 @@ struct callback
%{ template <%(class A%n%:, %)>
%} static R call_method(PyObject* self, const char* name%(, const A%n& a%n%))
{%(
ref p%n(to_python(a%n));%)
ref p%n(to_python(a%n, lookup_tag()));%)
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(%(O%))")%(,
p%n.get()%)));
@@ -49,7 +49,7 @@ struct callback
%{ template <%(class A%n%:, %)>
%} static R call(PyObject* self%(, const A%n& a%n%))
{%(
ref p%n(to_python(a%n));%)
ref p%n(to_python(a%n, lookup_tag()));%)
ref result(PyEval_CallFunction(self, const_cast<char*>("(%(O%))")%(,
p%n.get()%)));
detail::callback_adjust_refcount(result.get(), type<R>());
@@ -70,7 +70,7 @@ struct callback<void>
%{ template <%(class A%n%:, %)>
%} static void call_method(PyObject* self, const char* name%(, const A%n& a%n%))
{%(
ref p%n(to_python(a%n));%)
ref p%n(to_python(a%n, lookup_tag()));%)
ref result(PyEval_CallMethod(self, const_cast<char*>(name),
const_cast<char*>("(%(O%))")%(,
p%n.get()%)));
@@ -79,7 +79,7 @@ struct callback<void>
%{ template <%(class A%n%:, %)>
%} static void call(PyObject* self%(, const A%n& a%n%))
{%(
ref p%n(to_python(a%n));%)
ref p%n(to_python(a%n, lookup_tag()));%)
ref result(PyEval_CallFunction(self, const_cast<char*>("(%(O%))")%(,
p%n.get()%)));
}

View File

@@ -97,14 +97,14 @@ def gen_caller(member_function_args, free_function_args = None):
return (header % (member_function_args, free_function_args)
+ body_sections[0]
+ gen_functions(member_function, member_function_args,
'R', '', 'return to_python(', ');')
'R', '', 'return to_python(', ', lookup_tag());')
+ body_sections[1]
+ gen_functions(member_function, member_function_args,
'R', ' const', 'return to_python(', ');')
'R', ' const', 'return to_python(', ', lookup_tag());')
+ body_sections[2]
+ gen_functions(free_function, free_function_args,
'R', 'return to_python(', ');')
'R', 'return to_python(', ', lookup_tag());')
+ body_sections[3]
# specialized part for void return values begins here

View File

@@ -3,7 +3,7 @@ import string
def gen_extclass(args):
return (
"""// (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and
"""// (C) Copyright David Abrahams 2000-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.
@@ -184,32 +184,33 @@ template <class T, class U = boost::python::detail::held_instance<T> >
class python_extension_class_converters
{
public:
// Get an object which can be used to convert T to/from python. This is used
// as a kind of concept check by the global template
//
// PyObject* to_python(const T& x)
//
// below this class, to prevent the confusing messages that would otherwise
// pop up. Now, if T hasn't been wrapped as an extension class, the user
// will see an error message about the lack of an eligible
// py_extension_class_converters() function.
friend python_extension_class_converters py_extension_class_converters(boost::python::type<T>)
/// Get an object which can be used to convert T to/from python. This is used
/// as a kind of concept check by the free template function
///
/// PyObject* to_python(const T& x, boost::python::lookup_tag)
///
/// below this class, to prevent the confusing messages that would otherwise
/// pop up. Now, if T hasn't been wrapped as an extension class, the user
/// will see an error message about the lack of an eligible
/// py_extension_class_converters() function.
friend python_extension_class_converters py_extension_class_converters(
boost::python::type<T>)
{
return python_extension_class_converters();
}
// This is a member function because in a conforming implementation, friend
// funcitons defined inline in the class body are all instantiated as soon
// as the enclosing class is instantiated. If T is not copyable, that causes
// a compiler error. Instead, we access this function through the global
// template
//
// PyObject* to_python(const T& x)
//
// defined below this class. Since template functions are instantiated only
// on demand, errors will be avoided unless T is noncopyable and the user
// writes code which causes us to try to copy a T.
PyObject* to_python(const T& x) const
/// This is a member function because in a conforming implementation, friend
/// functions defined inline in the class body are all instantiated as soon
/// as the enclosing class is instantiated. If T is not copyable, that causes
/// a compiler error. Instead, we access this function through the global
/// template
///
/// PyObject* to_python(const T& x, boost::python::lookup_tag)
///
/// defined below this class. Since template functions are instantiated only
/// on demand, errors will be avoided unless T is noncopyable and the user
/// writes code which causes us to try to copy a T.
PyObject* m_to_python(const T& x) const
{
boost::python::reference<boost::python::detail::extension_instance> result(create_instance());
result->add_implementation(
@@ -218,6 +219,7 @@ class python_extension_class_converters
return result.release();
}
/// Extract a pointer to T from the given PyObject. Will throw argument_error if obj == None.
friend
T* non_null_from_python(PyObject* obj, boost::python::type<T*>)
{
@@ -240,16 +242,14 @@ class python_extension_class_converters
throw boost::python::argument_error();
}
// Convert to T*
/// Convert obj to T*. If obj == None, returns 0.
friend T* from_python(PyObject* obj, boost::python::type<T*>)
{
if (obj == Py_None)
return 0;
else
return non_null_from_python(obj, boost::python::type<T*>());
if (obj == Py_None) return 0;
return non_null_from_python(obj, boost::python::type<T*>());
}
// Extract from obj a mutable reference to the PtrType object which is holding a T.
/// Extract from obj a mutable reference to the PtrType object which is holding a T.
template <class PtrType>
static PtrType& smart_ptr_reference(PyObject* obj, boost::python::type<PtrType>)
{
@@ -268,10 +268,10 @@ class python_extension_class_converters
throw boost::python::argument_error();
}
// Extract from obj a reference to the PtrType object which is holding a
// T. If it weren't for auto_ptr, it would be a constant reference. Do not
// modify the referent except by copying an auto_ptr! If obj is None, the
// reference denotes a default-constructed PtrType
/// Extract from obj a reference to the PtrType object which is holding a
/// T. If it weren't for auto_ptr, it would be a constant reference. Do not
/// modify the referent except by copying an auto_ptr! If obj is None, the
/// reference denotes a default-constructed PtrType
template <class PtrType>
static PtrType& smart_ptr_value(PyObject* obj, boost::python::type<PtrType>)
{
@@ -282,7 +282,9 @@ class python_extension_class_converters
}
return smart_ptr_reference(obj, boost::python::type<PtrType>());
}
/// Wrap x in a Python object which implements the functionality of a
/// regular wrapped T by dereferencing a copy of x.
template <class PtrType>
static PyObject* smart_ptr_to_python(PtrType x)
{
@@ -298,6 +300,9 @@ class python_extension_class_converters
return result.release();
}
/// Create a Python object which is an instance of the Python type wrapper
/// for T. The result does not actually contain the neccessary instance of
/// T. This function is an implementation detail.
static boost::python::reference<boost::python::detail::extension_instance> create_instance()
{
PyTypeObject* class_object = boost::python::detail::class_registry<T>::class_object();
@@ -308,15 +313,15 @@ class python_extension_class_converters
new boost::python::detail::extension_instance(class_object));
}
// Convert to const T*
/// Convert p to const T*
friend const T* from_python(PyObject* p, boost::python::type<const T*>)
{ return from_python(p, boost::python::type<T*>()); }
// Convert to const T* const&
/// Convert p to const T* const&
friend const T* from_python(PyObject* p, boost::python::type<const T*const&>)
{ return from_python(p, boost::python::type<const T*>()); }
// Convert to T* const&
/// Convert p to T* const&
friend T* from_python(PyObject* p, boost::python::type<T* const&>)
{ return from_python(p, boost::python::type<T*>()); }
@@ -324,11 +329,11 @@ class python_extension_class_converters
friend T& from_python(PyObject* p, boost::python::type<T&>)
{ return *boost::python::detail::check_non_null(non_null_from_python(p, boost::python::type<T*>())); }
// Convert to const T&
// Convert p to const T&
friend const T& from_python(PyObject* p, boost::python::type<const T&>)
{ return from_python(p, boost::python::type<T&>()); }
// Convert to T
/// Convert p to T
friend const T& from_python(PyObject* p, boost::python::type<T>)
{ return from_python(p, boost::python::type<T&>()); }
@@ -341,7 +346,7 @@ class python_extension_class_converters
friend const std::auto_ptr<T>& from_python(PyObject* p, boost::python::type<const std::auto_ptr<T>&>)
{ return smart_ptr_value(p, boost::python::type<std::auto_ptr<T> >()); }
friend PyObject* to_python(std::auto_ptr<T> x)
friend PyObject* to_python(std::auto_ptr<T> x, boost::python::lookup_tag)
{ return smart_ptr_to_python(x); }
friend boost::shared_ptr<T>& from_python(PyObject* p, boost::python::type<boost::shared_ptr<T>&>)
@@ -353,7 +358,7 @@ class python_extension_class_converters
friend const boost::shared_ptr<T>& from_python(PyObject* p, boost::python::type<const boost::shared_ptr<T>&>)
{ return smart_ptr_value(p, boost::python::type<boost::shared_ptr<T> >()); }
friend PyObject* to_python(boost::shared_ptr<T> x)
friend PyObject* to_python(boost::shared_ptr<T> x, boost::python::lookup_tag)
{ return smart_ptr_to_python(x); }
};
@@ -362,17 +367,15 @@ class python_extension_class_converters
// T is a wrapped class. See the first 2 functions declared in
// python_extension_class_converters above for more info.
template <class T>
PyObject* to_python(const T& x)
PyObject* to_python(const T& x, boost::python::lookup_tag)
{
return py_extension_class_converters(boost::python::type<T>()).to_python(x);
return py_extension_class_converters(boost::python::type<T>()).m_to_python(x);
}
BOOST_PYTHON_END_CONVERSION_NAMESPACE
namespace boost { namespace python {
BOOST_PYTHON_IMPORT_CONVERSION(python_extension_class_converters);
namespace detail {
template <class T> class instance_holder;
@@ -616,12 +619,6 @@ class extension_class
choose_op<(which & op_and)>::template args<Operand>::add(this);
choose_op<(which & op_xor)>::template args<Operand>::add(this);
choose_op<(which & op_or)>::template args<Operand>::add(this);
choose_op<(which & op_gt)>::template args<Operand>::add(this);
choose_op<(which & op_ge)>::template args<Operand>::add(this);
choose_op<(which & op_lt)>::template args<Operand>::add(this);
choose_op<(which & op_le)>::template args<Operand>::add(this);
choose_op<(which & op_eq)>::template args<Operand>::add(this);
choose_op<(which & op_ne)>::template args<Operand>::add(this);
choose_unary_op<(which & op_neg)>::template args<Operand>::add(this);
choose_unary_op<(which & op_pos)>::template args<Operand>::add(this);
choose_unary_op<(which & op_abs)>::template args<Operand>::add(this);
@@ -651,12 +648,6 @@ class extension_class
choose_op<(which & op_xor)>::template args<Left,Right>::add(this);
choose_op<(which & op_or)>::template args<Left,Right>::add(this);
choose_op<(which & op_cmp)>::template args<Left,Right>::add(this);
choose_op<(which & op_gt)>::template args<Left,Right>::add(this);
choose_op<(which & op_ge)>::template args<Left,Right>::add(this);
choose_op<(which & op_lt)>::template args<Left,Right>::add(this);
choose_op<(which & op_le)>::template args<Left,Right>::add(this);
choose_op<(which & op_eq)>::template args<Left,Right>::add(this);
choose_op<(which & op_ne)>::template args<Left,Right>::add(this);
}
template <long which, class Left, class Right>

View File

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

View File

@@ -49,9 +49,9 @@ PyObject* object::get() const
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
PyObject* to_python(const boost::python::tuple& x)
PyObject* to_python(const boost::python::tuple& x, boost::python::lookup_tag)
{
return object_to_python(x);
return boost::python::object_to_python(x);
}
boost::python::tuple from_python(PyObject* p, boost::python::type<boost::python::tuple> type)
@@ -59,9 +59,9 @@ boost::python::tuple from_python(PyObject* p, boost::python::type<boost::python:
return boost::python::object_from_python(p, type);
}
PyObject* to_python(const boost::python::list& x)
PyObject* to_python(const boost::python::list& x, boost::python::lookup_tag)
{
return object_to_python(x);
return boost::python::object_to_python(x);
}
boost::python::list from_python(PyObject* p, boost::python::type<boost::python::list> type)
@@ -69,9 +69,9 @@ boost::python::list from_python(PyObject* p, boost::python::type<boost::python::
return boost::python::object_from_python(p, type);
}
PyObject* to_python(const boost::python::dictionary& x)
PyObject* to_python(const boost::python::dictionary& x, boost::python::lookup_tag)
{
return object_to_python(x);
return boost::python::object_to_python(x);
}
boost::python::dictionary from_python(PyObject* p, boost::python::type<boost::python::dictionary> type)
@@ -79,9 +79,9 @@ boost::python::dictionary from_python(PyObject* p, boost::python::type<boost::py
return boost::python::object_from_python(p, type);
}
PyObject* to_python(const boost::python::string& x)
PyObject* to_python(const boost::python::string& x, boost::python::lookup_tag)
{
return object_to_python(x);
return boost::python::object_to_python(x);
}
boost::python::string from_python(PyObject* p, boost::python::type<boost::python::string> type)

View File

@@ -159,28 +159,6 @@ static PyObject* do_instance_repr(PyObject* obj)
return call(obj, &type_object_base::instance_repr);
}
static PyObject* do_instance_richcompare(PyObject* obj, PyObject* other, int d)
{
#if PYTHON_API_VERSION >= 1010
switch(d)
{
case Py_LT:
return call(obj, &type_object_base::instance_lt, other);
case Py_LE:
return call(obj, &type_object_base::instance_le, other);
case Py_EQ:
return call(obj, &type_object_base::instance_eq, other);
case Py_NE:
return call(obj, &type_object_base::instance_ne, other);
case Py_GT:
return call(obj, &type_object_base::instance_gt, other);
case Py_GE:
return call(obj, &type_object_base::instance_ge, other);
}
#endif
return 0;
}
static int do_instance_compare(PyObject* obj, PyObject* other)
{
return call(obj, &type_object_base::instance_compare, other);
@@ -428,7 +406,7 @@ namespace
bool add_capability_general(type_object_base::capability capability, PyTypeObject* dest)
{
assert(dest != 0);
switch(capability)
{
ENABLE_GENERAL_CAPABILITY(hash);
@@ -457,20 +435,6 @@ void create_method_table_if_null(T*& table)
}
}
bool add_capability_richcompare(type_object_base::capability capability, PyTypeObject* dest)
{
assert(dest != 0);
if (capability == type_object_base::richcompare) {
#if PYTHON_API_VERSION >= 1010
dest->tp_richcompare = &do_instance_richcompare;
dest->tp_flags |= Py_TPFLAGS_HAVE_RICHCOMPARE;
#endif
return true;
}
return false;
}
#define ENABLE_MAPPING_CAPABILITY(field) \
case type_object_base::mapping_##field: \
create_method_table_if_null(dest); \
@@ -584,8 +548,6 @@ namespace detail {
{
if(add_capability_general(capability, dest_))
return;
if(add_capability_richcompare(capability, dest_))
return;
if(add_capability_mapping(capability, dest_->tp_as_mapping))
return;
if(add_capability_sequence(capability, dest_->tp_as_sequence))
@@ -1013,36 +975,6 @@ PyObject* type_object_base::instance_number_hex(PyObject*) const
return unimplemented("instance_number_hex");
}
PyObject* type_object_base::instance_lt(PyObject*, PyObject*) const
{
return unimplemented("instance_lt");
}
PyObject* type_object_base::instance_le(PyObject*, PyObject*) const
{
return unimplemented("instance_le");
}
PyObject* type_object_base::instance_eq(PyObject*, PyObject*) const
{
return unimplemented("instance_eq");
}
PyObject* type_object_base::instance_ne(PyObject*, PyObject*) const
{
return unimplemented("instance_ne");
}
PyObject* type_object_base::instance_gt(PyObject*, PyObject*) const
{
return unimplemented("instance_gt");
}
PyObject* type_object_base::instance_ge(PyObject*, PyObject*) const
{
return unimplemented("instance_ge");
}
}} // namespace boost::python
#ifdef TYPE_OBJECT_BASE_STANDALONE_TEST

View File

@@ -15,9 +15,7 @@
#include <math.h> // for pow()
#include <boost/rational.hpp>
#if defined(__sgi) \
&& ( (defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730) \
&& !defined(__GNUC__))
#if defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 730
inline double pow(int x, int y) { return pow(static_cast<double>(x), y); }
#endif
@@ -167,7 +165,7 @@ void throw_key_error_if_end(const StringMap& m, StringMap::const_iterator p, std
{
if (p == m.end())
{
PyErr_SetObject(PyExc_KeyError, BOOST_PYTHON_CONVERSION::to_python(key));
PyErr_SetObject(PyExc_KeyError, to_python(key, boost::python::lookup_tag()));
throw boost::python::error_already_set();
}
}
@@ -748,9 +746,9 @@ namespace boost { namespace python {
}} // namespace boost::python
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
inline PyObject* to_python(const bpl_test::Record* p)
inline PyObject* to_python(const bpl_test::Record* p, boost::python::lookup_tag)
{
return to_python(*p);
return to_python(*p, boost::python::lookup_tag());
}
BOOST_PYTHON_END_CONVERSION_NAMESPACE
@@ -837,7 +835,7 @@ namespace bpl_test {
throw boost::python::error_already_set();
}
const int number = BOOST_PYTHON_CONVERSION::from_python(state[0].get(), boost::python::type<int>());
const int number = from_python(state[0].get(), boost::python::type<int>());
if (number != 42)
w.set_secret_number(number);
}
@@ -1119,13 +1117,13 @@ PyObject* raw(const boost::python::tuple& args, const boost::python::dictionary&
throw boost::python::argument_error();
}
RawTest* first = BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type<RawTest*>());
int second = BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type<int>());
RawTest* first = from_python(args[0].get(), boost::python::type<RawTest*>());
int second = from_python(args[1].get(), boost::python::type<int>());
int third = BOOST_PYTHON_CONVERSION::from_python(keywords[boost::python::string("third")].get(), boost::python::type<int>());
int fourth = BOOST_PYTHON_CONVERSION::from_python(keywords[boost::python::string("fourth")].get(), boost::python::type<int>());
int third = from_python(keywords[boost::python::string("third")].get(), boost::python::type<int>());
int fourth = from_python(keywords[boost::python::string("fourth")].get(), boost::python::type<int>());
return BOOST_PYTHON_CONVERSION::to_python(first->i_ + second + third + fourth);
return to_python(first->i_ + second + third + fourth, boost::python::lookup_tag());
}
void init_module()

View File

@@ -19,13 +19,10 @@ Load up the extension module
Automatic checking of the number and type of arguments. Foo's constructor takes
a single long parameter.
>>> try:
... ext = Foo()
... except TypeError, err:
... assert re.match(r'function .* exactly 1 argument;? \(?0 given\)?',
... str(err))
... else:
... print 'no exception'
>>> ext = Foo()
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: function requires exactly 1 argument; 0 given
>>> try: ext = Foo('foo')
... except TypeError, err:
@@ -422,7 +419,7 @@ Some simple overloading tests:
>>> try: r = Range('yikes')
... except TypeError, e:
... assert re.match(
... 'No overloaded functions match [(]Range, str[a-z]*[)]\. Candidates are:\n.*\n.*',
... 'No overloaded functions match [(]Range, string[)]\. Candidates are:\n.*\n.*',
... str(e))
... else: print 'no exception'
@@ -632,7 +629,7 @@ Testing overloaded free functions
15
>>> try: overloaded(1, 'foo')
... except TypeError, err:
... assert re.match("No overloaded functions match \(int, str[a-z]*\)\. Candidates are:",
... assert re.match("No overloaded functions match \(int, string\)\. Candidates are:",
... str(err))
... else:
... print 'no exception'
@@ -662,7 +659,7 @@ Testing overloaded constructors
5
>>> try: over = OverloadTest(1, 'foo')
... except TypeError, err:
... assert re.match("No overloaded functions match \(OverloadTest, int, str[a-z]*\)\. Candidates are:",
... assert re.match("No overloaded functions match \(OverloadTest, int, string\)\. Candidates are:",
... str(err))
... else:
... print 'no exception'
@@ -684,7 +681,7 @@ Testing overloaded methods
5
>>> try: over.overloaded(1,'foo')
... except TypeError, err:
... assert re.match("No overloaded functions match \(OverloadTest, int, str[a-z]*\)\. Candidates are:",
... assert re.match("No overloaded functions match \(OverloadTest, int, string\)\. Candidates are:",
... str(err))
... else:
... print 'no exception'
@@ -1017,12 +1014,9 @@ test inheritB2
-2
>>> str(i)
'2'
>>> try: j = i/i
... except TypeError, err:
... assert re.match(r'(bad|unsupported) operand type\(s\) for /',
... str(err))
... else: print 'no exception'
>>> j = i/i
Traceback (innermost last):
TypeError: bad operand type(s) for /
>>> j = abs(i)
Traceback (innermost last):
TypeError: bad operand type for abs()
@@ -1194,7 +1188,7 @@ def run(args = None):
if args is not None:
sys.argv = args
import doctest, comprehensive
return doctest.testmod(comprehensive)
doctest.testmod(comprehensive)
if __name__ == '__main__':
sys.exit(run()[0])
run()