Skip to content

Commit

Permalink
Fix error handling when calling kernel32 functions
Browse files Browse the repository at this point in the history
  • Loading branch information
adang1345 committed Dec 18, 2023
1 parent 5376f0f commit 7583e8f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions delvewheel/_dll_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def null_translator(directory: str, arch: MachineType) -> str:
return null_translator

# determine architecture of interpreter and OS
kernel32 = ctypes.windll.kernel32
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
interpreter_arch = get_interpreter_arch()
if not interpreter_arch:
# file system redirection rules are unknown
Expand All @@ -160,7 +160,7 @@ def null_translator(directory: str, arch: MachineType) -> str:
process_machine = ctypes.c_ushort()
native_machine = ctypes.c_ushort()
if not kernel32.IsWow64Process2(ctypes.c_void_p(kernel32.GetCurrentProcess()), ctypes.byref(process_machine), ctypes.byref(native_machine)):
raise OSError(f'Unable to determine whether WOW64 is active, Error={ctypes.FormatError()}')
raise OSError(f'Unable to determine whether WOW64 is active, Error={ctypes.FormatError(ctypes.get_last_error())}')
if not process_machine.value:
os_arch = interpreter_arch
else:
Expand All @@ -170,7 +170,7 @@ def null_translator(directory: str, arch: MachineType) -> str:
elif hasattr(kernel32, 'IsWow64Process'):
wow64_process = ctypes.c_int()
if not kernel32.IsWow64Process(ctypes.c_void_p(kernel32.GetCurrentProcess()), ctypes.byref(wow64_process)):
raise OSError(f'Unable to determine whether WOW64 is active, Error={ctypes.FormatError()}')
raise OSError(f'Unable to determine whether WOW64 is active, Error={ctypes.FormatError(ctypes.get_last_error())}')
os_arch = MachineType.AMD64 if wow64_process.value else interpreter_arch
else:
os_arch = MachineType.I386
Expand Down
5 changes: 3 additions & 2 deletions delvewheel/_wheel_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ def _delvewheel_patch_{1}():
load_order = file.read().split()
for lib in load_order:
lib_path = os.path.join(os.path.join(libs_dir, lib))
if os.path.isfile(lib_path) and not ctypes.windll.kernel32.LoadLibraryExW(ctypes.c_wchar_p(lib_path), None, 0x00000008):
raise OSError('Error loading {{}}; {{}}'.format(lib, ctypes.FormatError()))
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
if os.path.isfile(lib_path) and not kernel32.LoadLibraryExW(ctypes.c_wchar_p(lib_path), None, 0x00000008):
raise OSError('Error loading {{}}; {{}}'.format(lib, ctypes.FormatError(ctypes.get_last_error())))
_delvewheel_patch_{1}()
Expand Down

0 comments on commit 7583e8f

Please sign in to comment.