Skip to content

ctypes.util.test() calls cdll.load, which LibraryLoader does not have #157763

Description

@tony-CloseAI

Bug report

ctypes.util.test() calls cdll.load(...), which LibraryLoader does not have, so the self-test raises on Windows.

Where: Lib/ctypes/util.py, test() (line 535 on main), the Windows branch:

if os.name == "nt":
    print(cdll.msvcrt)
    print(cdll.load("msvcrt"))

LibraryLoader defines LoadLibrary, not load, and its __getattr__ turns the unknown name into an AttributeError.

Reproduce (Windows, 3.13.5; the line is the same on main, whose util.py already needs 3.15 syntax to import):

> python -c "import ctypes.util; ctypes.util.test()"
<CDLL 'msvcrt', handle 7ffd0a0b0000 at 0x...>
AttributeError: load

Proposed fix:

-        print(cdll.load("msvcrt"))
+        print(cdll.LoadLibrary("msvcrt"))

Checked by running test() on Windows against 3.13.5's util.py: the current code raises AttributeError: load; the fixed code completes and prints the loaded CDLL.

Environment: Windows 11, CPython 3.13.5.


Found while auditing installed code with a verification tool I am building; the reproduction above was run on the version named, and the proposed fix was applied to a local copy and run as well. Report drafted with AI assistance.

Linked PRs

Activity

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

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytopic-ctypes

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions