PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/python/builtin.swg

#
Unknown | 510 lines | 469 code | 41 blank | 0 comment | 0 complexity | 052748c074d59b198f28017446a19c1e MD5 | raw file
  1#define SWIGPY_UNARYFUNC_CLOSURE(wrapper)	\
  2SWIGINTERN PyObject *				\
  3wrapper##_closure(PyObject *a) {		\
  4  return wrapper(a, NULL);			\
  5}
  6
  7#define SWIGPY_DESTRUCTOR_CLOSURE(wrapper)	\
  8SWIGINTERN void					\
  9wrapper##_closure(PyObject *a) {		\
 10    SwigPyObject *sobj;				\
 11    sobj = (SwigPyObject *)a;			\
 12    if (sobj->own) {				\
 13	PyObject *o = wrapper(a, NULL);		\
 14	Py_XDECREF(o);				\
 15    }						\
 16    PyObject_Del(a);				\
 17}
 18
 19#define SWIGPY_INQUIRY_CLOSURE(wrapper)				\
 20SWIGINTERN int							\
 21wrapper##_closure(PyObject *a) {				\
 22    PyObject *pyresult;						\
 23    int result;							\
 24    pyresult = wrapper(a, NULL);				\
 25    result = pyresult && PyObject_IsTrue(pyresult) ? 1 : 0;	\
 26    Py_XDECREF(pyresult);					\
 27    return result;						\
 28}
 29
 30#define SWIGPY_BINARYFUNC_CLOSURE(wrapper)	\
 31SWIGINTERN PyObject *				\
 32wrapper##_closure(PyObject *a, PyObject *b) {	\
 33    PyObject *tuple, *result;			\
 34    tuple = PyTuple_New(1);			\
 35    assert(tuple);				\
 36    PyTuple_SET_ITEM(tuple, 0, b);		\
 37    Py_XINCREF(b);				\
 38    result = wrapper(a, tuple);			\
 39    Py_DECREF(tuple);				\
 40    return result;				\
 41}
 42
 43typedef ternaryfunc ternarycallfunc;
 44
 45#define SWIGPY_TERNARYFUNC_CLOSURE(wrapper)			\
 46SWIGINTERN PyObject *						\
 47wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) {	\
 48    PyObject *tuple, *result;					\
 49    tuple = PyTuple_New(2);					\
 50    assert(tuple);						\
 51    PyTuple_SET_ITEM(tuple, 0, b);				\
 52    PyTuple_SET_ITEM(tuple, 1, c);				\
 53    Py_XINCREF(b);						\
 54    Py_XINCREF(c);						\
 55    result = wrapper(a, tuple);					\
 56    Py_DECREF(tuple);						\
 57    return result;						\
 58}
 59
 60#define SWIGPY_TERNARYCALLFUNC_CLOSURE(wrapper)			\
 61SWIGINTERN PyObject *						\
 62wrapper##_closure(PyObject *callable_object, PyObject *args, PyObject *) {	\
 63    return wrapper(callable_object, args);			\
 64}
 65
 66#define SWIGPY_LENFUNC_CLOSURE(wrapper)			\
 67SWIGINTERN Py_ssize_t					\
 68wrapper##_closure(PyObject *a) {			\
 69    PyObject *resultobj;				\
 70    Py_ssize_t result;					\
 71    resultobj = wrapper(a, NULL);			\
 72    result = PyNumber_AsSsize_t(resultobj, NULL);	\
 73    Py_DECREF(resultobj);				\
 74    return result;					\
 75}
 76
 77#define SWIGPY_SSIZESSIZEARGFUNC_CLOSURE(wrapper)		\
 78SWIGINTERN PyObject *						\
 79wrapper##_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c) {	\
 80    PyObject *tuple, *result;					\
 81    tuple = PyTuple_New(2);					\
 82    assert(tuple);						\
 83    PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b));		\
 84    PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c));		\
 85    result = wrapper(a, tuple);					\
 86    Py_DECREF(tuple);						\
 87    return result;						\
 88}
 89
 90#define SWIGPY_SSIZESSIZEOBJARGPROC_CLOSURE(wrapper)			\
 91SWIGINTERN int								\
 92wrapper##_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) { \
 93    PyObject *tuple, *resultobj;					\
 94    int result;								\
 95    tuple = PyTuple_New(d ? 3 : 2);					\
 96    assert(tuple);							\
 97    PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b));			\
 98    PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c));			\
 99    if (d) {								\
100        PyTuple_SET_ITEM(tuple, 2, d);					\
101        Py_INCREF(d);							\
102    }									\
103    resultobj = wrapper(a, tuple);					\
104    result = resultobj ? 0 : -1;					\
105    Py_DECREF(tuple);							\
106    Py_XDECREF(resultobj);						\
107    return result;							\
108}
109
110#define SWIGPY_SSIZEARGFUNC_CLOSURE(wrapper)		\
111SWIGINTERN PyObject *					\
112wrapper##_closure(PyObject *a, Py_ssize_t b) {		\
113    PyObject *tuple, *result;				\
114    tuple = PyTuple_New(1);				\
115    assert(tuple);					\
116    PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b));	\
117    result = wrapper(a, tuple);				\
118    Py_DECREF(tuple);					\
119    return result;					\
120}
121
122#define SWIGPY_FUNPACK_SSIZEARGFUNC_CLOSURE(wrapper)		\
123SWIGINTERN PyObject *					\
124wrapper##_closure(PyObject *a, Py_ssize_t b) {		\
125    PyObject *arg, *result;				\
126    arg = _PyLong_FromSsize_t(b);			\
127    result = wrapper(a, arg);				\
128    Py_DECREF(arg);					\
129    return result;					\
130}
131
132#define SWIGPY_SSIZEOBJARGPROC_CLOSURE(wrapper)			\
133SWIGINTERN int							\
134wrapper##_closure(PyObject *a, Py_ssize_t b, PyObject *c) {	\
135    PyObject *tuple, *resultobj;				\
136    int result;							\
137    tuple = PyTuple_New(2);					\
138    assert(tuple);						\
139    PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b));		\
140    PyTuple_SET_ITEM(tuple, 1, c);				\
141    Py_XINCREF(c);						\
142    resultobj = wrapper(a, tuple);				\
143    result = resultobj ? 0 : -1;				\
144    Py_XDECREF(resultobj);					\
145    Py_DECREF(tuple);						\
146    return result;						\
147}
148
149#define SWIGPY_OBJOBJARGPROC_CLOSURE(wrapper)			\
150SWIGINTERN int							\
151wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) {	\
152    PyObject *tuple, *resultobj;				\
153    int result;							\
154    tuple = PyTuple_New(c ? 2 : 1);				\
155    assert(tuple);						\
156    PyTuple_SET_ITEM(tuple, 0, b);				\
157    Py_XINCREF(b);						\
158    if (c) {							\
159        PyTuple_SET_ITEM(tuple, 1, c);				\
160        Py_XINCREF(c);						\
161    }								\
162    resultobj = wrapper(a, tuple);				\
163    result = resultobj ? 0 : -1;				\
164    Py_XDECREF(resultobj);					\
165    Py_DECREF(tuple);						\
166    return result;						\
167}
168
169#define SWIGPY_REPRFUNC_CLOSURE(wrapper)	\
170SWIGINTERN PyObject *				\
171wrapper##_closure(PyObject *a) {		\
172    return wrapper(a, NULL);			\
173}
174
175#define SWIGPY_HASHFUNC_CLOSURE(wrapper)	\
176SWIGINTERN long					\
177wrapper##_closure(PyObject *a) {		\
178    PyObject *pyresult;				\
179    long result;				\
180    pyresult = wrapper(a, NULL);		\
181    if (!pyresult || !PyLong_Check(pyresult))	\
182	return -1;				\
183    result = PyLong_AsLong(pyresult);		\
184    Py_DECREF(pyresult);			\
185    return result;				\
186}
187
188#define SWIGPY_ITERNEXT_CLOSURE(wrapper)	\
189SWIGINTERN PyObject *				\
190wrapper##_closure(PyObject *a) {		\
191    PyObject *result;				\
192    result = wrapper(a, NULL);			\
193    if (result && result == Py_None) {		\
194	Py_DECREF(result);			\
195	result = NULL;				\
196    }						\
197    return result;				\
198}
199
200#ifdef __cplusplus
201extern "C" {
202#endif
203
204SWIGINTERN int
205SwigPyBuiltin_BadInit(PyObject *self, PyObject *SWIGUNUSEDPARM(args), PyObject *SWIGUNUSEDPARM(kwds)) {
206  PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name);
207  return -1;
208}
209
210SWIGINTERN void
211SwigPyBuiltin_BadDealloc(PyObject *pyobj) {
212  SwigPyObject *sobj;
213  sobj = (SwigPyObject *)pyobj;
214  if (sobj->own) {
215    PyErr_Format(PyExc_TypeError, "Swig detected a memory leak in type '%.300s': no callable destructor found.", pyobj->ob_type->tp_name);
216  }
217}
218
219typedef struct {
220  PyCFunction get;
221  PyCFunction set;
222} SwigPyGetSet;
223
224SWIGINTERN PyObject *
225SwigPyBuiltin_GetterClosure (PyObject *obj, void *closure) {
226  SwigPyGetSet *getset;
227  PyObject *tuple, *result;
228  if (!closure)
229    return SWIG_Py_Void();
230  getset = (SwigPyGetSet *)closure;
231  if (!getset->get)
232    return SWIG_Py_Void();
233  tuple = PyTuple_New(0);
234  assert(tuple);
235  result = (*getset->get)(obj, tuple);
236  Py_DECREF(tuple);
237  return result;
238}
239
240SWIGINTERN PyObject *
241SwigPyBuiltin_FunpackGetterClosure (PyObject *obj, void *closure) {
242  SwigPyGetSet *getset;
243  PyObject *result;
244  if (!closure)
245    return SWIG_Py_Void();
246  getset = (SwigPyGetSet *)closure;
247  if (!getset->get)
248    return SWIG_Py_Void();
249  result = (*getset->get)(obj, NULL);
250  return result;
251}
252
253SWIGINTERN int
254SwigPyBuiltin_SetterClosure (PyObject *obj, PyObject *val, void *closure) {
255  SwigPyGetSet *getset;
256  PyObject *tuple, *result;
257  if (!closure) {
258    PyErr_Format(PyExc_TypeError, "Missing getset closure");
259    return -1;
260  }
261  getset = (SwigPyGetSet *)closure;
262  if (!getset->set) {
263    PyErr_Format(PyExc_TypeError, "Illegal member variable assignment in type '%.300s'", obj->ob_type->tp_name);
264    return -1;
265  }
266  tuple = PyTuple_New(1);
267  assert(tuple);
268  PyTuple_SET_ITEM(tuple, 0, val);
269  Py_XINCREF(val);
270  result = (*getset->set)(obj, tuple);
271  Py_DECREF(tuple);
272  Py_XDECREF(result);
273  return result ? 0 : -1;
274}
275
276SWIGINTERN int
277SwigPyBuiltin_FunpackSetterClosure (PyObject *obj, PyObject *val, void *closure) {
278  SwigPyGetSet *getset;
279  PyObject *result;
280  if (!closure) {
281    PyErr_Format(PyExc_TypeError, "Missing getset closure");
282    return -1;
283  }
284  getset = (SwigPyGetSet *)closure;
285  if (!getset->set) {
286    PyErr_Format(PyExc_TypeError, "Illegal member variable assignment in type '%.300s'", obj->ob_type->tp_name);
287    return -1;
288  }
289  result = (*getset->set)(obj, val);
290  Py_XDECREF(result);
291  return result ? 0 : -1;
292}
293
294SWIGINTERN void
295SwigPyStaticVar_dealloc(PyDescrObject *descr) {
296  _PyObject_GC_UNTRACK(descr);
297  Py_XDECREF(PyDescr_TYPE(descr));
298  Py_XDECREF(PyDescr_NAME(descr));
299  PyObject_GC_Del(descr);
300}
301
302SWIGINTERN PyObject *
303SwigPyStaticVar_repr(PyGetSetDescrObject *descr) {
304#if PY_VERSION_HEX >= 0x03000000
305
306  return PyUnicode_FromFormat("<class attribute '%S' of type '%s'>", PyDescr_NAME(descr), PyDescr_TYPE(descr)->tp_name);
307#else
308  return PyString_FromFormat("<class attribute '%s' of type '%s'>", PyString_AsString(PyDescr_NAME(descr)), PyDescr_TYPE(descr)->tp_name);
309#endif
310}
311
312SWIGINTERN int
313SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg) {
314  PyDescrObject *descr;
315  descr = (PyDescrObject *)self;
316  Py_VISIT((PyObject*) PyDescr_TYPE(descr));
317  return 0;
318}
319
320SWIGINTERN PyObject *
321SwigPyStaticVar_get(PyGetSetDescrObject *descr, PyObject *obj, PyObject *SWIGUNUSEDPARM(type)) {
322  if (descr->d_getset->get != NULL)
323    return descr->d_getset->get(obj, descr->d_getset->closure);
324#if PY_VERSION_HEX >= 0x03000000
325  PyErr_Format(PyExc_AttributeError, "attribute '%.300S' of '%.100s' objects is not readable", PyDescr_NAME(descr), PyDescr_TYPE(descr)->tp_name);
326#else
327  PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not readable", PyString_AsString(PyDescr_NAME(descr)), PyDescr_TYPE(descr)->tp_name);
328#endif
329  return NULL;
330}
331
332SWIGINTERN int
333SwigPyStaticVar_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) {
334  if (descr->d_getset->set != NULL)
335    return descr->d_getset->set(obj, value, descr->d_getset->closure);
336#if PY_VERSION_HEX >= 0x03000000
337  PyErr_Format(PyExc_AttributeError, "attribute '%.300S' of '%.100s' objects is not writable", PyDescr_NAME(descr), PyDescr_TYPE(descr)->tp_name);
338#else
339  PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not writable", PyString_AsString(PyDescr_NAME(descr)), PyDescr_TYPE(descr)->tp_name);
340#endif
341  return -1;
342}
343
344SWIGINTERN int
345SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) {
346  PyObject *attribute;
347  descrsetfunc local_set;
348  attribute = _PyType_Lookup(type, name);
349  if (attribute != NULL) {
350    /* Implement descriptor functionality, if any */
351    local_set = attribute->ob_type->tp_descr_set;
352    if (local_set != NULL)
353      return local_set(attribute, (PyObject *)type, value);
354#if PY_VERSION_HEX >= 0x03000000
355    PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400S'", type->tp_name, name);
356#else 
357    PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400s'", type->tp_name, PyString_AS_STRING(name));
358#endif
359  } else {
360#if PY_VERSION_HEX >= 0x03000000
361    PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400S'", type->tp_name, name);
362#else
363    PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400s'", type->tp_name, PyString_AS_STRING(name));
364#endif
365  }
366
367  return -1;
368}
369
370SWIGINTERN PyTypeObject*
371SwigPyStaticVar_Type(void) {
372  static PyTypeObject staticvar_type;
373  static int type_init = 0;
374  if (!type_init) {
375    const PyTypeObject tmp = {
376      /* PyObject header changed in Python 3 */
377#if PY_VERSION_HEX >= 0x03000000
378      PyVarObject_HEAD_INIT(&PyType_Type, 0)
379#else
380      PyObject_HEAD_INIT(&PyType_Type)
381      0,
382#endif
383      "swig_static_var_getset_descriptor",
384      sizeof(PyGetSetDescrObject),
385      0,
386      (destructor)SwigPyStaticVar_dealloc,      /* tp_dealloc */
387      0,                                        /* tp_print */
388      0,                                        /* tp_getattr */
389      0,                                        /* tp_setattr */
390      0,                                        /* tp_compare */
391      (reprfunc)SwigPyStaticVar_repr,           /* tp_repr */
392      0,                                        /* tp_as_number */
393      0,                                        /* tp_as_sequence */
394      0,                                        /* tp_as_mapping */
395      0,                                        /* tp_hash */
396      0,                                        /* tp_call */
397      0,                                        /* tp_str */
398      PyObject_GenericGetAttr,                  /* tp_getattro */
399      0,                                        /* tp_setattro */
400      0,                                        /* tp_as_buffer */
401      Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_CLASS, /* tp_flags */
402      0,                                        /* tp_doc */
403      SwigPyStaticVar_traverse,                 /* tp_traverse */
404      0,                                        /* tp_clear */
405      0,                                        /* tp_richcompare */
406      0,                                        /* tp_weaklistoffset */
407      0,                                        /* tp_iter */
408      0,                                        /* tp_iternext */
409      0,                                        /* tp_methods */
410      0,                                        /* tp_members */
411      0,                                        /* tp_getset */
412      0,                                        /* tp_base */
413      0,                                        /* tp_dict */
414      (descrgetfunc)SwigPyStaticVar_get,        /* tp_descr_get */
415      (descrsetfunc)SwigPyStaticVar_set,        /* tp_descr_set */
416      0,                                        /* tp_dictoffset */
417      0,                                        /* tp_init */
418      0,                                        /* tp_alloc */
419      0,                                        /* tp_new */
420      0,                                        /* tp_free */
421      0,                                        /* tp_is_gc */
422      0,                                        /* tp_bases */
423      0,                                        /* tp_mro */
424      0,                                        /* tp_cache */
425      0,                                        /* tp_subclasses */
426      0,                                        /* tp_weaklist */
427#if PY_VERSION_HEX >= 0x02030000
428      0,                                        /* tp_del */
429#endif
430#if PY_VERSION_HEX >= 0x02060000
431      0,                                        /* tp_version */
432#endif
433#ifdef COUNT_ALLOCS
434      0,0,0,0                                   /* tp_alloc -> tp_next */
435#endif
436    };
437    staticvar_type = tmp;
438    type_init = 1;
439#if PY_VERSION_HEX < 0x02020000
440    staticvar_type.ob_type = &PyType_Type;
441#else
442    if (PyType_Ready(&staticvar_type) < 0)
443      return NULL;
444#endif
445  }
446  return &staticvar_type;
447}
448
449SWIGINTERN PyGetSetDescrObject *
450SwigPyStaticVar_new_getset(PyTypeObject *type, PyGetSetDef *getset) {
451
452  PyGetSetDescrObject *descr;
453  descr = (PyGetSetDescrObject *)PyType_GenericAlloc(SwigPyStaticVar_Type(), 0);
454  assert(descr);
455  Py_XINCREF(type);
456  PyDescr_TYPE(descr) = type;
457  PyDescr_NAME(descr) = PyString_InternFromString(getset->name);
458  descr->d_getset = getset;
459  if (PyDescr_NAME(descr) == NULL) {
460    Py_DECREF(descr);
461    descr = NULL;
462  }
463  return descr;
464}
465
466SWIGINTERN void
467SwigPyBuiltin_InitBases (PyTypeObject *type, PyTypeObject **bases) {
468  int base_count = 0;
469  PyTypeObject **b;
470  PyObject *tuple;
471  int i;
472
473  if (!bases[0]) {
474    bases[0] = SwigPyObject_type();
475    bases[1] = NULL;
476  }
477  type->tp_base = bases[0];
478  Py_INCREF((PyObject *)bases[0]);
479  for (b = bases; *b != NULL; ++b)
480    ++base_count;
481  tuple = PyTuple_New(base_count);
482  for (i = 0; i < base_count; ++i) {
483    PyTuple_SET_ITEM(tuple, i, (PyObject *)bases[i]);
484    Py_INCREF((PyObject *)bases[i]);
485  }
486  type->tp_bases = tuple;
487}
488
489SWIGINTERN PyObject *
490SwigPyBuiltin_ThisClosure (PyObject *self, void *SWIGUNUSEDPARM(closure)) {
491  PyObject *result;
492  result = (PyObject *)SWIG_Python_GetSwigThis(self);
493  Py_XINCREF(result);
494  return result;
495}
496
497SWIGINTERN void
498SwigPyBuiltin_SetMetaType (PyTypeObject *type, PyTypeObject *metatype)
499{
500#if PY_VERSION_HEX >= 0x03000000
501    type->ob_base.ob_base.ob_type = metatype;
502#else
503    type->ob_type = metatype;
504#endif
505}
506
507#ifdef __cplusplus
508}
509#endif
510