mirror of
https://github.com/python/cpython.git
synced 2026-04-14 07:41:00 +00:00
[3.14] gh-143304: Fix ctypes.CDLL to honor handle parameter on POSIX systems (GH-143318) (GH-145172)
The handle parameter was being ignored in the POSIX implementation
of CDLL._load_library(), causing it to always call _dlopen() even
when a valid handle was provided. This was a regression introduced
in recent refactoring.
(cherry picked from commit 27ded24348)
Co-authored-by: Arjit Singh Grover <143692910+Koolvansh07@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
parent
7b3e6bde26
commit
c5542c905f
3 changed files with 11 additions and 0 deletions
|
|
@ -470,6 +470,8 @@ def _load_library(self, name, mode, handle, winmode):
|
|||
if name and name.endswith(")") and ".a(" in name:
|
||||
mode |= _os.RTLD_MEMBER | _os.RTLD_NOW
|
||||
self._name = name
|
||||
if handle is not None:
|
||||
return handle
|
||||
return _dlopen(name, mode)
|
||||
|
||||
def __repr__(self):
|
||||
|
|
|
|||
|
|
@ -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(lib2._handle, handle)
|
||||
|
||||
@unittest.skipUnless(os.name == "nt", 'Windows-specific test')
|
||||
def test_1703286_A(self):
|
||||
# On winXP 64-bit, advapi32 loads at an address that does
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
Fix :class:`ctypes.CDLL` to honor the ``handle`` parameter on POSIX systems.
|
||||
Loading…
Add table
Add a link
Reference in a new issue