Skip to content

Commit eeb1b92

Browse files
committed
Configure Windows at import time to use the 32-bit kerbeors on a
32-bit Python interpreter.
1 parent dfbf05a commit eeb1b92

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

gssapi/_win_config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import os
1010
import shutil
11+
import sys
1112
import ctypes
1213

1314
#: Path to normal KfW installed bin folder
@@ -17,12 +18,16 @@
1718
)
1819
#: Download location for KfW
1920
KFW_DL = "https://web.mit.edu/KERBEROS/dist"
21+
is64bits = sys.maxsize > 2**32
2022

2123

2224
def kfw_available():
2325
"""Return if the main GSSAPI DLL for KfW can be loaded"""
2426
try: # to load the main GSSAPI DLL
25-
ctypes.WinDLL('gssapi64.dll')
27+
if is64bits is True:
28+
ctypes.WinDLL('gssapi64.dll')
29+
else:
30+
ctypes.WinDLL('gssapi32.dll')
2631
except OSError: # DLL is not in PATH
2732
return False
2833
else: # DLL is in PATH, everything should work

setup.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ def get_output(*args, **kwargs):
3939
# get the compile and link args
4040
kc = "krb5-config"
4141
posix = os.name != 'nt'
42+
43+
# According to the Python documentation, in order to get the '64-bitness' of
44+
# the current interpreter, it is more reliable to query the sys.maxsize
45+
# attribute:
46+
#
47+
# Reference:
48+
# https://docs.python.org/3/library/platform.html#platform.architecture
49+
is64bits = sys.maxsize > 2**32
4250
link_args, compile_args = [
4351
shlex.split(os.environ[e], posix=posix) if e in os.environ else None
4452
for e in ['GSSAPI_LINKER_ARGS', 'GSSAPI_COMPILER_ARGS']
@@ -114,8 +122,9 @@ def get_output(*args, **kwargs):
114122
elif winkrb_path:
115123
compile_args = [
116124
'-I%s' % os.path.join(winkrb_path, 'include'),
117-
'-DMS_WIN64'
118125
]
126+
if is64bits:
127+
compile_args.push('-DMS_WIN64')
119128
elif os.environ.get('MINGW_PREFIX'):
120129
compile_args = ['-fPIC']
121130
else:

0 commit comments

Comments
 (0)