bpo-43541: Fix PyEval_EvalCodeEx() regression (GH-24918)
* Remove an assertion which required CO_NEWLOCALS and CO_OPTIMIZED
code flags. It is ok to call this function on a code with these
flags set.
* Fix reference counting on builtins: remove Py_DECREF().
Fix regression introduced in the
commit 46496f9d12582bf11f4911ad0f23315d6f277907.
Add also a comment to document that _PyEval_BuiltinsFromGlobals()
returns a borrowed reference.
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index 36df88a..45135a8 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -50,7 +50,7 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname
}
Py_XINCREF(module);
- builtins = _PyEval_BuiltinsFromGlobals(tstate, globals);
+ builtins = _PyEval_BuiltinsFromGlobals(tstate, globals); // borrowed ref
if (builtins == NULL) {
goto error;
}