Remove special handling for Python < 2.6

See #701.
This commit is contained in:
Olly Betts 2018-05-18 15:52:46 +12:00
commit 7c034ead32
9 changed files with 56 additions and 454 deletions

View file

@ -150,9 +150,9 @@
<p>
This chapter describes SWIG's support of Python. SWIG is compatible
with most recent Python versions including Python 3.0 and Python 2.6,
as well as older versions dating back to Python 2.0. For the best results,
consider using Python 2.3 or newer.
with most recent Python versions (Python 2.6 and later, including Python 3).
If you still need to generate bindings which work with older versions of
Python, you'll have to use SWIG 3.0.x.
</p>
<p>
@ -860,8 +860,8 @@ installation under "Additional include directories".
<li>Finally, select the settings for the entire project and go to
"Link Options". Add the Python library file to your link libraries.
For example "python21.lib". Also, set the name of the output file to
match the name of your Python module, ie. _example.pyd - Note that _example.dll also worked with Python-2.4 and earlier.
For example "python27.lib". Also, set the name of the output file to
match the name of your Python module, i.e. <tt>_example.pyd</tt>
<li>Build your project.
</ul>
@ -2290,13 +2290,6 @@ please refer to the python documentation:</p>
<p>Use of the <tt>-builtin</tt> option implies a couple of limitations:
<ul>
<li><p>python version support:</p>
<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>
<li><p>Some legacy syntax is no longer supported; in particular:</p>
<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>
@ -2808,43 +2801,6 @@ It is also possible to deal with situations like this using
typemaps--an advanced topic discussed later.
</p>
<H3><a name="Python_nn31">38.4.4 Python 2.2 and classic classes</a></H3>
<p>
SWIG makes every attempt to preserve backwards compatibility with
older versions of Python to the extent that it is possible. However,
in Python-2.2, an entirely new type of class system was introduced.
This new-style class system offers many enhancements including static
member functions, properties (managed attributes), and class methods.
Details about all of these changes can be found on <a
href="https://www.python.org">www.python.org</a> and is not repeated here.
</p>
<p>
To address differences between Python versions, SWIG currently emits
dual-mode proxy class wrappers. In Python-2.2 and newer releases,
these wrappers encapsulate C++ objects in new-style classes that take
advantage of new features (static methods and properties). However,
if these very same wrappers are imported into an older version of Python,
old-style classes are used instead.
</p>
<p>
This dual-nature of the wrapper code means that you can create extension
modules with SWIG and those modules will work with all versions of Python
ranging from Python-2.0 to the very latest release. Moreover, the wrappers take
advantage of Python-2.2 features when available.
</p>
<p>
For the most part, the interface presented to users is the same regardless
of what version of Python is used. The only incompatibility lies in the handling
of static member functions. In Python-2.2, they can be accessed via the
class itself. In Python-2.1 and earlier, they have to be accessed as a global
function or through an instance (see the earlier section).
</p>
<H2><a name="Python_directors">38.5 Cross language polymorphism</a></H2>
@ -3430,7 +3386,9 @@ statements.
</p>
<p>
The following shows example usage for Python 2.6 to use <tt>print</tt> as it can in Python 3, that is, as a function instead of a statement:
The following example for Python 2.x shows how to insert code into the
generated wrapper to enable <tt>print</tt> to be used as a Python3-compatible
function instead of a statement:
</p>
<div class="code">
@ -3447,13 +3405,13 @@ print("Loading", "Whizz", "Bang", sep=' ... ')
</div>
<p>
which can be seen when viewing the first few lines of the generated <tt>.py</tt> file:
The insert code can be seen at the start of the generated <tt>.py</tt> file:
</p>
<div class="code">
<pre>
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 2.0.11
# Version 4.0.0
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
@ -6255,8 +6213,8 @@ to do this (remember you are now the Python importer) or use dynamic linking.
<p>
SWIG is able to support Python 3.0. The wrapper code generated by
SWIG can be compiled with both Python 2.x or 3.0. Further more, by
SWIG is able to support Python 3.x. The wrapper code generated by
SWIG can be compiled with both Python 2.x or 3.x. Further more, by
passing the <tt>-py3</tt> command line option to SWIG, wrapper code
with some Python 3 specific features can be generated (see below
subsections for details of these features). The <tt>-py3</tt> option also
@ -6274,7 +6232,7 @@ There is a list of known-to-be-broken features in Python 3:
</ul>
<p>
The following are Python 3.0 new features that are currently supported by
The following are Python 3 new features that are currently supported by
SWIG.
</p>
@ -6333,8 +6291,8 @@ void get_path(char *s);
<p>
Then you can write a typemap like this: (the following example is
applied to both Python 3.0 and 2.6, since the <tt>bytearray</tt> type
is backported to 2.6.
applied to both Python 2 and 3, since the <tt>bytearray</tt> type
was backported to 2.6.
</p>

View file

@ -84,16 +84,11 @@ def container_insert_step(i, j, step, newval):
except IndexError, e:
il_error = e
# Python 2.6 contains bug fixes in extended slicing syntax:
# http://docs.python.org/2/whatsnew/2.6.html
skip_check = ps_error != None and(
iv_error == il_error == None) and step > 0 and (sys.version_info[0:2] < (2, 6))
if not(skip_check):
if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))):
raise RuntimeError, "ValueError exception not consistently thrown: " + \
str(ps_error) + " " + str(iv_error) + " " + str(il_error)
if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))):
raise RuntimeError, "ValueError exception not consistently thrown: " + \
str(ps_error) + " " + str(iv_error) + " " + str(il_error)
compare_containers(ps, iv, il)
compare_containers(ps, iv, il)
# Check std::vector and std::list delete behaves same as Python list

View file

@ -1,17 +1,9 @@
import python_strict_unicode
from sys import version_info
test_bytes = 'hello \x01world\x99'
BYTES = 'BYTES'
test_bytes = b'hello \x01world\x99'
BYTES = b'BYTES'
test_unicode = u'h\udce9llo w\u00f6rld'
# Python < 2.6 rejects the b prefix for byte string literals as a SyntaxError,
# so instead create Python3 bytes objects by encoding unicode strings as
# latin-1, which maps code points 0-255 directly to the corresponding bytes.
if version_info[0] >= 3:
test_bytes = test_bytes.encode('latin-1')
BYTES = BYTES.encode('latin-1')
# Test that byte string inputs and outputs work as expected
bdbl = python_strict_unicode.double_str(test_bytes)
if bdbl != test_bytes + test_bytes:

View file

@ -254,12 +254,8 @@ SwigPyStaticVar_Type(void) {
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
#if PY_VERSION_HEX >= 0x02030000
0, /* tp_del */
#endif
#if PY_VERSION_HEX >= 0x02060000
0, /* tp_version_tag */
#endif
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
@ -267,20 +263,14 @@ SwigPyStaticVar_Type(void) {
0, /* tp_allocs */
0, /* tp_frees */
0, /* tp_maxalloc */
#if PY_VERSION_HEX >= 0x02050000
0, /* tp_prev */
#endif
0 /* tp_next */
#endif
};
staticvar_type = tmp;
type_init = 1;
#if PY_VERSION_HEX < 0x02020000
staticvar_type.ob_type = &PyType_Type;
#else
if (PyType_Ready(&staticvar_type) < 0)
return NULL;
#endif
}
return &staticvar_type;
}
@ -342,12 +332,8 @@ SwigPyObjectType(void) {
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
#if PY_VERSION_HEX >= 0x02030000
0, /* tp_del */
#endif
#if PY_VERSION_HEX >= 0x02060000
0, /* tp_version_tag */
#endif
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
@ -355,21 +341,15 @@ SwigPyObjectType(void) {
0, /* tp_allocs */
0, /* tp_frees */
0, /* tp_maxalloc */
#if PY_VERSION_HEX >= 0x02050000
0, /* tp_prev */
#endif
0 /* tp_next */
#endif
};
swigpyobjecttype_type = tmp;
type_init = 1;
swigpyobjecttype_type.tp_base = &PyType_Type;
#if PY_VERSION_HEX < 0x02020000
swigpyobjecttype_type.ob_type = &PyType_Type;
#else
if (PyType_Ready(&swigpyobjecttype_type) < 0)
return NULL;
#endif
}
return &swigpyobjecttype_type;
}

View file

@ -71,143 +71,15 @@ SWIG_Python_str_FromChar(const char *c)
#endif
}
/* Add PyOS_snprintf for old Pythons */
#if PY_VERSION_HEX < 0x02020000
# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM)
# define PyOS_snprintf _snprintf
# else
# define PyOS_snprintf snprintf
# endif
#endif
/* A crude PyString_FromFormat implementation for old Pythons */
#if PY_VERSION_HEX < 0x02020000
#ifndef SWIG_PYBUFFER_SIZE
# define SWIG_PYBUFFER_SIZE 1024
#endif
static PyObject *
PyString_FromFormat(const char *fmt, ...) {
va_list ap;
char buf[SWIG_PYBUFFER_SIZE * 2];
int res;
va_start(ap, fmt);
res = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf);
}
#endif
#ifndef PyObject_DEL
# define PyObject_DEL PyObject_Del
#endif
/* A crude PyExc_StopIteration exception for old Pythons */
#if PY_VERSION_HEX < 0x02020000
# ifndef PyExc_StopIteration
# define PyExc_StopIteration PyExc_RuntimeError
# endif
# ifndef PyObject_GenericGetAttr
# define PyObject_GenericGetAttr 0
# endif
#endif
/* Py_NotImplemented is defined in 2.1 and up. */
#if PY_VERSION_HEX < 0x02010000
# ifndef Py_NotImplemented
# define Py_NotImplemented PyExc_RuntimeError
# endif
#endif
/* A crude PyString_AsStringAndSize implementation for old Pythons */
#if PY_VERSION_HEX < 0x02010000
# ifndef PyString_AsStringAndSize
# define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;}
# endif
#endif
/* PySequence_Size for old Pythons */
#if PY_VERSION_HEX < 0x02000000
# ifndef PySequence_Size
# define PySequence_Size PySequence_Length
# endif
#endif
/* PyBool_FromLong for old Pythons */
#if PY_VERSION_HEX < 0x02030000
static
PyObject *PyBool_FromLong(long ok)
{
PyObject *result = ok ? Py_True : Py_False;
Py_INCREF(result);
return result;
}
#endif
/* Py_ssize_t for old Pythons */
/* This code is as recommended by: */
/* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */
#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
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 long PyNumber_AsSsize_t (PyObject *x, void *SWIGUNUSEDPARM(exc))
{
long result = 0;
PyObject *i = PyNumber_Int(x);
if (i) {
result = PyInt_AsLong(i);
Py_DECREF(i);
}
return result;
}
#endif
#if PY_VERSION_HEX < 0x02050000
#define PyInt_FromSize_t(x) PyInt_FromLong((long)x)
#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
#if ((PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION > 6) || \
(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION > 0) || \
(PY_MAJOR_VERSION > 3))
# define SWIGPY_USE_CAPSULE
# define SWIGPY_CAPSULE_NAME ((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION ".type_pointer_capsule" SWIG_TYPE_TABLE_NAME)
# define SWIGPY_CAPSULE_NAME ("swig_runtime_data" SWIG_RUNTIME_VERSION ".type_pointer_capsule" SWIG_TYPE_TABLE_NAME)
#endif
#if PY_VERSION_HEX < 0x03020000

View file

@ -175,15 +175,9 @@ swig_varlink_type(void) {
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
#if PY_VERSION_HEX >= 0x02020000
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */
#endif
#if PY_VERSION_HEX >= 0x02030000
0, /* tp_del */
#endif
#if PY_VERSION_HEX >= 0x02060000
0, /* tp_version_tag */
#endif
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
@ -191,20 +185,14 @@ swig_varlink_type(void) {
0, /* tp_allocs */
0, /* tp_frees */
0, /* tp_maxalloc */
#if PY_VERSION_HEX >= 0x02050000
0, /* tp_prev */
#endif
0 /* tp_next */
#endif
};
varlink_type = tmp;
type_init = 1;
#if PY_VERSION_HEX < 0x02020000
varlink_type.ob_type = &PyType_Type;
#else
if (PyType_Ready(&varlink_type) < 0)
return NULL;
#endif
}
return &varlink_type;
}

View file

@ -7,6 +7,10 @@
*
* ----------------------------------------------------------------------------- */
#if PY_VERSION_HEX < 0x02060000 /* 2.6.0 */
# error "This version of SWIG only supports Python >= 2.6"
#endif
/* Common SWIG API */
/* for raw pointers */
@ -90,11 +94,7 @@ SwigPyBuiltin_AddPublicSymbol(PyObject *seq, const char *key) {
SWIGINTERN void
SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *name, PyObject *obj) {
#if PY_VERSION_HEX < 0x02030000
PyDict_SetItemString(d, (char *)name, obj);
#else
PyDict_SetItemString(d, name, obj);
#endif
Py_DECREF(obj);
if (public_interface)
SwigPyBuiltin_AddPublicSymbol(public_interface, name);
@ -104,11 +104,7 @@ SWIG_Python_SetConstant(PyObject *d, PyObject *public_interface, const char *nam
SWIGINTERN void
SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) {
#if PY_VERSION_HEX < 0x02030000
PyDict_SetItemString(d, (char *)name, obj);
#else
PyDict_SetItemString(d, name, obj);
#endif
Py_DECREF(obj);
}
@ -208,11 +204,7 @@ SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssi
}
/* A functor is a function object with one single object argument */
#if PY_VERSION_HEX >= 0x02020000
#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL);
#else
#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunction(functor, "O", obj);
#endif
#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunction(functor, (char*)"O", obj);
/*
Helper for static pointer initialization for both C and C++ code, for example
@ -258,7 +250,7 @@ extern "C" {
SWIGRUNTIMEINLINE PyObject *
_SWIG_Py_None(void)
{
PyObject *none = Py_BuildValue((char*)"");
PyObject *none = Py_BuildValue("");
Py_DECREF(none);
return none;
}
@ -323,11 +315,7 @@ SwigPyClientData_New(PyObject* obj)
data->newargs = obj;
Py_INCREF(obj);
} else {
#if (PY_VERSION_HEX < 0x02020000)
data->newraw = 0;
#else
data->newraw = PyObject_GetAttrString(data->klass, (char *)"__new__");
#endif
data->newraw = PyObject_GetAttrString(data->klass, "__new__");
if (data->newraw) {
Py_INCREF(data->newraw);
data->newargs = PyTuple_New(1);
@ -338,7 +326,7 @@ SwigPyClientData_New(PyObject* obj)
Py_INCREF(data->newargs);
}
/* the destroy method, aka as the C++ delete method */
data->destroy = PyObject_GetAttrString(data->klass, (char *)"__swig_destroy__");
data->destroy = PyObject_GetAttrString(data->klass, "__swig_destroy__");
if (PyErr_Occurred()) {
PyErr_Clear();
data->destroy = 0;
@ -347,11 +335,7 @@ SwigPyClientData_New(PyObject* obj)
int flags;
Py_INCREF(data->destroy);
flags = PyCFunction_GET_FLAGS(data->destroy);
#ifdef METH_O
data->delargs = !(flags & (METH_O));
#else
data->delargs = 0;
#endif
} else {
data->delargs = 0;
}
@ -439,20 +423,12 @@ SwigPyObject_hex(SwigPyObject *v)
}
SWIGRUNTIME PyObject *
#ifdef METH_NOARGS
SwigPyObject_repr(SwigPyObject *v)
#else
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 ? name : "unknown"), (void *)v);
if (v->next) {
# ifdef METH_NOARGS
PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next);
# else
PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next, args);
# endif
# if PY_VERSION_HEX >= 0x03000000
PyObject *joined = PyUnicode_Concat(repr, nrep);
Py_DecRef(repr);
@ -579,11 +555,6 @@ SWIGRUNTIME PyObject*
SwigPyObject_append(PyObject* v, PyObject* next)
{
SwigPyObject *sobj = (SwigPyObject *) v;
#ifndef METH_O
PyObject *tmp = 0;
if (!PyArg_ParseTuple(next,(char *)"O:append", &tmp)) return NULL;
next = tmp;
#endif
if (!SwigPyObject_Check(next)) {
PyErr_SetString(PyExc_TypeError, "Attempt to append a non SwigPyObject");
return NULL;
@ -594,11 +565,7 @@ SwigPyObject_append(PyObject* v, PyObject* next)
}
SWIGRUNTIME PyObject*
#ifdef METH_NOARGS
SwigPyObject_next(PyObject* v)
#else
SwigPyObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args))
#endif
{
SwigPyObject *sobj = (SwigPyObject *) v;
if (sobj->next) {
@ -610,11 +577,7 @@ SwigPyObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args))
}
SWIGINTERN PyObject*
#ifdef METH_NOARGS
SwigPyObject_disown(PyObject *v)
#else
SwigPyObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args))
#endif
{
SwigPyObject *sobj = (SwigPyObject *)v;
sobj->own = 0;
@ -622,11 +585,7 @@ SwigPyObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args))
}
SWIGINTERN PyObject*
#ifdef METH_NOARGS
SwigPyObject_acquire(PyObject *v)
#else
SwigPyObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args))
#endif
{
SwigPyObject *sobj = (SwigPyObject *)v;
sobj->own = SWIG_POINTER_OWN;
@ -637,13 +596,7 @@ SWIGINTERN PyObject*
SwigPyObject_own(PyObject *v, PyObject *args)
{
PyObject *val = 0;
#if (PY_VERSION_HEX < 0x02020000)
if (!PyArg_ParseTuple(args,(char *)"|O:own",&val))
#elif (PY_VERSION_HEX < 0x02050000)
if (!PyArg_UnpackTuple(args, (char *)"own", 0, 1, &val))
#else
if (!PyArg_UnpackTuple(args, "own", 0, 1, &val))
#endif
{
return NULL;
}
@ -652,55 +605,26 @@ SwigPyObject_own(PyObject *v, PyObject *args)
SwigPyObject *sobj = (SwigPyObject *)v;
PyObject *obj = PyBool_FromLong(sobj->own);
if (val) {
#ifdef METH_NOARGS
if (PyObject_IsTrue(val)) {
SwigPyObject_acquire(v);
} else {
SwigPyObject_disown(v);
}
#else
if (PyObject_IsTrue(val)) {
SwigPyObject_acquire(v,args);
} else {
SwigPyObject_disown(v,args);
}
#endif
}
return obj;
}
}
#ifdef METH_O
static PyMethodDef
swigobject_methods[] = {
{(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"},
{(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_NOARGS, (char *)"acquires ownership of the pointer"},
{(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"},
{(char *)"append", (PyCFunction)SwigPyObject_append, METH_O, (char *)"appends another 'this' object"},
{(char *)"next", (PyCFunction)SwigPyObject_next, METH_NOARGS, (char *)"returns the next 'this' object"},
{(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_NOARGS, (char *)"returns object representation"},
{"disown", (PyCFunction)SwigPyObject_disown, METH_NOARGS, "releases ownership of the pointer"},
{"acquire", (PyCFunction)SwigPyObject_acquire, METH_NOARGS, "acquires ownership of the pointer"},
{"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, "returns/sets ownership of the pointer"},
{"append", (PyCFunction)SwigPyObject_append, METH_O, "appends another 'this' object"},
{"next", (PyCFunction)SwigPyObject_next, METH_NOARGS, "returns the next 'this' object"},
{"__repr__",(PyCFunction)SwigPyObject_repr, METH_NOARGS, "returns object representation"},
{0, 0, 0, 0}
};
#else
static PyMethodDef
swigobject_methods[] = {
{(char *)"disown", (PyCFunction)SwigPyObject_disown, METH_VARARGS, (char *)"releases ownership of the pointer"},
{(char *)"acquire", (PyCFunction)SwigPyObject_acquire, METH_VARARGS, (char *)"acquires ownership of the pointer"},
{(char *)"own", (PyCFunction)SwigPyObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"},
{(char *)"append", (PyCFunction)SwigPyObject_append, METH_VARARGS, (char *)"appends another 'this' object"},
{(char *)"next", (PyCFunction)SwigPyObject_next, METH_VARARGS, (char *)"returns the next 'this' object"},
{(char *)"__repr__",(PyCFunction)SwigPyObject_repr, METH_VARARGS, (char *)"returns object representation"},
{0, 0, 0, 0}
};
#endif
#if PY_VERSION_HEX < 0x02020000
SWIGINTERN PyObject *
SwigPyObject_getattr(SwigPyObject *sobj,char *name)
{
return Py_FindMethod(swigobject_methods, (PyObject *)sobj, name);
}
#endif
SWIGRUNTIME PyTypeObject*
SwigPyObject_TypeOnce(void) {
@ -745,12 +669,8 @@ SwigPyObject_TypeOnce(void) {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_matrix_multiply */
#elif PY_VERSION_HEX >= 0x03000000 /* 3.0 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index, nb_inplace_divide removed */
#elif PY_VERSION_HEX >= 0x02050000 /* 2.5.0 */
#else
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */
#elif PY_VERSION_HEX >= 0x02020000 /* 2.2.0 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */
#elif PY_VERSION_HEX >= 0x02000000 /* 2.0.0 */
0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */
#endif
};
@ -764,16 +684,12 @@ SwigPyObject_TypeOnce(void) {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
#endif
(char *)"SwigPyObject", /* tp_name */
"SwigPyObject", /* tp_name */
sizeof(SwigPyObject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)SwigPyObject_dealloc, /* tp_dealloc */
0, /* tp_print */
#if PY_VERSION_HEX < 0x02020000
(getattrfunc)SwigPyObject_getattr, /* tp_getattr */
#else
(getattrfunc)0, /* tp_getattr */
#endif
(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 */
@ -796,7 +712,6 @@ SwigPyObject_TypeOnce(void) {
0, /* tp_clear */
(richcmpfunc)SwigPyObject_richcompare,/* tp_richcompare */
0, /* tp_weaklistoffset */
#if PY_VERSION_HEX >= 0x02020000
0, /* tp_iter */
0, /* tp_iternext */
swigobject_methods, /* tp_methods */
@ -817,13 +732,8 @@ SwigPyObject_TypeOnce(void) {
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_tag */
#endif
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
@ -831,20 +741,14 @@ SwigPyObject_TypeOnce(void) {
0, /* tp_allocs */
0, /* tp_frees */
0, /* tp_maxalloc */
#if PY_VERSION_HEX >= 0x02050000
0, /* tp_prev */
#endif
0 /* tp_next */
#endif
};
swigpyobject_type = tmp;
type_init = 1;
#if PY_VERSION_HEX < 0x02020000
swigpyobject_type.ob_type = &PyType_Type;
#else
if (PyType_Ready(&swigpyobject_type) < 0)
return NULL;
#endif
}
return &swigpyobject_type;
}
@ -955,7 +859,7 @@ SwigPyPacked_TypeOnce(void) {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
#endif
(char *)"SwigPyPacked", /* tp_name */
"SwigPyPacked", /* tp_name */
sizeof(SwigPyPacked), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)SwigPyPacked_dealloc, /* tp_dealloc */
@ -983,7 +887,6 @@ SwigPyPacked_TypeOnce(void) {
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
#if PY_VERSION_HEX >= 0x02020000
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
@ -1004,13 +907,8 @@ SwigPyPacked_TypeOnce(void) {
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_tag */
#endif
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
@ -1018,20 +916,14 @@ SwigPyPacked_TypeOnce(void) {
0, /* tp_allocs */
0, /* tp_frees */
0, /* tp_maxalloc */
#if PY_VERSION_HEX >= 0x02050000
0, /* tp_prev */
#endif
0 /* tp_next */
#endif
};
swigpypacked_type = tmp;
type_init = 1;
#if PY_VERSION_HEX < 0x02020000
swigpypacked_type.ob_type = &PyType_Type;
#else
if (PyType_Ready(&swigpypacked_type) < 0)
return NULL;
#endif
}
return &swigpypacked_type;
}
@ -1117,7 +1009,7 @@ SWIG_Python_GetSwigThis(PyObject *pyobj)
obj = 0;
#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000))
#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS)
if (PyInstance_Check(pyobj)) {
obj = _PyInstance_Lookup(pyobj, SWIG_This());
} else {
@ -1336,7 +1228,6 @@ SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *t
SWIGRUNTIME PyObject*
SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this)
{
#if (PY_VERSION_HEX >= 0x02020000)
PyObject *inst = 0;
PyObject *newraw = data->newraw;
if (newraw) {
@ -1374,45 +1265,13 @@ SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this)
#endif
}
return inst;
#else
#if (PY_VERSION_HEX >= 0x02010000)
PyObject *inst = 0;
PyObject *dict = PyDict_New();
if (dict) {
PyDict_SetItem(dict, SWIG_This(), swig_this);
inst = PyInstance_NewRaw(data->newargs, dict);
Py_DECREF(dict);
}
return (PyObject *) inst;
#else
PyInstanceObject *inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type);
if (inst == NULL) {
return NULL;
}
inst->in_class = (PyClassObject *)data->newargs;
Py_INCREF(inst->in_class);
inst->in_dict = PyDict_New();
if (inst->in_dict == NULL) {
Py_DECREF(inst);
return NULL;
}
#ifdef Py_TPFLAGS_HAVE_WEAKREFS
inst->in_weakreflist = NULL;
#endif
#ifdef Py_TPFLAGS_GC
PyObject_GC_Init(inst);
#endif
PyDict_SetItem(inst->in_dict, SWIG_This(), swig_this);
return (PyObject *) inst;
#endif
#endif
}
SWIGRUNTIME void
SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this)
{
PyObject *dict;
#if (PY_VERSION_HEX >= 0x02020000) && !defined(SWIG_PYTHON_SLOW_GETSET_THIS)
#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS)
PyObject **dictptr = _PyObject_GetDictPtr(inst);
if (dictptr != NULL) {
dict = *dictptr;
@ -1424,7 +1283,7 @@ SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this)
return;
}
#endif
dict = PyObject_GetAttrString(inst, (char*)"__dict__");
dict = PyObject_GetAttrString(inst, "__dict__");
PyDict_SetItem(dict, SWIG_This(), swig_this);
Py_DECREF(dict);
}
@ -1526,8 +1385,8 @@ SWIG_Python_GetModule(void *SWIGUNUSEDPARM(clientdata)) {
# ifdef SWIGPY_USE_CAPSULE
type_pointer = PyCapsule_Import(SWIGPY_CAPSULE_NAME, 0);
# else
type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION,
(char*)"type_pointer" SWIG_TYPE_TABLE_NAME);
type_pointer = PyCObject_Import((char *)"swig_runtime_data" SWIG_RUNTIME_VERSION,
(char *)"type_pointer" SWIG_TYPE_TABLE_NAME);
# endif
if (PyErr_Occurred()) {
PyErr_Clear();
@ -1567,22 +1426,22 @@ SWIGRUNTIME void
SWIG_Python_SetModule(swig_module_info *swig_module) {
#if PY_VERSION_HEX >= 0x03000000
/* Add a dummy module object into sys.modules */
PyObject *module = PyImport_AddModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION);
PyObject *module = PyImport_AddModule("swig_runtime_data" SWIG_RUNTIME_VERSION);
#else
static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} }; /* Sentinel */
PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, swig_empty_runtime_method_table);
PyObject *module = Py_InitModule("swig_runtime_data" SWIG_RUNTIME_VERSION, swig_empty_runtime_method_table);
#endif
#ifdef SWIGPY_USE_CAPSULE
PyObject *pointer = PyCapsule_New((void *) swig_module, SWIGPY_CAPSULE_NAME, SWIG_Python_DestroyModule);
if (pointer && module) {
PyModule_AddObject(module, (char*)"type_pointer_capsule" SWIG_TYPE_TABLE_NAME, pointer);
PyModule_AddObject(module, "type_pointer_capsule" SWIG_TYPE_TABLE_NAME, pointer);
} else {
Py_XDECREF(pointer);
}
#else
PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, SWIG_Python_DestroyModule);
if (pointer && module) {
PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer);
PyModule_AddObject(module, "type_pointer" SWIG_TYPE_TABLE_NAME, pointer);
} else {
Py_XDECREF(pointer);
}

View file

@ -5,9 +5,7 @@
#endif
#if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */
# if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL)
# if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */
# define SWIG_PYTHON_USE_GIL
# endif
# define SWIG_PYTHON_USE_GIL
# endif
# if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */
# ifndef SWIG_PYTHON_INITIALIZE_THREADS

View file

@ -755,30 +755,6 @@ public:
Printf(f_runtime, "\n");
Printf(f_header, "#if (PY_VERSION_HEX <= 0x02000000)\n");
Printf(f_header, "# if !defined(SWIG_PYTHON_CLASSIC)\n");
Printf(f_header, "# error \"This python version requires swig to be run with the '-classic' option\"\n");
Printf(f_header, "# endif\n");
Printf(f_header, "#endif\n");
if (modern) {
Printf(f_header, "#if (PY_VERSION_HEX <= 0x02020000)\n");
Printf(f_header, "# error \"This python version requires swig to be run with the '-nomodern' option\"\n");
Printf(f_header, "#endif\n");
}
if (modernargs) {
Printf(f_header, "#if (PY_VERSION_HEX <= 0x02020000)\n");
Printf(f_header, "# error \"This python version requires swig to be run with the '-nomodernargs' option\"\n");
Printf(f_header, "#endif\n");
}
if (fastunpack) {
Printf(f_header, "#ifndef METH_O\n");
Printf(f_header, "# error \"This python version requires swig to be run with the '-nofastunpack' option\"\n");
Printf(f_header, "#endif\n");
}
if (fastquery) {
Printf(f_header, "#ifdef SWIG_TypeQuery\n");
Printf(f_header, "# undef SWIG_TypeQuery\n");
@ -863,9 +839,7 @@ public:
* import, and there is thus no guarantee that the C-extension is on
* sys.path. Relative imports must be explicitly specified from 2.6.0
* onwards (implicit relative imports will raise a DeprecationWarning
* in 2.6, and fail in 2.7 onwards), but the relative import syntax
* isn't available in python 2.4 or earlier, so we have to write some
* code conditional on the python version.
* in 2.6, and fail in 2.7 onwards).
*
* For python 2.7.0 and newer, first determine the shadow wrappers package
* based on the __name__ it was given by the importer that loaded it.
@ -907,7 +881,7 @@ public:
Printf(default_import_code, tab4 "%s = swig_import_helper()\n", module);
Printv(default_import_code, tab4, "del swig_import_helper\n", NULL);
Printv(default_import_code, "else:\n", NULL);
Printf(default_import_code, tab4 "import %s\n", module);
Printv(default_import_code, tab4, "raise RuntimeError('Python 2.6 or later required')\n", NULL);
if (builtin) {
/*
@ -939,10 +913,6 @@ public:
* module. */
Printv(default_import_code, "del _swig_python_version_info\n\n", NULL);
if (modern || !classic) {
Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n\n", NULL);
}
/* Need builtins to qualify names like Exception that might also be
defined in this module (try both Python 3 and Python 2 names) */
Printv(f_shadow, "try:\n", tab4, "import builtins as __builtin__\n", "except ImportError:\n", tab4, "import __builtin__\n", NULL);
@ -1012,9 +982,7 @@ public:
}
if (directorsEnabled()) {
// Try loading weakref.proxy, which is only available in Python 2.1 and higher
Printv(f_shadow,
"try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except __builtin__.Exception:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL);
Printv(f_shadow, "import weakref\n\n", NIL);
}
}
// Include some information in the code
@ -3961,7 +3929,7 @@ public:
Printv(f_shadow, tab8, "self.this.disown()\n", NIL);
#endif
Printv(f_shadow, tab8, module, ".", mrename, "(self)\n", NIL);
Printv(f_shadow, tab8, "return weakref_proxy(self)\n", NIL);
Printv(f_shadow, tab8, "return weakref.proxy(self)\n", NIL);
Delete(mrename);
}
}
@ -4253,9 +4221,7 @@ public:
printSlot(f, getSlot(n, "feature:python:tp_subclasses"), "tp_subclasses", "PyObject *");
printSlot(f, getSlot(n, "feature:python:tp_weaklist"), "tp_weaklist", "PyObject *");
printSlot(f, getSlot(n, "feature:python:tp_del"), "tp_del", "destructor");
Printv(f, "#if PY_VERSION_HEX >= 0x02060000\n", NIL);
printSlot(f, getSlot(n, "feature:python:tp_version_tag"), "tp_version_tag", "int");
Printv(f, "#endif\n", NIL);
Printv(f, "#if PY_VERSION_HEX >= 0x03040000\n", NIL);
printSlot(f, getSlot(n, "feature:python:tp_finalize"), "tp_finalize", "destructor");
Printv(f, "#endif\n", NIL);
@ -4263,9 +4229,7 @@ public:
printSlot(f, getSlot(n, "feature:python:tp_allocs"), "tp_allocs", "Py_ssize_t");
printSlot(f, getSlot(n, "feature:python:tp_frees"), "tp_frees", "Py_ssize_t");
printSlot(f, getSlot(n, "feature:python:tp_maxalloc"), "tp_maxalloc", "Py_ssize_t");
Printv(f, "#if PY_VERSION_HEX >= 0x02050000\n", NIL);
printSlot(f, getSlot(n, "feature:python:tp_prev"), "tp_prev");
Printv(f, "#endif\n", NIL);
printSlot(f, getSlot(n, "feature:python:tp_next"), "tp_next");
Printv(f, "#endif\n", NIL);
Printf(f, " },\n");
@ -4331,9 +4295,7 @@ public:
printSlot(f, getSlot(n, "feature:python:nb_divide"), "nb_true_divide", "binaryfunc");
printSlot(f, getSlot(n, "feature:python:nb_inplace_floor_divide"), "nb_inplace_floor_divide", "binaryfunc");
printSlot(f, getSlot(n, "feature:python:nb_inplace_divide"), "nb_inplace_true_divide", "binaryfunc");
Printv(f, "#if PY_VERSION_HEX >= 0x02050000\n", NIL);
printSlot(f, getSlot(n, "feature:python:nb_index"), "nb_index", "unaryfunc");
Printv(f, "#endif\n", NIL);
Printv(f, "#if PY_VERSION_HEX >= 0x03050000\n", NIL);
printSlot(f, getSlot(n, "feature:python:nb_matrix_multiply"), "nb_matrix_multiply", "binaryfunc");
printSlot(f, getSlot(n, "feature:python:nb_inplace_matrix_multiply"), "nb_inplace_matrix_multiply", "binaryfunc");
@ -4377,10 +4339,8 @@ public:
printSlot(f, getSlot(n, "feature:python:bf_getsegcount"), "bf_getsegcount", "segcountproc");
printSlot(f, getSlot(n, "feature:python:bf_getcharbuffer"), "bf_getcharbuffer", "charbufferproc");
Printv(f, "#endif\n", NIL);
Printv(f, "#if PY_VERSION_HEX >= 0x02060000\n", NIL);
printSlot(f, getSlot(n, "feature:python:bf_getbuffer"), "bf_getbuffer", "getbufferproc");
printSlot(f, getSlot(n, "feature:python:bf_releasebuffer"), "bf_releasebuffer", "releasebufferproc");
Printv(f, "#endif\n", NIL);
Printf(f, " },\n");
// PyObject *ht_name, *ht_slots, *ht_qualname;
@ -4590,7 +4550,7 @@ public:
Printv(f_shadow, tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n", NIL);
} else {
Printv(f_shadow, tab4, "thisown = _swig_property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL);
Printv(f_shadow, tab4, "thisown = property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL);
/* Add static attribute */
if (GetFlag(n, "feature:python:nondynamic")) {
Printv(f_shadow_file,
@ -5182,7 +5142,7 @@ public:
if (!classic) {
if (!modern)
Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL);
Printv(f_shadow, tab4, symname, " = _swig_property(", module, ".", getname, NIL);
Printv(f_shadow, tab4, symname, " = property(", module, ".", getname, NIL);
if (assignable)
Printv(f_shadow, ", ", module, ".", setname, NIL);
Printv(f_shadow, ")\n", NIL);
@ -5256,7 +5216,7 @@ public:
if (!classic && !builtin) {
if (!modern)
Printv(f_shadow, tab4, "if _newclass:\n", tab4, NIL);
Printv(f_shadow, tab4, symname, " = _swig_property(", module, ".", getname, NIL);
Printv(f_shadow, tab4, symname, " = property(", module, ".", getname, NIL);
if (assignable)
Printv(f_shadow, ", ", module, ".", setname, NIL);
Printv(f_shadow, ")\n", NIL);