gh-143304: Fix ctypes.CDLL to honor handle parameter on POSIX systems#143318
gh-143304: Fix ctypes.CDLL to honor handle parameter on POSIX systems#143318encukou merged 7 commits intopython:mainfrom
Conversation
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. This commit adds the missing handle check to match the Windows implementation behavior, and includes a regression test. Fixes pythongh-143304
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Misc/NEWS.d/next/Library/2026-01-01-05-26-00.gh-issue-143304.Kv7x9Q.rst
Outdated
Show resolved
Hide resolved
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
- Remove AI-generated comments from test - Use skipIf decorator instead of runtime check - Simplify NEWS entry (don't mention private _dlopen)
Lib/test/test_ctypes/test_loading.py
Outdated
| lib1 = CDLL(libc_name) | ||
| handle = lib1._handle | ||
| lib2 = CDLL(name=None, handle=handle) | ||
| self.assertIs(handle, lib2._handle) |
There was a problem hiding this comment.
| 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).
There was a problem hiding this comment.
I checked the 3.12 branch source code:
Lib/ctypes/__init__.pyin 3.12 DID support thehandleparameter (it checkedif handle is None:).-
Lib/test/test_ctypes/test_loading.pyin 3.12 DID NOT have any test usingCDLL(..., handle=...)on POSIX.
The name parameter may be modified by .fwork and AIX processing, so we need to process it before checking the handle.
sharktide
left a comment
There was a problem hiding this comment.
LGTM
Thanks for your contribution @Koolvansh07
your welcome |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
I thought it was Windows-only parameter, but it is documented on Posix too.
LGTM. 👍
|
🤖 New build scheduled with the buildbot fleet by @encukou for commit cdb8f6e 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F143318%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
|
Thanks @Koolvansh07 for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
…ystems (pythonGH-143318) 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 27ded243485670fa836c9bb421e37a6ef16eca8e) Co-authored-by: Arjit Singh Grover <143692910+Koolvansh07@users.noreply.github.com>
…ystems (pythonGH-143318) 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 27ded24) Co-authored-by: Arjit Singh Grover <143692910+Koolvansh07@users.noreply.github.com>
|
GH-145172 is a backport of this pull request to the 3.14 branch. |
|
GH-145173 is a backport of this pull request to the 3.13 branch. |
The
handleparameter was being ignored in the POSIX implementation ofCDLL._load_library(), causing it to always call_dlopen()even when a valid handle was provided. This was a regression introduced in recent refactoring.This PR adds the missing handle check to match the Windows implementation behavior, and includes a regression test.
Fixes gh-143304