diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2022-11-08 17:03:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-08 17:03:03 (GMT) |
commit | 52f91c642b72003c57fc1fb855beab6dfab155b7 (patch) | |
tree | 051abac024b2749d6e54c7c933a5c46fea3e2b63 /Tools | |
parent | d45cc80452b11d5ffc5c9721f74a3e3df8ecad8b (diff) | |
download | cpython-52f91c642b72003c57fc1fb855beab6dfab155b7.zip cpython-52f91c642b72003c57fc1fb855beab6dfab155b7.tar.gz cpython-52f91c642b72003c57fc1fb855beab6dfab155b7.tar.bz2 |
gh-90868: Adjust the Generated Objects (gh-99223)
We do the following:
* move the generated _PyUnicode_InitStaticStrings() to its own file
* move the generated _PyStaticObjects_CheckRefcnt() to its own file
* include pycore_global_objects.h in extension modules instead of pycore_runtime_init.h
These changes help us avoid including things that aren't needed.
https://github.com/python/cpython/issues/90868
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/build/generate_global_objects.py | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/Tools/build/generate_global_objects.py b/Tools/build/generate_global_objects.py index dd67cfe..5516dcf 100644 --- a/Tools/build/generate_global_objects.py +++ b/Tools/build/generate_global_objects.py @@ -330,7 +330,29 @@ def generate_runtime_init(identifiers, strings): with printer.block('.tuple_empty =', ','): printer.write('.ob_base = _PyVarObject_IMMORTAL_INIT(&PyTuple_Type, 0)') immortal_objects.append(f'(PyObject *)&_Py_SINGLETON(tuple_empty)') - printer.write('') + printer.write(END) + printer.write(after) + return immortal_objects + + +def generate_static_strings_initializer(identifiers, strings): + # Target the runtime initializer. + filename = os.path.join(INTERNAL, 'pycore_unicodeobject_generated.h') + + # Read the non-generated part of the file. + with open(filename) as infile: + orig = infile.read() + lines = iter(orig.rstrip().splitlines()) + before = '\n'.join(iter_to_marker(lines, START)) + for _ in iter_to_marker(lines, END): + pass + after = '\n'.join(lines) + + # Generate the file. + with open_for_changes(filename, orig) as outfile: + printer = Printer(outfile) + printer.write(before) + printer.write(START) printer.write("static inline void") with printer.block("_PyUnicode_InitStaticStrings(void)"): printer.write(f'PyObject *string;') @@ -339,7 +361,29 @@ def generate_runtime_init(identifiers, strings): # since iter_files() ignores .h files. printer.write(f'string = &_Py_ID({i});') printer.write(f'PyUnicode_InternInPlace(&string);') - printer.write('') + # XXX What about "strings"? + printer.write(END) + printer.write(after) + + +def generate_global_object_finalizers(immortal_objects): + # Target the runtime initializer. + filename = os.path.join(INTERNAL, 'pycore_global_objects_fini_generated.h') + + # Read the non-generated part of the file. + with open(filename) as infile: + orig = infile.read() + lines = iter(orig.rstrip().splitlines()) + before = '\n'.join(iter_to_marker(lines, START)) + for _ in iter_to_marker(lines, END): + pass + after = '\n'.join(lines) + + # Generate the file. + with open_for_changes(filename, orig) as outfile: + printer = Printer(outfile) + printer.write(before) + printer.write(START) printer.write('#ifdef Py_DEBUG') printer.write("static inline void") with printer.block("_PyStaticObjects_CheckRefcnt(void)"): @@ -375,7 +419,9 @@ def main() -> None: identifiers, strings = get_identifiers_and_strings() generate_global_strings(identifiers, strings) - generate_runtime_init(identifiers, strings) + immortal_objects = generate_runtime_init(identifiers, strings) + generate_static_strings_initializer(identifiers, strings) + generate_global_object_finalizers(immortal_objects) if __name__ == '__main__': |