From aaeb0958f8aeaf7fa67b96dcf3bb02e9e078992b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 7 Apr 2020 15:40:44 +0200 Subject: [PATCH] bpo-37388: Don't check encoding/errors during finalization 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. --- .../2020-04-07-15-44-29.bpo-37388.stlxBq.rst | 4 ++++ Objects/unicodeobject.c | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-04-07-15-44-29.bpo-37388.stlxBq.rst 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 index 00000000000000..1da58d111912c9 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-04-07-15-44-29.bpo-37388.stlxBq.rst @@ -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(). diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 9d51c8a685ebed..da17bfe01f3100 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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) {