Finished std::pair and std::map support.

li_std_pair_extra test fails, because the _runme.py uses the
secret 'this' member variable, which doesn't exist when the
-builtin option is used.  Seems like a flaw in the test.

Test suite now fails on li_std_string_extra, because static
member variables are not fully implemented.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12351 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Stefan Zager 2010-12-15 23:04:20 +00:00
commit dd465f9588
7 changed files with 827 additions and 690 deletions

View file

@ -31,7 +31,7 @@ SWIGINTERN Py_ssize_t \
wrapper##_closure (PyObject *a) \ wrapper##_closure (PyObject *a) \
{ \ { \
PyObject *resultobj = wrapper(a, NULL); \ PyObject *resultobj = wrapper(a, NULL); \
Py_ssize_t result = _PyLong_AsSsize_t(resultobj); \ Py_ssize_t result = PyNumber_AsSsize_t(resultobj, NULL); \
Py_DECREF(resultobj); \ Py_DECREF(resultobj); \
return result; \ return result; \
} }
@ -53,12 +53,14 @@ wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c) \
SWIGINTERN int \ SWIGINTERN int \
wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) \ wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) \
{ \ { \
PyObject *tuple = PyTuple_New(3); \ PyObject *tuple = PyTuple_New(d ? 3 : 2); \
assert(tuple); \ assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \ PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \ PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \
if (d) { \
PyTuple_SET_ITEM(tuple, 2, d); \ PyTuple_SET_ITEM(tuple, 2, d); \
Py_XINCREF(d); \ Py_INCREF(d); \
} \
PyObject *resultobj = wrapper(a, tuple); \ PyObject *resultobj = wrapper(a, tuple); \
int result = resultobj ? 0 : -1; \ int result = resultobj ? 0 : -1; \
Py_DECREF(tuple); \ Py_DECREF(tuple); \
@ -94,6 +96,25 @@ wrapper##_closure (PyObject *a, Py_ssize_t b, PyObject *c) \
return result; \ 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; \
}
#ifdef __cplusplus #ifdef __cplusplus
namespace { namespace {
@ -105,6 +126,8 @@ template <typename _Tp> struct PySwigBuiltin : public SwigPyObject {
typedef obj_type* pointer; typedef obj_type* pointer;
typedef obj_type& reference; typedef obj_type& reference;
static PyObject* richcompare (PyObject *self, PyObject *other, int op);
static PyMethodDef methods[]; static PyMethodDef methods[];
static PyGetSetDef getset[]; static PyGetSetDef getset[];
static PyNumberMethods number_methods; static PyNumberMethods number_methods;

View file

@ -245,7 +245,7 @@ namespace swig {
template <class Sequence, class Difference, class InputSeq> template <class Sequence, class Difference, class InputSeq>
inline void inline void
setslice(Sequence* self, Difference i, Difference j, const InputSeq& v) { setslice(Sequence* self, Difference i, Difference j, const InputSeq& v = InputSeq()) {
typename Sequence::size_type size = self->size(); typename Sequence::size_type size = self->size();
typename Sequence::size_type ii = swig::check_index(i, size, true); typename Sequence::size_type ii = swig::check_index(i, size, true);
typename Sequence::size_type jj = swig::slice_index(j, size); typename Sequence::size_type jj = swig::slice_index(j, size);
@ -580,18 +580,18 @@ namespace swig
%fragment("SwigPySequence_Cont"); %fragment("SwigPySequence_Cont");
# if defined(SWIGPYTHON_BUILTIN)
%feature("tp_iter") Sequence "&swig::make_output_iterator_builtin< Sequence >";
# else
%newobject iterator(PyObject **PYTHON_SELF); %newobject iterator(PyObject **PYTHON_SELF);
%extend { %extend {
swig::SwigPyIterator* iterator(PyObject **PYTHON_SELF) { swig::SwigPyIterator* iterator(PyObject **PYTHON_SELF) {
return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
} }
#if defined(SWIGPYTHON_BUILTIN)
%feature("pyslot", "tp_iter", functype="getiterfunc") iterator;
#else
%pythoncode {def __iter__(self): return self.iterator()} %pythoncode {def __iter__(self): return self.iterator()}
#endif
} }
# endif // SWIGPYTHON_BUILTIN
#endif //SWIG_EXPORT_ITERATOR_METHODS #endif //SWIG_EXPORT_ITERATOR_METHODS
%enddef %enddef
@ -603,6 +603,11 @@ namespace swig
%newobject __getslice__; %newobject __getslice__;
#if defined(SWIGPYTHON_BUILTIN)
%feature("pyslot", "nb_nonzero", functype="unaryfunc") __nonzero__;
%feature("pyslot", "sq_length", functype="lenfunc") __len__;
#endif // SWIGPYTHON_BUILTIN
%extend { %extend {
bool __nonzero__() const { bool __nonzero__() const {
return !(self->empty()); return !(self->empty());
@ -618,11 +623,6 @@ namespace swig
} }
} }
#if defined(SWIGPYTHON_BUILTIN)
%pybinoperator(__nonzero__, __nonzero__, unaryfunc, nb_nonzero);
%pybinoperator(__len__, __len__, lenfunc, sq_length);
#endif // SWIGPYTHON_BUILTIN
%enddef %enddef
@ -633,6 +633,13 @@ namespace swig
%fragment("SwigPySequence_Base"); %fragment("SwigPySequence_Base");
#if defined(SWIGPYTHON_BUILTIN)
%feature("pyslot", "sq_item", functype="ssizeargfunc") __getitem__;
%feature("pyslot", "sq_slice", functype="ssizessizeargfunc") __getslice__;
%feature("pyslot", "sq_ass_item", functype="ssizeobjargproc") __setitem__;
%feature("pyslot", "sq_ass_slice", functype="ssizessizeobjargproc") __setslice__;
#endif // SWIGPYTHON_BUILTIN
%extend { %extend {
value_type pop() throw (std::out_of_range) { value_type pop() throw (std::out_of_range) {
if (self->size() == 0) if (self->size() == 0)
@ -654,7 +661,7 @@ namespace swig
return swig::getslice(self, i, j); return swig::getslice(self, i, j);
} }
void __setslice__(difference_type i, difference_type j, const Sequence& v) void __setslice__(difference_type i, difference_type j, const Sequence& v = Sequence())
throw (std::out_of_range, std::invalid_argument) { throw (std::out_of_range, std::invalid_argument) {
swig::setslice(self, i, j, v); swig::setslice(self, i, j, v);
} }
@ -705,13 +712,6 @@ namespace swig
} }
#if defined(SWIGPYTHON_BUILTIN)
%pybinoperator(__getitem__, __getitem__, ssizeargfunc, sq_item);
%pybinoperator(__getslice__, __getslice__, ssizessizeargfunc, sq_slice);
%pybinoperator(__setitem__, __setitem__, ssizeobjargproc, sq_ass_item);
%pybinoperator(__setslice__, __setslice__, ssizessizeobjargproc, sq_ass_slice);
#endif // SWIGPYTHON_BUILTIN
%enddef %enddef
%define %swig_sequence_methods(Sequence...) %define %swig_sequence_methods(Sequence...)

View file

@ -350,6 +350,7 @@ namespace swig
#if defined(SWIGPYTHON_BUILTIN) #if defined(SWIGPYTHON_BUILTIN)
%feature("tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin<swig::SwigPyIterator>"; %feature("tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin<swig::SwigPyIterator>";
%feature("pyslot", "tp_iternext", functype="iternextfunc") SwigPyIterator::__next__;
#else #else
%extend SwigPyIterator { %extend SwigPyIterator {
%pythoncode {def __iter__(self): return self} %pythoncode {def __iter__(self): return self}
@ -370,7 +371,6 @@ namespace swig
%catches(swig::stop_iteration) SwigPyIterator::operator + (ptrdiff_t n) const; %catches(swig::stop_iteration) SwigPyIterator::operator + (ptrdiff_t n) const;
%catches(swig::stop_iteration) SwigPyIterator::operator - (ptrdiff_t n) const; %catches(swig::stop_iteration) SwigPyIterator::operator - (ptrdiff_t n) const;
struct SwigPyIterator struct SwigPyIterator
{ {
protected: protected:

View file

@ -465,8 +465,17 @@ SwigPyObject_type(void) {
SWIGRUNTIMEINLINE int SWIGRUNTIMEINLINE int
SwigPyObject_Check(PyObject *op) { SwigPyObject_Check(PyObject *op) {
#ifdef SWIGPYTHON_BUILTIN
PyTypeObject *target_tp = SwigPyObject_type();
PyTypeObject *obj_tp;
for (obj_tp = op->ob_type; obj_tp; obj_tp = obj_tp->tp_base)
if (obj_tp == target_tp)
return 1;
return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0);
#else
return (Py_TYPE(op) == SwigPyObject_type()) return (Py_TYPE(op) == SwigPyObject_type())
|| (strcmp(Py_TYPE(op)->tp_name,"SwigPyObject") == 0); || (strcmp(Py_TYPE(op)->tp_name,"SwigPyObject") == 0);
#endif
} }
SWIGRUNTIME PyObject * SWIGRUNTIME PyObject *

View file

@ -119,6 +119,17 @@
return new SwigPyMapKeyIterator_T<OutIter>(current, begin, end, seq); return new SwigPyMapKeyIterator_T<OutIter>(current, begin, end, seq);
} }
template<typename Sequence>
inline PyObject* make_output_key_iterator_builtin (PyObject *pyself)
{
SwigPyObject *builtin_obj = (SwigPyObject*) pyself;
Sequence *seq = reinterpret_cast< Sequence * >(builtin_obj->ptr);
if (!seq)
return SWIG_Py_Void();
SwigPyIterator *iter = make_output_key_iterator(seq->begin(), seq->begin(), seq->end(), pyself);
return SWIG_NewPointerObj(iter, SWIGTYPE_p_swig__SwigPyIterator, SWIG_POINTER_OWN);
}
template<class OutIterator, template<class OutIterator,
class FromOper = from_value_oper<typename OutIterator::value_type> > class FromOper = from_value_oper<typename OutIterator::value_type> >
struct SwigPyMapValueITerator_T : SwigPyMapIterator_T<OutIterator, FromOper> struct SwigPyMapValueITerator_T : SwigPyMapIterator_T<OutIterator, FromOper>
@ -136,6 +147,7 @@
{ {
return new SwigPyMapValueITerator_T<OutIter>(current, begin, end, seq); return new SwigPyMapValueITerator_T<OutIter>(current, begin, end, seq);
} }
} }
} }
@ -143,6 +155,37 @@
%swig_sequence_iterator(Map); %swig_sequence_iterator(Map);
%swig_container_methods(Map) %swig_container_methods(Map)
#if defined(SWIGPYTHON_BUILTIN)
%feature("pyslot", "mp_length", functype="lenfunc") __len__;
%feature("pyslot", "mp_subscript", functype="binaryfunc") __getitem__;
%feature("tp_iter") Map "&swig::make_output_key_iterator_builtin< Map >";
%extend {
%newobject iterkeys(PyObject **PYTHON_SELF);
swig::SwigPyIterator* iterkeys(PyObject **PYTHON_SELF) {
return swig::make_output_key_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%newobject itervalues(PyObject **PYTHON_SELF);
swig::SwigPyIterator* itervalues(PyObject **PYTHON_SELF) {
return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%newobject iteritems(PyObject **PYTHON_SELF);
swig::SwigPyIterator* iteritems(PyObject **PYTHON_SELF) {
return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
}
#else
%extend {
%pythoncode {def __iter__(self): return self.key_iterator()}
%pythoncode {def iterkeys(self): return self.key_iterator()}
%pythoncode {def itervalues(self): return self.value_iterator()}
%pythoncode {def iteritems(self): return self.iterator()}
}
#endif
%extend { %extend {
mapped_type __getitem__(const key_type& key) const throw (std::out_of_range) { mapped_type __getitem__(const key_type& key) const throw (std::out_of_range) {
Map::const_iterator i = self->find(key); Map::const_iterator i = self->find(key);
@ -236,16 +279,24 @@
swig::SwigPyIterator* value_iterator(PyObject **PYTHON_SELF) { swig::SwigPyIterator* value_iterator(PyObject **PYTHON_SELF) {
return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF); return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
} }
%pythoncode {def __iter__(self): return self.key_iterator()}
%pythoncode {def iterkeys(self): return self.key_iterator()}
%pythoncode {def itervalues(self): return self.value_iterator()}
%pythoncode {def iteritems(self): return self.iterator()}
} }
%enddef %enddef
%define %swig_map_methods(Map...) %define %swig_map_methods(Map...)
%swig_map_common(Map) %swig_map_common(Map)
#if defined(SWIGPYTHON_BUILTIN)
%feature("pyslot", "mp_ass_subscript", functype="objobjargproc") __setitem__;
%extend {
// This will be called through the mp_ass_subscript slot to delete an entry.
void __setitem__(const key_type& key) {
self->erase(key);
}
}
#endif
%extend { %extend {
void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) { void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) {
(*self)[key] = x; (*self)[key] = x;

View file

@ -116,9 +116,58 @@
} }
}; };
} }
#if defined(SWIGPYTHON_BUILTIN)
SWIGINTERN Py_ssize_t
SwigPython_std_pair_len (PyObject *a)
{
return 2;
}
SWIGINTERN PyObject*
SwigPython_std_pair_repr (PyObject *o)
{
static PyObject *first = PyString_FromString("first");
static PyObject *second = PyString_FromString("second");
PyObject *tuple = PyTuple_New(2);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, PyObject_GetAttr(o, first));
PyTuple_SET_ITEM(tuple, 1, PyObject_GetAttr(o, second));
PyObject *result = PyObject_Repr(tuple);
Py_DECREF(tuple);
return result;
}
SWIGINTERN PyObject*
SwigPython_std_pair_getitem (PyObject *a, Py_ssize_t b)
{
static PyObject *first = PyString_FromString("first");
static PyObject *second = PyString_FromString("second");
PyObject *attr_name = b % 2 ? second : first;
PyObject *result = PyObject_GetAttr(a, attr_name);
return result;
}
SWIGINTERN int
SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c)
{
static PyObject *first = PyString_FromString("first");
static PyObject *second = PyString_FromString("second");
PyObject *attr_name = b % 2 ? second : first;
int result = PyObject_SetAttr(a, attr_name, c);
return result;
}
#endif
} }
%define %swig_pair_methods(pair...) %define %swig_pair_methods(pair...)
#if defined(SWIGPYTHON_BUILTIN)
%feature("sq_length") pair "SwigPython_std_pair_len";
%feature("tp_repr") pair "SwigPython_std_pair_repr";
%feature("sq_item") pair "SwigPython_std_pair_getitem";
%feature("sq_ass_item") pair "SwigPython_std_pair_setitem";
#else
%extend { %extend {
%pythoncode {def __len__(self): return 2 %pythoncode {def __len__(self): return 2
def __repr__(self): return str((self.first, self.second)) def __repr__(self): return str((self.first, self.second))
@ -133,6 +182,7 @@ def __setitem__(self, index, val):
else: else:
self.second = val} self.second = val}
} }
#endif
%enddef %enddef
%include <std/std_pair.i> %include <std/std_pair.i>

View file

@ -48,6 +48,7 @@ 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 Hash *builtin_getset = 0;
static String *builtin_richcompare = 0;
static String *methods; static String *methods;
static String *class_name; static String *class_name;
@ -164,17 +165,13 @@ static const char *usage3 = (char *) "\
Function annotation \n\ Function annotation \n\
\n"; \n";
static String* static String *getSlot(Node *n, const char *key) {
getSlot (Node *n, const char *key)
{
static String *slot_default = NewString("0"); static String *slot_default = NewString("0");
String *val = Getattr(n, key); String *val = Getattr(n, key);
return val ? val : slot_default; return val ? val : slot_default;
} }
static String* static String *getClosure(String *functype, String *wrapper) {
getClosure (String *functype, String *wrapper)
{
static const char *functypes[] = { static const char *functypes[] = {
"binaryfunc", "PYSWIG_BINARYFUNC_CLOSURE", "binaryfunc", "PYSWIG_BINARYFUNC_CLOSURE",
"ternaryfunc", "PYSWIG_TERNARYFUNC_CLOSURE", "ternaryfunc", "PYSWIG_TERNARYFUNC_CLOSURE",
@ -183,6 +180,7 @@ getClosure (String *functype, String *wrapper)
"ssizessizeargfunc", "PYSWIG_SSIZESSIZEARGFUNC_CLOSURE", "ssizessizeargfunc", "PYSWIG_SSIZESSIZEARGFUNC_CLOSURE",
"ssizeobjargproc", "PYSWIG_SSIZEOBJARGPROC_CLOSURE", "ssizeobjargproc", "PYSWIG_SSIZEOBJARGPROC_CLOSURE",
"ssizessizeobjargproc", "PYSWIG_SSIZESSIZEOBJARGPROC_CLOSURE", "ssizessizeobjargproc", "PYSWIG_SSIZESSIZEOBJARGPROC_CLOSURE",
"objobjargproc", "PYSWIG_OBJOBJARGPROC_CLOSURE",
NULL NULL
}; };
@ -192,7 +190,7 @@ getClosure (String *functype, String *wrapper)
int i; int i;
for (i = 0; functypes[i] != NULL; i += 2) { for (i = 0; functypes[i] != NULL; i += 2) {
if (!strcmp(c, functypes[i])) if (!strcmp(c, functypes[i]))
return NewStringf("%s(%s)", functypes[i+1], wrapper); return NewStringf("%s(%s)", functypes[i + 1], wrapper);
} }
return NULL; return NULL;
} }
@ -209,16 +207,11 @@ public:
director_multiple_inheritance = 1; director_multiple_inheritance = 1;
director_language = 1; director_language = 1;
} }
/* ------------------------------------------------------------ /* ------------------------------------------------------------
* Thread Implementation * Thread Implementation
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */ int threads_enable(Node *n) const {
int threads_enable(Node *n) const {
return threads && !GetFlagAttr(n, "feature:nothread"); return threads && !GetFlagAttr(n, "feature:nothread");
} } int initialize_threads(String *f_init) {
int initialize_threads(String *f_init) {
if (!threads) { if (!threads) {
return SWIG_OK; return SWIG_OK;
} }
@ -579,6 +572,7 @@ public:
f_directors_h = NewString(""); f_directors_h = NewString("");
f_directors = NewString(""); f_directors = NewString("");
builtin_getset = NewHash(); builtin_getset = NewHash();
builtin_richcompare = NewString("");
if (builtin) { if (builtin) {
f_builtins = NewString(""); f_builtins = NewString("");
@ -854,8 +848,7 @@ public:
// "import types\n", // "import types\n",
"try:\n", "try:\n",
// " _object = types.ObjectType\n", // " _object = types.ObjectType\n",
" _object = object\n", " _object = object\n", " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n",
" _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n",
// "del types\n", // "del types\n",
"\n\n", NIL); "\n\n", NIL);
} }
@ -878,7 +871,6 @@ public:
"try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL); "try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL);
} }
} }
// Include some information in the code // Include some information in the code
Printf(f_header, "\n/*-----------------------------------------------\n @(target):= %s.so\n\ Printf(f_header, "\n/*-----------------------------------------------\n @(target):= %s.so\n\
------------------------------------------------*/\n", module); ------------------------------------------------*/\n", module);
@ -980,9 +972,8 @@ public:
* This wrapper is used to implement -fastproxy, * This wrapper is used to implement -fastproxy,
* as a replacement of new.instancemethod in Python 3. * as a replacement of new.instancemethod in Python 3.
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
int add_pyinstancemethod_new() int add_pyinstancemethod_new() {
{ String *name = NewString("SWIG_PyInstanceMethod_New");
String* name = NewString("SWIG_PyInstanceMethod_New");
Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_O, NULL},\n", name, name); Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_O, NULL},\n", name, name);
Delete(name); Delete(name);
return 0; return 0;
@ -1243,7 +1234,7 @@ public:
String *pn = Swig_name_make(p, 0, Getattr(p, "name"), 0, 0); String *pn = Swig_name_make(p, 0, Getattr(p, "name"), 0, 0);
// Use C parameter name unless it is a duplicate or an empty parameter name // Use C parameter name unless it is a duplicate or an empty parameter name
int count = 0; int count = 0;
if ( SwigType_isvarargs(Getattr(p, "type")) ) { if (SwigType_isvarargs(Getattr(p, "type"))) {
return NewString("*args"); return NewString("*args");
} }
while (plist) { while (plist) {
@ -1263,7 +1254,7 @@ public:
* func_annotation: Function annotation support * func_annotation: Function annotation support
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
String *make_autodocParmList(Node *n, bool showTypes, bool calling=false, bool func_annotation=false) { String *make_autodocParmList(Node *n, bool showTypes, bool calling = false, bool func_annotation = false) {
String *doc = NewString(""); String *doc = NewString("");
@ -1278,7 +1269,7 @@ public:
int arg_num = 0; int arg_num = 0;
const int maxwidth = 50; const int maxwidth = 50;
if(calling) if (calling)
func_annotation = false; func_annotation = false;
if (pdocs) if (pdocs)
@ -1287,7 +1278,7 @@ public:
Swig_typemap_attach_parms("in", plist, 0); Swig_typemap_attach_parms("in", plist, 0);
Swig_typemap_attach_parms("doc", plist, 0); Swig_typemap_attach_parms("doc", plist, 0);
if (Strcmp(ParmList_protostr(plist), "void")==0) { if (Strcmp(ParmList_protostr(plist), "void") == 0) {
//No parameters actually //No parameters actually
return doc; return doc;
} }
@ -1356,14 +1347,13 @@ public:
pdocs = NewString("Parameters:\n"); pdocs = NewString("Parameters:\n");
Printf(pdocs, " %s\n", pdoc); Printf(pdocs, " %s\n", pdoc);
} }
// Write the function annoation // Write the function annoation
if (func_annotation) if (func_annotation)
Printf(doc, " : '%s'", type); Printf(doc, " : '%s'", type);
// Write default value // Write default value
if (value && !calling) { if (value && !calling) {
String* pv = pyvalue(value, Getattr(p, "type")); String *pv = pyvalue(value, Getattr(p, "type"));
if (pv) if (pv)
value = pv; value = pv;
else { else {
@ -1501,7 +1491,6 @@ public:
Printv(doc, "\n", pdocs, NULL); Printv(doc, "\n", pdocs, NULL);
} }
} }
// if it's overloaded then get the next decl and loop around again // if it's overloaded then get the next decl and loop around again
n = Getattr(n, "sym:nextSibling"); n = Getattr(n, "sym:nextSibling");
if (n) if (n)
@ -1516,22 +1505,21 @@ public:
* Check if string v can be a Python value literal, * Check if string v can be a Python value literal,
* (eg. number or string), or translate it to a Python literal. * (eg. number or string), or translate it to a Python literal.
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
String* pyvalue(String *v, SwigType *t) String *pyvalue(String *v, SwigType *t) {
{ if (v && Len(v) > 0) {
if (v && Len(v)>0) {
char fc = (Char(v))[0]; char fc = (Char(v))[0];
if (('0'<=fc && fc<='9') || '\''==fc || '"'==fc) { if (('0' <= fc && fc <= '9') || '\'' == fc || '"' == fc) {
/* number or string (or maybe NULL pointer)*/ /* number or string (or maybe NULL pointer) */
if (SwigType_ispointer(t) && Strcmp(v, "0")==0) if (SwigType_ispointer(t) && Strcmp(v, "0") == 0)
return NewString("None"); return NewString("None");
else else
return v; return v;
} }
if (Strcmp(v, "true")==0 || Strcmp(v, "FALSE")==0) if (Strcmp(v, "true") == 0 || Strcmp(v, "FALSE") == 0)
return NewString("True"); return NewString("True");
if (Strcmp(v, "false")==0 || Strcmp(v, "FALSE")==0) if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
return NewString("False"); return NewString("False");
if (Strcmp(v, "NULL")==0) if (Strcmp(v, "NULL") == 0)
return NewString("None"); return NewString("None");
} }
return 0; return 0;
@ -1542,8 +1530,7 @@ public:
* (So we can generate proper parameter list with default * (So we can generate proper parameter list with default
* values..) * values..)
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
bool is_primitive_defaultargs(Node *n) bool is_primitive_defaultargs(Node *n) {
{
ParmList *plist = CopyParmList(Getattr(n, "parms")); ParmList *plist = CopyParmList(Getattr(n, "parms"));
Parm *p; Parm *p;
Parm *pnext; Parm *pnext;
@ -1574,8 +1561,7 @@ public:
* siblings generated due to the original function have * siblings generated due to the original function have
* default arguments. * default arguments.
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
bool is_real_overloaded(Node *n) bool is_real_overloaded(Node *n) {
{
Node *h = Getattr(n, "sym:overloaded"); Node *h = Getattr(n, "sym:overloaded");
Node *i; Node *i;
if (!h) if (!h)
@ -1600,20 +1586,17 @@ public:
* Generate parameter list for Python functions or methods, * Generate parameter list for Python functions or methods,
* reuse make_autodocParmList() to do so. * reuse make_autodocParmList() to do so.
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
String* make_pyParmList(Node *n, bool in_class, bool is_calling, int kw) String *make_pyParmList(Node *n, bool in_class, bool is_calling, int kw) {
{
/* Get the original function for a defaultargs copy, /* Get the original function for a defaultargs copy,
* see default_arguments() in parser.y. */ * see default_arguments() in parser.y. */
Node *nn = Getattr(n, "defaultargs"); Node *nn = Getattr(n, "defaultargs");
if (nn) n = nn; if (nn)
n = nn;
/* For overloaded function, just use *args */ /* For overloaded function, just use *args */
if (is_real_overloaded(n) || if (is_real_overloaded(n) || GetFlag(n, "feature:compactdefaultargs") || !is_primitive_defaultargs(n)) {
GetFlag(n, "feature:compactdefaultargs") ||
!is_primitive_defaultargs(n))
{
String *parms = NewString(""); String *parms = NewString("");
if(in_class) if (in_class)
Printf(parms, "self, "); Printf(parms, "self, ");
Printf(parms, "*args"); Printf(parms, "*args");
if (kw) if (kw)
@ -1625,10 +1608,9 @@ public:
String *params = NewString(""); String *params = NewString("");
String *_params = make_autodocParmList(n, false, is_calling, funcanno); String *_params = make_autodocParmList(n, false, is_calling, funcanno);
if (in_class) if (in_class) {
{
Printf(params, "self"); Printf(params, "self");
if(Len(_params) > 0) if (Len(_params) > 0)
Printf(params, ", "); Printf(params, ", ");
} }
@ -1707,15 +1689,14 @@ public:
* Helper function for constructing the function annotation * Helper function for constructing the function annotation
* of the returning type, return a empty string for Python 2.x * of the returning type, return a empty string for Python 2.x
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
String* returnTypeAnnotation(Node *n) String *returnTypeAnnotation(Node *n) {
{ String *ret = 0;
String *ret=0;
Parm *p = Getattr(n, "parms"); Parm *p = Getattr(n, "parms");
String *tm; String *tm;
/* Try to guess the returning type by argout typemap, /* Try to guess the returning type by argout typemap,
* however the result may not accurate. */ * however the result may not accurate. */
while (p) { while (p) {
if ((tm=Getattr(p, "tmap:argout:match_type"))) { if ((tm = Getattr(p, "tmap:argout:match_type"))) {
tm = SwigType_str(tm, 0); tm = SwigType_str(tm, 0);
if (ret) if (ret)
Printv(ret, ", ", tm, NULL); Printv(ret, ", ", tm, NULL);
@ -1730,7 +1711,8 @@ public:
* the function prototype. */ * the function prototype. */
if (!ret) { if (!ret) {
ret = Getattr(n, "type"); ret = Getattr(n, "type");
if (ret) ret = SwigType_str(ret, 0); if (ret)
ret = SwigType_str(ret, 0);
} }
return (ret && py3) ? NewStringf(" -> \"%s\" ", ret) return (ret && py3) ? NewStringf(" -> \"%s\" ", ret)
: NewString(""); : NewString("");
@ -1855,7 +1837,7 @@ public:
Append(f->code, "argc = args ? (int)PyObject_Length(args) : 0;\n"); Append(f->code, "argc = args ? (int)PyObject_Length(args) : 0;\n");
if (add_self) if (add_self)
Append(f->code, "argv[0] = self;\n"); Append(f->code, "argv[0] = self;\n");
Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", add_self ? maxargs-1 : maxargs); Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", add_self ? maxargs - 1 : maxargs);
Printf(f->code, "argv[ii%s] = PyTuple_GET_ITEM(args,ii);\n", add_self ? " + 1" : ""); Printf(f->code, "argv[ii%s] = PyTuple_GET_ITEM(args,ii);\n", add_self ? " + 1" : "");
Append(f->code, "}\n"); Append(f->code, "}\n");
if (add_self) if (add_self)
@ -2119,7 +2101,7 @@ public:
if (Len(pn)) { if (Len(pn)) {
String *tmp = 0; String *tmp = 0;
String *name = pn; String *name = pn;
if (!Getattr(p,"hidden")) { if (!Getattr(p, "hidden")) {
name = tmp = Swig_name_make(p, 0, pn, 0, 0); name = tmp = Swig_name_make(p, 0, pn, 0, 0);
} }
Printf(kwargs, "(char *) \"%s\",", name); Printf(kwargs, "(char *) \"%s\",", name);
@ -2152,7 +2134,7 @@ public:
if (Getattr(p, "tmap:in:implicitconv")) { if (Getattr(p, "tmap:in:implicitconv")) {
const char *convflag = "0"; const char *convflag = "0";
if (!Getattr(p,"hidden")) { if (!Getattr(p, "hidden")) {
SwigType *ptype = Getattr(p, "type"); SwigType *ptype = Getattr(p, "type");
convflag = get_implicitconv_flag(classLookup(ptype)); convflag = get_implicitconv_flag(classLookup(ptype));
} }
@ -2259,7 +2241,7 @@ public:
if (!Getattr(p, "tmap:in:parse") && (tm = Getattr(p, "tmap:freearg"))) { if (!Getattr(p, "tmap:in:parse") && (tm = Getattr(p, "tmap:freearg"))) {
if (Getattr(p, "tmap:freearg:implicitconv")) { if (Getattr(p, "tmap:freearg:implicitconv")) {
const char *convflag = "0"; const char *convflag = "0";
if (!Getattr(p,"hidden")) { if (!Getattr(p, "hidden")) {
SwigType *ptype = Getattr(p, "type"); SwigType *ptype = Getattr(p, "type");
convflag = get_implicitconv_flag(classLookup(ptype)); convflag = get_implicitconv_flag(classLookup(ptype));
} }
@ -2336,11 +2318,11 @@ public:
if (allow_thread) { if (allow_thread) {
String *preaction = NewString(""); String *preaction = NewString("");
thread_begin_allow(n, preaction); thread_begin_allow(n, preaction);
Setattr(n,"wrap:preaction", preaction); Setattr(n, "wrap:preaction", preaction);
String *postaction = NewString(""); String *postaction = NewString("");
thread_end_allow(n, postaction); thread_end_allow(n, postaction);
Setattr(n,"wrap:postaction", postaction); Setattr(n, "wrap:postaction", postaction);
} }
} }
@ -2468,7 +2450,7 @@ public:
Printv(f->code, cleanup, NIL); Printv(f->code, cleanup, NIL);
} }
if (builtin_ctor) if (builtin_ctor)
Printv(f->code, " return 0;\n", NIL); Printv(f->code, " return -1;\n", NIL);
else else
Printv(f->code, " return NULL;\n", NIL); Printv(f->code, " return NULL;\n", NIL);
@ -2569,6 +2551,11 @@ public:
Delete(closure_name); Delete(closure_name);
} }
/* Handle comparison operators for builtin types */
String *compare = Getattr(n, "feature:pycompare");
if (compare)
Printf(builtin_richcompare, " case %s : result = %s(self, tuple); break;\n", compare, wrapper_name);
Delete(self_parse); Delete(self_parse);
Delete(parse_args); Delete(parse_args);
Delete(linkage); Delete(linkage);
@ -2994,8 +2981,7 @@ public:
* classDeclaration() * classDeclaration()
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
virtual bool get_single_base (Node *n, Node **base = NULL) virtual bool get_single_base(Node *n, Node **base = NULL) {
{
if (base) if (base)
*base = NULL; *base = NULL;
if (Getattr(n, "single_inh")) if (Getattr(n, "single_inh"))
@ -3044,8 +3030,7 @@ public:
* classHandler() * classHandler()
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
void builtin_pre_decl (Node *n, Node *base_node) void builtin_pre_decl(Node *n, Node *base_node) {
{
String *name = Getattr(n, "name"); String *name = Getattr(n, "name");
String *rname = SwigType_namestr(name); String *rname = SwigType_namestr(name);
Printf(f_init, tab4 "builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname); Printf(f_init, tab4 "builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname);
@ -3061,15 +3046,14 @@ public:
Delete(base_mname); Delete(base_mname);
Delete(base_name); Delete(base_name);
} else { } else {
//Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL); Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL);
Printv(f_init, tab4, "builtin_pytype->tp_base = &PyBaseObject_Type;\n", NIL); //Printv(f_init, tab4, "builtin_pytype->tp_base = &PyBaseObject_Type;\n", NIL);
} }
Printf(f_init, tab4 "builtin_pytype->tp_dict = d = PyDict_New();\n"); Printf(f_init, tab4 "builtin_pytype->tp_dict = d = PyDict_New();\n");
Delete(rname); Delete(rname);
} }
void builtin_post_decl (File *f, Node *n) void builtin_post_decl(File *f, Node *n) {
{
String *name = Getattr(n, "name"); String *name = Getattr(n, "name");
String *pname = Copy(name); String *pname = Copy(name);
SwigType_add_pointer(pname); SwigType_add_pointer(pname);
@ -3081,13 +3065,13 @@ public:
char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : "0"; char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : "0";
// Check for non-public destructor, in which case tp_dealloc should be "0" // Check for non-public destructor, in which case tp_dealloc should be "0"
// Any class that doesn't explicitly have a private/protected destructor
// has an implicit public destructor.
String *tp_dealloc = NewString(""); String *tp_dealloc = NewString("");
String *dtor_name = NewString("delete"); if (GetFlag(n, "private_dtor"))
if (Getattr(class_members, "delete"))
Printf(tp_dealloc, "py_builtin_dealloc< %s >", rname);
else
Printv(tp_dealloc, "0", NIL); Printv(tp_dealloc, "0", NIL);
Delete(dtor_name); else
Printf(tp_dealloc, "py_builtin_dealloc< %s >", rname);
Printf(f, "template <> PyGetSetDef PySwigBuiltin< %s >::getset[] = {\n", rname); Printf(f, "template <> PyGetSetDef PySwigBuiltin< %s >::getset[] = {\n", rname);
for (DohIterator member_iter = First(builtin_getset); member_iter.item; member_iter = Next(member_iter)) { for (DohIterator member_iter = First(builtin_getset); member_iter.item; member_iter = Next(member_iter)) {
@ -3095,13 +3079,14 @@ public:
Hash *mgetset = member_iter.item; Hash *mgetset = member_iter.item;
String *getter = Getattr(mgetset, "getter"); String *getter = Getattr(mgetset, "getter");
String *setter = Getattr(mgetset, "setter"); 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", Printf(f, tab4 "{ const_cast<char*>(\"%s\"), (getter) %s, (setter) %s, const_cast<char*>(\"%s.%s\"), (void*) %s },\n",
mname, getter ? getter : "0", name, mname, setter ? setter : "0"); mname, getter ? getter : "0", setter ? "pyswig_setter_closure" : "0", name, mname, setter ? setter : "0");
} }
Printv(f, " {NULL} // Sentinel\n", NIL); Printv(f, " {NULL} // Sentinel\n", NIL);
Printv(f, "};\n\n", NIL); Printv(f, "};\n\n", NIL);
Clear(builtin_getset); Clear(builtin_getset);
// Number methods
Printf(f, "template <> PyNumberMethods PySwigBuiltin< %s >::number_methods = {\n", rname); 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_add;\n", getSlot(n, "feature:nb_add"));
Printf(f, " (binaryfunc) %s, // nb_subtract;\n", getSlot(n, "feature:nb_subtract")); Printf(f, " (binaryfunc) %s, // nb_subtract;\n", getSlot(n, "feature:nb_subtract"));
@ -3144,25 +3129,46 @@ public:
Printf(f, " (unaryfunc) %s, // nb_index;\n", getSlot(n, "feature:nb_index")); Printf(f, " (unaryfunc) %s, // nb_index;\n", getSlot(n, "feature:nb_index"));
Printf(f, "};\n\n"); Printf(f, "};\n\n");
// Sequence methods
Printf(f, "template <> PySequenceMethods PySwigBuiltin< %s >::sequence_methods = {\n", rname); Printf(f, "template <> PySequenceMethods PySwigBuiltin< %s >::sequence_methods = {\n", rname);
Printf(f, " (lenfunc) %s, // sq_length\n", getSlot(n, "sq_length")); Printf(f, " (lenfunc) %s, // sq_length\n", getSlot(n, "feature:sq_length"));
Printf(f, " (binaryfunc) %s, // sq_concat\n", getSlot(n, "sq_concat")); Printf(f, " (binaryfunc) %s, // sq_concat\n", getSlot(n, "feature:sq_concat"));
Printf(f, " (ssizeargfunc) %s, // sq_repeat\n", getSlot(n, "sq_repeat")); Printf(f, " (ssizeargfunc) %s, // sq_repeat\n", getSlot(n, "feature:sq_repeat"));
Printf(f, " (ssizeargfunc) %s, // sq_item\n", getSlot(n, "sq_item")); Printf(f, " (ssizeargfunc) %s, // sq_item\n", getSlot(n, "feature:sq_item"));
Printf(f, " (ssizessizeargfunc) %s, // sq_slice\n", getSlot(n, "sq_slice")); Printf(f, " (ssizessizeargfunc) %s, // sq_slice\n", getSlot(n, "feature:sq_slice"));
Printf(f, " (ssizeobjargproc) %s, // sq_ass_item\n", getSlot(n, "sq_ass_item")); Printf(f, " (ssizeobjargproc) %s, // sq_ass_item\n", getSlot(n, "feature:sq_ass_item"));
Printf(f, " (ssizessizeobjargproc) %s, // sq_ass_slice\n", getSlot(n, "sq_ass_slice")); Printf(f, " (ssizessizeobjargproc) %s, // sq_ass_slice\n", getSlot(n, "feature:sq_ass_slice"));
Printf(f, " (objobjproc) %s, // sq_contains\n", getSlot(n, "sq_contains")); Printf(f, " (objobjproc) %s, // sq_contains\n", getSlot(n, "feature:sq_contains"));
Printf(f, " (binaryfunc) %s, // sq_inplace_concat\n", getSlot(n, "sq_inplace_concat")); Printf(f, " (binaryfunc) %s, // sq_inplace_concat\n", getSlot(n, "feature:sq_inplace_concat"));
Printf(f, " (ssizeargfunc) %s, // sq_inplace_repeat\n", getSlot(n, "sq_inplace_repeat")); Printf(f, " (ssizeargfunc) %s, // sq_inplace_repeat\n", getSlot(n, "feature:sq_inplace_repeat"));
Printf(f, "};\n\n"); Printf(f, "};\n\n");
// Mapping methods
Printf(f, "template <> PyMappingMethods PySwigBuiltin< %s >::mapping_methods = {\n", rname); Printf(f, "template <> PyMappingMethods PySwigBuiltin< %s >::mapping_methods = {\n", rname);
Printf(f, " (lenfunc) %s, // mp_length;\n", getSlot(n, "mp_length")); Printf(f, " (lenfunc) %s, // mp_length;\n", getSlot(n, "feature:mp_length"));
Printf(f, " (binaryfunc) %s, // mp_subscript;\n", getSlot(n, "mp_subscript")); Printf(f, " (binaryfunc) %s, // mp_subscript;\n", getSlot(n, "feature:mp_subscript"));
Printf(f, " (objobjargproc) %s, // mp_ass_subscript;\n", getSlot(n, "mp_ass_subscript")); Printf(f, " (objobjargproc) %s, // mp_ass_subscript;\n", getSlot(n, "feature:mp_ass_subscript"));
Printf(f, "};\n\n"); Printf(f, "};\n\n");
// Rich compare function
Printf(f, "template <> PyObject*\n");
Printf(f, "%s::richcompare (PyObject *self, PyObject *other, int op)\n", templ);
Printf(f, "{\n");
Printf(f, " PyObject *result = NULL;\n");
Printf(f, " PyObject *tuple = PyTuple_New(1);\n");
Printf(f, " assert(tuple);\n");
Printf(f, " PyTuple_SET_ITEM(tuple, 0, other);\n");
Printf(f, " Py_XINCREF(other);\n");
Printf(f, " switch (op) {\n");
Printv(f, builtin_richcompare, NIL);
Printf(f, " default : PyErr_Format(PyExc_TypeError, \"Cannot compare a(n) '%%s' to a(n) '%%s'\", self->ob_type->tp_name, other ? other->ob_type->tp_name : \"NIL\");\n");
Printf(f, " }\n");
Printf(f, " Py_DECREF(tuple);\n");
Printf(f, " return result;\n");
Printf(f, "}\n\n");
Clear(builtin_richcompare);
// Type object
String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES"); String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES");
// TODO: Add more flags based on slots // 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);
@ -3190,10 +3196,10 @@ public:
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"));
Printf(f, " %s, /* tp_richcompare */\n", getSlot(n, "feature:tp_richcompare")); Printf(f, " %s::richcompare, /* tp_richcompare */\n", templ);
Printf(f, " %s, /* tp_weaklistoffset */\n", getSlot(n, "feature:tp_weaklistoffset")); Printf(f, " %s, /* tp_weaklistoffset */\n", getSlot(n, "feature:tp_weaklistoffset"));
Printf(f, " %s, /* tp_iter */\n", getSlot(n, "feature:tp_iter")); Printf(f, " (getiterfunc) %s, /* tp_iter */\n", getSlot(n, "feature:tp_iter"));
Printf(f, " %s, /* tp_iternext */\n", getSlot(n, "feature:tp_iternext")); Printf(f, " (iternextfunc) %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::getset, /* tp_getset */\n", templ); Printf(f, " %s::getset, /* tp_getset */\n", templ);
@ -3284,7 +3290,8 @@ public:
if (!bname || ignore) { if (!bname || ignore) {
if (!bname && !ignore) { if (!bname && !ignore) {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n), Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n),
"Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n", SwigType_namestr(Getattr(b.item, "name"))); "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n",
SwigType_namestr(Getattr(b.item, "name")));
} }
b = Next(b); b = Next(b);
continue; continue;
@ -3315,7 +3322,7 @@ public:
if (!classic) { if (!classic) {
Printf(f_shadow, modern ? "(object)" : "(_object)"); Printf(f_shadow, modern ? "(object)" : "(_object)");
} }
if (GetFlag(n, "feature:exceptionclass") ) { if (GetFlag(n, "feature:exceptionclass")) {
Printf(f_shadow, "(Exception)"); Printf(f_shadow, "(Exception)");
} }
} }
@ -3421,8 +3428,7 @@ public:
} }
Printv(f_wrappers, Printv(f_wrappers,
" SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n", " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n", " return SWIG_Py_Void();\n", "}\n\n", NIL);
" return SWIG_Py_Void();\n", "}\n\n", NIL);
String *cname = NewStringf("%s_swigregister", class_name); String *cname = NewStringf("%s_swigregister", class_name);
add_method(cname, cname, 0); add_method(cname, cname, 0);
Delete(smart); Delete(smart);
@ -3432,7 +3438,8 @@ public:
} }
if (!have_constructor) { if (!have_constructor) {
if (!single_inh) if (!single_inh)
Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL); Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined",
(Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL);
} else if (fastinit && !single_inh) { } else if (fastinit && !single_inh) {
Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL); Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
@ -3487,7 +3494,8 @@ public:
List *shadow_list = Getattr(n, "shadow_methods"); List *shadow_list = Getattr(n, "shadow_methods");
for (int i = 0; i < Len(shadow_list); ++i) { for (int i = 0; i < Len(shadow_list); ++i) {
String *symname = Getitem(shadow_list, i); String *symname = Getitem(shadow_list, i);
Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname), class_name); Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module,
Swig_name_member(NSPACE_TODO, class_name, symname), class_name);
} }
} }
Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name); Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name);
@ -3555,7 +3563,13 @@ public:
if (!Getattr(n, "sym:nextSibling")) { if (!Getattr(n, "sym:nextSibling")) {
if (builtin && in_class) { if (builtin && in_class) {
String *name = Getattr(n, "name"); String *name = Getattr(n, "name");
if (checkAttribute(n, "access", "public") && strncmp(Char(name), "operator ", 9) && !Getattr(class_members, name)) {
// Can't use checkAttribute(n, "access", "public") because
// "access" attr isn't set on %extend methods
if (!checkAttribute(n, "access", "private") &&
!checkAttribute(n, "access", "protected") &&
strncmp(Char(name), "operator ", 9) &&
!Getattr(class_members, name)) {
String *fullname = Swig_name_member(NULL, class_name, symname); String *fullname = Swig_name_member(NULL, class_name, symname);
String *wname = Swig_name_wrapper(fullname); String *wname = Swig_name_wrapper(fullname);
Setattr(class_members, name, name); Setattr(class_members, name, name);
@ -3589,7 +3603,7 @@ public:
Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL); Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
} }
} else { } else {
Printv(f_shadow, tab4, "def ", symname, "(",parms , ")", returnTypeAnnotation(n), ":", NIL); Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL);
Printv(f_shadow, "\n", NIL); Printv(f_shadow, "\n", NIL);
if (have_docstring(n)) if (have_docstring(n))
Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL); Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL);
@ -3653,7 +3667,7 @@ public:
Delete(wname); Delete(wname);
Delete(pyflags); Delete(pyflags);
} }
} else if (shadow ) { } else if (shadow) {
if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) { if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) {
int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
String *parms = make_pyParmList(n, false, false, kw); String *parms = make_pyParmList(n, false, false, kw);
@ -3678,10 +3692,12 @@ public:
} else { } else {
if (!modern) { if (!modern) {
Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL); Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n",
NIL);
} }
if (!classic) { if (!classic) {
Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL); Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname),
")\n", NIL);
} }
} }
} }
@ -3732,16 +3748,16 @@ public:
if (!Getattr(n, "sym:nextSibling")) { if (!Getattr(n, "sym:nextSibling")) {
if (builtin && in_class) { if (builtin && in_class) {
String *name = NewString("new"); String *name = NewString("new");
if ((use_director || checkAttribute(n, "access", "public")) && !Getattr(class_members, name)) { // Can't use checkAttribute(n, "access", "public") because
// "access" attr isn't set on %extend methods
if ((use_director ||
(!checkAttribute(n, "access", "protected") &&
!checkAttribute(n, "access", "private"))) &&
!Getattr(class_members, name)) {
Setattr(class_members, name, name); Setattr(class_members, name, name);
String *fullname = Swig_name_member(NULL, name, class_name); String *fullname = Swig_name_member(NULL, name, class_name);
if (!builtin_tp_init) if (!builtin_tp_init)
builtin_tp_init = Swig_name_wrapper(fullname); builtin_tp_init = Swig_name_wrapper(fullname);
/*
ParmList *parms = Getattr(n, "parms");
char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS";
Printf(f_shadow, " { \"__init__\", (PyCFunction) %s, %s, \"\" },\n", builtin_tp_init, Char(pyflags));
*/
Delete(fullname); Delete(fullname);
} }
Delete(name); Delete(name);
@ -3842,20 +3858,8 @@ public:
virtual int destructorHandler(Node *n) { virtual int destructorHandler(Node *n) {
if (builtin && in_class) { if (builtin && in_class) {
String *name = NewString("delete"); if (checkAttribute(n, "access", "private") || checkAttribute(n, "access", "protected"))
if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) { SetFlag(Swig_methodclass(n), "private_dtor");
Setattr(class_members, name, name);
/*
String *fullname = Swig_name_member(NULL, name, class_name);
String *wname = Swig_name_wrapper(fullname);
ParmList *parms = Getattr(n, "parms");
char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS";
Printf(f_shadow, " { \"__del__\", (PyCFunction) %s, %s, \"\" },\n", wname, Char(pyflags));
Delete(fullname);
Delete(wname);
*/
}
Delete(name);
return SWIG_OK; return SWIG_OK;
} }