98 |
* #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n) |
* #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n) |
99 |
* if memory is available and otherwise does something you deem |
* if memory is available and otherwise does something you deem |
100 |
* appropriate. If MALLOC is undefined, malloc will be invoked |
* appropriate. If MALLOC is undefined, malloc will be invoked |
101 |
* directly -- and assumed always to succeed. |
* directly -- and assumed always to succeed. Similarly, if you |
102 |
|
* want something other than the system's free() to be called to |
103 |
|
* recycle memory acquired from MALLOC, #define FREE to be the |
104 |
|
* name of the alternate routine. (FREE or free is only called in |
105 |
|
* pathological cases, e.g., in a dtoa call after a dtoa return in |
106 |
|
* mode 3 with thousands of digits requested.) |
107 |
* #define Omit_Private_Memory to omit logic (added Jan. 1998) for making |
* #define Omit_Private_Memory to omit logic (added Jan. 1998) for making |
108 |
* memory allocations from a private pool of memory when possible. |
* memory allocations from a private pool of memory when possible. |
109 |
* When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes, |
* When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes, |
468 |
#define FREE_DTOA_LOCK(n) /*nothing*/ |
#define FREE_DTOA_LOCK(n) /*nothing*/ |
469 |
#endif |
#endif |
470 |
|
|
471 |
#define Kmax 15 |
#define Kmax 7 |
472 |
|
|
473 |
struct |
struct |
474 |
Bigint { |
Bigint { |
496 |
#endif |
#endif |
497 |
|
|
498 |
ACQUIRE_DTOA_LOCK(0); |
ACQUIRE_DTOA_LOCK(0); |
499 |
if ((rv = freelist[k])) { |
/* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */ |
500 |
|
/* but this case seems very unlikely. */ |
501 |
|
if (k <= Kmax && (rv = freelist[k])) |
502 |
freelist[k] = rv->next; |
freelist[k] = rv->next; |
|
} |
|
503 |
else { |
else { |
504 |
x = 1 << k; |
x = 1 << k; |
505 |
#ifdef Omit_Private_Memory |
#ifdef Omit_Private_Memory |
507 |
#else |
#else |
508 |
len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1) |
len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1) |
509 |
/sizeof(double); |
/sizeof(double); |
510 |
if (pmem_next - private_mem + len <= PRIVATE_mem) { |
if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) { |
511 |
rv = (Bigint*)pmem_next; |
rv = (Bigint*)pmem_next; |
512 |
pmem_next += len; |
pmem_next += len; |
513 |
} |
} |
531 |
#endif |
#endif |
532 |
{ |
{ |
533 |
if (v) { |
if (v) { |
534 |
ACQUIRE_DTOA_LOCK(0); |
if (v->k > Kmax) |
535 |
v->next = freelist[v->k]; |
#ifdef FREE |
536 |
freelist[v->k] = v; |
FREE((void*)v); |
537 |
FREE_DTOA_LOCK(0); |
#else |
538 |
|
free((void*)v); |
539 |
|
#endif |
540 |
|
else { |
541 |
|
ACQUIRE_DTOA_LOCK(0); |
542 |
|
v->next = freelist[v->k]; |
543 |
|
freelist[v->k] = v; |
544 |
|
FREE_DTOA_LOCK(0); |
545 |
|
} |
546 |
} |
} |
547 |
} |
} |
548 |
|
|
1266 |
b->wds = (x[1] = z) ? 2 : 1; |
b->wds = (x[1] = z) ? 2 : 1; |
1267 |
} |
} |
1268 |
else { |
else { |
|
#ifdef DEBUG |
|
|
if (!z) |
|
|
Bug("Zero passed to d2b"); |
|
|
#endif |
|
1269 |
k = lo0bits(&z); |
k = lo0bits(&z); |
1270 |
x[0] = z; |
x[0] = z; |
1271 |
#ifndef Sudden_Underflow |
#ifndef Sudden_Underflow |