[Python-checkins] bpo-34170: _PyCoreConfig_Read() defaults to argc=0 (GH-8595)

Victor Stinner webhook-mailer at python.org
Tue Jul 31 21:07:21 EDT 2018


https://github.com/python/cpython/commit/ea68d83933e6de6cabfb115ec1b8888301947369
commit: ea68d83933e6de6cabfb115ec1b8888301947369
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018-08-01T03:07:18+02:00
summary:

bpo-34170: _PyCoreConfig_Read() defaults to argc=0 (GH-8595)

Add unit tests for argc and argv of _PyCoreConfig.

files:
M Lib/test/test_embed.py
M Modules/main.c
M Programs/_testembed.c

diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index 79622f15945f..25593bdf4208 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 aef821fe93c3..664a70ad5ebb 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 1cdc4c3648f9..1c72580b9c67 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 */



More information about the Python-checkins mailing list