summaryrefslogtreecommitdiffstats
path: root/Python/suggestions.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2021-06-07 18:22:26 (GMT)
committerGitHub <noreply@github.com>2021-06-07 18:22:26 (GMT)
commit2ab27c4af4ddf7528e1375e77c787c7fbb09b5e6 (patch)
treed3983e5282f575560cb7449fae4785447fdfff14 /Python/suggestions.c
parent001eb520b5757294dc455c900d94b7b153de6cdd (diff)
downloadcpython-2ab27c4af4ddf7528e1375e77c787c7fbb09b5e6.zip
cpython-2ab27c4af4ddf7528e1375e77c787c7fbb09b5e6.tar.gz
cpython-2ab27c4af4ddf7528e1375e77c787c7fbb09b5e6.tar.bz2
bpo-43693: Un-revert commits 2c1e258 and b2bf2bc. (gh-26577)
These were reverted in gh-26530 (commit 17c4edc) due to refleaks. * 2c1e258 - Compute deref offsets in compiler (gh-25152) * b2bf2bc - Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. (gh-26388) This change fixes the refleaks. https://bugs.python.org/issue43693
Diffstat (limited to 'Python/suggestions.c')
-rw-r--r--Python/suggestions.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Python/suggestions.c b/Python/suggestions.c
index 2e76551..3dfcbfe 100644
--- a/Python/suggestions.c
+++ b/Python/suggestions.c
@@ -3,6 +3,7 @@
#include "pycore_frame.h"
#include "pycore_pyerrors.h"
+#include "pycore_code.h" // _PyCode_GetVarnames()
#define MAX_CANDIDATE_ITEMS 750
#define MAX_STRING_SIZE 40
@@ -210,8 +211,13 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc)
PyFrameObject *frame = traceback->tb_frame;
assert(frame != NULL);
PyCodeObject *code = PyFrame_GetCode(frame);
- assert(code != NULL && code->co_varnames != NULL);
- PyObject *dir = PySequence_List(code->co_varnames);
+ assert(code != NULL && code->co_localsplusnames != NULL);
+ PyObject *varnames = _PyCode_GetVarnames(code);
+ if (varnames == NULL) {
+ return NULL;
+ }
+ PyObject *dir = PySequence_List(varnames);
+ Py_DECREF(varnames);
Py_DECREF(code);
if (dir == NULL) {
return NULL;