Issue #8610: Load file system codec at startup, and display a fatal e… · python/cpython@b744ba1 · GitHub
Skip to content

Commit b744ba1

Browse files
author
Victor Stinner
committed
Issue #8610: Load file system codec at startup, and display a fatal error on
failure. Set the file system encoding to utf-8 (instead of None) if getting the locale encoding failed, or if nl_langinfo(CODESET) function is missing.
1 parent 06ba9ad commit b744ba1

4 files changed

Lines changed: 62 additions & 27 deletions

File tree

Doc/library/sys.rst

Lines changed: 7 additions & 5 deletions

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ What's New in Python 3.2 Alpha 1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #8610: Load file system codec at startup, and display a fatal error on
16+
failure. Set the file system encoding to utf-8 (instead of None) if getting
17+
the locale encoding failed, or if nl_langinfo(CODESET) function is missing.
18+
1519
- PyFile_FromFd() uses PyUnicode_DecodeFSDefault() instead of
1620
PyUnicode_FromString() to support surrogates in the filename and use the
1721
right encoding

Python/bltinmodule.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
#include <ctype.h>
1111

12+
#ifdef HAVE_LANGINFO_H
13+
#include <langinfo.h> /* CODESET */
14+
#endif
15+
1216
/* The default encoding used by the platform file system APIs
1317
Can remain NULL for all platforms that don't have such a concept
1418
@@ -21,9 +25,12 @@ int Py_HasFileSystemDefaultEncoding = 1;
2125
#elif defined(__APPLE__)
2226
const char *Py_FileSystemDefaultEncoding = "utf-8";
2327
int Py_HasFileSystemDefaultEncoding = 1;
24-
#else
25-
const char *Py_FileSystemDefaultEncoding = NULL; /* use default */
28+
#elif defined(HAVE_LANGINFO_H) && defined(CODESET)
29+
const char *Py_FileSystemDefaultEncoding = NULL; /* set by initfsencoding() */
2630
int Py_HasFileSystemDefaultEncoding = 0;
31+
#else
32+
const char *Py_FileSystemDefaultEncoding = "utf-8";
33+
int Py_HasFileSystemDefaultEncoding = 1;
2734
#endif
2835

2936
int

Python/pythonrun.c

Lines changed: 42 additions & 20 deletions

0 commit comments

Comments
 (0)