Skip to content

Py_fopen and Py_fclose not exported from python3.dll on Windows #152805

Closed

Description

@sonVishal

Bug report

Bug description:

The functions Py_fopen and Py_fclose introduced in PR#127821 are not visible on Windows.

Compiler: Microsoft (R) C/C++ Optimizing Compiler Version 19.42.34436 for x64
Windows SDK Version: 10.0.26100.0

Tested on: CPython 3.14.6

Command used for compilation: PCbuild\build.bat -p x64 -r -t Rebuild -e

I am not sure if these two APIs should be part of the stable ABI but we need them for the same reason mentioned in Issue#127350. We are upgrading to Python 3.14 from 3.12 and since _Py_wfopen is no longer exposed we are trying to replace it with Py_fopen and Py_fclose.

We load python3.dll via LoadLibrary Win32 API and then search for Py_fopen and Py_fclose via GetProcAddress Win32 API. These two symbols (Py_fopen and Py_fclose) cannot be found.

dumpbin /exports PCbuild\amd64\python3.dll | findstr Py_fopen returns empty after building.

Potential solution:
Should add the following to stable_abi.toml?

[function.Py_fopen]
    added = '3.14'
[function.Py_fclose]
    added = '3.14'

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Activity

  1. added
    type-bug
    on Jul 1, 2026
  2. Shrey-N commented on Jul 2, 2026

    @Shrey-N
    Contributor

    Hi @sonVishal,

    I believe this behavior is actually by design.

    python3.dll represents the Limited API / Stable ABI, which strictly excludes functions using standard FILE* objects. This is because FILE* depends on the specific C Runtime (CRT) version, and exposing it would break cross compiler binary compatibility. Therefore, Py_fopen and Py_fclose cannot be added to stable_abi.toml.

    (Note: _Py_wfopen and PyRun_FileExFlags were never part of the Stable ABI or exported by python3.dll either.)

    Solution:-
    To use Py_fopen and Py_fclose (or PyRun_FileExFlags), you must explicitly load the version specific DLL (e.g., python314.dll), which correctly exports them.

  3. sonVishal commented on Jul 2, 2026

    @sonVishal
    Author
  4. sergey-miryanov commented on Jul 8, 2026

    @sergey-miryanov
    Contributor

    @sonVishal Should we close this?

  5. sonVishal commented on Jul 8, 2026

    @sonVishal
    Author
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

    OS-windowstopic-C-APItype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions