Mercurial > cpython-lru_cache-weakref
diff Python/pythonrun.c @ 85673:c7fdb0637d0b
Issue #18818: The "encodingname" part of PYTHONIOENCODING is now optional.
| author | Serhiy Storchaka <storchaka@gmail.com> |
|---|---|
| date | Fri, 13 Sep 2013 11:46:24 +0300 |
| parents | acc7439b1406 |
| children | c13ef65f3dcf |
line wrap: on
line diff
--- a/Python/pythonrun.c Fri Sep 13 00:22:45 2013 -0700 +++ b/Python/pythonrun.c Fri Sep 13 11:46:24 2013 +0300 @@ -1056,7 +1056,7 @@ PyObject *std = NULL; int status = 0, fd; PyObject * encoding_attr; - char *encoding = NULL, *errors; + char *pythonioencoding = NULL, *encoding, *errors; /* Hack to avoid a nasty recursion issue when Python is invoked in verbose mode: pre-import the Latin-1 and UTF-8 codecs */ @@ -1088,19 +1088,23 @@ } Py_DECREF(wrapper); - encoding = Py_GETENV("PYTHONIOENCODING"); - errors = NULL; - if (encoding) { - encoding = _PyMem_Strdup(encoding); - if (encoding == NULL) { + pythonioencoding = Py_GETENV("PYTHONIOENCODING"); + encoding = errors = NULL; + if (pythonioencoding) { + pythonioencoding = _PyMem_Strdup(pythonioencoding); + if (pythonioencoding == NULL) { PyErr_NoMemory(); goto error; } - errors = strchr(encoding, ':'); + errors = strchr(pythonioencoding, ':'); if (errors) { *errors = '\0'; errors++; + if (!*errors) + errors = NULL; } + if (*pythonioencoding) + encoding = pythonioencoding; } /* Set sys.stdin */ @@ -1180,7 +1184,7 @@ status = -1; } - PyMem_Free(encoding); + PyMem_Free(pythonioencoding); Py_XDECREF(bimod); Py_XDECREF(iomod); return status;
