Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Use _Py_AddToGlobalDict().
  • Loading branch information
ericsnowcurrently committed Mar 22, 2023
commit 22753b33ad22bd50ba9ce207de6a41311c1e6ca1
30 changes: 2 additions & 28 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -14585,31 +14585,6 @@ _PyUnicode_InitTypes(PyInterpreterState *interp)
}


static inline PyObject *
store_interned(PyObject *obj)
{
PyObject *interned = get_interned_dict();
assert(interned != NULL);

/* Swap to the main interpreter, if necessary. */
PyInterpreterState *interp = _PyInterpreterState_GET();
PyThreadState *oldts = _Py_AcquireGlobalObjectsState(interp);

/* This might trigger a resize, which is why we must "acquire"
the global object state. */
PyObject *t = PyDict_SetDefault(interned, obj, obj);
if (t == NULL) {
PyErr_Clear();
}

/* Swap back. */
if (oldts != NULL) {
_Py_ReleaseGlobalObjectsState(oldts);
}

return t;
}

void
PyUnicode_InternInPlace(PyObject **p)
{
Expand All @@ -14633,16 +14608,15 @@ PyUnicode_InternInPlace(PyObject **p)
return;
}

PyObject *t = store_interned(s);
PyObject *interned = get_interned_dict();
PyObject *t = _Py_AddToGlobalDict(interned, s, s);
if (t != s) {
if (t != NULL) {
Py_SETREF(*p, Py_NewRef(t));
}
return;
}

// XXX Immortalize the object.

/* The two references in interned dict (key and value) are not counted by
refcnt. unicode_dealloc() and _PyUnicode_ClearInterned() take care of
this. */
Expand Down