summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-22 17:29:39 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-22 17:29:39 +0000
commita47dfe276352f2c02aa96341cb0a37ce7d5b4b69 (patch)
tree65e334506c36d6028a4aa82afb680191d268e8c3
parent7f6df101caca14f3bc68226ff33b7301ffbe6d74 (diff)
Merge from ruby_1_8.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@16166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog52
-rw-r--r--NEWS10
-rw-r--r--enumerator.c10
-rw-r--r--eval.c19
-rw-r--r--file.c4
-rw-r--r--intern.h1
-rw-r--r--object.c45
-rw-r--r--regex.c4
-rw-r--r--sprintf.c2
-rw-r--r--test/ruby/test_symbol.rb15
-rw-r--r--version.h6
11 files changed, 143 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index 22ae3367d4..e231fc7d13 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,55 @@
+Wed Apr 23 00:42:49 2008 Tanaka Akira <akr@fsij.org>
+
+ * eval.c (error_print): show full stack grace except SystemStackError.
+ backport from 1.9. [ruby-dev:31014]
+
+Wed Apr 23 00:18:45 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
+
+ * test/ruby/test_symbol.rb (TestSymbol#test_to_proc): Improve
+ tests of Symbol#to_proc.
+
+Tue Apr 22 22:43:05 2008 Akinori MUSHA <knu@iDaemons.org>
+
+ * eval.c (rb_proc_new, YIELD_FUNC_LAMBDA): Add a new nd_state
+ YIELD_FUNC_LAMBDA which avoids automatic `avalue' conversion for
+ arguments. This fixes a bug where [1,[2,3]].map(&:object_id)
+ fails.
+
+ * intern.h, object.c: Hide rb_proc_new() from intern.h. It should
+ not be considered an official API function yet.
+
+Tue Apr 22 21:24:32 2008 Akinori MUSHA <knu@iDaemons.org>
+
+ * eval.c (rb_proc_new): Turn the BLOCK_LAMBDA flag on.
+
+ * object.c (sym_to_proc), test/ruby/test_symbol.rb: Add back
+ Symbol#to_proc, now that it passes the tests.
+
+Tue Apr 22 19:35:03 2008 Akinori MUSHA <knu@iDaemons.org>
+
+ * enumerator.c (enumerator_initialize): Remove an undocumented
+ feature (passing a block to the constructor) that's broken.
+ This is not what I intended.
+
+Tue Apr 22 17:49:46 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * sprintf.c (rb_f_sprintf): should protect temporary string from
+ GC. [ruby-dev:34480]
+
+Tue Apr 22 17:12:05 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * regex.c (re_search): string might be NULL. [ruby-core:16478]
+
+Tue Apr 22 16:44:00 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
+
+ * object.c (rb_obj_tap): Correct documentation; pointed out by
+ okkez in [ruby-dev:34472].
+
+Tue Apr 22 10:05:51 2008 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * file.c (eaccess): workaround for recent msvcrt's behavior.
+ [ruby-core:16460]
+
Mon Apr 21 16:06:47 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* enumerator.c (enumerator_init): preserve the method name in ID.
diff --git a/NEWS b/NEWS
index 0a8fe6836b..568debf36c 100644
--- a/NEWS
+++ b/NEWS
@@ -232,6 +232,10 @@ with all sufficient information, see the ChangeLog file.
Return an enumerator if no block is given.
+ * Symbol#to_proc
+
+ New method.
+
* __method__
New global function that returns the name of the current method as
@@ -335,6 +339,12 @@ with all sufficient information, see the ChangeLog file.
* content:encoded with RSS 2.0 support
+=== Interpreter Implementation
+
+* stack trace
+
+ On non-SystemStackError exception, full stack trace is shown.
+
=== Compatibility issues (excluding feature bug fixes)
* tempfile
diff --git a/enumerator.c b/enumerator.c
index 4a5e88f6ac..2cb3ca01e3 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -51,7 +51,6 @@ enumerator_mark(p)
{
struct enumerator *ptr = p;
rb_gc_mark(ptr->obj);
- rb_gc_mark(ptr->proc);
rb_gc_mark(ptr->args);
}
@@ -258,13 +257,7 @@ enumerator_init(enum_obj, obj, meth, argc, argv)
ptr->obj = obj;
ptr->meth = rb_to_id(meth);
- if (rb_block_given_p()) {
- ptr->proc = rb_block_proc();
- ptr->iter = enumerator_iter_i;
- }
- else {
- ptr->iter = enumerator_each_i;
- }
+ ptr->iter = enumerator_each_i;
if (argc) ptr->args = rb_ary_new4(argc, argv);
return enum_obj;
@@ -316,7 +309,6 @@ enumerator_init_copy(obj, orig)
ptr1->obj = ptr0->obj;
ptr1->meth = ptr0->meth;
- ptr1->proc = ptr0->proc;
ptr1->iter = ptr0->iter;
ptr1->args = ptr0->args;
diff --git a/eval.c b/eval.c
index e439768090..9994015cf5 100644
--- a/eval.c
+++ b/eval.c
@@ -1111,6 +1111,7 @@ static VALUE rb_yield_0 _((VALUE, VALUE, VALUE, int, int));
#define YIELD_PUBLIC_DEF 4
#define YIELD_FUNC_AVALUE 1
#define YIELD_FUNC_SVALUE 2
+#define YIELD_FUNC_LAMBDA 3
static VALUE rb_call _((VALUE,VALUE,ID,int,const VALUE*,int,VALUE));
static VALUE module_setup _((VALUE,NODE*));
@@ -1306,6 +1307,7 @@ error_print()
if (!NIL_P(errat)) {
long i;
struct RArray *ep = RARRAY(errat);
+ int truncate = eclass == rb_eSysStackError;
#define TRACE_MAX (TRACE_HEAD+TRACE_TAIL+5)
#define TRACE_HEAD 8
@@ -1316,7 +1318,7 @@ error_print()
if (TYPE(ep->ptr[i]) == T_STRING) {
warn_printf("\tfrom %s\n", RSTRING(ep->ptr[i])->ptr);
}
- if (i == TRACE_HEAD && ep->len > TRACE_MAX) {
+ if (truncate && i == TRACE_HEAD && ep->len > TRACE_MAX) {
warn_printf("\t ... %ld levels...\n",
ep->len - TRACE_HEAD - TRACE_TAIL);
i = ep->len - TRACE_TAIL;
@@ -5014,12 +5016,18 @@ rb_yield_0(val, self, klass, flags, avalue)
if ((state = EXEC_TAG()) == 0) {
redo:
if (nd_type(node) == NODE_CFUNC || nd_type(node) == NODE_IFUNC) {
- if (node->nd_state == YIELD_FUNC_AVALUE) {
+ switch (node->nd_state) {
+ case YIELD_FUNC_LAMBDA:
+ if (!avalue) {
+ val = rb_ary_new3(1, val);
+ }
+ break;
+ case YIELD_FUNC_AVALUE:
if (!avalue) {
val = svalue_to_avalue(val);
}
- }
- else {
+ break;
+ default:
if (avalue) {
val = avalue_to_svalue(val);
}
@@ -9635,7 +9643,8 @@ rb_proc_new(func, val)
VALUE proc = rb_iterate((VALUE(*)_((VALUE)))mproc, 0, func, val);
Data_Get_Struct(proc, struct BLOCK, data);
- data->body->nd_state = YIELD_FUNC_AVALUE;
+ data->body->nd_state = YIELD_FUNC_LAMBDA;
+ data->flags |= BLOCK_LAMBDA;
return proc;
}
diff --git a/file.c b/file.c
index bde7f07a1d..cc2ccd3c33 100644
--- a/file.c
+++ b/file.c
@@ -891,8 +891,8 @@ eaccess(path, mode)
return -1;
#else
-# if _MSC_VER >= 1400
- mode &= 6;
+# if defined(_MSC_VER) || defined(__MINGW32__)
+ mode &= ~1;
# endif
return access(path, mode);
#endif
diff --git a/intern.h b/intern.h
index abf6752311..a676720530 100644
--- a/intern.h
+++ b/intern.h
@@ -194,7 +194,6 @@ void rb_obj_call_init _((VALUE, int, VALUE*));
VALUE rb_class_new_instance _((int, VALUE*, VALUE));
VALUE rb_block_proc _((void));
VALUE rb_f_lambda _((void));
-VALUE rb_proc_new _((VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE));
VALUE rb_proc_call _((VALUE, VALUE));
VALUE rb_obj_method _((VALUE, VALUE));
VALUE rb_protect _((VALUE (*)(VALUE), VALUE, int*));
diff --git a/object.c b/object.c
index c644b85a45..d45934b877 100644
--- a/object.c
+++ b/object.c
@@ -502,10 +502,15 @@ rb_obj_is_kind_of(obj, c)
* The primary purpose of this method is to "tap into" a method chain,
* in order to perform operations on intermediate results within the chain.
*
- * (1..10) .tap {|x| puts "original: #{x.inspect}"}
- * .to_a .tap {|x| puts "array: #{x.inspect}"}
- * .select {|x| x%2==0} .tap {|x| puts "evens: #{x.inspect}"}
- * .map { |x| x*x } .tap {|x| puts "squares: #{x.inspect}"}
+ * (1..10).tap {
+ * |x| puts "original: #{x.inspect}"
+ * }.to_a.tap {
+ * |x| puts "array: #{x.inspect}"
+ * }.select {|x| x%2==0}.tap {
+ * |x| puts "evens: #{x.inspect}"
+ * }.map {|x| x*x}.tap {
+ * |x| puts "squares: #{x.inspect}"
+ * }
*
*/
@@ -1207,6 +1212,37 @@ sym_to_sym(sym)
}
+static VALUE
+sym_call(args, mid)
+ VALUE args, mid;
+{
+ VALUE obj;
+
+ if (RARRAY(args)->len < 1) {
+ rb_raise(rb_eArgError, "no receiver given");
+ }
+ obj = rb_ary_shift(args);
+ return rb_apply(obj, (ID)mid, args);
+}
+
+VALUE rb_proc_new _((VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE));
+
+/*
+ * call-seq:
+ * sym.to_proc
+ *
+ * Returns a _Proc_ object which respond to the given method by _sym_.
+ *
+ * (1..3).collect(&:to_s) #=> ["1", "2", "3"]
+ */
+
+static VALUE
+sym_to_proc(VALUE sym)
+{
+ return rb_proc_new(sym_call, (VALUE)SYM2ID(sym));
+}
+
+
/***********************************************************************
*
* Document-class: Module
@@ -2750,6 +2786,7 @@ Init_Object()
rb_define_method(rb_cSymbol, "to_s", sym_to_s, 0);
rb_define_method(rb_cSymbol, "id2name", sym_to_s, 0);
rb_define_method(rb_cSymbol, "to_sym", sym_to_sym, 0);
+ rb_define_method(rb_cSymbol, "to_proc", sym_to_proc, 0);
rb_define_method(rb_cSymbol, "===", rb_obj_equal, 1);
rb_define_method(rb_cModule, "freeze", rb_mod_freeze, 0);
diff --git a/regex.c b/regex.c
index a7a831286e..45f7e20738 100644
--- a/regex.c
+++ b/regex.c
@@ -3177,6 +3177,10 @@ re_search(bufp, string, size, startpos, range, regs)
/* Check for out-of-range starting position. */
if (startpos < 0 || startpos > size)
return -1;
+ if (!string) {
+ if (size == 0) string = "";
+ else return -1;
+ }
/* Update the fastmap now if not correct already. */
if (fastmap && !bufp->fastmap_accurate) {
diff --git a/sprintf.c b/sprintf.c
index e32c456b63..c5334b1f9f 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -471,7 +471,7 @@ rb_f_sprintf(argc, argv)
long v = 0;
int base, bignum = 0;
int len, pos;
- VALUE tmp;
+ volatile VALUE tmp;
volatile VALUE tmp1;
switch (*p) {
diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb
index 2ccfe64c92..42350ba6e7 100644
--- a/test/ruby/test_symbol.rb
+++ b/test/ruby/test_symbol.rb
@@ -74,4 +74,19 @@ class TestSymbol < Test::Unit::TestCase
assert_inspect_evaled(':$0')
assert_inspect_evaled(':$1')
end
+
+ def test_to_proc
+ assert_equal %w(1 2 3), (1..3).map(&:to_s)
+ [
+ [],
+ [1],
+ [1, 2],
+ [1, [2, 3]],
+ ].each do |ary|
+ ary_id = ary.object_id
+ assert_equal ary_id, :object_id.to_proc.call(ary)
+ ary_ids = ary.collect{|x| x.object_id }
+ assert_equal ary_ids, ary.collect(&:object_id)
+ end
+ end
end
diff --git a/version.h b/version.h
index c391a4506a..f51e4832f8 100644
--- a/version.h
+++ b/version.h
@@ -1,7 +1,7 @@
#define RUBY_VERSION "1.8.7"
-#define RUBY_RELEASE_DATE "2008-04-21"
+#define RUBY_RELEASE_DATE "2008-04-23"
#define RUBY_VERSION_CODE 187
-#define RUBY_RELEASE_CODE 20080421
+#define RUBY_RELEASE_CODE 20080423
#define RUBY_PATCHLEVEL 0
#define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
#define RUBY_VERSION_TEENY 7
#define RUBY_RELEASE_YEAR 2008
#define RUBY_RELEASE_MONTH 4
-#define RUBY_RELEASE_DAY 21
+#define RUBY_RELEASE_DAY 23
#ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[];