remove 'thisown' and ClassPtr

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7767 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-10-31 09:58:24 +00:00
commit 39f173c12a
3 changed files with 338 additions and 202 deletions

View file

@ -46,6 +46,10 @@
* Pointer declarations * Pointer declarations
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
/* Flags for new pointer objects */
#define SWIG_POINTER_NEW SWIG_POINTER_OWN << 1
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#if 0 #if 0
@ -59,38 +63,12 @@ extern "C" {
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD
void *ptr; void *ptr;
const char *desc; swig_type_info *ty;
int own;
} PySwigObject; } PySwigObject;
SWIGRUNTIME int
PySwigObject_print(PySwigObject *v, FILE *fp, int flags)
{
char result[SWIG_BUFFER_SIZE];
flags = flags;
if (SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result))) {
fputs("<Swig Object at ", fp); fputs(result, fp); fputs(">", fp);
return 0;
} else {
return 1;
}
}
SWIGRUNTIME PyObject *
PySwigObject_repr(PySwigObject *v)
{
char result[SWIG_BUFFER_SIZE];
return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ?
PyString_FromFormat("<Swig Object at %s>", result) : 0;
}
SWIGRUNTIME PyObject *
PySwigObject_str(PySwigObject *v)
{
char result[SWIG_BUFFER_SIZE];
return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ?
PyString_FromString(result) : 0;
}
SWIGRUNTIME PyObject * SWIGRUNTIME PyObject *
PySwigObject_long(PySwigObject *v) PySwigObject_long(PySwigObject *v)
@ -126,29 +104,103 @@ PySwigObject_hex(PySwigObject *v)
return PySwigObject_format("%x",v); return PySwigObject_format("%x",v);
} }
SWIGRUNTIME int SWIGRUNTIME PyObject *
PySwigObject_compare(PySwigObject *v, PySwigObject *w) PySwigObject_repr(PySwigObject *v)
{ {
int c = strcmp(v->desc, w->desc); const char *name = SWIG_TypePrettyName(v->ty);
if (c) { PyObject *hex = PySwigObject_hex(v);
return (c > 0) ? 1 : -1; if (name) {
return PyString_FromFormat("<Swig Object of type '%s' at 0x%s>", name, PyString_AsString(hex));
} else { } else {
void *i = v->ptr; return PyString_FromFormat("<Swig Object at 0x%s>", PyString_AsString(hex));
void *j = w->ptr; }
return (i < j) ? -1 : ((i > j) ? 1 : 0); Py_DECREF(hex);
}
SWIGRUNTIME int
PySwigObject_print(PySwigObject *v, FILE *fp, int SWIGUNUSED flags)
{
PyObject *repr = PySwigObject_repr(v);
if (repr) {
fputs(PyString_AsString(repr), fp);
Py_DECREF(repr);
return 0;
} else {
return 1;
} }
} }
SWIGRUNTIME void
PySwigObject_dealloc(PySwigObject *self) SWIGRUNTIME PyObject *
PySwigObject_str(PySwigObject *v)
{ {
PyObject_Del(self); char result[SWIG_BUFFER_SIZE];
return SWIG_PackVoidPtr(result, v->ptr, v->ty->name, sizeof(result)) ?
PyString_FromString(result) : 0;
}
SWIGRUNTIME int
PySwigObject_compare(PySwigObject *v, PySwigObject *w)
{
void *i = v->ptr;
void *j = w->ptr;
return (i < j) ? -1 : ((i > j) ? 1 : 0);
}
SWIGRUNTIME PyTypeObject* PySwigObject_type(void);
SWIGRUNTIME int
PySwigObject_Check(PyObject *op) {
return ((op)->ob_type == PySwigObject_type())
|| (strcmp((op)->ob_type->tp_name,"PySwigObject") == 0);
}
SWIGRUNTIME void
PySwigObject_dealloc(PyObject *v)
{
if (PySwigObject_Check(v)) {
PySwigObject *self = (PySwigObject *) v;
if (self->own) {
}
}
v->ob_type->tp_free(v);
}
SWIGINTERN PyObject*
PySwigObject_disown(PySwigObject *self)
{
self->own = 0;
Py_INCREF(Py_None);
return Py_None;
}
SWIGINTERN PyObject*
PySwigObject_acquire(PySwigObject *self)
{
self->own = 1;
Py_INCREF(Py_None);
return Py_None;
}
SWIGINTERN PyObject*
PySwigObject_own(PySwigObject *self)
{
PyObject *obj = self->own ? Py_True : Py_False;
Py_INCREF(obj);
return obj;
} }
SWIGRUNTIME PyTypeObject* SWIGRUNTIME PyTypeObject*
PySwigObject_type(void) { PySwigObject_type(void) {
static char pyswigobject_type__doc__[] = static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer";
"Swig object carries a C/C++ instance pointer"; static PyMethodDef
swigobject_methods[] = {
{"disown", (PyCFunction)PySwigObject_disown, METH_NOARGS, "release ownership of the pointer"},
{"acquire", (PyCFunction)PySwigObject_acquire, METH_NOARGS, "aquire ownership of the pointer"},
{"own", (PyCFunction)PySwigObject_own, METH_NOARGS, "return ownership status of the pointer"},
{0, 0, 0, 0}
};
static PyNumberMethods PySwigObject_as_number = { static PyNumberMethods PySwigObject_as_number = {
(binaryfunc)0, /*nb_add*/ (binaryfunc)0, /*nb_add*/
@ -190,26 +242,27 @@ PySwigObject_type(void) {
#endif #endif
= { = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/ 0, /* ob_size */
(char *)"PySwigObject", /*tp_name*/ (char *)"PySwigObject", /* tp_name */
sizeof(PySwigObject), /*tp_basicsize*/ sizeof(PySwigObject), /* tp_basicsize */
0, /*tp_itemsize*/ 0, /* tp_itemsize */
/* methods */ (destructor)PySwigObject_dealloc, /* tp_dealloc */
(destructor)PySwigObject_dealloc, /*tp_dealloc*/ (printfunc)PySwigObject_print, /* tp_print */
(printfunc)PySwigObject_print, /*tp_print*/ (getattrfunc)0, /* tp_getattr */
(getattrfunc)0, /*tp_getattr*/ (setattrfunc)0, /* tp_setattr */
(setattrfunc)0, /*tp_setattr*/ (cmpfunc)PySwigObject_compare, /* tp_compare */
(cmpfunc)PySwigObject_compare, /*tp_compare*/ (reprfunc)PySwigObject_repr, /* tp_repr */
(reprfunc)PySwigObject_repr, /*tp_repr*/ &PySwigObject_as_number, /* tp_as_number */
&PySwigObject_as_number, /*tp_as_number*/ 0, /* tp_as_sequence */
0, /*tp_as_sequence*/ 0, /* tp_as_mapping */
0, /*tp_as_mapping*/ (hashfunc)0, /* tp_hash */
(hashfunc)0, /*tp_hash*/ (ternaryfunc)0, /* tp_call */
(ternaryfunc)0, /*tp_call*/ (reprfunc)PySwigObject_str, /* tp_str */
(reprfunc)PySwigObject_str, /*tp_str*/ PyObject_GenericGetAttr, /* tp_getattro */
/* Space for future expansion */ 0, /* tp_setattro */
0,0,0,0, 0, /* tp_as_buffer */
pyswigobject_type__doc__, /* Documentation string */ Py_TPFLAGS_DEFAULT, /* tp_flags */
swigobject_doc, /* tp_doc */
#if PY_VERSION_HEX >= 0x02000000 #if PY_VERSION_HEX >= 0x02000000
0, /* tp_traverse */ 0, /* tp_traverse */
0, /* tp_clear */ 0, /* tp_clear */
@ -219,8 +272,27 @@ PySwigObject_type(void) {
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
#endif #endif
#if PY_VERSION_HEX >= 0x02020000 #if PY_VERSION_HEX >= 0x02020000
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ 0, /* tp_iter */
0, /* tp_iternext */
#endif #endif
swigobject_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
PyObject_Del, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_mro */
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
#if PY_VERSION_HEX >= 0x02030000 #if PY_VERSION_HEX >= 0x02030000
0, /* tp_del */ 0, /* tp_del */
#endif #endif
@ -236,35 +308,19 @@ PySwigObject_type(void) {
return &pyswigobject_type; return &pyswigobject_type;
} }
SWIGRUNTIME PyObject * SWIGRUNTIME PyObject *
PySwigObject_FromVoidPtrAndDesc(void *ptr, const char *desc) PySwigObject_New(void *ptr, swig_type_info *ty, int own)
{ {
PySwigObject *self = PyObject_NEW(PySwigObject, PySwigObject_type()); PySwigObject *self = PyObject_NEW(PySwigObject, PySwigObject_type());
if (self) { if (self) {
self->ptr = ptr; self->ptr = ptr;
self->desc = desc; self->ty = ty;
self->own = own;
} }
return (PyObject *)self; return (PyObject *)self;
} }
SWIGRUNTIMEINLINE void *
PySwigObject_AsVoidPtr(PyObject *self)
{
return ((PySwigObject *)self)->ptr;
}
SWIGRUNTIMEINLINE const char *
PySwigObject_GetDesc(PyObject *self)
{
return ((PySwigObject *)self)->desc;
}
SWIGRUNTIMEINLINE int
PySwigObject_Check(PyObject *op) {
return ((op)->ob_type == PySwigObject_type())
|| (strcmp((op)->ob_type->tp_name,"PySwigObject") == 0);
}
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Implements a simple Swig Packed type, and use it instead of string * Implements a simple Swig Packed type, and use it instead of string
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -272,7 +328,7 @@ PySwigObject_Check(PyObject *op) {
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD
void *pack; void *pack;
const char *desc; swig_type_info *ty;
size_t size; size_t size;
} PySwigPacked; } PySwigPacked;
@ -286,7 +342,7 @@ PySwigPacked_print(PySwigPacked *v, FILE *fp, int flags)
fputs("at ", fp); fputs("at ", fp);
fputs(result, fp); fputs(result, fp);
} }
fputs(v->desc,fp); fputs(v->ty->name,fp);
fputs(">", fp); fputs(">", fp);
return 0; return 0;
} }
@ -296,9 +352,9 @@ PySwigPacked_repr(PySwigPacked *v)
{ {
char result[SWIG_BUFFER_SIZE]; char result[SWIG_BUFFER_SIZE];
if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) {
return PyString_FromFormat("<Swig Packed at %s%s>", result, v->desc); return PyString_FromFormat("<Swig Packed at %s%s>", result, v->ty->name);
} else { } else {
return PyString_FromFormat("<Swig Packed %s>", v->desc); return PyString_FromFormat("<Swig Packed %s>", v->ty->name);
} }
} }
@ -307,37 +363,42 @@ PySwigPacked_str(PySwigPacked *v)
{ {
char result[SWIG_BUFFER_SIZE]; char result[SWIG_BUFFER_SIZE];
if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){
return PyString_FromFormat("%s%s", result, v->desc); return PyString_FromFormat("%s%s", result, v->ty->name);
} else { } else {
return PyString_FromString(v->desc); return PyString_FromString(v->ty->name);
} }
} }
SWIGRUNTIME int SWIGRUNTIME int
PySwigPacked_compare(PySwigPacked *v, PySwigPacked *w) PySwigPacked_compare(PySwigPacked *v, PySwigPacked *w)
{ {
int c = strcmp(v->desc, w->desc); size_t i = v->size;
if (c) { size_t j = w->size;
return (c > 0) ? 1 : -1; int s = (i < j) ? -1 : ((i > j) ? 1 : 0);
} else { return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size);
size_t i = v->size; }
size_t j = w->size;
int s = (i < j) ? -1 : ((i > j) ? 1 : 0); SWIGRUNTIME PyTypeObject* PySwigPacked_type(void);
return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size);
} SWIGRUNTIME int
PySwigPacked_Check(PyObject *op) {
return ((op)->ob_type == PySwigPacked_type())
|| (strcmp((op)->ob_type->tp_name,"PySwigPacked") == 0);
} }
SWIGRUNTIME void SWIGRUNTIME void
PySwigPacked_dealloc(PySwigPacked *self) PySwigPacked_dealloc(PyObject *v)
{ {
free(self->pack); if (PySwigPacked_Check(v)) {
PyObject_Del(self); PySwigPacked *self = (PySwigPacked *) v;
free(self->pack);
}
v->ob_type->tp_free(v);
} }
SWIGRUNTIME PyTypeObject* SWIGRUNTIME PyTypeObject*
PySwigPacked_type(void) { PySwigPacked_type(void) {
static char pyswigpacked_type__doc__[] = static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer";
"Swig object carries a C/C++ instance pointer";
static PyTypeObject pyswigpacked_type static PyTypeObject pyswigpacked_type
#if !defined(__cplusplus) #if !defined(__cplusplus)
; ;
@ -347,26 +408,27 @@ PySwigPacked_type(void) {
#endif #endif
= { = {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/ 0, /* ob_size */
(char *)"PySwigPacked", /*tp_name*/ (char *)"PySwigPacked", /* tp_name */
sizeof(PySwigPacked), /*tp_basicsize*/ sizeof(PySwigPacked), /* tp_basicsize */
0, /*tp_itemsize*/ 0, /* tp_itemsize */
/* methods */ (destructor)PySwigPacked_dealloc, /* tp_dealloc */
(destructor)PySwigPacked_dealloc, /*tp_dealloc*/ (printfunc)PySwigPacked_print, /* tp_print */
(printfunc)PySwigPacked_print, /*tp_print*/ (getattrfunc)0, /* tp_getattr */
(getattrfunc)0, /*tp_getattr*/ (setattrfunc)0, /* tp_setattr */
(setattrfunc)0, /*tp_setattr*/ (cmpfunc)PySwigPacked_compare, /* tp_compare */
(cmpfunc)PySwigPacked_compare, /*tp_compare*/ (reprfunc)PySwigPacked_repr, /* tp_repr */
(reprfunc)PySwigPacked_repr, /*tp_repr*/ 0, /* tp_as_number */
0, /*tp_as_number*/ 0, /* tp_as_sequence */
0, /*tp_as_sequence*/ 0, /* tp_as_mapping */
0, /*tp_as_mapping*/ (hashfunc)0, /* tp_hash */
(hashfunc)0, /*tp_hash*/ (ternaryfunc)0, /* tp_call */
(ternaryfunc)0, /*tp_call*/ (reprfunc)PySwigPacked_str, /* tp_str */
(reprfunc)PySwigPacked_str, /*tp_str*/ PyObject_GenericGetAttr, /* tp_getattro */
/* Space for future expansion */ 0, /* tp_setattro */
0,0,0,0, 0, /* tp_as_buffer */
pyswigpacked_type__doc__, /* Documentation string */ Py_TPFLAGS_DEFAULT, /* tp_flags */
swigpacked_doc, /* tp_doc */
#if PY_VERSION_HEX >= 0x02000000 #if PY_VERSION_HEX >= 0x02000000
0, /* tp_traverse */ 0, /* tp_traverse */
0, /* tp_clear */ 0, /* tp_clear */
@ -375,9 +437,28 @@ PySwigPacked_type(void) {
0, /* tp_richcompare */ 0, /* tp_richcompare */
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
#endif #endif
#if PY_VERSION_HEX >= 0x02020000 #if PY_VERSION_HEX >= 0x02020000
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ 0, /* tp_iter */
0, /* tp_iternext */
#endif #endif
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
PyObject_Del, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_mro */
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
#if PY_VERSION_HEX >= 0x02030000 #if PY_VERSION_HEX >= 0x02030000
0, /* tp_del */ 0, /* tp_del */
#endif #endif
@ -394,7 +475,7 @@ PySwigPacked_type(void) {
} }
SWIGRUNTIME PyObject * SWIGRUNTIME PyObject *
PySwigPacked_FromDataAndDesc(void *ptr, size_t size, const char *desc) PySwigPacked_New(void *ptr, size_t size, swig_type_info *ty)
{ {
PySwigPacked *self = PyObject_NEW(PySwigPacked, PySwigPacked_type()); PySwigPacked *self = PyObject_NEW(PySwigPacked, PySwigPacked_type());
if (self == NULL) { if (self == NULL) {
@ -404,7 +485,7 @@ PySwigPacked_FromDataAndDesc(void *ptr, size_t size, const char *desc)
if (pack) { if (pack) {
memcpy(pack, ptr, size); memcpy(pack, ptr, size);
self->pack = pack; self->pack = pack;
self->desc = desc; self->ty = ty;
self->size = size; self->size = size;
return (PyObject *) self; return (PyObject *) self;
} }
@ -412,41 +493,38 @@ PySwigPacked_FromDataAndDesc(void *ptr, size_t size, const char *desc)
} }
} }
SWIGRUNTIMEINLINE const char * SWIGRUNTIMEINLINE swig_type_info *
PySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size) PySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size)
{ {
PySwigPacked *self = (PySwigPacked *)obj; if (PySwigPacked_Check(obj)) {
if (self->size != size) return 0; PySwigPacked *self = (PySwigPacked *)obj;
memcpy(ptr, self->pack, size); if (self->size != size) return 0;
return self->desc; memcpy(ptr, self->pack, size);
return self->ty;
} else {
return 0;
}
} }
SWIGRUNTIMEINLINE const char *
PySwigPacked_GetDesc(PyObject *self)
{
return ((PySwigPacked *)self)->desc;
}
SWIGRUNTIMEINLINE int
PySwigPacked_Check(PyObject *op) {
return ((op)->ob_type == PySwigPacked_type())
|| (strcmp((op)->ob_type->tp_name,"PySwigPacked") == 0);
}
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* pointers/data manipulation * pointers/data manipulation
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
/* Convert a pointer value */ /* Convert a pointer value */
SWIGRUNTIME int SWIGRUNTIME int
SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) { SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {
swig_cast_info *tc; swig_type_info *to = 0;
const char *c = 0; const char *desc = 0;
static PyObject *SWIG_this = 0;
int newref = 0; int newref = 0;
PyObject *pyobj = 0; PyObject *pyobj = 0;
void *vptr; void *vptr = 0;
PySwigObject *sobj = 0;
static PyObject *SWIG_this =
#if !defined(__cplusplus)
0; if (!SWIG_this) SWIG_this =
#endif
PyString_FromString("this");
if (!obj) return SWIG_ERROR; if (!obj) return SWIG_ERROR;
if (obj == Py_None) { if (obj == Py_None) {
@ -454,33 +532,37 @@ SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags)
return SWIG_OK; return SWIG_OK;
} }
if (!(PySwigObject_Check(obj))) { if (!(PySwigObject_Check(obj))) {
if (!SWIG_this)
SWIG_this = PyString_FromString("this");
pyobj = obj; pyobj = obj;
obj = PyObject_GetAttr(obj,SWIG_this); obj = PyObject_GetAttr(obj,SWIG_this);
newref = 1;
if (!obj) goto type_error; if (!obj) goto type_error;
if (!PySwigObject_Check(obj)) { if (!PySwigObject_Check(obj)) {
Py_DECREF(obj); Py_DECREF(obj);
goto type_error; goto type_error;
} }
newref = 1;
} }
vptr = PySwigObject_AsVoidPtr(obj); sobj = (PySwigObject *) obj;
c = (const char *) PySwigObject_GetDesc(obj); vptr = sobj->ptr;
if (newref) { Py_DECREF(obj); } to = sobj->ty;
goto type_check; desc = (const char *) to->name;
if (newref) { newref = 0; Py_DECREF(obj); }
type_check: type_check:
if (ty) { if (ty) {
tc = SWIG_TypeCheck(c,ty); if (to == ty) {
if (!tc) goto type_error; /* no type cast needed */
*ptr = SWIG_TypeCast(tc,vptr); *ptr = vptr;
} else {
swig_cast_info *tc = SWIG_TypeCheck(desc,ty);
if (!tc) goto type_error;
*ptr = SWIG_TypeCast(tc,vptr);
}
} else { } else {
*ptr = vptr; *ptr = vptr;
} }
if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) { if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) {
PyObject_SetAttrString(pyobj,(char*)"thisown",Py_False); sobj->own = 0;
} }
return SWIG_OK; return SWIG_OK;
@ -491,10 +573,10 @@ SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags)
if (PyCFunction_Check(obj)) { if (PyCFunction_Check(obj)) {
/* here we get the method pointer for callbacks */ /* here we get the method pointer for callbacks */
char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);
c = doc ? strstr(doc, "swig_ptr: ") : 0; desc = doc ? strstr(doc, "swig_ptr: ") : 0;
if (c) { if (desc) {
c = ty ? SWIG_UnpackVoidPtr(c + 10, &vptr, ty->name) : 0; desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0;
if (!c) goto type_error; if (!desc) goto type_error;
goto type_check; goto type_check;
} }
} }
@ -505,19 +587,18 @@ SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags)
/* Convert a packed value value */ /* Convert a packed value value */
SWIGRUNTIME int SWIGRUNTIME int
SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) { SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) {
swig_cast_info *tc; swig_type_info *to = PySwigPacked_UnpackData(obj, ptr, sz);
const char *c = 0; if (!to) goto type_error;
c = PySwigPacked_UnpackData(obj, ptr, sz);
if (!c) goto type_error;
if (ty) { if (ty) {
tc = SWIG_TypeCheck(c,ty); if (to != ty) {
if (!tc) goto type_error; /* check type cast? */
swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
if (!tc) goto type_error;
}
} }
return SWIG_OK; return SWIG_OK;
type_error: type_error:
PyErr_Clear();
return SWIG_ERROR; return SWIG_ERROR;
} }
@ -528,7 +609,7 @@ SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *t
SWIGRUNTIME PyObject * SWIGRUNTIME PyObject *
SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
PyObject *robj = 0; PyObject *robj = 0;
int own = flags & SWIG_POINTER_OWN; int own = (flags & SWIG_POINTER_OWN) || (flags & SWIG_POINTER_NEW);
if (!type) { if (!type) {
if (!PyErr_Occurred()) { if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, "Swig: null type passed to NewPointerObj"); PyErr_SetString(PyExc_TypeError, "Swig: null type passed to NewPointerObj");
@ -539,18 +620,17 @@ SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
robj = PySwigObject_FromVoidPtrAndDesc((void *) ptr, (char *)type->name); robj = PySwigObject_New((void *) ptr, type, own);
if (!robj || (robj == Py_None)) return robj; if (!robj || (robj == Py_None)) return robj;
if (type->clientdata) { /* direct new call doesn't create a shadow */
if (!(flags & SWIG_POINTER_NEW) && type->clientdata) {
PyObject *inst; PyObject *inst;
PyObject *args = Py_BuildValue((char*)"(O)", robj); PyObject *args = PyDict_New();
PyDict_SetItemString(args, "_swig_this", robj);
Py_DECREF(robj); Py_DECREF(robj);
inst = PyObject_CallObject((PyObject *) type->clientdata, args); inst = PyEval_CallObjectWithKeywords((PyObject *) type->clientdata, NULL, args);
Py_DECREF(args); Py_DECREF(args);
if (inst) { if (inst) {
if (own) {
PyObject_SetAttrString(inst,(char*)"thisown",Py_True);
}
robj = inst; robj = inst;
} }
} }
@ -567,7 +647,7 @@ SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
return Py_None; return Py_None;
} }
robj = PySwigPacked_FromDataAndDesc((void *) ptr, sz, (char *)type->name); robj = PySwigPacked_New((void *) ptr, sz, type);
return robj; return robj;
} }

View file

@ -2269,10 +2269,17 @@ Language::constructorHandler(Node *n) {
Swig_require("constructorHandler",n,"?name","*sym:name","?type","?parms",NIL); Swig_require("constructorHandler",n,"?name","*sym:name","?type","?parms",NIL);
String *symname = Getattr(n,"sym:name"); String *symname = Getattr(n,"sym:name");
String *mrename = Swig_name_construct(symname); String *mrename = Swig_name_construct(symname);
String *nodeType = Getattr(n, "nodeType");
int constructor = (!Cmp(nodeType, "constructor"));
List *abstract = 0; List *abstract = 0;
String *director_ctor = get_director_ctor_code(n, director_ctor_code, String *director_ctor = get_director_ctor_code(n, director_ctor_code,
director_prot_ctor_code, director_prot_ctor_code,
abstract); abstract);
if (!constructor) {
/* if not originally a constructor, still handle it as one */
Setattr(n,"handled_as_constructor","1");
}
Swig_ConstructorToFunction(n, ClassType, none_comparison, director_ctor, Swig_ConstructorToFunction(n, ClassType, none_comparison, director_ctor,
CPlusPlus, Getattr(n, "template") ? 0 :Extend); CPlusPlus, Getattr(n, "template") ? 0 :Extend);
Setattr(n,"sym:name", mrename); Setattr(n,"sym:name", mrename);

View file

@ -351,12 +351,18 @@ public:
tab4, "if (name == \"this\"):\n", tab4, "if (name == \"this\"):\n",
tab4, tab4, "if isinstance(value, class_type):\n", tab4, tab4, "if isinstance(value, class_type):\n",
tab4, tab8, "self.__dict__[name] = value.this\n", tab4, tab8, "self.__dict__[name] = value.this\n",
#ifdef USE_THISOWN
tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n", tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n",
tab4, tab8, "del value.thisown\n", tab4, tab8, "del value.thisown\n",
#endif
tab4, tab8, "return\n", tab4, tab8, "return\n",
tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", tab4, "method = class_type.__swig_setmethods__.get(name,None)\n",
tab4, "if method: return method(self,value)\n", tab4, "if method: return method(self,value)\n",
#ifdef USE_THISOWN
tab4, "if (not static) or hasattr(self,name) or (name == \"thisown\"):\n", tab4, "if (not static) or hasattr(self,name) or (name == \"thisown\"):\n",
#else
tab4, "if (not static) or hasattr(self,name):\n",
#endif
tab4, tab4, "self.__dict__[name] = value\n", tab4, tab4, "self.__dict__[name] = value\n",
tab4, "else:\n", tab4, "else:\n",
tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n", tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n",
@ -389,7 +395,11 @@ public:
Printv(f_shadow, Printv(f_shadow,
"def _swig_setattr_nondynamic_method(set):\n", "def _swig_setattr_nondynamic_method(set):\n",
tab4, "def set_attr(self,name,value):\n", tab4, "def set_attr(self,name,value):\n",
#ifdef USE_THISOWN
tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n", tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n",
#else
tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n",
#endif
tab4, tab4, tab4, "set(self,name,value)\n", tab4, tab4, tab4, "set(self,name,value)\n",
tab4, tab4, "else:\n", tab4, tab4, "else:\n",
tab4, tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n", tab4, tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n",
@ -523,14 +533,19 @@ public:
* to use keyword args or not. * to use keyword args or not.
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
String *funcCallHelper(String *name, int kw) { String *funcCallHelper(String *name, int kw, const char* self = 0) {
String *str; String *str;
str = NewString(""); str = NewString("");
if (apply) { if (apply) {
Printv(str, "apply(", module, ".", name, ", args", (kw ? ", kwargs" : ""), ")", NIL); Printv(str, "apply(", module, ".", name, ", args", (kw ? ", kwargs" : ""), ")", NIL);
} else { } else {
Printv(str, module, ".", name, "(*args", (kw ? ", **kwargs" : ""), ")", NIL); if (self) {
Printv(str, module, ".", name, "(", self, ", *args", (kw ? ", **kwargs" : ""), ")", NIL);
} else {
Printv(str, module, ".", name, "(*args", (kw ? ", **kwargs" : ""), ")", NIL);
}
} }
return str; return str;
} }
@ -784,7 +799,7 @@ public:
Printf(pdocs, " %s\n", pdoc); Printf(pdocs, " %s\n", pdoc);
} }
} else { } else {
Printf(doc, "??"); Printf(doc, "?");
} }
if (value) { if (value) {
@ -1454,12 +1469,15 @@ public:
Replaceall(tm,"$source", "result"); Replaceall(tm,"$source", "result");
Replaceall(tm,"$target", "resultobj"); Replaceall(tm,"$target", "resultobj");
Replaceall(tm,"$result", "resultobj"); Replaceall(tm,"$result", "resultobj");
if (GetFlag(n,"feature:new")) { if (constructor || Getattr(n,"handled_as_constructor")) {
Replaceall(tm,"$owner","SWIG_POINTER_OWN"); Replaceall(tm,"$owner","SWIG_POINTER_NEW");
} else { } else {
Replaceall(tm,"$owner","0"); if (GetFlag(n,"feature:new")) {
Replaceall(tm,"$owner","SWIG_POINTER_OWN");
} else {
Replaceall(tm,"$owner","0");
}
} }
// FIXME: this will not try to unwrap directors returned as non-director // FIXME: this will not try to unwrap directors returned as non-director
// base class pointers! // base class pointers!
@ -1922,7 +1940,11 @@ public:
String *symname = Getattr(n,"sym:name"); String *symname = Getattr(n,"sym:name");
String *mrename = Swig_name_disown(symname); //Getattr(n, "name")); String *mrename = Swig_name_disown(symname); //Getattr(n, "name"));
Printv(f_shadow, tab4, "def __disown__(self):\n", NIL); Printv(f_shadow, tab4, "def __disown__(self):\n", NIL);
#ifdef USE_THISOWN
Printv(f_shadow, tab8, "self.thisown = 0\n", NIL); Printv(f_shadow, tab8, "self.thisown = 0\n", NIL);
#else
Printv(f_shadow, tab8, "self.this.disown()\n", NIL);
#endif
Printv(f_shadow, tab8, module, ".", mrename,"(self)\n", NIL); Printv(f_shadow, tab8, module, ".", mrename,"(self)\n", NIL);
Printv(f_shadow, tab8, "return weakref_proxy(self)\n", NIL); Printv(f_shadow, tab8, "return weakref_proxy(self)\n", NIL);
Delete(mrename); Delete(mrename);
@ -2107,7 +2129,16 @@ public:
Delete(ct); Delete(ct);
} }
if (!have_constructor) { if (!have_constructor) {
Printv(f_shadow_file,tab4,"def __init__(self): raise RuntimeError, \"No constructor defined\"\n",NIL); String *rclassname = Swig_class_name(getCurrentClass());
Printv(f_shadow_file, tab4,"def __init__(self, **kwargs):\n",NIL);
Printv(f_shadow_file, tab8, "try: this = kwargs[\"_swig_this\"]\n", NIL);
Printv(f_shadow_file, tab8, "except: this = None\n", NIL);
Printv(f_shadow_file, tab8, "if this == None: raise RuntimeError, \"No constructor defined\"\n", NIL);
if (!modern) {
Printv(f_shadow_file, tab8, "_swig_setattr(self, ", rclassname, ", 'this', this )\n", NIL);
} else {
Printv(f_shadow_file, tab8, "self.this = this\n", NIL);
}
} }
if (!have_repr) { if (!have_repr) {
@ -2116,13 +2147,13 @@ public:
if (new_repr) { if (new_repr) {
Printv(f_shadow_file, Printv(f_shadow_file,
tab4, "def __repr__(self):\n", tab4, "def __repr__(self):\n",
tab8, "return \"<%s.%s; proxy of ", CPlusPlus ? "C++ " : "C ", rname," instance at %s>\" % (self.__class__.__module__, self.__class__.__name__, self.this,)\n", tab8, "return \"<%s.%s; proxy of ", CPlusPlus ? "C++ " : "C ", rname," instance at 0x%x>\" % (self.__class__.__module__, self.__class__.__name__, self.this,)\n",
NIL); NIL);
} }
else { else {
Printv(f_shadow_file, Printv(f_shadow_file,
tab4, "def __repr__(self):\n", tab4, "def __repr__(self):\n",
tab8, "return \"<C ", rname," instance at %s>\" % (self.this,)\n", tab8, "return \"<C ", rname," instance at 0x%x>\" % (self.this,)\n",
NIL); NIL);
} }
Delete(rname); Delete(rname);
@ -2133,24 +2164,30 @@ public:
Printv(f_shadow_file, f_shadow, NIL); Printv(f_shadow_file, f_shadow, NIL);
/* Now the Ptr class */ /* Now the Ptr class */
#if 0
Printv(f_shadow_file, Printv(f_shadow_file,
"\nclass ", class_name, "Ptr(", class_name, "):\n", "\nclass ", class_name, "Ptr(", class_name, "):\n",
tab4, "def __init__(self, this):\n", NIL); tab4, "def __init__(self, this):\n", NIL);
if (!modern) { if (!modern) {
Printv(f_shadow_file, Printv(f_shadow_file,
tab8, "_swig_setattr(self, ", class_name, ", 'this', this)\n", tab8, "_swig_setattr(self, ", class_name, ", 'this', this)\n",
#ifdef USE_THISOWN
tab8, "if not hasattr(self,\"thisown\"): _swig_setattr(self, ", class_name, ", 'thisown', 0)\n", tab8, "if not hasattr(self,\"thisown\"): _swig_setattr(self, ", class_name, ", 'thisown', 0)\n",
#endif
tab8, "self.__class__ = ", class_name, "\n", NIL); tab8, "self.__class__ = ", class_name, "\n", NIL);
} else { } else {
Printv(f_shadow_file, Printv(f_shadow_file,
tab8, "self.this = this\n", tab8, "self.this = this\n",
#ifdef USE_THISOWN
tab8, "if not hasattr(self,\"thisown\"): self.thisown = 0\n", tab8, "if not hasattr(self,\"thisown\"): self.thisown = 0\n",
#endif
tab8, "self.__class__ = ", class_name, "\n", NIL); tab8, "self.__class__ = ", class_name, "\n", NIL);
// tab8,"try: self.this = this.this; self.thisown = getattr(this,'thisown',0); this.thisown=0\n", // tab8,"try: self.this = this.this; self.thisown = getattr(this,'thisown',0); this.thisown=0\n",
// tab8,"except AttributeError: self.this = this\n" // tab8,"except AttributeError: self.this = this\n"
} }
#endif
Printf(f_shadow_file,"%s.%s_swigregister(%sPtr)\n", module, class_name, class_name,0); Printf(f_shadow_file,"%s.%s_swigregister(%s)\n", module, class_name, class_name,0);
shadow_indent = 0; shadow_indent = 0;
Printf(f_shadow_file,"%s\n", f_shadow_stubs); Printf(f_shadow_file,"%s\n", f_shadow_stubs);
Clear(f_shadow_stubs); Clear(f_shadow_stubs);
@ -2336,7 +2373,7 @@ public:
String *classname = Swig_class_name(parent); String *classname = Swig_class_name(parent);
String *rclassname = Swig_class_name(getCurrentClass()); String *rclassname = Swig_class_name(getCurrentClass());
assert(rclassname); assert(rclassname);
if (use_director) { if (use_director) {
Printv(pass_self, tab8, NIL); Printv(pass_self, tab8, NIL);
Printf(pass_self, "if self.__class__ == %s:\n", classname); Printf(pass_self, "if self.__class__ == %s:\n", classname);
Printv(pass_self, tab8, tab4, "args = (None,) + args\n", Printv(pass_self, tab8, tab4, "args = (None,) + args\n",
@ -2345,25 +2382,28 @@ public:
NIL); NIL);
} }
Printv(f_shadow, tab4, "def __init__(self, *args", Printv(f_shadow, tab4, "def __init__(self, *args, **kwargs):\n", NIL);
(allow_kwargs ? ", **kwargs" : ""), "):\n", NIL);
if ( have_docstring(n) ) if ( have_docstring(n) )
Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL); Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL);
if ( have_pythonprepend(n) ) if ( have_pythonprepend(n) )
Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL);
Printv(f_shadow, pass_self, NIL); Printv(f_shadow, pass_self, NIL);
Printv(f_shadow, tab8, "try: this = kwargs[\"_swig_this\"]\n", NIL);
Printv(f_shadow, tab8, "except: this = None\n", NIL);
Printv(f_shadow, tab8, "if this == None: this = ", funcCallHelper(Swig_name_construct(symname), allow_kwargs),"\n", NIL);
if (!modern) { if (!modern) {
Printv(f_shadow, tab8, "_swig_setattr(self, ", rclassname, ", 'this', ", Printv(f_shadow, tab8, "_swig_setattr(self, ", rclassname, ", 'this', this )\n", NIL);
funcCallHelper(Swig_name_construct(symname), allow_kwargs), ")\n", NIL);
Printv(f_shadow, Printv(f_shadow,
#ifdef USE_THISOWN
tab8, "_swig_setattr(self, ", rclassname, ", 'thisown', 1)\n", tab8, "_swig_setattr(self, ", rclassname, ", 'thisown', 1)\n",
#endif
NIL); NIL);
} else { } else {
Printv(f_shadow, tab8, "newobj = ", Printv(f_shadow, tab8, "self.this = this\n", NIL);
funcCallHelper(Swig_name_construct(symname), allow_kwargs), "\n", NIL); #ifdef USE_THISOWN
Printv(f_shadow, tab8, "self.this = newobj.this\n", NIL);
Printv(f_shadow, tab8, "self.thisown = 1\n", NIL); Printv(f_shadow, tab8, "self.thisown = 1\n", NIL);
Printv(f_shadow, tab8, "del newobj.thisown\n", NIL); Printv(f_shadow, tab8, "del newobj.thisown\n", NIL);
#endif
} }
if ( have_pythonappend(n) ) if ( have_pythonappend(n) )
Printv(f_shadow, tab8, pythonappend(n), "\n\n", NIL); Printv(f_shadow, tab8, pythonappend(n), "\n\n", NIL);
@ -2390,7 +2430,9 @@ public:
Printv(f_shadow_stubs, tab4, pythonprepend(n), "\n", NIL); Printv(f_shadow_stubs, tab4, pythonprepend(n), "\n", NIL);
Printv(f_shadow_stubs, tab4, "val = ", Printv(f_shadow_stubs, tab4, "val = ",
funcCallHelper(Swig_name_construct(symname), allow_kwargs), "\n", NIL); funcCallHelper(Swig_name_construct(symname), allow_kwargs), "\n", NIL);
#ifdef USE_THISOWN
Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL); Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL);
#endif
if ( have_pythonappend(n) ) if ( have_pythonappend(n) )
Printv(f_shadow_stubs, tab4, pythonappend(n), "\n", NIL); Printv(f_shadow_stubs, tab4, pythonappend(n), "\n", NIL);
Printv(f_shadow_stubs, tab4, "return val\n", NIL); Printv(f_shadow_stubs, tab4, "return val\n", NIL);
@ -2410,6 +2452,7 @@ public:
int oldshadow = shadow; int oldshadow = shadow;
if (shadow) shadow = shadow | PYSHADOW_MEMBER; if (shadow) shadow = shadow | PYSHADOW_MEMBER;
//Setattr(n,"emit:dealloc","1");
Language::destructorHandler(n); Language::destructorHandler(n);
shadow = oldshadow; shadow = oldshadow;
if (shadow) { if (shadow) {
@ -2425,9 +2468,15 @@ public:
Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL); Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL);
if ( have_pythonprepend(n) ) if ( have_pythonprepend(n) )
Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL); Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL);
#ifdef USE_THISOWN
Printv(f_shadow, tab8, "try:\n", NIL); Printv(f_shadow, tab8, "try:\n", NIL);
Printv(f_shadow, tab8, tab4, "if self.thisown: destroy(self)\n", NIL); Printv(f_shadow, tab8, tab4, "if self.thisown: destroy(self)\n", NIL);
Printv(f_shadow, tab8, "except: pass\n", NIL); Printv(f_shadow, tab8, "except: pass\n", NIL);
#else
Printv(f_shadow, tab8, "try:\n", NIL);
Printv(f_shadow, tab8, tab4, "if self.this.own(): destroy(self.this)\n", NIL);
Printv(f_shadow, tab8, "except: pass\n", NIL);
#endif
if ( have_pythonappend(n) ) if ( have_pythonappend(n) )
Printv(f_shadow, tab8, pythonappend(n), "\n", NIL); Printv(f_shadow, tab8, pythonappend(n), "\n", NIL);
Printv(f_shadow, "\n", NIL); Printv(f_shadow, "\n", NIL);