]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38858: Call _PyUnicode_Fini() in Py_EndInterpreter() (GH-17330)
authorVictor Stinner <vstinner@python.org>
Fri, 22 Nov 2019 11:27:50 +0000 (12:27 +0100)
committerGitHub <noreply@github.com>
Fri, 22 Nov 2019 11:27:50 +0000 (12:27 +0100)
Py_EndInterpreter() now clears the filesystem codec.

Include/internal/pycore_pylifecycle.h
Objects/unicodeobject.c
Python/pylifecycle.c

index c837bcdbc03cc9d9b78213ddb5b3bbcd82107134..73aa5ef1f6cabdcd727a317cb3c21307d02b60d2 100644 (file)
@@ -77,7 +77,7 @@ extern void _PyImport_Fini2(void);
 extern void _PyGC_Fini(PyThreadState *tstate);
 extern void _PyType_Fini(void);
 extern void _Py_HashRandomization_Fini(void);
-extern void _PyUnicode_Fini(void);
+extern void _PyUnicode_Fini(PyThreadState *tstate);
 extern void _PyLong_Fini(void);
 extern void _PyFaulthandler_Fini(void);
 extern void _PyHash_Fini(void);
index 5ae0af8ea336a7d1cde6b9bb65b7e75bd3ee75fc..89e45d01e3789e06551ef151fe62f1205703a748 100644 (file)
@@ -15929,34 +15929,37 @@ _PyUnicode_EnableLegacyWindowsFSEncoding(void)
 
 
 void
-_PyUnicode_Fini(void)
+_PyUnicode_Fini(PyThreadState *tstate)
 {
+    if (_Py_IsMainInterpreter(tstate)) {
 #if defined(WITH_VALGRIND) || defined(__INSURE__)
-    /* Insure++ is a memory analysis tool that aids in discovering
-     * memory leaks and other memory problems.  On Python exit, the
-     * interned string dictionaries are flagged as being in use at exit
-     * (which it is).  Under normal circumstances, this is fine because
-     * the memory will be automatically reclaimed by the system.  Under
-     * memory debugging, it's a huge source of useless noise, so we
-     * trade off slower shutdown for less distraction in the memory
-     * reports.  -baw
-     */
-    unicode_release_interned();
+        /* Insure++ is a memory analysis tool that aids in discovering
+         * memory leaks and other memory problems.  On Python exit, the
+         * interned string dictionaries are flagged as being in use at exit
+         * (which it is).  Under normal circumstances, this is fine because
+         * the memory will be automatically reclaimed by the system.  Under
+         * memory debugging, it's a huge source of useless noise, so we
+         * trade off slower shutdown for less distraction in the memory
+         * reports.  -baw
+         */
+        unicode_release_interned();
 #endif /* __INSURE__ */
 
-    Py_CLEAR(unicode_empty);
+        Py_CLEAR(unicode_empty);
 
-    for (Py_ssize_t i = 0; i < 256; i++) {
-        Py_CLEAR(unicode_latin1[i]);
+        for (Py_ssize_t i = 0; i < 256; i++) {
+            Py_CLEAR(unicode_latin1[i]);
+        }
+        _PyUnicode_ClearStaticStrings();
+        (void)PyUnicode_ClearFreeList();
     }
-    _PyUnicode_ClearStaticStrings();
-    (void)PyUnicode_ClearFreeList();
 
     PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
     PyMem_RawFree(interp->fs_codec.encoding);
     interp->fs_codec.encoding = NULL;
     PyMem_RawFree(interp->fs_codec.errors);
     interp->fs_codec.errors = NULL;
+    interp->config.filesystem_errors = _Py_ERROR_UNKNOWN;
 }
 
 
index 8c508e33800eff529682fbdf3bbac485753c0624..5f3c49a6804391315801e2386c9a068875698b3b 100644 (file)
@@ -1182,9 +1182,6 @@ finalize_interp_types(PyThreadState *tstate, int is_main_interp)
         _PySet_Fini();
         _PyBytes_Fini();
         _PyLong_Fini();
-    }
-
-    if (is_main_interp) {
         _PyFloat_Fini();
         _PyDict_Fini();
         _PySlice_Fini();
@@ -1197,9 +1194,12 @@ finalize_interp_types(PyThreadState *tstate, int is_main_interp)
         _PyArg_Fini();
         _PyAsyncGen_Fini();
         _PyContext_Fini();
+    }
+
+    /* Cleanup Unicode implementation */
+    _PyUnicode_Fini(tstate);
 
-        /* Cleanup Unicode implementation */
-        _PyUnicode_Fini();
+    if (is_main_interp) {
         _Py_ClearFileSystemEncoding();
     }
 }