Permalink
Browse files

Merge from ruby_1_8.

git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_7@16166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 10899ae commit 64ad39d5be44f5bbb2c3bc72376e5686e0eb25bc @knu knu committed Apr 22, 2008
Showing with 143 additions and 25 deletions.
  1. +52 −0 ChangeLog
  2. +10 −0 NEWS
  3. +1 −9 enumerator.c
  4. +14 −5 eval.c
  5. +2 −2 file.c
  6. +0 −1 intern.h
  7. +41 −4 object.c
  8. +4 −0 regex.c
  9. +1 −1 sprintf.c
  10. +15 −0 test/ruby/test_symbol.rb
  11. +3 −3 version.h
View
@@ -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.
View
@@ -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
View
@@ -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;
View
@@ -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;
}
View
@@ -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
View
@@ -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*));
View
@@ -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);
View
@@ -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) {
View
@@ -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) {
@@ -74,4 +74,19 @@ def test_inspect_number
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
View
@@ -1,15 +1,15 @@
#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
#define RUBY_VERSION_MINOR 8
#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[];

0 comments on commit 64ad39d

Please sign in to comment.