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

ruby-changes:4633

From: ko1@a...
Date: Mon, 21 Apr 2008 18:43:59 +0900 (JST)
Subject: [ruby-changes:4633] knu - Ruby:r16127 (ruby_1_8_7): Merge from ruby_1_8.

knu	2008-04-21 18:43:44 +0900 (Mon, 21 Apr 2008)

  New Revision: 16127

  Modified files:
    branches/ruby_1_8_7/ChangeLog
    branches/ruby_1_8_7/NEWS
    branches/ruby_1_8_7/enumerator.c
    branches/ruby_1_8_7/eval.c
    branches/ruby_1_8_7/intern.h
    branches/ruby_1_8_7/lib/tempfile.rb

  Log:
    Merge from ruby_1_8.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/enumerator.c?r1=16127&r2=16126&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/eval.c?r1=16127&r2=16126&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/ChangeLog?r1=16127&r2=16126&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/lib/tempfile.rb?r1=16127&r2=16126&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/NEWS?r1=16127&r2=16126&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_7/intern.h?r1=16127&r2=16126&diff_format=u

Index: ruby_1_8_7/intern.h
===================================================================
--- ruby_1_8_7/intern.h	(revision 16126)
+++ ruby_1_8_7/intern.h	(revision 16127)
@@ -133,7 +133,7 @@
 VALUE rb_enumeratorize _((VALUE, VALUE, int, VALUE *));
 #define RETURN_ENUMERATOR(obj, argc, argv) do {				\
 	if (!rb_block_given_p())					\
-	    return rb_enumeratorize(obj, ID2SYM(rb_frame_last_func()),	\
+	    return rb_enumeratorize(obj, ID2SYM(rb_frame_this_func()),	\
 				    argc, argv);			\
     } while (0)
 /* error.c */
@@ -180,6 +180,7 @@
 VALUE rb_apply _((VALUE, ID, VALUE));
 void rb_backtrace _((void));
 ID rb_frame_last_func _((void));
+ID rb_frame_this_func _((void));
 VALUE rb_obj_instance_eval _((int, VALUE*, VALUE));
 VALUE rb_mod_module_eval _((int, VALUE*, VALUE));
 void rb_load _((VALUE, int));
Index: ruby_1_8_7/NEWS
===================================================================
--- ruby_1_8_7/NEWS	(revision 16126)
+++ ruby_1_8_7/NEWS	(revision 16127)
@@ -232,6 +232,11 @@
 
     Return an enumerator if no block is given.
 
+  * __method__
+
+    New global function that returns the name of the current method as
+    a Symbol.
+
 * enumerator
 
   * Enumerator is now a built-in module.  The #next and #rewind
Index: ruby_1_8_7/ChangeLog
===================================================================
--- ruby_1_8_7/ChangeLog	(revision 16126)
+++ ruby_1_8_7/ChangeLog	(revision 16127)
@@ -1,3 +1,29 @@
+Mon Apr 21 16:06:47 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* enumerator.c (enumerator_init): preserve the method name in ID.
+
+	* enumerator.c (enumerator_each): need not to call rb_to_id().
+
+	* enumerator.c (enumerator_with_index): ditto.
+
+Mon Apr 21 17:19:52 2008  Akinori MUSHA  <knu@i...>
+
+	* eval.c (rb_f_method_name): New gloval function: __method__;
+	  backported from matzruby / 1.9.
+
+	* eval.c (rb_frame_this_func), intern.h: New internal function.
+
+	* intern.h (RETURN_ENUMERATOR): Use rb_frame_this_func() instead
+	  of rb_frame_last_func(), to accommodate the behavior to that of
+	  1.9.
+
+Mon Apr 21 15:54:48 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* lib/tempfile.rb (Tempfile::_close): check @data before modifying
+	  it; backported from 1.9.  [ruby-dev:34094]
+
+	* lib/tempfile.rb (Tempfile::close): clear @data and @tmpname.
+
 Mon Apr 21 10:17:17 2008  NAKAMURA Usaku  <usa@r...>
 
 	* time.c: should include <errno.h> to refer errno.
Index: ruby_1_8_7/enumerator.c
===================================================================
--- ruby_1_8_7/enumerator.c	(revision 16126)
+++ ruby_1_8_7/enumerator.c	(revision 16127)
@@ -38,7 +38,7 @@
 
 struct enumerator {
     VALUE obj;
-    VALUE meth;
+    ID    meth;
     VALUE proc;
     VALUE args;
     rb_block_call_func *iter;
@@ -51,7 +51,6 @@
 {
     struct enumerator *ptr = p;
     rb_gc_mark(ptr->obj);
-    rb_gc_mark(ptr->meth);
     rb_gc_mark(ptr->proc);
     rb_gc_mark(ptr->args);
 }
@@ -258,7 +257,7 @@
     struct enumerator *ptr = enumerator_ptr(enum_obj);
 
     ptr->obj  = obj;
-    ptr->meth = meth;
+    ptr->meth = rb_to_id(meth);
     if (rb_block_given_p()) {
 	ptr->proc = rb_block_proc();
 	ptr->iter = enumerator_iter_i;
@@ -357,7 +356,7 @@
 	argc = RARRAY_LEN(e->args);
 	argv = RARRAY_PTR(e->args);
     }
-    return rb_block_call(e->obj, rb_to_id(e->meth), argc, argv, e->iter, (VALUE)e);
+    return rb_block_call(e->obj, e->meth, argc, argv, e->iter, (VALUE)e);
 }
 
 static VALUE
@@ -393,7 +392,7 @@
 	argc = RARRAY_LEN(e->args);
 	argv = RARRAY_PTR(e->args);
     }
-    return rb_block_call(e->obj, rb_to_id(e->meth), argc, argv,
+    return rb_block_call(e->obj, e->meth, argc, argv,
 			 enumerator_with_index_i, (VALUE)&memo);
 }
 
Index: ruby_1_8_7/lib/tempfile.rb
===================================================================
--- ruby_1_8_7/lib/tempfile.rb	(revision 16126)
+++ ruby_1_8_7/lib/tempfile.rb	(revision 16127)
@@ -95,7 +95,8 @@
 
   def _close	# :nodoc:
     @tmpfile.close if @tmpfile
-    @data[1] = @tmpfile = nil
+    @tmpfile = nil
+    @data[1] = nil if @data
   end    
   protected :_close
 
@@ -117,6 +118,7 @@
     _close
     @clean_proc.call
     ObjectSpace.undefine_finalizer(self)
+    @data = @tmpname = nil
   end
 
   # Unlinks the file.  On UNIX-like systems, it is often a good idea
Index: ruby_1_8_7/eval.c
===================================================================
--- ruby_1_8_7/eval.c	(revision 16126)
+++ ruby_1_8_7/eval.c	(revision 16127)
@@ -6407,6 +6407,12 @@
     return ruby_frame->last_func;
 }
 
+ID
+rb_frame_this_func()
+{
+    return ruby_frame->orig_func;
+}
+
 static NODE*
 compile(src, file, line)
     VALUE src;
@@ -7990,6 +7996,37 @@
     ruby_safe_level = safe;
 }
 
+/*
+ *  call-seq:
+ *     __method__         => symbol
+ *  
+ *  Returns the name of the current method as a Symbol.
+ *  If called from inside of an aliased method it will return the original
+ *  nonaliased name.
+ *  If called outside of a method, it returns <code>nil</code>.
+ *  
+ *    def foo
+ *      __method__
+ *    end
+ *    alias bar foo
+ *    
+ *    foo                # => :foo
+ *    bar                # => :foo
+ *
+ */
+
+static VALUE
+rb_f_method_name()
+{
+    struct FRAME* prev = ruby_frame->prev;
+    if (prev && prev->orig_func) {
+	return ID2SYM(prev->orig_func);
+    }
+    else {
+	return Qnil;
+    }
+}
+
 void
 Init_eval()
 {
@@ -8046,6 +8083,8 @@
     rb_define_global_function("global_variables", rb_f_global_variables, 0); /* in variable.c */
     rb_define_global_function("local_variables", rb_f_local_variables, 0);
 
+    rb_define_global_function("__method__", rb_f_method_name, 0);
+
     rb_define_method(rb_mKernel, "send", rb_f_send, -1);
     rb_define_method(rb_mKernel, "__send__", rb_f_send, -1);
     rb_define_method(rb_mKernel, "instance_eval", rb_obj_instance_eval, -1);

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

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