]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-37388: Don't check encoding/errors during finalization (GH-19409)
authorVictor Stinner <vstinner@python.org>
Tue, 7 Apr 2020 14:07:42 +0000 (16:07 +0200)
committerGitHub <noreply@github.com>
Tue, 7 Apr 2020 14:07:42 +0000 (16:07 +0200)
str.encode() and str.decode() no longer check the encoding and errors
in development mode or in debug mode during Python finalization. The
codecs machinery can no longer work on very late calls to
str.encode() and str.decode().

This change should help to call _PyObject_Dump() to debug during late
Python finalization.

Misc/NEWS.d/next/Core and Builtins/2020-04-07-15-44-29.bpo-37388.stlxBq.rst [new file with mode: 0644]
Objects/unicodeobject.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-04-07-15-44-29.bpo-37388.stlxBq.rst b/Misc/NEWS.d/next/Core and Builtins/2020-04-07-15-44-29.bpo-37388.stlxBq.rst
new file mode 100644 (file)
index 0000000..1da58d1
--- /dev/null
@@ -0,0 +1,4 @@
+str.encode() and str.decode() no longer check the encoding and errors in
+development mode or in debug mode during Python finalization. The codecs
+machinery can no longer work on very late calls to str.encode() and
+str.decode().
index 9d51c8a685ebed23d75e94b0f86d328658af24c0..da17bfe01f3100d0e55a4790896dc92eda985e4b 100644 (file)
@@ -451,6 +451,12 @@ unicode_check_encoding_errors(const char *encoding, const char *errors)
         return 0;
     }
 
+    /* Disable checks during Python finalization. For example, it allows to
+       call _PyObject_Dump() during finalization for debugging purpose. */
+    if (interp->finalizing) {
+        return 0;
+    }
+
     if (encoding != NULL) {
         PyObject *handler = _PyCodec_Lookup(encoding);
         if (handler == NULL) {