public
Last active

  • Download Gist
gistfile1.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
diff -r 22d6fe14e945 runtime/doc/if_pyth.txt
--- a/runtime/doc/if_pyth.txt Sun Jun 30 23:24:08 2013 +0200
+++ b/runtime/doc/if_pyth.txt Mon Jul 01 19:25:24 2013 +0900
@@ -740,6 +740,11 @@
3. You undefine PY_NO_RTLD_GLOBAL in auto/config.h after configuration. This
may crash Vim though.
+ *E880*
+Raising SystemExit exception in python isn't endosed way to quit vim, use: >
+ :py vim.command("qall!")
+<
+
*has-python*
You can test what Python version is available with: >
if has('python')
diff -r 22d6fe14e945 src/if_py_both.h
--- a/src/if_py_both.h Sun Jun 30 23:24:08 2013 +0200
+++ b/src/if_py_both.h Mon Jul 01 19:25:24 2013 +0900
@@ -13,6 +13,8 @@
* Common code for if_python.c and if_python3.c.
*/
+static char_u e_py_systemexit[] = "E880: Can't handle SystemExit of %s exception in vim";
+
#if PY_VERSION_HEX < 0x02050000
typedef int Py_ssize_t; /* Python 2.4 and earlier don't have this type. */
#endif
@@ -4961,7 +4963,17 @@
#endif
)
{
- PyRun_SimpleString((char *) cmd);
+ PyObject *run_ret;
+ run_ret = PyRun_String((char *) cmd, Py_file_input, globals, globals);
+ if (run_ret != NULL)
+ {
+ Py_DECREF(run_ret);
+ }
+ if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit))
+ {
+ EMSG2(_(e_py_systemexit), "python");
+ PyErr_Clear();
+ }
}
static const char *code_hdr = "def " DOPY_FUNC "(line, linenr):\n ";
@@ -4979,6 +4991,7 @@
char *code;
int status;
PyObject *pyfunc, *pymain;
+ PyObject *run_ret;
if (u_save((linenr_T)RangeStart - 1, (linenr_T)RangeEnd + 1) != OK)
{
@@ -4990,9 +5003,23 @@
code = PyMem_New(char, len + 1);
memcpy(code, code_hdr, code_hdr_len);
STRCPY(code + code_hdr_len, cmd);
- status = PyRun_SimpleString(code);
+ run_ret = PyRun_String(code, Py_file_input, globals, globals);
+ status = -1;
+ if (run_ret != NULL)
+ {
+ status = 0;
+ Py_DECREF(run_ret);
+ }
+
PyMem_Free(code);
+ if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit))
+ {
+ EMSG2(_(e_py_systemexit), "python");
+ PyErr_Clear();
+ return;
+ }
+
if (status)
{
EMSG(_("failed to run the code"));
@@ -5071,6 +5098,11 @@
run_ret = PyRun_String((char *) cmd, Py_eval_input, globals, globals);
if (run_ret == NULL)
{
+ if (PyErr_ExceptionMatches(PyExc_SystemExit))
+ {
+ EMSG2(_(e_py_systemexit), "python");
+ PyErr_Clear();
+ }
if (PyErr_Occurred() && !msg_silent)
PyErr_PrintEx(0);
EMSG(_("E858: Eval did not return a valid python object"));
diff -r 22d6fe14e945 src/if_python.c
--- a/src/if_python.c Sun Jun 30 23:24:08 2013 +0200
+++ b/src/if_python.c Mon Jul 01 19:25:24 2013 +0900
@@ -444,6 +444,7 @@
static PyObject *imp_PyExc_KeyboardInterrupt;
static PyObject *imp_PyExc_TypeError;
static PyObject *imp_PyExc_ValueError;
+static PyObject *imp_PyExc_SystemExit;
static PyObject *imp_PyExc_RuntimeError;
static PyObject *imp_PyExc_ImportError;
static PyObject *imp_PyExc_OverflowError;
@@ -454,6 +455,7 @@
# define PyExc_KeyboardInterrupt imp_PyExc_KeyboardInterrupt
# define PyExc_TypeError imp_PyExc_TypeError
# define PyExc_ValueError imp_PyExc_ValueError
+# define PyExc_SystemExit imp_PyExc_SystemExit
# define PyExc_RuntimeError imp_PyExc_RuntimeError
# define PyExc_ImportError imp_PyExc_ImportError
# define PyExc_OverflowError imp_PyExc_OverflowError
@@ -731,6 +733,7 @@
imp_PyExc_KeyboardInterrupt = PyDict_GetItemString(exdict, "KeyboardInterrupt");
imp_PyExc_TypeError = PyDict_GetItemString(exdict, "TypeError");
imp_PyExc_ValueError = PyDict_GetItemString(exdict, "ValueError");
+ imp_PyExc_SystemExit = PyDict_GetItemString(exdict, "SystemExit");
imp_PyExc_RuntimeError = PyDict_GetItemString(exdict, "RuntimeError");
imp_PyExc_ImportError = PyDict_GetItemString(exdict, "ImportError");
imp_PyExc_OverflowError = PyDict_GetItemString(exdict, "OverflowError");
@@ -740,6 +743,7 @@
Py_XINCREF(imp_PyExc_KeyboardInterrupt);
Py_XINCREF(imp_PyExc_TypeError);
Py_XINCREF(imp_PyExc_ValueError);
+ Py_XINCREF(imp_PyExc_SystemExit);
Py_XINCREF(imp_PyExc_RuntimeError);
Py_XINCREF(imp_PyExc_ImportError);
Py_XINCREF(imp_PyExc_OverflowError);
diff -r 22d6fe14e945 src/if_python3.c
--- a/src/if_python3.c Sun Jun 30 23:24:08 2013 +0200
+++ b/src/if_python3.c Mon Jul 01 19:25:24 2013 +0900
@@ -403,6 +403,7 @@
static PyObject *p3imp_PyExc_KeyboardInterrupt;
static PyObject *p3imp_PyExc_TypeError;
static PyObject *p3imp_PyExc_ValueError;
+static PyObject *p3imp_PyExc_SystemExit;
static PyObject *p3imp_PyExc_RuntimeError;
static PyObject *p3imp_PyExc_ImportError;
static PyObject *p3imp_PyExc_OverflowError;
@@ -413,6 +414,7 @@
# define PyExc_KeyboardInterrupt p3imp_PyExc_KeyboardInterrupt
# define PyExc_TypeError p3imp_PyExc_TypeError
# define PyExc_ValueError p3imp_PyExc_ValueError
+# define PyExc_SystemExit p3imp_PyExc_SystemExit
# define PyExc_RuntimeError p3imp_PyExc_RuntimeError
# define PyExc_ImportError p3imp_PyExc_ImportError
# define PyExc_OverflowError p3imp_PyExc_OverflowError
@@ -681,6 +683,7 @@
p3imp_PyExc_KeyboardInterrupt = PyDict_GetItemString(exdict, "KeyboardInterrupt");
p3imp_PyExc_TypeError = PyDict_GetItemString(exdict, "TypeError");
p3imp_PyExc_ValueError = PyDict_GetItemString(exdict, "ValueError");
+ p3imp_PyExc_SystemExit = PyDict_GetItemString(exdict, "SystemExit");
p3imp_PyExc_RuntimeError = PyDict_GetItemString(exdict, "RuntimeError");
p3imp_PyExc_ImportError = PyDict_GetItemString(exdict, "ImportError");
p3imp_PyExc_OverflowError = PyDict_GetItemString(exdict, "OverflowError");
@@ -690,6 +693,7 @@
Py_XINCREF(p3imp_PyExc_KeyboardInterrupt);
Py_XINCREF(p3imp_PyExc_TypeError);
Py_XINCREF(p3imp_PyExc_ValueError);
+ Py_XINCREF(p3imp_PyExc_SystemExit);
Py_XINCREF(p3imp_PyExc_RuntimeError);
Py_XINCREF(p3imp_PyExc_ImportError);
Py_XINCREF(p3imp_PyExc_OverflowError);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.