From 96f581cf9d2f1d7888d2fd9bb89f19f10c0477bf Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Mon, 1 Jul 2019 10:39:58 -0700 Subject: bpo-36763: Add PyConfig_SetWideStringList() (GH-14444) (cherry picked from commit 36242fd871d0f0977e720d4fae5700774bd8c09a) Co-authored-by: Victor Stinner --- Doc/c-api/init_config.rst | 7 +++++++ Include/cpython/initconfig.h | 3 +++ .../C API/2019-06-28-15-49-16.bpo-36763.zrmgki.rst | 1 + Python/initconfig.c | 19 ++++++++++++++++++- 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/C API/2019-06-28-15-49-16.bpo-36763.zrmgki.rst diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst index 0d94e6b..d2c1f9a2 100644 --- a/Doc/c-api/init_config.rst +++ b/Doc/c-api/init_config.rst @@ -25,6 +25,7 @@ Functions: * :c:func:`PyConfig_SetBytesArgv` * :c:func:`PyConfig_SetBytesString` * :c:func:`PyConfig_SetString` +* :c:func:`PyConfig_SetWideStringList` * :c:func:`PyPreConfig_InitIsolatedConfig` * :c:func:`PyPreConfig_InitPythonConfig` * :c:func:`PyStatus_Error` @@ -368,6 +369,12 @@ PyConfig Preinitialize Python if needed. + .. c:function:: PyStatus PyConfig_SetWideStringList(PyConfig *config, PyWideStringList *list, Py_ssize_t length, wchar_t **items) + + Set the list of wide strings *list* to *length* and *items*. + + Preinitialize Python if needed. + .. c:function:: PyStatus PyConfig_Read(PyConfig *config) Read all Python configuration. diff --git a/Include/cpython/initconfig.h b/Include/cpython/initconfig.h index 297fbf7..bd07a48 100644 --- a/Include/cpython/initconfig.h +++ b/Include/cpython/initconfig.h @@ -422,6 +422,9 @@ PyAPI_FUNC(PyStatus) PyConfig_SetBytesArgv( PyAPI_FUNC(PyStatus) PyConfig_SetArgv(PyConfig *config, Py_ssize_t argc, wchar_t * const *argv); +PyAPI_FUNC(PyStatus) PyConfig_SetWideStringList(PyConfig *config, + PyWideStringList *list, + Py_ssize_t length, wchar_t **items); #ifdef __cplusplus } diff --git a/Misc/NEWS.d/next/C API/2019-06-28-15-49-16.bpo-36763.zrmgki.rst b/Misc/NEWS.d/next/C API/2019-06-28-15-49-16.bpo-36763.zrmgki.rst new file mode 100644 index 0000000..095d581 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2019-06-28-15-49-16.bpo-36763.zrmgki.rst @@ -0,0 +1 @@ +Add :func:`PyConfig_SetWideStringList` function. diff --git a/Python/initconfig.c b/Python/initconfig.c index e791a0d..1c7078a 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -732,7 +732,7 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2) } while (0) #define COPY_WSTRLIST(LIST) \ do { \ - if (_PyWideStringList_Copy(&config->LIST, &config2->LIST) < 0 ) { \ + if (_PyWideStringList_Copy(&config->LIST, &config2->LIST) < 0) { \ return _PyStatus_NO_MEMORY(); \ } \ } while (0) @@ -2277,6 +2277,23 @@ PyConfig_SetArgv(PyConfig *config, Py_ssize_t argc, wchar_t * const *argv) } +PyStatus +PyConfig_SetWideStringList(PyConfig *config, PyWideStringList *list, + Py_ssize_t length, wchar_t **items) +{ + PyStatus status = _Py_PreInitializeFromConfig(config, NULL); + if (_PyStatus_EXCEPTION(status)) { + return status; + } + + PyWideStringList list2 = {.length = length, .items = items}; + if (_PyWideStringList_Copy(list, &list2) < 0) { + return _PyStatus_NO_MEMORY(); + } + return _PyStatus_OK(); +} + + /* Read the configuration into PyConfig from: * Command line arguments -- cgit v0.12