avoid allocating huge data structures on the stack
authorTony Cook <tony@develop=help.com>
Tue, 11 Dec 2001 12:28:36 +0000 (12:28 +0000)
committerTony Cook <tony@develop=help.com>
Tue, 11 Dec 2001 12:28:36 +0000 (12:28 +0000)
Changes
quant.c

diff --git a/Changes b/Changes
index cd403170acb33a09940d5481f1f80a49b3424942..e4d7f66dc7564ecaf0a6bf7bee7b0a4eaa8def49 100644 (file)
--- a/Changes
+++ b/Changes
@@ -561,6 +561,8 @@ Revision history for Perl extension Imager.
         - freetype 2 bounding box function didn't know UTF8 (doh!)
         - write paletted images as paletted to tiff
        - initialize counter for packing 4 bit data
+        - don't allocate hashboxes as locals since it overflows the 
+         stack by default in Darwin
 
 =================================================================
 
diff --git a/quant.c b/quant.c
index 40a54a7152295adf5f05ab214e819a187f05e75b..b80c0538e7460d0b366b44c2607f06d8d1345e5f 100644 (file)
--- a/quant.c
+++ b/quant.c
@@ -376,9 +376,10 @@ makemap_addi(i_quantize *quant, i_img **imgs, int count) {
   int cnum, i, x, y, bst_idx=0, ld, cd, iter, currhb, img_num;
   i_color val;
   float dlt, accerr;
-  hashbox hb[512];
+  hashbox *hb;
 
   clr = (cvec *)mymalloc(sizeof(cvec) * quant->mc_size);
+  hb = mymalloc(sizeof(hashbox) * 512);
   for (i=0; i < quant->mc_count; ++i) {
     clr[i].r = quant->mc_colors[i].rgb.r;
     clr[i].g = quant->mc_colors[i].rgb.g;
@@ -492,6 +493,7 @@ makemap_addi(i_quantize *quant, i_img **imgs, int count) {
 #endif
 
   /* don't want to keep this */
+  myfree(hb);
   myfree(clr);
 }
 
@@ -542,7 +544,7 @@ makemap_addi(i_quantize *quant, i_img **imgs, int count) {
 #define HB_SORT
 
 /* assume i is available */
-#define CF_VARS hashbox hb[512]; \
+#define CF_VARS hashbox *hb = mymalloc(sizeof(hashbox) * 512); \
                int currhb;  \
                long ld, cd
 
@@ -642,7 +644,7 @@ static void hbsetup(i_quantize *quant, hashbox *hb) {
     if (cd < ld) { ld = cd; bst_idx = hb[currhb].vec[i]; } \
   }
 
-#define CF_CLEANUP
+#define CF_CLEANUP myfree(hb)
   
 #endif