Skip to content

Commit

Permalink
bpo-37388: Don't check encoding/errors during finalization (GH-19409)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vstinner authored Apr 7, 2020
1 parent 74e1b6b commit d8acf0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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().
6 changes: 6 additions & 0 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d8acf0d

Please sign in to comment.