comparison 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
comparison
equal deleted inserted replaced
85672:b85c9d2a5227 85673:c7fdb0637d0b
1054 PyObject *bimod = NULL; 1054 PyObject *bimod = NULL;
1055 PyObject *m; 1055 PyObject *m;
1056 PyObject *std = NULL; 1056 PyObject *std = NULL;
1057 int status = 0, fd; 1057 int status = 0, fd;
1058 PyObject * encoding_attr; 1058 PyObject * encoding_attr;
1059 char *encoding = NULL, *errors; 1059 char *pythonioencoding = NULL, *encoding, *errors;
1060 1060
1061 /* Hack to avoid a nasty recursion issue when Python is invoked 1061 /* Hack to avoid a nasty recursion issue when Python is invoked
1062 in verbose mode: pre-import the Latin-1 and UTF-8 codecs */ 1062 in verbose mode: pre-import the Latin-1 and UTF-8 codecs */
1063 if ((m = PyImport_ImportModule("encodings.utf_8")) == NULL) { 1063 if ((m = PyImport_ImportModule("encodings.utf_8")) == NULL) {
1064 goto error; 1064 goto error;
1086 Py_DECREF(wrapper); 1086 Py_DECREF(wrapper);
1087 goto error; 1087 goto error;
1088 } 1088 }
1089 Py_DECREF(wrapper); 1089 Py_DECREF(wrapper);
1090 1090
1091 encoding = Py_GETENV("PYTHONIOENCODING"); 1091 pythonioencoding = Py_GETENV("PYTHONIOENCODING");
1092 errors = NULL; 1092 encoding = errors = NULL;
1093 if (encoding) { 1093 if (pythonioencoding) {
1094 encoding = _PyMem_Strdup(encoding); 1094 pythonioencoding = _PyMem_Strdup(pythonioencoding);
1095 if (encoding == NULL) { 1095 if (pythonioencoding == NULL) {
1096 PyErr_NoMemory(); 1096 PyErr_NoMemory();
1097 goto error; 1097 goto error;
1098 } 1098 }
1099 errors = strchr(encoding, ':'); 1099 errors = strchr(pythonioencoding, ':');
1100 if (errors) { 1100 if (errors) {
1101 *errors = '\0'; 1101 *errors = '\0';
1102 errors++; 1102 errors++;
1103 } 1103 if (!*errors)
1104 errors = NULL;
1105 }
1106 if (*pythonioencoding)
1107 encoding = pythonioencoding;
1104 } 1108 }
1105 1109
1106 /* Set sys.stdin */ 1110 /* Set sys.stdin */
1107 fd = fileno(stdin); 1111 fd = fileno(stdin);
1108 /* Under some conditions stdin, stdout and stderr may not be connected 1112 /* Under some conditions stdin, stdout and stderr may not be connected
1178 if (0) { 1182 if (0) {
1179 error: 1183 error:
1180 status = -1; 1184 status = -1;
1181 } 1185 }
1182 1186
1183 PyMem_Free(encoding); 1187 PyMem_Free(pythonioencoding);
1184 Py_XDECREF(bimod); 1188 Py_XDECREF(bimod);
1185 Py_XDECREF(iomod); 1189 Py_XDECREF(iomod);
1186 return status; 1190 return status;
1187 } 1191 }
1188 1192