aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Python/symtable.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-04-28 21:17:44 +0300
committershadchin <shadchin@yandex-team.com>2024-04-28 21:25:54 +0300
commita55d99a3eb72f90355bc146baeda18aa7eb97352 (patch)
treeb17cfed786effe8b81bba022239d6729f716fbeb /contrib/tools/python3/Python/symtable.c
parent67bf49d08acf1277eff4c336021ac22d964bb4c4 (diff)
downloadydb-a55d99a3eb72f90355bc146baeda18aa7eb97352.tar.gz
Update Python 3 to 3.12.3
7d09de7d8b99ea2be554ef0fc61276942ca9c2e1
Diffstat (limited to 'contrib/tools/python3/Python/symtable.c')
-rw-r--r--contrib/tools/python3/Python/symtable.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/contrib/tools/python3/Python/symtable.c b/contrib/tools/python3/Python/symtable.c
index a5c6b465b7..65ebdee0d7 100644
--- a/contrib/tools/python3/Python/symtable.c
+++ b/contrib/tools/python3/Python/symtable.c
@@ -281,11 +281,6 @@ symtable_new(void)
return NULL;
}
-/* Using a scaling factor means this should automatically adjust when
- the recursion limit is adjusted for small or large C stack allocations.
-*/
-#define COMPILER_STACK_FRAME_SCALE 2
-
struct symtable *
_PySymtable_Build(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
{
@@ -312,9 +307,9 @@ _PySymtable_Build(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
}
/* Be careful here to prevent overflow. */
int recursion_depth = C_RECURSION_LIMIT - tstate->c_recursion_remaining;
- starting_recursion_depth = recursion_depth * COMPILER_STACK_FRAME_SCALE;
+ starting_recursion_depth = recursion_depth;
st->recursion_depth = starting_recursion_depth;
- st->recursion_limit = C_RECURSION_LIMIT * COMPILER_STACK_FRAME_SCALE;
+ st->recursion_limit = C_RECURSION_LIMIT;
/* Make the initial symbol information gathering pass */
if (!symtable_enter_block(st, &_Py_ID(top), ModuleBlock, (void *)mod, 0, 0, 0, 0)) {
@@ -658,6 +653,8 @@ inline_comprehension(PySTEntryObject *ste, PySTEntryObject *comp,
{
PyObject *k, *v;
Py_ssize_t pos = 0;
+ int remove_dunder_class = 0;
+
while (PyDict_Next(comp->ste_symbols, &pos, &k, &v)) {
// skip comprehension parameter
long comp_flags = PyLong_AS_LONG(v);
@@ -679,6 +676,19 @@ inline_comprehension(PySTEntryObject *ste, PySTEntryObject *comp,
if (!existing) {
// name does not exist in scope, copy from comprehension
assert(scope != FREE || PySet_Contains(comp_free, k) == 1);
+ if (scope == FREE && ste->ste_type == ClassBlock &&
+ _PyUnicode_EqualToASCIIString(k, "__class__")) {
+ // if __class__ is unbound in the enclosing class scope and free
+ // in the comprehension scope, it needs special handling; just
+ // letting it be marked as free in class scope will break due to
+ // drop_class_free
+ scope = GLOBAL_IMPLICIT;
+ only_flags &= ~DEF_FREE;
+ if (PySet_Discard(comp_free, k) < 0) {
+ return 0;
+ }
+ remove_dunder_class = 1;
+ }
PyObject *v_flags = PyLong_FromLong(only_flags);
if (v_flags == NULL) {
return 0;
@@ -703,6 +713,10 @@ inline_comprehension(PySTEntryObject *ste, PySTEntryObject *comp,
}
}
}
+ comp->ste_free = PySet_Size(comp_free) > 0;
+ if (remove_dunder_class && PyDict_DelItemString(comp->ste_symbols, "__class__") < 0) {
+ return 0;
+ }
return 1;
}
@@ -1240,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)
@@ -1890,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);
@@ -1906,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);