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

ruby-changes:18498

From: akr <ko1@a...>
Date: Wed, 12 Jan 2011 19:27:57 +0900 (JST)
Subject: [ruby-changes:18498] Ruby:r30521 (trunk): * enum.c (sort_by_i): reenter check more strictly.

akr	2011-01-12 19:27:48 +0900 (Wed, 12 Jan 2011)

  New Revision: 30521

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

  Log:
    * enum.c (sort_by_i): reenter check more strictly.
      (sort_by_cmp): ditto.
      [ruby-dev:43003] reported by Usaku NAKAMURA.

  Modified files:
    trunk/ChangeLog
    trunk/enum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30520)
+++ ChangeLog	(revision 30521)
@@ -1,3 +1,9 @@
+Wed Jan 12 19:09:29 2011  Tanaka Akira  <akr@f...>
+
+	* enum.c (sort_by_i): reenter check more strictly.
+	  (sort_by_cmp): ditto.
+	  [ruby-dev:43003] reported by Usaku NAKAMURA.
+
 Wed Jan 12 16:25:12 2011  Yuki Sonoda (Yugui)  <yugui@y...>
 
 	* lib/net/http.rb (Net::HTTP#connect): makes it timeout during 
Index: enum.c
===================================================================
--- enum.c	(revision 30520)
+++ enum.c	(revision 30521)
@@ -782,14 +782,20 @@
 {
     struct sort_by_data *data = (struct sort_by_data *)_data;
     VALUE ary = data->ary;
+    VALUE v;
 
     ENUM_WANT_SVALUE();
 
+    v = rb_yield(i);
+
     if (RBASIC(ary)->klass) {
 	rb_raise(rb_eRuntimeError, "sort_by reentered");
     }
-    
-    RARRAY_PTR(data->buf)[data->n*2] = rb_yield(i);
+    if (RARRAY_LEN(data->buf) != SORT_BY_BUFSIZE*2) {
+	rb_raise(rb_eRuntimeError, "sort_by reentered");
+    }
+
+    RARRAY_PTR(data->buf)[data->n*2] = v;
     RARRAY_PTR(data->buf)[data->n*2+1] = i;
     data->n++;
     if (data->n == SORT_BY_BUFSIZE) {
@@ -802,13 +808,17 @@
 static int
 sort_by_cmp(const void *ap, const void *bp, void *data)
 {
-    VALUE a = *(VALUE *)ap;
-    VALUE b = *(VALUE *)bp;
+    VALUE a;
+    VALUE b;
     VALUE ary = (VALUE)data;
 
     if (RBASIC(ary)->klass) {
 	rb_raise(rb_eRuntimeError, "sort_by reentered");
     }
+
+    a = *(VALUE *)ap;
+    b = *(VALUE *)bp;
+
     return rb_cmpint(rb_funcall(a, id_cmp, 1, b), a, b);
 }
 

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

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