aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-06-08 18:12:59 +0200
committerGitHub <noreply@github.com>2020-06-08 18:12:59 +0200
commite81f6e687d0f04a45f2389d0b43fafd6d8491624 (patch)
tree58e75c8ff552241a84bb1f9b1904e06b1c88527f /Programs
parentbpo-40854: Allow overriding sys.platlibdir via PYTHONPLATLIBDIR env-var (GH-2... (diff)
downloadcpython-e81f6e687d0f04a45f2389d0b43fafd6d8491624.tar.gz
cpython-e81f6e687d0f04a45f2389d0b43fafd6d8491624.tar.bz2
cpython-e81f6e687d0f04a45f2389d0b43fafd6d8491624.zip
bpo-40910: Export Py_GetArgcArgv() function (GH-20721)
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().
Diffstat (limited to 'Programs')
-rw-r--r--Programs/_testembed.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index 11524dfbc0d..d89f6be6570 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -1334,6 +1334,7 @@ static int test_init_read_set(void)
return 0;
fail:
+ PyConfig_Clear(&config);
Py_ExitStatusException(status);
}
@@ -1592,6 +1593,46 @@ static int test_run_main(void)
}
+static int test_get_argc_argv(void)
+{
+ PyConfig config;
+ PyConfig_InitPythonConfig(&config);
+
+ wchar_t *argv[] = {L"python3", L"-c",
+ (L"import sys; "
+ L"print(f'Py_RunMain(): sys.argv={sys.argv}')"),
+ L"arg2"};
+ config_set_argv(&config, Py_ARRAY_LENGTH(argv), argv);
+ config_set_string(&config, &config.program_name, L"./python3");
+
+ // Calling PyConfig_Read() twice must not change Py_GetArgcArgv() result.
+ // The second call is done by Py_InitializeFromConfig().
+ PyStatus status = PyConfig_Read(&config);
+ if (PyStatus_Exception(status)) {
+ PyConfig_Clear(&config);
+ Py_ExitStatusException(status);
+ }
+
+ init_from_config_clear(&config);
+
+ int get_argc;
+ wchar_t **get_argv;
+ Py_GetArgcArgv(&get_argc, &get_argv);
+ printf("argc: %i\n", get_argc);
+ assert(get_argc == Py_ARRAY_LENGTH(argv));
+ for (int i=0; i < get_argc; i++) {
+ printf("argv[%i]: %ls\n", i, get_argv[i]);
+ assert(wcscmp(get_argv[i], argv[i]) == 0);
+ }
+
+ Py_Finalize();
+
+ printf("\n");
+ printf("test ok\n");
+ return 0;
+}
+
+
/* *********************************************************
* List of test cases and the function that implements it.
*
@@ -1649,6 +1690,7 @@ static struct TestCase TestCases[] = {
{"test_init_setpythonhome", test_init_setpythonhome},
{"test_init_warnoptions", test_init_warnoptions},
{"test_run_main", test_run_main},
+ {"test_get_argc_argv", test_get_argc_argv},
{"test_open_code_hook", test_open_code_hook},
{"test_audit", test_audit},