Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
Use _PyRuntime.cached_objects.main_tstate instead.
  • Loading branch information
ericsnowcurrently committed Mar 22, 2023
commit d5fbc37edb8e2c3e983ef79e78c861e1e16b9ce8
6 changes: 1 addition & 5 deletions Include/internal/pycore_unicodeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ struct _Py_unicode_runtime_ids {
};

struct _Py_unicode_runtime_state {
struct {
PyThreadState *tstate;
/* The actual interned dict is at
_PyRuntime.cached_objects.interned_strings. */
} interned;
struct _Py_unicode_runtime_ids ids;
/* The interned dict is at _PyRuntime.cached_objects.interned_strings. */
};

/* fs_codec.encoding is initialized to NULL.
Expand Down
29 changes: 1 addition & 28 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -14588,29 +14588,7 @@ _PyUnicode_InitTypes(PyInterpreterState *interp)
static PyThreadState *
get_interned_tstate(void)
{
PyThreadState *tstate = _PyRuntime.unicode_state.interned.tstate;
if (tstate == NULL) {
PyInterpreterState *main_interp = _PyInterpreterState_Main();
/* We do not "bind" the thread state here. */
tstate = _PyThreadState_New(main_interp);
if (tstate == NULL) {
PyErr_Clear();
return NULL;
}
_PyRuntime.unicode_state.interned.tstate = tstate;
}
return tstate;
}

static void
clear_interned_tstate(void)
{
PyThreadState *tstate = _PyRuntime.unicode_state.interned.tstate;
if (tstate != NULL) {
_PyRuntime.unicode_state.interned.tstate = NULL;
PyThreadState_Clear(tstate);
PyThreadState_Delete(tstate);
}
return &_PyRuntime.cached_objects.main_tstate;
}

static inline PyObject *
Expand All @@ -14623,9 +14601,6 @@ store_interned(PyObject *obj)
PyThreadState *oldts = NULL;
if (!_Py_IsMainInterpreter(_PyInterpreterState_GET())) {
PyThreadState *main_tstate = get_interned_tstate();
if (main_tstate == NULL) {
return NULL;
}
oldts = PyThreadState_Swap(main_tstate);
assert(oldts != NULL);
}
Expand Down Expand Up @@ -14750,8 +14725,6 @@ _PyUnicode_ClearInterned(PyInterpreterState *interp)
PyDict_Clear(interned);
Py_DECREF(interned);
set_interned_dict(NULL);

clear_interned_tstate();
}


Expand Down