0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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)
This commit is contained in:
Bram Moolenaar
2018-08-11 14:24:11 +02:00
parent d569bb0299
commit 51e9fbf1c7
3 changed files with 33 additions and 1 deletions

View File

@@ -299,6 +299,11 @@ static void ruby_vim_init(void);
# define rb_string_value_ptr dll_rb_string_value_ptr # define rb_string_value_ptr dll_rb_string_value_ptr
# define rb_float_new dll_rb_float_new # define rb_float_new dll_rb_float_new
# define rb_ary_new dll_rb_ary_new # define rb_ary_new dll_rb_ary_new
# ifdef rb_ary_new4
# define RB_ARY_NEW4_MACRO 1
# undef rb_ary_new4
# endif
# define rb_ary_new4 dll_rb_ary_new4
# define rb_ary_push dll_rb_ary_push # define rb_ary_push dll_rb_ary_push
# if defined(RUBY19_OR_LATER) || defined(RUBY_INIT_STACK) # if defined(RUBY19_OR_LATER) || defined(RUBY_INIT_STACK)
# ifdef __ia64 # ifdef __ia64
@@ -441,6 +446,7 @@ static int (*dll_rb_w32_snprintf)(char*, size_t, const char*, ...);
static char * (*dll_rb_string_value_ptr) (volatile VALUE*); static char * (*dll_rb_string_value_ptr) (volatile VALUE*);
static VALUE (*dll_rb_float_new) (double); static VALUE (*dll_rb_float_new) (double);
static VALUE (*dll_rb_ary_new) (void); static VALUE (*dll_rb_ary_new) (void);
static VALUE (*dll_rb_ary_new4) (long n, const VALUE *elts);
static VALUE (*dll_rb_ary_push) (VALUE, VALUE); static VALUE (*dll_rb_ary_push) (VALUE, VALUE);
# if defined(RUBY19_OR_LATER) || defined(RUBY_INIT_STACK) # if defined(RUBY19_OR_LATER) || defined(RUBY_INIT_STACK)
# ifdef __ia64 # ifdef __ia64
@@ -647,6 +653,11 @@ static struct
{"rb_float_new_in_heap", (RUBY_PROC*)&dll_rb_float_new}, {"rb_float_new_in_heap", (RUBY_PROC*)&dll_rb_float_new},
# endif # endif
{"rb_ary_new", (RUBY_PROC*)&dll_rb_ary_new}, {"rb_ary_new", (RUBY_PROC*)&dll_rb_ary_new},
# ifdef RB_ARY_NEW4_MACRO
{"rb_ary_new_from_values", (RUBY_PROC*)&dll_rb_ary_new4},
# else
{"rb_ary_new4", (RUBY_PROC*)&dll_rb_ary_new4},
# endif
{"rb_ary_push", (RUBY_PROC*)&dll_rb_ary_push}, {"rb_ary_push", (RUBY_PROC*)&dll_rb_ary_push},
# endif # endif
# ifdef RUBY19_OR_LATER # ifdef RUBY19_OR_LATER
@@ -1577,6 +1588,7 @@ static VALUE f_p(int argc, VALUE *argv, VALUE self UNUSED)
{ {
int i; int i;
VALUE str = rb_str_new("", 0); VALUE str = rb_str_new("", 0);
VALUE ret = Qnil;
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)
{ {
@@ -1584,7 +1596,12 @@ static VALUE f_p(int argc, VALUE *argv, VALUE self UNUSED)
rb_str_concat(str, rb_inspect(argv[i])); rb_str_concat(str, rb_inspect(argv[i]));
} }
MSG(RSTRING_PTR(str)); MSG(RSTRING_PTR(str));
return Qnil;
if (argc == 1)
ret = argv[0];
else if (argc > 1)
ret = rb_ary_new4(argc, argv);
return ret;
} }
static void ruby_io_init(void) static void ruby_io_init(void)

View File

@@ -363,4 +363,17 @@ func Test_p()
ruby p 'Just a test' ruby p 'Just a test'
let messages = split(execute('message'), "\n") let messages = split(execute('message'), "\n")
call assert_equal('"Just a test"', messages[-1]) call assert_equal('"Just a test"', messages[-1])
" Check return values of p method
call assert_equal('123', RubyEval('p(123)'))
call assert_equal('[1, 2, 3]', RubyEval('p(1, 2, 3)'))
" Avoid the "message maintainer" line.
let $LANG = ''
messages clear
call assert_equal('true', RubyEval('p() == nil'))
let messages = split(execute('message'), "\n")
call assert_equal(0, len(messages))
endfunc endfunc

View File

@@ -794,6 +794,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
269,
/**/ /**/
268, 268,
/**/ /**/