Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Loading library on Aarch64 fails because pylink attempts to load 32-bit library #182

Merged
merged 6 commits into from
Jul 12, 2024
18 changes: 18 additions & 0 deletions pylink/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ def get_appropriate_windows_sdk_name(cls):
else:
return Library.WINDOWS_32_JLINK_SDK_NAME

@classmethod
def can_load_library(cls, dllpath):
"""Test whether a library is the correct architecture to load.

Args:
dllpath: A path to a library.

Returns:
True if the library could be successfully loaded, False if not.
"""
try:
ctypes.CDLL(dllpath)
return True
except:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific error we could catch here instead of a raw except?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try catching OSError, that's what we get in this scenario

return False

@classmethod
def find_library_windows(cls):
"""Loads the SEGGER DLL from the windows installation directory.
Expand Down Expand Up @@ -202,6 +218,8 @@ def find_library_linux(cls):

for fname in fnames:
fpath = os.path.join(directory_name, fname)
if not cls.can_load_library(fpath):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this check actually occur after the OS check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, should only be checked on 64 bit OSes. Changed

continue
if util.is_os_64bit():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not cls.can_load_library(fpath):
continue
if util.is_os_64bit():
if not cls.can_load_library(fpath):
continue
elif util.is_os_64bit():

if '_x86' not in fname:
yield fpath
Expand Down