ruby-changes:2100
From: ko1@a...
Date: 2 Oct 2007 08:37:12 +0900
Subject: [ruby-changes:2100] matz -  Ruby:r13591 (trunk): * array.c (rb_ary_permutation): small dirty hack by Matz to avoid
matz	2007-10-02 08:37:02 +0900 (Tue, 02 Oct 2007)
  New Revision: 13591
  Modified files:
    trunk/ChangeLog
    trunk/array.c
  Log:
    * array.c (rb_ary_permutation): small dirty hack by Matz to avoid
      arrays on stack.
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/array.c?r1=13591&r2=13590
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13591&r2=13590
Index: array.c
===================================================================
--- array.c	(revision 13590)
+++ array.c	(revision 13591)
@@ -3036,8 +3036,11 @@
     }
     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 */
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 13590)
+++ ChangeLog	(revision 13591)
@@ -6,6 +6,9 @@
 	* array.c (rb_ary_combination): RDoc update to clarify.  a patch
 	  from David Flanagan.  [ruby-core:12344]
 
+	* array.c (rb_ary_permutation): small dirty hack by Matz to avoid
+	  arrays on stack.
+
 Tue Oct  2 07:01:05 2007  Koichi Sasada  <ko1@a...>
 
 	* proc.c (proc_dup): proc->block.proc should be self.
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml