Added support for operator overrides (PyNumberMethods) and

member variable access.

test suite now croaks on inplaceadd.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12345 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Stefan Zager 2010-12-14 00:08:45 +00:00
commit b1682d4d80
4 changed files with 1933 additions and 1755 deletions

View file

@ -1,3 +1,18 @@
extern 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 {
@ -10,6 +25,8 @@ template <typename _Tp> struct PySwigBuiltin : public SwigPyObject {
typedef obj_type& reference;
static PyMethodDef methods[];
static PyGetSetDef getset[];
static PyNumberMethods number_methods;
static PyTypeObject pytype;
static SwigPyClientData clientdata;
};
@ -23,6 +40,29 @@ template <typename _Tp> void py_builtin_dealloc (PyObject *pyobj)
(*pyobj->ob_type->tp_free)(pyobj);
}
template <PyCFunction func> PyObject*
pyswig_binaryfunc_closure (PyObject *a, PyObject *b)
{
PyObject *tuple = PyTuple_New(1);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, b);
PyObject *result = func(a, tuple);
Py_DECREF(tuple);
return result;
}
template <PyCFunction func> PyObject*
pyswig_ternaryfunc_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);
PyObject *result = func(a, tuple);
Py_DECREF(tuple);
return result;
}
} // namespace {
#endif