]> granicus.if.org Git - vim/commitdiff
patch 8.0.0265: may get ml_get error when :pydo deletes lines v8.0.0265
authorBram Moolenaar <Bram@vim.org>
Sun, 29 Jan 2017 20:31:09 +0000 (21:31 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 29 Jan 2017 20:31:09 +0000 (21:31 +0100)
Problem:    May get ml_get error when :pydo deletes lines or switches to
            another buffer. (Nikolai Pavlov, issue #1421)
Solution:   Check the buffer and line every time.

src/Makefile
src/if_py_both.h
src/testdir/Make_all.mak
src/testdir/test_python2.vim [new file with mode: 0644]
src/testdir/test_python3.vim [new file with mode: 0644]
src/version.c

index 6844443e9a56187a9d04033b88b46a6f4469b99a..76170ec36bf2e37ca03e8c408bf26b92653384b1 100644 (file)
@@ -2168,6 +2168,8 @@ test_arglist \
        test_popup \
        test_profile \
        test_put \
+       test_python2 \
+       test_python3 \
        test_pyx2 \
        test_pyx3 \
        test_quickfix \
index c44fc93acbd024b3d6c37af272f57737abc51c68..4cd373402cd948d51cf36873873a71ae33e437ba 100644 (file)
@@ -5619,6 +5619,7 @@ run_do(const char *cmd, void *arg UNUSED
     int                status;
     PyObject   *pyfunc, *pymain;
     PyObject   *run_ret;
+    buf_T      *was_curbuf = curbuf;
 
     if (u_save((linenr_T)RangeStart - 1, (linenr_T)RangeEnd + 1) != OK)
     {
@@ -5671,7 +5672,9 @@ run_do(const char *cmd, void *arg UNUSED
 #ifdef PY_CAN_RECURSE
        *pygilstate = PyGILState_Ensure();
 #endif
-       if (!(line = GetBufferLine(curbuf, lnum)))
+       /* Check the line number, the command my have deleted lines. */
+       if (lnum > curbuf->b_ml.ml_line_count
+               || !(line = GetBufferLine(curbuf, lnum)))
            goto err;
        if (!(linenr = PyInt_FromLong((long) lnum)))
        {
@@ -5684,9 +5687,19 @@ run_do(const char *cmd, void *arg UNUSED
        if (!ret)
            goto err;
 
+       /* Check that the command didn't switch to another buffer. */
+       if (curbuf != was_curbuf)
+       {
+           Py_XDECREF(ret);
+           goto err;
+       }
+
        if (ret != Py_None)
            if (SetBufferLine(curbuf, lnum, ret, NULL) == FAIL)
+           {
+               Py_XDECREF(ret);
                goto err;
+           }
 
        Py_XDECREF(ret);
        PythonIO_Flush();
index 12abb78bae205dc828341bbd920cd3f1a3b90eae..c01634cc0c50791faa2b0ebf91daf4d37d531155 100644 (file)
@@ -176,6 +176,8 @@ NEW_TESTS = test_arglist.res \
            test_packadd.res \
            test_perl.res \
            test_profile.res \
+           test_python2.res \
+           test_python3.res \
            test_pyx2.res \
            test_pyx3.res \
            test_quickfix.res \
diff --git a/src/testdir/test_python2.vim b/src/testdir/test_python2.vim
new file mode 100644 (file)
index 0000000..fb98c1e
--- /dev/null
@@ -0,0 +1,24 @@
+" Test for python 2 commands.
+" TODO: move tests from test87.in here.
+
+if !has('python')
+  finish
+endif
+
+func Test_pydo()
+  " Check deleting lines does not trigger ml_get error.
+  py import vim
+  new
+  call setline(1, ['one', 'two', 'three'])
+  pydo vim.command("%d_")
+  bwipe!
+
+  " Check switching to another buffer does not trigger ml_get error.
+  new
+  let wincount = winnr('$')
+  call setline(1, ['one', 'two', 'three'])
+  pydo vim.command("new")
+  call assert_equal(wincount + 1, winnr('$'))
+  bwipe!
+  bwipe!
+endfunc
diff --git a/src/testdir/test_python3.vim b/src/testdir/test_python3.vim
new file mode 100644 (file)
index 0000000..bb241da
--- /dev/null
@@ -0,0 +1,24 @@
+" Test for python 2 commands.
+" TODO: move tests from test88.in here.
+
+if !has('python3')
+  finish
+endif
+
+func Test_py3do()
+  " Check deleting lines does not trigger an ml_get error.
+  py3 import vim
+  new
+  call setline(1, ['one', 'two', 'three'])
+  py3do vim.command("%d_")
+  bwipe!
+
+  " Check switching to another buffer does not trigger an ml_get error.
+  new
+  let wincount = winnr('$')
+  call setline(1, ['one', 'two', 'three'])
+  py3do vim.command("new")
+  call assert_equal(wincount + 1, winnr('$'))
+  bwipe!
+  bwipe!
+endfunc
index 5431022f469714ea77bc0f69e04a01e5fc6acf99..bf28557567d7da6d0368974cbbcaa1fcf67cc349 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    265,
 /**/
     264,
 /**/