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 #ifdef __cplusplus
namespace { namespace {
@ -10,6 +25,8 @@ template <typename _Tp> struct PySwigBuiltin : public SwigPyObject {
typedef obj_type& reference; typedef obj_type& reference;
static PyMethodDef methods[]; static PyMethodDef methods[];
static PyGetSetDef getset[];
static PyNumberMethods number_methods;
static PyTypeObject pytype; static PyTypeObject pytype;
static SwigPyClientData clientdata; static SwigPyClientData clientdata;
}; };
@ -23,6 +40,29 @@ template <typename _Tp> void py_builtin_dealloc (PyObject *pyobj)
(*pyobj->ob_type->tp_free)(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 { } // namespace {
#endif #endif

View file

@ -5,41 +5,53 @@
#ifdef __cplusplus #ifdef __cplusplus
#define %pybinoperator(pyname,oper) %rename(pyname) oper; %pythonmaybecall oper #if defined(SWIGPYTHON_BUILTIN)
#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper; %feature("pyslot", #slot, functype=#functp) oper;
%pybinoperator(__add__, *::operator+); #define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("pycompare", #comptype) oper;
%pybinoperator(__pos__, *::operator+()); #else
%pybinoperator(__pos__, *::operator+() const); #define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper
%pybinoperator(__sub__, *::operator-); #define %pycompare(pyname,oper,comptype) %pybinoperator(pyname,oper,,comptype)
%pybinoperator(__neg__, *::operator-()); #endif
%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!=);
%pybinoperator(__add__, *::operator+, binary_func, nb_add);
%pybinoperator(__pos__, *::operator+(), unary_func, nb_positive);
%pybinoperator(__pos__, *::operator+() const, unary_func, nb_positive);
%pybinoperator(__sub__, *::operator-, binary_func, nb_subtract);
%pybinoperator(__neg__, *::operator-(), unary_func, nb_negative);
%pybinoperator(__neg__, *::operator-() const, unary_func, nb_negative);
%pybinoperator(__mul__, *::operator*, binary_func, nb_multiply);
%pybinoperator(__div__, *::operator/, binary_func, nb_div);
%pybinoperator(__mod__, *::operator%, binary_func, nb_remainder);
%pybinoperator(__lshift__, *::operator<<, binary_func, nb_lshift);
%pybinoperator(__rshift__, *::operator>>, binary_func, nb_rshift);
%pybinoperator(__and__, *::operator&, binary_func, nb_and);
%pybinoperator(__or__, *::operator|, binary_func, nb_or);
%pybinoperator(__xor__, *::operator^, binary_func, 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("pyslot", "nb_truediv", functype="binary_func") *::operator/;
/* Special cases */ /* Special cases */
%rename(__invert__) *::operator~; %rename(__invert__) *::operator~;
%feature("pyslot", "nb_invert", functype="unary_func") *::operator~;
%rename(__call__) *::operator(); %rename(__call__) *::operator();
%feature("pyslot", "tp_call", functype="ternary_func") *::operator();
#if defined(SWIGPYTHON_BUILTIN)
%pybinoperator(__nonzero__, *::operator bool, unary_func, nb_nonzero);
#else
%feature("shadow") *::operator bool %{ %feature("shadow") *::operator bool %{
def __nonzero__(self): def __nonzero__(self):
return $action(self) return $action(self)
__bool__ = __nonzero__ __bool__ = __nonzero__
%}; %};
%rename(__nonzero__) *::operator bool; %rename(__nonzero__) *::operator bool;
#endif
/* Ignored operators */ /* Ignored operators */
%ignoreoperator(LNOT) operator!; %ignoreoperator(LNOT) operator!;
@ -90,18 +102,22 @@ __bool__ = __nonzero__
*/ */
#define %pyinplaceoper(SwigPyOper, Oper) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper #if defined(SWIGPYTHON_BUILTIN)
#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %rename(SwigPyOper) Oper; %feature("pyslot", #slot, functype=#functp) Oper;
#else
#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper
#endif
%pyinplaceoper(__iadd__ , *::operator +=); %pyinplaceoper(__iadd__ , *::operator +=, binary_func, nb_inplace_add);
%pyinplaceoper(__isub__ , *::operator -=); %pyinplaceoper(__isub__ , *::operator -=, binary_func, nb_inplace_subtract);
%pyinplaceoper(__imul__ , *::operator *=); %pyinplaceoper(__imul__ , *::operator *=, binary_func, nb_inplace_multiply);
%pyinplaceoper(__idiv__ , *::operator /=); %pyinplaceoper(__idiv__ , *::operator /=, binary_func, nb_inplace_divide);
%pyinplaceoper(__imod__ , *::operator %=); %pyinplaceoper(__imod__ , *::operator %=, binary_func, nb_inplace_remainder);
%pyinplaceoper(__iand__ , *::operator &=); %pyinplaceoper(__iand__ , *::operator &=, binary_func, nb_inplace_and);
%pyinplaceoper(__ior__ , *::operator |=); %pyinplaceoper(__ior__ , *::operator |=, binary_func, nb_inplace_or);
%pyinplaceoper(__ixor__ , *::operator ^=); %pyinplaceoper(__ixor__ , *::operator ^=, binary_func, nb_inplace_xor);
%pyinplaceoper(__ilshift__, *::operator <<=); %pyinplaceoper(__ilshift__, *::operator <<=, binary_func, nb_inplace_lshift);
%pyinplaceoper(__irshift__, *::operator >>=); %pyinplaceoper(__irshift__, *::operator >>=, binary_func, nb_inplace_rshift);
/* Finally, in python we need to mark the binary operations to fail as /* Finally, in python we need to mark the binary operations to fail as

View file

@ -1076,8 +1076,13 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
PyTypeObject *obj_tp; PyTypeObject *obj_tp;
for (obj_tp = obj->ob_type; obj_tp; obj_tp = obj_tp->tp_base) { for (obj_tp = obj->ob_type; obj_tp; obj_tp = obj_tp->tp_base) {
if (obj_tp == target_tp) { if (obj_tp == target_tp) {
SwigPyObject *sobj = (SwigPyObject*) obj;
if (own)
*own = *own | sobj->own;
if (flags & SWIG_POINTER_DISOWN)
sobj->own = 0;
if (ptr) if (ptr)
*ptr = ((SwigPyObject*) obj)->ptr; *ptr = sobj->ptr;
return SWIG_OK; return SWIG_OK;
} }
} }

View file

@ -1,3 +1,4 @@
/* mode: c++; c-basic-offset: 2 */
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3 * This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional * (or any later version) of the GNU General Public License. Some additional
@ -46,7 +47,7 @@ static String *f_shadow = 0;
static String *f_shadow_imports = 0; static String *f_shadow_imports = 0;
static String *f_shadow_import_stmts = 0; static String *f_shadow_import_stmts = 0;
static String *f_shadow_stubs = 0; static String *f_shadow_stubs = 0;
static Hash *builtin_getset = 0;
static String *methods; static String *methods;
static String *class_name; static String *class_name;
@ -553,6 +554,7 @@ public:
f_wrappers = NewString(""); f_wrappers = NewString("");
f_directors_h = NewString(""); f_directors_h = NewString("");
f_directors = NewString(""); f_directors = NewString("");
builtin_getset = NewHash();
if (builtin) { if (builtin) {
f_builtins = NewString(""); f_builtins = NewString("");
@ -1792,7 +1794,7 @@ public:
/* ------------------------------------------------------------ /* ------------------------------------------------------------
* dispatchFunction() * dispatchFunction()
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
void dispatchFunction(Node *n, int funpack = 0, bool builtin_self = false, bool constructor = false) { void dispatchFunction(Node *n, String *linkage, int funpack = 0, bool builtin_self = false, bool constructor = false) {
/* Last node in overloaded chain */ /* Last node in overloaded chain */
int maxargs; int maxargs;
@ -1814,7 +1816,7 @@ public:
String *symname = Getattr(n, "sym:name"); String *symname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(symname); String *wname = Swig_name_wrapper(symname);
Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL); Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL);
Wrapper_add_local(f, "argc", "int argc"); Wrapper_add_local(f, "argc", "int argc");
Printf(tmp, "PyObject *argv[%d]", maxargs + 1); Printf(tmp, "PyObject *argv[%d]", maxargs + 1);
@ -1940,8 +1942,23 @@ public:
bool builtin_self = builtin && in_class && (constructor || (l && Getattr(l, "self"))); bool builtin_self = builtin && in_class && (constructor || (l && Getattr(l, "self")));
bool builtin_ctor = builtin_self && constructor; bool builtin_ctor = builtin_self && constructor;
bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass())); bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass()));
bool builtin_getter = (builtin && GetFlag(n, "memberget"));
bool builtin_setter = (builtin && GetFlag(n, "memberset") && !builtin_getter);
char const *self_param = builtin_self ? "self" : "SWIGUNUSEDPARM(self)"; char const *self_param = builtin_self ? "self" : "SWIGUNUSEDPARM(self)";
char const *wrap_return = builtin_ctor ? "int " : "PyObject *"; char const *wrap_return = builtin_ctor ? "int " : "PyObject *";
String *linkage = NewString("SWIGINTERN ");
String *slot = Getattr(n, "feature:pyslot");
if (builtin_setter || builtin_getter) {
Clear(linkage);
Printv(linkage, "extern ", NIL);
}
if (slot) {
String *functype = Getattr(n, "feature:pyslot:functype");
if (!strcmp(Char(functype), "binary_func") || !strcmp(Char(functype), "ternary_func")) {
Clear(linkage);
Printv(linkage, "extern ", NIL);
}
}
if (Getattr(n, "sym:overloaded")) { if (Getattr(n, "sym:overloaded")) {
overname = Getattr(n, "sym:overname"); overname = Getattr(n, "sym:overname");
@ -1990,9 +2007,9 @@ public:
if (!allow_kwargs || Getattr(n, "sym:overloaded")) { if (!allow_kwargs || Getattr(n, "sym:overloaded")) {
if (!varargs) { if (!varargs) {
Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
} else { } else {
Printv(f->def, "SWIGINTERN ", wrap_return, wname, "__varargs__", "(PyObject *", self_param, ", PyObject *args, PyObject *varargs) {", NIL); Printv(f->def, linkage, wrap_return, wname, "__varargs__", "(PyObject *", self_param, ", PyObject *args, PyObject *varargs) {", NIL);
} }
if (allow_kwargs) { if (allow_kwargs) {
Swig_warning(WARN_LANG_OVERLOAD_KEYWORD, input_file, line_number, "Can't use keyword arguments with overloaded functions (%s).\n", Swig_name_decl(n)); Swig_warning(WARN_LANG_OVERLOAD_KEYWORD, input_file, line_number, "Can't use keyword arguments with overloaded functions (%s).\n", Swig_name_decl(n));
@ -2003,7 +2020,7 @@ public:
Swig_warning(WARN_LANG_VARARGS_KEYWORD, input_file, line_number, "Can't wrap varargs with keyword arguments enabled\n"); Swig_warning(WARN_LANG_VARARGS_KEYWORD, input_file, line_number, "Can't wrap varargs with keyword arguments enabled\n");
varargs = 0; varargs = 0;
} }
Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args, PyObject *kwargs) {", NIL); Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args, PyObject *kwargs) {", NIL);
} }
if (!builtin || !in_class || tuple_arguments > 0) { if (!builtin || !in_class || tuple_arguments > 0) {
if (!allow_kwargs) { if (!allow_kwargs) {
@ -2048,7 +2065,7 @@ public:
if (builtin_self && !builtin_ctor) if (builtin_self && !builtin_ctor)
Printf(self_parse, "%s = self;\n", funpack ? "swig_obj[0]" : "obj0"); Printf(self_parse, "%s = self;\n", funpack ? "swig_obj[0]" : "obj0");
if (constructor && director_class) if (builtin_ctor && director_class)
Printv(self_parse, funpack ? "swig_obj[1]" : "obj1", " = self;\n", NIL); Printv(self_parse, funpack ? "swig_obj[1]" : "obj1", " = self;\n", NIL);
int use_parse = 0; int use_parse = 0;
@ -2164,16 +2181,16 @@ public:
Clear(f->def); Clear(f->def);
if (overname) { if (overname) {
if (noargs) { if (noargs) {
Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL); Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
} else { } else {
Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **swig_obj) {", NIL); Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **swig_obj) {", NIL);
} }
Printf(parse_args, "if ((nobjs < %d) || (nobjs > %d)) SWIG_fail;\n", num_required, num_arguments); Printf(parse_args, "if ((nobjs < %d) || (nobjs > %d)) SWIG_fail;\n", num_required, num_arguments);
} else { } else {
if (noargs) { if (noargs) {
Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
} else { } else {
Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL); Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
} }
if (onearg) { if (onearg) {
Printf(parse_args, "if (!args) SWIG_fail;\n"); Printf(parse_args, "if (!args) SWIG_fail;\n");
@ -2426,7 +2443,7 @@ public:
if (need_cleanup) { if (need_cleanup) {
Printv(f->code, cleanup, NIL); Printv(f->code, cleanup, NIL);
} }
if (builtin_self && constructor) if (builtin_ctor)
Printv(f->code, " return 0;\n", NIL); Printv(f->code, " return 0;\n", NIL);
else else
Printv(f->code, " return NULL;\n", NIL); Printv(f->code, " return NULL;\n", NIL);
@ -2463,7 +2480,7 @@ public:
if (varargs) { if (varargs) {
DelWrapper(f); DelWrapper(f);
f = NewWrapper(); f = NewWrapper();
Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL); Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL);
Wrapper_add_local(f, "resultobj", constructor && builtin_self ? "int resultobj" : "PyObject *resultobj"); Wrapper_add_local(f, "resultobj", constructor && builtin_self ? "int resultobj" : "PyObject *resultobj");
Wrapper_add_local(f, "varargs", "PyObject *varargs"); Wrapper_add_local(f, "varargs", "PyObject *varargs");
Wrapper_add_local(f, "newargs", "PyObject *newargs"); Wrapper_add_local(f, "newargs", "PyObject *newargs");
@ -2489,11 +2506,53 @@ public:
} }
} else { } else {
if (!Getattr(n, "sym:nextSibling")) { if (!Getattr(n, "sym:nextSibling")) {
dispatchFunction(n, funpack, builtin_self, constructor); dispatchFunction(n, linkage, funpack, builtin_self, constructor);
} }
} }
String *wrapper_name = Swig_name_wrapper(iname);
/* If this is a builtin type, create a PyGetSetDef entry for this member variable. */
if (builtin_getter) {
Hash *h = Getattr(builtin_getset, name);
if (!h) {
h = NewHash();
Setattr(builtin_getset, name, h);
Delete(h);
}
Setattr(h, "getter", wrapper_name);
}
if (builtin_setter) {
Hash *h = Getattr(builtin_getset, name);
if (!h) {
h = NewHash();
Setattr(builtin_getset, name, h);
Delete(h);
}
Setattr(h, "setter", wrapper_name);
}
/* Handle builtin operator overloads */
if (slot) {
String *functype = Getattr(n, "feature:pyslot:functype");
String *feature_name = NewStringf("feature:%s", slot);
String *closure_name = NewString("");
if (!strcmp(Char(functype), "binary_func")) {
Printf(closure_name, "pyswig_binaryfunc_closure< %s >", wrapper_name);
} else if (!strcmp(Char(functype), "ternary_func")) {
Printf(closure_name, "pyswig_ternaryfunc_closure< %s >", wrapper_name);
} else {
Append(closure_name, wrapper_name);
}
Node *parent = Swig_methodclass(n);
Setattr(parent, feature_name, closure_name);
Delete(feature_name);
Delete(closure_name);
}
Delete(self_parse); Delete(self_parse);
Delete(parse_args); Delete(parse_args);
Delete(linkage);
Delete(arglist); Delete(arglist);
Delete(get_pointers); Delete(get_pointers);
Delete(cleanup); Delete(cleanup);
@ -2501,6 +2560,7 @@ public:
Delete(kwargs); Delete(kwargs);
Delete(wname); Delete(wname);
DelWrapper(f); DelWrapper(f);
Delete(wrapper_name);
return SWIG_OK; return SWIG_OK;
} }
@ -3008,6 +3068,63 @@ public:
Printv(tp_dealloc, "0", NIL); Printv(tp_dealloc, "0", NIL);
Delete(dtor_name); Delete(dtor_name);
Printf(f, "template <> PyGetSetDef PySwigBuiltin< %s >::getset[] = {\n", rname);
for (DohIterator member_iter = First(builtin_getset); member_iter.item; member_iter = Next(member_iter)) {
String *mname = member_iter.key;
Hash *mgetset = member_iter.item;
String *getter = Getattr(mgetset, "getter");
String *setter = Getattr(mgetset, "setter");
Printf(f, tab4 "{ const_cast<char*>(\"%s\"), (getter) %s, (setter) pyswig_setter_closure, const_cast<char*>(\"%s.%s\"), (void*) &%s },\n",
mname, getter ? getter : "0", name, mname, setter ? setter : "0");
}
Printv(f, " {NULL} // Sentinel\n", NIL);
Printv(f, "};\n\n", NIL);
Clear(builtin_getset);
Printf(f, "template <> PyNumberMethods PySwigBuiltin< %s >::number_methods = {\n", rname);
Printf(f, " (binaryfunc) %s, // nb_add;\n", getSlot(n, "feature:nb_add"));
Printf(f, " (binaryfunc) %s, // nb_subtract;\n", getSlot(n, "feature:nb_subtract"));
Printf(f, " (binaryfunc) %s, // nb_multiply;\n", getSlot(n, "feature:nb_multiply"));
Printf(f, " (binaryfunc) %s, // nb_divide;\n", getSlot(n, "feature:nb_divide"));
Printf(f, " (binaryfunc) %s, // nb_remainder;\n", getSlot(n, "feature:nb_remainder"));
Printf(f, " (binaryfunc) %s, // nb_divmod;\n", getSlot(n, "feature:nb_divmod"));
Printf(f, " (ternaryfunc) %s, // nb_power;\n", getSlot(n, "feature:nb_power"));
Printf(f, " (unaryfunc) %s, // nb_negative;\n", getSlot(n, "feature:nb_negative"));
Printf(f, " (unaryfunc) %s, // nb_positive;\n", getSlot(n, "feature:nb_positive"));
Printf(f, " (unaryfunc) %s, // nb_absolute;\n", getSlot(n, "feature:nb_absolute"));
Printf(f, " (inquiry) %s, // nb_nonzero;\n", getSlot(n, "feature:nb_nonzero"));
Printf(f, " (unaryfunc) %s, // nb_invert;\n", getSlot(n, "feature:nb_invert"));
Printf(f, " (binaryfunc) %s, // nb_lshift;\n", getSlot(n, "feature:nb_lshift"));
Printf(f, " (binaryfunc) %s, // nb_rshift;\n", getSlot(n, "feature:nb_rshift"));
Printf(f, " (binaryfunc) %s, // nb_and;\n", getSlot(n, "feature:nb_and"));
Printf(f, " (binaryfunc) %s, // nb_xor;\n", getSlot(n, "feature:nb_xor"));
Printf(f, " (binaryfunc) %s, // nb_or;\n", getSlot(n, "feature:nb_or"));
Printf(f, " (coercion) %s, // nb_coerce;\n", getSlot(n, "feature:nb_coerce"));
Printf(f, " (unaryfunc) %s, // nb_int;\n", getSlot(n, "feature:nb_int"));
Printf(f, " (unaryfunc) %s, // nb_long;\n", getSlot(n, "feature:nb_long"));
Printf(f, " (unaryfunc) %s, // nb_float;\n", getSlot(n, "feature:nb_float"));
Printf(f, " (unaryfunc) %s, // nb_oct;\n", getSlot(n, "feature:nb_oct"));
Printf(f, " (unaryfunc) %s, // nb_hex;\n", getSlot(n, "feature:nb_hex"));
Printf(f, " (binaryfunc) %s, // nb_inplace_add;\n", getSlot(n, "feature:nb_inplace_add"));
Printf(f, " (binaryfunc) %s, // nb_inplace_subtract;\n", getSlot(n, "feature:nb_inplace_subtract"));
Printf(f, " (binaryfunc) %s, // nb_inplace_multiply;\n", getSlot(n, "feature:nb_inplace_multiply"));
Printf(f, " (binaryfunc) %s, // nb_inplace_divide;\n", getSlot(n, "feature:nb_inplace_divide"));
Printf(f, " (binaryfunc) %s, // nb_inplace_remainder;\n", getSlot(n, "feature:nb_inplace_remainder"));
Printf(f, " (ternaryfunc) %s, // nb_inplace_power;\n", getSlot(n, "feature:nb_inplace_power"));
Printf(f, " (binaryfunc) %s, // nb_inplace_lshift;\n", getSlot(n, "feature:nb_inplace_lshift"));
Printf(f, " (binaryfunc) %s, // nb_inplace_rshift;\n", getSlot(n, "feature:nb_inplace_rshift"));
Printf(f, " (binaryfunc) %s, // nb_inplace_and;\n", getSlot(n, "feature:nb_inplace_and"));
Printf(f, " (binaryfunc) %s, // nb_inplace_xor;\n", getSlot(n, "feature:nb_inplace_xor"));
Printf(f, " (binaryfunc) %s, // nb_inplace_or;\n", getSlot(n, "feature:nb_inplace_or"));
Printf(f, " (binaryfunc) %s, // nb_floor_divide;\n", getSlot(n, "feature:nb_floor_divide"));
Printf(f, " (binaryfunc) %s, // nb_true_divide;\n", getSlot(n, "feature:nb_true_divide"));
Printf(f, " (binaryfunc) %s, // nb_inplace_floor_divide;\n", getSlot(n, "feature:nb_inplace_floor_divide"));
Printf(f, " (binaryfunc) %s, // nb_inplace_true_divide;\n", getSlot(n, "feature:nb_inplace_true_divide"));
Printf(f, " (unaryfunc) %s, // nb_index;\n", getSlot(n, "feature:nb_index"));
Printf(f, "};\n\n");
String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES");
// TODO: Add more flags based on slots
Printf(f, "template <> PyTypeObject PySwigBuiltin< %s >::pytype = {\n", rname); Printf(f, "template <> PyTypeObject PySwigBuiltin< %s >::pytype = {\n", rname);
Printf(f, " PyObject_HEAD_INIT(NULL)\n"); Printf(f, " PyObject_HEAD_INIT(NULL)\n");
Printf(f, " 0, /*ob_size*/\n"); Printf(f, " 0, /*ob_size*/\n");
@ -3020,7 +3137,7 @@ public:
Printf(f, " %s, /*tp_setattr*/\n", getSlot(n, "feature:tp_setattr")); Printf(f, " %s, /*tp_setattr*/\n", getSlot(n, "feature:tp_setattr"));
Printf(f, " %s, /*tp_compare*/\n", getSlot(n, "feature:tp_compare")); Printf(f, " %s, /*tp_compare*/\n", getSlot(n, "feature:tp_compare"));
Printf(f, " %s, /*tp_repr*/\n", getSlot(n, "feature:tp_repr")); Printf(f, " %s, /*tp_repr*/\n", getSlot(n, "feature:tp_repr"));
Printf(f, " %s, /*tp_as_number*/\n", getSlot(n, "feature:tp_as_number")); Printf(f, " &%s::number_methods, /*tp_as_number*/\n", templ);
Printf(f, " %s, /*tp_as_sequence*/\n", getSlot(n, "feature:tp_as_sequence")); Printf(f, " %s, /*tp_as_sequence*/\n", getSlot(n, "feature:tp_as_sequence"));
Printf(f, " %s, /*tp_as_mapping*/\n", getSlot(n, "feature:tp_as_mapping")); Printf(f, " %s, /*tp_as_mapping*/\n", getSlot(n, "feature:tp_as_mapping"));
Printf(f, " %s, /*tp_hash */\n", getSlot(n, "feature:tp_hash")); Printf(f, " %s, /*tp_hash */\n", getSlot(n, "feature:tp_hash"));
@ -3029,7 +3146,7 @@ public:
Printf(f, " %s, /*tp_getattro*/\n", getSlot(n, "feature:tp_getattro")); Printf(f, " %s, /*tp_getattro*/\n", getSlot(n, "feature:tp_getattro"));
Printf(f, " %s, /*tp_setattro*/\n", getSlot(n, "feature:tp_setattro")); Printf(f, " %s, /*tp_setattro*/\n", getSlot(n, "feature:tp_setattro"));
Printf(f, " %s, /*tp_as_buffer*/\n", getSlot(n, "feature:tp_as_buffer")); Printf(f, " %s, /*tp_as_buffer*/\n", getSlot(n, "feature:tp_as_buffer"));
Printf(f, " Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_RICHCOMPARE, /*tp_flags*/\n"); Printf(f, " %s, /*tp_flags*/\n", tp_flags);
Printf(f, " \"%s\", /* tp_doc */\n", rname); Printf(f, " \"%s\", /* tp_doc */\n", rname);
Printf(f, " %s, /* tp_traverse */\n", getSlot(n, "feature:tp_traverse")); Printf(f, " %s, /* tp_traverse */\n", getSlot(n, "feature:tp_traverse"));
Printf(f, " %s, /* tp_clear */\n", getSlot(n, "feature:tp_clear")); Printf(f, " %s, /* tp_clear */\n", getSlot(n, "feature:tp_clear"));
@ -3039,7 +3156,7 @@ public:
Printf(f, " %s, /* tp_iternext */\n", getSlot(n, "feature:tp_iternext")); Printf(f, " %s, /* tp_iternext */\n", getSlot(n, "feature:tp_iternext"));
Printf(f, " %s::methods, /* tp_methods */\n", templ); Printf(f, " %s::methods, /* tp_methods */\n", templ);
Printf(f, " %s, /* tp_members */\n", getSlot(n, "feature:tp_members")); Printf(f, " %s, /* tp_members */\n", getSlot(n, "feature:tp_members"));
Printf(f, " %s, /* tp_getset */\n", getSlot(n, "feature:tp_getset")); Printf(f, " %s::getset, /* tp_getset */\n", templ);
Printf(f, " %s, /* tp_base */\n", getSlot(n, "feature:tp_base")); Printf(f, " %s, /* tp_base */\n", getSlot(n, "feature:tp_base"));
Printf(f, " %s, /* tp_dict */\n", getSlot(n, "feature:tp_dict")); Printf(f, " %s, /* tp_dict */\n", getSlot(n, "feature:tp_dict"));
Printf(f, " %s, /* tp_descr_get */\n", getSlot(n, "feature:tp_descr_get")); Printf(f, " %s, /* tp_descr_get */\n", getSlot(n, "feature:tp_descr_get"));
@ -3071,6 +3188,7 @@ public:
Delete(rname); Delete(rname);
Delete(pname); Delete(pname);
Delete(tp_dealloc); Delete(tp_dealloc);
Delete(tp_flags);
} }
virtual int classHandler(Node *n) { virtual int classHandler(Node *n) {
@ -3403,7 +3521,7 @@ public:
Setattr(class_members, name, name); Setattr(class_members, name, name);
ParmList *parms = Getattr(n, "parms"); ParmList *parms = Getattr(n, "parms");
bool noArgs = !parms || Len(parms) == 0; bool noArgs = !parms || Len(parms) == 0;
String *pyflags = NewString(noArgs ? "METH_NOARGS" : "METH_VARARGS"); String *pyflags = NewString("METH_VARARGS");
Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags)); Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags));
Delete(name); Delete(name);
Delete(fullname); Delete(fullname);
@ -3761,8 +3879,7 @@ public:
Language::membervariableHandler(n); Language::membervariableHandler(n);
shadow = oldshadow; shadow = oldshadow;
if (builtin && in_class) { if (shadow && !builtin) {
} else if (shadow) {
String *mname = Swig_name_member(NSPACE_TODO, class_name, symname); String *mname = Swig_name_member(NSPACE_TODO, class_name, symname);
String *setname = Swig_name_set(NSPACE_TODO, mname); String *setname = Swig_name_set(NSPACE_TODO, mname);
String *getname = Swig_name_get(NSPACE_TODO, mname); String *getname = Swig_name_get(NSPACE_TODO, mname);