mirror of
https://github.com/python/cpython.git
synced 2025-07-10 04:45:36 +00:00
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
This commit is contained in:
parent
ac1a248968
commit
1805a62f1f
3 changed files with 22 additions and 9 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue