aboutsummaryrefslogtreecommitdiffstats
path: root/array.c
diff options
context:
space:
mode:
Diffstat (limited to 'array.c')
-rw-r--r--array.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/array.c b/array.c
index 93a95d96e8..801f2e6c2d 100644
--- a/array.c
+++ b/array.c
@@ -3036,8 +3036,11 @@ rb_ary_permutation(VALUE ary, VALUE num)
}
else { /* this is the general case */
ary = rb_ary_dup(ary); /* private defensive copy of ary */
- long p[n];
- int used[n];
+ 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 */
+
for(i = 0; i < n; i++) used[i] = 0; /* initialize array */
permute0(n,r,p,0,used,ary); /* compute and yield permutations */