D7444: setup: conditionalize access to `sys.dllhandle` when building extensions
mharbison72 (Matt Harbison)
phabricator at mercurial-scm.org
Sat Nov 16 14:24:39 EST 2019
Closed by commit rHG10875cf85f22: setup: conditionalize access to `sys.dllhandle` when building extensions (authored by mharbison72).
This revision was automatically updated to reflect the committed changes.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D7444?vs=18179&id=18188
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D7444/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D7444
AFFECTED FILES
setup.py
CHANGE DETAILS
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -713,30 +713,34 @@
self.compiler.compiler_so = self.compiler.compiler # no -mdll
self.compiler.dll_libraries = [] # no -lmsrvc90
- # Different Python installs can have different Python library
- # names. e.g. the official CPython distribution uses pythonXY.dll
- # and MinGW uses libpythonX.Y.dll.
- _kernel32 = ctypes.windll.kernel32
- _kernel32.GetModuleFileNameA.argtypes = [
- ctypes.c_void_p,
- ctypes.c_void_p,
- ctypes.c_ulong,
- ]
- _kernel32.GetModuleFileNameA.restype = ctypes.c_ulong
- size = 1000
- buf = ctypes.create_string_buffer(size + 1)
- filelen = _kernel32.GetModuleFileNameA(
- sys.dllhandle, ctypes.byref(buf), size
- )
+ pythonlib = None
- if filelen > 0 and filelen != size:
- dllbasename = os.path.basename(buf.value)
- if not dllbasename.lower().endswith(b'.dll'):
- raise SystemExit(
- 'Python DLL does not end with .dll: %s' % dllbasename
- )
- pythonlib = dllbasename[:-4]
- else:
+ if getattr(sys, 'dllhandle', None):
+ # Different Python installs can have different Python library
+ # names. e.g. the official CPython distribution uses pythonXY.dll
+ # and MinGW uses libpythonX.Y.dll.
+ _kernel32 = ctypes.windll.kernel32
+ _kernel32.GetModuleFileNameA.argtypes = [
+ ctypes.c_void_p,
+ ctypes.c_void_p,
+ ctypes.c_ulong,
+ ]
+ _kernel32.GetModuleFileNameA.restype = ctypes.c_ulong
+ size = 1000
+ buf = ctypes.create_string_buffer(size + 1)
+ filelen = _kernel32.GetModuleFileNameA(
+ sys.dllhandle, ctypes.byref(buf), size
+ )
+
+ if filelen > 0 and filelen != size:
+ dllbasename = os.path.basename(buf.value)
+ if not dllbasename.lower().endswith(b'.dll'):
+ raise SystemExit(
+ 'Python DLL does not end with .dll: %s' % dllbasename
+ )
+ pythonlib = dllbasename[:-4]
+
+ if not pythonlib:
log.warn(
'could not determine Python DLL filename; assuming pythonXY'
)
To: mharbison72, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel
More information about the Mercurial-devel
mailing list