Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea68d83

Browse files
authored
bpo-34170: _PyCoreConfig_Read() defaults to argc=0 (GH-8595)
Add unit tests for argc and argv of _PyCoreConfig.
1 parent 9851227 commit ea68d83

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

Lib/test/test_embed.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
272272

273273
'pycache_prefix': '(null)',
274274
'program_name': './_testembed',
275+
'argc': 0,
276+
'argv': '[]',
275277
'program': '(null)',
276278

277279
'isolated': 0,

Modules/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,6 +2294,9 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
22942294
if (config->_frozen < 0) {
22952295
config->_frozen = 0;
22962296
}
2297+
if (config->argc < 0) {
2298+
config->argc = 0;
2299+
}
22972300

22982301
return _Py_INIT_OK();
22992302
}

Programs/_testembed.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,17 @@ dump_config(void)
335335
printf("pycache_prefix = %ls\n", config->pycache_prefix);
336336
printf("program_name = %ls\n", config->program_name);
337337
ASSERT_STR_EQUAL(config->program_name, Py_GetProgramName());
338-
/* FIXME: test argc/argv */
338+
339+
printf("argc = %i\n", config->argc);
340+
printf("argv = [");
341+
for (int i=0; i < config->argc; i++) {
342+
if (i) {
343+
printf(", ");
344+
}
345+
printf("\"%ls\"", config->argv[i]);
346+
}
347+
printf("]\n");
348+
339349
printf("program = %ls\n", config->program);
340350
/* FIXME: test xoptions */
341351
/* FIXME: test warnoptions */

0 commit comments

Comments
 (0)