git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6752 626c5289-ae23-0410-ae9c-e8d60b6d4f22
408 lines
11 KiB
Text
408 lines
11 KiB
Text
/***********************************************************************
|
|
* pyrun.swg
|
|
*
|
|
* This file contains the runtime support for Python modules
|
|
* and includes code for managing global variables and pointer
|
|
* type checking.
|
|
*
|
|
* Author : David Beazley (beazley@cs.uchicago.edu)
|
|
************************************************************************/
|
|
|
|
/* Common SWIG API */
|
|
#define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Python_ConvertPtr(obj, pp, type, flags)
|
|
#define SWIG_NewPointerObj(p, type, flags) SWIG_Python_NewPointerObj(p, type, flags)
|
|
#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags)
|
|
|
|
|
|
/* Python-specific SWIG API */
|
|
#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) SWIG_Python_ConvertPacked(obj, ptr, sz, ty, flags)
|
|
#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type)
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
* Pointer declarations
|
|
* ----------------------------------------------------------------------------- */
|
|
/*
|
|
Use SWIG_NO_COBJECT_TYPES to force the use of strings to represent
|
|
C/C++ pointers in the python side. Very useful for debugging, but
|
|
not always safe.
|
|
*/
|
|
#if !defined(SWIG_NO_COBJECT_TYPES) && !defined(SWIG_COBJECT_TYPES)
|
|
# define SWIG_COBJECT_TYPES
|
|
#endif
|
|
|
|
/* Flags for pointer conversion */
|
|
#define SWIG_POINTER_EXCEPTION 0x1
|
|
#define SWIG_POINTER_DISOWN 0x2
|
|
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
/* -----------------------------------------------------------------------------
|
|
* errors manipulation
|
|
* ----------------------------------------------------------------------------- */
|
|
|
|
SWIGRUNTIME void
|
|
SWIG_Python_TypeError(const char *type, PyObject *obj)
|
|
{
|
|
if (type) {
|
|
if (!PyCObject_Check(obj)) {
|
|
const char *otype = (obj ? obj->ob_type->tp_name : 0);
|
|
if (otype) {
|
|
PyObject *str = PyObject_Str(obj);
|
|
const char *cstr = str ? PyString_AsString(str) : 0;
|
|
if (cstr) {
|
|
PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received",
|
|
type, otype, cstr);
|
|
} else {
|
|
PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received",
|
|
type, otype);
|
|
}
|
|
Py_DECREF(str);
|
|
return;
|
|
}
|
|
} else {
|
|
const char *otype = (char *) PyCObject_GetDesc(obj);
|
|
if (otype) {
|
|
PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'PyCObject(%s)' is received",
|
|
type, otype);
|
|
return;
|
|
}
|
|
}
|
|
PyErr_Format(PyExc_TypeError, "a '%s' is expected", type);
|
|
|
|
} else {
|
|
PyErr_Format(PyExc_TypeError, "unexpected type is received");
|
|
}
|
|
}
|
|
|
|
SWIGRUNTIME void
|
|
SWIG_Python_NullRef(const char *type)
|
|
{
|
|
if (type) {
|
|
PyErr_Format(PyExc_TypeError, "null reference of type '%s' was received",type);
|
|
} else {
|
|
PyErr_Format(PyExc_TypeError, "null reference was received");
|
|
}
|
|
}
|
|
|
|
SWIGRUNTIME int
|
|
SWIG_Python_AddErrMesg(const char* mesg, int infront)
|
|
{
|
|
if (PyErr_Occurred()) {
|
|
PyObject *type = 0;
|
|
PyObject *value = 0;
|
|
PyObject *traceback = 0;
|
|
PyErr_Fetch(&type, &value, &traceback);
|
|
if (value) {
|
|
PyObject *old_str = PyObject_Str(value);
|
|
Py_XINCREF(type);
|
|
PyErr_Clear();
|
|
if (infront) {
|
|
PyErr_Format(type, "%s %s", mesg, PyString_AsString(old_str));
|
|
} else {
|
|
PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg);
|
|
}
|
|
Py_DECREF(old_str);
|
|
}
|
|
return 1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
SWIGRUNTIME int
|
|
SWIG_Python_ArgFail(int argnum)
|
|
{
|
|
if (PyErr_Occurred()) {
|
|
/* add information about failing argument */
|
|
char mesg[256];
|
|
sprintf(mesg, "argument number %d:", argnum);
|
|
return SWIG_Python_AddErrMesg(mesg, 1);
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
* pointers/data manipulation
|
|
* ----------------------------------------------------------------------------- */
|
|
|
|
/* Convert a pointer value */
|
|
SWIGRUNTIME int
|
|
SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {
|
|
swig_type_info *tc;
|
|
char *c = 0;
|
|
static PyObject *SWIG_this = 0;
|
|
int newref = 0;
|
|
PyObject *pyobj = 0;
|
|
void *vptr;
|
|
|
|
if (!obj) return 0;
|
|
if (obj == Py_None) {
|
|
*ptr = 0;
|
|
return 0;
|
|
}
|
|
|
|
#ifdef SWIG_COBJECT_TYPES
|
|
if (!(PyCObject_Check(obj))) {
|
|
if (!SWIG_this)
|
|
SWIG_this = PyString_FromString("this");
|
|
pyobj = obj;
|
|
obj = PyObject_GetAttr(obj,SWIG_this);
|
|
newref = 1;
|
|
if (!obj) goto type_error;
|
|
if (!PyCObject_Check(obj)) {
|
|
Py_DECREF(obj);
|
|
goto type_error;
|
|
}
|
|
}
|
|
vptr = PyCObject_AsVoidPtr(obj);
|
|
c = (char *) PyCObject_GetDesc(obj);
|
|
if (newref) Py_DECREF(obj);
|
|
goto type_check;
|
|
#else
|
|
if (!(PyString_Check(obj))) {
|
|
if (!SWIG_this)
|
|
SWIG_this = PyString_FromString("this");
|
|
pyobj = obj;
|
|
obj = PyObject_GetAttr(obj,SWIG_this);
|
|
newref = 1;
|
|
if (!obj) goto type_error;
|
|
if (!PyString_Check(obj)) {
|
|
Py_DECREF(obj);
|
|
goto type_error;
|
|
}
|
|
}
|
|
c = PyString_AS_STRING(obj);
|
|
/* Pointer values must start with leading underscore */
|
|
if (*c != '_') {
|
|
if (strcmp(c,"NULL") == 0) {
|
|
if (newref) { Py_DECREF(obj); }
|
|
*ptr = (void *) 0;
|
|
return 0;
|
|
} else {
|
|
if (newref) { Py_DECREF(obj); }
|
|
goto type_error;
|
|
}
|
|
}
|
|
c++;
|
|
c = SWIG_UnpackData(c,&vptr,sizeof(void *));
|
|
if (!c) goto type_error;
|
|
if (newref) { Py_DECREF(obj); }
|
|
#endif
|
|
|
|
type_check:
|
|
|
|
if (ty) {
|
|
tc = SWIG_TypeCheck(c,ty);
|
|
if (!tc) goto type_error;
|
|
*ptr = SWIG_TypeCast(tc,vptr);
|
|
}
|
|
|
|
if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) {
|
|
PyObject_SetAttrString(pyobj,(char*)"thisown",Py_False);
|
|
}
|
|
return 0;
|
|
|
|
type_error:
|
|
PyErr_Clear();
|
|
if (pyobj && !obj) {
|
|
obj = pyobj;
|
|
if (PyCFunction_Check(obj)) {
|
|
/* here we get the method pointer for callbacks */
|
|
char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);
|
|
c = doc ? strstr(doc, "swig_ptr: ") : 0;
|
|
if (c) {
|
|
c += 10;
|
|
if (*c == '_') {
|
|
c++;
|
|
c = SWIG_UnpackData(c,&vptr,sizeof(void *));
|
|
if (!c) goto type_error;
|
|
goto type_check;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (flags & SWIG_POINTER_EXCEPTION) {
|
|
if (ty) {
|
|
SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
|
|
} else {
|
|
SWIG_Python_TypeError("C/C++ pointer", obj);
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
/* Convert a pointer value, signal an exception on a type mismatch */
|
|
SWIGRUNTIME void *
|
|
SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) {
|
|
void *result;
|
|
if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) {
|
|
PyErr_Clear();
|
|
if (flags & SWIG_POINTER_EXCEPTION) {
|
|
SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
|
|
SWIG_Python_ArgFail(argnum);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/* Convert a packed value value */
|
|
SWIGRUNTIME int
|
|
SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty, int flags) {
|
|
swig_type_info *tc;
|
|
char *c = 0;
|
|
|
|
if ((!obj) || (!PyString_Check(obj))) goto type_error;
|
|
c = PyString_AS_STRING(obj);
|
|
/* Pointer values must start with leading underscore */
|
|
if (*c != '_') goto type_error;
|
|
c++;
|
|
c = SWIG_UnpackData(c,ptr,sz);
|
|
if (!c) goto type_error;
|
|
if (ty) {
|
|
tc = SWIG_TypeCheck(c,ty);
|
|
if (!tc) goto type_error;
|
|
}
|
|
return 0;
|
|
|
|
type_error:
|
|
PyErr_Clear();
|
|
if (flags & SWIG_POINTER_EXCEPTION) {
|
|
if (ty) {
|
|
SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
|
|
} else {
|
|
SWIG_Python_TypeError("C/C++ packed data", obj);
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
/* Create a new pointer string */
|
|
SWIGRUNTIME char *
|
|
SWIG_Python_PointerStr(char *buff, void *ptr, const char *name, size_t bsz) {
|
|
char *r = buff;
|
|
if ((2*sizeof(void *) + 2) > bsz) return 0;
|
|
*(r++) = '_';
|
|
r = SWIG_PackData(r,&ptr,sizeof(void *));
|
|
if (strlen(name) + 1 > (bsz - (r - buff))) return 0;
|
|
strcpy(r,name);
|
|
return buff;
|
|
}
|
|
|
|
|
|
/* Create a new pointer object */
|
|
SWIGRUNTIME PyObject *
|
|
SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) {
|
|
PyObject *robj;
|
|
if (!ptr) {
|
|
Py_INCREF(Py_None);
|
|
return Py_None;
|
|
}
|
|
#ifdef SWIG_COBJECT_TYPES
|
|
robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, (char *) type->name, NULL);
|
|
#else
|
|
{
|
|
char result[1024];
|
|
SWIG_Python_PointerStr(result, ptr, type->name, 1024);
|
|
robj = PyString_FromString(result);
|
|
}
|
|
#endif
|
|
if (!robj || (robj == Py_None)) return robj;
|
|
if (type->clientdata) {
|
|
PyObject *inst;
|
|
PyObject *args = Py_BuildValue((char*)"(O)", robj);
|
|
Py_DECREF(robj);
|
|
inst = PyObject_CallObject((PyObject *) type->clientdata, args);
|
|
Py_DECREF(args);
|
|
if (inst) {
|
|
if (own) {
|
|
PyObject_SetAttrString(inst,(char*)"thisown",Py_True);
|
|
}
|
|
robj = inst;
|
|
}
|
|
}
|
|
return robj;
|
|
}
|
|
|
|
SWIGRUNTIME PyObject *
|
|
SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
|
|
char result[1024];
|
|
char *r = result;
|
|
if ((2*sz + 2 + strlen(type->name)) > 1024) return 0;
|
|
*(r++) = '_';
|
|
r = SWIG_PackData(r,ptr,sz);
|
|
strcpy(r,type->name);
|
|
return PyString_FromString(result);
|
|
}
|
|
|
|
/* -----------------------------------------------------------------------------*
|
|
* Get type list
|
|
* -----------------------------------------------------------------------------*/
|
|
|
|
#ifdef SWIG_LINK_RUNTIME
|
|
void *SWIG_ReturnGlobalTypeList(void *);
|
|
#endif
|
|
|
|
SWIGRUNTIME swig_type_info **
|
|
SWIG_Python_GetTypeListHandle() {
|
|
static void *type_pointer = (void *)0;
|
|
/* first check if module already created */
|
|
if (!type_pointer) {
|
|
#ifdef SWIG_LINK_RUNTIME
|
|
type_pointer = SWIG_ReturnGlobalTypeList((void *)0);
|
|
#else
|
|
type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION,
|
|
(char*)"type_pointer" SWIG_TYPE_TABLE_NAME);
|
|
if (PyErr_Occurred()) {
|
|
PyErr_Clear();
|
|
type_pointer = (void *)0;
|
|
}
|
|
}
|
|
#endif
|
|
return (swig_type_info **) type_pointer;
|
|
}
|
|
|
|
/*
|
|
Search for a swig_type_info structure
|
|
*/
|
|
SWIGRUNTIME swig_type_info *
|
|
SWIG_Python_GetTypeList() {
|
|
swig_type_info **type_list_handle = SWIG_Python_GetTypeListHandle();
|
|
return type_list_handle ? *type_list_handle : (swig_type_info *)0;
|
|
}
|
|
|
|
/* -----------------------------------------------------------------------------*
|
|
* Standard SWIG API
|
|
* -----------------------------------------------------------------------------*/
|
|
|
|
SWIGRUNTIME swig_type_info *
|
|
SWIG_Python_TypeQuery(const char *name) {
|
|
swig_type_info *tl = SWIG_Python_GetTypeList();
|
|
return SWIG_TypeQueryTL(tl, name);
|
|
}
|
|
|
|
SWIGRUNTIME swig_type_info *
|
|
SWIG_Python_TypeRegister(swig_type_info *ti) {
|
|
swig_type_info **tlh = SWIG_Python_GetTypeListHandle();
|
|
return SWIG_TypeRegisterTL(tlh, ti);
|
|
}
|
|
|
|
SWIGRUNTIME void
|
|
SWIG_Python_TypeClientData(swig_type_info *ti, void *clientdata) {
|
|
swig_type_info *tl = SWIG_Python_GetTypeList();
|
|
SWIG_TypeClientDataTL(tl, ti, clientdata);
|
|
}
|
|
|
|
SWIGRUNTIME void
|
|
SWIG_Python_PropagateClientData(swig_type_info *type) {
|
|
swig_type_info *tl = SWIG_Python_GetTypeList();
|
|
SWIG_PropagateClientDataTL(tl, type);
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|