@@ -294,35 +294,29 @@ def generate_runtime_init(identifiers, strings):
294
294
295
295
# Generate the file.
296
296
with open_for_changes (filename , orig ) as outfile :
297
- immortal_objects = []
298
297
printer = Printer (outfile )
299
298
printer .write (before )
300
299
printer .write (START )
301
300
with printer .block ('#define _Py_small_ints_INIT' , continuation = True ):
302
301
for i in range (- nsmallnegints , nsmallposints ):
303
302
printer .write (f'_PyLong_DIGIT_INIT({ i } ),' )
304
- immortal_objects .append (f'(PyObject *)&_Py_SINGLETON(small_ints)[_PY_NSMALLNEGINTS + { i } ]' )
305
303
printer .write ('' )
306
304
with printer .block ('#define _Py_bytes_characters_INIT' , continuation = True ):
307
305
for i in range (256 ):
308
306
printer .write (f'_PyBytes_CHAR_INIT({ i } ),' )
309
- immortal_objects .append (f'(PyObject *)&_Py_SINGLETON(bytes_characters)[{ i } ]' )
310
307
printer .write ('' )
311
308
with printer .block ('#define _Py_str_literals_INIT' , continuation = True ):
312
309
for literal , name in sorted (strings .items (), key = lambda x : x [1 ]):
313
310
printer .write (f'INIT_STR({ name } , "{ literal } "),' )
314
- immortal_objects .append (f'(PyObject *)&_Py_STR({ name } )' )
315
311
printer .write ('' )
316
312
with printer .block ('#define _Py_str_identifiers_INIT' , continuation = True ):
317
313
for name in sorted (identifiers ):
318
314
assert name .isidentifier (), name
319
315
printer .write (f'INIT_ID({ name } ),' )
320
- immortal_objects .append (f'(PyObject *)&_Py_ID({ name } )' )
321
316
printer .write ('' )
322
317
with printer .block ('#define _Py_str_ascii_INIT' , continuation = True ):
323
318
for i in range (128 ):
324
319
printer .write (f'_PyASCIIObject_INIT("\\ x{ i :02x} "),' )
325
- immortal_objects .append (f'(PyObject *)&_Py_SINGLETON(strings).ascii[{ i } ]' )
326
320
printer .write ('' )
327
321
with printer .block ('#define _Py_str_latin1_INIT' , continuation = True ):
328
322
for i in range (128 , 256 ):
@@ -331,10 +325,8 @@ def generate_runtime_init(identifiers, strings):
331
325
utf8 .append (f"\\ x{ c :02x} " )
332
326
utf8 .append ('"' )
333
327
printer .write (f'_PyUnicode_LATIN1_INIT("\\ x{ i :02x} ", { "" .join (utf8 )} ),' )
334
- immortal_objects .append (f'(PyObject *)&_Py_SINGLETON(strings).latin1[{ i } - 128]' )
335
328
printer .write (END )
336
329
printer .write (after )
337
- return immortal_objects
338
330
339
331
340
332
def generate_static_strings_initializer (identifiers , strings ):
@@ -369,40 +361,6 @@ def generate_static_strings_initializer(identifiers, strings):
369
361
printer .write (after )
370
362
371
363
372
- def generate_global_object_finalizers (generated_immortal_objects ):
373
- # Target the runtime initializer.
374
- filename = os .path .join (INTERNAL , 'pycore_global_objects_fini_generated.h' )
375
-
376
- # Read the non-generated part of the file.
377
- with open (filename ) as infile :
378
- orig = infile .read ()
379
- lines = iter (orig .rstrip ().splitlines ())
380
- before = '\n ' .join (iter_to_marker (lines , START ))
381
- for _ in iter_to_marker (lines , END ):
382
- pass
383
- after = '\n ' .join (lines )
384
-
385
- # Generate the file.
386
- with open_for_changes (filename , orig ) as outfile :
387
- printer = Printer (outfile )
388
- printer .write (before )
389
- printer .write (START )
390
- printer .write ('#ifdef Py_DEBUG' )
391
- printer .write ("static inline void" )
392
- with printer .block (
393
- "_PyStaticObjects_CheckRefcnt(PyInterpreterState *interp)" ):
394
- printer .write ('/* generated runtime-global */' )
395
- printer .write ('// (see pycore_runtime_init_generated.h)' )
396
- for ref in generated_immortal_objects :
397
- printer .write (f'_PyStaticObject_CheckRefcnt({ ref } );' )
398
- printer .write ('/* non-generated */' )
399
- for ref in NON_GENERATED_IMMORTAL_OBJECTS :
400
- printer .write (f'_PyStaticObject_CheckRefcnt({ ref } );' )
401
- printer .write ('#endif // Py_DEBUG' )
402
- printer .write (END )
403
- printer .write (after )
404
-
405
-
406
364
def get_identifiers_and_strings () -> 'tuple[set[str], dict[str, str]]' :
407
365
identifiers = set (IDENTIFIERS )
408
366
strings = {}
@@ -425,9 +383,8 @@ def main() -> None:
425
383
identifiers , strings = get_identifiers_and_strings ()
426
384
427
385
generate_global_strings (identifiers , strings )
428
- generated_immortal_objects = generate_runtime_init (identifiers , strings )
386
+ generate_runtime_init (identifiers , strings )
429
387
generate_static_strings_initializer (identifiers , strings )
430
- generate_global_object_finalizers (generated_immortal_objects )
431
388
432
389
433
390
if __name__ == '__main__' :
0 commit comments