cpython/Include/cpython
Eric Snow 81c72044a1
bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized global objects. (gh-30928)
We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code.  It is still used in a number of non-builtin stdlib modules.

The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime.  A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings).

https://bugs.python.org/issue46541#msg411799 explains the rationale for this change.

The core of the change is in:

* (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros
* Include/internal/pycore_runtime_init.h - added the static initializers for the global strings
* Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState
* Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers

I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings.  That check is added to the PR CI config.

The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()).  This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *.

The following are not changed (yet):

* stop using _Py_IDENTIFIER() in the stdlib modules
* (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API
* (maybe) intern the strings during runtime init

https://bugs.python.org/issue46541
2022-02-08 13:39:07 -07:00
..
abstract.h bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized global objects. (gh-30928) 2022-02-08 13:39:07 -07:00
bytearrayobject.h bpo-35134: Add Include/cpython/bytesobject.h file (GH-18494) 2020-02-12 23:54:31 +01:00
bytesobject.h bpo-42431: Fix outdated bytes comments (GH-23458) 2020-12-03 12:46:16 +02:00
cellobject.h bpo-45476: Add _Py_RVALUE() macro (GH-29860) 2021-11-30 12:14:45 +01:00
ceval.h bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized global objects. (gh-30928) 2022-02-08 13:39:07 -07:00
classobject.h bpo-35134: Move classobject.h to Include/cpython/ (GH-28968) 2021-10-15 09:46:29 +02:00
code.h Remove legacy opcache structs (GH-27164) 2021-07-17 00:49:35 +09:00
compile.h bpo-46521: Fix codeop to use a new partial-input mode of the parser (GH-31010) 2022-02-08 11:54:37 +00:00
context.h bpo-35134: Move classobject.h to Include/cpython/ (GH-28968) 2021-10-15 09:46:29 +02:00
descrobject.h bpo-35134: Add Include/cpython/descrobject.h (GH-30923) 2022-01-26 17:32:47 +01:00
dictobject.h bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized global objects. (gh-30928) 2022-02-08 13:39:07 -07:00
fileobject.h bpo-41986: Add Py_FileSystemDefaultEncodeErrors and Py_UTF8Mode back to limited API (GH-22621) 2020-10-10 17:09:45 +03:00
fileutils.h bpo-46303: Move fileutils.h private functions to internal C API (GH-30484) 2022-01-11 11:56:16 +01:00
floatobject.h bpo-35134: Add Include/cpython/floatobject.h (GH-28957) 2021-10-14 23:41:06 +02:00
frameobject.h bpo-45786: Allocate space for frame in frame object. (GH-29729) 2021-11-29 12:34:59 +00:00
funcobject.h bpo-44525: Copy free variables in bytecode to allow calls to inner functions to be specialized (GH-29595) 2021-11-23 09:53:24 +00:00
genobject.h bpo-46409: Make generators in bytecode (GH-30633) 2022-01-20 11:46:39 +00:00
import.h bpo-46608: exclude marshalled-frozen data if deep-freezing to save 300 KB space (GH-31074) 2022-02-04 09:57:03 -08:00
initconfig.h bpo-45582: Port getpath[p].c to Python (GH-29041) 2021-12-03 00:08:42 +00:00
listobject.h bpo-45476: Add _Py_RVALUE() macro (GH-29860) 2021-11-30 12:14:45 +01:00
longintrepr.h bpo-46218: Change long_pow() to sliding window algorithm (GH-30319) 2022-01-02 13:18:20 -06:00
longobject.h bpo-35134: Add Include/cpython/longobject.h (GH-29044) 2021-10-19 02:04:52 +02:00
methodobject.h bpo-38787: Add PyCFunction_CheckExact() macro for exact type checks (GH-20024) 2020-05-12 07:12:41 -07:00
object.h bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized global objects. (gh-30928) 2022-02-08 13:39:07 -07:00
objimpl.h bpo-40170: Remove _Py_GetAllocatedBlocks() function (GH-30940) 2022-01-27 03:35:51 +01:00
odictobject.h bpo-35134: Move non-limited C API files to Include/cpython/ (GH-24561) 2021-02-19 15:55:46 +01:00
picklebufobject.h bpo-35134: Move non-limited C API files to Include/cpython/ (GH-24561) 2021-02-19 15:55:46 +01:00
pyctype.h bpo-43816: Add extern "C" to Include/cpython/pyctype.h (GH-25365) 2021-04-13 13:27:21 +02:00
pydebug.h bpo-45434: Convert Py_GETENV() macro to a function (GH-28912) 2021-10-13 03:39:50 +02:00
pyerrors.h bpo-45607: Make it possible to enrich exception displays via setting their __note__ field (GH-29880) 2021-12-03 22:01:15 +00:00
pyfpe.h bpo-35134: Move non-limited C API files to Include/cpython/ (GH-24561) 2021-02-19 15:55:46 +01:00
pylifecycle.h bpo-43795: Remove Py_FrozenMain from the Limited API & Stable ABI (GH-26241) 2021-05-25 04:42:03 -07:00
pymem.h bpo-43795: PEP-652: Clean up the stable ABI/limited API (GH-25482) 2021-04-23 14:17:58 +02:00
pystate.h bpo-45953: Preserve backward compatibility on some PyThreadState field names. (GH-31038) 2022-02-01 09:02:25 -08:00
pythonrun.h bpo-43868: Remove PyOS_ReadlineFunctionPointer from the stable ABI list (GH-25442) 2021-04-23 14:23:38 +02:00
pytime.h Fix typos in the Include directory (GH-28745) 2021-10-06 11:32:38 -07:00
sysmodule.h bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized global objects. (gh-30928) 2022-02-08 13:39:07 -07:00
traceback.h bpo-43950: Print columns in tracebacks (PEP 657) (GH-26958) 2021-07-05 00:14:33 +01:00
tupleobject.h bpo-45476: Add _Py_RVALUE() macro (GH-29860) 2021-11-30 12:14:45 +01:00
unicodeobject.h bpo-46007: Exclude PyUnicode_CHECK_INTERNED() from limited C API (GH-29987) 2021-12-09 00:58:09 -08:00
warnings.h bpo-35134: Split warnings.h and weakrefobject.h (GH-29042) 2021-10-19 01:31:57 +02:00
weakrefobject.h bpo-46481: Implement vectorcall for weakref.ref.__call__ method. (GH-30820) 2022-01-24 00:39:45 +09:00