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
This commit is contained in:
parent
dd465f9588
commit
3a86f2068f
5 changed files with 182 additions and 55 deletions
|
|
@ -115,6 +115,21 @@ wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \
|
|||
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 {
|
||||
|
|
@ -146,21 +161,6 @@ template <typename _Tp> void py_builtin_dealloc (PyObject *pyobj)
|
|||
(*pyobj->ob_type->tp_free)(pyobj);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
} // namespace {
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
%init %{
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <vector>
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
|
@ -338,7 +340,11 @@ SWIG_init(void) {
|
|||
|
||||
#if defined(SWIGPYTHON_BUILTIN)
|
||||
PyTypeObject *builtin_pytype = 0;
|
||||
PyObject *propargs = NULL, *propget = NULL, *propset = NULL, *propobj = NULL;
|
||||
std::vector<PyTypeObject*> builtin_bases;
|
||||
swig_type_info *builtin_basetype = 0;
|
||||
PyObject *base_tuple = NULL;
|
||||
int i;
|
||||
|
||||
SWIG_Python_builtin_imports();
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
#ifdef __cplusplus
|
||||
|
||||
#if defined(SWIGPYTHON_BUILTIN)
|
||||
#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper; %feature("pyslot", #slot, functype=#functp) oper;
|
||||
#define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("pycompare", #comptype) oper;
|
||||
#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper; %feature("pyslot", #slot, functype=#functp) oper; %feature("pyslot", #slot, functype=#functp) pyname;
|
||||
#define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("pycompare", #comptype) oper; %feature("pycompare", #comptype) pyname;
|
||||
#else
|
||||
#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper
|
||||
#define %pycompare(pyname,oper,comptype) %pybinoperator(pyname,oper,,comptype)
|
||||
|
|
|
|||
|
|
@ -1628,6 +1628,55 @@ SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Cribbed from Objects/object.c in the python source code and modified
|
||||
SWIGRUNTIME int
|
||||
SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value)
|
||||
{
|
||||
PyTypeObject *tp = obj->ob_type;
|
||||
PyObject *descr;
|
||||
descrsetfunc f;
|
||||
int res = -1;
|
||||
|
||||
if (!PyString_Check(name)) {
|
||||
#ifdef Py_USING_UNICODE
|
||||
if (PyUnicode_Check(name)) {
|
||||
name = PyUnicode_AsEncodedString(name, NULL, NULL);
|
||||
if (name == NULL)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
#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 == NULL) {
|
||||
if (PyType_Ready(tp) < 0)
|
||||
goto done;
|
||||
}
|
||||
|
||||
descr = _PyType_Lookup(tp, name);
|
||||
f = NULL;
|
||||
if (descr != NULL && PyType_HasFeature(descr->ob_type, Py_TPFLAGS_HAVE_CLASS))
|
||||
f = descr->ob_type->tp_descr_set;
|
||||
if (f == NULL)
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"'%.100s' object has no attribute '%.200s'",
|
||||
tp->tp_name, PyString_AS_STRING(name));
|
||||
else
|
||||
res = f(descr, obj, value);
|
||||
|
||||
done:
|
||||
Py_DECREF(name);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue