Mercurial > cpython-lru_cache-weakref
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 86425:0ba7280545fe | 86426:12d7b6171b28 |
|---|---|
| 146 { | 146 { |
| 147 if (Py_IsInitialized()) { | 147 if (Py_IsInitialized()) { |
| 148 /* This is too late to have any effect */ | 148 /* This is too late to have any effect */ |
| 149 return -1; | 149 return -1; |
| 150 } | 150 } |
| 151 /* Can't call PyErr_NoMemory() on errors, as Python hasn't been | |
| 152 * initialised yet. | |
| 153 * | |
| 154 * However, the raw memory allocators are initialised appropriately | |
| 155 * as C static variables, so _PyMem_RawStrdup is OK even though | |
| 156 * Py_Initialize hasn't been called yet. | |
| 157 */ | |
| 151 if (encoding) { | 158 if (encoding) { |
| 152 _Py_StandardStreamEncoding = _PyMem_RawStrdup(encoding); | 159 _Py_StandardStreamEncoding = _PyMem_RawStrdup(encoding); |
| 153 if (!_Py_StandardStreamEncoding) { | 160 if (!_Py_StandardStreamEncoding) { |
| 154 PyErr_NoMemory(); | 161 return -2; |
| 155 return -1; | |
| 156 } | 162 } |
| 157 } | 163 } |
| 158 if (errors) { | 164 if (errors) { |
| 159 _Py_StandardStreamErrors = _PyMem_RawStrdup(errors); | 165 _Py_StandardStreamErrors = _PyMem_RawStrdup(errors); |
| 160 if (!_Py_StandardStreamErrors) { | 166 if (!_Py_StandardStreamErrors) { |
| 161 if (_Py_StandardStreamEncoding) { | 167 if (_Py_StandardStreamEncoding) { |
| 162 PyMem_RawFree(_Py_StandardStreamEncoding); | 168 PyMem_RawFree(_Py_StandardStreamEncoding); |
| 163 } | 169 } |
| 164 PyErr_NoMemory(); | 170 return -3; |
| 165 return -1; | |
| 166 } | 171 } |
| 167 } | 172 } |
| 168 return 0; | 173 return 0; |
| 169 } | 174 } |
| 170 | 175 |
