swig/Lib/python/builtin.swg
Stefan Zager 3a86f2068f Added support for multiple inheritance. Not as hard as I feared.
Apply operator features to both the operator name, and the renamed
"__*__" method.  That's the only way to hit all corners.

Added support for %pythonnondynamic.  I believe this implementation
is more correct than the existing implementation, but I'm still
waiting for an adjudication on the behavior of the python_nondynamic
test.

Current list of unsupported features that require minor tweaks
to the test suite:

- 'this' member variable is obsolete.

- No support for reversible operator overloads (e.g., __radd__).  You
can still support this:

a = MyString("foo")
b = "bar"
c = a + b

... but you can't do this:

a = "foo"
b = MyString("bar")
c = a + b

With the tweaks, the test suite now fails on python_nondynamic.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12353 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-12-20 23:35:18 +00:00

166 lines
4.8 KiB
Text

#define PYSWIG_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 PYSWIG_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 PYSWIG_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 PYSWIG_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 PYSWIG_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 PYSWIG_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 PYSWIG_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 PYSWIG_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; \
}
SWIGINTERN int
pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure)
{
if (!closure)
return -1;
PyObject *tuple = PyTuple_New(1);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, val);
Py_XINCREF(val);
PyObject *result = ((PyCFunction) closure)(obj, tuple);
Py_DECREF(tuple);
Py_XDECREF(result);
return result ? 0 : -1;
}
#ifdef __cplusplus
namespace {
template <typename _Tp> struct PySwigBuiltin : public SwigPyObject {
typedef PySwigBuiltin<_Tp> this_type;
typedef _Tp obj_type;
typedef obj_type* pointer;
typedef obj_type& reference;
static PyObject* richcompare (PyObject *self, PyObject *other, int op);
static PyMethodDef methods[];
static PyGetSetDef getset[];
static PyNumberMethods number_methods;
static PySequenceMethods sequence_methods;
static PyMappingMethods mapping_methods;
static PyTypeObject pytype;
static SwigPyClientData clientdata;
};
template <typename _Tp> void py_builtin_dealloc (PyObject *pyobj)
{
typedef PySwigBuiltin<_Tp> builtin_type;
builtin_type *obj = (builtin_type*) pyobj;
if (obj->own)
delete reinterpret_cast<_Tp*>(obj->ptr);
(*pyobj->ob_type->tp_free)(pyobj);
}
} // namespace {
#endif