Commit 32614c6b authored by Robert Bradshaw's avatar Robert Bradshaw

Use PyImport_GetModuleDict() for common utility types.

parent 0ccbb03a
...@@ -6,17 +6,13 @@ static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type); ...@@ -6,17 +6,13 @@ static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) { static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
static PyObject* fake_module = NULL; static PyObject* fake_module = NULL;
PyObject* sys = NULL;
PyObject* sys_modules = NULL;
PyObject* args = NULL; PyObject* args = NULL;
PyTypeObject* cached_type = NULL; PyTypeObject* cached_type = NULL;
const char* cython_module = "_cython_" CYTHON_ABI; const char* cython_module = "_cython_" CYTHON_ABI;
if (fake_module == NULL) { if (fake_module == NULL) {
sys = PyImport_ImportModule("sys"); if (sys == NULL) goto bad; PyObject* sys_modules = PyImport_GetModuleDict(); // borrowed
sys_modules = PyObject_GetAttrString(sys, "modules"); if (sys_modules == NULL) goto bad; fake_module = PyDict_GetItemString(sys_modules, cython_module); // borrowed
fake_module = PyDict_GetItemString(sys_modules, cython_module);
if (fake_module != NULL) { if (fake_module != NULL) {
// borrowed
Py_INCREF(fake_module); Py_INCREF(fake_module);
} else { } else {
PyObject* py_cython_module; PyObject* py_cython_module;
...@@ -33,6 +29,7 @@ static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) { ...@@ -33,6 +29,7 @@ static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
goto bad; goto bad;
} }
} }
if (PyObject_HasAttrString(fake_module, type->tp_name)) { if (PyObject_HasAttrString(fake_module, type->tp_name)) {
cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name); cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
} else { } else {
...@@ -43,8 +40,6 @@ static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) { ...@@ -43,8 +40,6 @@ static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
} }
cleanup: cleanup:
Py_XDECREF(sys);
Py_XDECREF(sys_modules);
Py_XDECREF(args); Py_XDECREF(args);
return cached_type; return cached_type;
......
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