Skip to content

Commit 7bdfabe

Browse files
authored
gh-124785: Revert "gh-116510: Fix crash due to shared immortal interned strings (gh-124646)" (gh-124807)
Revert "gh-116510: Fix crash due to shared immortal interned strings. (gh-124646)" This reverts commit 98b2ed7.
1 parent 626d706 commit 7bdfabe

File tree

2 files changed

+6
-47
lines changed

2 files changed

+6
-47
lines changed

Misc/NEWS.d/next/Core_and_Builtins/2024-09-26-18-21-06.gh-issue-116510.FacUWO.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

Objects/unicodeobject.c

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -282,37 +282,13 @@ hashtable_unicode_compare(const void *key1, const void *key2)
282282
}
283283
}
284284

285-
/* Return true if this interpreter should share the main interpreter's
286-
intern_dict. That's important for interpreters which load basic
287-
single-phase init extension modules (m_size == -1). There could be interned
288-
immortal strings that are shared between interpreters, due to the
289-
PyDict_Update(mdict, m_copy) call in import_find_extension().
290-
291-
It's not safe to deallocate those strings until all interpreters that
292-
potentially use them are freed. By storing them in the main interpreter, we
293-
ensure they get freed after all other interpreters are freed.
294-
*/
295-
static bool
296-
has_shared_intern_dict(PyInterpreterState *interp)
297-
{
298-
PyInterpreterState *main_interp = _PyInterpreterState_Main();
299-
return interp != main_interp && interp->feature_flags & Py_RTFLAGS_USE_MAIN_OBMALLOC;
300-
}
301-
302285
static int
303286
init_interned_dict(PyInterpreterState *interp)
304287
{
305288
assert(get_interned_dict(interp) == NULL);
306-
PyObject *interned;
307-
if (has_shared_intern_dict(interp)) {
308-
interned = get_interned_dict(_PyInterpreterState_Main());
309-
Py_INCREF(interned);
310-
}
311-
else {
312-
interned = PyDict_New();
313-
if (interned == NULL) {
314-
return -1;
315-
}
289+
PyObject *interned = interned = PyDict_New();
290+
if (interned == NULL) {
291+
return -1;
316292
}
317293
_Py_INTERP_CACHED_OBJECT(interp, interned_strings) = interned;
318294
return 0;
@@ -323,10 +299,7 @@ clear_interned_dict(PyInterpreterState *interp)
323299
{
324300
PyObject *interned = get_interned_dict(interp);
325301
if (interned != NULL) {
326-
if (!has_shared_intern_dict(interp)) {
327-
// only clear if the dict belongs to this interpreter
328-
PyDict_Clear(interned);
329-
}
302+
PyDict_Clear(interned);
330303
Py_DECREF(interned);
331304
_Py_INTERP_CACHED_OBJECT(interp, interned_strings) = NULL;
332305
}
@@ -15645,13 +15618,6 @@ _PyUnicode_ClearInterned(PyInterpreterState *interp)
1564515618
}
1564615619
assert(PyDict_CheckExact(interned));
1564715620

15648-
if (has_shared_intern_dict(interp)) {
15649-
// the dict doesn't belong to this interpreter, skip the debug
15650-
// checks on it and just clear the pointer to it
15651-
clear_interned_dict(interp);
15652-
return;
15653-
}
15654-
1565515621
#ifdef INTERNED_STATS
1565615622
fprintf(stderr, "releasing %zd interned strings\n",
1565715623
PyDict_GET_SIZE(interned));
@@ -16160,10 +16126,8 @@ _PyUnicode_Fini(PyInterpreterState *interp)
1616016126
{
1616116127
struct _Py_unicode_state *state = &interp->unicode;
1616216128

16163-
if (!has_shared_intern_dict(interp)) {
16164-
// _PyUnicode_ClearInterned() must be called before _PyUnicode_Fini()
16165-
assert(get_interned_dict(interp) == NULL);
16166-
}
16129+
// _PyUnicode_ClearInterned() must be called before _PyUnicode_Fini()
16130+
assert(get_interned_dict(interp) == NULL);
1616716131

1616816132
_PyUnicode_FiniEncodings(&state->fs_codec);
1616916133

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy