[Python-checkins] python/dist/src/Python pythonrun.c, 2.195, 2.195.6.1 sysmodule.c, 2.120, 2.120.6.1

loewis at users.sourceforge.net loewis at users.sourceforge.net
Sat Aug 9 03:48:31 EDT 2003


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv406/Python

Modified Files:
      Tag: release23-maint
	pythonrun.c sysmodule.c 
Log Message:
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Verify that the encoding actually exists. Fixes #775985.


Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.195
retrieving revision 2.195.6.1
diff -C2 -d -r2.195 -r2.195.6.1
*** pythonrun.c	16 Jul 2003 01:54:38 -0000	2.195
--- pythonrun.c	9 Aug 2003 09:48:29 -0000	2.195.6.1
***************
*** 78,82 ****
     without acquiring the import lock
  */
! PyObject *PyModule_GetWarningsModule()
  {
  	PyObject *typ, *val, *tb;
--- 78,82 ----
     without acquiring the import lock
  */
! PyObject *PyModule_GetWarningsModule(void)
  {
  	PyObject *typ, *val, *tb;
***************
*** 143,146 ****
--- 143,151 ----
  	PyObject *bimod, *sysmod;
  	char *p;
+ #if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET)
+ 	char *codeset;
+ 	char *saved_locale;
+ 	PyObject *sys_stream, *sys_isatty;
+ #endif
  	extern void _Py_ReadyTypes(void);
  
***************
*** 228,246 ****
  	   user's preference, if the CODESET names a well-known
  	   Python codec, and Py_FileSystemDefaultEncoding isn't
! 	   initialized by other means.  */
! 	if (!Py_FileSystemDefaultEncoding) {
! 		char *saved_locale = setlocale(LC_CTYPE, NULL);
! 		char *codeset;
! 		setlocale(LC_CTYPE, "");
! 		codeset = nl_langinfo(CODESET);
! 		if (*codeset) {
! 			PyObject *enc = PyCodec_Encoder(codeset);
! 			if (enc) {
! 				Py_FileSystemDefaultEncoding = strdup(codeset);
! 				Py_DECREF(enc);
! 			} else
! 				PyErr_Clear();
  		}
! 		setlocale(LC_CTYPE, saved_locale);
  	}
  #endif
--- 233,282 ----
  	   user's preference, if the CODESET names a well-known
  	   Python codec, and Py_FileSystemDefaultEncoding isn't
! 	   initialized by other means. Also set the encoding of
! 	   stdin and stdout if these are terminals.  */
! 
! 	saved_locale = setlocale(LC_CTYPE, NULL);
! 	setlocale(LC_CTYPE, "");
! 	codeset = nl_langinfo(CODESET);
! 	if (codeset && *codeset) {
! 		PyObject *enc = PyCodec_Encoder(codeset);
! 		if (enc) {
! 			codeset = strdup(codeset);
! 			Py_DECREF(enc);
! 		} else {
! 			codeset = NULL;
! 			PyErr_Clear();
  		}
! 	} else
! 		codeset = NULL;
! 	setlocale(LC_CTYPE, saved_locale);
! 
! 	if (codeset) {
! 		sys_stream = PySys_GetObject("stdout");
! 		sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
! 		if (!sys_isatty)
! 			PyErr_Clear();
! 		if(sys_isatty && PyObject_IsTrue(sys_isatty)) {
! 			if (!PyFile_SetEncoding(sys_stream, codeset))
! 				Py_FatalError("Cannot set codeset of stdin");
! 		}
! 		Py_XDECREF(sys_stream);
! 		Py_XDECREF(sys_isatty);
! 
! 		sys_stream = PySys_GetObject("stdout");
! 		sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
! 		if (!sys_isatty)
! 			PyErr_Clear();
! 		if(sys_isatty && PyObject_IsTrue(sys_isatty)) {
! 			if (!PyFile_SetEncoding(sys_stream, codeset))
! 				Py_FatalError("Cannot set codeset of stdout");
! 		}
! 		Py_XDECREF(sys_stream);
! 		Py_XDECREF(sys_isatty);
! 
! 		if (!Py_FileSystemDefaultEncoding)
! 			Py_FileSystemDefaultEncoding = codeset;
! 		else
! 			free(codeset);
  	}
  #endif

Index: sysmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/sysmodule.c,v
retrieving revision 2.120
retrieving revision 2.120.6.1
diff -C2 -d -r2.120 -r2.120.6.1
*** sysmodule.c	6 Jul 2003 18:36:54 -0000	2.120
--- sysmodule.c	9 Aug 2003 09:48:29 -0000	2.120.6.1
***************
*** 906,912 ****
  	char buf[10];
  #endif
- #if defined(HAVE_LANGINFO_H) && defined(CODESET)
- 	char *oldloc, *codeset;
- #endif
  
  	m = Py_InitModule3("sys", sys_methods, sys_doc);
--- 906,909 ----
***************
*** 931,949 ****
  #endif
  
- #if defined(HAVE_LANGINFO_H) && defined(CODESET)
- 	oldloc = setlocale(LC_CTYPE, 0);
- 	setlocale(LC_CTYPE, "");
- 	codeset = nl_langinfo(CODESET);
- 	setlocale(LC_CTYPE, oldloc);
- 	if(codeset && isatty(fileno(stdin))){
- 		if (!PyFile_SetEncoding(sysin, codeset))
- 			return NULL;
- 	}
- 	if(codeset && isatty(fileno(stdout))) {
- 		if (!PyFile_SetEncoding(sysout, codeset))
- 			return NULL;
- 	}
- #endif
- 	
  	PyDict_SetItemString(sysdict, "stdin", sysin);
  	PyDict_SetItemString(sysdict, "stdout", sysout);
--- 928,931 ----





More information about the Python-checkins mailing list