Skip to content

ctypes.util.find_library() returns None in non-UTF-8 locales #154551

Description

@serhiy-storchaka

Bug report

$ LC_ALL=uk_UA.koi8u python3 -c 'import ctypes.util; print(ctypes.util.find_library("c"))'
None

(it returns the library in a UTF-8 or C locale.)

_findLib_ld() runs ld with universal_newlines=True, so communicate() decodes its output in the locale encoding and fails on a localized diagnostic on stderr. The exception is swallowed, so find_library() returns None. The stderr is discarded and the stdout is already decoded with os.fsdecode(), so the output should be read as bytes.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixestopic-ctypestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions