From f6b3445050d7e95ff4dfbb59ba21f2b8cced735b Mon Sep 17 00:00:00 2001 From: Brendan Gerrity Date: Sun, 2 Sep 2018 23:39:00 -0700 Subject: [PATCH 1/2] bpo-34532: Fixed exit code for py.exe list versions arg Previously, any of the list version args would cause the launcher to exit with the `RC_NO_PYTHON` error code. This change causes the list version args to exit successfully. --- .../2018-09-03-01-23-52.bpo-34532.N1HEbE.rst | 1 + PC/launcher.c | 48 +++++++++---------- 2 files changed, 24 insertions(+), 25 deletions(-) create mode 100644 Misc/NEWS.d/next/Windows/2018-09-03-01-23-52.bpo-34532.N1HEbE.rst diff --git a/Misc/NEWS.d/next/Windows/2018-09-03-01-23-52.bpo-34532.N1HEbE.rst b/Misc/NEWS.d/next/Windows/2018-09-03-01-23-52.bpo-34532.N1HEbE.rst new file mode 100644 index 00000000000000..812b47497c2de9 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2018-09-03-01-23-52.bpo-34532.N1HEbE.rst @@ -0,0 +1 @@ +Fixes exit code of list version arguments for py.exe. diff --git a/PC/launcher.c b/PC/launcher.c index fcc3abb63de6c5..2d519ef4132ee7 100644 --- a/PC/launcher.c +++ b/PC/launcher.c @@ -1468,6 +1468,7 @@ process(int argc, wchar_t ** argv) size_t plen; INSTALLED_PYTHON * ip; BOOL valid; + BOOL version_call = FALSE; DWORD size, attrs; HRESULT hr; wchar_t message[MSGSIZE]; @@ -1600,14 +1601,15 @@ process(int argc, wchar_t ** argv) } else { p = argv[1]; - plen = wcslen(p); if ((argc == 2) && - (!wcsncmp(p, L"-0", wcslen(L"-0")) || /* Starts with -0 or --list */ - !wcsncmp(p, L"--list", wcslen(L"--list")))) + (!_wcsicmp(p, L"-0") || !_wcsicmp(p, L"--list") || /* Version args. */ + !_wcsicmp(p, L"-0p") || !_wcsicmp(p, L"--list-paths"))) { - valid = show_python_list(argv); /* Check for -0 or --list FIRST */ + show_python_list(argv); + version_call = TRUE; + executable = NULL; } - valid = valid && (*p == L'-') && validate_version(&p[1]); + valid = !version_call && (*p == L'-') && validate_version(&p[1]); if (valid) { ip = locate_python(&p[1], FALSE); if (ip == NULL) @@ -1638,29 +1640,25 @@ installed, use -0 for available pythons", &p[1]); if (!valid) { if ((argc == 2) && (!_wcsicmp(p, L"-h") || !_wcsicmp(p, L"--help"))) show_help_text(argv); - if ((argc == 2) && - (!_wcsicmp(p, L"-0") || !_wcsicmp(p, L"--list") || - !_wcsicmp(p, L"-0p") || !_wcsicmp(p, L"--list-paths"))) - { - executable = NULL; /* Info call only */ - } - else { - /* Look for an active virtualenv */ - executable = find_python_by_venv(); - - /* If we didn't find one, look for the default Python */ - if (executable == NULL) { - ip = locate_python(L"", FALSE); - if (ip == NULL) - error(RC_NO_PYTHON, L"Can't find a default Python."); - executable = ip->executable; - } + + /* Look for an active virtualenv */ + executable = find_python_by_venv(); + + /* If we didn't find one, look for the default Python */ + if (executable == NULL) { + ip = locate_python(L"", FALSE); + if (ip == NULL) + error(RC_NO_PYTHON, L"Can't find a default Python."); + executable = ip->executable; } } - if (executable != NULL) - invoke_child(executable, NULL, command); - else + if (executable == NULL) { rc = RC_NO_PYTHON; + } + else if (!version_call) { + invoke_child(executable, NULL, command); + } + return rc; } From 10e01f07789a54e909a92723f613a45dc674b80e Mon Sep 17 00:00:00 2001 From: Brendan Gerrity Date: Tue, 6 Nov 2018 00:16:42 -0800 Subject: [PATCH 2/2] bpo-34532: Fixed exit code for py.exe list versions arg --- PC/launcher.c | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/PC/launcher.c b/PC/launcher.c index 6e0c7bc7ed72b4..2c2da76f614675 100644 --- a/PC/launcher.c +++ b/PC/launcher.c @@ -1454,7 +1454,7 @@ show_python_list(wchar_t ** argv) fwprintf(stderr, L"\n\nCan't find a Default Python.\n\n"); else fwprintf(stderr, L"\n\n"); /* End with a blank line */ - return(FALSE); /* If this has been called we cannot continue */ + return FALSE; /* If this has been called we cannot continue */ } static int @@ -1468,7 +1468,6 @@ process(int argc, wchar_t ** argv) size_t plen; INSTALLED_PYTHON * ip; BOOL valid; - BOOL version_call = FALSE; DWORD size, attrs; HRESULT hr; wchar_t message[MSGSIZE]; @@ -1601,15 +1600,15 @@ process(int argc, wchar_t ** argv) } else { p = argv[1]; - if ((argc == 2) && - (!_wcsicmp(p, L"-0") || !_wcsicmp(p, L"--list") || /* Version args. */ - !_wcsicmp(p, L"-0p") || !_wcsicmp(p, L"--list-paths"))) + plen = wcslen(p); + if ((argc == 2) && // list version args + (!wcsncmp(p, L"-0", wcslen(L"-0")) || + !wcsncmp(p, L"--list", wcslen(L"--list")))) { show_python_list(argv); - version_call = TRUE; - executable = NULL; + return rc; } - valid = !version_call && (*p == L'-') && validate_version(&p[1]); + valid = valid && (*p == L'-') && validate_version(&p[1]); if (valid) { ip = locate_python(&p[1], FALSE); if (ip == NULL) @@ -1640,25 +1639,29 @@ installed, use -0 for available pythons", &p[1]); if (!valid) { if ((argc == 2) && (!_wcsicmp(p, L"-h") || !_wcsicmp(p, L"--help"))) show_help_text(argv); - - /* Look for an active virtualenv */ - executable = find_python_by_venv(); - - /* If we didn't find one, look for the default Python */ - if (executable == NULL) { - ip = locate_python(L"", FALSE); - if (ip == NULL) - error(RC_NO_PYTHON, L"Can't find a default Python."); - executable = ip->executable; + if ((argc == 2) && + (!_wcsicmp(p, L"-0") || !_wcsicmp(p, L"--list") || + !_wcsicmp(p, L"-0p") || !_wcsicmp(p, L"--list-paths"))) + { + executable = NULL; /* Info call only */ + } + else { + /* Look for an active virtualenv */ + executable = find_python_by_venv(); + + /* If we didn't find one, look for the default Python */ + if (executable == NULL) { + ip = locate_python(L"", FALSE); + if (ip == NULL) + error(RC_NO_PYTHON, L"Can't find a default Python."); + executable = ip->executable; + } } } - if (executable == NULL) { - rc = RC_NO_PYTHON; - } - else if (!version_call) { + if (executable != NULL) invoke_child(executable, NULL, command); - } - + else + rc = RC_NO_PYTHON; return rc; }