summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2023-04-14 11:21:28 +0200
committerStefan Behnel <stefan_ml@behnel.de>2023-04-14 11:40:21 +0200
commit56b30f2e2cbf964eb5b1d1ea4448963d58301035 (patch)
tree7b385b6a276e94a30165873f35d06aca51a23323
parent6d8c4ffa5261684e4428e10388d3e6daeb3d7daf (diff)
downloadcython-56b30f2e2cbf964eb5b1d1ea4448963d58301035.tar.gz
Refactor __Pyx_PyCode_New() to avoid "dead code" warnings and special error cases.
-rw-r--r--Cython/Utility/ModuleSetupCode.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c
index 59111ed28..8f926e757 100644
--- a/Cython/Utility/ModuleSetupCode.c
+++ b/Cython/Utility/ModuleSetupCode.c
@@ -641,10 +641,10 @@ class __Pyx_FakeReference {
// TODO - currently written to be simple and work in limited API etc.
// A more optimized version would be good
PyObject *kwds=NULL, *argcount=NULL, *posonlyargcount=NULL, *kwonlyargcount=NULL;
- PyObject *nlocals=NULL, *stacksize=NULL, *flags=NULL, *replace=NULL, *call_result=NULL, *empty=NULL;
+ PyObject *nlocals=NULL, *stacksize=NULL, *flags=NULL, *replace=NULL, *empty=NULL;
const char *fn_cstr=NULL;
const char *name_cstr=NULL;
- PyCodeObject* co=NULL;
+ PyCodeObject *co=NULL, *result=NULL;
PyObject *type, *value, *traceback;
// we must be able to call this while an exception is happening - thus clear then restore the state
@@ -675,20 +675,14 @@ class __Pyx_FakeReference {
if (!(name_cstr=PyUnicode_AsUTF8AndSize(name, NULL))) goto end;
if (!(co = PyCode_NewEmpty(fn_cstr, name_cstr, fline))) goto end;
- if (!(replace = PyObject_GetAttrString((PyObject*)co, "replace"))) goto cleanup_code_too;
- if (!(empty = PyTuple_New(0))) goto cleanup_code_too; // unfortunately __pyx_empty_tuple isn't available here
- if (!(call_result = PyObject_Call(replace, empty, kwds))) goto cleanup_code_too;
+ if (!(replace = PyObject_GetAttrString((PyObject*)co, "replace"))) goto end;
+ // unfortunately, __pyx_empty_tuple isn't available here
+ if (!(empty = PyTuple_New(0))) goto end;
- Py_XDECREF((PyObject*)co);
- co = (PyCodeObject*)call_result;
- call_result = NULL;
+ result = (PyCodeObject*) PyObject_Call(replace, empty, kwds);
- if (0) {
- cleanup_code_too:
- Py_XDECREF((PyObject*)co);
- co = NULL;
- }
- end:
+ end:
+ Py_XDECREF((PyObject*) co);
Py_XDECREF(kwds);
Py_XDECREF(argcount);
Py_XDECREF(posonlyargcount);
@@ -696,12 +690,11 @@ class __Pyx_FakeReference {
Py_XDECREF(nlocals);
Py_XDECREF(stacksize);
Py_XDECREF(replace);
- Py_XDECREF(call_result);
Py_XDECREF(empty);
if (type) {
PyErr_Restore(type, value, traceback);
}
- return co;
+ return result;
}
#elif PY_VERSION_HEX >= 0x030800B2 && !CYTHON_COMPILING_IN_PYPY