Skip to content

Commit b49b7fd

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 5f6b7f2 + bed36b9 commit b49b7fd

6 files changed

Lines changed: 115 additions & 18 deletions

File tree

src/if_py_both.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,7 +3374,7 @@ OptionsItem(OptionsObject *self, PyObject *keyObject)
33743374
char_u *stringval;
33753375
PyObject *todecref;
33763376

3377-
if (self->Check(self->from))
3377+
if (self->Check(self->fromObj))
33783378
return NULL;
33793379

33803380
if (!(key = StringToChars(keyObject, &todecref)))
@@ -3565,7 +3565,7 @@ OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject)
35653565
int ret = 0;
35663566
PyObject *todecref;
35673567

3568-
if (self->Check(self->from))
3568+
if (self->Check(self->fromObj))
35693569
return -1;
35703570

35713571
if (!(key = StringToChars(keyObject, &todecref)))
@@ -4334,10 +4334,15 @@ GetBufferLineList(buf_T *buf, PyInt lo, PyInt hi)
43344334

43354335
for (i = 0; i < n; ++i)
43364336
{
4337-
PyObject *string = LineToString(
4338-
(char *)ml_get_buf(buf, (linenr_T)(lo+i), FALSE));
4337+
linenr_T lnum = (linenr_T)(lo + i);
4338+
char *text;
4339+
PyObject *string;
43394340

4340-
// Error check - was the Python string creation OK?
4341+
if (lnum > buf->b_ml.ml_line_count)
4342+
text = "";
4343+
else
4344+
text = (char *)ml_get_buf(buf, lnum, FALSE);
4345+
string = LineToString(text);
43414346
if (string == NULL)
43424347
{
43434348
Py_DECREF(list);

src/testdir/test_python2.vim

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ func Test_python_range()
278278
py r[1:0] = ["d"]
279279
call assert_equal(['c', 'd', 'a', 'two', 'three', 'b'], getline(1, '$'))
280280

281-
" FIXME: The following code triggers ml_get errors
282-
" %d
283-
" let x = pyeval('r[:]')
281+
" The following code used to trigger an ml_get error
282+
%d
283+
let x = pyeval('r[:]')
284284

285285
" Non-existing range attribute
286286
call AssertException(["let x = pyeval('r.abc')"],
@@ -332,9 +332,9 @@ func Test_python_window()
332332
call AssertException(["py vim.current.window = w"],
333333
\ 'Vim(python):vim.error: attempt to refer to deleted window')
334334
" Try to set one of the options of the closed window
335-
" FIXME: The following causes ASAN failure
336-
"call AssertException(["py wopts['list'] = False"],
337-
" \ 'vim.error: problem while switching windows')
335+
" The following caused an ASAN failure
336+
call AssertException(["py wopts['list'] = False"],
337+
\ 'vim.error: attempt to refer to deleted window')
338338
call assert_match('<window object (deleted)', pyeval("repr(w)"))
339339
%bw!
340340
endfunc
@@ -623,6 +623,9 @@ func Test_python_slice_assignment()
623623
py l = vim.bindeval('l')
624624
py l[2:2:1] = ()
625625
call assert_equal([0, 1, 2, 3, 4, 5, 6, 7], l)
626+
627+
call AssertException(["py x = l[10:11:0]"],
628+
\ "Vim(python):ValueError: slice step cannot be zero")
626629
endfunc
627630

628631
" Locked variables
@@ -809,6 +812,10 @@ func Test_python_vim_bindeval()
809812
call assert_equal(0, pyeval("vim.bindeval('v:false')"))
810813
call assert_equal(v:none, pyeval("vim.bindeval('v:null')"))
811814
call assert_equal(v:none, pyeval("vim.bindeval('v:none')"))
815+
816+
" channel/job
817+
call assert_equal(v:none, pyeval("vim.bindeval('test_null_channel()')"))
818+
call assert_equal(v:none, pyeval("vim.bindeval('test_null_job()')"))
812819
endfunc
813820

814821
" threading
@@ -1402,6 +1409,20 @@ func Test_python_buffer()
14021409
call assert_equal([], pyeval('b[2:0]'))
14031410
call assert_equal([], pyeval('b[10:12]'))
14041411
call assert_equal([], pyeval('b[-10:-8]'))
1412+
call AssertException(["py x = b[0:3:0]"],
1413+
\ "Vim(python):TypeError: sequence index must be integer, not 'slice'")
1414+
call AssertException(["py b[0:3:0] = 'abc'"],
1415+
\ "Vim(python):TypeError: sequence index must be integer, not 'slice'")
1416+
call AssertException(["py x = b[{}]"],
1417+
\ "Vim(python):TypeError: sequence index must be integer, not 'dict'")
1418+
call AssertException(["py b[{}] = 'abc'"],
1419+
\ "Vim(python):TypeError: sequence index must be integer, not 'dict'")
1420+
1421+
" Test for getting lines using a range
1422+
call AssertException(["py x = b.range(0,3)[0:2:0]"],
1423+
\ "Vim(python):TypeError: sequence index must be integer, not 'slice'")
1424+
call AssertException(["py b.range(0,3)[0:2:0] = 'abc'"],
1425+
\ "Vim(python):TypeError: sequence index must be integer, not 'slice'")
14051426

14061427
" Tests BufferAppend and BufferItem
14071428
py cb.append(b[0])
@@ -1512,6 +1533,9 @@ func Test_python_buffer()
15121533
py vim.current.buffer[:] = []
15131534
call assert_equal([''], getline(1, '$'))
15141535

1536+
" Test for buffer marks
1537+
call assert_equal(v:none, pyeval("vim.current.buffer.mark('r')"))
1538+
15151539
" Test for modifying a 'nomodifiable' buffer
15161540
setlocal nomodifiable
15171541
call AssertException(["py vim.current.buffer[0] = 'abc'"],
@@ -2408,6 +2432,7 @@ func Test_python_chdir()
24082432
call assert_equal(['testdir', 'Xfile', 'src', 'testdir/Xfile', 'testdir',
24092433
\ 'Xfile'], getline(2, '$'))
24102434
close!
2435+
call AssertException(["py vim.chdir(None)"], "Vim(python):TypeError:")
24112436
endfunc
24122437

24132438
" Test errors

src/testdir/test_python3.vim

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,9 @@ func Test_python3_range2()
462462
py3 r[1:0] = ["d"]
463463
call assert_equal(['c', 'd', 'a', 'two', 'three', 'b'], getline(1, '$'))
464464

465-
" FIXME: The following code triggers ml_get errors
466-
" %d
467-
" let x = py3eval('r[:]')
465+
" The following code used to trigger an ml_get error
466+
%d
467+
let x = py3eval('r[:]')
468468

469469
" Non-existing range attribute
470470
call AssertException(["let x = py3eval('r.abc')"],
@@ -516,9 +516,9 @@ func Test_python3_window()
516516
call AssertException(["py3 vim.current.window = w"],
517517
\ 'Vim(py3):vim.error: attempt to refer to deleted window')
518518
" Try to set one of the options of the closed window
519-
" FIXME: The following causes ASAN failure
520-
"call AssertException(["py3 wopts['list'] = False"],
521-
" \ 'Vim(py3):vim.error: problem while switching windows')
519+
" The following caused ASAN failure
520+
call AssertException(["py3 wopts['list'] = False"],
521+
\ 'Vim(py3):vim.error: attempt to refer to deleted window')
522522
call assert_match('<window object (deleted)', py3eval("repr(w)"))
523523
%bw!
524524
endfunc
@@ -798,6 +798,9 @@ func Test_python3_slice_assignment()
798798
py3 l = vim.bindeval('l')
799799
py3 l[2:2:1] = ()
800800
call assert_equal([0, 1, 2, 3, 4, 5, 6, 7], l)
801+
802+
call AssertException(["py3 x = l[10:11:0]"],
803+
\ "Vim(py3):ValueError: slice step cannot be zero")
801804
endfunc
802805

803806
" Locked variables
@@ -987,6 +990,10 @@ func Test_python3_vim_bindeval()
987990
call assert_equal(0, py3eval("vim.bindeval('v:false')"))
988991
call assert_equal(v:none, py3eval("vim.bindeval('v:null')"))
989992
call assert_equal(v:none, py3eval("vim.bindeval('v:none')"))
993+
994+
" channel/job
995+
call assert_equal(v:none, py3eval("vim.bindeval('test_null_channel()')"))
996+
call assert_equal(v:none, py3eval("vim.bindeval('test_null_job()')"))
990997
endfunc
991998

992999
" threading
@@ -1580,6 +1587,20 @@ func Test_python3_buffer()
15801587
call assert_equal([], py3eval('b[2:0]'))
15811588
call assert_equal([], py3eval('b[10:12]'))
15821589
call assert_equal([], py3eval('b[-10:-8]'))
1590+
call AssertException(["py3 x = b[0:3:0]"],
1591+
\ 'Vim(py3):ValueError: slice step cannot be zero')
1592+
call AssertException(["py3 b[0:3:0] = 'abc'"],
1593+
\ 'Vim(py3):ValueError: slice step cannot be zero')
1594+
call AssertException(["py3 x = b[{}]"],
1595+
\ 'Vim(py3):TypeError: index must be int or slice, not dict')
1596+
call AssertException(["py3 b[{}] = 'abc'"],
1597+
\ 'Vim(py3):TypeError: index must be int or slice, not dict')
1598+
1599+
" Test for getting lines using a range
1600+
call AssertException(["py3 x = b.range(0,3)[0:2:0]"],
1601+
\ "Vim(py3):ValueError: slice step cannot be zero")
1602+
call AssertException(["py3 b.range(0,3)[0:2:0] = 'abc'"],
1603+
\ "Vim(py3):ValueError: slice step cannot be zero")
15831604

15841605
" Tests BufferAppend and BufferItem
15851606
py3 cb.append(b[0])
@@ -1690,6 +1711,9 @@ func Test_python3_buffer()
16901711
py3 vim.current.buffer[:] = []
16911712
call assert_equal([''], getline(1, '$'))
16921713

1714+
" Test for buffer marks
1715+
call assert_equal(v:none, py3eval("vim.current.buffer.mark('r')"))
1716+
16931717
" Test for modifying a 'nomodifiable' buffer
16941718
setlocal nomodifiable
16951719
call AssertException(["py3 vim.current.buffer[0] = 'abc'"],
@@ -2578,6 +2602,7 @@ func Test_python3_chdir()
25782602
call assert_equal(["b'testdir'", 'Xfile', "b'src'", 'testdir/Xfile',
25792603
\"b'testdir'", 'Xfile'], getline(2, '$'))
25802604
close!
2605+
call AssertException(["py3 vim.chdir(None)"], "Vim(py3):TypeError:")
25812606
endfunc
25822607

25832608
" Test errors

src/testdir/test_vim9_script.vim

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,39 @@ def Test_vim9script_reload_import()
980980
delete('Ximport.vim')
981981
enddef
982982

983+
" Not exported function that is referenced needs to be accessed by the
984+
" script-local name.
985+
def Test_vim9script_funcref()
986+
let sortlines =<< trim END
987+
vim9script
988+
def Compare(i1: number, i2: number): number
989+
return i2 - i1
990+
enddef
991+
992+
export def FastSort(): list<number>
993+
return range(5)->sort(Compare)
994+
enddef
995+
END
996+
writefile(sortlines, 'Xsort.vim')
997+
998+
let lines =<< trim END
999+
vim9script
1000+
import FastSort from './Xsort.vim'
1001+
def Test()
1002+
g:result = FastSort()
1003+
enddef
1004+
Test()
1005+
END
1006+
writefile(lines, 'Xscript.vim')
1007+
1008+
source Xscript.vim
1009+
assert_equal([4, 3, 2, 1, 0], g:result)
1010+
1011+
unlet g:result
1012+
delete('Xsort.vim')
1013+
delete('Xscript.vim')
1014+
enddef
1015+
9831016
def Test_vim9script_reload_delfunc()
9841017
let first_lines =<< trim END
9851018
vim9script

src/version.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,14 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
1153,
774+
/**/
775+
1152,
776+
/**/
777+
1151,
778+
/**/
779+
1150,
772780
/**/
773781
1149,
774782
/**/

src/vim9compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2676,7 +2676,8 @@ generate_funcref(cctx_T *cctx, char_u *name)
26762676
if (ufunc == NULL)
26772677
return FAIL;
26782678

2679-
return generate_PUSHFUNC(cctx, vim_strsave(name), ufunc->uf_func_type);
2679+
return generate_PUSHFUNC(cctx, vim_strsave(ufunc->uf_name),
2680+
ufunc->uf_func_type);
26802681
}
26812682

26822683
/*

0 commit comments

Comments
 (0)