bpo-45445: Revert "bpo-45445: Fail if an invalid X-option is provided in the command line (GH-28823)" (GH-94745)

(cherry picked from commit aa37ffda29)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-07-31 08:58:02 -07:00 committed by GitHub
parent db13c0c1b8
commit 147a9a8be7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 83 deletions

View file

@ -2046,49 +2046,6 @@ _PyConfig_InitImportConfig(PyConfig *config)
return config_init_import(config, 1);
}
// List of known xoptions to validate against the provided ones. Note that all
// options are listed, even if they are only available if a specific macro is
// set, like -X showrefcount which requires a debug build. In this case unknown
// options are silently ignored.
const wchar_t* known_xoptions[] = {
L"faulthandler",
L"showrefcount",
L"tracemalloc",
L"importtime",
L"dev",
L"utf8",
L"pycache_prefix",
L"warn_default_encoding",
L"no_debug_ranges",
L"frozen_modules",
NULL,
};
static const wchar_t*
_Py_check_xoptions(const PyWideStringList *xoptions, const wchar_t **names)
{
for (Py_ssize_t i=0; i < xoptions->length; i++) {
const wchar_t *option = xoptions->items[i];
size_t len;
wchar_t *sep = wcschr(option, L'=');
if (sep != NULL) {
len = (sep - option);
}
else {
len = wcslen(option);
}
int found = 0;
for (const wchar_t** name = names; *name != NULL; name++) {
if (wcsncmp(option, *name, len) == 0 && (*name)[len] == L'\0') {
found = 1;
}
}
if (found == 0) {
return option;
}
}
return NULL;
}
static PyStatus
config_read(PyConfig *config, int compute_path_config)
@ -2104,11 +2061,6 @@ config_read(PyConfig *config, int compute_path_config)
}
/* -X options */
const wchar_t* option = _Py_check_xoptions(&config->xoptions, known_xoptions);
if (option != NULL) {
return PyStatus_Error("Unknown value for option -X (see --help-xoptions)");
}
if (config_get_xoption(config, L"showrefcount")) {
config->show_ref_count = 1;
}