mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	SF patch #1630975: Fix crash when replacing sys.stdout in sitecustomize
When running the interpreter in an environment that would cause it to set stdout/stderr/stdin's encoding, having a sitecustomize that would replace them with something other than PyFile objects would crash the interpreter. Fix it by simply ignoring the encoding-setting for non-files. This could do with a test, but I can think of no maintainable and portable way to test this bug, short of adding a sitecustomize.py to the buildsystem and have it always run with it (hmmm....)
This commit is contained in:
		
							parent
							
								
									d2e22903d3
								
							
						
					
					
						commit
						afea529088
					
				
					 3 changed files with 11 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -275,7 +275,8 @@ Py_InitializeEx(int install_sigs)
 | 
			
		|||
		sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
 | 
			
		||||
		if (!sys_isatty)
 | 
			
		||||
			PyErr_Clear();
 | 
			
		||||
		if(sys_isatty && PyObject_IsTrue(sys_isatty)) {
 | 
			
		||||
		if(sys_isatty && PyObject_IsTrue(sys_isatty) &&
 | 
			
		||||
		   PyFile_Check(sys_stream)) {
 | 
			
		||||
			if (!PyFile_SetEncoding(sys_stream, codeset))
 | 
			
		||||
				Py_FatalError("Cannot set codeset of stdin");
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -285,7 +286,8 @@ Py_InitializeEx(int install_sigs)
 | 
			
		|||
		sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
 | 
			
		||||
		if (!sys_isatty)
 | 
			
		||||
			PyErr_Clear();
 | 
			
		||||
		if(sys_isatty && PyObject_IsTrue(sys_isatty)) {
 | 
			
		||||
		if(sys_isatty && PyObject_IsTrue(sys_isatty) &&
 | 
			
		||||
		   PyFile_Check(sys_stream)) {
 | 
			
		||||
			if (!PyFile_SetEncoding(sys_stream, codeset))
 | 
			
		||||
				Py_FatalError("Cannot set codeset of stdout");
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -295,7 +297,8 @@ Py_InitializeEx(int install_sigs)
 | 
			
		|||
		sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
 | 
			
		||||
		if (!sys_isatty)
 | 
			
		||||
			PyErr_Clear();
 | 
			
		||||
		if(sys_isatty && PyObject_IsTrue(sys_isatty)) {
 | 
			
		||||
		if(sys_isatty && PyObject_IsTrue(sys_isatty) &&
 | 
			
		||||
		   PyFile_Check(sys_stream)) {
 | 
			
		||||
			if (!PyFile_SetEncoding(sys_stream, codeset))
 | 
			
		||||
				Py_FatalError("Cannot set codeset of stderr");
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue