Skip to content

Conversation

@Koolvansh07
Copy link

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 PR adds the missing handle check to match the Windows implementation behavior, and includes a regression test.

Fixes gh-143304

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
@bedevere-app
Copy link

bedevere-app bot commented Dec 31, 2025

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 skip news label instead.

@python-cla-bot
Copy link

python-cla-bot bot commented Dec 31, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

picnixz
picnixz previously requested changes Jan 1, 2026
@bedevere-app
Copy link

bedevere-app bot commented Jan 1, 2026

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

- Remove AI-generated comments from test
- Use skipIf decorator instead of runtime check
- Simplify NEWS entry (don't mention private _dlopen)
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!

The name parameter may be modified by .fwork and AIX processing,
so we need to process it before checking the handle.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ctypes.CDLL does no longer honor the handle argument starting Python 3.13.10+ & 3.14.1+?

2 participants