From 32596ce0d8e5d03f5efc1438789c7eaf37a68603 Mon Sep 17 00:00:00 2001 From: Aryan Date: Sun, 21 Jun 2026 13:05:56 -0400 Subject: [PATCH] fix(pathfinder): remove dead/misleading error handling in platform loaders Two dead error-handling paths in the dynamic-lib platform loaders: - load_dl_linux.load_with_system_search guarded abs_path with 'if abs_path is None: raise RuntimeError("No expected symbol ...")'. abs_path_for_dynamic_library never returns None (it returns a resolved path or raises OSError), so the branch is unreachable and its message is factually wrong (it concerns dlinfo path resolution, not symbols). Drop the dead branch and let the descriptive OSError surface, matching the deterministic-loader policy of not masking discovery/load failures. - load_dl_windows.add_dll_directory had 'if not result: pass', a no-op; the PATH update below already runs unconditionally. Remove the dead branch and clarify the comment on why PATH is updated regardless. No behavior change: both removed branches were unreachable or no-ops. Signed-off-by: Aryan --- .../cuda/pathfinder/_dynamic_libs/load_dl_linux.py | 8 +++++--- .../cuda/pathfinder/_dynamic_libs/load_dl_windows.py | 9 ++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py index 4bce75d109c..8dbb72a8502 100644 --- a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py +++ b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py @@ -165,7 +165,8 @@ def load_with_system_search(desc: LibDescriptor) -> LoadedDL | None: A LoadedDL object if successful, None if the library cannot be loaded Raises: - RuntimeError: If the library is loaded but no expected symbol is found + OSError: If the library is loaded but its absolute path cannot be + resolved via dlinfo (surfaced from abs_path_for_dynamic_library). """ for soname in _candidate_sonames(desc): try: @@ -173,9 +174,10 @@ def load_with_system_search(desc: LibDescriptor) -> LoadedDL | None: except OSError: pass else: + # abs_path_for_dynamic_library never returns None: it returns a + # resolved path or raises OSError. Let that error surface rather + # than masking it, consistent with the deterministic-loader policy. abs_path = abs_path_for_dynamic_library(desc.name, handle) - if abs_path is None: - raise RuntimeError(f"No expected symbol for libname={desc.name!r}") return LoadedDL(abs_path, False, handle._handle, "system-search") return None diff --git a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py index a296813aa29..5069a624790 100644 --- a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py +++ b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py @@ -69,11 +69,10 @@ def add_dll_directory(dll_abs_path: str) -> None: dirpath = os.path.dirname(dll_abs_path) assert os.path.isdir(dirpath), dll_abs_path - # Add the DLL directory to the search path - result = kernel32.AddDllDirectory(dirpath) - if not result: - # Fallback: just update PATH if AddDllDirectory fails - pass + # Add the DLL directory to the native search path. AddDllDirectory only + # affects the LOAD_LIBRARY_SEARCH_USER_DIRS search; PATH is updated + # unconditionally below to also cover legacy dependent-DLL resolution. + kernel32.AddDllDirectory(dirpath) # Update PATH as a fallback for dependent DLL resolution curr_path = os.environ.get("PATH")