Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/ctypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ def _load_library(self, name, mode, handle, winmode):

else:
def _load_library(self, name, mode, handle, winmode):
if handle is not None:
self._name = name
return handle
# If the filename that has been provided is an iOS/tvOS/watchOS
# .fwork file, dereference the location to the true origin of the
# binary.
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_ctypes/test_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ def test_load_without_name_and_with_handle(self):
lib = ctypes.WinDLL(name=None, handle=handle)
self.assertIs(handle, lib._handle)

@unittest.skipIf(os.name == "nt", 'POSIX-specific test')
@unittest.skipIf(libc_name is None, 'could not find libc')
def test_load_without_name_and_with_handle_posix(self):
lib1 = CDLL(libc_name)
handle = lib1._handle
lib2 = CDLL(name=None, handle=handle)
self.assertIs(handle, lib2._handle)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.assertIs(handle, lib2._handle)
self.assertIs(lib2._handle, handle)

Can you check whether there were tests for Python 3.12 where we had this handle? or if the tests were rewritten as well (see the PRs mentioned on the issue).

Copy link
Author

Choose a reason for hiding this comment

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

I checked the 3.12 branch source code:

  1. Lib/ctypes/__init__.py in 3.12 DID support the handle parameter (it checked if handle is None:).
    1. Lib/test/test_ctypes/test_loading.py in 3.12 DID NOT have any test using CDLL(..., handle=...) on POSIX.

Copy link
Member

Choose a reason for hiding this comment

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

Ok thx!


@unittest.skipUnless(os.name == "nt", 'Windows-specific test')
def test_1703286_A(self):
# On winXP 64-bit, advapi32 loads at an address that does
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :class:`ctypes.CDLL` to honor the ``handle`` parameter on POSIX systems.
Loading