[3.13] gh-122728: Fix SystemError in PyEval_GetLocals() (GH-122735) (#122757)

gh-122728: Fix SystemError in PyEval_GetLocals() (GH-122735)

Fix PyEval_GetLocals() to avoid SystemError ("bad argument to
internal function"). Don't redefine the 'ret' variable in the if
block.

Add an unit test on PyEval_GetLocals().
(cherry picked from commit 4767a6e31c)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2024-08-06 23:37:10 +02:00 committed by GitHub
parent e808146af1
commit 5c161cb832
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 1 deletions

View file

@ -2482,7 +2482,7 @@ PyEval_GetLocals(void)
PyFrameObject *f = _PyFrame_GetFrameObject(current_frame);
PyObject *ret = f->f_locals_cache;
if (ret == NULL) {
PyObject *ret = PyDict_New();
ret = PyDict_New();
if (ret == NULL) {
Py_DECREF(locals);
return NULL;