diff options
author | Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> | 2023-03-14 08:52:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-14 08:52:21 (GMT) |
commit | 3d872a74c8c16d4a077c2223f678b1f8f7e0e988 (patch) | |
tree | 0a93758065d323778fb8c7cf2c28c28a9a600e18 /Objects | |
parent | 7bdb331b67c4aee513e01794ba7dd2c3be43d3ca (diff) | |
download | cpython-3d872a74c8c16d4a077c2223f678b1f8f7e0e988.zip cpython-3d872a74c8c16d4a077c2223f678b1f8f7e0e988.tar.gz cpython-3d872a74c8c16d4a077c2223f678b1f8f7e0e988.tar.bz2 |
GH-100227: cleanup initialization of global interned dict (#102682)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 2d50f9c..b9fb531 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -14533,6 +14533,15 @@ _PyUnicode_InitGlobalObjects(PyInterpreterState *interp) return _PyStatus_OK(); } + // Initialize the global interned dict + PyObject *interned = PyDict_New(); + if (interned == NULL) { + PyErr_Clear(); + return _PyStatus_ERR("failed to create interned dict"); + } + + set_interned_dict(interned); + /* Intern statically allocated string identifiers and deepfreeze strings. * This must be done before any module initialization so that statically * allocated string identifiers are used instead of heap allocated strings. @@ -14600,14 +14609,7 @@ PyUnicode_InternInPlace(PyObject **p) } PyObject *interned = get_interned_dict(); - if (interned == NULL) { - interned = PyDict_New(); - if (interned == NULL) { - PyErr_Clear(); /* Don't leave an exception */ - return; - } - set_interned_dict(interned); - } + assert(interned != NULL); PyObject *t = PyDict_SetDefault(interned, s, s); if (t == NULL) { |