FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GH-103929: handle long input lines with PyOS_InputHook by tacaswell · Pull Request #103931 · python/cpython · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 2 additions & 0 deletions Doc/c-api/veryhigh.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ the same library that the Python runtime is using.
event loops, as done in :file:`Modules/_tkinter.c` in the
Python source code.

This function should block until stdin is readable.

.. versionchanged:: 3.12
This function is only called from the
:ref:`main interpreter <sub-interpreter-support>`.
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix repeated calls to :c:var:`PyOS_InputHook` for long input lines.
13 changes: 7 additions & 6 deletions Parser/myreadline.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ my_fgets(PyThreadState* tstate, char *buf, int len, FILE *fp)
#endif

while (1) {
if (PyOS_InputHook != NULL &&
// GH-104668: See PyOS_ReadlineFunctionPointer's comment below...
_Py_IsMainInterpreter(tstate->interp))
{
(void)(PyOS_InputHook)();
}

errno = 0;
clearerr(fp);
Expand Down Expand Up @@ -318,6 +312,13 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
fprintf(stderr, "%s", prompt);
}
fflush(stderr);
// Keep this outside my_fgets(): long lines call my_fgets() repeatedly.
if (PyOS_InputHook != NULL &&
// GH-104668: See PyOS_ReadlineFunctionPointer's comment below...
_Py_IsMainInterpreter(tstate->interp))
{
(void)(PyOS_InputHook)();
}

n = 0;
p = NULL;
Expand Down
Loading

Back | FazBrowse Home | New Git URL