From bb790dcc46b74e6f9a1c4126be8a575f9fe73444 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 7 Jul 2020 20:12:54 +0200 Subject: [PATCH 1/4] patch 8.2.1150: ml_get error when using Python Problem: ml_get error when using Python. (Yegappan Lakshmanan) Solution: Check the line number is not out of range. Call "Check" with "fromObj" instead of "from". --- src/if_py_both.h | 15 ++++++++++----- src/testdir/test_python2.vim | 12 ++++++------ src/testdir/test_python3.vim | 12 ++++++------ src/version.c | 2 ++ 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/if_py_both.h b/src/if_py_both.h index c7df93be2a..5bd6a0e677 100644 --- a/src/if_py_both.h +++ b/src/if_py_both.h @@ -3374,7 +3374,7 @@ OptionsItem(OptionsObject *self, PyObject *keyObject) char_u *stringval; PyObject *todecref; - if (self->Check(self->from)) + if (self->Check(self->fromObj)) return NULL; if (!(key = StringToChars(keyObject, &todecref))) @@ -3565,7 +3565,7 @@ OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject) int ret = 0; PyObject *todecref; - if (self->Check(self->from)) + if (self->Check(self->fromObj)) return -1; if (!(key = StringToChars(keyObject, &todecref))) @@ -4334,10 +4334,15 @@ GetBufferLineList(buf_T *buf, PyInt lo, PyInt hi) for (i = 0; i < n; ++i) { - PyObject *string = LineToString( - (char *)ml_get_buf(buf, (linenr_T)(lo+i), FALSE)); + linenr_T lnum = (linenr_T)(lo + i); + char *text; + PyObject *string; - // Error check - was the Python string creation OK? + if (lnum > buf->b_ml.ml_line_count) + text = ""; + else + text = (char *)ml_get_buf(buf, lnum, FALSE); + string = LineToString(text); if (string == NULL) { Py_DECREF(list); diff --git a/src/testdir/test_python2.vim b/src/testdir/test_python2.vim index f0b9b06c72..0d41f391a3 100644 --- a/src/testdir/test_python2.vim +++ b/src/testdir/test_python2.vim @@ -278,9 +278,9 @@ func Test_python_range() py r[1:0] = ["d"] call assert_equal(['c', 'd', 'a', 'two', 'three', 'b'], getline(1, '$')) - " FIXME: The following code triggers ml_get errors - " %d - " let x = pyeval('r[:]') + " The following code used to trigger an ml_get error + %d + let x = pyeval('r[:]') " Non-existing range attribute call AssertException(["let x = pyeval('r.abc')"], @@ -332,9 +332,9 @@ func Test_python_window() call AssertException(["py vim.current.window = w"], \ 'Vim(python):vim.error: attempt to refer to deleted window') " Try to set one of the options of the closed window - " FIXME: The following causes ASAN failure - "call AssertException(["py wopts['list'] = False"], - " \ 'vim.error: problem while switching windows') + " The following caused an ASAN failure + call AssertException(["py wopts['list'] = False"], + \ 'vim.error: attempt to refer to deleted window') call assert_match(' Date: Tue, 7 Jul 2020 20:50:39 +0200 Subject: [PATCH 2/4] patch 8.2.1151: insufficient test coverage for Python Problem: Insufficient test coverage for Python. Solution: Add more test cases. (Yegappan Lakshmanan, closes #6415) --- src/testdir/test_python2.vim | 25 +++++++++++++++++++++++++ src/testdir/test_python3.vim | 25 +++++++++++++++++++++++++ src/version.c | 2 ++ 3 files changed, 52 insertions(+) diff --git a/src/testdir/test_python2.vim b/src/testdir/test_python2.vim index 0d41f391a3..42fadaab69 100644 --- a/src/testdir/test_python2.vim +++ b/src/testdir/test_python2.vim @@ -623,6 +623,9 @@ func Test_python_slice_assignment() py l = vim.bindeval('l') py l[2:2:1] = () call assert_equal([0, 1, 2, 3, 4, 5, 6, 7], l) + + call AssertException(["py x = l[10:11:0]"], + \ "Vim(python):ValueError: slice step cannot be zero") endfunc " Locked variables @@ -809,6 +812,10 @@ func Test_python_vim_bindeval() call assert_equal(0, pyeval("vim.bindeval('v:false')")) call assert_equal(v:none, pyeval("vim.bindeval('v:null')")) call assert_equal(v:none, pyeval("vim.bindeval('v:none')")) + + " channel/job + call assert_equal(v:none, pyeval("vim.bindeval('test_null_channel()')")) + call assert_equal(v:none, pyeval("vim.bindeval('test_null_job()')")) endfunc " threading @@ -1402,6 +1409,20 @@ func Test_python_buffer() call assert_equal([], pyeval('b[2:0]')) call assert_equal([], pyeval('b[10:12]')) call assert_equal([], pyeval('b[-10:-8]')) + call AssertException(["py x = b[0:3:0]"], + \ "Vim(python):TypeError: sequence index must be integer, not 'slice'") + call AssertException(["py b[0:3:0] = 'abc'"], + \ "Vim(python):TypeError: sequence index must be integer, not 'slice'") + call AssertException(["py x = b[{}]"], + \ "Vim(python):TypeError: sequence index must be integer, not 'dict'") + call AssertException(["py b[{}] = 'abc'"], + \ "Vim(python):TypeError: sequence index must be integer, not 'dict'") + + " Test for getting lines using a range + call AssertException(["py x = b.range(0,3)[0:2:0]"], + \ "Vim(python):TypeError: sequence index must be integer, not 'slice'") + call AssertException(["py b.range(0,3)[0:2:0] = 'abc'"], + \ "Vim(python):TypeError: sequence index must be integer, not 'slice'") " Tests BufferAppend and BufferItem py cb.append(b[0]) @@ -1512,6 +1533,9 @@ func Test_python_buffer() py vim.current.buffer[:] = [] call assert_equal([''], getline(1, '$')) + " Test for buffer marks + call assert_equal(v:none, pyeval("vim.current.buffer.mark('r')")) + " Test for modifying a 'nomodifiable' buffer setlocal nomodifiable call AssertException(["py vim.current.buffer[0] = 'abc'"], @@ -2408,6 +2432,7 @@ func Test_python_chdir() call assert_equal(['testdir', 'Xfile', 'src', 'testdir/Xfile', 'testdir', \ 'Xfile'], getline(2, '$')) close! + call AssertException(["py vim.chdir(None)"], "Vim(python):TypeError:") endfunc " Test errors diff --git a/src/testdir/test_python3.vim b/src/testdir/test_python3.vim index 1fb22fc7bd..0082751d77 100644 --- a/src/testdir/test_python3.vim +++ b/src/testdir/test_python3.vim @@ -798,6 +798,9 @@ func Test_python3_slice_assignment() py3 l = vim.bindeval('l') py3 l[2:2:1] = () call assert_equal([0, 1, 2, 3, 4, 5, 6, 7], l) + + call AssertException(["py3 x = l[10:11:0]"], + \ "Vim(py3):ValueError: slice step cannot be zero") endfunc " Locked variables @@ -987,6 +990,10 @@ func Test_python3_vim_bindeval() call assert_equal(0, py3eval("vim.bindeval('v:false')")) call assert_equal(v:none, py3eval("vim.bindeval('v:null')")) call assert_equal(v:none, py3eval("vim.bindeval('v:none')")) + + " channel/job + call assert_equal(v:none, py3eval("vim.bindeval('test_null_channel()')")) + call assert_equal(v:none, py3eval("vim.bindeval('test_null_job()')")) endfunc " threading @@ -1580,6 +1587,20 @@ func Test_python3_buffer() call assert_equal([], py3eval('b[2:0]')) call assert_equal([], py3eval('b[10:12]')) call assert_equal([], py3eval('b[-10:-8]')) + call AssertException(["py3 x = b[0:3:0]"], + \ 'Vim(py3):ValueError: slice step cannot be zero') + call AssertException(["py3 b[0:3:0] = 'abc'"], + \ 'Vim(py3):ValueError: slice step cannot be zero') + call AssertException(["py3 x = b[{}]"], + \ 'Vim(py3):TypeError: index must be int or slice, not dict') + call AssertException(["py3 b[{}] = 'abc'"], + \ 'Vim(py3):TypeError: index must be int or slice, not dict') + + " Test for getting lines using a range + call AssertException(["py3 x = b.range(0,3)[0:2:0]"], + \ "Vim(py3):ValueError: slice step cannot be zero") + call AssertException(["py3 b.range(0,3)[0:2:0] = 'abc'"], + \ "Vim(py3):ValueError: slice step cannot be zero") " Tests BufferAppend and BufferItem py3 cb.append(b[0]) @@ -1690,6 +1711,9 @@ func Test_python3_buffer() py3 vim.current.buffer[:] = [] call assert_equal([''], getline(1, '$')) + " Test for buffer marks + call assert_equal(v:none, py3eval("vim.current.buffer.mark('r')")) + " Test for modifying a 'nomodifiable' buffer setlocal nomodifiable call AssertException(["py3 vim.current.buffer[0] = 'abc'"], @@ -2578,6 +2602,7 @@ func Test_python3_chdir() call assert_equal(["b'testdir'", 'Xfile', "b'src'", 'testdir/Xfile', \"b'testdir'", 'Xfile'], getline(2, '$')) close! + call AssertException(["py3 vim.chdir(None)"], "Vim(py3):TypeError:") endfunc " Test errors diff --git a/src/version.c b/src/version.c index d00c960f4c..d8124ef4d1 100644 --- a/src/version.c +++ b/src/version.c @@ -754,6 +754,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1151, /**/ 1150, /**/ From fe465a01cfbbbae5d870d6108e0ad0947f03b0c4 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 7 Jul 2020 22:50:12 +0200 Subject: [PATCH 3/4] patch 8.2.1152: Vim9: function reference is missing script prefix Problem: Vim9: function reference is missing script prefix. Solution: Use the actual function name instead of the name searched for in the script context. (closes #6412) --- src/testdir/test_vim9_script.vim | 33 ++++++++++++++++++++++++++++++++ src/version.c | 2 ++ src/vim9compile.c | 3 ++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index 726ca9af6d..63da003500 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -980,6 +980,39 @@ def Test_vim9script_reload_import() delete('Ximport.vim') enddef +" Not exported function that is referenced needs to be accessed by the +" script-local name. +def Test_vim9script_funcref() + let sortlines =<< trim END + vim9script + def Compare(i1: number, i2: number): number + return 1 + enddef + + export def FastSort(): list + return range(5)->sort(Compare) + enddef + END + writefile(sortlines, 'Xsort.vim') + + let lines =<< trim END + vim9script + import FastSort from './Xsort.vim' + def Test() + g:result = FastSort() + enddef + Test() + END + writefile(lines, 'Xscript.vim') + + source Xscript.vim + assert_equal([4, 3, 2, 1, 0], g:result) + + unlet g:result + delete('Xsort.vim') + delete('Xscript.vim') +enddef + def Test_vim9script_reload_delfunc() let first_lines =<< trim END vim9script diff --git a/src/version.c b/src/version.c index d8124ef4d1..f5de446b54 100644 --- a/src/version.c +++ b/src/version.c @@ -754,6 +754,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1152, /**/ 1151, /**/ diff --git a/src/vim9compile.c b/src/vim9compile.c index ff6668fe46..07e0d27277 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -2676,7 +2676,8 @@ generate_funcref(cctx_T *cctx, char_u *name) if (ufunc == NULL) return FAIL; - return generate_PUSHFUNC(cctx, vim_strsave(name), ufunc->uf_func_type); + return generate_PUSHFUNC(cctx, vim_strsave(ufunc->uf_name), + ufunc->uf_func_type); } /* From bed36b939a4c66f41d1f24e32cfa521b10f22b82 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 7 Jul 2020 23:31:36 +0200 Subject: [PATCH 4/4] patch 8.2.1153: Vim9: script test fails on some systems Problem: Vim9: script test fails on some systems. Solution: Return proper value from Compare(). --- src/testdir/test_vim9_script.vim | 2 +- src/version.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index 63da003500..c1d722865e 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -986,7 +986,7 @@ def Test_vim9script_funcref() let sortlines =<< trim END vim9script def Compare(i1: number, i2: number): number - return 1 + return i2 - i1 enddef export def FastSort(): list diff --git a/src/version.c b/src/version.c index f5de446b54..0d3e85e54f 100644 --- a/src/version.c +++ b/src/version.c @@ -754,6 +754,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1153, /**/ 1152, /**/