diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2013-10-18 23:11:47 +1000 |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2013-10-18 23:11:47 +1000 |
commit | 595d11f97b0cb5fb5242835f3a4f5db2e4ce08c1 (patch) | |
tree | 2cb261a233f0a446a3c1606efa21e9412709fd66 /Python/pythonrun.c | |
parent | e24cacbf5f774e3485d59ab8cb0d59774835d50f (diff) | |
download | cpython-595d11f97b0cb5fb5242835f3a4f5db2e4ce08c1.tar.gz |
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
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 3bcc4742d1..b963ce1132 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -148,11 +148,17 @@ Py_SetStandardStreamEncoding(const char *encoding, const char *errors) /* 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 @@ Py_SetStandardStreamEncoding(const char *encoding, const char *errors) if (_Py_StandardStreamEncoding) { PyMem_RawFree(_Py_StandardStreamEncoding); } - PyErr_NoMemory(); - return -1; + return -3; } } return 0; |