diff options
Diffstat (limited to 'Python')
-rw-r--r-- | Python/initconfig.c | 108 | ||||
-rw-r--r-- | Python/pathconfig.c | 31 | ||||
-rw-r--r-- | Python/pylifecycle.c | 1 | ||||
-rw-r--r-- | Python/sysmodule.c | 21 |
4 files changed, 20 insertions, 141 deletions
diff --git a/Python/initconfig.c b/Python/initconfig.c index 0d42b7e..1dcefd4 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -514,94 +514,6 @@ _PyWideStringList_AsList(const PyWideStringList *list) } -/* --- Py_SetStandardStreamEncoding() ----------------------------- */ - -/* Helper to allow an embedding application to override the normal - * mechanism that attempts to figure out an appropriate IO encoding - */ - -static char *_Py_StandardStreamEncoding = NULL; -static char *_Py_StandardStreamErrors = NULL; - -int -Py_SetStandardStreamEncoding(const char *encoding, const char *errors) -{ - if (Py_IsInitialized()) { - /* This is too late to have any effect */ - return -1; - } - - int res = 0; - - /* Py_SetStandardStreamEncoding() can be called before Py_Initialize(), - but Py_Initialize() can change the allocator. Use a known allocator - to be able to release the memory later. */ - PyMemAllocatorEx old_alloc; - _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - - /* 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) { - PyMem_RawFree(_Py_StandardStreamEncoding); - _Py_StandardStreamEncoding = _PyMem_RawStrdup(encoding); - if (!_Py_StandardStreamEncoding) { - res = -2; - goto done; - } - } - if (errors) { - PyMem_RawFree(_Py_StandardStreamErrors); - _Py_StandardStreamErrors = _PyMem_RawStrdup(errors); - if (!_Py_StandardStreamErrors) { - PyMem_RawFree(_Py_StandardStreamEncoding); - _Py_StandardStreamEncoding = NULL; - res = -3; - goto done; - } - } -#ifdef MS_WINDOWS - if (_Py_StandardStreamEncoding) { -_Py_COMP_DIAG_PUSH -_Py_COMP_DIAG_IGNORE_DEPR_DECLS - /* Overriding the stream encoding implies legacy streams */ - Py_LegacyWindowsStdioFlag = 1; -_Py_COMP_DIAG_POP - } -#endif - -done: - PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - - return res; -} - - -void -_Py_ClearStandardStreamEncoding(void) -{ - /* Use the same allocator than Py_SetStandardStreamEncoding() */ - PyMemAllocatorEx old_alloc; - _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - - /* We won't need them anymore. */ - if (_Py_StandardStreamEncoding) { - PyMem_RawFree(_Py_StandardStreamEncoding); - _Py_StandardStreamEncoding = NULL; - } - if (_Py_StandardStreamErrors) { - PyMem_RawFree(_Py_StandardStreamErrors); - _Py_StandardStreamErrors = NULL; - } - - PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); -} - - /* --- Py_GetArgcArgv() ------------------------------------------- */ void @@ -1973,26 +1885,6 @@ config_init_stdio_encoding(PyConfig *config, { PyStatus status; - /* If Py_SetStandardStreamEncoding() has been called, use its - arguments if they are not NULL. */ - if (config->stdio_encoding == NULL && _Py_StandardStreamEncoding != NULL) { - status = CONFIG_SET_BYTES_STR(config, &config->stdio_encoding, - _Py_StandardStreamEncoding, - "_Py_StandardStreamEncoding"); - if (_PyStatus_EXCEPTION(status)) { - return status; - } - } - - if (config->stdio_errors == NULL && _Py_StandardStreamErrors != NULL) { - status = CONFIG_SET_BYTES_STR(config, &config->stdio_errors, - _Py_StandardStreamErrors, - "_Py_StandardStreamErrors"); - if (_PyStatus_EXCEPTION(status)) { - return status; - } - } - // Exit if encoding and errors are defined if (config->stdio_encoding != NULL && config->stdio_errors != NULL) { return _PyStatus_OK(); diff --git a/Python/pathconfig.c b/Python/pathconfig.c index be0f97c..afffa13 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -211,7 +211,8 @@ path_out_of_memory(const char *func) _Py_FatalErrorFunc(func, "out of memory"); } -void +// Removed in Python 3.13 API, but kept for the stable ABI +PyAPI_FUNC(void) Py_SetPath(const wchar_t *path) { if (path == NULL) { @@ -252,7 +253,8 @@ Py_SetPath(const wchar_t *path) } -void +// Removed in Python 3.13 API, but kept for the stable ABI +PyAPI_FUNC(void) Py_SetPythonHome(const wchar_t *home) { int has_value = home && home[0]; @@ -275,7 +277,8 @@ Py_SetPythonHome(const wchar_t *home) } -void +// Removed in Python 3.13 API, but kept for the stable ABI +PyAPI_FUNC(void) Py_SetProgramName(const wchar_t *program_name) { int has_value = program_name && program_name[0]; @@ -297,28 +300,6 @@ Py_SetProgramName(const wchar_t *program_name) } } -void -_Py_SetProgramFullPath(const wchar_t *program_full_path) -{ - int has_value = program_full_path && program_full_path[0]; - - PyMemAllocatorEx old_alloc; - _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - - PyMem_RawFree(_Py_path_config.program_full_path); - _Py_path_config.program_full_path = NULL; - - if (has_value) { - _Py_path_config.program_full_path = _PyMem_RawWcsdup(program_full_path); - } - - PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - - if (has_value && _Py_path_config.program_full_path == NULL) { - path_out_of_memory(__func__); - } -} - wchar_t * Py_GetPath(void) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 06c4345..c6fbf17 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2556,7 +2556,6 @@ error: res = _PyStatus_ERR("can't initialize sys standard streams"); done: - _Py_ClearStandardStreamEncoding(); Py_XDECREF(iomod); return res; } diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 32be7ec..4427e73 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2614,7 +2614,8 @@ _PySys_AddWarnOptionWithError(PyThreadState *tstate, PyObject *option) return 0; } -void +// Removed in Python 3.13 API, but kept for the stable ABI +PyAPI_FUNC(void) PySys_AddWarnOptionUnicode(PyObject *option) { PyThreadState *tstate = _PyThreadState_GET(); @@ -2626,7 +2627,8 @@ PySys_AddWarnOptionUnicode(PyObject *option) } } -void +// Removed in Python 3.13 API, but kept for the stable ABI +PyAPI_FUNC(void) PySys_AddWarnOption(const wchar_t *s) { PyThreadState *tstate = _PyThreadState_GET(); @@ -2645,7 +2647,8 @@ _Py_COMP_DIAG_POP Py_DECREF(unicode); } -int +// Removed in Python 3.13 API, but kept for the stable ABI +PyAPI_FUNC(int) PySys_HasWarnOptions(void) { PyThreadState *tstate = _PyThreadState_GET(); @@ -2718,7 +2721,8 @@ error: return -1; } -void +// Removed in Python 3.13 API, but kept for the stable ABI +PyAPI_FUNC(void) PySys_AddXOption(const wchar_t *s) { PyThreadState *tstate = _PyThreadState_GET(); @@ -3621,7 +3625,8 @@ makepathobject(const wchar_t *path, wchar_t delim) return v; } -void +// Removed in Python 3.13 API, but kept for the stable ABI +PyAPI_FUNC(void) PySys_SetPath(const wchar_t *path) { PyObject *v; @@ -3653,7 +3658,8 @@ make_sys_argv(int argc, wchar_t * const * argv) return list; } -void +// Removed in Python 3.13 API, but kept for the stable ABI +PyAPI_FUNC(void) PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) { wchar_t* empty_argv[1] = {L""}; @@ -3697,7 +3703,8 @@ PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) } } -void +// Removed in Python 3.13 API, but kept for the stable ABI +PyAPI_FUNC(void) PySys_SetArgv(int argc, wchar_t **argv) { _Py_COMP_DIAG_PUSH |