summaryrefslogtreecommitdiffstats
path: root/Python/symtable.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-02-17 12:49:39 (GMT)
committerGitHub <noreply@github.com>2024-02-17 12:49:39 (GMT)
commitbf0e0729803c20298beda40af016e58510594a1d (patch)
tree171efabef5474e2c118939ee4194e95b070059b5 /Python/symtable.c
parentebf8eb2740a46ca685c03660114eb047d054eb30 (diff)
downloadcpython-bf0e0729803c20298beda40af016e58510594a1d.zip
cpython-bf0e0729803c20298beda40af016e58510594a1d.tar.gz
cpython-bf0e0729803c20298beda40af016e58510594a1d.tar.bz2
[3.12] gh-96497: Mangle name before symtable lookup in 'symtable_extend_namedexpr_scope' (GH-96561) (GH-115603)
(cherry picked from commit 664965a1c141e8af5eb465d29099781a6a2fc3f3) Co-authored-by: wookie184 <wookie1840@gmail.com>
Diffstat (limited to 'Python/symtable.c')
-rw-r--r--Python/symtable.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/Python/symtable.c b/Python/symtable.c
index cfa5bec..65ebdee 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -1254,16 +1254,22 @@ symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
}
static long
-symtable_lookup(struct symtable *st, PyObject *name)
+symtable_lookup_entry(struct symtable *st, PySTEntryObject *ste, PyObject *name)
{
PyObject *mangled = _Py_Mangle(st->st_private, name);
if (!mangled)
return 0;
- long ret = _PyST_GetSymbol(st->st_cur, mangled);
+ long ret = _PyST_GetSymbol(ste, mangled);
Py_DECREF(mangled);
return ret;
}
+static long
+symtable_lookup(struct symtable *st, PyObject *name)
+{
+ return symtable_lookup_entry(st, st->st_cur, name);
+}
+
static int
symtable_add_def_helper(struct symtable *st, PyObject *name, int flag, struct _symtable_entry *ste,
int lineno, int col_offset, int end_lineno, int end_col_offset)
@@ -1904,7 +1910,7 @@ symtable_extend_namedexpr_scope(struct symtable *st, expr_ty e)
* binding conflict with iteration variables, otherwise skip it
*/
if (ste->ste_comprehension) {
- long target_in_scope = _PyST_GetSymbol(ste, target_name);
+ long target_in_scope = symtable_lookup_entry(st, ste, target_name);
if ((target_in_scope & DEF_COMP_ITER) &&
(target_in_scope & DEF_LOCAL)) {
PyErr_Format(PyExc_SyntaxError, NAMED_EXPR_COMP_CONFLICT, target_name);
@@ -1920,7 +1926,7 @@ symtable_extend_namedexpr_scope(struct symtable *st, expr_ty e)
/* If we find a FunctionBlock entry, add as GLOBAL/LOCAL or NONLOCAL/LOCAL */
if (ste->ste_type == FunctionBlock) {
- long target_in_scope = _PyST_GetSymbol(ste, target_name);
+ long target_in_scope = symtable_lookup_entry(st, ste, target_name);
if (target_in_scope & DEF_GLOBAL) {
if (!symtable_add_def(st, target_name, DEF_GLOBAL, LOCATION(e)))
VISIT_QUIT(st, 0);