diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2022-02-23 00:23:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-23 00:23:51 (GMT) |
commit | 1f455361ecfb1892e375bdbee813cdf095b6cfb8 (patch) | |
tree | d7def4d5d167965a45c4b0e30bb5a1a0bb5c3b4a /Python/symtable.c | |
parent | cff4d5c5d29528299ec1ac5b3b3a6f7735577c01 (diff) | |
download | cpython-1f455361ecfb1892e375bdbee813cdf095b6cfb8.zip cpython-1f455361ecfb1892e375bdbee813cdf095b6cfb8.tar.gz cpython-1f455361ecfb1892e375bdbee813cdf095b6cfb8.tar.bz2 |
bpo-46765: Replace Locally Cached Strings with Statically Initialized Objects (gh-31366)
https://bugs.python.org/issue46765
Diffstat (limited to 'Python/symtable.c')
-rw-r--r-- | Python/symtable.c | 50 |
1 files changed, 11 insertions, 39 deletions
diff --git a/Python/symtable.c b/Python/symtable.c index e9bdff3..0b259b0 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -230,13 +230,6 @@ static int symtable_raise_if_annotation_block(struct symtable *st, const char *, static int symtable_raise_if_comprehension_block(struct symtable *st, expr_ty); -static identifier top = NULL, lambda = NULL, genexpr = NULL, - listcomp = NULL, setcomp = NULL, dictcomp = NULL, - __class__ = NULL, _annotation = NULL; - -#define GET_IDENTIFIER(VAR) \ - ((VAR) ? (VAR) : ((VAR) = PyUnicode_InternFromString(# VAR))) - #define DUPLICATE_ARGUMENT \ "duplicate argument '%U' in function definition" @@ -313,8 +306,7 @@ _PySymtable_Build(mod_ty mod, PyObject *filename, PyFutureFeatures *future) recursion_limit * COMPILER_STACK_FRAME_SCALE : recursion_limit; /* Make the initial symbol information gathering pass */ - if (!GET_IDENTIFIER(top) || - !symtable_enter_block(st, top, ModuleBlock, (void *)mod, 0, 0, 0, 0)) { + if (!symtable_enter_block(st, &_Py_ID(top), ModuleBlock, (void *)mod, 0, 0, 0, 0)) { _PySymtable_Free(st); return NULL; } @@ -619,9 +611,7 @@ static int drop_class_free(PySTEntryObject *ste, PyObject *free) { int res; - if (!GET_IDENTIFIER(__class__)) - return 0; - res = PySet_Discard(free, __class__); + res = PySet_Discard(free, &_Py_ID(__class__)); if (res < 0) return 0; if (res) @@ -834,9 +824,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free, } else { /* Special-case __class__ */ - if (!GET_IDENTIFIER(__class__)) - goto error; - if (PySet_Add(newbound, __class__) < 0) + if (PySet_Add(newbound, &_Py_ID(__class__)) < 0) goto error; } @@ -1610,13 +1598,11 @@ symtable_visit_expr(struct symtable *st, expr_ty e) VISIT(st, expr, e->v.UnaryOp.operand); break; case Lambda_kind: { - if (!GET_IDENTIFIER(lambda)) - VISIT_QUIT(st, 0); if (e->v.Lambda.args->defaults) VISIT_SEQ(st, expr, e->v.Lambda.args->defaults); if (e->v.Lambda.args->kw_defaults) VISIT_SEQ_WITH_NULL(st, expr, e->v.Lambda.args->kw_defaults); - if (!symtable_enter_block(st, lambda, + if (!symtable_enter_block(st, &_Py_ID(lambda), FunctionBlock, (void *)e, e->lineno, e->col_offset, e->end_lineno, e->end_col_offset)) @@ -1730,8 +1716,7 @@ symtable_visit_expr(struct symtable *st, expr_ty e) if (e->v.Name.ctx == Load && st->st_cur->ste_type == FunctionBlock && _PyUnicode_EqualToASCIIString(e->v.Name.id, "super")) { - if (!GET_IDENTIFIER(__class__) || - !symtable_add_def(st, __class__, USE, LOCATION(e))) + if (!symtable_add_def(st, &_Py_ID(__class__), USE, LOCATION(e))) VISIT_QUIT(st, 0); } break; @@ -1832,7 +1817,7 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation) { int future_annotations = st->st_future->ff_features & CO_FUTURE_ANNOTATIONS; if (future_annotations && - !symtable_enter_block(st, GET_IDENTIFIER(_annotation), AnnotationBlock, + !symtable_enter_block(st, &_Py_ID(_annotation), AnnotationBlock, (void *)annotation, annotation->lineno, annotation->col_offset, annotation->end_lineno, annotation->end_col_offset)) { @@ -1867,7 +1852,7 @@ symtable_visit_annotations(struct symtable *st, stmt_ty o, arguments_ty a, expr_ { int future_annotations = st->st_future->ff_features & CO_FUTURE_ANNOTATIONS; if (future_annotations && - !symtable_enter_block(st, GET_IDENTIFIER(_annotation), AnnotationBlock, + !symtable_enter_block(st, &_Py_ID(_annotation), AnnotationBlock, (void *)o, o->lineno, o->col_offset, o->end_lineno, o->end_col_offset)) { VISIT_QUIT(st, 0); @@ -2085,7 +2070,7 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e, static int symtable_visit_genexp(struct symtable *st, expr_ty e) { - return symtable_handle_comprehension(st, e, GET_IDENTIFIER(genexpr), + return symtable_handle_comprehension(st, e, &_Py_ID(genexpr), e->v.GeneratorExp.generators, e->v.GeneratorExp.elt, NULL); } @@ -2093,7 +2078,7 @@ symtable_visit_genexp(struct symtable *st, expr_ty e) static int symtable_visit_listcomp(struct symtable *st, expr_ty e) { - return symtable_handle_comprehension(st, e, GET_IDENTIFIER(listcomp), + return symtable_handle_comprehension(st, e, &_Py_ID(listcomp), e->v.ListComp.generators, e->v.ListComp.elt, NULL); } @@ -2101,7 +2086,7 @@ symtable_visit_listcomp(struct symtable *st, expr_ty e) static int symtable_visit_setcomp(struct symtable *st, expr_ty e) { - return symtable_handle_comprehension(st, e, GET_IDENTIFIER(setcomp), + return symtable_handle_comprehension(st, e, &_Py_ID(setcomp), e->v.SetComp.generators, e->v.SetComp.elt, NULL); } @@ -2109,7 +2094,7 @@ symtable_visit_setcomp(struct symtable *st, expr_ty e) static int symtable_visit_dictcomp(struct symtable *st, expr_ty e) { - return symtable_handle_comprehension(st, e, GET_IDENTIFIER(dictcomp), + return symtable_handle_comprehension(st, e, &_Py_ID(dictcomp), e->v.DictComp.generators, e->v.DictComp.key, e->v.DictComp.value); @@ -2173,16 +2158,3 @@ _Py_SymtableStringObjectFlags(const char *str, PyObject *filename, _PyArena_Free(arena); return st; } - -void -_PySymtable_Fini(void) -{ - Py_CLEAR(top); - Py_CLEAR(lambda); - Py_CLEAR(genexpr); - Py_CLEAR(listcomp); - Py_CLEAR(setcomp); - Py_CLEAR(dictcomp); - Py_CLEAR(__class__); - Py_CLEAR(_annotation); -} |