8000 gh-95359: Fix py.exe launcher handling of per-user py.ini and command… · python/cpython@38bb206 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 38bb206

Browse files
authored
gh-95359: Fix py.exe launcher handling of per-user py.ini and command names (GH-95399)
1 parent a1daf6e commit 38bb206

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

Lib/test/test_launcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
TEST_PY_COMMANDS = "\n".join([
7171
"[defaults]",
72-
*[f"{k.lower()}={v}" for k, v in TEST_PY_ENV.items()]
72+
*[f"{k[3:].lower()}={v}" for k, v in TEST_PY_ENV.items()]
7373
])
7474

7575

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix :ref:`launcher` handling of :file:`py.ini` commands (it was incorrectly
2+
expecting a ``py_`` prefix on keys) and crashes when reading per-user
3+
configuration file.

PC/launcher2.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ _readIni(const wchar_t *section, const wchar_t *settingName, wchar_t *buffer, in
761761
n = GetPrivateProfileStringW(section, settingName, NULL, buffer, bufferLength, iniPath);
762762
if (n) {
763763
debug(L"# Found %s in %s\n", settingName, iniPath);
764-
return true;
764+
return n;
765765
} else if (GetLastError() == ERROR_FILE_NOT_FOUND) {
766766
debug(L"# Did not find file %s\n", iniPath);
767767
} else {
@@ -946,25 +946,29 @@ checkDefaults(SearchInfo *search)
946946

947947
// If tag is only a major version number, expand it from the environment
948948
// or an ini file
949-
const wchar_t *settingName = NULL;
949+
const wchar_t *iniSettingName = NULL;
950+
const wchar_t *envSettingName = NULL;
950951
if (!search->tag || !search->tagLength) {
951-
settingName = L"py_python";
952+
iniSettingName = L"python";
953+
envSettingName = L"py_python";
952954
} else if (0 == wcsncmp(search->tag, L"3", search->tagLength)) {
953-
settingName = L"py_python3";
955+
iniSettingName = L"python3";
956+
envSettingName = L"py_python3";
954957
} else if (0 == wcsncmp(search->tag, L"2", search->tagLength)) {
955-
settingName = L"py_python2";
958+
iniSettingName = L"python2";
959+
envSettingName = L"py_python2";
956960
} else {
957961
debug(L"# Cannot select defaults for tag '%.*s'\n", search->tagLength, search->tag);
958962
return 0;
959963
}
960964

961965
// First, try to read an environment variable
962966
wchar_t buffer[MAXLEN];
963-
int n = GetEnvironmentVariableW(settingName, buffer, MAXLEN);
967+
int n = GetEnvironmentVariableW(envSettingName, buffer, MAXLEN);
964968

965969
// If none found, check in our two .ini files instead
966970
if (!n) {
967-
n = _readIni(L"defaults", settingName, buffer, MAXLEN);
971+
n = _readIni(L"defaults", iniSettingName, buffer, MAXLEN);
968972
}
969973

970974
if (n) {

0 commit comments

Comments
 (0)
0