comparison Python/pythonrun.c @ 30910:a29a585b03d9 legacy-trunk

Patch #804543: strdup saved locales. Backported to 2.3.
author Martin v. Löwis <martin@v.loewis.de>
date Thu, 13 Nov 2003 07:43:21 +0000
parents 3b59fa5d25b1
children b6c139544c16
comparison
equal deleted inserted replaced
30907:3d9b36d6ab89 30910:a29a585b03d9
233 user's preference, if the CODESET names a well-known 233 user's preference, if the CODESET names a well-known
234 Python codec, and Py_FileSystemDefaultEncoding isn't 234 Python codec, and Py_FileSystemDefaultEncoding isn't
235 initialized by other means. Also set the encoding of 235 initialized by other means. Also set the encoding of
236 stdin and stdout if these are terminals. */ 236 stdin and stdout if these are terminals. */
237 237
238 saved_locale = setlocale(LC_CTYPE, NULL); 238 saved_locale = strdup(setlocale(LC_CTYPE, NULL));
239 setlocale(LC_CTYPE, ""); 239 setlocale(LC_CTYPE, "");
240 codeset = nl_langinfo(CODESET); 240 codeset = nl_langinfo(CODESET);
241 if (codeset && *codeset) { 241 if (codeset && *codeset) {
242 PyObject *enc = PyCodec_Encoder(codeset); 242 PyObject *enc = PyCodec_Encoder(codeset);
243 if (enc) { 243 if (enc) {
248 PyErr_Clear(); 248 PyErr_Clear();
249 } 249 }
250 } else 250 } else
251 codeset = NULL; 251 codeset = NULL;
252 setlocale(LC_CTYPE, saved_locale); 252 setlocale(LC_CTYPE, saved_locale);
253 free(saved_locale);
253 254
254 if (codeset) { 255 if (codeset) {
255 sys_stream = PySys_GetObject("stdin"); 256 sys_stream = PySys_GetObject("stdin");
256 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); 257 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
257 if (!sys_isatty) 258 if (!sys_isatty)