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

ruby-changes:2134

From: ko1@a...
Date: 4 Oct 2007 20:18:43 +0900
Subject: [ruby-changes:2134] usa - Ruby:r13625 (trunk): * array.c (rb_ary_permutation, rb_ary_product): support non C99

usa	2007-10-04 20:18:14 +0900 (Thu, 04 Oct 2007)

  New Revision: 13625

  Modified files:
    trunk/ChangeLog
    trunk/array.c

  Log:
    * array.c (rb_ary_permutation, rb_ary_product): support non C99
      compilers.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/array.c?r1=13625&r2=13624
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13625&r2=13624

Index: array.c
===================================================================
--- array.c	(revision 13624)
+++ array.c	(revision 13625)
@@ -3037,11 +3037,11 @@
 	}
     }
     else {             /* this is the general case */
-	ary = rb_ary_dup(ary); /* private defensive copy of ary */
 	volatile VALUE t0 = rb_str_new(0, n*sizeof(long));
 	long *p = (long*)RSTRING_PTR(t0); /* array indexes of current permutation */
 	volatile VALUE t1 = rb_str_new(0, n*sizeof(int));
 	int *used = (int*)RSTRING_PTR(t1); /* booleans: which indexes are already used */
+	ary = rb_ary_dup(ary); /* private defensive copy of ary */
 
 	for(i = 0; i < n; i++) used[i] = 0; /* initialize array */
 
@@ -3158,6 +3158,7 @@
     int *counters = (int*)RSTRING_PTR(t1); /* The current position in each one */
     VALUE result;      /* The array we'll be returning */
     long i,j;
+    long resultlen = 1;
 
     /* initialize the arrays of arrays */
     arrays[0] = ary;
@@ -3167,7 +3168,6 @@
     for(i = 0; i < n; i++) counters[i] = 0;
 
     /* Compute the length of the result array; return [] if any is empty */
-    long resultlen = 1;
     for(i = 0; i < n; i++) {
 	resultlen *= RARRAY_LEN(arrays[i]);
 	if (resultlen == 0) return rb_ary_new2(0);
@@ -3176,6 +3176,7 @@
     /* Otherwise, allocate and fill in an array of results */
     result = rb_ary_new2(resultlen);
     for(i = 0; i < resultlen; i++) {
+	int m;
 	/* fill in one subarray */
 	VALUE subarray = rb_ary_new2(n);
 	for(j = 0; j < n; j++) {
@@ -3189,7 +3190,7 @@
 	 * Increment the last counter.  If it overflows, reset to 0
 	 * and increment the one before it.
 	 */
-	int m = n-1;
+	m = n-1;
 	counters[m]++;
 	while(m >= 0 && counters[m] == RARRAY_LEN(arrays[m])) {
 	    counters[m] = 0;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 13624)
+++ ChangeLog	(revision 13625)
@@ -1,3 +1,8 @@
+Thu Oct  4 20:17:19 2007  NAKAMURA Usaku  <usa@r...>
+
+	* array.c (rb_ary_permutation, rb_ary_product): support non C99
+	  compilers.
+
 Thu Oct  4 17:33:18 2007  Yukihiro Matsumoto  <matz@r...>
 
 	* re.c (kcode_setter): Perl-ish global variable `$=' no longer

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

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