Permalink
Browse files

Merge from ruby_1_8.

git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_7@16127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
knu committed Apr 21, 2008
1 parent b5d283b commit 10899ae9d16e5f4b7a32984db3a8ecb4e8e9a61c
Showing with 79 additions and 7 deletions.
  1. +26 −0 ChangeLog
  2. +5 −0 NEWS
  3. +4 −5 enumerator.c
  4. +39 −0 eval.c
  5. +2 −1 intern.h
  6. +3 −1 lib/tempfile.rb
View
@@ -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.
View
5 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
View
@@ -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);
}
View
39 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);
View
@@ -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));
View
@@ -95,7 +95,8 @@ def open
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 @@ def close!
_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

0 comments on commit 10899ae

Please sign in to comment.