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

ruby-changes:22987

From: nobu <ko1@a...>
Date: Thu, 15 Mar 2012 15:19:53 +0900 (JST)
Subject: [ruby-changes:22987] nobu:r35036 (trunk): * enumerator.c (lazy_cycle): check argument number overflow before

nobu	2012-03-15 15:19:42 +0900 (Thu, 15 Mar 2012)

  New Revision: 35036

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35036

  Log:
    * enumerator.c (lazy_cycle): check argument number overflow before
      creating temporary array.

  Modified files:
    trunk/ChangeLog
    trunk/enumerator.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35035)
+++ ChangeLog	(revision 35036)
@@ -1,3 +1,8 @@
+Thu Mar 15 15:19:38 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* enumerator.c (lazy_cycle): check argument number overflow before
+	  creating temporary array.
+
 Thu Mar 15 15:04:54 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* util.c (ruby_strtod): no need to check same digit for hexdigit
Index: enumerator.c
===================================================================
--- enumerator.c	(revision 35035)
+++ enumerator.c	(revision 35036)
@@ -106,7 +106,7 @@
 VALUE rb_cLazy;
 static ID id_rewind, id_each, id_new, id_initialize, id_yield, id_call;
 static ID id_eqq, id_next, id_result, id_lazy;
-static VALUE sym_each;
+static VALUE sym_each, sym_cycle;
 
 VALUE rb_eStopIteration;
 
@@ -1526,17 +1526,17 @@
 lazy_cycle(int argc, VALUE *argv, VALUE obj)
 {
     VALUE args;
-    int i;
+    int len = rb_long2int((long)argc + 2);
 
-    args = rb_ary_new2(argc + 1);
+    args = rb_ary_tmp_new(len);
     rb_ary_push(args, obj);
-    rb_ary_push(args, ID2SYM(rb_intern("cycle")));
-    for (i = 0; i < argc; i++) {
-	rb_ary_push(args, argv[i]);
+    rb_ary_push(args, sym_cycle);
+    if (argc > 0) {
+	rb_ary_cat(args, argv, argc);
     }
-    return rb_block_call(rb_cLazy, id_new, RARRAY_LEN(args), RARRAY_PTR(args),
+    return rb_block_call(rb_cLazy, id_new, len, RARRAY_PTR(args),
 			 rb_block_given_p() ? lazy_map_func : lazy_cycle_func,
-			 0);
+			 args /* prevent from GC */);
 }
 
 static VALUE
@@ -1680,6 +1680,7 @@
     id_lazy = rb_intern("lazy");
     id_eqq = rb_intern("===");
     sym_each = ID2SYM(id_each);
+    sym_cycle = ID2SYM(rb_intern("cycle"));
 
     InitVM(Enumerator);
 }

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

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