Skip to content

Commit cd89f39

Browse files
committed
revert: fix(library): alternative implementation that cleans up using a finalizer
This reverts commit 73c43ae.
1 parent 73c43ae commit cd89f39

File tree

3 files changed

+1
-32
lines changed

3 files changed

+1
-32
lines changed

cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,11 @@ def _load_libdl() -> ctypes.CDLL:
3838
LIBDL.dlerror.argtypes = []
3939
LIBDL.dlerror.restype = ctypes.c_char_p
4040

41-
LIBDL.dlclose.argtypes = [ctypes.c_void_p]
42-
LIBDL.dlclose.restype = ctypes.c_int
43-
4441
# First appeared in 2004-era glibc. Universally correct on Linux for all practical purposes.
4542
RTLD_DI_LINKMAP = 2
4643
RTLD_DI_ORIGIN = 6
4744

4845

49-
def unload_dl(handle: ctypes.c_void_p) -> None:
50-
result = LIBDL.dlclose(handle)
51-
if result:
52-
raise RuntimeError(LIBDL.dlerror())
53-
54-
5546
class _LinkMapLNameView(ctypes.Structure):
5647
"""
5748
Prefix-only view of glibc's `struct link_map` used **solely** to read `l_name`.

cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@
4646
kernel32.AddDllDirectory.argtypes = [ctypes.wintypes.LPCWSTR]
4747
kernel32.AddDllDirectory.restype = ctypes.c_void_p # DLL_DIRECTORY_COOKIE
4848

49-
kernel32.FreeLibrary.argtypes = [ctypes.wintypes.HMODULE]
50-
kernel32.FreeLibrary.restype = ctypes.c_bool
51-
5249

5350
def ctypes_handle_to_unsigned_int(handle: ctypes.wintypes.HMODULE) -> int:
5451
"""Convert ctypes HMODULE to unsigned int."""
@@ -160,9 +157,3 @@ def load_with_abs_path(libname: str, found_path: str) -> LoadedDL:
160157
raise RuntimeError(f"Failed to load DLL at {found_path}: Windows error {error_code}")
161158

162159
return LoadedDL(found_path, False, ctypes_handle_to_unsigned_int(handle))
163-
164-
165-
def unload_dl(handle: ctypes.c_void_p) -> None:
166-
result = kernel32.FreeLibrary(handle)
167-
if not result:
168-
raise RuntimeError(f"Failed to load windows DLL with error code: {ctypes.GetLastError()}")

cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
import ctypes
54
import functools
65
import struct
76
import sys
8-
import weakref
97

108
from cuda.pathfinder._dynamic_libs.find_nvidia_dynamic_lib import _FindNvidiaDynamicLib
119
from cuda.pathfinder._dynamic_libs.load_dl_common import LoadedDL, load_dependencies
@@ -16,14 +14,12 @@
1614
check_if_already_loaded_from_elsewhere,
1715
load_with_abs_path,
1816
load_with_system_search,
19-
unload_dl,
2017
)
2118
else:
2219
from cuda.pathfinder._dynamic_libs.load_dl_linux import (
2320
check_if_already_loaded_from_elsewhere,
2421
load_with_abs_path,
2522
load_with_system_search,
26-
unload_dl,
2723
)
2824

2925

@@ -121,13 +117,4 @@ def load_nvidia_dynamic_lib(libname: str) -> LoadedDL:
121117
f" Currently running: {pointer_size_bits}-bit Python"
122118
f" {sys.version_info.major}.{sys.version_info.minor}"
123119
)
124-
125-
library = _load_lib_no_cache(libname)
126-
127-
# Ensure that the library is unloaded after GC runs on `library`
128-
#
129-
# We only need the address, so the rest of whatever is in `library` is free
130-
# to be cleaned up. The integer address is immutable, so it gets copied
131-
# upon being referenced here
132-
weakref.finalize(library, unload_dl, ctypes.c_void_p(library._handle_uint))
133-
return library
120+
return _load_lib_no_cache(libname)

0 commit comments

Comments
 (0)