@@ -412,53 +412,12 @@ def find_library(name):
412412 _get_soname (_findLib_gcc (name )) or _get_soname (_findLib_ld (name ))
413413
414414
415- # Listing loaded libraries on other systems will try to use
416- # functions common to Linux and a few other Unix-like systems.
417- # See the following for several platforms' documentation of the same API:
418- # https://man7.org/linux/man-pages/man3/dl_iterate_phdr.3.html
419- # https://man.freebsd.org/cgi/man.cgi?query=dl_iterate_phdr
420- # https://man.openbsd.org/dl_iterate_phdr
421- # https://docs.oracle.com/cd/E88353_01/html/E37843/dl-iterate-phdr-3c.html
422- if (os .name == "posix" and
423- sys .platform not in {"darwin" , "ios" , "tvos" , "watchos" }):
424- import ctypes
425- if hasattr ((_libc := ctypes .CDLL (None )), "dl_iterate_phdr" ):
426-
427- class _dl_phdr_info (ctypes .Structure ):
428- _fields_ = [
429- ("dlpi_addr" , ctypes .c_void_p ),
430- ("dlpi_name" , ctypes .c_char_p ),
431- ("dlpi_phdr" , ctypes .c_void_p ),
432- ("dlpi_phnum" , ctypes .c_ushort ),
433- ]
434-
435- _dl_phdr_callback = ctypes .CFUNCTYPE (
436- ctypes .c_int ,
437- ctypes .POINTER (_dl_phdr_info ),
438- ctypes .c_size_t ,
439- ctypes .POINTER (ctypes .py_object ),
440- )
441-
442- @_dl_phdr_callback
443- def _info_callback (info , _size , data ):
444- libraries = data .contents .value
445- name = os .fsdecode (info .contents .dlpi_name )
446- libraries .append (name )
447- return 0
448-
449- _dl_iterate_phdr = _libc ["dl_iterate_phdr" ]
450- _dl_iterate_phdr .argtypes = [
451- _dl_phdr_callback ,
452- ctypes .POINTER (ctypes .py_object ),
453- ]
454- _dl_iterate_phdr .restype = ctypes .c_int
455-
456- def dllist ():
457- """Return a list of loaded shared libraries in the current process."""
458- libraries = []
459- _dl_iterate_phdr (_info_callback ,
460- ctypes .byref (ctypes .py_object (libraries )))
461- return libraries
415+ # On platforms which provide dl_iterate_phdr(), dllist() is implemented
416+ # in _ctypes.
417+ try :
418+ from _ctypes import dllist
419+ except ImportError :
420+ pass
462421
463422
464423@dataclass (slots = True , frozen = True )
0 commit comments