Sfoglia il codice sorgente

Catch and reset KeyboardInterrupt after py_input read() call.

Sander Mathijs van Veen 14 anni fa
parent
commit
b4fd7ccf01
1 ha cambiato i file con 11 aggiunte e 1 eliminazioni
  1. 11 1
      src/c/bison_callback.c

+ 11 - 1
src/c/bison_callback.c

@@ -163,7 +163,17 @@ void py_input(PyObject *parser, char *buf, int *result, int max_size)
     Py_DECREF(handle);
     Py_DECREF(arglist);
 
-    if (unlikely(!res)) { return; }
+    if (unlikely(!res)) {
+        // Catch and reset KeyboardInterrupt exception
+        PyObject *given = PyErr_Occurred();
+        if (given && PyErr_GivenExceptionMatches(given,
+                                                 PyExc_KeyboardInterrupt)) {
+
+            PyErr_Clear();
+        }
+
+        return;
+    }
 
     // Check if the "hook_read_after" callback exists
     if (unlikely(!PyObject_HasAttr(parser, py_attr_hook_read_after_name)))