summaryrefslogtreecommitdiff
path: root/Cython/Utility/Builtins.c
diff options
context:
space:
mode:
authorEddie Elizondo <eelizondo@fb.com>2020-02-18 02:23:19 -0800
committerGitHub <noreply@github.com>2020-02-18 11:23:19 +0100
commita87f498d964f4b63a93aba79ed8c5f082fedaa4f (patch)
tree34d505214cc831bd8f1f039070e78fccef6fb0f5 /Cython/Utility/Builtins.c
parent1431cc4e492f06abd191e639903966733201baba (diff)
downloadcython-a87f498d964f4b63a93aba79ed8c5f082fedaa4f.tar.gz
Expand LIMITED_API support (GH-3311)
* Add more limited api support * Fix Fused Functions * Fixed profile * Use PyModule_GetDict * Simplify __Pyx_Globals * Address issues in CommonStructures * ifdef guard CyFunction and FusedFunction
Diffstat (limited to 'Cython/Utility/Builtins.c')
-rw-r--r--Cython/Utility/Builtins.c44
1 files changed, 6 insertions, 38 deletions
diff --git a/Cython/Utility/Builtins.c b/Cython/Utility/Builtins.c
index c508917d5..df5b0d86f 100644
--- a/Cython/Utility/Builtins.c
+++ b/Cython/Utility/Builtins.c
@@ -20,47 +20,15 @@ static PyObject* __Pyx_Globals(void); /*proto*/
// access requires a rewrite as a dedicated class.
static PyObject* __Pyx_Globals(void) {
- Py_ssize_t i;
- PyObject *names;
- PyObject *globals = $moddict_cname;
- Py_INCREF(globals);
- names = PyObject_Dir($module_cname);
- if (!names)
- goto bad;
- for (i = PyList_GET_SIZE(names)-1; i >= 0; i--) {
-#if CYTHON_COMPILING_IN_PYPY
- PyObject* name = PySequence_ITEM(names, i);
- if (!name)
- goto bad;
+ PyObject *globals;
+#if CYTHON_COMPILING_IN_LIMITED_API
+ globals = PyModule_GetDict($module_cname);
+ if (unlikely(!globals)) return NULL;
#else
- PyObject* name = PyList_GET_ITEM(names, i);
-#endif
- if (!PyDict_Contains(globals, name)) {
- PyObject* value = __Pyx_GetAttr($module_cname, name);
- if (!value) {
-#if CYTHON_COMPILING_IN_PYPY
- Py_DECREF(name);
-#endif
- goto bad;
- }
- if (PyDict_SetItem(globals, name, value) < 0) {
-#if CYTHON_COMPILING_IN_PYPY
- Py_DECREF(name);
-#endif
- Py_DECREF(value);
- goto bad;
- }
- }
-#if CYTHON_COMPILING_IN_PYPY
- Py_DECREF(name);
+ globals = $moddict_cname;
#endif
- }
- Py_DECREF(names);
+ Py_INCREF(globals);
return globals;
-bad:
- Py_XDECREF(names);
- Py_XDECREF(globals);
- return NULL;
}
//////////////////// PyExecGlobals.proto ////////////////////