From 24e0d7d1a7a541644a3f75bfe9f67c8beec5285e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Fri, 7 Jun 2024 13:39:26 +0200 Subject: [PATCH 1/2] remove unused macros in ``symtable.c`` - remove ``DEF_FREE`` - remove ``GENERATOR`` - remove ``GENERATOR_EXPRESSION`` --- Include/internal/pycore_symtable.h | 4 ---- Modules/symtablemodule.c | 1 - Python/symtable.c | 2 -- 3 files changed, 7 deletions(-) diff --git a/Include/internal/pycore_symtable.h b/Include/internal/pycore_symtable.h index ac6c499c08264e..2cde810acf4877 100644 --- a/Include/internal/pycore_symtable.h +++ b/Include/internal/pycore_symtable.h @@ -139,7 +139,6 @@ extern PyObject* _Py_Mangle(PyObject *p, PyObject *name); #define DEF_PARAM (2<<1) /* formal parameter */ #define DEF_NONLOCAL (2<<2) /* nonlocal stmt */ #define USE (2<<3) /* name is used */ -#define DEF_FREE (2<<4) /* name used but not defined in nested block */ #define DEF_FREE_CLASS (2<<5) /* free variable from class's method */ #define DEF_IMPORT (2<<6) /* assignment occurred via import */ #define DEF_ANNOT (2<<7) /* this name is annotated */ @@ -162,9 +161,6 @@ extern PyObject* _Py_Mangle(PyObject *p, PyObject *name); #define FREE 4 #define CELL 5 -#define GENERATOR 1 -#define GENERATOR_EXPRESSION 2 - // Used by symtablemodule.c extern struct symtable* _Py_SymtableStringObjectFlags( const char *str, diff --git a/Modules/symtablemodule.c b/Modules/symtablemodule.c index 63c4dd4225298d..6a4271233f4ec0 100644 --- a/Modules/symtablemodule.c +++ b/Modules/symtablemodule.c @@ -76,7 +76,6 @@ symtable_init_constants(PyObject *m) if (PyModule_AddIntMacro(m, DEF_LOCAL) < 0) return -1; if (PyModule_AddIntMacro(m, DEF_PARAM) < 0) return -1; if (PyModule_AddIntMacro(m, DEF_TYPE_PARAM) < 0) return -1; - if (PyModule_AddIntMacro(m, DEF_FREE) < 0) return -1; if (PyModule_AddIntMacro(m, DEF_FREE_CLASS) < 0) return -1; if (PyModule_AddIntMacro(m, DEF_IMPORT) < 0) return -1; if (PyModule_AddIntMacro(m, DEF_BOUND) < 0) return -1; diff --git a/Python/symtable.c b/Python/symtable.c index 0ee8ca36cf8df0..857f4a8383b7fb 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -323,7 +323,6 @@ static void _dump_symtable(PySTEntryObject* ste, PyObject* prefix) if (flags & DEF_PARAM) printf(" DEF_PARAM"); if (flags & DEF_NONLOCAL) printf(" DEF_NONLOCAL"); if (flags & USE) printf(" USE"); - if (flags & DEF_FREE) printf(" DEF_FREE"); if (flags & DEF_FREE_CLASS) printf(" DEF_FREE_CLASS"); if (flags & DEF_IMPORT) printf(" DEF_IMPORT"); if (flags & DEF_ANNOT) printf(" DEF_ANNOT"); @@ -791,7 +790,6 @@ inline_comprehension(PySTEntryObject *ste, PySTEntryObject *comp, // 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; } From beb26dcc0c9ffde2b9afb348722e8d4c80e74e09 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Tue, 11 Jun 2024 10:52:12 -0400 Subject: [PATCH 2/2] Update symtable.c --- Python/symtable.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/Python/symtable.c b/Python/symtable.c index 6783c1403421e9..7999d0283168d4 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -813,21 +813,6 @@ 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); -<<<<<<< only-deprecate-def-free-symtable - 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; - if (PySet_Discard(comp_free, k) < 0) { - return 0; - } - remove_dunder_class = 1; - } -======= ->>>>>>> main PyObject *v_flags = PyLong_FromLong(only_flags); if (v_flags == NULL) { return 0;