Index: Include/pythonrun.h =================================================================== RCS file: /cvsroot/python/python/dist/src/Include/pythonrun.h,v retrieving revision 2.54 diff -p -u -r2.54 pythonrun.h --- Include/pythonrun.h 12 Aug 2002 13:06:35 -0000 2.54 +++ Include/pythonrun.h 11 Oct 2002 07:19:35 -0000 @@ -115,7 +115,7 @@ PyAPI_FUNC(void) PyOS_FiniInterrupts(voi /* Stuff with no proper home (yet) */ PyAPI_FUNC(char *) PyOS_Readline(char *); PyAPI_DATA(int) (*PyOS_InputHook)(void); -PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(char *); +PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *); /* Stack size, in "pointers" (so we get extra safety margins on 64-bit platforms). On a 32-bit platform, this translates Index: Modules/readline.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/readline.c,v retrieving revision 2.53 diff -p -u -r2.53 readline.c --- Modules/readline.c 9 Oct 2002 21:27:33 -0000 2.53 +++ Modules/readline.c 11 Oct 2002 07:19:36 -0000 @@ -32,7 +32,7 @@ /* Pointers needed from outside (but not declared in a header file). */ extern DL_IMPORT(int) (*PyOS_InputHook)(void); -extern DL_IMPORT(char) *(*PyOS_ReadlineFunctionPointer)(char *); +extern DL_IMPORT(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *,char *); /* Exported function to send one line to readline's init file parser */ @@ -606,12 +606,12 @@ onintr(int sig) /* Wrapper around GNU readline that handles signals differently. */ static char * -call_readline(char *prompt) +call_readline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) { size_t n; char *p, *q; PyOS_sighandler_t old_inthandler; - + old_inthandler = PyOS_setsig(SIGINT, onintr); if (setjmp(jbuf)) { #ifdef HAVE_SIGRELSE @@ -622,6 +622,13 @@ call_readline(char *prompt) return NULL; } rl_event_hook = PyOS_InputHook; + + if (sys_stdin != rl_instream || sys_stdout != rl_outstream) { + rl_instream = sys_stdin; + rl_outstream = sys_stdout; + rl_prep_terminal (1); + } + p = readline(prompt); PyOS_setsig(SIGINT, old_inthandler); @@ -676,8 +683,7 @@ initreadline(void) m = Py_InitModule4("readline", readline_methods, doc_module, (PyObject *)NULL, PYTHON_API_VERSION); - if (isatty(fileno(stdin))) { - PyOS_ReadlineFunctionPointer = call_readline; - setup_readline(); - } + + PyOS_ReadlineFunctionPointer = call_readline; + setup_readline(); } Index: Parser/myreadline.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Parser/myreadline.c,v retrieving revision 2.27 diff -p -u -r2.27 myreadline.c --- Parser/myreadline.c 14 Jul 2002 23:12:29 -0000 2.27 +++ Parser/myreadline.c 11 Oct 2002 07:19:36 -0000 @@ -87,14 +87,14 @@ my_fgets(char *buf, int len, FILE *fp) /* Readline implementation using fgets() */ char * -PyOS_StdioReadline(char *prompt) +PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, char *prompt) { size_t n; char *p; n = 100; if ((p = PyMem_MALLOC(n)) == NULL) return NULL; - fflush(stdout); + fflush(sys_stdout); #ifndef RISCOS if (prompt) fprintf(stderr, "%s", prompt); @@ -107,7 +107,7 @@ PyOS_StdioReadline(char *prompt) } #endif fflush(stderr); - switch (my_fgets(p, (int)n, stdin)) { + switch (my_fgets(p, (int)n, sys_stdin)) { case 0: /* Normal case */ break; case 1: /* Interrupt */ @@ -135,7 +135,7 @@ PyOS_StdioReadline(char *prompt) if (incr > INT_MAX) { PyErr_SetString(PyExc_OverflowError, "input line too long"); } - if (my_fgets(p+n, (int)incr, stdin) != 0) + if (my_fgets(p+n, (int)incr, sys_stdin) != 0) break; n += strlen(p+n); } @@ -148,7 +148,7 @@ PyOS_StdioReadline(char *prompt) Note: Python expects in return a buffer allocated with PyMem_Malloc. */ -char *(*PyOS_ReadlineFunctionPointer)(char *); +char *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *); /* Interface used by tokenizer.c and bltinmodule.c */ @@ -156,12 +156,19 @@ char *(*PyOS_ReadlineFunctionPointer)(ch char * PyOS_Readline(char *prompt) { + FILE *sys_stdin; + FILE *sys_stdout; char *rv; + if (PyOS_ReadlineFunctionPointer == NULL) { - PyOS_ReadlineFunctionPointer = PyOS_StdioReadline; + PyOS_ReadlineFunctionPointer = PyOS_StdioReadline; } + + sys_stdin = PyFile_AsFile (PySys_GetObject ("stdin")); + sys_stdout = PyFile_AsFile (PySys_GetObject ("stdout")); + Py_BEGIN_ALLOW_THREADS - rv = (*PyOS_ReadlineFunctionPointer)(prompt); + rv = (*PyOS_ReadlineFunctionPointer)(sys_stdin, sys_stdout, prompt); Py_END_ALLOW_THREADS return rv; } Index: Python/bltinmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v retrieving revision 2.265 diff -p -u -r2.265 bltinmodule.c --- Python/bltinmodule.c 27 Aug 2002 16:58:00 -0000 2.265 +++ Python/bltinmodule.c 11 Oct 2002 07:19:36 -0000 @@ -1311,8 +1311,8 @@ builtin_raw_input(PyObject *self, PyObje if (PyFile_WriteString(" ", fout) != 0) return NULL; } - if (PyFile_AsFile(fin) == stdin && PyFile_AsFile(fout) == stdout && - isatty(fileno(stdin)) && isatty(fileno(stdout))) { + if (isatty(fileno(PyFile_AsFile(fin))) + && isatty(fileno(PyFile_AsFile(fout)))) { PyObject *po; char *prompt; char *s;