Merged from branches/szager-python-builtin

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12596 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Stefan Zager 2011-04-03 08:33:41 +00:00
commit bc9a32a658
53 changed files with 3413 additions and 563 deletions

View file

@ -43,6 +43,7 @@
<li><a href="#Python_nn28">Further details on the Python class interface</a>
<ul>
<li><a href="#Python_nn29">Proxy classes</a>
<li><a href="#Python_BuiltinClasses">Built-in classes</a>
<li><a href="#Python_nn30">Memory management</a>
<li><a href="#Python_nn31">Python 2.2 and classic classes</a>
</ul>
@ -2203,6 +2204,16 @@ of low-level details were omitted. This section provides a brief overview
of how the proxy classes work.
</p>
<p><b>New in SWIG version 2.0.3:</b>
The use of Python proxy classes has performance implications that may be
unacceptable for a high-performance library. The new <tt>-builtin</tt>
option instructs SWIG to forego the use of proxy classes, and instead
create wrapped types as new built-in Python types. When this option is used,
the following section ("Proxy classes") does not apply. Details on the use of
the <tt>-builtin</tt> option are in the <a href="#Python_BuiltinClasses">Built-in Classes</a>
section.
</p>
<H3><a name="Python_nn29"></a>33.4.1 Proxy classes</H3>
@ -2292,8 +2303,280 @@ you can attach new Python methods to the class and you can even inherit from it
by Python built-in types until Python 2.2).
</p>
<H3><a name="Python_nn30"></a>33.4.2 Memory management</H3>
<H3><a name="Python_BuiltinClasses"></a>33.4.2 Built-in Classes</H3>
<p>
The <tt>-builtin</tt> option provides a significant performance improvement
in the wrapped code. To understand the difference between proxy classes
and built-in types, let's take a look at what a wrapped object looks like
under both circumstances.
</p>
<p>When proxy classes are used, each wrapped object in python is an instance
of a pure python class. As a reminder, here is what the <tt>__init__</tt> method looks
like in a proxy class:
</p>
<div class="targetlang">
<pre>
class Foo(object):
def __init__(self):
self.this = _example.new_Foo()
self.thisown = 1
</pre>
</div>
<p>When a <tt>Foo</tt> instance is created, the call to <tt>_example.new_Foo()</tt>
creates a new C++ <tt>Foo</tt> instance; wraps that C++ instance inside an instance of
a python built-in type called <tt>SwigPyObject</tt>; and stores the <tt>SwigPyObject</tt>
instance in the 'this' field of the python Foo object. Did you get all that? So, the
python <tt>Foo</tt> object is composed of three parts:</p>
<ul>
<li> The python <tt>Foo</tt> instance, which contains...</li>
<li> ... an instance of <tt>struct SwigPyObject</tt>, which contains...</li>
<li> ... a C++ <tt>Foo</tt> instance</li>
</ul>
<p>When <tt>-builtin</tt> is used, the pure python layer is stripped off. Each
wrapped class is turned into a new python built-in type which inherits from
<tt>SwigPyObject</tt>, and <tt>SwigPyObject</tt> instances are returned directly
from the wrapped methods. For more information about python built-in extensions,
please refer to the python documentation:</p>
<p><a href="http://docs.python.org/extending/newtypes.html">http://docs.python.org/extending/newtypes.html</a></p>
<H4>33.4.2.1 Limitations</H4>
<p>Use of the <tt>-builtin</tt> option implies a couple of limitations:
<ul>
<li><p>python version support:</p></li>
<ul>
<li>Versions 2.5 and up are fully supported</li>
<li>Versions 2.3 and 2.4 are mostly supported; there are problems with director classes and/or sub-classing a wrapped type in python.</li>
<li>Versions older than 2.3 are not supported.</li>
</ul>
<li><p>Some legacy syntax is no longer supported; in particular:</p></li>
<ul>
<li>The functional interface is no longer exposed. For example, you may no longer call <tt>Whizzo.new_CrunchyFrog()</tt>. Instead, you must use <tt>Whizzo.CrunchyFrog()</tt>.</li>
<li>Static member variables are no longer accessed through the 'cvar' field (e.g., <tt>Dances.cvar.FishSlap</tt>).
They are instead accessed in the idiomatic way (<tt>Dances.FishSlap</tt>).</li>
</ul>
<li><p>Wrapped types may not be raised as python exceptions. Here's why: the python internals expect that all sub-classes of Exception will have this struct layout:</p>
<div class="code">
<pre>
typedef struct {
PyObject_HEAD
PyObject *dict;
PyObject *args;
PyObject *message;
} PyBaseExceptionObject;
</pre>
</div>
<p>But swig-generated wrappers expect that all swig-wrapped classes will have this struct layout:</p>
<div class="code">
<pre>
typedef struct {
PyObject_HEAD
void *ptr;
swig_type_info *ty;
int own;
PyObject *next;
PyObject *dict;
} SwigPyObject;
</pre>
</div>
<p>There are workarounds for this. For example, if you wrap this class:
<div class="code">
<pre>
class MyException {
public:
MyException (const char *msg_);
~MyException ();
const char *what () const;
private:
char *msg;
};
</pre>
</div>
<p>... you can define this python class, which may be raised as an exception:</p>
<div class="targetlang">
<pre>
class MyPyException (Exception) :
def __init__(self, msg, *args) :
Exception.__init__(self, *args)
self.myexc = MyException(msg)
def what (self) :
return self.myexc.what()
</pre>
</div>
</li>
<li><p>Reverse binary operators (e.g., <tt>__radd__</tt>) are not supported.</p></li>
</ul>
</p>
<p>
To illustrate the last point, if you have a wrapped class called <tt>MyString</tt>,
and you want to use instances of <tt>MyString</tt> interchangeably with native python
strings, you can define an <tt>'operator+ (const char*)'</tt> method :
</p>
<div class="code">
<pre>
class MyString {
public:
MyString (const char *init);
MyString operator+ (const char *other) const;
...
};
</pre>
</div>
<p>
SWIG will automatically create an operator overload in python that will allow this:
</p>
<div class="targetlang">
<pre>
from MyModule import MyString
mystr = MyString("No one expects")
episode = mystr + " the Spanish Inquisition"
</pre>
</div>
<p>
This works because the first operand (<tt>mystr</tt>) defines a way
to add a native string to itself. However, the following will <b>not</b> work:
</p>
<div class="targetlang">
<pre>
from MyModule import MyString
mystr = MyString("Parrot")
episode = "Dead " + mystr
</pre>
</div>
<p>
The above code fails, because the first operand -- a native python string --
doesn't know how to add an instance of <tt>MyString</tt> to itself.
</p>
<H4>33.4.2.2 Operator overloads -- use them!</H4>
<p>The entire justification for the <tt>-builtin</tt> option is improved
performance. To that end, the best way to squeeze maximum performance out
of your wrappers is to <b>use operator overloads.</b>
Named method dispatch is slow in python, even when compared to other scripting languages.
However, python built-in types have a large number of "slots",
analogous to C++ operator overloads, which allow you to short-circuit named method dispatch
for certain common operations.
</p>
<p>By default, SWIG will translate most C++ arithmetic operator overloads into python
slot entries. For example, suppose you have this class:
<div class="code">
<pre>
class Twit {
public:
Twit operator+ (const Twit& twit) const;
// Forward to operator+
Twit add (const Twit& twit) const
{ return *this + twit; }
};
</pre>
</div>
<p>SWIG will automatically register <tt>operator+</tt> as a python slot operator for addition. You may write python code like this:</p>
<div class="targetlang">
<pre>
from MyModule import Twit
nigel = Twit()
emily = Twit()
percival = nigel + emily
percival = nigel.add(emily)
</pre>
</div>
<p>The last two lines of the python code are equivalent,
but <b>the line that uses the '+' operator is much faster</b>.
</p>
<p>In-place operators (e.g., <tt>operator+=</tt>) and comparison operators
(<tt>operator==, operator&lt;</tt>, etc.) are also converted to python
slot operators. For a complete list of C++ operators that are
automatically converted to python slot operators, refer to the file
<tt>python/pyopers.swig</tt> in the SWIG library.
</p>
<p>There are other very useful python slots that you
may explicitly define using <tt>%feature</tt> directives. For example,
suppose you want to use instances of a wrapped class as keys in a native python
<tt>dict</tt>. That will work as long as you define a hash function for
instances of your class, and use it to define the python <tt>tp_hash</tt>
slot:
</p>
<div class="code">
<pre>
class Cheese {
public:
Cheese (const char *name);
long cheeseHashFunc () const;
};
%feature("python:slot", "tp_hash", functype="hashfunc") Cheese::cheeseHashFunc;
</pre>
</div>
<p>This will allow you to write python code like this:</p>
<div class="targetlang">
<pre>
from my MyPackage import Cheese
inventory = {
Cheese("cheddar") : 0,
Cheese("gouda") : 0,
Cheese("camembert") : 0
}
</pre>
</div>
<p>Because you defined the <tt>tp_hash</tt> slot, <tt>Cheese</tt> objects may
be used as hash keys; and when the <tt>cheeseHashFunc</tt> method is invoked
by a python <tt>dict</tt>, it will <b>not</b> go through named method dispatch.
A more detailed discussion about <tt>%feature("python:slot")</tt> can be found
in the file <tt>python/pyopers.swig</tt> in the SWIG library.
You can read about all of the available python slots here:</p>
<p><a href="http://docs.python.org/c-api/typeobj.html">http://docs.python.org/c-api/typeobj.html</a></p>
<p>You may override (almost) all of the slots defined in the <tt>PyTypeObject,
PyNumberMethods, PyMappingMethods, PySequenceMethods</tt>, and <tt>PyBufferProcs</tt>
structs.
</p>
<H3><a name="Python_nn30"></a>33.4.3 Memory management</H3>
<p>NOTE: Although this section refers to proxy objects, everything here also applies
when the <tt>-builtin</tt> option is used.</p>
<p>
Associated with proxy object, is an ownership flag <tt>.thisown</tt> The value of this
@ -2484,7 +2767,7 @@ It is also possible to deal with situations like this using
typemaps--an advanced topic discussed later.
</p>
<H3><a name="Python_nn31"></a>33.4.3 Python 2.2 and classic classes</H3>
<H3><a name="Python_nn31"></a>33.4.4 Python 2.2 and classic classes</H3>
<p>

View file

@ -0,0 +1,35 @@
ifeq (,$(PY3))
PYSCRIPT = runme.py
else
PYSCRIPT = runme3.py
endif
default : all
include ../../Makefile
SUBDIRS := constructor func hierarchy operator hierarchy_operator
all : $(SUBDIRS:%=%-build)
@for subdir in $(SUBDIRS); do \
echo Running $$subdir test... ; \
echo -------------------------------------------------------------------------------- ; \
cd $$subdir; \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT); \
cd ..; \
done
$(SUBDIRS) :
$(MAKE) -C $@
@echo Running $$subdir test...
@echo --------------------------------------------------------------------------------
cd $@ && env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH PYTHONPATH=$(srcdir):$$PYTHONPATH $(PYTHON) $(PYSCRIPT)
%-build :
$(MAKE) -C $*
%-clean :
$(MAKE) -s -C $* clean
clean : $(SUBDIRS:%=%-clean)
rm -f *.pyc

View file

@ -0,0 +1,21 @@
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
CXXSRCS =
TARGET = Simple
INTERFACE = Simple.i
all :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
static :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
clean :
$(MAKE) -f $(TOP)/Makefile python_clean
rm -f $(TARGET).py

View file

@ -0,0 +1,8 @@
%inline %{
class MyClass {
public:
MyClass () {}
~MyClass () {}
void func () {}
};
%}

View file

@ -0,0 +1,11 @@
#!/usr/bin/env
import sys
sys.path.append('..')
import harness
def proc (mod) :
for i in range(1000000) :
x = mod.MyClass()
harness.run(proc)

View file

@ -0,0 +1,23 @@
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
CXXSRCS =
TARGET = Simple
INTERFACE = Simple.i
default : all
all :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
static :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
clean :
$(MAKE) -f $(TOP)/Makefile python_clean
rm -f $(TARGET).py

View file

@ -0,0 +1,8 @@
%inline %{
class MyClass {
public:
MyClass () {}
~MyClass () {}
void func () {}
};
%}

View file

@ -0,0 +1,12 @@
#!/usr/bin/env
import sys
sys.path.append('..')
import harness
def proc (mod) :
x = mod.MyClass()
for i in range(10000000) :
x.func()
harness.run(proc)

View file

@ -0,0 +1,30 @@
#!/usr/bin/env
import sys
import time
import imp
from subprocess import *
def run (proc) :
try :
mod = imp.find_module(sys.argv[1])
mod = imp.load_module(sys.argv[1], *mod)
t1 = time.clock()
proc(mod)
t2 = time.clock()
print "%s took %f seconds" % (mod.__name__, t2 - t1)
except IndexError :
proc = Popen([sys.executable, 'runme.py', 'Simple_baseline'], stdout=PIPE)
(stdout, stderr) = proc.communicate()
print stdout
proc = Popen([sys.executable, 'runme.py', 'Simple_optimized'], stdout=PIPE)
(stdout, stderr) = proc.communicate()
print stdout
proc = Popen([sys.executable, 'runme.py', 'Simple_builtin'], stdout=PIPE)
(stdout, stderr) = proc.communicate()
print stdout

View file

@ -0,0 +1,23 @@
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
CXXSRCS =
TARGET = Simple
INTERFACE = Simple.i
default : all
all :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
static :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
clean :
$(MAKE) -f $(TOP)/Makefile python_clean
rm -f $(TARGET).py

View file

@ -0,0 +1,52 @@
%inline %{
class A {
public:
A () {}
~A () {}
void func () {}
};
class B : public A {
public:
B () {}
~B () {}
};
class C : public B {
public:
C () {}
~C () {}
};
class D : public C {
public:
D () {}
~D () {}
};
class E : public D {
public:
E () {}
~E () {}
};
class F : public E {
public:
F () {}
~F () {}
};
class G : public F {
public:
G () {}
~G () {}
};
class H : public G {
public:
H () {}
~H () {}
};
%}

View file

@ -0,0 +1,12 @@
#!/usr/bin/env
import sys
sys.path.append('..')
import harness
def proc (mod) :
x = mod.H()
for i in range(10000000) :
x.func()
harness.run(proc)

View file

@ -0,0 +1,23 @@
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
CXXSRCS =
TARGET = Simple
INTERFACE = Simple.i
default : all
all :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
static :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
clean :
$(MAKE) -f $(TOP)/Makefile python_clean
rm -f $(TARGET).py

View file

@ -0,0 +1,53 @@
%inline %{
class A {
public:
A () {}
~A () {}
void func () {}
A& operator+= (int i) { return *this; }
};
class B : public A {
public:
B () {}
~B () {}
};
class C : public B {
public:
C () {}
~C () {}
};
class D : public C {
public:
D () {}
~D () {}
};
class E : public D {
public:
E () {}
~E () {}
};
class F : public E {
public:
F () {}
~F () {}
};
class G : public F {
public:
G () {}
~G () {}
};
class H : public G {
public:
H () {}
~H () {}
};
%}

View file

@ -0,0 +1,12 @@
#!/usr/bin/env
import sys
sys.path.append('..')
import harness
def proc (mod) :
x = mod.H()
for i in range(10000000) :
x += i
harness.run(proc)

View file

@ -0,0 +1,23 @@
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
CXXSRCS =
TARGET = Simple
INTERFACE = Simple.i
default : all
all :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -module Simple_baseline' \
TARGET='$(TARGET)_baseline' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -O -module Simple_optimized' \
TARGET='$(TARGET)_optimized' INTERFACE='$(INTERFACE)' python_cpp
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG) -builtin -O -module Simple_builtin' \
TARGET='$(TARGET)_builtin' INTERFACE='$(INTERFACE)' python_cpp
static :
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
clean :
$(MAKE) -f $(TOP)/Makefile python_clean
rm -f $(TARGET).py

View file

@ -0,0 +1,8 @@
%inline %{
class MyClass {
public:
MyClass () {}
~MyClass () {}
MyClass& operator+ (int i) { return *this; }
};
%}

View file

@ -0,0 +1,12 @@
#!/usr/bin/env
import sys
sys.path.append('..')
import harness
def proc (mod) :
x = mod.MyClass()
for i in range(10000000) :
x = x + i
harness.run(proc)

View file

@ -61,6 +61,7 @@ CPP_TEST_CASES += \
python_kwargs \
python_nondynamic \
python_overload_simple_cast \
python_richcompare \
std_containers \
swigobject \
template_matrix \

View file

@ -2,16 +2,16 @@ from argcargvtest import *
largs=['hi','hola','hello']
if mainc(largs) != 3:
raise RuntimeError, "bad main typemap"
raise RuntimeError("bad main typemap")
targs=('hi','hola')
if mainv(targs,1) != 'hola':
print mainv(targs,1)
raise RuntimeError, "bad main typemap"
print(mainv(targs,1))
raise RuntimeError("bad main typemap")
targs=('hi', 'hola')
if mainv(targs,1) != 'hola':
raise RuntimeError, "bad main typemap"
raise RuntimeError("bad main typemap")
try:
error = 0
@ -20,7 +20,7 @@ try:
except TypeError:
pass
if error:
raise RuntimeError, "bad main typemap"
raise RuntimeError("bad main typemap")

View file

@ -1,3 +1,7 @@
# This test is expected to fail with -builtin option.
# It uses the old static syntax (e.g., dc.new_A() rather than dc.A()),
# which is not provided with the -builtin option.
import _default_constructor
dc = _default_constructor

View file

@ -66,11 +66,15 @@ except MyException, e:
if not ok:
raise RuntimeError
# This is expected to fail with -builtin option
# Throwing builtin classes as exceptions not supported
try:
raise Exception2()
except Exception2:
pass
# This is expected to fail with -builtin option
# Throwing builtin classes as exceptions not supported
try:
raise Exception1()
except Exception1:

View file

@ -1,5 +1,7 @@
from exception_order import *
# This test is expected to fail with -builtin option.
# Throwing builtin classes as exceptions not supported
a = A()

View file

@ -11,3 +11,4 @@ if x != -37:
raise RuntimeError
grouping.cvar.test3 = 42
grouping.test3 = 42

View file

@ -92,5 +92,5 @@ sum = ()
for i in s:
sum = sum + (i,)
if sum != (1, 'hello', (1, 2)):
if (len(sum) != 3 or (not 1 in sum) or (not 'hello' in sum) or (not (1, 2) in sum)) :
raise RuntimeError

View file

@ -54,9 +54,13 @@ if a + b != "hello world":
if a + " world" != "hello world":
raise RuntimeError, "bad string mapping"
# This is expected to fail with -builtin option
# Reverse operators not supported in builtin types
if "hello" + b != "hello world":
raise RuntimeError, "bad string mapping"
# This is expected to fail with -builtin option
# Reverse operators not supported in builtin types
c = "hello" + b
if c.find_last_of("l") != 9:
raise RuntimeError, "bad string mapping"

View file

@ -4,21 +4,21 @@ x=u"h"
if li_std_wstring.test_wcvalue(x) != x:
print li_std_wstring.test_wcvalue(x)
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
x=u"hello"
if li_std_wstring.test_ccvalue(x) != x:
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
if li_std_wstring.test_cvalue(x) != x:
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
if li_std_wstring.test_value(x) != x:
print x, li_std_wstring.test_value(x)
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
if li_std_wstring.test_const_reference(x) != x:
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
s = li_std_wstring.wstring(u"he")
@ -26,39 +26,41 @@ s = s + u"llo"
if s != x:
print s, x
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
if s[1:4] != x[1:4]:
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
if li_std_wstring.test_value(s) != x:
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
if li_std_wstring.test_const_reference(s) != x:
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
a = li_std_wstring.A(s)
if li_std_wstring.test_value(a) != x:
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
if li_std_wstring.test_const_reference(a) != x:
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
b = li_std_wstring.wstring(" world")
if a + b != "hello world":
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
if a + " world" != "hello world":
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
# This is expected to fail if -builtin is used
if "hello" + b != "hello world":
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
# This is expected to fail if -builtin is used
c = "hello" + b
if c.find_last_of("l") != 9:
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
s = "hello world"
@ -66,11 +68,11 @@ b = li_std_wstring.B("hi")
b.name = li_std_wstring.wstring(u"hello")
if b.name != "hello":
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")
b.a = li_std_wstring.A("hello")
if b.a != u"hello":
raise RuntimeError, "bad string mapping"
raise RuntimeError("bad string mapping")

View file

@ -1,5 +1,9 @@
from python_abstractbase import *
from collections import *
# This is expected to fail with -builtin option
# Builtin types can't inherit from pure-python abstract bases
assert issubclass(Mapii, MutableMapping)
assert issubclass(Multimapii, MutableMapping)
assert issubclass(IntSet, MutableSet)

View file

@ -13,7 +13,6 @@ except:
if not err:
raise RuntimeError, "A is not static"
class B(python_nondynamic.A):
c = 4
def __init__(self):
@ -21,10 +20,19 @@ class B(python_nondynamic.A):
pass
pass
bb = B()
bb.c = 3
try:
bb.c = 3
err = 0
except:
err = 1
if not err:
print "bb.c = %d" % bb.c
print "B.c = %d" % B.c
raise RuntimeError, "B.c class variable messes up nondynamic-ness of B"
try:
bb.d = 2
err = 0
@ -33,7 +41,6 @@ except:
if not err:
raise RuntimeError, "B is not static"
cc = python_nondynamic.C()
cc.d = 3

View file

@ -0,0 +1,100 @@
import python_richcompare
base1 = python_richcompare.BaseClass(1)
base2 = python_richcompare.BaseClass(2)
base3 = python_richcompare.BaseClass(3)
a1 = python_richcompare.SubClassA(1)
a2 = python_richcompare.SubClassA(2)
a3 = python_richcompare.SubClassA(3)
b1 = python_richcompare.SubClassB(1)
b2 = python_richcompare.SubClassB(2)
b3 = python_richcompare.SubClassB(3)
# Check == and != within a single type
#-------------------------------------------------------------------------------
if not (base1 == base1) :
raise RuntimeError("Object not == to itself")
if not (base1 == python_richcompare.BaseClass(1)) :
raise RuntimeError("Object not == to an equivalent object")
if (base1 == base2) :
raise RuntimeError("Comparing non-equivalent objects of the same type, == returned True")
if (base1 != base1) :
raise RuntimeError("Object is != itself")
if (base1 != python_richcompare.BaseClass(1)) :
raise RuntimeError("Object is != an equivalent object")
if not (base1 != base2) :
raise RuntimeError("Comparing non-equivalent objects of the same type, != returned False")
# Check redefined operator== in SubClassA
#-------------------------------------------------------------------------------
if (a2 == base2) :
raise RuntimeError("Redefined operator== in SubClassA failed")
if (a2 == b2) :
raise RuntimeError("Redefined operator== in SubClassA failed")
if not (a1 == a2) :
raise RuntimeError("Redefined operator== in SubClassA failed")
# Check up-casting of subclasses
#-------------------------------------------------------------------------------
if (base2 != a2) :
raise RuntimeError("Comparing equivalent base and subclass instances, != returned True")
if (a2 == base2) :
raise RuntimeError("Comparing non-equivalent base and subclass instances, == returned True")
if (a1 == b1) :
raise RuntimeError("Comparing equivalent instances of different subclasses, == returned True")
if (b1 == a1) :
raise RuntimeError("Comparing equivalent instances of different subclasses, == returned True")
# Check inequalities
#-------------------------------------------------------------------------------
if (a2 > b2) :
raise RuntimeError("operator> failed")
if (a2 < b2) :
raise RuntimeError("operator< failed")
if not (a2 >= b2) :
raise RuntimeError("operator>= failed")
if not (a2 <= b2) :
raise RuntimeError("operator<= failed")
# Check inequalities used for ordering
#-------------------------------------------------------------------------------
x = sorted([a2, a3, a1])
if not (x[0] is a1) :
raise RuntimeError("Ordering failed")
if not (x[1] is a2) :
raise RuntimeError("Ordering failed")
if not (x[2] is a3) :
raise RuntimeError("Ordering failed")
x = sorted([base2, a3, b1])
if not (x[0] is b1) :
raise RuntimeError("Ordering failed")
if not (x[1] is base2) :
raise RuntimeError("Ordering failed")
if not (x[2] is a3) :
raise RuntimeError("Ordering failed")

View file

@ -18,8 +18,11 @@ except RuntimeError,e:
if e.args[0] != "I died.":
raise RuntimeError
# This is expected fail with -builtin option
# Throwing builtin classes as exceptions not supported
try:
t.hosed()
pass
except threads_exception.Exc,e:
if e.code != 42:
raise RuntimeError

View file

@ -0,0 +1,60 @@
/* Test the tp_richcompare functions generated with the -builtin option */
%module python_richcompare
%inline {
class BaseClass {
public:
BaseClass (int i_) : i(i_) {}
~BaseClass () {}
int getValue () const
{ return i; }
bool operator< (const BaseClass& x) const
{ return this->i < x.i; }
bool operator> (const BaseClass& x) const
{ return this->i > x.i; }
bool operator<= (const BaseClass& x) const
{ return this->i <= x.i; }
bool operator>= (const BaseClass& x) const
{ return this->i >= x.i; }
bool operator== (const BaseClass& x) const
{ return this->i == x.i; }
bool operator!= (const BaseClass& x) const
{ return this->i != x.i; }
int i;
};
class SubClassA : public BaseClass {
public:
SubClassA (int i_) : BaseClass(i_) {}
~SubClassA () {}
bool operator== (const SubClassA& x) const
{ return true; }
bool operator== (const BaseClass& x) const
{ return false; }
};
class SubClassB : public BaseClass {
public:
SubClassB (int i_) : BaseClass(i_) {}
~SubClassB () {}
bool operator== (const SubClassB& x) const
{ return true; }
bool operator== (const SubClassA& x) const
{ return false; }
};
}

View file

@ -6,6 +6,10 @@
#define SHARED_PTR_DISOWN 0
#endif
%fragment("SWIG_null_deleter_python", "header", fragment="SWIG_null_deleter") {
%#define SWIG_NO_NULL_DELETER_SWIG_BUILTIN_INIT
}
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
@ -75,7 +79,8 @@
$1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype);
}
}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * {
%typemap(out, fragment="SWIG_null_deleter_python") CONST TYPE * {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), $owner | SWIG_POINTER_OWN));
}
@ -98,7 +103,7 @@
$1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype);
}
}
%typemap(varout, fragment="SWIG_null_deleter") CONST TYPE * {
%typemap(varout, fragment="SWIG_null_deleter_python") CONST TYPE * {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
%set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
@ -119,7 +124,7 @@
$1 = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype);
}
}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE & {
%typemap(out, fragment="SWIG_null_deleter_python") CONST TYPE & {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner);
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
@ -141,7 +146,7 @@
$1 = *%const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype);
}
}
%typemap(varout, fragment="SWIG_null_deleter") CONST TYPE & {
%typemap(varout, fragment="SWIG_null_deleter_python") CONST TYPE & {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(&$1 SWIG_NO_NULL_DELETER_0);
%set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
@ -163,7 +168,7 @@
}
$1 = &temp;
}
%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& {
%typemap(out, fragment="SWIG_null_deleter_python") TYPE *CONST& {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner);
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
@ -311,5 +316,16 @@
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
#if defined(SWIGPYTHON_BUILTIN)
%typemap(builtin_init, fragment="SWIG_null_deleter_python") CONST TYPE * {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
%set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), $owner | SWIG_POINTER_OWN));
}
#endif
%enddef

421
Lib/python/builtin.swg Normal file
View file

@ -0,0 +1,421 @@
#define SWIGPY_UNARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a) { \
return wrapper(a, NULL); \
}
#define SWIGPY_DESTRUCTOR_CLOSURE(wrapper) \
SWIGINTERN void \
wrapper##_closure(PyObject *a) { \
SwigPyObject *sobj = (SwigPyObject *)a; \
if (sobj->own) { \
PyObject *o = wrapper(a, NULL); \
Py_XDECREF(o); \
} \
}
#define SWIGPY_INQUIRY_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_closure(PyObject *a) { \
PyObject *pyresult = wrapper(a, NULL); \
int result = pyresult && PyObject_IsTrue(pyresult) ? 1 : 0; \
Py_XDECREF(pyresult); \
return result; \
}
#define SWIGPY_BINARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, PyObject *b) { \
PyObject *tuple = PyTuple_New(1); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, b); \
Py_XINCREF(b); \
PyObject *result = wrapper(a, tuple); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_TERNARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) { \
PyObject *tuple = PyTuple_New(2); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, b); \
PyTuple_SET_ITEM(tuple, 1, c); \
Py_XINCREF(b); \
Py_XINCREF(c); \
PyObject *result = wrapper(a, tuple); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_LENFUNC_CLOSURE(wrapper) \
SWIGINTERN Py_ssize_t \
wrapper##_closure(PyObject *a) { \
PyObject *resultobj = wrapper(a, NULL); \
Py_ssize_t result = PyNumber_AsSsize_t(resultobj, NULL); \
Py_DECREF(resultobj); \
return result; \
}
#define SWIGPY_SSIZESSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c) { \
PyObject *tuple = PyTuple_New(2); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \
PyObject *result = wrapper(a, tuple); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_SSIZESSIZEOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) { \
PyObject *tuple = PyTuple_New(d ? 3 : 2); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \
if (d) { \
PyTuple_SET_ITEM(tuple, 2, d); \
Py_INCREF(d); \
} \
PyObject *resultobj = wrapper(a, tuple); \
int result = resultobj ? 0 : -1; \
Py_DECREF(tuple); \
Py_XDECREF(resultobj); \
return result; \
}
#define SWIGPY_SSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, Py_ssize_t b) { \
PyObject *tuple = PyTuple_New(1); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
PyObject *result = wrapper(a, tuple); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_FUNPACK_SSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, Py_ssize_t b) { \
PyObject *arg = _PyLong_FromSsize_t(b); \
PyObject *result = wrapper(a, arg); \
Py_DECREF(arg); \
return result; \
}
#define SWIGPY_SSIZEOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_closure(PyObject *a, Py_ssize_t b, PyObject *c) { \
PyObject *tuple = PyTuple_New(2); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
PyTuple_SET_ITEM(tuple, 1, c); \
Py_XINCREF(c); \
PyObject *resultobj = wrapper(a, tuple); \
int result = resultobj ? 0 : -1; \
Py_XDECREF(resultobj); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_OBJOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) { \
PyObject *tuple = PyTuple_New(c ? 2 : 1); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, b); \
Py_XINCREF(b); \
if (c) { \
PyTuple_SET_ITEM(tuple, 1, c); \
Py_XINCREF(c); \
} \
PyObject *resultobj = wrapper(a, tuple); \
int result = resultobj ? 0 : -1; \
Py_XDECREF(resultobj); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_REPRFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a) { \
return wrapper(a, NULL); \
}
#define SWIGPY_HASHFUNC_CLOSURE(wrapper) \
SWIGINTERN long \
wrapper##_closure(PyObject *a) { \
PyObject *pyresult = wrapper(a, NULL); \
if (!pyresult || !PyLong_Check(pyresult)) \
return -1; \
long result = PyLong_AsLong(pyresult); \
Py_DECREF(pyresult); \
return result; \
}
#define SWIGPY_ITERNEXT_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a) { \
PyObject *result = wrapper(a, NULL); \
if (result && result == Py_None) { \
Py_DECREF(result); \
result = NULL; \
} \
return result; \
}
SWIGINTERN int
SwigPyBuiltin_BadInit(PyObject *self, PyObject *args, PyObject *kwds) {
PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name);
return -1;
}
SWIGINTERN void
SwigPyBuiltin_BadDealloc(PyObject *pyobj) {
SwigPyObject *sobj = (SwigPyObject *)pyobj;
if (sobj->own) {
PyErr_Format(PyExc_TypeError, "Swig detected a memory leak in type '%.300s': no callable destructor found.", pyobj->ob_type->tp_name);
}
}
typedef struct {
PyCFunction get;
PyCFunction set;
} SwigPyGetSet;
SWIGINTERN PyObject *
SwigPyBuiltin_GetterClosure (PyObject *obj, void *closure) {
if (!closure)
return SWIG_Py_Void();
SwigPyGetSet *getset = (SwigPyGetSet *)closure;
if (!getset->get)
return SWIG_Py_Void();
PyObject *tuple = PyTuple_New(0);
assert(tuple);
PyObject *result = (*getset->get)(obj, tuple);
Py_DECREF(tuple);
return result;
}
SWIGINTERN PyObject *
SwigPyBuiltin_FunpackGetterClosure (PyObject *obj, void *closure) {
if (!closure)
return SWIG_Py_Void();
SwigPyGetSet *getset = (SwigPyGetSet *)closure;
if (!getset->get)
return SWIG_Py_Void();
PyObject *result = (*getset->get)(obj, NULL);
return result;
}
SWIGINTERN int
SwigPyBuiltin_SetterClosure (PyObject *obj, PyObject *val, void *closure) {
if (!closure) {
PyErr_Format(PyExc_TypeError, "Missing getset closure");
return -1;
}
SwigPyGetSet *getset = (SwigPyGetSet *)closure;
if (!getset->set) {
PyErr_Format(PyExc_TypeError, "Illegal member variable assignment in type '%.300s'", obj->ob_type->tp_name);
return -1;
}
PyObject *tuple = PyTuple_New(1);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, val);
Py_XINCREF(val);
PyObject *result = (*getset->set)(obj, tuple);
Py_DECREF(tuple);
Py_XDECREF(result);
return result ? 0 : -1;
}
SWIGINTERN int
SwigPyBuiltin_FunpackSetterClosure (PyObject *obj, PyObject *val, void *closure) {
if (!closure) {
PyErr_Format(PyExc_TypeError, "Missing getset closure");
return -1;
}
SwigPyGetSet *getset = (SwigPyGetSet *)closure;
if (!getset->set) {
PyErr_Format(PyExc_TypeError, "Illegal member variable assignment in type '%.300s'", obj->ob_type->tp_name);
return -1;
}
PyObject *result = (*getset->set)(obj, val);
Py_XDECREF(result);
return result ? 0 : -1;
}
SWIGINTERN void
SwigPyStaticVar_dealloc(PyDescrObject *descr) {
_PyObject_GC_UNTRACK(descr);
Py_XDECREF(descr->d_type);
Py_XDECREF(descr->d_name);
PyObject_GC_Del(descr);
}
SWIGINTERN PyObject *
SwigPyStaticVar_repr(PyGetSetDescrObject *descr) {
#if PY_VERSION_HEX >= 0x03000000
return PyUnicode_FromFormat("<class attribute '%S' of type '%s'>", descr->d_name, descr->d_type->tp_name);
#else
return PyString_FromFormat("<class attribute '%s' of type '%s'>", PyString_AsString(descr->d_name), descr->d_type->tp_name);
#endif
}
SWIGINTERN int
SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg) {
PyDescrObject *descr = (PyDescrObject *)self;
Py_VISIT((PyObject*) descr->d_type);
return 0;
}
SWIGINTERN PyObject *
SwigPyStaticVar_get(PyGetSetDescrObject *descr, PyObject *obj, PyObject *type) {
if (descr->d_getset->get != NULL)
return descr->d_getset->get(obj, descr->d_getset->closure);
#if PY_VERSION_HEX >= 0x03000000
PyErr_Format(PyExc_AttributeError, "attribute '%.300S' of '%.100s' objects is not readable", descr->d_name, descr->d_type->tp_name);
#else
PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not readable", PyString_AsString(descr->d_name), descr->d_type->tp_name);
#endif
return NULL;
}
SWIGINTERN int
SwigPyStaticVar_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) {
int res;
if (descr->d_getset->set != NULL)
return descr->d_getset->set(obj, value, descr->d_getset->closure);
#if PY_VERSION_HEX >= 0x03000000
PyErr_Format(PyExc_AttributeError, "attribute '%.300S' of '%.100s' objects is not writable", descr->d_name, descr->d_type->tp_name);
#else
PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not writable", PyString_AsString(descr->d_name), descr->d_type->tp_name);
#endif
return -1;
}
SWIGINTERN PyTypeObject SwigPyStaticVar_Type = {
#if PY_VERSION_HEX >= 0x03000000
PyVarObject_HEAD_INIT(&PyType_Type, 0)
#else
PyObject_HEAD_INIT(&PyType_Type)
0,
#endif
"swig_static_var_getset_descriptor",
sizeof(PyGetSetDescrObject),
0,
(destructor)SwigPyStaticVar_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
(reprfunc)SwigPyStaticVar_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_CLASS, /* tp_flags */
0, /* tp_doc */
SwigPyStaticVar_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
(descrgetfunc)SwigPyStaticVar_get, /* tp_descr_get */
(descrsetfunc)SwigPyStaticVar_set, /* tp_descr_set */
};
SWIGINTERN int
SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) {
PyObject *attribute = _PyType_Lookup(type, name);
if (attribute != NULL) {
/* Implement descriptor functionality, if any */
descrsetfunc local_set = attribute->ob_type->tp_descr_set;
if (local_set != NULL)
return local_set(attribute, (PyObject *)type, value);
#if PY_VERSION_HEX >= 0x03000000
PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400S'", type->tp_name, name);
#else
PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400s'", type->tp_name, PyString_AS_STRING(name));
#endif
} else {
#if PY_VERSION_HEX >= 0x03000000
PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400S'", type->tp_name, name);
#else
PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400s'", type->tp_name, PyString_AS_STRING(name));
#endif
}
return -1;
}
SWIGINTERN PyGetSetDescrObject *
SwigPyStaticVar_new_getset(PyTypeObject *type, PyGetSetDef *getset) {
PyGetSetDescrObject *descr = (PyGetSetDescrObject *)PyType_GenericAlloc(&SwigPyStaticVar_Type, 0);
assert(descr);
Py_XINCREF(type);
descr->d_type = type;
descr->d_name = PyString_InternFromString(getset->name);
descr->d_getset = getset;
if (descr->d_name == NULL) {
Py_DECREF(descr);
descr = NULL;
}
return descr;
}
SWIGINTERN void
SwigPyBuiltin_InitBases (PyTypeObject *type, PyTypeObject **bases) {
int base_count = 0;
PyTypeObject **b;
int i;
if (!bases[0]) {
bases[0] = SwigPyObject_type();
bases[1] = NULL;
}
type->tp_base = bases[0];
Py_INCREF((PyObject *)bases[0]);
for (b = bases; *b != NULL; ++b)
++base_count;
PyObject *tuple = PyTuple_New(base_count);
for (i = 0; i < base_count; ++i) {
PyTuple_SET_ITEM(tuple, i, (PyObject *)bases[i]);
Py_INCREF((PyObject *)bases[i]);
}
type->tp_bases = tuple;
}
SWIGINTERN PyObject *
SwigPyBuiltin_ThisClosure (PyObject *self, void *closure) {
PyObject *result = (PyObject *)SWIG_Python_GetSwigThis(self);
Py_XINCREF(result);
return result;
}
SWIGINTERN void
SwigPyBuiltin_SetMetaType (PyTypeObject *type, PyTypeObject *metatype)
{
#if PY_VERSION_HEX >= 0x03000000
type->ob_base.ob_base.ob_type = metatype;
#else
type->ob_type = metatype;
#endif
}

View file

@ -1,5 +1,49 @@
%define %array_class(TYPE,NAME)
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "sq_item", functype="ssizeargfunc") NAME::__getitem__;
%feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") NAME::__setitem__;
%inline %{
typedef struct NAME {
TYPE *el;
} NAME;
%}
%extend NAME {
NAME(size_t nelements) {
NAME *arr = %new_instance(NAME);
arr->el = %new_array(nelements, TYPE);
return arr;
}
~NAME() {
%delete_array(self->el);
%delete(self);
}
TYPE __getitem__(size_t index) {
return self->el[index];
}
void __setitem__(size_t index, TYPE value) {
self->el[index] = value;
}
TYPE * cast() {
return self->el;
}
static NAME *frompointer(TYPE *t) {
return %reinterpret_cast(t, NAME *);
}
};
%types(NAME = TYPE);
#else
%array_class_wrap(TYPE,NAME,__getitem__,__setitem__)
#endif
%enddef
%include <typemaps/carrays.swg>

View file

@ -459,6 +459,18 @@ namespace Swig {
}
return own;
}
template <typename Type>
static PyObject* swig_pyobj_disown(PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args))
{
SwigPyObject *sobj = (SwigPyObject *)pyobj;
sobj->own = 0;
Director *d = SWIG_DIRECTOR_CAST(reinterpret_cast<Type *>(sobj->ptr));
if (d)
d->swig_disown();
return PyWeakref_NewProxy(pyobj, NULL);
}
};
#ifdef __THREAD__

View file

@ -32,7 +32,7 @@ typedef struct swig_const_info {
* Wrapper of PyInstanceMethod_New() used in Python 3
* It is exported to the generated module, used for -fastproxy
* ----------------------------------------------------------------------------- */
SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *self, PyObject *func)
SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(func))
{
#if PY_VERSION_HEX >= 0x03000000
return PyInstanceMethod_New(func);

View file

@ -43,6 +43,9 @@ namespace swig {
%apply PyObject * {SwigPtr_PyObject};
%apply PyObject * const& {SwigPtr_PyObject const&};
%typemap(typecheck,precedence=SWIG_TYPECHECK_SWIGOBJECT,noblock=1) SwigPtr_PyObject const& "$1 = ($input != 0);";
/* For output */
%typemap(out,noblock=1) SwigPtr_PyObject {
$result = (PyObject *)$1;

View file

@ -245,7 +245,7 @@ namespace swig {
template <class Sequence, class Difference, class InputSeq>
inline void
setslice(Sequence* self, Difference i, Difference j, const InputSeq& v) {
setslice(Sequence* self, Difference i, Difference j, const InputSeq& v = InputSeq()) {
typename Sequence::size_type size = self->size();
typename Sequence::size_type ii = swig::check_index(i, size, true);
typename Sequence::size_type jj = swig::slice_index(j, size);
@ -586,19 +586,28 @@ namespace swig
return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%pythoncode {def __iter__(self): return self.iterator()}
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "tp_iter", functype="getiterfunc") iterator;
#else
%pythoncode {def __iter__(self): return self.iterator()}
#endif
}
#endif //SWIG_EXPORT_ITERATOR_METHODS
%enddef
/**** The python container methods ****/
%define %swig_container_methods(Container...)
%newobject __getslice__;
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "nb_nonzero", functype="inquiry") __nonzero__;
%feature("python:slot", "sq_length", functype="lenfunc") __len__;
#endif // SWIGPYTHON_BUILTIN
%extend {
bool __nonzero__() const {
return !(self->empty());
@ -613,14 +622,26 @@ namespace swig
return self->size();
}
}
%enddef
%define %swig_sequence_methods_common(Sequence...)
%swig_sequence_iterator(%arg(Sequence))
%swig_container_methods(%arg(Sequence))
%fragment("SwigPySequence_Base");
#if defined(SWIGPYTHON_BUILTIN)
//%feature("python:slot", "sq_item", functype="ssizeargfunc") __getitem__;
//%feature("python:slot", "sq_slice", functype="ssizessizeargfunc") __getslice__;
//%feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") __setitem__;
//%feature("python:slot", "sq_ass_slice", functype="ssizessizeobjargproc") __setslice__;
%feature("python:slot", "mp_subscript", functype="binaryfunc") __getitem__;
%feature("python:slot", "mp_ass_subscript", functype="objobjargproc") __setitem__;
#endif // SWIGPYTHON_BUILTIN
%extend {
value_type pop() throw (std::out_of_range) {
if (self->size() == 0)
@ -632,6 +653,9 @@ namespace swig
/* typemap for slice object support */
%typemap(in) PySliceObject* {
if (!PySlice_Check($input)) {
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
}
$1 = (PySliceObject *) $input;
}
%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) PySliceObject* {
@ -642,7 +666,7 @@ namespace swig
return swig::getslice(self, i, j);
}
void __setslice__(difference_type i, difference_type j, const Sequence& v)
void __setslice__(difference_type i, difference_type j, const Sequence& v = Sequence())
throw (std::out_of_range, std::invalid_argument) {
swig::setslice(self, i, j, v);
}
@ -680,6 +704,17 @@ namespace swig
swig::setslice(self, i, j, v);
}
void __setitem__(PySliceObject *slice)
throw (std::out_of_range) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return;
}
PySlice_GetIndices(slice, self->size(), &i, &j, &step);
swig::delslice(self, i,j);
}
void __delitem__(PySliceObject *slice)
throw (std::out_of_range) {
Py_ssize_t i, j, step;
@ -692,6 +727,7 @@ namespace swig
}
}
%enddef
%define %swig_sequence_methods(Sequence...)
@ -709,6 +745,7 @@ namespace swig
self->push_back(x);
}
}
%enddef
%define %swig_sequence_methods_val(Sequence...)
@ -726,6 +763,7 @@ namespace swig
self->push_back(x);
}
}
%enddef

View file

@ -5,7 +5,15 @@
#define PyInt_Check(x) PyLong_Check(x)
#define PyInt_AsLong(x) PyLong_AsLong(x)
#define PyInt_FromLong(x) PyLong_FromLong(x)
#define PyString_Check(name) PyBytes_Check(name)
#define PyString_FromString(x) PyUnicode_FromString(x)
#define PyString_Format(fmt, args) PyUnicode_Format(fmt, args)
#define PyString_AsString(str) PyBytes_AsString(str)
#define PyString_Size(str) PyBytes_Size(str)
#define PyString_InternFromString(key) PyUnicode_InternFromString(key)
#define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE
#define PyString_AS_STRING(x) PyUnicode_AS_STRING(x)
#define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x)
#endif
@ -145,4 +153,49 @@ PyObject *PyBool_FromLong(long ok)
typedef int Py_ssize_t;
# define PY_SSIZE_T_MAX INT_MAX
# define PY_SSIZE_T_MIN INT_MIN
typedef inquiry lenfunc;
typedef intargfunc ssizeargfunc;
typedef intintargfunc ssizessizeargfunc;
typedef intobjargproc ssizeobjargproc;
typedef intintobjargproc ssizessizeobjargproc;
typedef getreadbufferproc readbufferproc;
typedef getwritebufferproc writebufferproc;
typedef getsegcountproc segcountproc;
typedef getcharbufferproc charbufferproc;
static inline long PyNumber_AsSsize_t (PyObject *x, void*)
{
long result = 0;
PyObject *i = PyNumber_Int(x);
if (i) {
result = PyInt_AsLong(i);
Py_DECREF(i);
}
return result;
}
#endif
#if PY_VERSION_HEX < 0x02040000
#define Py_VISIT(op) \
do { \
if (op) { \
int vret = visit((op), arg); \
if (vret) \
return vret; \
} \
} while (0)
#endif
#if PY_VERSION_HEX < 0x02030000
typedef struct {
PyTypeObject type;
PyNumberMethods as_number;
PyMappingMethods as_mapping;
PySequenceMethods as_sequence;
PyBufferProcs as_buffer;
PyObject *name, *slots;
} PyHeapTypeObject;
#endif
#if PY_VERSION_HEX < 0x02030000
typedef destructor freefunc;
#endif

View file

@ -138,7 +138,7 @@ SWIGINTERN PyTypeObject*
swig_varlink_type(void) {
static char varlink__doc__[] = "Swig var link object";
static PyTypeObject varlink_type;
static int type_init = 0;
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp
= {
@ -152,7 +152,7 @@ swig_varlink_type(void) {
(char *)"swigvarlink", /* Type name (tp_name) */
sizeof(swig_varlinkobject), /* Basic size (tp_basicsize) */
0, /* Itemsize (tp_itemsize) */
(destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */
(destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */
(printfunc) swig_varlink_print, /* Print (tp_print) */
(getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */
(setattrfunc) swig_varlink_setattr, /* Set attr (tp_setattr) */
@ -179,6 +179,9 @@ swig_varlink_type(void) {
#if PY_VERSION_HEX >= 0x02030000
0, /* tp_del */
#endif
#if PY_VERSION_HEX >= 0x02060000
0, /* tp_version */
#endif
#ifdef COUNT_ALLOCS
0,0,0,0 /* tp_alloc -> tp_next */
#endif
@ -239,7 +242,7 @@ SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) {
for (i = 0; constants[i].type; ++i) {
switch(constants[i].type) {
case SWIG_PY_POINTER:
obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0);
obj = SWIG_InternalNewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0);
break;
case SWIG_PY_BINARY:
obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype));
@ -320,7 +323,7 @@ SWIGEXPORT
void
#endif
SWIG_init(void) {
PyObject *m, *d;
PyObject *m, *d, *md;
#if PY_VERSION_HEX >= 0x03000000
static struct PyModuleDef SWIG_module = {
PyModuleDef_HEAD_INIT,
@ -335,6 +338,25 @@ SWIG_init(void) {
};
#endif
#if defined(SWIGPYTHON_BUILTIN)
PyTypeObject *builtin_pytype = 0;
int builtin_base_count = 0;
swig_type_info *builtin_basetype = 0;
PyObject *tuple = NULL;
PyGetSetDescrObject *static_getset = NULL;
int i;
/* metatype is used to implement static member variables. */
PyObject *metatype_args = Py_BuildValue("(s(O){})", "SwigPyObjectType", &PyType_Type);
assert(metatype_args);
PyTypeObject *metatype = (PyTypeObject *) PyType_Type.tp_call((PyObject *) &PyType_Type, metatype_args, NULL);
assert(metatype);
Py_DECREF(metatype_args);
metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro;
assert(PyType_Ready(metatype) >= 0);
#endif
/* Fix SwigMethods to carry the callback ptrs when needed */
SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial);
@ -343,10 +365,53 @@ SWIG_init(void) {
#else
m = Py_InitModule((char *) SWIG_name, SwigMethods);
#endif
d = PyModule_GetDict(m);
md = d = PyModule_GetDict(m);
SWIG_InitializeModule(0);
#ifdef SWIGPYTHON_BUILTIN
static SwigPyClientData SwigPyObject_clientdata = {0};
SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject");
assert(SwigPyObject_stype);
SwigPyClientData *cd = (SwigPyClientData*) SwigPyObject_stype->clientdata;
if (!cd) {
SwigPyObject_stype->clientdata = &SwigPyObject_clientdata;
SwigPyObject_clientdata.pytype = SwigPyObject_TypeOnce();
} else if (SwigPyObject_TypeOnce()->tp_basicsize != cd->pytype->tp_basicsize) {
PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules.");
# if PY_VERSION_HEX >= 0x03000000
return NULL;
# else
return;
# endif
}
/* All objects have a 'this' attribute */
static PyGetSetDef this_getset_def = {
(char*) "this", SwigPyBuiltin_ThisClosure, NULL, NULL, NULL
};
PyObject *this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def);
/* All objects have a 'thisown' attribute */
static SwigPyGetSet thisown_getset_closure = {
(PyCFunction) SwigPyObject_own,
(PyCFunction) SwigPyObject_own
};
static PyGetSetDef thisown_getset_def = {
const_cast<char*>("thisown"), SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure
};
PyObject *thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def);
PyObject *public_interface = PyList_New(0);
PyObject *public_symbol = 0;
PyDict_SetItemString(md, "__all__", public_interface);
Py_DECREF(public_interface);
for (i = 0; SwigMethods[i].ml_name != NULL; ++i)
SwigPyBuiltin_AddPublicSymbol(public_interface, SwigMethods[i].ml_name);
for (i = 0; swig_const_table[i].name != 0; ++i)
SwigPyBuiltin_AddPublicSymbol(public_interface, swig_const_table[i].name);
#endif
SWIG_InstallConstants(d,swig_const_table);
%}

View file

@ -128,6 +128,13 @@ namespace swig {
return desc;
}
};
inline PyObject* make_output_iterator_builtin (PyObject *pyself)
{
Py_INCREF(pyself);
return pyself;
}
}
}
@ -302,6 +309,18 @@ namespace swig {
{
return new SwigPyIteratorOpen_T<OutIter>(current, seq);
}
template <typename Sequence>
inline PyObject* make_output_iterator_builtin_T (PyObject *pyself)
{
SwigPyObject *builtin_obj = (SwigPyObject*) pyself;
Sequence *seq = reinterpret_cast< Sequence * >(builtin_obj->ptr);
if (!seq)
return SWIG_Py_Void();
SwigPyIterator *iter = make_output_iterator(seq->begin(), seq->begin(), seq->end(), pyself);
return SWIG_InternalNewPointerObj(iter, SWIGTYPE_p_swig__SwigPyIterator, SWIG_POINTER_OWN);
}
}
}
@ -329,9 +348,15 @@ namespace swig
%newobject SwigPyIterator::operator - (ptrdiff_t n) const;
%nodirector SwigPyIterator;
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin";
%feature("python:slot", "tp_iternext", functype="iternextfunc") SwigPyIterator::__next__;
#else
%extend SwigPyIterator {
%pythoncode {def __iter__(self): return self}
}
#endif
%catches(swig::stop_iteration) SwigPyIterator::value() const;
%catches(swig::stop_iteration) SwigPyIterator::incr(size_t n = 1);
@ -347,7 +372,6 @@ namespace swig
%catches(swig::stop_iteration) SwigPyIterator::operator + (ptrdiff_t n) const;
%catches(swig::stop_iteration) SwigPyIterator::operator - (ptrdiff_t n) const;
struct SwigPyIterator
{
protected:

View file

@ -1,45 +1,140 @@
/* ------------------------------------------------------------
* Overloaded operator support
The directives in this file apply whether or not you use the
-builtin option to SWIG, but operator overloads are particularly
attractive when using -builtin, because they are much faster
than named methods.
If you're using the -builtin option to SWIG, and you want to define
python operator overloads beyond the defaults defined in this file,
here's what you need to know:
There are two ways to define a python slot function: dispatch to a
statically defined function; or dispatch to a method defined on the
operand.
To dispatch to a statically defined function, use %feature("python:<slot>"),
where <slot> is the name of a field in a PyTypeObject, PyNumberMethods,
PyMappingMethods, PySequenceMethods, or PyBufferProcs. For example:
%{
static long myHashFunc (PyObject *pyobj) {
MyClass *cobj;
// Convert pyobj to cobj
return (cobj->field1 * (cobj->field2 << 7));
}
%}
%feature("python:tp_hash") MyClass "myHashFunc";
NOTE: It is the responsibility of the programmer (that's you) to ensure
that a statically defined slot function has the correct signature.
If, instead, you want to dispatch to an instance method, you can
use %feature("python:slot"). For example:
class MyClass {
public:
long myHashFunc () const;
...
};
%feature("python:slot", "tp_hash", functype="hashfunc") MyClass::myHashFunc;
NOTE: Some python slots use a method signature which does not
match the signature of SWIG-wrapped methods. For those slots,
SWIG will automatically generate a "closure" function to re-marshall
the arguments before dispatching to the wrapped method. Setting
the "functype" attribute of the feature enables SWIG to generate
a correct closure function.
--------------------------------------------------------------
The tp_richcompare slot is a special case: SWIG automatically generates
a rich compare function for all wrapped types. If a type defines C++
operator overloads for comparison (operator==, operator<, etc.), they
will be called from the generated rich compare function. If you
want to explicitly choose a method to handle a certain comparison
operation, you may use %feature("python:slot") like this:
class MyClass {
public:
bool lessThan (const MyClass& x) const;
...
};
%feature("python:slot", "Py_LT") MyClass::lessThan;
... where "Py_LT" is one of rich comparison opcodes defined in the
python header file object.h.
If there's no method defined to handle a particular comparsion operation,
the default behavior is to compare pointer values of the wrapped
C++ objects.
--------------------------------------------------------------
For more information about python slots, including their names and
signatures, you may refer to the python documentation :
http://docs.python.org/c-api/typeobj.html
* ------------------------------------------------------------ */
#ifdef __cplusplus
#define %pybinoperator(pyname,oper) %rename(pyname) oper; %pythonmaybecall oper
%pybinoperator(__add__, *::operator+);
%pybinoperator(__pos__, *::operator+());
%pybinoperator(__pos__, *::operator+() const);
%pybinoperator(__sub__, *::operator-);
%pybinoperator(__neg__, *::operator-());
%pybinoperator(__neg__, *::operator-() const);
%pybinoperator(__mul__, *::operator*);
%pybinoperator(__div__, *::operator/);
%pybinoperator(__mod__, *::operator%);
%pybinoperator(__lshift__, *::operator<<);
%pybinoperator(__rshift__, *::operator>>);
%pybinoperator(__and__, *::operator&);
%pybinoperator(__or__, *::operator|);
%pybinoperator(__xor__, *::operator^);
%pybinoperator(__lt__, *::operator<);
%pybinoperator(__le__, *::operator<=);
%pybinoperator(__gt__, *::operator>);
%pybinoperator(__ge__, *::operator>=);
%pybinoperator(__eq__, *::operator==);
%pybinoperator(__ne__, *::operator!=);
#if defined(SWIGPYTHON_BUILTIN)
#define %pybinoperator(pyname,oper,functp,slt) %rename(pyname) oper; %pythonmaybecall oper; %feature("python:slot", #slt, functype=#functp) oper; %feature("python:slot", #slt, functype=#functp) pyname;
#define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("python:compare", #comptype) oper; %feature("python:compare", #comptype) pyname;
#else
#define %pybinoperator(pyname,oper,functp,slt) %rename(pyname) oper; %pythonmaybecall oper
#define %pycompare(pyname,oper,comptype) %pybinoperator(pyname,oper,,comptype)
#endif
%pybinoperator(__add__, *::operator+, binaryfunc, nb_add);
%pybinoperator(__pos__, *::operator+(), unaryfunc, nb_positive);
%pybinoperator(__pos__, *::operator+() const, unaryfunc, nb_positive);
%pybinoperator(__sub__, *::operator-, binaryfunc, nb_subtract);
%pybinoperator(__neg__, *::operator-(), unaryfunc, nb_negative);
%pybinoperator(__neg__, *::operator-() const, unaryfunc, nb_negative);
%pybinoperator(__mul__, *::operator*, binaryfunc, nb_multiply);
%pybinoperator(__div__, *::operator/, binaryfunc, nb_div);
%pybinoperator(__mod__, *::operator%, binaryfunc, nb_remainder);
%pybinoperator(__lshift__, *::operator<<, binaryfunc, nb_lshift);
%pybinoperator(__rshift__, *::operator>>, binaryfunc, nb_rshift);
%pybinoperator(__and__, *::operator&, binaryfunc, nb_and);
%pybinoperator(__or__, *::operator|, binaryfunc, nb_or);
%pybinoperator(__xor__, *::operator^, binaryfunc, nb_xor);
%pycompare(__lt__, *::operator<, Py_LT);
%pycompare(__le__, *::operator<=, Py_LE);
%pycompare(__gt__, *::operator>, Py_GT);
%pycompare(__ge__, *::operator>=, Py_GE);
%pycompare(__eq__, *::operator==, Py_EQ);
%pycompare(__ne__, *::operator!=, Py_NE);
%feature("python:slot", "nb_truediv", functype="binaryfunc") *::operator/;
/* Special cases */
%rename(__invert__) *::operator~;
%feature("python:slot", "nb_invert", functype="unaryfunc") *::operator~;
%rename(__call__) *::operator();
%feature("python:slot", "tp_call", functype="ternaryfunc") *::operator();
#if defined(SWIGPYTHON_BUILTIN)
%pybinoperator(__nonzero__, *::operator bool, inquiry, nb_nonzero);
#else
%feature("shadow") *::operator bool %{
def __nonzero__(self):
return $action(self)
__bool__ = __nonzero__
%};
%rename(__nonzero__) *::operator bool;
#endif
/* Ignored operators */
%ignoreoperator(LNOT) operator!;
@ -90,18 +185,22 @@ __bool__ = __nonzero__
*/
#define %pyinplaceoper(SwigPyOper, Oper) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper
#if defined(SWIGPYTHON_BUILTIN)
#define %pyinplaceoper(SwigPyOper, Oper, functp, slt) %delobject Oper; %newobject Oper; %feature("python:slot", #slt, functype=#functp) Oper; %rename(SwigPyOper) Oper
#else
#define %pyinplaceoper(SwigPyOper, Oper, functp, slt) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper
#endif
%pyinplaceoper(__iadd__ , *::operator +=);
%pyinplaceoper(__isub__ , *::operator -=);
%pyinplaceoper(__imul__ , *::operator *=);
%pyinplaceoper(__idiv__ , *::operator /=);
%pyinplaceoper(__imod__ , *::operator %=);
%pyinplaceoper(__iand__ , *::operator &=);
%pyinplaceoper(__ior__ , *::operator |=);
%pyinplaceoper(__ixor__ , *::operator ^=);
%pyinplaceoper(__ilshift__, *::operator <<=);
%pyinplaceoper(__irshift__, *::operator >>=);
%pyinplaceoper(__iadd__ , *::operator +=, binaryfunc, nb_inplace_add);
%pyinplaceoper(__isub__ , *::operator -=, binaryfunc, nb_inplace_subtract);
%pyinplaceoper(__imul__ , *::operator *=, binaryfunc, nb_inplace_multiply);
%pyinplaceoper(__idiv__ , *::operator /=, binaryfunc, nb_inplace_divide);
%pyinplaceoper(__imod__ , *::operator %=, binaryfunc, nb_inplace_remainder);
%pyinplaceoper(__iand__ , *::operator &=, binaryfunc, nb_inplace_and);
%pyinplaceoper(__ior__ , *::operator |=, binaryfunc, nb_inplace_or);
%pyinplaceoper(__ixor__ , *::operator ^=, binaryfunc, nb_inplace_xor);
%pyinplaceoper(__ilshift__, *::operator <<=, binaryfunc, nb_inplace_lshift);
%pyinplaceoper(__irshift__, *::operator >>=, binaryfunc, nb_inplace_rshift);
/* Finally, in python we need to mark the binary operations to fail as

View file

@ -13,7 +13,15 @@
#define SWIG_Python_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, 0)
#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags)
#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, own)
#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(ptr, type, flags)
#ifdef SWIGPYTHON_BUILTIN
#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(self, ptr, type, flags)
#else
#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(NULL, ptr, type, flags)
#endif
#define SWIG_InternalNewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(NULL, ptr, type, flags)
#define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty)
#define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src)
#define swig_owntype int
@ -28,7 +36,7 @@
/* for C or C++ function pointers */
#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Python_ConvertFunctionPtr(obj, pptr, type)
#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(ptr, type, 0)
#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(NULL, ptr, type, 0)
/* for C++ member pointers, ie, member methods */
#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty)
@ -71,12 +79,33 @@ SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) {
/* Set a constant value */
#if defined(SWIGPYTHON_BUILTIN)
SWIGINTERN void
SwigPyBuiltin_AddPublicSymbol(PyObject *seq, const char *key) {
PyObject *s = PyString_InternFromString(key);
PyList_Append(seq, s);
Py_DECREF(s);
}
SWIGINTERN void
SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *name, PyObject *obj) {
PyDict_SetItemString(d, (char *)name, obj);
Py_DECREF(obj);
if (public_interface)
SwigPyBuiltin_AddPublicSymbol(public_interface, name);
}
#else
SWIGINTERN void
SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) {
PyDict_SetItemString(d, (char*) name, obj);
PyDict_SetItemString(d, (char *)name, obj);
Py_DECREF(obj);
}
#endif
/* Append a value to the result obj */
SWIGINTERN PyObject*
@ -137,6 +166,14 @@ SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssi
}
}
if (!PyTuple_Check(args)) {
if (min <= 1 && max >= 1) {
objs[0] = args;
register int i;
for (i = 1; i < max; ++i) {
objs[i] = 0;
}
return 2;
}
PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple");
return 0;
} else {
@ -189,6 +226,9 @@ SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssi
#define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1)
#define SWIG_BUILTIN_TP_INIT (SWIG_POINTER_OWN << 2)
#define SWIG_BUILTIN_INIT (SWIG_BUILTIN_TP_INIT | SWIG_POINTER_OWN)
#ifdef __cplusplus
extern "C" {
#if 0
@ -244,6 +284,7 @@ typedef struct {
PyObject *destroy;
int delargs;
int implicitconv;
PyTypeObject *pytype;
} SwigPyClientData;
SWIGRUNTIMEINLINE int
@ -310,13 +351,13 @@ SwigPyClientData_New(PyObject* obj)
data->delargs = 0;
}
data->implicitconv = 0;
data->pytype = 0;
return data;
}
}
SWIGRUNTIME void
SwigPyClientData_Del(SwigPyClientData* data)
{
SwigPyClientData_Del(SwigPyClientData *data) {
Py_XDECREF(data->newraw);
Py_XDECREF(data->newargs);
Py_XDECREF(data->destroy);
@ -330,6 +371,9 @@ typedef struct {
swig_type_info *ty;
int own;
PyObject *next;
#ifdef SWIGPYTHON_BUILTIN
PyObject *dict;
#endif
} SwigPyObject;
SWIGRUNTIME PyObject *
@ -380,21 +424,21 @@ SwigPyObject_repr(SwigPyObject *v, PyObject *args)
#endif
{
const char *name = SWIG_TypePrettyName(v->ty);
PyObject *repr = SWIG_Python_str_FromFormat("<Swig Object of type '%s' at %p>", name, v);
PyObject *repr = SWIG_Python_str_FromFormat("<Swig Object of type '%s' at %p>", name, (void *)v);
if (v->next) {
#ifdef METH_NOARGS
# ifdef METH_NOARGS
PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next);
#else
# else
PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next, args);
#endif
#if PY_VERSION_HEX >= 0x03000000
# endif
# if PY_VERSION_HEX >= 0x03000000
PyObject *joined = PyUnicode_Concat(repr, nrep);
Py_DecRef(repr);
Py_DecRef(nrep);
repr = joined;
#else
# else
PyString_ConcatAndDel(&repr,nrep);
#endif
# endif
}
return repr;
}
@ -453,18 +497,38 @@ SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op)
}
SWIGRUNTIME PyTypeObject* _PySwigObject_type(void);
SWIGRUNTIME PyTypeObject* SwigPyObject_TypeOnce(void);
#ifdef SWIGPYTHON_BUILTIN
static swig_type_info *SwigPyObject_stype = 0;
SWIGRUNTIME PyTypeObject*
SwigPyObject_type(void) {
static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigObject_type();
assert(SwigPyObject_stype);
SwigPyClientData *cd = (SwigPyClientData*) SwigPyObject_stype->clientdata;
assert(cd);
assert(cd->pytype);
return cd->pytype;
}
#else
SWIGRUNTIME PyTypeObject*
SwigPyObject_type(void) {
static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyObject_TypeOnce();
return type;
}
#endif
SWIGRUNTIMEINLINE int
SwigPyObject_Check(PyObject *op) {
#ifdef SWIGPYTHON_BUILTIN
PyTypeObject *target_tp = SwigPyObject_type();
PyTypeObject *obj_tp;
if (PyType_IsSubtype(op->ob_type, target_tp))
return 1;
return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0);
#else
return (Py_TYPE(op) == SwigPyObject_type())
|| (strcmp(Py_TYPE(op)->tp_name,"SwigPyObject") == 0);
#endif
}
SWIGRUNTIME PyObject *
@ -630,9 +694,9 @@ SwigPyObject_getattr(SwigPyObject *sobj,char *name)
#endif
SWIGRUNTIME PyTypeObject*
_PySwigObject_type(void) {
SwigPyObject_TypeOnce(void) {
static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer";
static PyNumberMethods SwigPyObject_as_number = {
(binaryfunc)0, /*nb_add*/
(binaryfunc)0, /*nb_subtract*/
@ -679,7 +743,7 @@ _PySwigObject_type(void) {
#endif
};
static PyTypeObject swigpyobject_type;
static PyTypeObject swigpyobject_type;
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp
@ -687,7 +751,7 @@ _PySwigObject_type(void) {
/* PyObject header changed in Python 3 */
#if PY_VERSION_HEX >= 0x03000000
PyVarObject_HEAD_INIT(&PyType_Type, 0)
#else
#else
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
#endif
@ -697,17 +761,17 @@ _PySwigObject_type(void) {
(destructor)SwigPyObject_dealloc, /* tp_dealloc */
(printfunc)SwigPyObject_print, /* tp_print */
#if PY_VERSION_HEX < 0x02020000
(getattrfunc)SwigPyObject_getattr, /* tp_getattr */
(getattrfunc)SwigPyObject_getattr, /* tp_getattr */
#else
(getattrfunc)0, /* tp_getattr */
(getattrfunc)0, /* tp_getattr */
#endif
(setattrfunc)0, /* tp_setattr */
(setattrfunc)0, /* tp_setattr */
#if PY_VERSION_HEX >= 0x03000000
0, /* tp_reserved in 3.0.1, tp_compare in 3.0.0 but not used */
#else
(cmpfunc)SwigPyObject_compare, /* tp_compare */
#endif
(reprfunc)SwigPyObject_repr, /* tp_repr */
(reprfunc)SwigPyObject_repr, /* tp_repr */
&SwigPyObject_as_number, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
@ -718,7 +782,7 @@ _PySwigObject_type(void) {
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
swigobject_doc, /* tp_doc */
swigobject_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
(richcmpfunc)SwigPyObject_richcompare, /* tp_richcompare */
@ -726,28 +790,31 @@ _PySwigObject_type(void) {
#if PY_VERSION_HEX >= 0x02020000
0, /* tp_iter */
0, /* tp_iternext */
swigobject_methods, /* tp_methods */
swigobject_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_mro */
0, /* tp_cache */
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
#endif
#if PY_VERSION_HEX >= 0x02030000
0, /* tp_del */
#endif
#if PY_VERSION_HEX >= 0x02060000
0, /* tp_version */
#endif
#ifdef COUNT_ALLOCS
0,0,0,0 /* tp_alloc -> tp_next */
#endif
@ -831,17 +898,17 @@ SwigPyPacked_compare(SwigPyPacked *v, SwigPyPacked *w)
return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size);
}
SWIGRUNTIME PyTypeObject* _PySwigPacked_type(void);
SWIGRUNTIME PyTypeObject* SwigPyPacked_TypeOnce(void);
SWIGRUNTIME PyTypeObject*
SwigPyPacked_type(void) {
static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigPacked_type();
static PyTypeObject *SWIG_STATIC_POINTER(type) = SwigPyPacked_TypeOnce();
return type;
}
SWIGRUNTIMEINLINE int
SwigPyPacked_Check(PyObject *op) {
return ((op)->ob_type == _PySwigPacked_type())
return ((op)->ob_type == SwigPyPacked_TypeOnce())
|| (strcmp((op)->ob_type->tp_name,"SwigPyPacked") == 0);
}
@ -856,10 +923,10 @@ SwigPyPacked_dealloc(PyObject *v)
}
SWIGRUNTIME PyTypeObject*
_PySwigPacked_type(void) {
SwigPyPacked_TypeOnce(void) {
static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer";
static PyTypeObject swigpypacked_type;
static int type_init = 0;
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp
= {
@ -901,28 +968,31 @@ _PySwigPacked_type(void) {
#if PY_VERSION_HEX >= 0x02020000
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_mro */
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
#endif
#if PY_VERSION_HEX >= 0x02030000
0, /* tp_del */
#endif
#if PY_VERSION_HEX >= 0x02060000
0, /* tp_version */
#endif
#ifdef COUNT_ALLOCS
0,0,0,0 /* tp_alloc -> tp_next */
#endif
@ -999,50 +1069,63 @@ SWIG_This(void)
SWIGRUNTIME SwigPyObject *
SWIG_Python_GetSwigThis(PyObject *pyobj)
{
if (SwigPyObject_Check(pyobj)) {
PyObject *obj;
if (SwigPyObject_Check(pyobj))
return (SwigPyObject *) pyobj;
} else {
PyObject *obj = 0;
#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000))
if (PyInstance_Check(pyobj)) {
obj = _PyInstance_Lookup(pyobj, SWIG_This());
} else {
PyObject **dictptr = _PyObject_GetDictPtr(pyobj);
if (dictptr != NULL) {
PyObject *dict = *dictptr;
obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0;
} else {
#ifdef PyWeakref_CheckProxy
if (PyWeakref_CheckProxy(pyobj)) {
PyObject *wobj = PyWeakref_GET_OBJECT(pyobj);
return wobj ? SWIG_Python_GetSwigThis(wobj) : 0;
}
#ifdef SWIGPYTHON_BUILTIN
# ifdef PyWeakref_CheckProxy
if (PyWeakref_CheckProxy(pyobj)) {
pyobj = PyWeakref_GET_OBJECT(pyobj);
if (pyobj && SwigPyObject_Check(pyobj))
return (SwigPyObject*) pyobj;
}
# endif
return NULL;
#endif
obj = PyObject_GetAttr(pyobj,SWIG_This());
if (obj) {
Py_DECREF(obj);
} else {
if (PyErr_Occurred()) PyErr_Clear();
return 0;
}
obj = 0;
#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000))
if (PyInstance_Check(pyobj)) {
obj = _PyInstance_Lookup(pyobj, SWIG_This());
} else {
PyObject **dictptr = _PyObject_GetDictPtr(pyobj);
if (dictptr != NULL) {
PyObject *dict = *dictptr;
obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0;
} else {
#ifdef PyWeakref_CheckProxy
if (PyWeakref_CheckProxy(pyobj)) {
PyObject *wobj = PyWeakref_GET_OBJECT(pyobj);
return wobj ? SWIG_Python_GetSwigThis(wobj) : 0;
}
#endif
obj = PyObject_GetAttr(pyobj,SWIG_This());
if (obj) {
Py_DECREF(obj);
} else {
if (PyErr_Occurred()) PyErr_Clear();
return 0;
}
}
#else
obj = PyObject_GetAttr(pyobj,SWIG_This());
if (obj) {
Py_DECREF(obj);
} else {
if (PyErr_Occurred()) PyErr_Clear();
return 0;
}
#endif
if (obj && !SwigPyObject_Check(obj)) {
/* a PyObject is called 'this', try to get the 'real this'
SwigPyObject from it */
return SWIG_Python_GetSwigThis(obj);
}
return (SwigPyObject *)obj;
}
#else
obj = PyObject_GetAttr(pyobj,SWIG_This());
if (obj) {
Py_DECREF(obj);
} else {
if (PyErr_Occurred()) PyErr_Clear();
return 0;
}
#endif
if (obj && !SwigPyObject_Check(obj)) {
/* a PyObject is called 'this', try to get the 'real this'
SwigPyObject from it */
return SWIG_Python_GetSwigThis(obj);
}
return (SwigPyObject *)obj;
}
/* Acquire a pointer value */
@ -1064,91 +1147,97 @@ SWIG_Python_AcquirePtr(PyObject *obj, int own) {
SWIGRUNTIME int
SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) {
if (!obj) return SWIG_ERROR;
int res;
SwigPyObject *sobj;
if (!obj)
return SWIG_ERROR;
if (obj == Py_None) {
if (ptr) *ptr = 0;
if (ptr)
*ptr = 0;
return SWIG_OK;
} else {
SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj);
if (own)
*own = 0;
while (sobj) {
void *vptr = sobj->ptr;
if (ty) {
swig_type_info *to = sobj->ty;
if (to == ty) {
/* no type cast needed */
if (ptr) *ptr = vptr;
break;
} else {
swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
if (!tc) {
sobj = (SwigPyObject *)sobj->next;
} else {
if (ptr) {
int newmemory = 0;
*ptr = SWIG_TypeCast(tc,vptr,&newmemory);
if (newmemory == SWIG_CAST_NEW_MEMORY) {
assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
if (own)
*own = *own | SWIG_CAST_NEW_MEMORY;
}
}
break;
}
}
}
res = SWIG_ERROR;
sobj = SWIG_Python_GetSwigThis(obj);
if (own)
*own = 0;
while (sobj) {
void *vptr = sobj->ptr;
if (ty) {
swig_type_info *to = sobj->ty;
if (to == ty) {
/* no type cast needed */
if (ptr) *ptr = vptr;
break;
} else {
if (ptr) *ptr = vptr;
break;
swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
if (!tc) {
sobj = (SwigPyObject *)sobj->next;
} else {
if (ptr) {
int newmemory = 0;
*ptr = SWIG_TypeCast(tc,vptr,&newmemory);
if (newmemory == SWIG_CAST_NEW_MEMORY) {
assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
if (own)
*own = *own | SWIG_CAST_NEW_MEMORY;
}
}
break;
}
}
}
if (sobj) {
if (own)
*own = *own | sobj->own;
if (flags & SWIG_POINTER_DISOWN) {
sobj->own = 0;
}
return SWIG_OK;
} else {
int res = SWIG_ERROR;
if (flags & SWIG_POINTER_IMPLICIT_CONV) {
SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0;
if (data && !data->implicitconv) {
PyObject *klass = data->klass;
if (klass) {
PyObject *impconv;
data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/
impconv = SWIG_Python_CallFunctor(klass, obj);
data->implicitconv = 0;
if (PyErr_Occurred()) {
PyErr_Clear();
impconv = 0;
}
if (impconv) {
SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv);
if (iobj) {
void *vptr;
res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0);
if (SWIG_IsOK(res)) {
if (ptr) {
*ptr = vptr;
/* transfer the ownership to 'ptr' */
iobj->own = 0;
res = SWIG_AddCast(res);
res = SWIG_AddNewMask(res);
} else {
res = SWIG_AddCast(res);
}
}
}
Py_DECREF(impconv);
}
}
}
}
return res;
if (ptr) *ptr = vptr;
break;
}
}
if (sobj) {
if (own)
*own = *own | sobj->own;
if (flags & SWIG_POINTER_DISOWN) {
sobj->own = 0;
}
res = SWIG_OK;
} else {
if (flags & SWIG_POINTER_IMPLICIT_CONV) {
SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0;
if (data && !data->implicitconv) {
PyObject *klass = data->klass;
if (klass) {
PyObject *impconv;
data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/
impconv = SWIG_Python_CallFunctor(klass, obj);
data->implicitconv = 0;
if (PyErr_Occurred()) {
PyErr_Clear();
impconv = 0;
}
if (impconv) {
SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv);
if (iobj) {
void *vptr;
res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0);
if (SWIG_IsOK(res)) {
if (ptr) {
*ptr = vptr;
/* transfer the ownership to 'ptr' */
iobj->own = 0;
res = SWIG_AddCast(res);
res = SWIG_AddNewMask(res);
} else {
res = SWIG_AddCast(res);
}
}
}
Py_DECREF(impconv);
}
}
}
}
}
return res;
}
/* Convert a function ptr value */
@ -1318,22 +1407,54 @@ SWIG_Python_InitShadowInstance(PyObject *args) {
/* Create a new pointer object */
SWIGRUNTIME PyObject *
SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
if (!ptr) {
SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int flags) {
SwigPyClientData *clientdata;
PyObject * robj;
int own;
if (!ptr)
return SWIG_Py_Void();
} else {
int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
PyObject *robj = SwigPyObject_New(ptr, type, own);
SwigPyClientData *clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0;
if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) {
PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj);
if (inst) {
Py_DECREF(robj);
robj = inst;
clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0;
own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
if (clientdata && clientdata->pytype) {
SwigPyObject *newobj;
if (flags & SWIG_BUILTIN_TP_INIT) {
newobj = (SwigPyObject*) self;
if (newobj->ptr) {
PyObject *next_self = clientdata->pytype->tp_alloc(clientdata->pytype, 0);
while (newobj->next)
newobj = (SwigPyObject *) newobj->next;
newobj->next = next_self;
newobj = (SwigPyObject *)next_self;
}
} else {
newobj = PyObject_New(SwigPyObject, clientdata->pytype);
}
return robj;
if (newobj) {
newobj->ptr = ptr;
newobj->ty = type;
newobj->own = own;
newobj->next = 0;
#ifdef SWIGPYTHON_BUILTIN
newobj->dict = 0;
#endif
return (PyObject*) newobj;
}
return SWIG_Py_Void();
}
assert(!(flags & SWIG_BUILTIN_TP_INIT));
robj = SwigPyObject_New(ptr, type, own);
if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) {
PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj);
if (inst) {
Py_DECREF(robj);
robj = inst;
}
}
return robj;
}
/* Create a new packed object */
@ -1562,7 +1683,7 @@ SWIG_Python_TypeError(const char *type, PyObject *obj)
/* Convert a pointer value, signal an exception on a type mismatch */
SWIGRUNTIME void *
SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) {
SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int SWIGUNUSEDPARM(argnum), int flags) {
void *result;
if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) {
PyErr_Clear();
@ -1576,6 +1697,57 @@ SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags)
return result;
}
SWIGRUNTIME int
SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) {
PyTypeObject *tp = obj->ob_type;
PyObject *descr;
PyObject *encoded_name;
descrsetfunc f;
int res;
#ifdef Py_USING_UNICODE
if (PyString_Check(name)) {
name = PyUnicode_Decode(PyString_AsString(name), PyString_Size(name), NULL, NULL);
if (!name)
return -1;
} else if (!PyUnicode_Check(name)) {
#else
if (!PyString_Check(name)) {
#endif
PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", name->ob_type->tp_name);
return -1;
} else {
Py_INCREF(name);
}
if (!tp->tp_dict) {
if (PyType_Ready(tp) < 0)
goto done;
}
res = -1;
descr = _PyType_Lookup(tp, name);
f = NULL;
if (descr != NULL)
f = descr->ob_type->tp_descr_set;
if (!f) {
if (PyString_Check(name)) {
encoded_name = name;
Py_INCREF(name);
} else {
encoded_name = PyUnicode_AsUTF8String(name);
}
PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200s'", tp->tp_name, PyString_AsString(encoded_name));
Py_DECREF(encoded_name);
} else {
res = f(descr, obj, value);
}
done:
Py_DECREF(name);
return res;
}
#ifdef __cplusplus
#if 0

View file

@ -11,3 +11,6 @@
%insert(runtime) "pyapi.swg"; /* Python API */
%insert(runtime) "pyrun.swg"; /* Python run-time code */
#if defined(SWIGPYTHON_BUILTIN)
%insert(runtime) "builtin.swg"; /* Specialization for classes with single inheritance */
#endif

View file

@ -6,7 +6,7 @@ namespace swig {
*/
template <class Type> struct traits_from_ptr {
static PyObject *from(Type *val, int owner = 0) {
return SWIG_NewPointerObj(val, type_info<Type>(), owner);
return SWIG_InternalNewPointerObj(val, type_info<Type>(), owner);
}
};

View file

@ -86,7 +86,7 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
if (size > INT_MAX) {
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
return pchar_descriptor ?
SWIG_NewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
SWIG_InternalNewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
} else {
%#if PY_VERSION_HEX >= 0x03000000
return PyUnicode_FromStringAndSize(carray, %numeric_cast(size,int));

View file

@ -51,7 +51,11 @@
#define SWIG_AppendOutput(result, obj) SWIG_Python_AppendOutput(result, obj)
/* set constant */
#define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, name,obj)
#if defined(SWIGPYTHON_BUILTIN)
#define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, d == md ? public_interface : NULL, name,obj)
#else
#define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, name,obj)
#endif
/* raise */
#define SWIG_Raise(obj, type, desc) SWIG_Python_Raise(obj, type, desc)
@ -84,6 +88,12 @@
$result = SWIG_NewPointerObj(%new_copy(*$1, $*ltype), $descriptor, SWIG_POINTER_OWN | %newpointer_flags);
}
/*
%typemap(builtin_init,noblock=1) const SWIGTYPE & SMARTPOINTER {
$result = SWIG_NewBuiltinObj(self, %new_copy(*$1, $*ltype), $descriptor, SWIG_POINTER_OWN | %newpointer_flags);
}
*/
%typemap(ret,noblock=1) const SWIGTYPE & SMARTPOINTER, SWIGTYPE SMARTPOINTER {
if ($result) {
PyObject *robj = PyObject_CallMethod($result, (char *)"__deref__", NULL);
@ -95,4 +105,24 @@
}
}
/* -------------------------------------------------------------
* Output typemap for the __init__ method of a built-in type.
* ------------------------------------------------------------ */
/* Pointers, references */
/*
%typemap(builtin_init,noblock=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE[] {
%set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr($1), $descriptor, $owner | %newpointer_flags));
}
*/
/*
%typemap(builtin_init, noblock=1) SWIGTYPE *const& {
%set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(*$1), $*descriptor, $owner | %newpointer_flags));
}
*/
/* Return by value */
/*
%typemap(builtin_init, noblock=1) SWIGTYPE {
%set_output(SWIG_Python_NewBuiltinObj(self, %new_copy($1, $ltype), $&descriptor, $owner | %newpointer_flags));
}
*/

View file

@ -50,7 +50,7 @@ SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size)
if (size > INT_MAX) {
swig_type_info* pwchar_descriptor = SWIG_pwchar_descriptor();
return pwchar_descriptor ?
SWIG_NewPointerObj(%const_cast(carray,wchar_t *), pwchar_descriptor, 0) : SWIG_Py_Void();
SWIG_InternalNewPointerObj(%const_cast(carray,wchar_t *), pwchar_descriptor, 0) : SWIG_Py_Void();
} else {
return PyUnicode_FromWideChar(carray, %numeric_cast(size,int));
}

View file

@ -47,7 +47,7 @@
static PyObject *from(const map_type& map) {
swig_type_info *desc = swig::type_info<map_type>();
if (desc && desc->clientdata) {
return SWIG_NewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN);
return SWIG_InternalNewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN);
} else {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
size_type size = map.size();
@ -119,6 +119,17 @@
return new SwigPyMapKeyIterator_T<OutIter>(current, begin, end, seq);
}
template<typename Sequence>
inline PyObject* make_output_key_iterator_builtin (PyObject *pyself)
{
SwigPyObject *builtin_obj = (SwigPyObject*) pyself;
Sequence *seq = reinterpret_cast< Sequence * >(builtin_obj->ptr);
if (!seq)
return SWIG_Py_Void();
SwigPyIterator *iter = make_output_key_iterator(seq->begin(), seq->begin(), seq->end(), pyself);
return SWIG_InternalNewPointerObj(iter, SWIGTYPE_p_swig__SwigPyIterator, SWIG_POINTER_OWN);
}
template<class OutIterator,
class FromOper = from_value_oper<typename OutIterator::value_type> >
struct SwigPyMapValueITerator_T : SwigPyMapIterator_T<OutIterator, FromOper>
@ -136,6 +147,7 @@
{
return new SwigPyMapValueITerator_T<OutIter>(current, begin, end, seq);
}
}
}
@ -143,6 +155,37 @@
%swig_sequence_iterator(Map);
%swig_container_methods(Map)
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "mp_length", functype="lenfunc") __len__;
%feature("python:slot", "mp_subscript", functype="binaryfunc") __getitem__;
%feature("python:slot", "tp_iter", functype="getiterfunc") key_iterator;
%extend {
%newobject iterkeys(PyObject **PYTHON_SELF);
swig::SwigPyIterator* iterkeys(PyObject **PYTHON_SELF) {
return swig::make_output_key_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%newobject itervalues(PyObject **PYTHON_SELF);
swig::SwigPyIterator* itervalues(PyObject **PYTHON_SELF) {
return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%newobject iteritems(PyObject **PYTHON_SELF);
swig::SwigPyIterator* iteritems(PyObject **PYTHON_SELF) {
return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
}
#else
%extend {
%pythoncode {def __iter__(self): return self.key_iterator()}
%pythoncode {def iterkeys(self): return self.key_iterator()}
%pythoncode {def itervalues(self): return self.value_iterator()}
%pythoncode {def iteritems(self): return self.iterator()}
}
#endif
%extend {
mapped_type __getitem__(const key_type& key) const throw (std::out_of_range) {
Map::const_iterator i = self->find(key);
@ -151,7 +194,7 @@
else
throw std::out_of_range("key not found");
}
void __delitem__(const key_type& key) throw (std::out_of_range) {
Map::iterator i = self->find(key);
if (i != self->end())
@ -236,21 +279,30 @@
swig::SwigPyIterator* value_iterator(PyObject **PYTHON_SELF) {
return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%pythoncode {def __iter__(self): return self.key_iterator()}
%pythoncode {def iterkeys(self): return self.key_iterator()}
%pythoncode {def itervalues(self): return self.value_iterator()}
%pythoncode {def iteritems(self): return self.iterator()}
}
%enddef
%define %swig_map_methods(Map...)
%swig_map_common(Map)
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "mp_ass_subscript", functype="objobjargproc") __setitem__;
#endif
%extend {
// This will be called through the mp_ass_subscript slot to delete an entry.
void __setitem__(const key_type& key) {
self->erase(key);
}
}
%extend {
void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) {
(*self)[key] = x;
}
}
%enddef

View file

@ -42,7 +42,7 @@
static PyObject *from(const multimap_type& multimap) {
swig_type_info *desc = swig::type_info<multimap_type>();
if (desc && desc->clientdata) {
return SWIG_NewPointerObj(new multimap_type(multimap), desc, SWIG_POINTER_OWN);
return SWIG_InternalNewPointerObj(new multimap_type(multimap), desc, SWIG_POINTER_OWN);
} else {
size_type size = multimap.size();
int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1;

View file

@ -116,9 +116,65 @@
}
};
}
#if defined(SWIGPYTHON_BUILTIN)
SWIGINTERN Py_ssize_t
SwigPython_std_pair_len (PyObject *a)
{
return 2;
}
SWIGINTERN PyObject*
SwigPython_std_pair_repr (PyObject *o)
{
PyObject *tuple = PyTuple_New(2);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, PyObject_GetAttrString(o, (char*) "first"));
PyTuple_SET_ITEM(tuple, 1, PyObject_GetAttrString(o, (char*) "second"));
PyObject *result = PyObject_Repr(tuple);
Py_DECREF(tuple);
return result;
}
SWIGINTERN PyObject*
SwigPython_std_pair_getitem (PyObject *a, Py_ssize_t b)
{
PyObject *result = PyObject_GetAttrString(a, b % 2 ? (char*) "second" : (char*) "first");
return result;
}
SWIGINTERN int
SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c)
{
int result = PyObject_SetAttrString(a, b % 2 ? (char*) "second" : (char*) "first", c);
return result;
}
#endif
}
%feature("python:sq_length") std::pair "SwigPython_std_pair_len";
%feature("python:sq_length") std::pair<T*,U> "SwigPython_std_pair_len";
%feature("python:sq_length") std::pair<T,U*> "SwigPython_std_pair_len";
%feature("python:sq_length") std::pair<T*,U*> "SwigPython_std_pair_len";
%feature("python:tp_repr") std::pair "SwigPython_std_pair_repr";
%feature("python:tp_repr") std::pair<T*,U> "SwigPython_std_pair_repr";
%feature("python:tp_repr") std::pair<T,U*> "SwigPython_std_pair_repr";
%feature("python:tp_repr") std::pair<T*,U*> "SwigPython_std_pair_repr";
%feature("python:sq_item") std::pair "SwigPython_std_pair_getitem";
%feature("python:sq_item") std::pair<T*,U> "SwigPython_std_pair_getitem";
%feature("python:sq_item") std::pair<T,U*> "SwigPython_std_pair_getitem";
%feature("python:sq_item") std::pair<T*,U*> "SwigPython_std_pair_getitem";
%feature("python:sq_ass_item") std::pair "SwigPython_std_pair_setitem";
%feature("python:sq_ass_item") std::pair<T*,U> "SwigPython_std_pair_setitem";
%feature("python:sq_ass_item") std::pair<T,U*> "SwigPython_std_pair_setitem";
%feature("python:sq_ass_item") std::pair<T*,U*> "SwigPython_std_pair_setitem";
%define %swig_pair_methods(pair...)
#if !defined(SWIGPYTHON_BUILTIN)
%extend {
%pythoncode {def __len__(self): return 2
def __repr__(self): return str((self.first, self.second))
@ -133,6 +189,7 @@ def __setitem__(self, index, val):
else:
self.second = val}
}
#endif
%enddef
%include <std/std_pair.i>

File diff suppressed because it is too large Load diff