diff Python/pythonrun.c @ 86426:12d7b6171b28

Issue #16129: Py_SetStandardStreamEncoding cleanups - don't call PyErr_NoMemory with interpreter is not initialised - note that it's OK to call _PyMem_RawStrDup here - don't include this in the limited API - capitalise "IO" - be explicit that a non-zero return indicates an error - include versionadded marker in docs
author Nick Coghlan <ncoghlan@gmail.com>
date Fri, 18 Oct 2013 23:11:47 +1000
parents 9cd88b39ef62
children b5cc822d5bf0
line wrap: on
line diff
--- a/Python/pythonrun.c	Fri Oct 18 22:39:50 2013 +1000
+++ b/Python/pythonrun.c	Fri Oct 18 23:11:47 2013 +1000
@@ -148,11 +148,17 @@
         /* This is too late to have any effect */
         return -1;
     }
+    /* Can't call PyErr_NoMemory() on errors, as Python hasn't been
+     * initialised yet.
+     *
+     * However, the raw memory allocators are initialised appropriately
+     * as C static variables, so _PyMem_RawStrdup is OK even though
+     * Py_Initialize hasn't been called yet.
+     */
     if (encoding) {
         _Py_StandardStreamEncoding = _PyMem_RawStrdup(encoding);
         if (!_Py_StandardStreamEncoding) {
-            PyErr_NoMemory();
-            return -1;
+            return -2;
         }
     }
     if (errors) {
@@ -161,8 +167,7 @@
             if (_Py_StandardStreamEncoding) {
                 PyMem_RawFree(_Py_StandardStreamEncoding);
             }
-            PyErr_NoMemory();
-            return -1;
+            return -3;
         }
     }
     return 0;