bpo-38858: Call _PyUnicode_Fini() in Py_EndInterpreter() (GH-17330) · python/cpython@3d48334 · GitHub
Skip to content

Commit 3d48334

Browse files
authored
bpo-38858: Call _PyUnicode_Fini() in Py_EndInterpreter() (GH-17330)
Py_EndInterpreter() now clears the filesystem codec.
1 parent 310e2d2 commit 3d48334

3 files changed

Lines changed: 25 additions & 22 deletions

File tree

Include/internal/pycore_pylifecycle.h

Lines changed: 1 addition & 1 deletion

Objects/unicodeobject.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15929,34 +15929,37 @@ _PyUnicode_EnableLegacyWindowsFSEncoding(void)
1592915929

1593015930

1593115931
void
15932-
_PyUnicode_Fini(void)
15932+
_PyUnicode_Fini(PyThreadState *tstate)
1593315933
{
15934+
if (_Py_IsMainInterpreter(tstate)) {
1593415935
#if defined(WITH_VALGRIND) || defined(__INSURE__)
15935-
/* Insure++ is a memory analysis tool that aids in discovering
15936-
* memory leaks and other memory problems. On Python exit, the
15937-
* interned string dictionaries are flagged as being in use at exit
15938-
* (which it is). Under normal circumstances, this is fine because
15939-
* the memory will be automatically reclaimed by the system. Under
15940-
* memory debugging, it's a huge source of useless noise, so we
15941-
* trade off slower shutdown for less distraction in the memory
15942-
* reports. -baw
15943-
*/
15944-
unicode_release_interned();
15936+
/* Insure++ is a memory analysis tool that aids in discovering
15937+
* memory leaks and other memory problems. On Python exit, the
15938+
* interned string dictionaries are flagged as being in use at exit
15939+
* (which it is). Under normal circumstances, this is fine because
15940+
* the memory will be automatically reclaimed by the system. Under
15941+
* memory debugging, it's a huge source of useless noise, so we
15942+
* trade off slower shutdown for less distraction in the memory
15943+
* reports. -baw
15944+
*/
15945+
unicode_release_interned();
1594515946
#endif /* __INSURE__ */
1594615947

15947-
Py_CLEAR(unicode_empty);
15948+
Py_CLEAR(unicode_empty);
1594815949

15949-
for (Py_ssize_t i = 0; i < 256; i++) {
15950-
Py_CLEAR(unicode_latin1[i]);
15950+
for (Py_ssize_t i = 0; i < 256; i++) {
15951+
Py_CLEAR(unicode_latin1[i]);
15952+
}
15953+
_PyUnicode_ClearStaticStrings();
15954+
(void)PyUnicode_ClearFreeList();
1595115955
}
15952-
_PyUnicode_ClearStaticStrings();
15953-
(void)PyUnicode_ClearFreeList();
1595415956

1595515957
PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
1595615958
PyMem_RawFree(interp->fs_codec.encoding);
1595715959
interp->fs_codec.encoding = NULL;
1595815960
PyMem_RawFree(interp->fs_codec.errors);
1595915961
interp->fs_codec.errors = NULL;
15962+
interp->config.filesystem_errors = _Py_ERROR_UNKNOWN;
1596015963
}
1596115964

1596215965

Python/pylifecycle.c

Lines changed: 5 additions & 5 deletions

0 commit comments

Comments
 (0)