ruby-changes:44252
From: nobu <ko1@a...>
Date: Mon, 3 Oct 2016 16:10:57 +0900 (JST)
Subject: [ruby-changes:44252] nobu:r56324 (trunk): readline.c: mustbe_callable
nobu 2016-10-03 16:10:49 +0900 (Mon, 03 Oct 2016) New Revision: 56324 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56324 Log: readline.c: mustbe_callable * ext/readline/readline.c (mustbe_callable): extract to check a given argument to be callable. Modified files: trunk/ext/readline/readline.c Index: ext/readline/readline.c =================================================================== --- ext/readline/readline.c (revision 56323) +++ ext/readline/readline.c (revision 56324) @@ -58,7 +58,7 @@ static VALUE mReadline; https://github.com/ruby/ruby/blob/trunk/ext/readline/readline.c#L58 #define COMPLETION_PROC "completion_proc" #define COMPLETION_CASE_FOLD "completion_case_fold" -static ID completion_proc, completion_case_fold; +static ID id_call, completion_proc, completion_case_fold; #if USE_INSERT_IGNORE_ESCAPE static ID id_orig_prompt, id_last_prompt; #endif @@ -132,6 +132,13 @@ static VALUE readline_outstream; https://github.com/ruby/ruby/blob/trunk/ext/readline/readline.c#L132 static FILE *readline_rl_instream; static FILE *readline_rl_outstream; +static void +mustbe_callable(VALUE proc) +{ + if (!NIL_P(proc) && !rb_respond_to(proc, id_call)) + rb_raise(rb_eArgError, "argument must respond to `call'"); +} + #if defined HAVE_RL_GETC_FUNCTION #ifndef HAVE_RL_GETC @@ -618,8 +625,7 @@ readline_s_set_output(VALUE self, VALUE https://github.com/ruby/ruby/blob/trunk/ext/readline/readline.c#L625 static VALUE readline_s_set_pre_input_hook(VALUE self, VALUE proc) { - if (!NIL_P(proc) && !rb_respond_to(proc, rb_intern("call"))) - rb_raise(rb_eArgError, "argument must respond to `call'"); + mustbe_callable(proc); return rb_ivar_set(mReadline, id_pre_input_hook, proc); } @@ -646,7 +652,7 @@ readline_pre_input_hook(void) https://github.com/ruby/ruby/blob/trunk/ext/readline/readline.c#L652 proc = rb_attr_get(mReadline, id_pre_input_hook); if (!NIL_P(proc)) - rb_funcall(proc, rb_intern("call"), 0); + rb_funcall(proc, id_call, 0); return 0; } #else @@ -815,8 +821,7 @@ readline_s_redisplay(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/readline/readline.c#L821 static VALUE readline_s_set_completion_proc(VALUE self, VALUE proc) { - if (!NIL_P(proc) && !rb_respond_to(proc, rb_intern("call"))) - rb_raise(rb_eArgError, "argument must respond to `call'"); + mustbe_callable(proc); return rb_ivar_set(mReadline, completion_proc, proc); } @@ -953,7 +958,7 @@ readline_attempted_completion_function(c https://github.com/ruby/ruby/blob/trunk/ext/readline/readline.c#L958 rl_attempted_completion_over = 1; #endif case_fold = RTEST(rb_attr_get(mReadline, completion_case_fold)); - ary = rb_funcall(proc, rb_intern("call"), 1, rb_locale_str_new_cstr(text)); + ary = rb_funcall(proc, id_call, 1, rb_locale_str_new_cstr(text)); if (!RB_TYPE_P(ary, T_ARRAY)) ary = rb_Array(ary); matches = RARRAY_LEN(ary); @@ -1794,6 +1799,7 @@ username_completion_proc_call(VALUE self https://github.com/ruby/ruby/blob/trunk/ext/readline/readline.c#L1799 return result; } +#undef rb_intern void Init_readline(void) { @@ -1813,6 +1819,7 @@ Init_readline(void) https://github.com/ruby/ruby/blob/trunk/ext/readline/readline.c#L1819 using_history(); + id_call = rb_intern("call"); completion_proc = rb_intern(COMPLETION_PROC); completion_case_fold = rb_intern(COMPLETION_CASE_FOLD); #if defined(HAVE_RL_PRE_INPUT_HOOK) @@ -1979,7 +1986,7 @@ Init_readline(void) https://github.com/ruby/ruby/blob/trunk/ext/readline/readline.c#L1986 rl_attempted_completion_function = readline_attempted_completion_function; #if defined(HAVE_RL_PRE_INPUT_HOOK) - rl_pre_input_hook = (rl_hook_func_t *)readline_pre_input_hook; + rl_pre_input_hook = readline_pre_input_hook; #endif #ifdef HAVE_RL_CATCH_SIGNALS rl_catch_signals = 0; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/