summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-04-02 13:28:13 (GMT)
committerGitHub <noreply@github.com>2021-04-02 13:28:13 (GMT)
commit442ad74fc2928b095760eb89aba93c28eab17f9b (patch)
tree29f784c0860f41cd6d2c16d34e8ced47ebf5e005 /Objects
parent58384c6ab01bbc35cc14cdeb716f6c45a3df426b (diff)
downloadcpython-442ad74fc2928b095760eb89aba93c28eab17f9b.zip
cpython-442ad74fc2928b095760eb89aba93c28eab17f9b.tar.gz
cpython-442ad74fc2928b095760eb89aba93c28eab17f9b.tar.bz2
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.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/floatobject.c10
-rw-r--r--Objects/longobject.c19
-rw-r--r--Objects/structseq.c3
-rw-r--r--Objects/unicodeobject.c52
4 files changed, 48 insertions, 36 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 178f7b2..b3c41b1 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1968,7 +1968,7 @@ PyTypeObject PyFloat_Type = {
.tp_vectorcall = (vectorcallfunc)float_vectorcall,
};
-int
+void
_PyFloat_Init(void)
{
/* We attempt to determine if this machine is using IEEE
@@ -2016,14 +2016,18 @@ _PyFloat_Init(void)
double_format = detected_double_format;
float_format = detected_float_format;
+}
+int
+_PyFloat_InitTypes(void)
+{
/* Init float info */
if (FloatInfoType.tp_name == NULL) {
if (PyStructSequence_InitType2(&FloatInfoType, &floatinfo_desc) < 0) {
- return 0;
+ return -1;
}
}
- return 1;
+ return 0;
}
void
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
diff --git a/Objects/structseq.c b/Objects/structseq.c
index 8a92bdb..88e63b6 100644
--- a/Objects/structseq.c
+++ b/Objects/structseq.c
@@ -579,7 +579,8 @@ int _PyStructSequence_Init(void)
if (_PyUnicode_FromId(&PyId_n_sequence_fields) == NULL
|| _PyUnicode_FromId(&PyId_n_fields) == NULL
|| _PyUnicode_FromId(&PyId_n_unnamed_fields) == NULL)
+ {
return -1;
-
+ }
return 0;
}
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index f6bf505..74c5888 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -15676,18 +15676,6 @@ PyTypeObject PyUnicode_Type = {
PyStatus
_PyUnicode_Init(PyInterpreterState *interp)
{
- /* XXX - move this array to unicodectype.c ? */
- const Py_UCS2 linebreak[] = {
- 0x000A, /* LINE FEED */
- 0x000D, /* CARRIAGE RETURN */
- 0x001C, /* FILE SEPARATOR */
- 0x001D, /* GROUP SEPARATOR */
- 0x001E, /* RECORD SEPARATOR */
- 0x0085, /* NEXT LINE */
- 0x2028, /* LINE SEPARATOR */
- 0x2029, /* PARAGRAPH SEPARATOR */
- };
-
struct _Py_unicode_state *state = &interp->unicode;
if (unicode_create_empty_string_singleton(state) < 0) {
return _PyStatus_NO_MEMORY();
@@ -15695,23 +15683,39 @@ _PyUnicode_Init(PyInterpreterState *interp)
if (_Py_IsMainInterpreter(interp)) {
/* initialize the linebreak bloom filter */
+ const Py_UCS2 linebreak[] = {
+ 0x000A, /* LINE FEED */
+ 0x000D, /* CARRIAGE RETURN */
+ 0x001C, /* FILE SEPARATOR */
+ 0x001D, /* GROUP SEPARATOR */
+ 0x001E, /* RECORD SEPARATOR */
+ 0x0085, /* NEXT LINE */
+ 0x2028, /* LINE SEPARATOR */
+ 0x2029, /* PARAGRAPH SEPARATOR */
+ };
bloom_linebreak = make_bloom_mask(
PyUnicode_2BYTE_KIND, linebreak,
Py_ARRAY_LENGTH(linebreak));
+ }
- if (PyType_Ready(&PyUnicode_Type) < 0) {
- return _PyStatus_ERR("Can't initialize unicode type");
- }
+ return _PyStatus_OK();
+}
- if (PyType_Ready(&EncodingMapType) < 0) {
- return _PyStatus_ERR("Can't initialize encoding map type");
- }
- if (PyType_Ready(&PyFieldNameIter_Type) < 0) {
- return _PyStatus_ERR("Can't initialize field name iterator type");
- }
- if (PyType_Ready(&PyFormatterIter_Type) < 0) {
- return _PyStatus_ERR("Can't initialize formatter iter type");
- }
+
+PyStatus
+_PyUnicode_InitTypes(void)
+{
+ if (PyType_Ready(&PyUnicode_Type) < 0) {
+ return _PyStatus_ERR("Can't initialize unicode type");
+ }
+ if (PyType_Ready(&EncodingMapType) < 0) {
+ return _PyStatus_ERR("Can't initialize encoding map type");
+ }
+ if (PyType_Ready(&PyFieldNameIter_Type) < 0) {
+ return _PyStatus_ERR("Can't initialize field name iterator type");
+ }
+ if (PyType_Ready(&PyFormatterIter_Type) < 0) {
+ return _PyStatus_ERR("Can't initialize formatter iter type");
}
return _PyStatus_OK();
}