bpo-14916: use specified tokenizer fd for file input (GH-31006)

@pablogsal, sorry i failed to rebase to main, so i recreated https://github.com/python/cpython/pull/22190GH-issuecomment-1024633392

> PyRun_InteractiveOne\*() functions allow to explicitily set fd instead of stdin.
but stdin was hardcoded in readline call.

> This patch does not fix target file for prompt unlike original bpo one : prompt fd is unrelated to tokenizer source which could be read only. It is more of a bugfix regarding the docs :  actual documentation say "prompt the user" so one would expect prompt to go on stdout not a file for both PyRun_InteractiveOne\*() and PyRun_InteractiveLoop\*().

Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit 89b13042fc)

Co-authored-by: Paul m. p. P <mail.peny@free.fr>
This commit is contained in:
Miss Islington (bot) 2022-02-03 15:32:22 -08:00 committed by GitHub
parent 4f76b3667d
commit 91e8889044
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View file

@ -0,0 +1 @@
Fixed bug in the tokenizer that prevented ``PyRun_InteractiveOne`` from parsing from the provided FD.

View file

@ -854,7 +854,7 @@ tok_underflow_interactive(struct tok_state *tok) {
tok->done = E_INTERACT_STOP;
return 1;
}
char *newtok = PyOS_Readline(stdin, stdout, tok->prompt);
char *newtok = PyOS_Readline(tok->fp ? tok->fp : stdin, stdout, tok->prompt);
if (newtok != NULL) {
char *translated = translate_newlines(newtok, 0, tok);
PyMem_Free(newtok);