Commit 2fa32b3c authored by Robert Bradshaw's avatar Robert Bradshaw

Share common type object for Cython functions.

parent 367498f1
/////////////// FetchCommonType.proto ///////////////
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);
/////////////// FetchCommonType ///////////////
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
static PyObject* fake_module = NULL;
PyTypeObject* cached_type;
if (fake_module == NULL) {
PyObject* sys = PyImport_ImportModule("sys");
PyObject* sys_modules = PyObject_GetAttrString(sys, "modules");
fake_module = PyDict_GetItemString(sys_modules, "_cython");
if (fake_module == NULL) {
PyObject* args = PyTuple_New(1);
PyTuple_SET_ITEM(args, 0, __Pyx_PyStr_FromString("_cython"));
fake_module = PyObject_Call((PyObject*) &PyModule_Type, args, NULL);
PyDict_SetItemString(sys_modules, "_cython", fake_module);
}
}
if (PyObject_HasAttrString(fake_module, type->tp_name)) {
cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
} else {
PyType_Ready(type);
PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type);
cached_type = type;
}
return cached_type;
}
...@@ -67,6 +67,7 @@ static int __Pyx_CyFunction_init(void); ...@@ -67,6 +67,7 @@ static int __Pyx_CyFunction_init(void);
//////////////////// CythonFunction //////////////////// //////////////////// CythonFunction ////////////////////
//@substitute: naming //@substitute: naming
//@requires: CommonTypes.c::FetchCommonType
static PyObject * static PyObject *
__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure) __Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure)
...@@ -645,9 +646,15 @@ static int __Pyx_CyFunction_init(void) { ...@@ -645,9 +646,15 @@ static int __Pyx_CyFunction_init(void) {
// avoid a useless level of call indirection // avoid a useless level of call indirection
__pyx_CyFunctionType_type.tp_call = PyCFunction_Call; __pyx_CyFunctionType_type.tp_call = PyCFunction_Call;
#endif #endif
#if 1
__pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type);
if (__pyx_CyFunctionType == NULL)
return -1;
#else
if (PyType_Ready(&__pyx_CyFunctionType_type) < 0) if (PyType_Ready(&__pyx_CyFunctionType_type) < 0)
return -1; return -1;
__pyx_CyFunctionType = &__pyx_CyFunctionType_type; __pyx_CyFunctionType = &__pyx_CyFunctionType_type;
#endif
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment