Skip to content

Commit

Permalink
GH-100227: cleanup initialization of global interned dict (#102682)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaraditya303 authored Mar 14, 2023
1 parent 7bdb331 commit 3d872a7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3d872a7

Please sign in to comment.