From 3700a0495f18bccd69874f01d9b9b7733ebea69f Mon Sep 17 00:00:00 2001 From: namaevae Date: Tue, 15 Jul 2025 17:55:21 +0300 Subject: [PATCH 1/7] ? --- Tools/build/generate_global_objects.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Tools/build/generate_global_objects.py b/Tools/build/generate_global_objects.py index 94905b3756d0d8..c030ed6f563603 100644 --- a/Tools/build/generate_global_objects.py +++ b/Tools/build/generate_global_objects.py @@ -131,6 +131,32 @@ 'exc_value', 'self', 'traceback', + + # Syntactic symbols with len() > 2 + '...', + '**', + ':=', + '//', + '==', + '!=', + '>=', + '<=', + '+=', + '-=', + '*=', + '/=', + '//=', + '%=', + '**=', + '<<', + '>>', + '>>>', + '<<=', + '>>=', + '&=', + '|=', + '^=', + '->', ] NON_GENERATED_IMMORTAL_OBJECTS = [ From 44475ecfecc663c9912d8e5177f45e40c86da582 Mon Sep 17 00:00:00 2001 From: Albert N Date: Fri, 10 Oct 2025 14:03:19 +0000 Subject: [PATCH 2/7] testing: will this work or not --- .../pycore_global_objects_fini_generated.h | 24 +++++ Include/internal/pycore_global_strings.h | 24 +++++ .../internal/pycore_runtime_init_generated.h | 24 +++++ .../internal/pycore_unicodeobject_generated.h | 96 +++++++++++++++++++ Tools/build/generate_global_objects.py | 4 +- 5 files changed, 170 insertions(+), 2 deletions(-) diff --git a/Include/internal/pycore_global_objects_fini_generated.h b/Include/internal/pycore_global_objects_fini_generated.h index 1f6b27b14d074b..34e17c88e92f9c 100644 --- a/Include/internal/pycore_global_objects_fini_generated.h +++ b/Include/internal/pycore_global_objects_fini_generated.h @@ -1333,6 +1333,28 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(str_replace_inf)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(type_params)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(utf_8)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(!=)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(%=)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(&=)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(**)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(**=)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(*=)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(+=)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(-=)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(->)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(...)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(//)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(//=)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(/=)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(:=)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(<<)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(<<=)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(<=)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(==)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(>=)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(>>)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(>>=)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(>>>)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(CANCELLED)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(Emax)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(Emin)); @@ -1344,6 +1366,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(TextIOWrapper)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(True)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(WarningMessage)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(^=)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_WindowsConsoleIO)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__IOBase_closed)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__abc_tpflags__)); @@ -2128,6 +2151,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(year)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(zdict)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(zstd_dict)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(|=)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(strings).ascii[0]); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(strings).ascii[1]); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(strings).ascii[2]); diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 6959343947c1f4..cc567942081ffc 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -56,6 +56,28 @@ struct _Py_global_strings { } literals; struct { + STRUCT_FOR_ID(!=) + STRUCT_FOR_ID(%=) + STRUCT_FOR_ID(&=) + STRUCT_FOR_ID(**) + STRUCT_FOR_ID(**=) + STRUCT_FOR_ID(*=) + STRUCT_FOR_ID(+=) + STRUCT_FOR_ID(-=) + STRUCT_FOR_ID(->) + STRUCT_FOR_ID(...) + STRUCT_FOR_ID(//) + STRUCT_FOR_ID(//=) + STRUCT_FOR_ID(/=) + STRUCT_FOR_ID(:=) + STRUCT_FOR_ID(<<) + STRUCT_FOR_ID(<<=) + STRUCT_FOR_ID(<=) + STRUCT_FOR_ID(==) + STRUCT_FOR_ID(>=) + STRUCT_FOR_ID(>>) + STRUCT_FOR_ID(>>=) + STRUCT_FOR_ID(>>>) STRUCT_FOR_ID(CANCELLED) STRUCT_FOR_ID(Emax) STRUCT_FOR_ID(Emin) @@ -67,6 +89,7 @@ struct _Py_global_strings { STRUCT_FOR_ID(TextIOWrapper) STRUCT_FOR_ID(True) STRUCT_FOR_ID(WarningMessage) + STRUCT_FOR_ID(^=) STRUCT_FOR_ID(_WindowsConsoleIO) STRUCT_FOR_ID(__IOBase_closed) STRUCT_FOR_ID(__abc_tpflags__) @@ -851,6 +874,7 @@ struct _Py_global_strings { STRUCT_FOR_ID(year) STRUCT_FOR_ID(zdict) STRUCT_FOR_ID(zstd_dict) + STRUCT_FOR_ID(|=) } identifiers; struct { PyASCIIObject _ascii; diff --git a/Include/internal/pycore_runtime_init_generated.h b/Include/internal/pycore_runtime_init_generated.h index be4eae42b5de1b..34530058738c9c 100644 --- a/Include/internal/pycore_runtime_init_generated.h +++ b/Include/internal/pycore_runtime_init_generated.h @@ -1331,6 +1331,28 @@ extern "C" { } #define _Py_str_identifiers_INIT { \ + INIT_ID(!=), \ + INIT_ID(%=), \ + INIT_ID(&=), \ + INIT_ID(**), \ + INIT_ID(**=), \ + INIT_ID(*=), \ + INIT_ID(+=), \ + INIT_ID(-=), \ + INIT_ID(->), \ + INIT_ID(...), \ + INIT_ID(//), \ + INIT_ID(//=), \ + INIT_ID(/=), \ + INIT_ID(:=), \ + INIT_ID(<<), \ + INIT_ID(<<=), \ + INIT_ID(<=), \ + INIT_ID(==), \ + INIT_ID(>=), \ + INIT_ID(>>), \ + INIT_ID(>>=), \ + INIT_ID(>>>), \ INIT_ID(CANCELLED), \ INIT_ID(Emax), \ INIT_ID(Emin), \ @@ -1342,6 +1364,7 @@ extern "C" { INIT_ID(TextIOWrapper), \ INIT_ID(True), \ INIT_ID(WarningMessage), \ + INIT_ID(^=), \ INIT_ID(_WindowsConsoleIO), \ INIT_ID(__IOBase_closed), \ INIT_ID(__abc_tpflags__), \ @@ -2126,6 +2149,7 @@ extern "C" { INIT_ID(year), \ INIT_ID(zdict), \ INIT_ID(zstd_dict), \ + INIT_ID(|=), \ } #define _Py_str_ascii_INIT { \ diff --git a/Include/internal/pycore_unicodeobject_generated.h b/Include/internal/pycore_unicodeobject_generated.h index 45b00a20a07dda..5214716ce26059 100644 --- a/Include/internal/pycore_unicodeobject_generated.h +++ b/Include/internal/pycore_unicodeobject_generated.h @@ -12,6 +12,94 @@ extern "C" { static inline void _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { PyObject *string; + string = &_Py_ID(!=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(%=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(&=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(**); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(**=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(*=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(+=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(-=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(->); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(...); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(//); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(//=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(/=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(:=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(<<); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(<<=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(<=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(==); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(>=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(>>); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(>>=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(>>>); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_ID(CANCELLED); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); @@ -56,6 +144,10 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(^=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_ID(_WindowsConsoleIO); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); @@ -3192,6 +3284,10 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(|=); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_STR(empty); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); diff --git a/Tools/build/generate_global_objects.py b/Tools/build/generate_global_objects.py index c030ed6f563603..7204366da9c3bd 100644 --- a/Tools/build/generate_global_objects.py +++ b/Tools/build/generate_global_objects.py @@ -287,7 +287,7 @@ def generate_global_strings(identifiers, strings): outfile.write('\n') with printer.block('struct', ' identifiers;'): for name in sorted(identifiers): - assert name.isidentifier(), name + # assert name.isidentifier(), name printer.write(f'STRUCT_FOR_ID({name})') with printer.block('struct', ' ascii[128];'): printer.write("PyASCIIObject _ascii;") @@ -350,7 +350,7 @@ def generate_runtime_init(identifiers, strings): printer.write('') with printer.block('#define _Py_str_identifiers_INIT', continuation=True): for name in sorted(identifiers): - assert name.isidentifier(), name + # assert name.isidentifier(), name printer.write(f'INIT_ID({name}),') immortal_objects.append(f'(PyObject *)&_Py_ID({name})') printer.write('') From 63000ab589231d863f0fa14678d1dda2c2710de4 Mon Sep 17 00:00:00 2001 From: Albert N Date: Fri, 17 Oct 2025 08:26:23 +0000 Subject: [PATCH 3/7] I'm not sure how where to put `_Py_DECLARE_STR` --- .../pycore_global_objects_fini_generated.h | 49 ++--- Include/internal/pycore_global_strings.h | 49 ++--- .../internal/pycore_runtime_init_generated.h | 49 ++--- .../internal/pycore_unicodeobject_generated.h | 192 +++++++++--------- Tools/build/generate_global_objects.py | 54 ++--- 5 files changed, 200 insertions(+), 193 deletions(-) diff --git a/Include/internal/pycore_global_objects_fini_generated.h b/Include/internal/pycore_global_objects_fini_generated.h index 34e17c88e92f9c..cab3624d802ade 100644 --- a/Include/internal/pycore_global_objects_fini_generated.h +++ b/Include/internal/pycore_global_objects_fini_generated.h @@ -1310,6 +1310,31 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(bytes_characters)[253]); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(bytes_characters)[254]); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(bytes_characters)[255]); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(AMPEREQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(ATEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(CIRCUMFLEXEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(COLONEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(DOUBLESLASH)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(DOUBLESLASHEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(DOUBLESTAR)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(DOUBLESTAREQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(ELLIPSIS)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(EQEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(GREATEREQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(LEFTSHIFT)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(LEFTSHIFTEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(LESSEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(MINEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(NOTEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(PERCENTEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(PLUSEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(RARROW)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(REPLSHIFT)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(RIGHTSHIFT)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(RIGHTSHIFTEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(SLASHEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(STAREQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(VBAREQUAL)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(anon_dictcomp)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(anon_genexpr)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(anon_lambda)); @@ -1333,28 +1358,6 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(str_replace_inf)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(type_params)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(utf_8)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(!=)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(%=)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(&=)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(**)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(**=)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(*=)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(+=)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(-=)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(->)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(...)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(//)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(//=)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(/=)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(:=)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(<<)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(<<=)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(<=)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(==)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(>=)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(>>)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(>>=)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(>>>)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(CANCELLED)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(Emax)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(Emin)); @@ -1366,7 +1369,6 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(TextIOWrapper)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(True)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(WarningMessage)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(^=)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_WindowsConsoleIO)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__IOBase_closed)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__abc_tpflags__)); @@ -2151,7 +2153,6 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(year)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(zdict)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(zstd_dict)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(|=)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(strings).ascii[0]); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(strings).ascii[1]); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(strings).ascii[2]); diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index cc567942081ffc..10a856fade753c 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -30,6 +30,31 @@ extern "C" { /* The following is auto-generated by Tools/build/generate_global_objects.py. */ struct _Py_global_strings { struct { + STRUCT_FOR_STR(AMPEREQUAL, "&=") + STRUCT_FOR_STR(ATEQUAL, "@=") + STRUCT_FOR_STR(CIRCUMFLEXEQUAL, "^=") + STRUCT_FOR_STR(COLONEQUAL, ":=") + STRUCT_FOR_STR(DOUBLESLASH, "//") + STRUCT_FOR_STR(DOUBLESLASHEQUAL, "//=") + STRUCT_FOR_STR(DOUBLESTAR, "**") + STRUCT_FOR_STR(DOUBLESTAREQUAL, "**=") + STRUCT_FOR_STR(ELLIPSIS, "...") + STRUCT_FOR_STR(EQEQUAL, "==") + STRUCT_FOR_STR(GREATEREQUAL, ">=") + STRUCT_FOR_STR(LEFTSHIFT, "<<") + STRUCT_FOR_STR(LEFTSHIFTEQUAL, "<<=") + STRUCT_FOR_STR(LESSEQUAL, "<=") + STRUCT_FOR_STR(MINEQUAL, "-=") + STRUCT_FOR_STR(NOTEQUAL, "!=") + STRUCT_FOR_STR(PERCENTEQUAL, "%=") + STRUCT_FOR_STR(PLUSEQUAL, "+=") + STRUCT_FOR_STR(RARROW, "->") + STRUCT_FOR_STR(REPLSHIFT, ">>>") + STRUCT_FOR_STR(RIGHTSHIFT, ">>") + STRUCT_FOR_STR(RIGHTSHIFTEQUAL, ">>=") + STRUCT_FOR_STR(SLASHEQUAL, "/=") + STRUCT_FOR_STR(STAREQUAL, "*=") + STRUCT_FOR_STR(VBAREQUAL, "|=") STRUCT_FOR_STR(anon_dictcomp, "") STRUCT_FOR_STR(anon_genexpr, "") STRUCT_FOR_STR(anon_lambda, "") @@ -56,28 +81,6 @@ struct _Py_global_strings { } literals; struct { - STRUCT_FOR_ID(!=) - STRUCT_FOR_ID(%=) - STRUCT_FOR_ID(&=) - STRUCT_FOR_ID(**) - STRUCT_FOR_ID(**=) - STRUCT_FOR_ID(*=) - STRUCT_FOR_ID(+=) - STRUCT_FOR_ID(-=) - STRUCT_FOR_ID(->) - STRUCT_FOR_ID(...) - STRUCT_FOR_ID(//) - STRUCT_FOR_ID(//=) - STRUCT_FOR_ID(/=) - STRUCT_FOR_ID(:=) - STRUCT_FOR_ID(<<) - STRUCT_FOR_ID(<<=) - STRUCT_FOR_ID(<=) - STRUCT_FOR_ID(==) - STRUCT_FOR_ID(>=) - STRUCT_FOR_ID(>>) - STRUCT_FOR_ID(>>=) - STRUCT_FOR_ID(>>>) STRUCT_FOR_ID(CANCELLED) STRUCT_FOR_ID(Emax) STRUCT_FOR_ID(Emin) @@ -89,7 +92,6 @@ struct _Py_global_strings { STRUCT_FOR_ID(TextIOWrapper) STRUCT_FOR_ID(True) STRUCT_FOR_ID(WarningMessage) - STRUCT_FOR_ID(^=) STRUCT_FOR_ID(_WindowsConsoleIO) STRUCT_FOR_ID(__IOBase_closed) STRUCT_FOR_ID(__abc_tpflags__) @@ -874,7 +876,6 @@ struct _Py_global_strings { STRUCT_FOR_ID(year) STRUCT_FOR_ID(zdict) STRUCT_FOR_ID(zstd_dict) - STRUCT_FOR_ID(|=) } identifiers; struct { PyASCIIObject _ascii; diff --git a/Include/internal/pycore_runtime_init_generated.h b/Include/internal/pycore_runtime_init_generated.h index 34530058738c9c..54ff2a18445154 100644 --- a/Include/internal/pycore_runtime_init_generated.h +++ b/Include/internal/pycore_runtime_init_generated.h @@ -1305,6 +1305,31 @@ extern "C" { } #define _Py_str_literals_INIT { \ + INIT_STR(AMPEREQUAL, "&="), \ + INIT_STR(ATEQUAL, "@="), \ + INIT_STR(CIRCUMFLEXEQUAL, "^="), \ + INIT_STR(COLONEQUAL, ":="), \ + INIT_STR(DOUBLESLASH, "//"), \ + INIT_STR(DOUBLESLASHEQUAL, "//="), \ + INIT_STR(DOUBLESTAR, "**"), \ + INIT_STR(DOUBLESTAREQUAL, "**="), \ + INIT_STR(ELLIPSIS, "..."), \ + INIT_STR(EQEQUAL, "=="), \ + INIT_STR(GREATEREQUAL, ">="), \ + INIT_STR(LEFTSHIFT, "<<"), \ + INIT_STR(LEFTSHIFTEQUAL, "<<="), \ + INIT_STR(LESSEQUAL, "<="), \ + INIT_STR(MINEQUAL, "-="), \ + INIT_STR(NOTEQUAL, "!="), \ + INIT_STR(PERCENTEQUAL, "%="), \ + INIT_STR(PLUSEQUAL, "+="), \ + INIT_STR(RARROW, "->"), \ + INIT_STR(REPLSHIFT, ">>>"), \ + INIT_STR(RIGHTSHIFT, ">>"), \ + INIT_STR(RIGHTSHIFTEQUAL, ">>="), \ + INIT_STR(SLASHEQUAL, "/="), \ + INIT_STR(STAREQUAL, "*="), \ + INIT_STR(VBAREQUAL, "|="), \ INIT_STR(anon_dictcomp, ""), \ INIT_STR(anon_genexpr, ""), \ INIT_STR(anon_lambda, ""), \ @@ -1331,28 +1356,6 @@ extern "C" { } #define _Py_str_identifiers_INIT { \ - INIT_ID(!=), \ - INIT_ID(%=), \ - INIT_ID(&=), \ - INIT_ID(**), \ - INIT_ID(**=), \ - INIT_ID(*=), \ - INIT_ID(+=), \ - INIT_ID(-=), \ - INIT_ID(->), \ - INIT_ID(...), \ - INIT_ID(//), \ - INIT_ID(//=), \ - INIT_ID(/=), \ - INIT_ID(:=), \ - INIT_ID(<<), \ - INIT_ID(<<=), \ - INIT_ID(<=), \ - INIT_ID(==), \ - INIT_ID(>=), \ - INIT_ID(>>), \ - INIT_ID(>>=), \ - INIT_ID(>>>), \ INIT_ID(CANCELLED), \ INIT_ID(Emax), \ INIT_ID(Emin), \ @@ -1364,7 +1367,6 @@ extern "C" { INIT_ID(TextIOWrapper), \ INIT_ID(True), \ INIT_ID(WarningMessage), \ - INIT_ID(^=), \ INIT_ID(_WindowsConsoleIO), \ INIT_ID(__IOBase_closed), \ INIT_ID(__abc_tpflags__), \ @@ -2149,7 +2151,6 @@ extern "C" { INIT_ID(year), \ INIT_ID(zdict), \ INIT_ID(zstd_dict), \ - INIT_ID(|=), \ } #define _Py_str_ascii_INIT { \ diff --git a/Include/internal/pycore_unicodeobject_generated.h b/Include/internal/pycore_unicodeobject_generated.h index 5214716ce26059..b7fbbd9fade2c9 100644 --- a/Include/internal/pycore_unicodeobject_generated.h +++ b/Include/internal/pycore_unicodeobject_generated.h @@ -12,94 +12,6 @@ extern "C" { static inline void _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { PyObject *string; - string = &_Py_ID(!=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(%=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(&=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(**); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(**=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(*=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(+=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(-=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(->); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(...); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(//); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(//=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(/=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(:=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(<<); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(<<=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(<=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(==); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(>=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(>>); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(>>=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(>>>); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_ID(CANCELLED); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); @@ -144,10 +56,6 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(^=); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_ID(_WindowsConsoleIO); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); @@ -3284,11 +3192,11 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_ID(|=); + string = &_Py_STR(empty); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_STR(empty); + string = &_Py_STR(NOTEQUAL); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); @@ -3296,6 +3204,42 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(PERCENTEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(AMPEREQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(DOUBLESTAR); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(DOUBLESTAREQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(STAREQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(PLUSEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(MINEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(RARROW); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(ELLIPSIS); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_STR(dot_locals); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); @@ -3320,10 +3264,38 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(DOUBLESLASH); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(DOUBLESLASHEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(SLASHEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_STR(str_replace_inf); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(COLONEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(LEFTSHIFT); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(LEFTSHIFTEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(LESSEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_STR(anon_null); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); @@ -3360,6 +3332,34 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(EQEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(GREATEREQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(RIGHTSHIFT); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(RIGHTSHIFTEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(REPLSHIFT); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(ATEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(CIRCUMFLEXEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_STR(json_decoder); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); @@ -3376,6 +3376,10 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_STR(VBAREQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_STR(dbl_close_br); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); diff --git a/Tools/build/generate_global_objects.py b/Tools/build/generate_global_objects.py index 7204366da9c3bd..f88e7da9e1b6aa 100644 --- a/Tools/build/generate_global_objects.py +++ b/Tools/build/generate_global_objects.py @@ -131,32 +131,6 @@ 'exc_value', 'self', 'traceback', - - # Syntactic symbols with len() > 2 - '...', - '**', - ':=', - '//', - '==', - '!=', - '>=', - '<=', - '+=', - '-=', - '*=', - '/=', - '//=', - '%=', - '**=', - '<<', - '>>', - '>>>', - '<<=', - '>>=', - '&=', - '|=', - '^=', - '->', ] NON_GENERATED_IMMORTAL_OBJECTS = [ @@ -479,7 +453,33 @@ def get_identifiers_and_strings() -> 'tuple[set[str], dict[str, str]]': def main() -> None: identifiers, strings = get_identifiers_and_strings() - + strings.update([ + ("==", "EQEQUAL"), + ("!=", "NOTEQUAL"), + ("<=", "LESSEQUAL"), + (">=", "GREATEREQUAL"), + ("<<", "LEFTSHIFT"), + (">>", "RIGHTSHIFT"), + ("**", "DOUBLESTAR"), + ("+=", "PLUSEQUAL"), + ("-=", "MINEQUAL"), + ("*=", "STAREQUAL"), + ("/=", "SLASHEQUAL"), + ("%=", "PERCENTEQUAL"), + ("&=", "AMPEREQUAL"), + ("|=", "VBAREQUAL"), + ("^=", "CIRCUMFLEXEQUAL"), + ("<<=", "LEFTSHIFTEQUAL"), + (">>=", "RIGHTSHIFTEQUAL"), + ("**=", "DOUBLESTAREQUAL"), + ("//", "DOUBLESLASH"), + ("//=", "DOUBLESLASHEQUAL"), + ("@=", "ATEQUAL"), + ("->", "RARROW"), + ("...", "ELLIPSIS"), + (":=", "COLONEQUAL"), + (">>>", "REPLSHIFT"), + ]) generate_global_strings(identifiers, strings) generated_immortal_objects = generate_runtime_init(identifiers, strings) generate_static_strings_initializer(identifiers, strings) From 2ab472b97a1108f4fed7d3d4004c3ebf5b0d07d2 Mon Sep 17 00:00:00 2001 From: Albert N Date: Fri, 17 Oct 2025 13:29:46 +0000 Subject: [PATCH 4/7] in token.c --- .../pycore_global_objects_fini_generated.h | 1 - Include/internal/pycore_global_strings.h | 1 - .../internal/pycore_runtime_init_generated.h | 1 - .../internal/pycore_unicodeobject_generated.h | 4 --- Parser/token.c | 29 ++++++++++++++++- Tools/build/generate_global_objects.py | 31 ++----------------- Tools/build/generate_token.py | 22 ++++++++++++- 7 files changed, 51 insertions(+), 38 deletions(-) diff --git a/Include/internal/pycore_global_objects_fini_generated.h b/Include/internal/pycore_global_objects_fini_generated.h index cab3624d802ade..a90f3211866937 100644 --- a/Include/internal/pycore_global_objects_fini_generated.h +++ b/Include/internal/pycore_global_objects_fini_generated.h @@ -1329,7 +1329,6 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(PERCENTEQUAL)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(PLUSEQUAL)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(RARROW)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(REPLSHIFT)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(RIGHTSHIFT)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(RIGHTSHIFTEQUAL)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(SLASHEQUAL)); diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 10a856fade753c..4b5131666aff73 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -49,7 +49,6 @@ struct _Py_global_strings { STRUCT_FOR_STR(PERCENTEQUAL, "%=") STRUCT_FOR_STR(PLUSEQUAL, "+=") STRUCT_FOR_STR(RARROW, "->") - STRUCT_FOR_STR(REPLSHIFT, ">>>") STRUCT_FOR_STR(RIGHTSHIFT, ">>") STRUCT_FOR_STR(RIGHTSHIFTEQUAL, ">>=") STRUCT_FOR_STR(SLASHEQUAL, "/=") diff --git a/Include/internal/pycore_runtime_init_generated.h b/Include/internal/pycore_runtime_init_generated.h index 54ff2a18445154..895ef7048f72e1 100644 --- a/Include/internal/pycore_runtime_init_generated.h +++ b/Include/internal/pycore_runtime_init_generated.h @@ -1324,7 +1324,6 @@ extern "C" { INIT_STR(PERCENTEQUAL, "%="), \ INIT_STR(PLUSEQUAL, "+="), \ INIT_STR(RARROW, "->"), \ - INIT_STR(REPLSHIFT, ">>>"), \ INIT_STR(RIGHTSHIFT, ">>"), \ INIT_STR(RIGHTSHIFTEQUAL, ">>="), \ INIT_STR(SLASHEQUAL, "/="), \ diff --git a/Include/internal/pycore_unicodeobject_generated.h b/Include/internal/pycore_unicodeobject_generated.h index b7fbbd9fade2c9..ee9483a8da5f2d 100644 --- a/Include/internal/pycore_unicodeobject_generated.h +++ b/Include/internal/pycore_unicodeobject_generated.h @@ -3348,10 +3348,6 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); - string = &_Py_STR(REPLSHIFT); - _PyUnicode_InternStatic(interp, &string); - assert(_PyUnicode_CheckConsistency(string, 1)); - assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_STR(ATEQUAL); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); diff --git a/Parser/token.c b/Parser/token.c index a6e7ce35dfad85..dc2ca9bd797c1c 100644 --- a/Parser/token.c +++ b/Parser/token.c @@ -2,6 +2,34 @@ #include "Python.h" #include "pycore_token.h" +#include "pycore_global_strings.h" + +/* Interning tokens */ + +_Py_DECLARE_STR(EQEQUAL, "=="); +_Py_DECLARE_STR(NOTEQUAL, "!="); +_Py_DECLARE_STR(LESSEQUAL, "<="); +_Py_DECLARE_STR(GREATEREQUAL, ">="); +_Py_DECLARE_STR(LEFTSHIFT, "<<"); +_Py_DECLARE_STR(RIGHTSHIFT, ">>"); +_Py_DECLARE_STR(DOUBLESTAR, "**"); +_Py_DECLARE_STR(PLUSEQUAL, "+="); +_Py_DECLARE_STR(MINEQUAL, "-="); +_Py_DECLARE_STR(STAREQUAL, "*="); +_Py_DECLARE_STR(SLASHEQUAL, "/="); +_Py_DECLARE_STR(PERCENTEQUAL, "%="); +_Py_DECLARE_STR(AMPEREQUAL, "&="); +_Py_DECLARE_STR(VBAREQUAL, "|="); +_Py_DECLARE_STR(CIRCUMFLEXEQUAL, "^="); +_Py_DECLARE_STR(LEFTSHIFTEQUAL, "<<="); +_Py_DECLARE_STR(RIGHTSHIFTEQUAL, ">>="); +_Py_DECLARE_STR(DOUBLESTAREQUAL, "**="); +_Py_DECLARE_STR(DOUBLESLASH, "//"); +_Py_DECLARE_STR(DOUBLESLASHEQUAL, "//="); +_Py_DECLARE_STR(ATEQUAL, "@="); +_Py_DECLARE_STR(RARROW, "->"); +_Py_DECLARE_STR(ELLIPSIS, "..."); +_Py_DECLARE_STR(COLONEQUAL, ":="); /* Token names */ @@ -163,7 +191,6 @@ _PyToken_TwoChars(int c1, int c2) switch (c2) { case '<': return LEFTSHIFT; case '=': return LESSEQUAL; - case '>': return NOTEQUAL; } break; case '=': diff --git a/Tools/build/generate_global_objects.py b/Tools/build/generate_global_objects.py index f88e7da9e1b6aa..47667fffba4621 100644 --- a/Tools/build/generate_global_objects.py +++ b/Tools/build/generate_global_objects.py @@ -261,7 +261,7 @@ def generate_global_strings(identifiers, strings): outfile.write('\n') with printer.block('struct', ' identifiers;'): for name in sorted(identifiers): - # assert name.isidentifier(), name + assert name.isidentifier(), name printer.write(f'STRUCT_FOR_ID({name})') with printer.block('struct', ' ascii[128];'): printer.write("PyASCIIObject _ascii;") @@ -324,7 +324,7 @@ def generate_runtime_init(identifiers, strings): printer.write('') with printer.block('#define _Py_str_identifiers_INIT', continuation=True): for name in sorted(identifiers): - # assert name.isidentifier(), name + assert name.isidentifier(), name printer.write(f'INIT_ID({name}),') immortal_objects.append(f'(PyObject *)&_Py_ID({name})') printer.write('') @@ -453,33 +453,6 @@ def get_identifiers_and_strings() -> 'tuple[set[str], dict[str, str]]': def main() -> None: identifiers, strings = get_identifiers_and_strings() - strings.update([ - ("==", "EQEQUAL"), - ("!=", "NOTEQUAL"), - ("<=", "LESSEQUAL"), - (">=", "GREATEREQUAL"), - ("<<", "LEFTSHIFT"), - (">>", "RIGHTSHIFT"), - ("**", "DOUBLESTAR"), - ("+=", "PLUSEQUAL"), - ("-=", "MINEQUAL"), - ("*=", "STAREQUAL"), - ("/=", "SLASHEQUAL"), - ("%=", "PERCENTEQUAL"), - ("&=", "AMPEREQUAL"), - ("|=", "VBAREQUAL"), - ("^=", "CIRCUMFLEXEQUAL"), - ("<<=", "LEFTSHIFTEQUAL"), - (">>=", "RIGHTSHIFTEQUAL"), - ("**=", "DOUBLESTAREQUAL"), - ("//", "DOUBLESLASH"), - ("//=", "DOUBLESLASHEQUAL"), - ("@=", "ATEQUAL"), - ("->", "RARROW"), - ("...", "ELLIPSIS"), - (":=", "COLONEQUAL"), - (">>>", "REPLSHIFT"), - ]) generate_global_strings(identifiers, strings) generated_immortal_objects = generate_runtime_init(identifiers, strings) generate_static_strings_initializer(identifiers, strings) diff --git a/Tools/build/generate_token.py b/Tools/build/generate_token.py index 9ee5ec86e75d47..4a3119e556b17b 100755 --- a/Tools/build/generate_token.py +++ b/Tools/build/generate_token.py @@ -125,6 +125,12 @@ def make_h(infile, outfile='Include/internal/pycore_token.h'): #include "Python.h" #include "pycore_token.h" +#include "pycore_global_strings.h" + +/* Interning tokens */ + +%s\ + /* Token names */ @@ -176,10 +182,23 @@ def generate_chars_to_token(mapping, n=1): write('}\n') return ''.join(result) +def declate_tokens(tok_name_to_string): + return "\n".join( + f'_Py_DECLARE_STR({name}, "{token}");' + for name, token in tok_name_to_string.items() + ) + + def make_c(infile, outfile='Parser/token.c'): tok_names, ERRORTOKEN, string_to_tok = load_tokens(infile) - string_to_tok['<>'] = string_to_tok['!='] + # string_to_tok['<>'] = string_to_tok['!='] chars_to_token = {} + tok_name_to_string = { + tok_names[name_idx]: token + for token, name_idx in string_to_tok.items() + if len(token) > 1 + } + for string, value in string_to_tok.items(): assert 1 <= len(string) <= 3 name = tok_names[value] @@ -196,6 +215,7 @@ def make_c(infile, outfile='Parser/token.c'): names.append(' "",\n') if update_file(outfile, token_c_template % ( + declate_tokens(tok_name_to_string), ''.join(names), generate_chars_to_token(chars_to_token[1]), generate_chars_to_token(chars_to_token[2]), From b7e9668889e564ca84aff1105282234104a89793 Mon Sep 17 00:00:00 2001 From: Albert N Date: Fri, 17 Oct 2025 14:04:07 +0000 Subject: [PATCH 5/7] ? --- .../pycore_global_objects_fini_generated.h | 24 +++++ Include/internal/pycore_global_strings.h | 24 +++++ .../internal/pycore_runtime_init_generated.h | 24 +++++ .../internal/pycore_unicodeobject_generated.h | 96 +++++++++++++++++++ Tools/build/generate_global_objects.py | 25 +++++ 5 files changed, 193 insertions(+) diff --git a/Include/internal/pycore_global_objects_fini_generated.h b/Include/internal/pycore_global_objects_fini_generated.h index a90f3211866937..fefe878949a8e7 100644 --- a/Include/internal/pycore_global_objects_fini_generated.h +++ b/Include/internal/pycore_global_objects_fini_generated.h @@ -1357,16 +1357,40 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(str_replace_inf)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(type_params)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_STR(utf_8)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(AMPEREQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(ATEQUAL)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(CANCELLED)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(CIRCUMFLEXEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(COLONEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(DOUBLESLASH)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(DOUBLESLASHEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(DOUBLESTAR)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(DOUBLESTAREQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(ELLIPSIS)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(EQEQUAL)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(Emax)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(Emin)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(FINISHED)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(False)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(GREATEREQUAL)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(JSONDecodeError)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(LEFTSHIFT)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(LEFTSHIFTEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(LESSEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(MINEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(NOTEQUAL)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(PENDING)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(PERCENTEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(PLUSEQUAL)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(Py_Repr)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(RARROW)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(RIGHTSHIFT)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(RIGHTSHIFTEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(SLASHEQUAL)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(STAREQUAL)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(TextIOWrapper)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(True)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(VBAREQUAL)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(WarningMessage)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_WindowsConsoleIO)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__IOBase_closed)); diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 4b5131666aff73..8749daeaf732d5 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -80,16 +80,40 @@ struct _Py_global_strings { } literals; struct { + STRUCT_FOR_ID(AMPEREQUAL) + STRUCT_FOR_ID(ATEQUAL) STRUCT_FOR_ID(CANCELLED) + STRUCT_FOR_ID(CIRCUMFLEXEQUAL) + STRUCT_FOR_ID(COLONEQUAL) + STRUCT_FOR_ID(DOUBLESLASH) + STRUCT_FOR_ID(DOUBLESLASHEQUAL) + STRUCT_FOR_ID(DOUBLESTAR) + STRUCT_FOR_ID(DOUBLESTAREQUAL) + STRUCT_FOR_ID(ELLIPSIS) + STRUCT_FOR_ID(EQEQUAL) STRUCT_FOR_ID(Emax) STRUCT_FOR_ID(Emin) STRUCT_FOR_ID(FINISHED) STRUCT_FOR_ID(False) + STRUCT_FOR_ID(GREATEREQUAL) STRUCT_FOR_ID(JSONDecodeError) + STRUCT_FOR_ID(LEFTSHIFT) + STRUCT_FOR_ID(LEFTSHIFTEQUAL) + STRUCT_FOR_ID(LESSEQUAL) + STRUCT_FOR_ID(MINEQUAL) + STRUCT_FOR_ID(NOTEQUAL) STRUCT_FOR_ID(PENDING) + STRUCT_FOR_ID(PERCENTEQUAL) + STRUCT_FOR_ID(PLUSEQUAL) STRUCT_FOR_ID(Py_Repr) + STRUCT_FOR_ID(RARROW) + STRUCT_FOR_ID(RIGHTSHIFT) + STRUCT_FOR_ID(RIGHTSHIFTEQUAL) + STRUCT_FOR_ID(SLASHEQUAL) + STRUCT_FOR_ID(STAREQUAL) STRUCT_FOR_ID(TextIOWrapper) STRUCT_FOR_ID(True) + STRUCT_FOR_ID(VBAREQUAL) STRUCT_FOR_ID(WarningMessage) STRUCT_FOR_ID(_WindowsConsoleIO) STRUCT_FOR_ID(__IOBase_closed) diff --git a/Include/internal/pycore_runtime_init_generated.h b/Include/internal/pycore_runtime_init_generated.h index 895ef7048f72e1..fd96fb92d8c56d 100644 --- a/Include/internal/pycore_runtime_init_generated.h +++ b/Include/internal/pycore_runtime_init_generated.h @@ -1355,16 +1355,40 @@ extern "C" { } #define _Py_str_identifiers_INIT { \ + INIT_ID(AMPEREQUAL), \ + INIT_ID(ATEQUAL), \ INIT_ID(CANCELLED), \ + INIT_ID(CIRCUMFLEXEQUAL), \ + INIT_ID(COLONEQUAL), \ + INIT_ID(DOUBLESLASH), \ + INIT_ID(DOUBLESLASHEQUAL), \ + INIT_ID(DOUBLESTAR), \ + INIT_ID(DOUBLESTAREQUAL), \ + INIT_ID(ELLIPSIS), \ + INIT_ID(EQEQUAL), \ INIT_ID(Emax), \ INIT_ID(Emin), \ INIT_ID(FINISHED), \ INIT_ID(False), \ + INIT_ID(GREATEREQUAL), \ INIT_ID(JSONDecodeError), \ + INIT_ID(LEFTSHIFT), \ + INIT_ID(LEFTSHIFTEQUAL), \ + INIT_ID(LESSEQUAL), \ + INIT_ID(MINEQUAL), \ + INIT_ID(NOTEQUAL), \ INIT_ID(PENDING), \ + INIT_ID(PERCENTEQUAL), \ + INIT_ID(PLUSEQUAL), \ INIT_ID(Py_Repr), \ + INIT_ID(RARROW), \ + INIT_ID(RIGHTSHIFT), \ + INIT_ID(RIGHTSHIFTEQUAL), \ + INIT_ID(SLASHEQUAL), \ + INIT_ID(STAREQUAL), \ INIT_ID(TextIOWrapper), \ INIT_ID(True), \ + INIT_ID(VBAREQUAL), \ INIT_ID(WarningMessage), \ INIT_ID(_WindowsConsoleIO), \ INIT_ID(__IOBase_closed), \ diff --git a/Include/internal/pycore_unicodeobject_generated.h b/Include/internal/pycore_unicodeobject_generated.h index ee9483a8da5f2d..bbbc1caa574880 100644 --- a/Include/internal/pycore_unicodeobject_generated.h +++ b/Include/internal/pycore_unicodeobject_generated.h @@ -12,10 +12,50 @@ extern "C" { static inline void _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { PyObject *string; + string = &_Py_ID(AMPEREQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(ATEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_ID(CANCELLED); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(CIRCUMFLEXEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(COLONEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(DOUBLESLASH); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(DOUBLESLASHEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(DOUBLESTAR); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(DOUBLESTAREQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(ELLIPSIS); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(EQEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_ID(Emax); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); @@ -32,18 +72,70 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(GREATEREQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_ID(JSONDecodeError); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(LEFTSHIFT); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(LEFTSHIFTEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(LESSEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(MINEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(NOTEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_ID(PENDING); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(PERCENTEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(PLUSEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_ID(Py_Repr); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(RARROW); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(RIGHTSHIFT); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(RIGHTSHIFTEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(SLASHEQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(STAREQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_ID(TextIOWrapper); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); @@ -52,6 +144,10 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(VBAREQUAL); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_ID(WarningMessage); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); diff --git a/Tools/build/generate_global_objects.py b/Tools/build/generate_global_objects.py index 47667fffba4621..14963280f4a272 100644 --- a/Tools/build/generate_global_objects.py +++ b/Tools/build/generate_global_objects.py @@ -131,6 +131,31 @@ 'exc_value', 'self', 'traceback', + + "AMPEREQUAL", + "ATEQUAL", + "CIRCUMFLEXEQUAL", + "COLONEQUAL", + "DOUBLESLASH", + "DOUBLESLASHEQUAL", + "DOUBLESTAR", + "DOUBLESTAREQUAL", + "ELLIPSIS", + "EQEQUAL", + "GREATEREQUAL", + "LEFTSHIFT", + "LEFTSHIFTEQUAL", + "LESSEQUAL", + "MINEQUAL", + "NOTEQUAL", + "PERCENTEQUAL", + "PLUSEQUAL", + "RARROW", + "RIGHTSHIFT", + "RIGHTSHIFTEQUAL", + "SLASHEQUAL", + "STAREQUAL", + "VBAREQUAL", ] NON_GENERATED_IMMORTAL_OBJECTS = [ From c169e9881dcf3eaec0d015b3d1c6c1eb68ced148 Mon Sep 17 00:00:00 2001 From: Albert N Date: Fri, 17 Oct 2025 14:27:15 +0000 Subject: [PATCH 6/7] fix --- Tools/build/generate_token.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tools/build/generate_token.py b/Tools/build/generate_token.py index 4a3119e556b17b..eab43fa1061389 100755 --- a/Tools/build/generate_token.py +++ b/Tools/build/generate_token.py @@ -191,13 +191,13 @@ def declate_tokens(tok_name_to_string): def make_c(infile, outfile='Parser/token.c'): tok_names, ERRORTOKEN, string_to_tok = load_tokens(infile) - # string_to_tok['<>'] = string_to_tok['!='] - chars_to_token = {} tok_name_to_string = { tok_names[name_idx]: token for token, name_idx in string_to_tok.items() if len(token) > 1 } + chars_to_token = {} + string_to_tok['<>'] = string_to_tok['!='] for string, value in string_to_tok.items(): assert 1 <= len(string) <= 3 From 6c065f31479fe299150dd3c2720173abd05ab135 Mon Sep 17 00:00:00 2001 From: Albert N Date: Fri, 17 Oct 2025 14:40:20 +0000 Subject: [PATCH 7/7] fix --- Parser/token.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Parser/token.c b/Parser/token.c index dc2ca9bd797c1c..ae321655343f25 100644 --- a/Parser/token.c +++ b/Parser/token.c @@ -191,6 +191,7 @@ _PyToken_TwoChars(int c1, int c2) switch (c2) { case '<': return LEFTSHIFT; case '=': return LESSEQUAL; + case '>': return NOTEQUAL; } break; case '=':