@@ -67,11 +67,11 @@ def find_library(name):
6767 return fname
6868 return None
6969
70- import ctypes
71- from ctypes import wintypes
72-
70+ # Listing loaded DLLs on Windows relies on the following APIs:
7371 # https://learn.microsoft.com/windows/win32/api/psapi/nf-psapi-enumprocessmodules
7472 # https://learn.microsoft.com/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamew
73+ import ctypes
74+ from ctypes import wintypes
7575
7676 _kernel32 = ctypes .WinDLL ('kernel32' , use_last_error = True )
7777 _get_current_process = _kernel32 ["GetCurrentProcess" ]
@@ -120,6 +120,7 @@ def _get_module_handles():
120120 return modules [:n ]
121121
122122 def dllist ():
123+ """Return a list of loaded shared libraries in the current process."""
123124 modules = _get_module_handles ()
124125 libraries = [name for h in modules
125126 if (name := _get_module_filename (h )) is not None ]
@@ -138,14 +139,16 @@ def find_library(name):
138139 continue
139140 return None
140141
142+ # Listing loaded libraries on Apple systems relies on the following API:
143+ # https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dyld.3.html
141144 import ctypes
142145
143- # https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dyld.3.html
144146 _libc = ctypes .CDLL (find_library ("c" ))
145147 _dyld_get_image_name = _libc ["_dyld_get_image_name" ]
146148 _dyld_get_image_name .restype = ctypes .c_char_p
147149
148150 def dllist ():
151+ """Return a list of loaded shared libraries in the current process."""
149152 num_images = _libc ._dyld_image_count ()
150153 libraries = [os .fsdecode (name ) for i in range (num_images )
151154 if (name := _dyld_get_image_name (i )) is not None ]
@@ -414,7 +417,9 @@ def find_library(name):
414417 _get_soname (_findLib_gcc (name )) or _get_soname (_findLib_ld (name ))
415418
416419
417- # other systems use functions common to Linux and a few other Unix-like systems
420+ # Listing loaded libraries on other systems will try to use
421+ # functions common to Linux and a few other Unix-like systems.
422+ # See the following for several platforms' documentation of the same API:
418423# https://man7.org/linux/man-pages/man3/dl_iterate_phdr.3.html
419424# https://man.freebsd.org/cgi/man.cgi?query=dl_iterate_phdr
420425# https://man.openbsd.org/dl_iterate_phdr
@@ -454,6 +459,7 @@ def _info_callback(info, _size, data):
454459 _dl_iterate_phdr .restype = ctypes .c_int
455460
456461 def dllist ():
462+ """Return a list of loaded shared libraries in the current process."""
457463 libraries = []
458464 _dl_iterate_phdr (_info_callback ,
459465 ctypes .byref (ctypes .py_object (libraries )))
0 commit comments