bpo-43687: Py_Initialize() creates singletons earlier (GH-25147)
Reorganize pycore_interp_init() to initialize singletons before the
the first PyType_Ready() call. Fix an issue when Python is configured
using --without-doc-strings.
diff --git a/Objects/longobject.c b/Objects/longobject.c
index d5037a7..e1c1191 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -5719,17 +5719,20 @@ _PyLong_Init(PyInterpreterState *interp)
interp->small_ints[i] = v;
}
+ return 0;
+}
- if (_Py_IsMainInterpreter(interp)) {
- /* initialize int_info */
- if (Int_InfoType.tp_name == NULL) {
- if (PyStructSequence_InitType2(&Int_InfoType, &int_info_desc) < 0) {
- return 0;
- }
+
+int
+_PyLong_InitTypes(void)
+{
+ /* initialize int_info */
+ if (Int_InfoType.tp_name == NULL) {
+ if (PyStructSequence_InitType2(&Int_InfoType, &int_info_desc) < 0) {
+ return -1;
}
}
-
- return 1;
+ return 0;
}
void