Skip to content

Commit 1f45536

Browse files
bpo-46765: Replace Locally Cached Strings with Statically Initialized Objects (gh-31366)
https://bugs.python.org/issue46765
1 parent cff4d5c commit 1f45536

22 files changed

+192
-526
lines changed

Include/internal/pycore_global_strings.h

+32
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,26 @@ struct _Py_global_strings {
3535
STRUCT_FOR_STR(anon_module, "<module>")
3636
STRUCT_FOR_STR(anon_setcomp, "<setcomp>")
3737
STRUCT_FOR_STR(anon_string, "<string>")
38+
STRUCT_FOR_STR(anon_unknown, "<unknown>")
39+
STRUCT_FOR_STR(close_br, "}")
3840
STRUCT_FOR_STR(comma_sep, ", ")
41+
STRUCT_FOR_STR(dbl_close_br, "}}")
42+
STRUCT_FOR_STR(dbl_open_br, "{{")
3943
STRUCT_FOR_STR(dbl_percent, "%%")
4044
STRUCT_FOR_STR(dot, ".")
4145
STRUCT_FOR_STR(dot_locals, ".<locals>")
4246
STRUCT_FOR_STR(empty, "")
47+
STRUCT_FOR_STR(list_err, "list index out of range")
48+
STRUCT_FOR_STR(newline, "\n")
49+
STRUCT_FOR_STR(open_br, "{")
4350
STRUCT_FOR_STR(percent, "%")
4451
} literals;
4552

4653
struct {
54+
STRUCT_FOR_ID(False)
4755
STRUCT_FOR_ID(Py_Repr)
4856
STRUCT_FOR_ID(TextIOWrapper)
57+
STRUCT_FOR_ID(True)
4958
STRUCT_FOR_ID(WarningMessage)
5059
STRUCT_FOR_ID(_)
5160
STRUCT_FOR_ID(__IOBase_closed)
@@ -194,7 +203,9 @@ struct _Py_global_strings {
194203
STRUCT_FOR_ID(__weakref__)
195204
STRUCT_FOR_ID(__xor__)
196205
STRUCT_FOR_ID(_abc_impl)
206+
STRUCT_FOR_ID(_annotation)
197207
STRUCT_FOR_ID(_blksize)
208+
STRUCT_FOR_ID(_bootstrap)
198209
STRUCT_FOR_ID(_dealloc_warn)
199210
STRUCT_FOR_ID(_finalizing)
200211
STRUCT_FOR_ID(_find_and_load)
@@ -216,46 +227,62 @@ struct _Py_global_strings {
216227
STRUCT_FOR_ID(big)
217228
STRUCT_FOR_ID(buffer)
218229
STRUCT_FOR_ID(builtins)
230+
STRUCT_FOR_ID(c_call)
231+
STRUCT_FOR_ID(c_exception)
232+
STRUCT_FOR_ID(c_return)
233+
STRUCT_FOR_ID(call)
219234
STRUCT_FOR_ID(clear)
220235
STRUCT_FOR_ID(close)
236+
STRUCT_FOR_ID(closed)
221237
STRUCT_FOR_ID(code)
222238
STRUCT_FOR_ID(copy)
223239
STRUCT_FOR_ID(copyreg)
224240
STRUCT_FOR_ID(decode)
225241
STRUCT_FOR_ID(default)
226242
STRUCT_FOR_ID(defaultaction)
243+
STRUCT_FOR_ID(dictcomp)
227244
STRUCT_FOR_ID(difference_update)
228245
STRUCT_FOR_ID(dispatch_table)
229246
STRUCT_FOR_ID(displayhook)
230247
STRUCT_FOR_ID(enable)
248+
STRUCT_FOR_ID(encode)
231249
STRUCT_FOR_ID(encoding)
232250
STRUCT_FOR_ID(end_lineno)
233251
STRUCT_FOR_ID(end_offset)
234252
STRUCT_FOR_ID(errors)
235253
STRUCT_FOR_ID(excepthook)
254+
STRUCT_FOR_ID(exception)
236255
STRUCT_FOR_ID(extend)
237256
STRUCT_FOR_ID(filename)
238257
STRUCT_FOR_ID(fileno)
239258
STRUCT_FOR_ID(fillvalue)
240259
STRUCT_FOR_ID(filters)
241260
STRUCT_FOR_ID(find_class)
242261
STRUCT_FOR_ID(flush)
262+
STRUCT_FOR_ID(genexpr)
243263
STRUCT_FOR_ID(get)
244264
STRUCT_FOR_ID(get_source)
245265
STRUCT_FOR_ID(getattr)
266+
STRUCT_FOR_ID(getstate)
246267
STRUCT_FOR_ID(ignore)
247268
STRUCT_FOR_ID(importlib)
269+
STRUCT_FOR_ID(inf)
248270
STRUCT_FOR_ID(intersection)
249271
STRUCT_FOR_ID(isatty)
250272
STRUCT_FOR_ID(items)
251273
STRUCT_FOR_ID(iter)
274+
STRUCT_FOR_ID(join)
252275
STRUCT_FOR_ID(keys)
276+
STRUCT_FOR_ID(lambda)
253277
STRUCT_FOR_ID(last_traceback)
254278
STRUCT_FOR_ID(last_type)
255279
STRUCT_FOR_ID(last_value)
256280
STRUCT_FOR_ID(latin1)
281+
STRUCT_FOR_ID(line)
257282
STRUCT_FOR_ID(lineno)
283+
STRUCT_FOR_ID(listcomp)
258284
STRUCT_FOR_ID(little)
285+
STRUCT_FOR_ID(locale)
259286
STRUCT_FOR_ID(match)
260287
STRUCT_FOR_ID(metaclass)
261288
STRUCT_FOR_ID(mode)
@@ -266,9 +293,11 @@ struct _Py_global_strings {
266293
STRUCT_FOR_ID(n_sequence_fields)
267294
STRUCT_FOR_ID(n_unnamed_fields)
268295
STRUCT_FOR_ID(name)
296+
STRUCT_FOR_ID(newlines)
269297
STRUCT_FOR_ID(obj)
270298
STRUCT_FOR_ID(offset)
271299
STRUCT_FOR_ID(onceregistry)
300+
STRUCT_FOR_ID(opcode)
272301
STRUCT_FOR_ID(open)
273302
STRUCT_FOR_ID(parent)
274303
STRUCT_FOR_ID(partial)
@@ -296,6 +325,7 @@ struct _Py_global_strings {
296325
STRUCT_FOR_ID(seek)
297326
STRUCT_FOR_ID(seekable)
298327
STRUCT_FOR_ID(send)
328+
STRUCT_FOR_ID(setcomp)
299329
STRUCT_FOR_ID(setstate)
300330
STRUCT_FOR_ID(sort)
301331
STRUCT_FOR_ID(stderr)
@@ -307,6 +337,8 @@ struct _Py_global_strings {
307337
STRUCT_FOR_ID(text)
308338
STRUCT_FOR_ID(threading)
309339
STRUCT_FOR_ID(throw)
340+
STRUCT_FOR_ID(top)
341+
STRUCT_FOR_ID(truncate)
310342
STRUCT_FOR_ID(unraisablehook)
311343
STRUCT_FOR_ID(values)
312344
STRUCT_FOR_ID(version)

Include/internal/pycore_runtime_init.h

+32
Original file line numberDiff line numberDiff line change
@@ -651,16 +651,25 @@ extern "C" {
651651
INIT_STR(anon_module, "<module>"), \
652652
INIT_STR(anon_setcomp, "<setcomp>"), \
653653
INIT_STR(anon_string, "<string>"), \
654+
INIT_STR(anon_unknown, "<unknown>"), \
655+
INIT_STR(close_br, "}"), \
654656
INIT_STR(comma_sep, ", "), \
657+
INIT_STR(dbl_close_br, "}}"), \
658+
INIT_STR(dbl_open_br, "{{"), \
655659
INIT_STR(dbl_percent, "%%"), \
656660
INIT_STR(dot, "."), \
657661
INIT_STR(dot_locals, ".<locals>"), \
658662
INIT_STR(empty, ""), \
663+
INIT_STR(list_err, "list index out of range"), \
664+
INIT_STR(newline, "\n"), \
665+
INIT_STR(open_br, "{"), \
659666
INIT_STR(percent, "%"), \
660667
}, \
661668
.identifiers = { \
669+
INIT_ID(False), \
662670
INIT_ID(Py_Repr), \
663671
INIT_ID(TextIOWrapper), \
672+
INIT_ID(True), \
664673
INIT_ID(WarningMessage), \
665674
INIT_ID(_), \
666675
INIT_ID(__IOBase_closed), \
@@ -809,7 +818,9 @@ extern "C" {
809818
INIT_ID(__weakref__), \
810819
INIT_ID(__xor__), \
811820
INIT_ID(_abc_impl), \
821+
INIT_ID(_annotation), \
812822
INIT_ID(_blksize), \
823+
INIT_ID(_bootstrap), \
813824
INIT_ID(_dealloc_warn), \
814825
INIT_ID(_finalizing), \
815826
INIT_ID(_find_and_load), \
@@ -831,46 +842,62 @@ extern "C" {
831842
INIT_ID(big), \
832843
INIT_ID(buffer), \
833844
INIT_ID(builtins), \
845+
INIT_ID(c_call), \
846+
INIT_ID(c_exception), \
847+
INIT_ID(c_return), \
848+
INIT_ID(call), \
834849
INIT_ID(clear), \
835850
INIT_ID(close), \
851+
INIT_ID(closed), \
836852
INIT_ID(code), \
837853
INIT_ID(copy), \
838854
INIT_ID(copyreg), \
839855
INIT_ID(decode), \
840856
INIT_ID(default), \
841857
INIT_ID(defaultaction), \
858+
INIT_ID(dictcomp), \
842859
INIT_ID(difference_update), \
843860
INIT_ID(dispatch_table), \
844861
INIT_ID(displayhook), \
845862
INIT_ID(enable), \
863+
INIT_ID(encode), \
846864
INIT_ID(encoding), \
847865
INIT_ID(end_lineno), \
848866
INIT_ID(end_offset), \
849867
INIT_ID(errors), \
850868
INIT_ID(excepthook), \
869+
INIT_ID(exception), \
851870
INIT_ID(extend), \
852871
INIT_ID(filename), \
853872
INIT_ID(fileno), \
854873
INIT_ID(fillvalue), \
855874
INIT_ID(filters), \
856875
INIT_ID(find_class), \
857876
INIT_ID(flush), \
877+
INIT_ID(genexpr), \
858878
INIT_ID(get), \
859879
INIT_ID(get_source), \
860880
INIT_ID(getattr), \
881+
INIT_ID(getstate), \
861882
INIT_ID(ignore), \
862883
INIT_ID(importlib), \
884+
INIT_ID(inf), \
863885
INIT_ID(intersection), \
864886
INIT_ID(isatty), \
865887
INIT_ID(items), \
866888
INIT_ID(iter), \
889+
INIT_ID(join), \
867890
INIT_ID(keys), \
891+
INIT_ID(lambda), \
868892
INIT_ID(last_traceback), \
869893
INIT_ID(last_type), \
870894
INIT_ID(last_value), \
871895
INIT_ID(latin1), \
896+
INIT_ID(line), \
872897
INIT_ID(lineno), \
898+
INIT_ID(listcomp), \
873899
INIT_ID(little), \
900+
INIT_ID(locale), \
874901
INIT_ID(match), \
875902
INIT_ID(metaclass), \
876903
INIT_ID(mode), \
@@ -881,9 +908,11 @@ extern "C" {
881908
INIT_ID(n_sequence_fields), \
882909
INIT_ID(n_unnamed_fields), \
883910
INIT_ID(name), \
911+
INIT_ID(newlines), \
884912
INIT_ID(obj), \
885913
INIT_ID(offset), \
886914
INIT_ID(onceregistry), \
915+
INIT_ID(opcode), \
887916
INIT_ID(open), \
888917
INIT_ID(parent), \
889918
INIT_ID(partial), \
@@ -911,6 +940,7 @@ extern "C" {
911940
INIT_ID(seek), \
912941
INIT_ID(seekable), \
913942
INIT_ID(send), \
943+
INIT_ID(setcomp), \
914944
INIT_ID(setstate), \
915945
INIT_ID(sort), \
916946
INIT_ID(stderr), \
@@ -922,6 +952,8 @@ extern "C" {
922952
INIT_ID(text), \
923953
INIT_ID(threading), \
924954
INIT_ID(throw), \
955+
INIT_ID(top), \
956+
INIT_ID(truncate), \
925957
INIT_ID(unraisablehook), \
926958
INIT_ID(values), \
927959
INIT_ID(version), \

Include/internal/pycore_symtable.h

-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ extern struct symtable* _Py_SymtableStringObjectFlags(
128128
int start,
129129
PyCompilerFlags *flags);
130130

131-
extern void _PySymtable_Fini(void);
132-
133131
#ifdef __cplusplus
134132
}
135133
#endif

0 commit comments

Comments
 (0)