Skip to content

Commit 3d872a7

Browse files
GH-100227: cleanup initialization of global interned dict (#102682)
1 parent 7bdb331 commit 3d872a7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Objects/unicodeobject.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -14533,6 +14533,15 @@ _PyUnicode_InitGlobalObjects(PyInterpreterState *interp)
1453314533
return _PyStatus_OK();
1453414534
}
1453514535

14536+
// Initialize the global interned dict
14537+
PyObject *interned = PyDict_New();
14538+
if (interned == NULL) {
14539+
PyErr_Clear();
14540+
return _PyStatus_ERR("failed to create interned dict");
14541+
}
14542+
14543+
set_interned_dict(interned);
14544+
1453614545
/* Intern statically allocated string identifiers and deepfreeze strings.
1453714546
* This must be done before any module initialization so that statically
1453814547
* allocated string identifiers are used instead of heap allocated strings.
@@ -14600,14 +14609,7 @@ PyUnicode_InternInPlace(PyObject **p)
1460014609
}
1460114610

1460214611
PyObject *interned = get_interned_dict();
14603-
if (interned == NULL) {
14604-
interned = PyDict_New();
14605-
if (interned == NULL) {
14606-
PyErr_Clear(); /* Don't leave an exception */
14607-
return;
14608-
}
14609-
set_interned_dict(interned);
14610-
}
14612+
assert(interned != NULL);
1461114613

1461214614
PyObject *t = PyDict_SetDefault(interned, s, s);
1461314615
if (t == NULL) {

0 commit comments

Comments
 (0)