summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-08 15:32:09 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-08 15:32:09 +0000
commit7ad4bd137d004ef4db69cc0b45d93ddd8d417b5f (patch)
tree1dea87beba2a67d9afa0bef1f8a5ff8ebcb0de9d
parent208ec9936afe059ff064d66ac05a20303022ad79 (diff)
merges r24364 from trunk into ruby_1_9_1.
-- * array.c (rb_ary_{permutation,combination}): disallow reentrance with continuation since work-buffers cannot restore. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@24459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--array.c10
-rw-r--r--version.h2
3 files changed, 13 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 7f3f168ca4..cc31f9edf1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
-Mon Aug 3 13:05:22 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Aug 3 15:48:40 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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.
diff --git a/array.c b/array.c
index 14b2f7c0c3..19edf851da 100644
--- a/array.c
+++ b/array.c
@@ -3401,6 +3401,7 @@ rb_ary_cycle(int argc, VALUE *argv, VALUE ary)
}
#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 @@ permute0(long n, long r, long *p, long index, int *used, VALUE values)
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 @@ rb_ary_combination(VALUE ary, VALUE num)
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 @@ rb_ary_combination(VALUE ary, VALUE num)
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));
diff --git a/version.h b/version.h
index 8cdb9da5b7..497ae013a1 100644
--- a/version.h
+++ b/version.h
@@ -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