Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'coerce_c_locale_warn': 0,

'program_name': './_testembed',
'argv': [],
'argv': [''],
'program': None,

'xoptions': [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ensure that :data:`sys.argv` always exists and is non-empty. When Python is
embedded in an application and ``argv`` is not set, use ``['']``.
15 changes: 11 additions & 4 deletions Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2373,6 +2373,17 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
}
}

/* ensure that sys.argv is always set and non-empty */
if (config->argc < 0) {
config->argc = 0;
}
if (config->argc == 0) {
err = wstrlist_append(&config->argc, &config->argv, L"");
if (_Py_INIT_FAILED(err)) {
return err;
}
}

/* default values */
if (config->dev_mode) {
if (config->faulthandler < 0) {
Expand Down Expand Up @@ -2401,10 +2412,6 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
if (config->utf8_mode < 0) {
config->utf8_mode = 0;
}
if (config->argc < 0) {
config->argc = 0;
}

return _Py_INIT_OK();
}

Expand Down