[前][次][番号順一覧][スレッド一覧]

ruby-changes:28869

From: nobu <ko1@a...>
Date: Sat, 25 May 2013 11:24:48 +0900 (JST)
Subject: [ruby-changes:28869] nobu:r40921 (trunk): eval.c: rb_frame_callee returns current name

nobu	2013-05-25 11:24:33 +0900 (Sat, 25 May 2013)

  New Revision: 40921

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40921

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/eval.c
    trunk/variable.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40920)
+++ ChangeLog	(revision 40921)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat May 25 11:24:24 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* string.c (rb_str_quote_unprintable): check if argument is a string.
Index: variable.c
===================================================================
--- variable.c	(revision 40920)
+++ variable.c	(revision 40921)
@@ -2231,7 +2231,7 @@ set_const_visibility(VALUE mod, int argc https://github.com/ruby/ruby/blob/trunk/variable.c#L2231
 
     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++) {
Index: eval.c
===================================================================
--- eval.c	(revision 40920)
+++ eval.c	(revision 40921)
@@ -914,6 +914,12 @@ rb_frame_this_func(void) https://github.com/ruby/ruby/blob/trunk/eval.c#L914
     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) https://github.com/ruby/ruby/blob/trunk/eval.c#L931
     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) https://github.com/ruby/ruby/blob/trunk/eval.c#L940
 }
 
 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 *va https://github.com/ruby/ruby/blob/trunk/eval.c#L1477
 /*
  *  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 *va https://github.com/ruby/ruby/blob/trunk/eval.c#L1487
 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) https://github.com/ruby/ruby/blob/trunk/eval.c#L1497
     }
 }
 
+/*
+ *  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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]