1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

eval.c: rb_frame_callee returns current name

* eval.c (rb_frame_callee): returns the called name of the current
  frame, not the previous frame.
* eval.c (prev_frame_callee, prev_frame_func): rename and make static,
  as these are used by rb_f_method_name() and rb_f_callee_name() only.
* variable.c (set_const_visibility): use the called name.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-05-25 02:24:33 +00:00
parent 165db57cdc
commit 8a4fb4acba
3 changed files with 33 additions and 8 deletions

View file

@ -1,3 +1,13 @@
Sat May 25 11:24:24 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_frame_callee): returns the called name of the current
frame, not the previous frame.
* eval.c (prev_frame_callee, prev_frame_func): rename and make static,
as these are used by rb_f_method_name() and rb_f_callee_name() only.
* variable.c (set_const_visibility): use the called name.
Sat May 25 08:58:23 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_quote_unprintable): check if argument is a string.

29
eval.c
View file

@ -914,6 +914,12 @@ rb_frame_this_func(void)
return frame_func_id(GET_THREAD()->cfp);
}
ID
rb_frame_callee(void)
{
return frame_called_id(GET_THREAD()->cfp);
}
static rb_control_frame_t *
previous_frame(rb_thread_t *th)
{
@ -925,8 +931,8 @@ previous_frame(rb_thread_t *th)
return prev_cfp;
}
ID
rb_frame_callee(void)
static ID
prev_frame_callee(void)
{
rb_control_frame_t *prev_cfp = previous_frame(GET_THREAD());
if (!prev_cfp) return 0;
@ -934,7 +940,7 @@ rb_frame_callee(void)
}
static ID
rb_frame_caller(void)
prev_frame_func(void)
{
rb_control_frame_t *prev_cfp = previous_frame(GET_THREAD());
if (!prev_cfp) return 0;
@ -1471,9 +1477,9 @@ errat_setter(VALUE val, ID id, VALUE *var)
/*
* call-seq:
* __method__ -> symbol
* __callee__ -> symbol
*
* Returns the name of the current method as a Symbol.
* Returns the name at the definition of the current method as a
* Symbol.
* If called outside of a method, it returns <code>nil</code>.
*
*/
@ -1481,7 +1487,7 @@ errat_setter(VALUE val, ID id, VALUE *var)
static VALUE
rb_f_method_name(void)
{
ID fname = rb_frame_caller(); /* need *caller* ID */
ID fname = prev_frame_func(); /* need *method* ID */
if (fname) {
return ID2SYM(fname);
@ -1491,10 +1497,19 @@ rb_f_method_name(void)
}
}
/*
* call-seq:
* __callee__ -> symbol
*
* Returns the called name of the current method as a Symbol.
* If called outside of a method, it returns <code>nil</code>.
*
*/
static VALUE
rb_f_callee_name(void)
{
ID fname = rb_frame_callee(); /* need *callee* ID */
ID fname = prev_frame_callee(); /* need *callee* ID */
if (fname) {
return ID2SYM(fname);

View file

@ -2231,7 +2231,7 @@ set_const_visibility(VALUE mod, int argc, VALUE *argv, rb_const_flag_t flag)
if (argc == 0) {
rb_warning("%"PRIsVALUE" with no argument is just ignored",
QUOTE_ID(rb_frame_this_func()));
QUOTE_ID(rb_frame_callee()));
}
for (i = 0; i < argc; i++) {