1 /* ------------------------------------------------------------ 2 * The start of the Python initialization function 3 * ------------------------------------------------------------ */ 4 5 %insert(init) "swiginit.swg" 6 7 %init %{ 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /* Python-specific SWIG API */ 14 #define SWIG_newvarlink() SWIG_Python_newvarlink() 15 #define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) 16 #define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) 17 18 /* ----------------------------------------------------------------------------- 19 * global variable support code. 20 * ----------------------------------------------------------------------------- */ 21 22 typedef struct swig_globalvar { 23 char *name; /* Name of global variable */ 24 PyObject *(*get_attr)(void); /* Return the current value */ 25 int (*set_attr)(PyObject *); /* Set the value */ 26 struct swig_globalvar *next; 27 } swig_globalvar; 28 29 typedef struct swig_varlinkobject { 30 PyObject_HEAD 31 swig_globalvar *vars; 32 } swig_varlinkobject; 33 34 SWIGINTERN PyObject * 35 swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { 36 #if PY_VERSION_HEX >= 0x03000000 37 return PyUnicode_InternFromString("<Swig global variables>"); 38 #else 39 return PyString_FromString("<Swig global variables>"); 40 #endif 41 } 42 43 SWIGINTERN PyObject * 44 swig_varlink_str(swig_varlinkobject *v) { 45 #if PY_VERSION_HEX >= 0x03000000 46 PyObject *str = PyUnicode_InternFromString("("); 47 PyObject *tail; 48 PyObject *joined; 49 swig_globalvar *var; 50 for (var = v->vars; var; var=var->next) { 51 tail = PyUnicode_FromString(var->name); 52 joined = PyUnicode_Concat(str, tail); 53 Py_DecRef(str); 54 Py_DecRef(tail); 55 str = joined; 56 if (var->next) { 57 tail = PyUnicode_InternFromString(", "); 58 joined = PyUnicode_Concat(str, tail); 59 Py_DecRef(str); 60 Py_DecRef(tail); 61 str = joined; 62 } 63 } 64 tail = PyUnicode_InternFromString(")"); 65 joined = PyUnicode_Concat(str, tail); 66 Py_DecRef(str); 67 Py_DecRef(tail); 68 str = joined; 69 #else 70 PyObject *str = PyString_FromString("("); 71 swig_globalvar *var; 72 for (var = v->vars; var; var=var->next) { 73 PyString_ConcatAndDel(&str,PyString_FromString(var->name)); 74 if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); 75 } 76 PyString_ConcatAndDel(&str,PyString_FromString(")")); 77 #endif 78 return str; 79 } 80 81 SWIGINTERN int 82 swig_varlink_print(swig_varlinkobject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) { 83 char *tmp; 84 PyObject *str = swig_varlink_str(v); 85 fprintf(fp,"Swig global variables "); 86 fprintf(fp,"%s\n", tmp = SWIG_Python_str_AsChar(str)); 87 SWIG_Python_str_DelForPy3(tmp); 88 Py_DECREF(str); 89 return 0; 90 } 91 92 SWIGINTERN void 93 swig_varlink_dealloc(swig_varlinkobject *v) { 94 swig_globalvar *var = v->vars; 95 while (var) { 96 swig_globalvar *n = var->next; 97 free(var->name); 98 free(var); 99 var = n; 100 } 101 } 102 103 SWIGINTERN PyObject * 104 swig_varlink_getattr(swig_varlinkobject *v, char *n) { 105 PyObject *res = NULL; 106 swig_globalvar *var = v->vars; 107 while (var) { 108 if (strcmp(var->name,n) == 0) { 109 res = (*var->get_attr)(); 110 break; 111 } 112 var = var->next; 113 } 114 if (res == NULL && !PyErr_Occurred()) { 115 PyErr_SetString(PyExc_NameError,"Unknown C global variable"); 116 } 117 return res; 118 } 119 120 SWIGINTERN int 121 swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { 122 int res = 1; 123 swig_globalvar *var = v->vars; 124 while (var) { 125 if (strcmp(var->name,n) == 0) { 126 res = (*var->set_attr)(p); 127 break; 128 } 129 var = var->next; 130 } 131 if (res == 1 && !PyErr_Occurred()) { 132 PyErr_SetString(PyExc_NameError,"Unknown C global variable"); 133 } 134 return res; 135 } 136 137 SWIGINTERN PyTypeObject* 138 swig_varlink_type(void) { 139 static char varlink__doc__[] = "Swig var link object"; 140 static PyTypeObject varlink_type; 141 static int type_init = 0; 142 if (!type_init) { 143 const PyTypeObject tmp = { 144 /* PyObject header changed in Python 3 */ 145 #if PY_VERSION_HEX >= 0x03000000 146 PyVarObject_HEAD_INIT(NULL, 0) 147 #else 148 PyObject_HEAD_INIT(NULL) 149 0, /* ob_size */ 150 #endif 151 (char *)"swigvarlink", /* tp_name */ 152 sizeof(swig_varlinkobject), /* tp_basicsize */ 153 0, /* tp_itemsize */ 154 (destructor) swig_varlink_dealloc, /* tp_dealloc */ 155 (printfunc) swig_varlink_print, /* tp_print */ 156 (getattrfunc) swig_varlink_getattr, /* tp_getattr */ 157 (setattrfunc) swig_varlink_setattr, /* tp_setattr */ 158 0, /* tp_compare */ 159 (reprfunc) swig_varlink_repr, /* tp_repr */ 160 0, /* tp_as_number */ 161 0, /* tp_as_sequence */ 162 0, /* tp_as_mapping */ 163 0, /* tp_hash */ 164 0, /* tp_call */ 165 (reprfunc) swig_varlink_str, /* tp_str */ 166 0, /* tp_getattro */ 167 0, /* tp_setattro */ 168 0, /* tp_as_buffer */ 169 0, /* tp_flags */ 170 varlink__doc__, /* tp_doc */ 171 0, /* tp_traverse */ 172 0, /* tp_clear */ 173 0, /* tp_richcompare */ 174 0, /* tp_weaklistoffset */ 175 #if PY_VERSION_HEX >= 0x02020000 176 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ 177 #endif 178 #if PY_VERSION_HEX >= 0x02030000 179 0, /* tp_del */ 180 #endif 181 #if PY_VERSION_HEX >= 0x02060000 182 0, /* tp_version */ 183 #endif 184 #ifdef COUNT_ALLOCS 185 0,0,0,0 /* tp_alloc -> tp_next */ 186 #endif 187 }; 188 varlink_type = tmp; 189 type_init = 1; 190 #if PY_VERSION_HEX < 0x02020000 191 varlink_type.ob_type = &PyType_Type; 192 #else 193 if (PyType_Ready(&varlink_type) < 0) 194 return NULL; 195 #endif 196 } 197 return &varlink_type; 198 } 199 200 /* Create a variable linking object for use later */ 201 SWIGINTERN PyObject * 202 SWIG_Python_newvarlink(void) { 203 swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); 204 if (result) { 205 result->vars = 0; 206 } 207 return ((PyObject*) result); 208 } 209 210 SWIGINTERN void 211 SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { 212 swig_varlinkobject *v = (swig_varlinkobject *) p; 213 swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); 214 if (gv) { 215 size_t size = strlen(name)+1; 216 gv->name = (char *)malloc(size); 217 if (gv->name) { 218 strncpy(gv->name,name,size); 219 gv->get_attr = get_attr; 220 gv->set_attr = set_attr; 221 gv->next = v->vars; 222 } 223 } 224 v->vars = gv; 225 } 226 227 SWIGINTERN PyObject * 228 SWIG_globals(void) { 229 static PyObject *_SWIG_globals = 0; 230 if (!_SWIG_globals) _SWIG_globals = SWIG_newvarlink(); 231 return _SWIG_globals; 232 } 233 234 /* ----------------------------------------------------------------------------- 235 * constants/methods manipulation 236 * ----------------------------------------------------------------------------- */ 237 238 /* Install Constants */ 239 SWIGINTERN void 240 SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { 241 PyObject *obj = 0; 242 size_t i; 243 for (i = 0; constants[i].type; ++i) { 244 switch(constants[i].type) { 245 case SWIG_PY_POINTER: 246 obj = SWIG_InternalNewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); 247 break; 248 case SWIG_PY_BINARY: 249 obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); 250 break; 251 default: 252 obj = 0; 253 break; 254 } 255 if (obj) { 256 PyDict_SetItemString(d, constants[i].name, obj); 257 Py_DECREF(obj); 258 } 259 } 260 } 261 262 /* -----------------------------------------------------------------------------*/ 263 /* Fix SwigMethods to carry the callback ptrs when needed */ 264 /* -----------------------------------------------------------------------------*/ 265 266 SWIGINTERN void 267 SWIG_Python_FixMethods(PyMethodDef *methods, 268 swig_const_info *const_table, 269 swig_type_info **types, 270 swig_type_info **types_initial) { 271 size_t i; 272 for (i = 0; methods[i].ml_name; ++i) { 273 const char *c = methods[i].ml_doc; 274 if (c && (c = strstr(c, "swig_ptr: "))) { 275 int j; 276 swig_const_info *ci = 0; 277 const char *name = c + 10; 278 for (j = 0; const_table[j].type; ++j) { 279 if (strncmp(const_table[j].name, name, 280 strlen(const_table[j].name)) == 0) { 281 ci = &(const_table[j]); 282 break; 283 } 284 } 285 if (ci) { 286 void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; 287 if (ptr) { 288 size_t shift = (ci->ptype) - types; 289 swig_type_info *ty = types_initial[shift]; 290 size_t ldoc = (c - methods[i].ml_doc); 291 size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; 292 char *ndoc = (char*)malloc(ldoc + lptr + 10); 293 if (ndoc) { 294 char *buff = ndoc; 295 strncpy(buff, methods[i].ml_doc, ldoc); 296 buff += ldoc; 297 strncpy(buff, "swig_ptr: ", 10); 298 buff += 10; 299 SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); 300 methods[i].ml_doc = ndoc; 301 } 302 } 303 } 304 } 305 } 306 } 307 308 #ifdef __cplusplus 309 } 310 #endif 311 312 /* -----------------------------------------------------------------------------* 313 * Partial Init method 314 * -----------------------------------------------------------------------------*/ 315 316 #ifdef __cplusplus 317 extern "C" 318 #endif 319 320 SWIGEXPORT 321 #if PY_VERSION_HEX >= 0x03000000 322 PyObject* 323 #else 324 void 325 #endif 326 SWIG_init(void) { 327 PyObject *m, *d, *md; 328 #if PY_VERSION_HEX >= 0x03000000 329 static struct PyModuleDef SWIG_module = { 330 # if PY_VERSION_HEX >= 0x03020000 331 PyModuleDef_HEAD_INIT, 332 # else 333 { 334 PyObject_HEAD_INIT(NULL) 335 NULL, /* m_init */ 336 0, /* m_index */ 337 NULL, /* m_copy */ 338 }, 339 # endif 340 (char *) SWIG_name, 341 NULL, 342 -1, 343 SwigMethods, 344 NULL, 345 NULL, 346 NULL, 347 NULL 348 }; 349 #endif 350 351 #if defined(SWIGPYTHON_BUILTIN) 352 static SwigPyClientData SwigPyObject_clientdata = {0, 0, 0, 0, 0, 0, 0}; 353 static PyGetSetDef this_getset_def = { 354 (char *)"this", &SwigPyBuiltin_ThisClosure, NULL, NULL, NULL 355 }; 356 static SwigPyGetSet thisown_getset_closure = { 357 (PyCFunction) SwigPyObject_own, 358 (PyCFunction) SwigPyObject_own 359 }; 360 static PyGetSetDef thisown_getset_def = { 361 (char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure 362 }; 363 PyObject *metatype_args; 364 PyTypeObject *builtin_pytype; 365 int builtin_base_count; 366 swig_type_info *builtin_basetype; 367 PyObject *tuple; 368 PyGetSetDescrObject *static_getset; 369 PyTypeObject *metatype; 370 SwigPyClientData *cd; 371 PyObject *public_interface, *public_symbol; 372 PyObject *this_descr; 373 PyObject *thisown_descr; 374 int i; 375 376 (void)builtin_pytype; 377 (void)builtin_base_count; 378 (void)builtin_basetype; 379 (void)tuple; 380 (void)static_getset; 381 382 /* metatype is used to implement static member variables. */ 383 metatype_args = Py_BuildValue("(s(O){})", "SwigPyObjectType", &PyType_Type); 384 assert(metatype_args); 385 metatype = (PyTypeObject *) PyType_Type.tp_call((PyObject *) &PyType_Type, metatype_args, NULL); 386 assert(metatype); 387 Py_DECREF(metatype_args); 388 metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro; 389 assert(PyType_Ready(metatype) >= 0); 390 #endif 391 392 /* Fix SwigMethods to carry the callback ptrs when needed */ 393 SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); 394 395 #if PY_VERSION_HEX >= 0x03000000 396 m = PyModule_Create(&SWIG_module); 397 #else 398 m = Py_InitModule((char *) SWIG_name, SwigMethods); 399 #endif 400 md = d = PyModule_GetDict(m); 401 (void)md; 402 403 SWIG_InitializeModule(0); 404 405 #ifdef SWIGPYTHON_BUILTIN 406 SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject"); 407 assert(SwigPyObject_stype); 408 cd = (SwigPyClientData*) SwigPyObject_stype->clientdata; 409 if (!cd) { 410 SwigPyObject_stype->clientdata = &SwigPyObject_clientdata; 411 SwigPyObject_clientdata.pytype = SwigPyObject_TypeOnce(); 412 } else if (SwigPyObject_TypeOnce()->tp_basicsize != cd->pytype->tp_basicsize) { 413 PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules."); 414 # if PY_VERSION_HEX >= 0x03000000 415 return NULL; 416 # else 417 return; 418 # endif 419 } 420 421 /* All objects have a 'this' attribute */ 422 this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def); 423 (void)this_descr; 424 425 /* All objects have a 'thisown' attribute */ 426 thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def); 427 (void)thisown_descr; 428 429 public_interface = PyList_New(0); 430 public_symbol = 0; 431 (void)public_symbol; 432 433 PyDict_SetItemString(md, "__all__", public_interface); 434 Py_DECREF(public_interface); 435 for (i = 0; SwigMethods[i].ml_name != NULL; ++i) 436 SwigPyBuiltin_AddPublicSymbol(public_interface, SwigMethods[i].ml_name); 437 for (i = 0; swig_const_table[i].name != 0; ++i) 438 SwigPyBuiltin_AddPublicSymbol(public_interface, swig_const_table[i].name); 439 #endif 440 441 SWIG_InstallConstants(d,swig_const_table); 442 %} 443 444