Skip to content

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

Description

@leofang

Bug report

Bug description:

By inspecting the source code, I noticed that in the 3.12 branch handle is still used:

if handle is None:
self._handle = _dlopen(self._name, mode)
else:
self._handle = handle

but starting 3.13 & Unix-like systems it is not:
def _load_library(self, name, mode, handle, winmode):
# If the filename that has been provided is an iOS/tvOS/watchOS
# .fwork file, dereference the location to the true origin of the
# binary.
if name and name.endswith(".fwork"):
with open(name) as f:
name = _os.path.join(
_os.path.dirname(_sys.executable),
f.read().strip()
)
if _sys.platform.startswith("aix"):
"""When the name contains ".a(" and ends with ")",
e.g., "libFOO.a(libFOO.so)" - this is taken to be an
archive(member) syntax for dlopen(), and the mode is adjusted.
Otherwise, name is presented to dlopen() as a file argument.
"""
if name and name.endswith(")") and ".a(" in name:
mode |= _os.RTLD_MEMBER | _os.RTLD_NOW
self._name = name
return _dlopen(name, mode)

where handle is passed to CDLL._load_library() but is not used at all. Instead, _dlopen() is always called to populate self._handle.

A quick check shows that this starts fairly recently, Python 3.13.10+ & 3.14.1+. It seems to me like a refactoring bug introduced in #136878, #138546, #138547 IIUC.

CPython versions tested on:

3.13

Operating systems tested on:

No response

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-ctypestype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions