1 /////////////// PyIdentifierFromString.proto ///////////////
3 #if !defined(__Pyx_PyIdentifier_FromString)
4 #if PY_MAJOR_VERSION < 3
5 #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
7 #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
12 /////////////// Import.proto ///////////////
14 static PyObject
*__Pyx_Import(PyObject
*name
, PyObject
*from_list
, int level
); /*proto*/
16 /////////////// Import ///////////////
17 //@requires: ObjectHandling.c::PyObjectGetAttrStr
20 static PyObject
*__Pyx_Import(PyObject
*name
, PyObject
*from_list
, int level
) {
21 PyObject
*empty_list
= 0;
23 PyObject
*global_dict
= 0;
24 PyObject
*empty_dict
= 0;
26 #if PY_VERSION_HEX < 0x03030000
28 py_import
= __Pyx_PyObject_GetAttrStr($builtins_cname
, PYIDENT("__import__"));
35 empty_list
= PyList_New(0);
40 global_dict
= PyModule_GetDict($module_cname
);
43 empty_dict
= PyDict_New();
46 #if PY_VERSION_HEX >= 0x02050000
48 #if PY_MAJOR_VERSION >= 3
50 if (strchr(__Pyx_MODULE_NAME
, '.')) {
51 /* try package relative import first */
52 #if PY_VERSION_HEX < 0x03030000
53 PyObject
*py_level
= PyInt_FromLong(1);
56 module
= PyObject_CallFunctionObjArgs(py_import
,
57 name
, global_dict
, empty_dict
, list
, py_level
, NULL
);
60 module
= PyImport_ImportModuleLevelObject(
61 name
, global_dict
, empty_dict
, list
, 1);
64 if (!PyErr_ExceptionMatches(PyExc_ImportError
))
69 level
= 0; /* try absolute import on failure */
73 #if PY_VERSION_HEX < 0x03030000
74 PyObject
*py_level
= PyInt_FromLong(level
);
77 module
= PyObject_CallFunctionObjArgs(py_import
,
78 name
, global_dict
, empty_dict
, list
, py_level
, NULL
);
81 module
= PyImport_ImportModuleLevelObject(
82 name
, global_dict
, empty_dict
, list
, level
);
88 PyErr_SetString(PyExc_RuntimeError
, "Relative import is not supported for Python <=2.4.");
91 module
= PyObject_CallFunctionObjArgs(py_import
,
92 name
, global_dict
, empty_dict
, list
, NULL
);
95 #if PY_VERSION_HEX < 0x03030000
96 Py_XDECREF(py_import
);
98 Py_XDECREF(empty_list
);
99 Py_XDECREF(empty_dict
);
104 /////////////// ImportFrom.proto ///////////////
106 static PyObject
* __Pyx_ImportFrom(PyObject
* module
, PyObject
* name
); /*proto*/
108 /////////////// ImportFrom ///////////////
109 //@requires: ObjectHandling.c::PyObjectGetAttrStr
111 static PyObject
* __Pyx_ImportFrom(PyObject
* module
, PyObject
* name
) {
112 PyObject
* value
= __Pyx_PyObject_GetAttrStr(module
, name
);
113 if (unlikely(!value
) && PyErr_ExceptionMatches(PyExc_AttributeError
)) {
114 PyErr_Format(PyExc_ImportError
,
115 #if PY_MAJOR_VERSION < 3
116 "cannot import name %.230s", PyString_AS_STRING(name
));
118 "cannot import name %S", name
);
125 /////////////// ModuleImport.proto ///////////////
127 static PyObject
*__Pyx_ImportModule(const char *name
); /*proto*/
129 /////////////// ModuleImport ///////////////
130 //@requires: PyIdentifierFromString
132 #ifndef __PYX_HAVE_RT_ImportModule
133 #define __PYX_HAVE_RT_ImportModule
134 static PyObject
*__Pyx_ImportModule(const char *name
) {
135 PyObject
*py_name
= 0;
136 PyObject
*py_module
= 0;
138 py_name
= __Pyx_PyIdentifier_FromString(name
);
141 py_module
= PyImport_Import(py_name
);
151 /////////////// SetPackagePathFromImportLib.proto ///////////////
153 #if PY_VERSION_HEX >= 0x03030000
154 static int __Pyx_SetPackagePathFromImportLib(const char* parent_package_name
, PyObject
*module_name
);
156 #define __Pyx_SetPackagePathFromImportLib(a, b) 0
159 /////////////// SetPackagePathFromImportLib ///////////////
160 //@requires: ObjectHandling.c::PyObjectGetAttrStr
161 //@substitute: naming
163 #if PY_VERSION_HEX >= 0x03030000
164 static int __Pyx_SetPackagePathFromImportLib(const char* parent_package_name
, PyObject
*module_name
) {
165 PyObject
*importlib
, *loader
, *osmod
, *ossep
, *parts
, *package_path
;
166 PyObject
*path
= NULL
, *file_path
= NULL
;
168 if (parent_package_name
) {
169 PyObject
*package
= PyImport_ImportModule(parent_package_name
);
170 if (unlikely(!package
))
172 path
= PyObject_GetAttrString(package
, "__path__");
174 if (unlikely(!path
) || unlikely(path
== Py_None
))
177 path
= Py_None
; Py_INCREF(Py_None
);
179 // package_path = [importlib.find_loader(module_name, path).path.rsplit(os.sep, 1)[0]]
180 importlib
= PyImport_ImportModule("importlib");
181 if (unlikely(!importlib
))
183 loader
= PyObject_CallMethod(importlib
, "find_loader", "(OO)", module_name
, path
);
184 Py_DECREF(importlib
);
185 Py_DECREF(path
); path
= NULL
;
186 if (unlikely(!loader
))
188 file_path
= PyObject_GetAttrString(loader
, "path");
190 if (unlikely(!file_path
))
193 if (unlikely(__Pyx_SetAttrString($module_cname
, "__file__", file_path
) < 0))
196 osmod
= PyImport_ImportModule("os");
197 if (unlikely(!osmod
))
199 ossep
= PyObject_GetAttrString(osmod
, "sep");
201 if (unlikely(!ossep
))
203 parts
= PyObject_CallMethod(file_path
, "rsplit", "(Oi)", ossep
, 1);
204 Py_DECREF(file_path
); file_path
= NULL
;
206 if (unlikely(!parts
))
208 package_path
= Py_BuildValue("[O]", PyList_GET_ITEM(parts
, 0));
210 if (unlikely(!package_path
))
215 PyErr_WriteUnraisable(module_name
);
217 Py_XDECREF(file_path
);
219 // set an empty path list on failure
221 package_path
= PyList_New(0);
222 if (unlikely(!package_path
))
226 result
= __Pyx_SetAttrString($module_cname
, "__path__", package_path
);
227 Py_DECREF(package_path
);
233 /////////////// TypeImport.proto ///////////////
235 static PyTypeObject
*__Pyx_ImportType(const char *module_name
, const char *class_name
, size_t size
, int strict
); /*proto*/
237 /////////////// TypeImport ///////////////
238 //@requires: PyIdentifierFromString
239 //@requires: ModuleImport
241 #ifndef __PYX_HAVE_RT_ImportType
242 #define __PYX_HAVE_RT_ImportType
243 static PyTypeObject
*__Pyx_ImportType(const char *module_name
, const char *class_name
,
244 size_t size
, int strict
)
246 PyObject
*py_module
= 0;
247 PyObject
*result
= 0;
248 PyObject
*py_name
= 0;
250 Py_ssize_t basicsize
;
251 #ifdef Py_LIMITED_API
252 PyObject
*py_basicsize
;
255 py_module
= __Pyx_ImportModule(module_name
);
258 py_name
= __Pyx_PyIdentifier_FromString(class_name
);
261 result
= PyObject_GetAttr(py_module
, py_name
);
264 Py_DECREF(py_module
);
268 if (!PyType_Check(result
)) {
269 PyErr_Format(PyExc_TypeError
,
270 "%.200s.%.200s is not a type object",
271 module_name
, class_name
);
274 #ifndef Py_LIMITED_API
275 basicsize
= ((PyTypeObject
*)result
)->tp_basicsize
;
277 py_basicsize
= PyObject_GetAttrString(result
, "__basicsize__");
280 basicsize
= PyLong_AsSsize_t(py_basicsize
);
281 Py_DECREF(py_basicsize
);
283 if (basicsize
== (Py_ssize_t
)-1 && PyErr_Occurred())
286 if (!strict
&& (size_t)basicsize
> size
) {
287 PyOS_snprintf(warning
, sizeof(warning
),
288 "%s.%s size changed, may indicate binary incompatibility",
289 module_name
, class_name
);
290 #if PY_VERSION_HEX < 0x02050000
291 if (PyErr_Warn(NULL
, warning
) < 0) goto bad
;
293 if (PyErr_WarnEx(NULL
, warning
, 0) < 0) goto bad
;
296 else if ((size_t)basicsize
!= size
) {
297 PyErr_Format(PyExc_ValueError
,
298 "%.200s.%.200s has the wrong size, try recompiling",
299 module_name
, class_name
);
302 return (PyTypeObject
*)result
;
304 Py_XDECREF(py_module
);
310 /////////////// FunctionImport.proto ///////////////
312 static int __Pyx_ImportFunction(PyObject
*module
, const char *funcname
, void (**f
)(void), const char *sig
); /*proto*/
314 /////////////// FunctionImport ///////////////
315 //@substitute: naming
317 #ifndef __PYX_HAVE_RT_ImportFunction
318 #define __PYX_HAVE_RT_ImportFunction
319 static int __Pyx_ImportFunction(PyObject
*module
, const char *funcname
, void (**f
)(void), const char *sig
) {
327 d
= PyObject_GetAttrString(module
, (char *)"$api_name");
330 cobj
= PyDict_GetItemString(d
, funcname
);
332 PyErr_Format(PyExc_ImportError
,
333 "%.200s does not export expected C function %.200s",
334 PyModule_GetName(module
), funcname
);
337 #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3 && PY_MINOR_VERSION==0)
338 if (!PyCapsule_IsValid(cobj
, sig
)) {
339 PyErr_Format(PyExc_TypeError
,
340 "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
341 PyModule_GetName(module
), funcname
, sig
, PyCapsule_GetName(cobj
));
344 tmp
.p
= PyCapsule_GetPointer(cobj
, sig
);
346 {const char *desc
, *s1
, *s2
;
347 desc
= (const char *)PyCObject_GetDesc(cobj
);
351 while (*s1
!= '\0' && *s1
== *s2
) { s1
++; s2
++; }
353 PyErr_Format(PyExc_TypeError
,
354 "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
355 PyModule_GetName(module
), funcname
, sig
, desc
);
358 tmp
.p
= PyCObject_AsVoidPtr(cobj
);}
371 /////////////// FunctionExport.proto ///////////////
373 static int __Pyx_ExportFunction(const char *name
, void (*f
)(void), const char *sig
); /*proto*/
375 /////////////// FunctionExport ///////////////
376 //@substitute: naming
378 static int __Pyx_ExportFunction(const char *name
, void (*f
)(void), const char *sig
) {
386 d
= PyObject_GetAttrString($module_cname
, (char *)"$api_name");
393 if (PyModule_AddObject($module_cname
, (char *)"$api_name", d
) < 0)
397 #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
398 cobj
= PyCapsule_New(tmp
.p
, sig
, 0);
400 cobj
= PyCObject_FromVoidPtrAndDesc(tmp
.p
, (void *)sig
, 0);
404 if (PyDict_SetItemString(d
, name
, cobj
) < 0)
415 /////////////// VoidPtrImport.proto ///////////////
417 static int __Pyx_ImportVoidPtr(PyObject
*module
, const char *name
, void **p
, const char *sig
); /*proto*/
419 /////////////// VoidPtrImport ///////////////
420 //@substitute: naming
422 #ifndef __PYX_HAVE_RT_ImportVoidPtr
423 #define __PYX_HAVE_RT_ImportVoidPtr
424 static int __Pyx_ImportVoidPtr(PyObject
*module
, const char *name
, void **p
, const char *sig
) {
428 d
= PyObject_GetAttrString(module
, (char *)"$api_name");
431 cobj
= PyDict_GetItemString(d
, name
);
433 PyErr_Format(PyExc_ImportError
,
434 "%.200s does not export expected C variable %.200s",
435 PyModule_GetName(module
), name
);
438 #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3 && PY_MINOR_VERSION==0)
439 if (!PyCapsule_IsValid(cobj
, sig
)) {
440 PyErr_Format(PyExc_TypeError
,
441 "C variable %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
442 PyModule_GetName(module
), name
, sig
, PyCapsule_GetName(cobj
));
445 *p
= PyCapsule_GetPointer(cobj
, sig
);
447 {const char *desc
, *s1
, *s2
;
448 desc
= (const char *)PyCObject_GetDesc(cobj
);
452 while (*s1
!= '\0' && *s1
== *s2
) { s1
++; s2
++; }
454 PyErr_Format(PyExc_TypeError
,
455 "C variable %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
456 PyModule_GetName(module
), name
, sig
, desc
);
459 *p
= PyCObject_AsVoidPtr(cobj
);}
471 /////////////// VoidPtrExport.proto ///////////////
473 static int __Pyx_ExportVoidPtr(PyObject
*name
, void *p
, const char *sig
); /*proto*/
475 /////////////// VoidPtrExport ///////////////
476 //@substitute: naming
477 //@requires: ObjectHandling.c::PyObjectSetAttrStr
479 static int __Pyx_ExportVoidPtr(PyObject
*name
, void *p
, const char *sig
) {
483 d
= PyDict_GetItem($moddict_cname
, PYIDENT("$api_name"));
489 if (__Pyx_PyObject_SetAttrStr($module_cname
, PYIDENT("$api_name"), d
) < 0)
492 #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3 && PY_MINOR_VERSION==0)
493 cobj
= PyCapsule_New(p
, sig
, 0);
495 cobj
= PyCObject_FromVoidPtrAndDesc(p
, (void *)sig
, 0);
499 if (PyDict_SetItem(d
, name
, cobj
) < 0)
511 /////////////// SetVTable.proto ///////////////
513 static int __Pyx_SetVtable(PyObject
*dict
, void *vtable
); /*proto*/
515 /////////////// SetVTable ///////////////
517 static int __Pyx_SetVtable(PyObject
*dict
, void *vtable
) {
518 #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
519 PyObject
*ob
= PyCapsule_New(vtable
, 0, 0);
521 PyObject
*ob
= PyCObject_FromVoidPtr(vtable
, 0);
525 if (PyDict_SetItem(dict
, PYIDENT("__pyx_vtable__"), ob
) < 0)
535 /////////////// GetVTable.proto ///////////////
537 static void* __Pyx_GetVtable(PyObject
*dict
); /*proto*/
539 /////////////// GetVTable ///////////////
541 static void* __Pyx_GetVtable(PyObject
*dict
) {
543 PyObject
*ob
= PyObject_GetItem(dict
, PYIDENT("__pyx_vtable__"));
546 #if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
547 ptr
= PyCapsule_GetPointer(ob
, 0);
549 ptr
= PyCObject_AsVoidPtr(ob
);
551 if (!ptr
&& !PyErr_Occurred())
552 PyErr_SetString(PyExc_RuntimeError
, "invalid vtable found for imported type");