Skip to content

Commit 51e9fbf

Browse files
committed
patch 8.1.0269: Ruby Kernel.#p method always returns nil
Problem: Ruby Kernel.#p method always returns nil. Solution: Copy p method implementation from Ruby code. (Masataka Pocke Kuwabara, closes #3315)
1 parent d569bb0 commit 51e9fbf

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/if_ruby.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ static void ruby_vim_init(void);
299299
# define rb_string_value_ptr dll_rb_string_value_ptr
300300
# define rb_float_new dll_rb_float_new
301301
# define rb_ary_new dll_rb_ary_new
302+
# ifdef rb_ary_new4
303+
# define RB_ARY_NEW4_MACRO 1
304+
# undef rb_ary_new4
305+
# endif
306+
# define rb_ary_new4 dll_rb_ary_new4
302307
# define rb_ary_push dll_rb_ary_push
303308
# if defined(RUBY19_OR_LATER) || defined(RUBY_INIT_STACK)
304309
# ifdef __ia64
@@ -441,6 +446,7 @@ static int (*dll_rb_w32_snprintf)(char*, size_t, const char*, ...);
441446
static char * (*dll_rb_string_value_ptr) (volatile VALUE*);
442447
static VALUE (*dll_rb_float_new) (double);
443448
static VALUE (*dll_rb_ary_new) (void);
449+
static VALUE (*dll_rb_ary_new4) (long n, const VALUE *elts);
444450
static VALUE (*dll_rb_ary_push) (VALUE, VALUE);
445451
# if defined(RUBY19_OR_LATER) || defined(RUBY_INIT_STACK)
446452
# ifdef __ia64
@@ -647,6 +653,11 @@ static struct
647653
{"rb_float_new_in_heap", (RUBY_PROC*)&dll_rb_float_new},
648654
# endif
649655
{"rb_ary_new", (RUBY_PROC*)&dll_rb_ary_new},
656+
# ifdef RB_ARY_NEW4_MACRO
657+
{"rb_ary_new_from_values", (RUBY_PROC*)&dll_rb_ary_new4},
658+
# else
659+
{"rb_ary_new4", (RUBY_PROC*)&dll_rb_ary_new4},
660+
# endif
650661
{"rb_ary_push", (RUBY_PROC*)&dll_rb_ary_push},
651662
# endif
652663
# ifdef RUBY19_OR_LATER
@@ -1577,14 +1588,20 @@ static VALUE f_p(int argc, VALUE *argv, VALUE self UNUSED)
15771588
{
15781589
int i;
15791590
VALUE str = rb_str_new("", 0);
1591+
VALUE ret = Qnil;
15801592

15811593
for (i = 0; i < argc; i++)
15821594
{
15831595
if (i > 0) rb_str_cat(str, ", ", 2);
15841596
rb_str_concat(str, rb_inspect(argv[i]));
15851597
}
15861598
MSG(RSTRING_PTR(str));
1587-
return Qnil;
1599+
1600+
if (argc == 1)
1601+
ret = argv[0];
1602+
else if (argc > 1)
1603+
ret = rb_ary_new4(argc, argv);
1604+
return ret;
15881605
}
15891606

15901607
static void ruby_io_init(void)

src/testdir/test_ruby.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,17 @@ func Test_p()
363363
ruby p 'Just a test'
364364
let messages = split(execute('message'), "\n")
365365
call assert_equal('"Just a test"', messages[-1])
366+
367+
" Check return values of p method
368+
369+
call assert_equal('123', RubyEval('p(123)'))
370+
call assert_equal('[1, 2, 3]', RubyEval('p(1, 2, 3)'))
371+
372+
" Avoid the "message maintainer" line.
373+
let $LANG = ''
374+
messages clear
375+
call assert_equal('true', RubyEval('p() == nil'))
376+
377+
let messages = split(execute('message'), "\n")
378+
call assert_equal(0, len(messages))
366379
endfunc

src/version.c

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

795795
static int included_patches[] =
796796
{ /* Add new patch number below this line */
797+
/**/
798+
269,
797799
/**/
798800
268,
799801
/**/

0 commit comments

Comments
 (0)