mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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 46496f9d12
.
Add also a comment to document that _PyEval_BuiltinsFromGlobals()
returns a borrowed reference.
This commit is contained in:
parent
6af528b4ab
commit
fc980e0be1
4 changed files with 6 additions and 6 deletions
|
@ -1127,7 +1127,7 @@ PyEval_EvalCode(PyObject *co, PyObject *globals, PyObject *locals)
|
|||
if (locals == NULL) {
|
||||
locals = globals;
|
||||
}
|
||||
PyObject *builtins = _PyEval_BuiltinsFromGlobals(tstate, globals);
|
||||
PyObject *builtins = _PyEval_BuiltinsFromGlobals(tstate, globals); // borrowed ref
|
||||
if (builtins == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -5140,12 +5140,11 @@ PyEval_EvalCodeEx(PyObject *_co, PyObject *globals, PyObject *locals,
|
|||
if (defaults == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
PyObject *builtins = _PyEval_BuiltinsFromGlobals(tstate, globals);
|
||||
PyObject *builtins = _PyEval_BuiltinsFromGlobals(tstate, globals); // borrowed ref
|
||||
if (builtins == NULL) {
|
||||
Py_DECREF(defaults);
|
||||
return NULL;
|
||||
}
|
||||
assert ((((PyCodeObject *)_co)->co_flags & (CO_NEWLOCALS | CO_OPTIMIZED)) == 0);
|
||||
if (locals == NULL) {
|
||||
locals = globals;
|
||||
}
|
||||
|
@ -5208,7 +5207,6 @@ PyEval_EvalCodeEx(PyObject *_co, PyObject *globals, PyObject *locals,
|
|||
}
|
||||
fail:
|
||||
Py_DECREF(defaults);
|
||||
Py_DECREF(builtins);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue