From b618f011b7820d64c533c8d8e9fb99cc7bec121e Mon Sep 17 00:00:00 2001 From: usa Date: Thu, 4 Oct 2007 11:18:14 +0000 Subject: [PATCH] * array.c (rb_ary_permutation, rb_ary_product): support non C99 compilers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ array.c | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index dfb82b2f24..daabfc5e8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Oct 4 20:17:19 2007 NAKAMURA Usaku + + * array.c (rb_ary_permutation, rb_ary_product): support non C99 + compilers. + Thu Oct 4 17:33:18 2007 Yukihiro Matsumoto * re.c (kcode_setter): Perl-ish global variable `$=' no longer diff --git a/array.c b/array.c index a75def20b8..d6af269009 100644 --- a/array.c +++ b/array.c @@ -3037,11 +3037,11 @@ rb_ary_permutation(VALUE ary, VALUE num) } } 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 @@ rb_ary_product(int argc, VALUE *argv, VALUE ary) 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 @@ rb_ary_product(int argc, VALUE *argv, VALUE ary) 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 @@ rb_ary_product(int argc, VALUE *argv, VALUE ary) /* 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 @@ rb_ary_product(int argc, VALUE *argv, VALUE ary) * 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;