gh-81057: Generate a Separate Initializer For Each Part of the Global Objects Initializer (gh-99389)

Up until now we had a single generated initializer macro for all the statically declared global objects in _PyRuntimeState, including several one-offs (e.g. the empty tuple). The one-offs don't need to be generated, but were because we had one big initializer. Having separate initializers for set of generated global objects allows us to generate only the ones we need to.  This allows us to add initializers for one-off global objects without having to generate them.

https://github.com/python/cpython/issues/81057
This commit is contained in:
Eric Snow 2022-11-11 13:23:41 -07:00 committed by GitHub
parent 6abec1caff
commit fe55ff3f68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 1528 additions and 1517 deletions

View file

@ -25,6 +25,7 @@ _PyStaticObject_CheckRefcnt(PyObject *obj) {
#ifdef Py_DEBUG
static inline void
_PyStaticObjects_CheckRefcnt(void) {
/* generated (see pycore_runtime_init_generated.h) */
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(small_ints)[_PY_NSMALLNEGINTS + -5]);
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(small_ints)[_PY_NSMALLNEGINTS + -4]);
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(small_ints)[_PY_NSMALLNEGINTS + -3]);
@ -287,7 +288,6 @@ _PyStaticObjects_CheckRefcnt(void) {
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(small_ints)[_PY_NSMALLNEGINTS + 254]);
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(small_ints)[_PY_NSMALLNEGINTS + 255]);
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(small_ints)[_PY_NSMALLNEGINTS + 256]);
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(bytes_empty));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(bytes_characters)[0]);
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(bytes_characters)[1]);
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(bytes_characters)[2]);
@ -1469,6 +1469,8 @@ _PyStaticObjects_CheckRefcnt(void) {
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(strings).latin1[253 - 128]);
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(strings).latin1[254 - 128]);
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(strings).latin1[255 - 128]);
/* non-generated */
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(bytes_empty));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_SINGLETON(tuple_empty));
}
#endif // Py_DEBUG

View file

@ -28,7 +28,22 @@ extern "C" {
until _PyInterpreterState_Enable() is called. */ \
.next_id = -1, \
}, \
.global_objects = _Py_global_objects_INIT, \
.global_objects = { \
.singletons = { \
.small_ints = _Py_small_ints_INIT, \
.bytes_empty = _PyBytes_SIMPLE_INIT(0, 0), \
.bytes_characters = _Py_bytes_characters_INIT, \
.strings = { \
.literals = _Py_str_literals_INIT, \
.identifiers = _Py_str_identifiers_INIT, \
.ascii = _Py_str_ascii_INIT, \
.latin1 = _Py_str_latin1_INIT, \
}, \
.tuple_empty = { \
.ob_base = _PyVarObject_IMMORTAL_INIT(&PyTuple_Type, 0) \
}, \
}, \
}, \
._main_interpreter = _PyInterpreterState_INIT, \
}

File diff suppressed because it is too large Load diff