Skip to content

Commit 36242fd

Browse files
authored
bpo-36763: Add PyConfig_SetWideStringList() (GH-14444)
1 parent e21b45a commit 36242fd

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

Doc/c-api/init_config.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Functions:
2525
* :c:func:`PyConfig_SetBytesArgv`
2626
* :c:func:`PyConfig_SetBytesString`
2727
* :c:func:`PyConfig_SetString`
28+
* :c:func:`PyConfig_SetWideStringList`
2829
* :c:func:`PyPreConfig_InitIsolatedConfig`
2930
* :c:func:`PyPreConfig_InitPythonConfig`
3031
* :c:func:`PyStatus_Error`
@@ -368,6 +369,12 @@ PyConfig
368369
369370
Preinitialize Python if needed.
370371
372+
.. c:function:: PyStatus PyConfig_SetWideStringList(PyConfig *config, PyWideStringList *list, Py_ssize_t length, wchar_t **items)
373+
374+
Set the list of wide strings *list* to *length* and *items*.
375+
376+
Preinitialize Python if needed.
377+
371378
.. c:function:: PyStatus PyConfig_Read(PyConfig *config)
372379
373380
Read all Python configuration.

Include/cpython/initconfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ PyAPI_FUNC(PyStatus) PyConfig_SetBytesArgv(
422422
PyAPI_FUNC(PyStatus) PyConfig_SetArgv(PyConfig *config,
423423
Py_ssize_t argc,
424424
wchar_t * const *argv);
425+
PyAPI_FUNC(PyStatus) PyConfig_SetWideStringList(PyConfig *config,
426+
PyWideStringList *list,
427+
Py_ssize_t length, wchar_t **items);
425428

426429
#ifdef __cplusplus
427430
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add :func:`PyConfig_SetWideStringList` function.

Python/initconfig.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2)
732732
} while (0)
733733
#define COPY_WSTRLIST(LIST) \
734734
do { \
735-
if (_PyWideStringList_Copy(&config->LIST, &config2->LIST) < 0 ) { \
735+
if (_PyWideStringList_Copy(&config->LIST, &config2->LIST) < 0) { \
736736
return _PyStatus_NO_MEMORY(); \
737737
} \
738738
} while (0)
@@ -2324,6 +2324,23 @@ PyConfig_SetArgv(PyConfig *config, Py_ssize_t argc, wchar_t * const *argv)
23242324
}
23252325

23262326

2327+
PyStatus
2328+
PyConfig_SetWideStringList(PyConfig *config, PyWideStringList *list,
2329+
Py_ssize_t length, wchar_t **items)
2330+
{
2331+
PyStatus status = _Py_PreInitializeFromConfig(config, NULL);
2332+
if (_PyStatus_EXCEPTION(status)) {
2333+
return status;
2334+
}
2335+
2336+
PyWideStringList list2 = {.length = length, .items = items};
2337+
if (_PyWideStringList_Copy(list, &list2) < 0) {
2338+
return _PyStatus_NO_MEMORY();
2339+
}
2340+
return _PyStatus_OK();
2341+
}
2342+
2343+
23272344
/* Read the configuration into PyConfig from:
23282345
23292346
* Command line arguments

0 commit comments

Comments
 (0)