Skip to content

Commit e474309

Browse files
author
Victor Stinner
committed
initfsencoding(): get_codeset() failure is now a fatal error
Don't fallback to utf-8 anymore to avoid mojibake. I never got any error from his function.
1 parent 07298a1 commit e474309

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

Python/pythonrun.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -730,21 +730,14 @@ initfsencoding(void)
730730
/* On Unix, set the file system encoding according to the
731731
user's preference, if the CODESET names a well-known
732732
Python codec, and Py_FileSystemDefaultEncoding isn't
733-
initialized by other means. Also set the encoding of
734-
stdin and stdout if these are terminals. */
733+
initialized by other means. */
735734
codeset = get_codeset();
736-
if (codeset != NULL) {
737-
Py_FileSystemDefaultEncoding = codeset;
738-
Py_HasFileSystemDefaultEncoding = 0;
739-
return;
740-
} else {
741-
fprintf(stderr, "Unable to get the locale encoding:\n");
742-
PyErr_Print();
743-
}
735+
if (codeset == NULL)
736+
Py_FatalError("Py_Initialize: Unable to get the locale encoding");
744737

745-
fprintf(stderr, "Unable to get the filesystem encoding: fallback to utf-8\n");
746-
Py_FileSystemDefaultEncoding = "utf-8";
747-
Py_HasFileSystemDefaultEncoding = 1;
738+
Py_FileSystemDefaultEncoding = codeset;
739+
Py_HasFileSystemDefaultEncoding = 0;
740+
return;
748741
}
749742
#endif
750743

0 commit comments

Comments
 (0)