bpo-40910: Export Py_GetArgcArgv() function (GH-20721) (GH-20723)
Export explicitly the Py_GetArgcArgv() function to the C API and
document the function. Previously, it was exported implicitly which
no longer works since Python is built with -fvisibility=hidden.
* Add PyConfig._orig_argv member.
* Py_InitializeFromConfig() no longer calls _PyConfig_Write() twice.
* PyConfig_Read() no longer initializes Py_GetArgcArgv(): it is now
_PyConfig_Write() responsibility.
* _PyConfig_Write() result type becomes PyStatus instead of void.
* Write an unit test on Py_GetArgcArgv().
(cherry picked from commit e81f6e687d0f04a45f2389d0b43fafd6d8491624)
diff --git a/Include/cpython/initconfig.h b/Include/cpython/initconfig.h
index df93a55..69db2af 100644
--- a/Include/cpython/initconfig.h
+++ b/Include/cpython/initconfig.h
@@ -413,6 +413,14 @@
/* If non-zero, disallow threads, subprocesses, and fork.
Default: 0. */
int _isolated_interpreter;
+
+ /* Original command line arguments. If _orig_argv is empty and _argv is
+ not equal to [''], PyConfig_Read() copies the configuration 'argv' list
+ into '_orig_argv' list before modifying 'argv' list (if parse_argv
+ is non-zero).
+
+ _PyConfig_Write() initializes Py_GetArgcArgv() to this list. */
+ PyWideStringList _orig_argv;
} PyConfig;
PyAPI_FUNC(void) PyConfig_InitPythonConfig(PyConfig *config);
@@ -438,6 +446,14 @@
PyWideStringList *list,
Py_ssize_t length, wchar_t **items);
+
+/* --- Helper functions --------------------------------------- */
+
+/* Get the original command line arguments, before Python modified them.
+
+ See also PyConfig._orig_argv. */
+PyAPI_FUNC(void) Py_GetArgcArgv(int *argc, wchar_t ***argv);
+
#ifdef __cplusplus
}
#endif