ruby-changes:12752
From: yugui <ko1@a...>
Date: Sun, 9 Aug 2009 15:52:54 +0900 (JST)
Subject: [ruby-changes:12752] Ruby:r24459 (ruby_1_9_1): merges r24364 from trunk into ruby_1_9_1.
yugui 2009-08-09 00:32:09 +0900 (Sun, 09 Aug 2009) New Revision: 24459 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24459 Log: merges r24364 from trunk into ruby_1_9_1. -- * array.c (rb_ary_{permutation,combination}): disallow reentrance with continuation since work-buffers cannot restore. Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/array.c branches/ruby_1_9_1/version.h Index: ruby_1_9_1/array.c =================================================================== --- ruby_1_9_1/array.c (revision 24458) +++ ruby_1_9_1/array.c (revision 24459) @@ -3401,6 +3401,7 @@ } #define tmpbuf(n, size) rb_str_tmp_new((n)*(size)) +#define tmpary(n) rb_ary_tmp_new(n) /* * Recursively compute permutations of r elements of the set [0..n-1]. @@ -3438,6 +3439,9 @@ for (j = 0; j < r; j++) result_array[j] = values_array[p[j]]; ARY_SET_LEN(result, r); rb_yield(result); + if (RBASIC(values)->klass) { + rb_raise(rb_eRuntimeError, "permute reentered"); + } } } } @@ -3576,11 +3580,10 @@ volatile VALUE t0 = tmpbuf(n+1, sizeof(long)); long *stack = (long*)RSTRING_PTR(t0); long nlen = combi_len(len, n); - volatile VALUE cc = rb_ary_new2(n); + volatile VALUE cc = tmpary(n); VALUE *chosen = RARRAY_PTR(cc); long lev = 0; - RBASIC(cc)->klass = 0; MEMZERO(stack, long, n); stack[0] = -1; for (i = 0; i < nlen; i++) { @@ -3589,6 +3592,9 @@ chosen[lev] = RARRAY_PTR(ary)[stack[lev+1] = stack[lev]+1]; } rb_yield(rb_ary_new4(n, chosen)); + if (RBASIC(t0)->klass) { + rb_raise(rb_eRuntimeError, "combination reentered"); + } do { stack[lev--]++; } while (lev && (stack[lev+1]+n == len+lev+1)); Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 24458) +++ ruby_1_9_1/ChangeLog (revision 24459) @@ -1,5 +1,8 @@ -Mon Aug 3 13:05:22 2009 Nobuyoshi Nakada <nobu@r...> +Mon Aug 3 15:48:40 2009 Nobuyoshi Nakada <nobu@r...> + * array.c (rb_ary_{permutation,combination}): disallow reentrance + with continuation since work-buffers cannot restore. + * array.c (rb_ary_{permutation,combination,product}): must not use ary_discard on strings. Index: ruby_1_9_1/version.h =================================================================== --- ruby_1_9_1/version.h (revision 24458) +++ ruby_1_9_1/version.h (revision 24459) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.1" -#define RUBY_PATCHLEVEL 263 +#define RUBY_PATCHLEVEL 264 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/