mirror of
https://github.com/python/cpython.git
synced 2024-11-28 04:15:11 +08:00
bpo-46297: Fix interpreter crash on startup with multiple PythonPaths set in registry (GH-30466)
This commit is contained in:
parent
74d1663580
commit
c9dc1f491e
@ -734,12 +734,15 @@ class MockWinreg:
|
||||
return n.removeprefix(prefix)
|
||||
raise OSError("end of enumeration")
|
||||
|
||||
def QueryValue(self, hkey):
|
||||
def QueryValue(self, hkey, subkey):
|
||||
if verbose:
|
||||
print(f"QueryValue({hkey})")
|
||||
print(f"QueryValue({hkey}, {subkey})")
|
||||
hkey = hkey.casefold()
|
||||
if hkey not in self.open:
|
||||
raise RuntimeError("key is not open")
|
||||
if subkey:
|
||||
subkey = subkey.casefold()
|
||||
hkey = f'{hkey}\\{subkey}'
|
||||
try:
|
||||
return self.keys[hkey]
|
||||
except KeyError:
|
||||
|
@ -400,6 +400,7 @@ Lars Damerow
|
||||
Evan Dandrea
|
||||
Eric Daniel
|
||||
Scott David Daniels
|
||||
Derzsi Dániel
|
||||
Lawrence D'Anna
|
||||
Ben Darnell
|
||||
Kushal Das
|
||||
|
@ -0,0 +1,2 @@
|
||||
Fixed an interpreter crash on bootup with multiple PythonPaths set in
|
||||
the Windows registry. Patch by Derzsi Dániel.
|
@ -127,7 +127,7 @@
|
||||
# checked by looking for the BUILDDIR_TXT file, which contains the
|
||||
# relative path to the platlib dir. The executable_dir value is
|
||||
# derived from joining the VPATH preprocessor variable to the
|
||||
# directory containing pybuilddir.txt. If it is not found, the
|
||||
# directory containing pybuilddir.txt. If it is not found, the
|
||||
# BUILD_LANDMARK file is found, which is part of the source tree.
|
||||
# prefix is then found by searching up for a file that should only
|
||||
# exist in the source tree, and the stdlib dir is set to prefix/Lib.
|
||||
@ -642,19 +642,12 @@ elif not pythonpath:
|
||||
i = 0
|
||||
while True:
|
||||
try:
|
||||
keyname = winreg.EnumKey(key, i)
|
||||
subkey = winreg.OpenKeyEx(key, keyname)
|
||||
if not subkey:
|
||||
continue
|
||||
try:
|
||||
v = winreg.QueryValue(subkey)
|
||||
finally:
|
||||
winreg.CloseKey(subkey)
|
||||
if isinstance(v, str):
|
||||
pythonpath.append(v)
|
||||
i += 1
|
||||
v = winreg.QueryValue(key, winreg.EnumKey(key, i))
|
||||
except OSError:
|
||||
break
|
||||
if isinstance(v, str):
|
||||
pythonpath.append(v)
|
||||
i += 1
|
||||
finally:
|
||||
winreg.CloseKey(key)
|
||||
except OSError:
|
||||
|
Loading…
Reference in New Issue
Block a user