Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc980e0

Browse files
authored
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 46496f9. Add also a comment to document that _PyEval_BuiltinsFromGlobals() returns a borrowed reference.
1 parent 6af528b commit fc980e0

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a ``PyEval_EvalCodeEx()`` regression: fix reference counting on
2+
builtins. Patch by Victor Stinner.

Objects/frameobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ PyFrameObject*
847847
PyFrame_New(PyThreadState *tstate, PyCodeObject *code,
848848
PyObject *globals, PyObject *locals)
849849
{
850-
PyObject *builtins = _PyEval_BuiltinsFromGlobals(tstate, globals);
850+
PyObject *builtins = _PyEval_BuiltinsFromGlobals(tstate, globals); // borrowed ref
851851
if (builtins == NULL) {
852852
return NULL;
853853
}

Objects/funcobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname
5050
}
5151
Py_XINCREF(module);
5252

53-
builtins = _PyEval_BuiltinsFromGlobals(tstate, globals);
53+
builtins = _PyEval_BuiltinsFromGlobals(tstate, globals); // borrowed ref
5454
if (builtins == NULL) {
5555
goto error;
5656
}

Python/ceval.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ PyEval_EvalCode(PyObject *co, PyObject *globals, PyObject *locals)
11271127
if (locals == NULL) {
11281128
locals = globals;
11291129
}
1130-
PyObject *builtins = _PyEval_BuiltinsFromGlobals(tstate, globals);
1130+
PyObject *builtins = _PyEval_BuiltinsFromGlobals(tstate, globals); // borrowed ref
11311131
if (builtins == NULL) {
11321132
return NULL;
11331133
}
@@ -5140,12 +5140,11 @@ PyEval_EvalCodeEx(PyObject *_co, PyObject *globals, PyObject *locals,
51405140
if (defaults == NULL) {
51415141
return NULL;
51425142
}
5143-
PyObject *builtins = _PyEval_BuiltinsFromGlobals(tstate, globals);
5143+
PyObject *builtins = _PyEval_BuiltinsFromGlobals(tstate, globals); // borrowed ref
51445144
if (builtins == NULL) {
51455145
Py_DECREF(defaults);
51465146
return NULL;
51475147
}
5148-
assert ((((PyCodeObject *)_co)->co_flags & (CO_NEWLOCALS | CO_OPTIMIZED)) == 0);
51495148
if (locals == NULL) {
51505149
locals = globals;
51515150
}
@@ -5208,7 +5207,6 @@ PyEval_EvalCodeEx(PyObject *_co, PyObject *globals, PyObject *locals,
52085207
}
52095208
fail:
52105209
Py_DECREF(defaults);
5211-
Py_DECREF(builtins);
52125210
return res;
52135211
}
52145212

0 commit comments

Comments
 (0)