Mercurial > vim
changeset 10751:27b42717662b v8.0.0265
patch 8.0.0265: may get ml_get error when :pydo deletes lines
commit https://github.com/vim/vim/commit/a58883b4ea0bbb813fd4dd7eb49dd6f03e3e5387
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 29 21:31:09 2017 +0100
patch 8.0.0265: may get ml_get error when :pydo deletes lines
Problem: May get ml_get error when :pydo deletes lines or switches to
another buffer. (Nikolai Pavlov, issue https://github.com/vim/vim/issues/1421)
Solution: Check the buffer and line every time.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 29 Jan 2017 21:45:04 +0100 |
parents | bc18332a39a1 |
children | 8d88dc61518f |
files | src/Makefile src/if_py_both.h src/testdir/Make_all.mak src/testdir/test_python2.vim src/testdir/test_python3.vim src/version.c |
diffstat | 6 files changed, 68 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Makefile +++ b/src/Makefile @@ -2168,6 +2168,8 @@ test_arglist \ test_popup \ test_profile \ test_put \ + test_python2 \ + test_python3 \ test_pyx2 \ test_pyx3 \ test_quickfix \
--- a/src/if_py_both.h +++ b/src/if_py_both.h @@ -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();
--- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -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 \
new file mode 100644 --- /dev/null +++ b/src/testdir/test_python2.vim @@ -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
new file mode 100644 --- /dev/null +++ b/src/testdir/test_python3.vim @@ -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