-#if LOG_GIANT_STACK
-#define gstackDbg(x) printf x
-#else // LOG_GIANT_STACK
-#define gstackDbg(x)
-#endif // LOG_GIANT_STACK
-
-typedef struct {
- unsigned numDigits; // capacity of giants in this stack
- unsigned numFree; // number of free giants in stack
- unsigned totalGiants; // total number in *stack
- giant *stack;
-} gstack;
-
-static gstack *gstacks = NULL; // array of stacks
-static unsigned numGstacks = 0; // # of elements in gstacks
-static int gstackInitd = 0; // this module has been init'd
-
-#define INIT_NUM_GIANTS 16 /* initial # of giants / stack */
-#define MIN_GIANT_SIZE 4 /* numDigits for gstack[0] */
-#define GIANT_SIZE_INCR 2 /* in << bits */
-
-/*
- * Initialize giant stacks, with up to specified max giant size.
- */
-void initGiantStacks(unsigned maxDigits)
-{
- unsigned curSize = MIN_GIANT_SIZE;
- unsigned sz;
- unsigned i;
-
- dblog0("initGiantStacks\n");
-
- if(gstackInitd) {
- /*
- * Shouldn't be called more than once...
- */
- printf("multiple initGiantStacks calls\n");
- return;
- }
- gstackDbg(("initGiantStacks(%d)\n", maxDigits));
-
- /*
- * How many stacks?
- */
- numGstacks = 1;
- while(curSize<=maxDigits) {
- curSize <<= GIANT_SIZE_INCR;
- numGstacks++;
- }
-
- sz = sizeof(gstack) * numGstacks;
- gstacks = (gstack*) fmalloc(sz);
- bzero(gstacks, sz);
-
- curSize = MIN_GIANT_SIZE;
- for(i=0; i<numGstacks; i++) {
- gstacks[i].numDigits = curSize;
- curSize <<= GIANT_SIZE_INCR;
- }
-
- gstackInitd = 1;
-}
-
-/* called at shut down - free resources */
-void freeGiantStacks(void)
-{
- int i;
- int j;
- gstack *gs;
-
- if(!gstackInitd) {
- return;
- }
- for(i=0; i<numGstacks; i++) {
- gs = &gstacks[i];
- for(j=0; j<gs->numFree; j++) {
- freeGiant(gs->stack[j]);
- gs->stack[j] = NULL;
- }
- /* and the stack itself - may be null if this was never used */
- if(gs->stack != NULL) {
- ffree(gs->stack);
- gs->stack = NULL;
- }
- }
- ffree(gstacks);
- gstacks = NULL;
- gstackInitd = 0;
-}
-
-#endif // GIANTS_VIA_STACK