Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Small code cleanup as suggested by review.
  • Loading branch information
nascheme committed Sep 27, 2024
commit 82cfa9675a7632a8b940fd9de8d18d904745cfa5
18 changes: 11 additions & 7 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,12 @@ init_interned_dict(PyInterpreterState *interp)
static void
clear_interned_dict(PyInterpreterState *interp)
{
if (has_shared_intern_dict(interp)) {
return; // the dict doesn't belong to this interpreter
}
PyObject *interned = get_interned_dict(interp);
if (interned != NULL) {
PyDict_Clear(interned);
if (!has_shared_intern_dict(interp)) {
// only clear if the dict belongs to this interpreter
PyDict_Clear(interned);
}
Py_DECREF(interned);
_Py_INTERP_CACHED_OBJECT(interp, interned_strings) = NULL;
}
Expand Down Expand Up @@ -14882,15 +14882,19 @@ PyUnicode_InternFromString(const char *cp)
void
_PyUnicode_ClearInterned(PyInterpreterState *interp)
{
if (has_shared_intern_dict(interp)) {
return; // the dict doesn't belong to this interpreter
}
PyObject *interned = get_interned_dict(interp);
if (interned == NULL) {
return;
}
assert(PyDict_CheckExact(interned));

if (has_shared_intern_dict(interp)) {
// the dict doesn't belong to this interpreter, skip the debug
// checks on it and just clear the pointer to it
clear_interned_dict(interp);
return;
}

/* TODO:
* Currently, the runtime is not able to guarantee that it can exit without
* allocations that carry over to a future initialization of Python within
Expand Down