[Python-checkins] python/dist/src/Parser myreadline.c,2.26,2.27
mhammond@users.sourceforge.net
mhammond@users.sourceforge.net
Sun, 14 Jul 2002 16:12:31 -0700
Update of /cvsroot/python/python/dist/src/Parser
In directory usw-pr-cvs1:/tmp/cvs-serv1634
Modified Files:
myreadline.c
Log Message:
Fix bug 439992 - [win32] KeyboardInterrupt Not Caught.
This gets us closer to consistent Ctrl+C behaviour on NT and Win9x. NT now reliably generates KeyboardInterrupt exceptions for NT when a file IO operation was aborted. Bugfix candidate
Index: myreadline.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Parser/myreadline.c,v
retrieving revision 2.26
retrieving revision 2.27
diff -C2 -d -r2.26 -r2.27
*** myreadline.c 2 Mar 2001 06:29:51 -0000 2.26
--- myreadline.c 14 Jul 2002 23:12:29 -0000 2.27
***************
*** 11,14 ****
--- 11,18 ----
#include "Python.h"
+ #ifdef MS_WINDOWS
+ #define WIN32_LEAN_AND_MEAN
+ #include "windows.h"
+ #endif /* MS_WINDOWS */
int (*PyOS_InputHook)(void) = NULL;
***************
*** 32,35 ****
--- 36,68 ----
if (p != NULL)
return 0; /* No error */
+ #ifdef MS_WINDOWS
+ /* In the case of a Ctrl+C or some other external event
+ interrupting the operation:
+ Win2k/NT: ERROR_OPERATION_ABORTED is the most recent Win32
+ error code (and feof() returns TRUE).
+ Win9x: Ctrl+C seems to have no effect on fgets() returning
+ early - the signal handler is called, but the fgets()
+ only returns "normally" (ie, when Enter hit or feof())
+ */
+ if (GetLastError()==ERROR_OPERATION_ABORTED) {
+ /* Signals come asynchronously, so we sleep a brief
+ moment before checking if the handler has been
+ triggered (we cant just return 1 before the
+ signal handler has been called, as the later
+ signal may be treated as a separate interrupt).
+ */
+ Sleep(1);
+ if (PyOS_InterruptOccurred()) {
+ return 1; /* Interrupt */
+ }
+ /* Either the sleep wasn't long enough (need a
+ short loop retrying?) or not interrupted at all
+ (in which case we should revisit the whole thing!)
+ Logging some warning would be nice. assert is not
+ viable as under the debugger, the various dialogs
+ mean the condition is not true.
+ */
+ }
+ #endif /* MS_WINDOWS */
if (feof(fp)) {
return -1; /* EOF */