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().
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index f1371db..b7b7058 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -366,6 +366,7 @@
'program_name': GET_DEFAULT_CONFIG,
'parse_argv': 0,
'argv': [""],
+ '_orig_argv': [],
'xoptions': [],
'warnoptions': [],
@@ -739,7 +740,12 @@
'pycache_prefix': 'conf_pycache_prefix',
'program_name': './conf_program_name',
- 'argv': ['-c', 'arg2', ],
+ 'argv': ['-c', 'arg2'],
+ '_orig_argv': ['python3',
+ '-W', 'cmdline_warnoption',
+ '-X', 'cmdline_xoption',
+ '-c', 'pass',
+ 'arg2'],
'parse_argv': 1,
'xoptions': [
'config_xoption1=3',
@@ -872,6 +878,7 @@
}
config = {
'argv': ['script.py'],
+ '_orig_argv': ['python3', '-X', 'dev', 'script.py'],
'run_filename': os.path.abspath('script.py'),
'dev_mode': 1,
'faulthandler': 1,
@@ -886,9 +893,14 @@
preconfig = {
'isolated': 0,
}
+ argv = ["python3",
+ "-E", "-I",
+ "-X", "dev",
+ "-X", "utf8",
+ "script.py"]
config = {
- 'argv': ["python3", "-E", "-I",
- "-X", "dev", "-X", "utf8", "script.py"],
+ 'argv': argv,
+ '_orig_argv': argv,
'isolated': 0,
}
self.check_all_configs("test_preinit_dont_parse_argv", config, preconfig,
@@ -967,6 +979,9 @@
'ignore:::sysadd_warnoption',
'ignore:::config_warnoption',
],
+ '_orig_argv': ['python3',
+ '-W', 'ignore:::cmdline_warnoption',
+ '-X', 'cmdline_xoption'],
}
self.check_all_configs("test_init_sys_add", config, api=API_PYTHON)
@@ -975,6 +990,7 @@
'print(json.dumps(_testinternalcapi.get_configs()))')
config = {
'argv': ['-c', 'arg2'],
+ '_orig_argv': ['python3', '-c', code, 'arg2'],
'program_name': './python3',
'run_command': code + '\n',
'parse_argv': 1,
@@ -986,6 +1002,9 @@
'print(json.dumps(_testinternalcapi.get_configs()))')
config = {
'argv': ['-c', 'arg2'],
+ '_orig_argv': ['python3',
+ '-c', code,
+ 'arg2'],
'program_name': './python3',
'run_command': code + '\n',
'parse_argv': 1,
@@ -999,6 +1018,7 @@
config = {
'parse_argv': 1,
'argv': ['-c', 'arg1', '-v', 'arg3'],
+ '_orig_argv': ['./argv0', '-E', '-c', 'pass', 'arg1', '-v', 'arg3'],
'program_name': './argv0',
'run_command': 'pass\n',
'use_environment': 0,
@@ -1012,6 +1032,7 @@
config = {
'parse_argv': 0,
'argv': ['./argv0', '-E', '-c', 'pass', 'arg1', '-v', 'arg3'],
+ '_orig_argv': ['./argv0', '-E', '-c', 'pass', 'arg1', '-v', 'arg3'],
'program_name': './argv0',
}
self.check_all_configs("test_init_dont_parse_argv", config, pre_config,
@@ -1299,10 +1320,17 @@
'faulthandler': 1,
'bytes_warning': 1,
'warnoptions': warnoptions,
+ '_orig_argv': ['python3',
+ '-Wignore:::cmdline1',
+ '-Wignore:::cmdline2'],
}
self.check_all_configs("test_init_warnoptions", config, preconfig,
api=API_PYTHON)
+ def test_get_argc_argv(self):
+ self.run_embedded_interpreter("test_get_argc_argv")
+ # ignore output
+
class AuditingTests(EmbeddingTestsMixin, unittest.TestCase):
def test_open_code_hook(self):