From ea68d83933e6de6cabfb115ec1b8888301947369 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 1 Aug 2018 03:07:18 +0200 Subject: [PATCH] bpo-34170: _PyCoreConfig_Read() defaults to argc=0 (GH-8595) Add unit tests for argc and argv of _PyCoreConfig. --- Lib/test/test_embed.py | 2 ++ Modules/main.c | 3 +++ Programs/_testembed.c | 12 +++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 79622f15945..25593bdf420 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -272,6 +272,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): 'pycache_prefix': '(null)', 'program_name': './_testembed', + 'argc': 0, + 'argv': '[]', 'program': '(null)', 'isolated': 0, diff --git a/Modules/main.c b/Modules/main.c index aef821fe93c..664a70ad5eb 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -2294,6 +2294,9 @@ _PyCoreConfig_Read(_PyCoreConfig *config) if (config->_frozen < 0) { config->_frozen = 0; } + if (config->argc < 0) { + config->argc = 0; + } return _Py_INIT_OK(); } diff --git a/Programs/_testembed.c b/Programs/_testembed.c index 1cdc4c3648f..1c72580b9c6 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -335,7 +335,17 @@ dump_config(void) printf("pycache_prefix = %ls\n", config->pycache_prefix); printf("program_name = %ls\n", config->program_name); ASSERT_STR_EQUAL(config->program_name, Py_GetProgramName()); - /* FIXME: test argc/argv */ + + printf("argc = %i\n", config->argc); + printf("argv = ["); + for (int i=0; i < config->argc; i++) { + if (i) { + printf(", "); + } + printf("\"%ls\"", config->argv[i]); + } + printf("]\n"); + printf("program = %ls\n", config->program); /* FIXME: test xoptions */ /* FIXME: test warnoptions */