Also added tests:

# HG changeset patch
# User ZyX <[email protected]>
# Date 1382108836 -14400
#      Fri Oct 18 19:07:16 2013 +0400
# Branch fix-py-vim-interrupt
# Node ID ce2b5adf52ff9b9ac37749e795d357d8b0a96f47
# Parent  92c9748e0ccbc42a5e28ce8fb9b8818e756a06da
Fix interrupt not being properly discarded in VimTryEnd

diff -r 92c9748e0ccb -r ce2b5adf52ff src/if_py_both.h
--- a/src/if_py_both.h  Sun Oct 06 17:46:56 2013 +0200
+++ b/src/if_py_both.h  Fri Oct 18 19:07:16 2013 +0400
@@ -558,7 +558,11 @@
     /* Keyboard interrupt should be preferred over anything else */
     if (got_int)
     {
-       did_throw = got_int = FALSE;
+       if (current_exception != NULL)
+           discard_current_exception();
+       else
+           need_rethrow = did_throw = FALSE;
+       got_int = FALSE;
        PyErr_SetNone(PyExc_KeyboardInterrupt);
        return -1;
     }
@@ -567,7 +571,10 @@
     /* Python exception is preferred over vim one; unlikely to occur though */
     else if (PyErr_Occurred())
     {
-       did_throw = FALSE;
+       if (current_exception != NULL)
+           discard_current_exception();
+       else
+           need_rethrow = did_throw = FALSE;
        return -1;
     }
     /* Finally transform VimL exception to python one */
# HG changeset patch
# User ZyX <[email protected]>
# Date 1382196954 -14400
#      Sat Oct 19 19:35:54 2013 +0400
# Branch fix-py-vim-interrupt
# Node ID 376d94dc5c21418e8f00143914b587be3f3c4dca
# Parent  ce2b5adf52ff9b9ac37749e795d357d8b0a96f47
Add tests for the fix

diff -r ce2b5adf52ff -r 376d94dc5c21 src/testdir/test86.in
--- a/src/testdir/test86.in     Fri Oct 18 19:07:16 2013 +0400
+++ b/src/testdir/test86.in     Sat Oct 19 19:35:54 2013 +0400
@@ -1278,6 +1278,37 @@
 EOF
 :delfunction Exe
 :"
+:" Regression: interrupting vim.command propagates to next vim.command
+py << EOF
+def test_keyboard_interrupt():
+    try:
+        vim.command('while 1 | endwhile')
+    except KeyboardInterrupt:
+        cb.append('Caught KeyboardInterrupt')
+    except Exception:
+        cb.append('!!!!!!!! Caught exception: ' + repr(sys.exc_info))
+    else:
+        cb.append('!!!!!!!! No exception')
+    try:
+        vim.command('$ put =\'Running :put\'')
+    except KeyboardInterrupt:
+        cb.append('!!!!!!!! Caught KeyboardInterrupt')
+    except Exception:
+        cb.append('!!!!!!!! Caught exception: ' + repr(sys.exc_info))
+    else:
+        cb.append('No exception')
+EOF
+:debuggreedy
+:call inputsave()
+:call feedkeys("s\ns\ns\ns\nq\n")
+:redir => output
+:debug silent! py test_keyboard_interrupt()
+:redir END
+:0 debuggreedy
+:silent $put =output
+:unlet output
+:py del test_keyboard_interrupt
+:"
 :" Cleanup
 py << EOF
 del cb
diff -r ce2b5adf52ff -r 376d94dc5c21 src/testdir/test86.ok
--- a/src/testdir/test86.ok     Fri Oct 18 19:07:16 2013 +0400
+++ b/src/testdir/test86.ok     Sat Oct 19 19:35:54 2013 +0400
@@ -1195,3 +1195,7 @@
 vim.eval("Exe('echoerr ''jkl''')"):error:('Vim(echoerr):jkl',)
 vim.eval("Exe('xxx_non_existent_command_xxx')"):error:('Vim:E492: Not an 
editor command: xxx_non_existent_command_xxx',)
 vim.bindeval("Exe('xxx_non_existent_command_xxx')"):error:('Vim:E492: Not an 
editor command: xxx_non_existent_command_xxx',)
+Caught KeyboardInterrupt
+Running :put
+No exception
+
diff -r ce2b5adf52ff -r 376d94dc5c21 src/testdir/test87.in
--- a/src/testdir/test87.in     Fri Oct 18 19:07:16 2013 +0400
+++ b/src/testdir/test87.in     Sat Oct 19 19:35:54 2013 +0400
@@ -1229,6 +1229,37 @@
 EOF
 :delfunction Exe
 :"
+:" Regression: interrupting vim.command propagates to next vim.command
+py3 << EOF
+def test_keyboard_interrupt():
+    try:
+        vim.command('while 1 | endwhile')
+    except KeyboardInterrupt:
+        cb.append('Caught KeyboardInterrupt')
+    except Exception as e:
+        cb.append('!!!!!!!! Caught exception: ' + repr(e))
+    else:
+        cb.append('!!!!!!!! No exception')
+    try:
+        vim.command('$ put =\'Running :put\'')
+    except KeyboardInterrupt:
+        cb.append('!!!!!!!! Caught KeyboardInterrupt')
+    except Exception as e:
+        cb.append('!!!!!!!! Caught exception: ' + repr(e))
+    else:
+        cb.append('No exception')
+EOF
+:debuggreedy
+:call inputsave()
+:call feedkeys("s\ns\ns\ns\nq\n")
+:redir => output
+:debug silent! py3 test_keyboard_interrupt()
+:redir END
+:0 debuggreedy
+:silent $put =output
+:unlet output
+:py3 del test_keyboard_interrupt
+:"
 :" Cleanup
 py3 << EOF
 del cb
diff -r ce2b5adf52ff -r 376d94dc5c21 src/testdir/test87.ok
--- a/src/testdir/test87.ok     Fri Oct 18 19:07:16 2013 +0400
+++ b/src/testdir/test87.ok     Sat Oct 19 19:35:54 2013 +0400
@@ -1184,3 +1184,7 @@
 vim.eval("Exe('echoerr ''jkl''')"):(<class 'vim.error'>, 
error('Vim(echoerr):jkl',))
 vim.eval("Exe('xxx_non_existent_command_xxx')"):(<class 'vim.error'>, 
error('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',))
 vim.bindeval("Exe('xxx_non_existent_command_xxx')"):(<class 'vim.error'>, 
error('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',))
+Caught KeyboardInterrupt
+Running :put
+No exception
+

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
diff -crN vim-small-patches.92c9748e0ccb/src/if_py_both.h vim-small-patches.376d94dc5c21/src/if_py_both.h
*** vim-small-patches.92c9748e0ccb/src/if_py_both.h	2013-10-19 19:37:59.063126606 +0400
--- vim-small-patches.376d94dc5c21/src/if_py_both.h	2013-10-19 19:37:59.073126504 +0400
***************
*** 558,564 ****
      /* Keyboard interrupt should be preferred over anything else */
      if (got_int)
      {
! 	did_throw = got_int = FALSE;
  	PyErr_SetNone(PyExc_KeyboardInterrupt);
  	return -1;
      }
--- 558,568 ----
      /* Keyboard interrupt should be preferred over anything else */
      if (got_int)
      {
! 	if (current_exception != NULL)
! 	    discard_current_exception();
! 	else
! 	    need_rethrow = did_throw = FALSE;
! 	got_int = FALSE;
  	PyErr_SetNone(PyExc_KeyboardInterrupt);
  	return -1;
      }
***************
*** 567,573 ****
      /* Python exception is preferred over vim one; unlikely to occur though */
      else if (PyErr_Occurred())
      {
! 	did_throw = FALSE;
  	return -1;
      }
      /* Finally transform VimL exception to python one */
--- 571,580 ----
      /* Python exception is preferred over vim one; unlikely to occur though */
      else if (PyErr_Occurred())
      {
! 	if (current_exception != NULL)
! 	    discard_current_exception();
! 	else
! 	    need_rethrow = did_throw = FALSE;
  	return -1;
      }
      /* Finally transform VimL exception to python one */
diff -crN vim-small-patches.92c9748e0ccb/src/testdir/test86.in vim-small-patches.376d94dc5c21/src/testdir/test86.in
*** vim-small-patches.92c9748e0ccb/src/testdir/test86.in	2013-10-19 19:37:59.065126583 +0400
--- vim-small-patches.376d94dc5c21/src/testdir/test86.in	2013-10-19 19:37:59.074126494 +0400
***************
*** 1278,1283 ****
--- 1278,1314 ----
  EOF
  :delfunction Exe
  :"
+ :" Regression: interrupting vim.command propagates to next vim.command
+ py << EOF
+ def test_keyboard_interrupt():
+     try:
+         vim.command('while 1 | endwhile')
+     except KeyboardInterrupt:
+         cb.append('Caught KeyboardInterrupt')
+     except Exception:
+         cb.append('!!!!!!!! Caught exception: ' + repr(sys.exc_info))
+     else:
+         cb.append('!!!!!!!! No exception')
+     try:
+         vim.command('$ put =\'Running :put\'')
+     except KeyboardInterrupt:
+         cb.append('!!!!!!!! Caught KeyboardInterrupt')
+     except Exception:
+         cb.append('!!!!!!!! Caught exception: ' + repr(sys.exc_info))
+     else:
+         cb.append('No exception')
+ EOF
+ :debuggreedy
+ :call inputsave()
+ :call feedkeys("s\ns\ns\ns\nq\n")
+ :redir => output
+ :debug silent! py test_keyboard_interrupt()
+ :redir END
+ :0 debuggreedy
+ :silent $put =output
+ :unlet output
+ :py del test_keyboard_interrupt
+ :"
  :" Cleanup
  py << EOF
  del cb
diff -crN vim-small-patches.92c9748e0ccb/src/testdir/test86.ok vim-small-patches.376d94dc5c21/src/testdir/test86.ok
*** vim-small-patches.92c9748e0ccb/src/testdir/test86.ok	2013-10-19 19:37:59.058126655 +0400
--- vim-small-patches.376d94dc5c21/src/testdir/test86.ok	2013-10-19 19:37:59.067126565 +0400
***************
*** 1195,1197 ****
--- 1195,1201 ----
  vim.eval("Exe('echoerr ''jkl''')"):error:('Vim(echoerr):jkl',)
  vim.eval("Exe('xxx_non_existent_command_xxx')"):error:('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',)
  vim.bindeval("Exe('xxx_non_existent_command_xxx')"):error:('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',)
+ Caught KeyboardInterrupt
+ Running :put
+ No exception
+ 
diff -crN vim-small-patches.92c9748e0ccb/src/testdir/test87.in vim-small-patches.376d94dc5c21/src/testdir/test87.in
*** vim-small-patches.92c9748e0ccb/src/testdir/test87.in	2013-10-19 19:37:59.059126645 +0400
--- vim-small-patches.376d94dc5c21/src/testdir/test87.in	2013-10-19 19:37:59.069126545 +0400
***************
*** 1229,1234 ****
--- 1229,1265 ----
  EOF
  :delfunction Exe
  :"
+ :" Regression: interrupting vim.command propagates to next vim.command
+ py3 << EOF
+ def test_keyboard_interrupt():
+     try:
+         vim.command('while 1 | endwhile')
+     except KeyboardInterrupt:
+         cb.append('Caught KeyboardInterrupt')
+     except Exception as e:
+         cb.append('!!!!!!!! Caught exception: ' + repr(e))
+     else:
+         cb.append('!!!!!!!! No exception')
+     try:
+         vim.command('$ put =\'Running :put\'')
+     except KeyboardInterrupt:
+         cb.append('!!!!!!!! Caught KeyboardInterrupt')
+     except Exception as e:
+         cb.append('!!!!!!!! Caught exception: ' + repr(e))
+     else:
+         cb.append('No exception')
+ EOF
+ :debuggreedy
+ :call inputsave()
+ :call feedkeys("s\ns\ns\ns\nq\n")
+ :redir => output
+ :debug silent! py3 test_keyboard_interrupt()
+ :redir END
+ :0 debuggreedy
+ :silent $put =output
+ :unlet output
+ :py3 del test_keyboard_interrupt
+ :"
  :" Cleanup
  py3 << EOF
  del cb
diff -crN vim-small-patches.92c9748e0ccb/src/testdir/test87.ok vim-small-patches.376d94dc5c21/src/testdir/test87.ok
*** vim-small-patches.92c9748e0ccb/src/testdir/test87.ok	2013-10-19 19:37:59.061126626 +0400
--- vim-small-patches.376d94dc5c21/src/testdir/test87.ok	2013-10-19 19:37:59.070126534 +0400
***************
*** 1184,1186 ****
--- 1184,1190 ----
  vim.eval("Exe('echoerr ''jkl''')"):(<class 'vim.error'>, error('Vim(echoerr):jkl',))
  vim.eval("Exe('xxx_non_existent_command_xxx')"):(<class 'vim.error'>, error('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',))
  vim.bindeval("Exe('xxx_non_existent_command_xxx')"):(<class 'vim.error'>, error('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',))
+ Caught KeyboardInterrupt
+ Running :put
+ No exception
+ 

Raspunde prin e-mail lui