summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog26
-rw-r--r--NEWS5
-rw-r--r--enumerator.c9
-rw-r--r--eval.c39
-rw-r--r--intern.h3
-rw-r--r--lib/tempfile.rb4
6 files changed, 79 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 1fc6d18a87..22ae3367d4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+Mon Apr 21 16:06:47 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * 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@iDaemons.org>
+
+ * 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@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* time.c: should include <errno.h> to refer errno.
diff --git a/NEWS b/NEWS
index 8da2f5db1b..0a8fe6836b 100644
--- a/NEWS
+++ b/NEWS
@@ -232,6 +232,11 @@ with all sufficient information, see the ChangeLog file.
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
diff --git a/enumerator.c b/enumerator.c
index 6702bca1cd..4a5e88f6ac 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -38,7 +38,7 @@ proc_call(proc, args)
struct enumerator {
VALUE obj;
- VALUE meth;
+ ID meth;
VALUE proc;
VALUE args;
rb_block_call_func *iter;
@@ -51,7 +51,6 @@ enumerator_mark(p)
{
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 @@ enumerator_init(enum_obj, obj, meth, argc, argv)
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 @@ enumerator_each(obj)
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 @@ enumerator_with_index(obj)
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);
}
diff --git a/eval.c b/eval.c
index 7b2b929bd2..e439768090 100644
--- a/eval.c
+++ b/eval.c
@@ -6407,6 +6407,12 @@ rb_frame_last_func()
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 @@ rb_exec_end_proc()
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 @@ Init_eval()
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);
diff --git a/intern.h b/intern.h
index f4f5b56aca..abf6752311 100644
--- a/intern.h
+++ b/intern.h
@@ -133,7 +133,7 @@ VALUE rb_block_call _((VALUE, ID, int, VALUE*, VALUE (*)(ANYARGS), VALUE));
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 @@ void rb_interrupt _((void));
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));
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index f87c5fd394..c984cd3393 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -95,7 +95,8 @@ class Tempfile < DelegateClass(File)
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 @@ class Tempfile < DelegateClass(File)
_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