summaryrefslogtreecommitdiff
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-04-02 15:28:13 +0200
committerGitHub <noreply@github.com>2021-04-02 15:28:13 +0200
commit442ad74fc2928b095760eb89aba93c28eab17f9b (patch)
tree29f784c0860f41cd6d2c16d34e8ced47ebf5e005 /Objects/unicodeobject.c
parent58384c6ab01bbc35cc14cdeb716f6c45a3df426b (diff)
downloadcpython-git-442ad74fc2928b095760eb89aba93c28eab17f9b.tar.gz
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/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c52
1 files changed, 28 insertions, 24 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index f6bf505b7f..74c5888d13 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();
}