summaryrefslogtreecommitdiff
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-11-04 14:53:01 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2014-11-04 14:53:01 +0100
commitdd228651e3a44907fdb6d9c487a6394c48dbfe34 (patch)
tree3a9d6c3c95bf279566b785a34005bad11038d701 /Python/pythonrun.c
parent661cba0fcc21c1904cdcd14431c53456b55b50e3 (diff)
parent56a58b5598c990c23dcdb77cbd8c517e29719acf (diff)
downloadcpython-dd228651e3a44907fdb6d9c487a6394c48dbfe34.tar.gz
Issue #22773: fix failing test with old readline versions due to issue #19884.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 0327830247..bac39c23b4 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -15,6 +15,7 @@
#include "ast.h"
#include "marshal.h"
#include "osdefs.h"
+#include <locale.h>
#ifdef HAVE_SIGNAL_H
#include <signal.h>
@@ -25,7 +26,6 @@
#endif
#ifdef HAVE_LANGINFO_H
-#include <locale.h>
#include <langinfo.h>
#endif
@@ -452,7 +452,8 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib)
if (_PyFaulthandler_Init())
Py_FatalError("Py_Initialize: can't initialize faulthandler");
- _PyTime_Init();
+ if (_PyTime_Init() < 0)
+ Py_FatalError("Py_Initialize: can't initialize time");
if (initfsencoding(interp) < 0)
Py_FatalError("Py_Initialize: unable to load the file system codec");
@@ -1160,6 +1161,15 @@ initstdio(void)
encoding = _Py_StandardStreamEncoding;
errors = _Py_StandardStreamErrors;
if (!encoding || !errors) {
+ if (!errors) {
+ /* When the LC_CTYPE locale is the POSIX locale ("C locale"),
+ stdin and stdout use the surrogateescape error handler by
+ default, instead of the strict error handler. */
+ char *loc = setlocale(LC_CTYPE, NULL);
+ if (loc != NULL && strcmp(loc, "C") == 0)
+ errors = "surrogateescape";
+ }
+
pythonioencoding = Py_GETENV("PYTHONIOENCODING");
if (pythonioencoding) {
char *err;
@@ -1172,7 +1182,7 @@ initstdio(void)
if (err) {
*err = '\0';
err++;
- if (*err && !errors) {
+ if (*err && !_Py_StandardStreamErrors) {
errors = err;
}
}
@@ -1729,7 +1739,7 @@ print_error_text(PyObject *f, int offset, PyObject *text_obj)
return;
if (offset >= 0) {
- if (offset > 0 && offset == strlen(text) && text[offset - 1] == '\n')
+ if (offset > 0 && (size_t)offset == strlen(text) && text[offset - 1] == '\n')
offset--;
for (;;) {
nl = strchr(text, '\n');