Static member variables are working.
Fixed some corner cases with protected members of director classes. Now dying in director_finalizer. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12371 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
3a86f2068f
commit
b77b64944b
5 changed files with 525 additions and 254 deletions
|
|
@ -1,3 +1,10 @@
|
|||
#define PYSWIG_UNARYFUNC_CLOSURE(wrapper) \
|
||||
SWIGINTERN PyObject* \
|
||||
wrapper##_closure (PyObject *a) \
|
||||
{ \
|
||||
return wrapper(a, NULL); \
|
||||
}
|
||||
|
||||
#define PYSWIG_BINARYFUNC_CLOSURE(wrapper) \
|
||||
SWIGINTERN PyObject* \
|
||||
wrapper##_closure (PyObject *a, PyObject *b) \
|
||||
|
|
@ -115,28 +122,13 @@ 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 {
|
||||
|
||||
template <typename _Tp> struct PySwigBuiltin : public SwigPyObject {
|
||||
template <typename _Tp> struct SwigPyBuiltin : public SwigPyObject {
|
||||
|
||||
typedef PySwigBuiltin<_Tp> this_type;
|
||||
typedef SwigPyBuiltin<_Tp> this_type;
|
||||
typedef _Tp obj_type;
|
||||
typedef obj_type* pointer;
|
||||
typedef obj_type& reference;
|
||||
|
|
@ -154,7 +146,7 @@ template <typename _Tp> struct PySwigBuiltin : public SwigPyObject {
|
|||
|
||||
template <typename _Tp> void py_builtin_dealloc (PyObject *pyobj)
|
||||
{
|
||||
typedef PySwigBuiltin<_Tp> builtin_type;
|
||||
typedef SwigPyBuiltin<_Tp> builtin_type;
|
||||
builtin_type *obj = (builtin_type*) pyobj;
|
||||
if (obj->own)
|
||||
delete reinterpret_cast<_Tp*>(obj->ptr);
|
||||
|
|
@ -164,3 +156,216 @@ template <typename _Tp> void py_builtin_dealloc (PyObject *pyobj)
|
|||
} // namespace {
|
||||
|
||||
#endif
|
||||
|
||||
SWIGRUNTIME int py_builtin_bad_init (PyObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SWIGRUNTIME void py_builtin_bad_dealloc (PyObject *pyobj)
|
||||
{
|
||||
SwigPyObject *sobj = (SwigPyObject*) pyobj;
|
||||
if (sobj->own) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"Swig detected a memory leak in type '%s': no callable destructor found.",
|
||||
pyobj->ob_type->tp_name);
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
PyCFunction get;
|
||||
PyCFunction set;
|
||||
} SwigPyGetSet;
|
||||
|
||||
SWIGRUNTIME PyObject*
|
||||
pyswig_getter_closure (PyObject *obj, void *closure)
|
||||
{
|
||||
if (!closure)
|
||||
return SWIG_Py_Void();
|
||||
SwigPyGetSet *getset = (SwigPyGetSet*) closure;
|
||||
if (!getset->get)
|
||||
return SWIG_Py_Void();
|
||||
PyObject *tuple = PyTuple_New(0);
|
||||
assert(tuple);
|
||||
PyObject *result = (*getset->get)(obj, tuple);
|
||||
Py_DECREF(tuple);
|
||||
return result;
|
||||
}
|
||||
|
||||
SWIGRUNTIME int
|
||||
pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure)
|
||||
{
|
||||
if (!closure)
|
||||
return -1;
|
||||
SwigPyGetSet *getset = (SwigPyGetSet*) closure;
|
||||
if (!getset->set)
|
||||
return -1;
|
||||
PyObject *tuple = PyTuple_New(1);
|
||||
assert(tuple);
|
||||
PyTuple_SET_ITEM(tuple, 0, val);
|
||||
Py_XINCREF(val);
|
||||
PyObject *result = (*getset->set)(obj, tuple);
|
||||
Py_DECREF(tuple);
|
||||
Py_XDECREF(result);
|
||||
return result ? 0 : -1;
|
||||
}
|
||||
|
||||
SWIGRUNTIME PyObject*
|
||||
pyswig_static_getter_closure (PyObject *obj, void *closure)
|
||||
{
|
||||
if (!closure)
|
||||
return SWIG_Py_Void();
|
||||
SwigPyGetSet *getset = (SwigPyGetSet*) closure;
|
||||
if (!getset->get)
|
||||
return SWIG_Py_Void();
|
||||
PyObject *tuple = PyTuple_New(0);
|
||||
assert(tuple);
|
||||
PyObject *result = (*getset->get)(obj, tuple);
|
||||
Py_DECREF(tuple);
|
||||
return result;
|
||||
}
|
||||
|
||||
SWIGRUNTIME int
|
||||
pyswig_static_setter_closure (PyObject *obj, PyObject *val, void *closure)
|
||||
{
|
||||
if (!closure)
|
||||
return -1;
|
||||
SwigPyGetSet *getset = (SwigPyGetSet*) closure;
|
||||
if (!getset->set)
|
||||
return -1;
|
||||
PyObject *tuple = PyTuple_New(1);
|
||||
assert(tuple);
|
||||
PyTuple_SET_ITEM(tuple, 0, val);
|
||||
Py_XINCREF(val);
|
||||
PyObject *result = (*getset->set)(obj, tuple);
|
||||
Py_DECREF(tuple);
|
||||
Py_XDECREF(result);
|
||||
return result ? 0 : -1;
|
||||
}
|
||||
|
||||
SWIGRUNTIME void
|
||||
SwigPyStaticVar_dealloc(PyDescrObject *descr)
|
||||
{
|
||||
_PyObject_GC_UNTRACK(descr);
|
||||
Py_XDECREF(descr->d_type);
|
||||
Py_XDECREF(descr->d_name);
|
||||
PyObject_GC_Del(descr);
|
||||
}
|
||||
|
||||
SWIGRUNTIME PyObject *
|
||||
SwigPyStaticVar_repr(PyGetSetDescrObject *descr)
|
||||
{
|
||||
return PyString_FromFormat("<class attribute '%s' of type '%s'>",
|
||||
PyString_AsString(descr->d_name),
|
||||
descr->d_type->tp_name);
|
||||
}
|
||||
|
||||
SWIGRUNTIME int
|
||||
SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg)
|
||||
{
|
||||
PyDescrObject *descr = (PyDescrObject *)self;
|
||||
Py_VISIT(descr->d_type);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SWIGRUNTIME PyObject *
|
||||
SwigPyStaticVar_get (PyGetSetDescrObject *descr, PyObject *obj, PyObject *type)
|
||||
{
|
||||
if (descr->d_getset->get != NULL)
|
||||
return descr->d_getset->get(obj, descr->d_getset->closure);
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"attribute '%.300s' of '%.100s' objects is not readable",
|
||||
PyString_AsString(descr->d_name),
|
||||
descr->d_type->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SWIGRUNTIME int
|
||||
SwigPyStaticVar_set (PyGetSetDescrObject *descr, PyObject *obj, PyObject *value)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (descr->d_getset->set != NULL)
|
||||
return descr->d_getset->set(obj, value, descr->d_getset->closure);
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"attribute '%.300s' of '%.100s' objects is not writable",
|
||||
PyString_AsString(descr->d_name),
|
||||
descr->d_type->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SWIGRUNTIME PyTypeObject SwigPyStaticVar_Type = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
"swig_static_var_getset_descriptor",
|
||||
sizeof(PyGetSetDescrObject),
|
||||
0,
|
||||
(destructor)SwigPyStaticVar_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
(reprfunc)SwigPyStaticVar_repr, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
|
||||
0, /* tp_doc */
|
||||
SwigPyStaticVar_traverse, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
(descrgetfunc)SwigPyStaticVar_get, /* tp_descr_get */
|
||||
(descrsetfunc)SwigPyStaticVar_set, /* tp_descr_set */
|
||||
};
|
||||
|
||||
SWIGRUNTIME int
|
||||
SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value)
|
||||
{
|
||||
PyObject *attribute = _PyType_Lookup(type, name);
|
||||
if (attribute != NULL) {
|
||||
/* Implement descriptor functionality, if any */
|
||||
descrsetfunc local_set = attribute->ob_type->tp_descr_set;
|
||||
if (local_set != NULL)
|
||||
return local_set(attribute, (PyObject*) type, value);
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"cannot modify read-only attribute '%.50s.%.400s'",
|
||||
type->tp_name, PyString_AS_STRING(name));
|
||||
} else {
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"type '%.50s' has no attribute '%.400s'",
|
||||
type->tp_name, PyString_AS_STRING(name));
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
SWIGINTERN PyGetSetDescrObject*
|
||||
SwigPyStaticVar_new_getset (PyTypeObject *type, PyGetSetDef *getset)
|
||||
{
|
||||
PyGetSetDescrObject *descr = (PyGetSetDescrObject*) PyType_GenericAlloc(&SwigPyStaticVar_Type, 0);
|
||||
assert(descr);
|
||||
Py_XINCREF(type);
|
||||
descr->d_type = type;
|
||||
descr->d_name = PyString_InternFromString(getset->name);
|
||||
descr->d_getset = getset;
|
||||
if (descr->d_name == NULL) {
|
||||
Py_DECREF(descr);
|
||||
descr = NULL;
|
||||
}
|
||||
return descr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -340,12 +340,25 @@ SWIG_init(void) {
|
|||
|
||||
#if defined(SWIGPYTHON_BUILTIN)
|
||||
PyTypeObject *builtin_pytype = 0;
|
||||
PyObject *propargs = NULL, *propget = NULL, *propset = NULL, *propobj = NULL;
|
||||
#ifdef __cplusplus
|
||||
std::vector<PyTypeObject*> builtin_bases;
|
||||
#endif
|
||||
swig_type_info *builtin_basetype = 0;
|
||||
PyObject *base_tuple = NULL;
|
||||
PyObject *tuple = NULL;
|
||||
PyGetSetDescrObject *static_getset = NULL;
|
||||
|
||||
int i;
|
||||
|
||||
// metatype is used to implement static member variables.
|
||||
|
||||
PyObject *metatype_args = Py_BuildValue("(s(O){})", "SwigPyObjectType", &PyType_Type);
|
||||
assert(metatype_args);
|
||||
PyTypeObject *metatype = (PyTypeObject*) PyType_Type.tp_call((PyObject*) &PyType_Type, metatype_args, NULL);
|
||||
assert(metatype);
|
||||
Py_DECREF(metatype_args);
|
||||
metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro;
|
||||
assert(PyType_Ready(metatype) >= 0);
|
||||
|
||||
SWIG_Python_builtin_imports();
|
||||
#endif
|
||||
|
||||
|
|
@ -361,6 +374,6 @@ SWIG_init(void) {
|
|||
|
||||
SWIG_InitializeModule(0);
|
||||
SWIG_InstallConstants(d,swig_const_table);
|
||||
|
||||
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -332,6 +332,9 @@ typedef struct {
|
|||
swig_type_info *ty;
|
||||
int own;
|
||||
PyObject *next;
|
||||
#ifdef SWIGPYTHON_BUILTIN
|
||||
PyObject *dict;
|
||||
#endif
|
||||
} SwigPyObject;
|
||||
|
||||
SWIGRUNTIME PyObject *
|
||||
|
|
@ -384,19 +387,19 @@ SwigPyObject_repr(SwigPyObject *v, PyObject *args)
|
|||
const char *name = SWIG_TypePrettyName(v->ty);
|
||||
PyObject *repr = SWIG_Python_str_FromFormat("<Swig Object of type '%s' at %p>", name, v);
|
||||
if (v->next) {
|
||||
#ifdef METH_NOARGS
|
||||
# ifdef METH_NOARGS
|
||||
PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next);
|
||||
#else
|
||||
# else
|
||||
PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next, args);
|
||||
#endif
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
# endif
|
||||
# if PY_VERSION_HEX >= 0x03000000
|
||||
PyObject *joined = PyUnicode_Concat(repr, nrep);
|
||||
Py_DecRef(repr);
|
||||
Py_DecRef(nrep);
|
||||
repr = joined;
|
||||
#else
|
||||
# else
|
||||
PyString_ConcatAndDel(&repr,nrep);
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
return repr;
|
||||
}
|
||||
|
|
@ -468,9 +471,8 @@ 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;
|
||||
if (PyType_IsSubtype(op->ob_type, target_tp))
|
||||
return 1;
|
||||
return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0);
|
||||
#else
|
||||
return (Py_TYPE(op) == SwigPyObject_type())
|
||||
|
|
@ -1080,6 +1082,7 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
|
|||
if (ptr) *ptr = 0;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
if (ty && ty->clientdata && ((SwigPyClientData*) ty->clientdata)->pytype) {
|
||||
PyTypeObject *target_tp = ((SwigPyClientData*) ty->clientdata)->pytype;
|
||||
PyTypeObject *obj_tp;
|
||||
|
|
@ -1096,6 +1099,9 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
int res = SWIG_ERROR;
|
||||
|
||||
SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj);
|
||||
if (own)
|
||||
*own = 0;
|
||||
|
|
@ -1135,9 +1141,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
|
|||
if (flags & SWIG_POINTER_DISOWN) {
|
||||
sobj->own = 0;
|
||||
}
|
||||
return SWIG_OK;
|
||||
res = SWIG_OK;
|
||||
} else {
|
||||
int res = SWIG_ERROR;
|
||||
if (flags & SWIG_POINTER_IMPLICIT_CONV) {
|
||||
SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0;
|
||||
if (data && !data->implicitconv) {
|
||||
|
|
@ -1173,8 +1178,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
|
|||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Convert a function ptr value */
|
||||
|
|
@ -1357,6 +1362,9 @@ SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
|
|||
newobj->ty = type;
|
||||
newobj->own = own;
|
||||
newobj->next = 0;
|
||||
#ifdef SWIGPYTHON_BUILTIN
|
||||
newobj->dict = 0;
|
||||
#endif
|
||||
return (PyObject*) newobj;
|
||||
}
|
||||
return SWIG_Py_Void();
|
||||
|
|
@ -1388,10 +1396,19 @@ SWIG_Python_NewBuiltinObj(PyObject *self, void *ptr, swig_type_info *type, int f
|
|||
assert(clientdata->pytype);
|
||||
int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
|
||||
SwigPyObject *newobj = (SwigPyObject*) self;
|
||||
if (newobj->ptr) {
|
||||
PyObject *next_self = clientdata->pytype->tp_alloc(clientdata->pytype, 0);
|
||||
while (newobj->next) newobj = (SwigPyObject*) newobj->next;
|
||||
newobj->next = next_self;
|
||||
newobj = (SwigPyObject*) next_self;
|
||||
}
|
||||
newobj->ptr = ptr;
|
||||
newobj->own = own;
|
||||
newobj->ty = type;
|
||||
newobj->next = 0;
|
||||
#ifdef SWIGPYTHON_BUILTIN
|
||||
newobj->dict = 0;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -161,13 +161,28 @@ SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c)
|
|||
|
||||
}
|
||||
|
||||
%feature("sq_length") std::pair "SwigPython_std_pair_len";
|
||||
%feature("sq_length") std::pair<T*,U> "SwigPython_std_pair_len";
|
||||
%feature("sq_length") std::pair<T,U*> "SwigPython_std_pair_len";
|
||||
%feature("sq_length") std::pair<T*,U*> "SwigPython_std_pair_len";
|
||||
|
||||
%feature("tp_repr") std::pair "SwigPython_std_pair_repr";
|
||||
%feature("tp_repr") std::pair<T*,U> "SwigPython_std_pair_repr";
|
||||
%feature("tp_repr") std::pair<T,U*> "SwigPython_std_pair_repr";
|
||||
%feature("tp_repr") std::pair<T*,U*> "SwigPython_std_pair_repr";
|
||||
|
||||
%feature("sq_item") std::pair "SwigPython_std_pair_getitem";
|
||||
%feature("sq_item") std::pair<T*,U> "SwigPython_std_pair_getitem";
|
||||
%feature("sq_item") std::pair<T,U*> "SwigPython_std_pair_getitem";
|
||||
%feature("sq_item") std::pair<T*,U*> "SwigPython_std_pair_getitem";
|
||||
|
||||
%feature("sq_ass_item") std::pair "SwigPython_std_pair_setitem";
|
||||
%feature("sq_ass_item") std::pair<T*,U> "SwigPython_std_pair_setitem";
|
||||
%feature("sq_ass_item") std::pair<T,U*> "SwigPython_std_pair_setitem";
|
||||
%feature("sq_ass_item") std::pair<T*,U*> "SwigPython_std_pair_setitem";
|
||||
|
||||
%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
|
||||
#if !defined(SWIGPYTHON_BUILTIN)
|
||||
%extend {
|
||||
%pythoncode {def __len__(self): return 2
|
||||
def __repr__(self): return str((self.first, self.second))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue