First cut. Works for wrapping OpenAccess, but there's plenty
left to do. Currently, the test suite hurls at director_stl. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12332 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
25a1f9844b
commit
ee3a6623da
8 changed files with 1520 additions and 1040 deletions
28
Lib/python/builtin.swg
Normal file
28
Lib/python/builtin.swg
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
template <typename _Tp> struct PySwigBuiltin : public SwigPyObject {
|
||||||
|
|
||||||
|
typedef PySwigBuiltin<_Tp> this_type;
|
||||||
|
typedef _Tp obj_type;
|
||||||
|
typedef obj_type* pointer;
|
||||||
|
typedef obj_type& reference;
|
||||||
|
|
||||||
|
static PyMethodDef methods[];
|
||||||
|
static PyTypeObject pytype;
|
||||||
|
static SwigPyClientData clientdata;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename _Tp> void py_builtin_dealloc (PyObject *pyobj)
|
||||||
|
{
|
||||||
|
typedef PySwigBuiltin<_Tp> builtin_type;
|
||||||
|
builtin_type *obj = (builtin_type*) pyobj;
|
||||||
|
if (obj->own)
|
||||||
|
delete reinterpret_cast<_Tp*>(obj->ptr);
|
||||||
|
(*pyobj->ob_type->tp_free)(pyobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace {
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -580,6 +580,9 @@ 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) {
|
||||||
|
|
@ -588,6 +591,8 @@ namespace swig
|
||||||
|
|
||||||
%pythoncode {def __iter__(self): return self.iterator()}
|
%pythoncode {def __iter__(self): return self.iterator()}
|
||||||
}
|
}
|
||||||
|
# endif // SWIGPYTHON_BUILTIN
|
||||||
|
|
||||||
#endif //SWIG_EXPORT_ITERATOR_METHODS
|
#endif //SWIG_EXPORT_ITERATOR_METHODS
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -320,7 +320,8 @@ SWIGEXPORT
|
||||||
void
|
void
|
||||||
#endif
|
#endif
|
||||||
SWIG_init(void) {
|
SWIG_init(void) {
|
||||||
PyObject *m, *d;
|
PyObject *m, *d, *md;
|
||||||
|
PyTypeObject *builtin_type;
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
#if PY_VERSION_HEX >= 0x03000000
|
||||||
static struct PyModuleDef SWIG_module = {
|
static struct PyModuleDef SWIG_module = {
|
||||||
PyModuleDef_HEAD_INIT,
|
PyModuleDef_HEAD_INIT,
|
||||||
|
|
@ -335,6 +336,13 @@ SWIG_init(void) {
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(SWIGPYTHON_BUILTIN)
|
||||||
|
PyTypeObject *builtin_pytype = 0;
|
||||||
|
swig_type_info *builtin_basetype = 0;
|
||||||
|
|
||||||
|
SWIG_Python_builtin_imports();
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Fix SwigMethods to carry the callback ptrs when needed */
|
/* Fix SwigMethods to carry the callback ptrs when needed */
|
||||||
SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial);
|
SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial);
|
||||||
|
|
||||||
|
|
@ -343,7 +351,7 @@ SWIG_init(void) {
|
||||||
#else
|
#else
|
||||||
m = Py_InitModule((char *) SWIG_name, SwigMethods);
|
m = Py_InitModule((char *) SWIG_name, SwigMethods);
|
||||||
#endif
|
#endif
|
||||||
d = PyModule_GetDict(m);
|
md = d = PyModule_GetDict(m);
|
||||||
|
|
||||||
SWIG_InitializeModule(0);
|
SWIG_InitializeModule(0);
|
||||||
SWIG_InstallConstants(d,swig_const_table);
|
SWIG_InstallConstants(d,swig_const_table);
|
||||||
|
|
|
||||||
|
|
@ -302,6 +302,24 @@ namespace swig {
|
||||||
{
|
{
|
||||||
return new SwigPyIteratorOpen_T<OutIter>(current, seq);
|
return new SwigPyIteratorOpen_T<OutIter>(current, seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Sequence>
|
||||||
|
inline PyObject* make_output_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_iterator(seq->begin(), seq->begin(), seq->end(), pyself);
|
||||||
|
return SWIG_NewPointerObj(iter, SWIGTYPE_p_swig__SwigPyIterator, SWIG_POINTER_OWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline PyObject* make_output_iterator_builtin<SwigPyIterator> (PyObject *pyself)
|
||||||
|
{
|
||||||
|
Py_INCREF(pyself);
|
||||||
|
return pyself;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -329,9 +347,14 @@ namespace swig
|
||||||
%newobject SwigPyIterator::operator - (ptrdiff_t n) const;
|
%newobject SwigPyIterator::operator - (ptrdiff_t n) const;
|
||||||
|
|
||||||
%nodirector SwigPyIterator;
|
%nodirector SwigPyIterator;
|
||||||
|
|
||||||
|
#if defined(SWIGPYTHON_BUILTIN)
|
||||||
|
%feature("tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin<swig::SwigPyIterator>";
|
||||||
|
#else
|
||||||
%extend SwigPyIterator {
|
%extend SwigPyIterator {
|
||||||
%pythoncode {def __iter__(self): return self}
|
%pythoncode {def __iter__(self): return self}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
%catches(swig::stop_iteration) SwigPyIterator::value() const;
|
%catches(swig::stop_iteration) SwigPyIterator::value() const;
|
||||||
%catches(swig::stop_iteration) SwigPyIterator::incr(size_t n = 1);
|
%catches(swig::stop_iteration) SwigPyIterator::incr(size_t n = 1);
|
||||||
|
|
|
||||||
|
|
@ -244,6 +244,7 @@ typedef struct {
|
||||||
PyObject *destroy;
|
PyObject *destroy;
|
||||||
int delargs;
|
int delargs;
|
||||||
int implicitconv;
|
int implicitconv;
|
||||||
|
PyTypeObject *pytype;
|
||||||
} SwigPyClientData;
|
} SwigPyClientData;
|
||||||
|
|
||||||
SWIGRUNTIMEINLINE int
|
SWIGRUNTIMEINLINE int
|
||||||
|
|
@ -310,6 +311,7 @@ SwigPyClientData_New(PyObject* obj)
|
||||||
data->delargs = 0;
|
data->delargs = 0;
|
||||||
}
|
}
|
||||||
data->implicitconv = 0;
|
data->implicitconv = 0;
|
||||||
|
data->pytype = 0;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1064,91 +1066,101 @@ SWIG_Python_AcquirePtr(PyObject *obj, int own) {
|
||||||
|
|
||||||
SWIGRUNTIME int
|
SWIGRUNTIME int
|
||||||
SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) {
|
SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) {
|
||||||
if (!obj) return SWIG_ERROR;
|
if (!obj) return SWIG_ERROR;
|
||||||
if (obj == Py_None) {
|
if (obj == Py_None) {
|
||||||
if (ptr) *ptr = 0;
|
if (ptr) *ptr = 0;
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
} else {
|
}
|
||||||
|
if (ty && ty->clientdata && ((SwigPyClientData*) ty->clientdata)->pytype) {
|
||||||
|
PyTypeObject *target_tp = ((SwigPyClientData*) ty->clientdata)->pytype;
|
||||||
|
PyTypeObject *obj_tp;
|
||||||
|
for (obj_tp = obj->ob_type; obj_tp; obj_tp = obj_tp->tp_base) {
|
||||||
|
if (obj_tp == target_tp) {
|
||||||
|
if (ptr)
|
||||||
|
*ptr = ((SwigPyObject*) obj)->ptr;
|
||||||
|
return SWIG_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj);
|
SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj);
|
||||||
if (own)
|
if (own)
|
||||||
*own = 0;
|
*own = 0;
|
||||||
while (sobj) {
|
while (sobj) {
|
||||||
void *vptr = sobj->ptr;
|
void *vptr = sobj->ptr;
|
||||||
if (ty) {
|
if (ty) {
|
||||||
swig_type_info *to = sobj->ty;
|
swig_type_info *to = sobj->ty;
|
||||||
if (to == ty) {
|
if (to == ty) {
|
||||||
/* no type cast needed */
|
/* no type cast needed */
|
||||||
if (ptr) *ptr = vptr;
|
if (ptr) *ptr = vptr;
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
|
||||||
|
if (!tc) {
|
||||||
|
sobj = (SwigPyObject *)sobj->next;
|
||||||
|
} else {
|
||||||
|
if (ptr) {
|
||||||
|
int newmemory = 0;
|
||||||
|
*ptr = SWIG_TypeCast(tc,vptr,&newmemory);
|
||||||
|
if (newmemory == SWIG_CAST_NEW_MEMORY) {
|
||||||
|
assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
|
||||||
|
if (own)
|
||||||
|
*own = *own | SWIG_CAST_NEW_MEMORY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
|
if (ptr) *ptr = vptr;
|
||||||
if (!tc) {
|
|
||||||
sobj = (SwigPyObject *)sobj->next;
|
|
||||||
} else {
|
|
||||||
if (ptr) {
|
|
||||||
int newmemory = 0;
|
|
||||||
*ptr = SWIG_TypeCast(tc,vptr,&newmemory);
|
|
||||||
if (newmemory == SWIG_CAST_NEW_MEMORY) {
|
|
||||||
assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
|
|
||||||
if (own)
|
|
||||||
*own = *own | SWIG_CAST_NEW_MEMORY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (ptr) *ptr = vptr;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (sobj) {
|
if (sobj) {
|
||||||
if (own)
|
if (own)
|
||||||
*own = *own | sobj->own;
|
*own = *own | sobj->own;
|
||||||
if (flags & SWIG_POINTER_DISOWN) {
|
if (flags & SWIG_POINTER_DISOWN) {
|
||||||
sobj->own = 0;
|
sobj->own = 0;
|
||||||
}
|
|
||||||
return SWIG_OK;
|
|
||||||
} else {
|
|
||||||
int res = SWIG_ERROR;
|
|
||||||
if (flags & SWIG_POINTER_IMPLICIT_CONV) {
|
|
||||||
SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0;
|
|
||||||
if (data && !data->implicitconv) {
|
|
||||||
PyObject *klass = data->klass;
|
|
||||||
if (klass) {
|
|
||||||
PyObject *impconv;
|
|
||||||
data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/
|
|
||||||
impconv = SWIG_Python_CallFunctor(klass, obj);
|
|
||||||
data->implicitconv = 0;
|
|
||||||
if (PyErr_Occurred()) {
|
|
||||||
PyErr_Clear();
|
|
||||||
impconv = 0;
|
|
||||||
}
|
|
||||||
if (impconv) {
|
|
||||||
SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv);
|
|
||||||
if (iobj) {
|
|
||||||
void *vptr;
|
|
||||||
res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0);
|
|
||||||
if (SWIG_IsOK(res)) {
|
|
||||||
if (ptr) {
|
|
||||||
*ptr = vptr;
|
|
||||||
/* transfer the ownership to 'ptr' */
|
|
||||||
iobj->own = 0;
|
|
||||||
res = SWIG_AddCast(res);
|
|
||||||
res = SWIG_AddNewMask(res);
|
|
||||||
} else {
|
|
||||||
res = SWIG_AddCast(res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Py_DECREF(impconv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
return SWIG_OK;
|
||||||
return res;
|
} else {
|
||||||
|
int res = SWIG_ERROR;
|
||||||
|
if (flags & SWIG_POINTER_IMPLICIT_CONV) {
|
||||||
|
SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0;
|
||||||
|
if (data && !data->implicitconv) {
|
||||||
|
PyObject *klass = data->klass;
|
||||||
|
if (klass) {
|
||||||
|
PyObject *impconv;
|
||||||
|
data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/
|
||||||
|
impconv = SWIG_Python_CallFunctor(klass, obj);
|
||||||
|
data->implicitconv = 0;
|
||||||
|
if (PyErr_Occurred()) {
|
||||||
|
PyErr_Clear();
|
||||||
|
impconv = 0;
|
||||||
|
}
|
||||||
|
if (impconv) {
|
||||||
|
SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv);
|
||||||
|
if (iobj) {
|
||||||
|
void *vptr;
|
||||||
|
res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0);
|
||||||
|
if (SWIG_IsOK(res)) {
|
||||||
|
if (ptr) {
|
||||||
|
*ptr = vptr;
|
||||||
|
/* transfer the ownership to 'ptr' */
|
||||||
|
iobj->own = 0;
|
||||||
|
res = SWIG_AddCast(res);
|
||||||
|
res = SWIG_AddNewMask(res);
|
||||||
|
} else {
|
||||||
|
res = SWIG_AddCast(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Py_DECREF(impconv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert a function ptr value */
|
/* Convert a function ptr value */
|
||||||
|
|
@ -1319,21 +1331,32 @@ SWIG_Python_InitShadowInstance(PyObject *args) {
|
||||||
|
|
||||||
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) {
|
||||||
if (!ptr) {
|
if (!ptr)
|
||||||
return SWIG_Py_Void();
|
return SWIG_Py_Void();
|
||||||
} else {
|
|
||||||
int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
|
|
||||||
PyObject *robj = SwigPyObject_New(ptr, type, own);
|
|
||||||
SwigPyClientData *clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0;
|
SwigPyClientData *clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0;
|
||||||
|
int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
|
||||||
|
if (clientdata && clientdata->pytype) {
|
||||||
|
SwigPyObject *newobj = PyObject_New(SwigPyObject, clientdata->pytype);
|
||||||
|
if (newobj) {
|
||||||
|
newobj->ptr = ptr;
|
||||||
|
newobj->ty = type;
|
||||||
|
newobj->own = own;
|
||||||
|
newobj->next = 0;
|
||||||
|
return (PyObject*) newobj;
|
||||||
|
}
|
||||||
|
return SWIG_Py_Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *robj = SwigPyObject_New(ptr, type, own);
|
||||||
if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) {
|
if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) {
|
||||||
PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj);
|
PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj);
|
||||||
if (inst) {
|
if (inst) {
|
||||||
Py_DECREF(robj);
|
Py_DECREF(robj);
|
||||||
robj = inst;
|
robj = inst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return robj;
|
return robj;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a new packed object */
|
/* Create a new packed object */
|
||||||
|
|
@ -1343,6 +1366,19 @@ SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
|
||||||
return ptr ? SwigPyPacked_New((void *) ptr, sz, type) : SWIG_Py_Void();
|
return ptr ? SwigPyPacked_New((void *) ptr, sz, type) : SWIG_Py_Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SWIGRUNTIME int
|
||||||
|
SWIG_Python_NewBuiltinObj(PyObject *self, void *ptr, swig_type_info *type, int flags) {
|
||||||
|
assert(self);
|
||||||
|
SwigPyClientData *clientdata = (SwigPyClientData *)(type->clientdata);
|
||||||
|
assert(clientdata);
|
||||||
|
assert(clientdata->pytype);
|
||||||
|
int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
|
||||||
|
SwigPyObject *newobj = (SwigPyObject*) self;
|
||||||
|
newobj->ptr = ptr;
|
||||||
|
newobj->own = own;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------*
|
/* -----------------------------------------------------------------------------*
|
||||||
* Get type list
|
* Get type list
|
||||||
* -----------------------------------------------------------------------------*/
|
* -----------------------------------------------------------------------------*/
|
||||||
|
|
|
||||||
|
|
@ -11,3 +11,4 @@
|
||||||
%insert(runtime) "pyapi.swg"; /* Python API */
|
%insert(runtime) "pyapi.swg"; /* Python API */
|
||||||
%insert(runtime) "pyrun.swg"; /* Python run-time code */
|
%insert(runtime) "pyrun.swg"; /* Python run-time code */
|
||||||
|
|
||||||
|
%insert(runtime) "builtin.swg"; /* Specialization for classes with single inheritance */
|
||||||
|
|
|
||||||
|
|
@ -96,3 +96,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------
|
||||||
|
* Output typemap for the __init__ method of a built-in type.
|
||||||
|
* ------------------------------------------------------------ */
|
||||||
|
|
||||||
|
/* Pointers, references */
|
||||||
|
%typemap(builtin_init,noblock=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE[] {
|
||||||
|
%set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr($1), $descriptor, $owner | %newpointer_flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(builtin_init, noblock=1) SWIGTYPE *const& {
|
||||||
|
%set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(*$1), $*descriptor, $owner | %newpointer_flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return by value */
|
||||||
|
%typemap(builtin_init, noblock=1) SWIGTYPE {
|
||||||
|
%set_output(SWIG_Python_NewBuiltinObj(self, %new_copy($1, $ltype), $&descriptor, SWIG_POINTER_OWN | %newpointer_flags));
|
||||||
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue