diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-10-01 23:37:02 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-10-01 23:37:02 +0000 |
commit | 209b950f3f92b8f7734a9b1456afedf7b5280b51 (patch) | |
tree | cf4b72fc0dace30dcc68e9f91880b834e2d5525c /array.c | |
parent | 04bc87e582ec83f56f3375724ef7370e53a914cd (diff) | |
download | ruby-209b950f3f92b8f7734a9b1456afedf7b5280b51.tar.gz |
* array.c (rb_ary_permutation): small dirty hack by Matz to avoid
arrays on stack.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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 */ |