-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-47084: Clear cached representations on finalization #32032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4b166f0
7d66a24
7a4b788
08c0999
55163a2
72f50c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16057,6 +16057,35 @@ _PyUnicode_FiniTypes(PyInterpreterState *interp) | |
} | ||
|
||
|
||
static void unicode_static_dealloc(PyObject *op) | ||
{ | ||
PyASCIIObject* ascii = (PyASCIIObject*)op; | ||
|
||
assert(ascii->state.compact); | ||
|
||
if (ascii->state.ascii) { | ||
if (ascii->wstr) { | ||
PyObject_Free(ascii->wstr); | ||
ascii->wstr = NULL; | ||
} | ||
} | ||
else { | ||
PyCompactUnicodeObject* compact = (PyCompactUnicodeObject*)op; | ||
void* data = (void*)(compact + 1); | ||
if (ascii->wstr && ascii->wstr != data) { | ||
PyObject_Free(ascii->wstr); | ||
ascii->wstr = NULL; | ||
compact->wstr_length = 0; | ||
} | ||
if (compact->utf8) { | ||
PyObject_Free(compact->utf8); | ||
compact->utf8 = NULL; | ||
compact->utf8_length = 0; | ||
} | ||
} | ||
} | ||
|
||
|
||
void | ||
_PyUnicode_Fini(PyInterpreterState *interp) | ||
{ | ||
|
@@ -16070,6 +16099,21 @@ _PyUnicode_Fini(PyInterpreterState *interp) | |
_PyUnicode_FiniEncodings(&state->fs_codec); | ||
|
||
unicode_clear_identifiers(state); | ||
|
||
// Clear the single character singletons | ||
for (int i = 0; i < 128; i++) { | ||
unicode_static_dealloc((PyObject*)&_Py_SINGLETON(strings).ascii[i]); | ||
} | ||
for (int i = 0; i < 128; i++) { | ||
unicode_static_dealloc((PyObject*)&_Py_SINGLETON(strings).latin1[i]); | ||
} | ||
} | ||
|
||
|
||
void | ||
_PyStaticUnicode_Dealloc(PyObject *op) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to share code between this function and unicode_dealloc()? Maybe add an unicode_dealloc_common() function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, there is the duplication of the |
||
{ | ||
unicode_static_dealloc(op); | ||
} | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please use
with self.subTest(flag=flag, stmt=stmt):
? Otherwise, it will be more complicated to debug if a test fails. With that, you can omitf"{xopt}, stmt='{stmt}' -> {out}")
below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know about
TestCase.subTest()
, thanks.