classification
Title: Remove PyOS_ReadlineFunctionPointer from the stable ABI list
Type: Stage: resolved
Components: C API, Windows Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: paul.moore, petr.viktorin, steve.dower, tim.golden, vstinner, zach.ware
Priority: normal Keywords: patch

Created on 2021-04-16 14:48 by petr.viktorin, last changed 2021-04-27 14:17 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25442 merged petr.viktorin, 2021-04-16 15:00
Messages (3)
msg391206 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2021-04-16 14:48
The inclusion of PyOS_ReadlineFunctionPointer in python3dll.c (*) was a mistake. According to PEP 384:

> functions expecting FILE* are not part of the ABI, to avoid depending on a specific version of the Microsoft C runtime DLL on Windows.

The situation may have changed and it might be reasonable to revisit this decision, but that would call for a larger discussion. There are FILE*-taking functions that are probably much ore useful than this one. (But, I think it's a good idea to limit the stable ABI to file-like Python objects anyway.)

I see PEP 384 as being definitive (where it's not ambiguous). The python3dll.c list and public/private headers do not actually define the stable ABI.

So, I'd like to remove the function from the list.


---

(*) it was actually PC/python3.def in 3.2
msg391237 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-04-16 17:28
Yes, please remove it from the limited C API.

PyOS_ReadlineFunctionPointer has a bad API. I fixed recently PyOS_StdioReadline because it used the Python C API without holding the GIL. To acquire the GIL, you need to access a *private* _PyOS_ReadlineTState variable which is kind of unfortunate :-(

commit c353764fd564e401cf47a5d9efab18c72c60014e
Author: Victor Stinner <vstinner@python.org>
Date:   Mon Jun 1 20:59:35 2020 +0200

    bpo-40826: Fix GIL usage in PyOS_Readline() (GH-20579)
    
    Fix GIL usage in PyOS_Readline(): lock the GIL to set an exception.
    
    Pass tstate to my_fgets() and _PyOS_WindowsConsoleReadline(). Cleanup
    these functions.

See also:

commit fa7ab6aa0f9a4f695e5525db5a113cd21fa93787
Author: Victor Stinner <vstinner@python.org>
Date:   Wed Jun 3 14:39:59 2020 +0200

    bpo-40826: Add _PyOS_InterruptOccurred(tstate) function (GH-20599)
    
    my_fgets() now calls _PyOS_InterruptOccurred(tstate) to check for
    pending signals, rather calling PyOS_InterruptOccurred().
    
    my_fgets() is called with the GIL released, whereas
    PyOS_InterruptOccurred() must be called with the GIL held.
    
    test_repl: use text=True and avoid SuppressCrashReport in
    test_multiline_string_parsing().
    
    Fix my_fgets() on Windows: fgets(fp) does crash if fileno(fp) is closed.
msg391690 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2021-04-23 12:23
New changeset 91b69b77cf5f78de6d35dea23098df34b6fd9e53 by Petr Viktorin in branch 'master':
bpo-43868: Remove PyOS_ReadlineFunctionPointer from the stable ABI list (GH-25442)
https://github.com/python/cpython/commit/91b69b77cf5f78de6d35dea23098df34b6fd9e53
History
Date User Action Args
2021-04-27 14:17:45vstinnersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-04-23 12:23:41petr.viktorinsetmessages: + msg391690
2021-04-16 17:28:05vstinnersetnosy: + vstinner
messages: + msg391237
2021-04-16 15:00:25petr.viktorinsetkeywords: + patch
stage: patch review
pull_requests: + pull_request24172
2021-04-16 14:48:28petr.viktorincreate