Skip to content

Commit c593fee

Browse files
committed
patch 8.0.0270: may get ml_get error when :rubydo deletes lines
Problem: May get ml_get error when :rubydo deletes lines or switches to another buffer. (Nikolai Pavlov, issue #1421) Solution: Check the buffer and line every time.
1 parent 85b5743 commit c593fee

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/if_ruby.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ void ex_rubydo(exarg_T *eap)
783783
{
784784
int state;
785785
linenr_T i;
786+
buf_T *was_curbuf = curbuf;
786787

787788
if (ensure_ruby_initialized())
788789
{
@@ -792,6 +793,8 @@ void ex_rubydo(exarg_T *eap)
792793
{
793794
VALUE line;
794795

796+
if (i > curbuf->b_ml.ml_line_count)
797+
break;
795798
line = vim_str2rb_enc_str((char *)ml_get(i));
796799
rb_lastline_set(line);
797800
eval_enc_string_protect((char *) eap->arg, &state);
@@ -800,6 +803,8 @@ void ex_rubydo(exarg_T *eap)
800803
error_print(state);
801804
break;
802805
}
806+
if (was_curbuf != curbuf)
807+
break;
803808
line = rb_lastline_get();
804809
if (!NIL_P(line))
805810
{

src/testdir/test_ruby.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,20 @@ func Test_ruby_evaluate_dict()
3232
redir END
3333
call assert_equal(['{"a"=>"foo", "b"=>123}'], split(l:out, "\n"))
3434
endfunc
35+
36+
func Test_rubydo()
37+
" Check deleting lines does not trigger ml_get error.
38+
new
39+
call setline(1, ['one', 'two', 'three'])
40+
rubydo Vim.command("%d_")
41+
bwipe!
42+
43+
" Check switching to another buffer does not trigger ml_get error.
44+
new
45+
let wincount = winnr('$')
46+
call setline(1, ['one', 'two', 'three'])
47+
rubydo Vim.command("new")
48+
call assert_equal(wincount + 1, winnr('$'))
49+
bwipe!
50+
bwipe!
51+
endfunc

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
270,
767769
/**/
768770
269,
769771
/**/

0 commit comments

Comments
 (0)