| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ac1a248 commit 1805a62
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,12 +93,12 @@ Process-wide parameters | |||
| 93 | 93 | single: main() | |
| 94 | 94 | triple: stdin; stdout; sdterr | |
| 95 | 95 | ||
| 96 | - This function should be called before :c:func:`Py_Initialize`. It | ||
| 97 | - specifies which encoding and error handling to use with standard io, | ||
| 98 | - with the same meanings as in :func:`str.encode`. | ||
| 96 | + This function should be called before :c:func:`Py_Initialize`, if it is | ||
| 97 | + called at all. It specifies which encoding and error handling to use | ||
| 98 | + with standard IO, with the same meanings as in :func:`str.encode`. | ||
| 99 | 99 | ||
| 100 | 100 | It overrides :envvar:`PYTHONIOENCODING` values, and allows embedding code | |
| 101 | - to control io encoding when the environment variable does not work. | ||
| 101 | + to control IO encoding when the environment variable does not work. | ||
| 102 | 102 | ||
| 103 | 103 | ``encoding`` and/or ``errors`` may be NULL to use | |
| 104 | 104 | :envvar:`PYTHONIOENCODING` and/or default values (depending on other | |
@@ -110,7 +110,10 @@ Process-wide parameters | |||
| 110 | 110 | If :c:func:`Py_Finalize` is called, this function will need to be called | |
| 111 | 111 | again in order to affect subsequent calls to :c:func:`Py_Initialize`. | |
| 112 | 112 | ||
| 113 | - Returns 0 if successful. | ||
| 113 | + Returns 0 if successful, a nonzero value on error (e.g. calling after the | ||
| 114 | + interpreter has already been initialized). | ||
| 115 | + | ||
| 116 | + .. versionadded:: 3.4 | ||
| 114 | 117 | ||
| 115 | 118 | ||
| 116 | 119 | .. c:function:: void Py_SetProgramName(wchar_t *name) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,8 +28,13 @@ PyAPI_FUNC(wchar_t *) Py_GetProgramName(void); | |||
| 28 | 28 | PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *); | |
| 29 | 29 | PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void); | |
| 30 | 30 | ||
| 31 | + #ifndef Py_LIMITED_API | ||
| 32 | + /* Only used by applications that embed the interpreter and need to | ||
| 33 | + * override the standard encoding determination mechanism | ||
| 34 | + */ | ||
| 31 | 35 | PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding, | |
| 32 | 36 | const char *errors); | |
| 37 | + #endif | ||
| 33 | 38 | ||
| 34 | 39 | PyAPI_FUNC(void) Py_Initialize(void); | |
| 35 | 40 | PyAPI_FUNC(void) Py_InitializeEx(int); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -148,11 +148,17 @@ Py_SetStandardStreamEncoding(const char *encoding, const char *errors) | |||
| 148 | 148 | /* This is too late to have any effect */ | |
| 149 | 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 | 158 | if (encoding) { | |
| 152 | 159 | _Py_StandardStreamEncoding = _PyMem_RawStrdup(encoding); | |
| 153 | 160 | if (!_Py_StandardStreamEncoding) { | |
| 154 | - PyErr_NoMemory(); | ||
| 155 | - return -1; | ||
| 161 | + return -2; | ||
| 156 | 162 | } | |
| 157 | 163 | } | |
| 158 | 164 | if (errors) { | |
@@ -161,8 +167,7 @@ Py_SetStandardStreamEncoding(const char *encoding, const char *errors) | |||
| 161 | 167 | if (_Py_StandardStreamEncoding) { | |
| 162 | 168 | PyMem_RawFree(_Py_StandardStreamEncoding); | |
| 163 | 169 | } | |
| 164 | - PyErr_NoMemory(); | ||
| 165 | - return -1; | ||
| 170 | + return -3; | ||
| 166 | 171 | } | |
| 167 | 172 | } | |
| 168 | 173 | return 0; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments