diff -r 70b9b55fd915 Python/dtoa.c --- a/Python/dtoa.c Sun Aug 17 21:14:46 2014 +0200 +++ b/Python/dtoa.c Sun Aug 17 21:43:21 2014 +0200 @@ -122,8 +122,8 @@ #include "float.h" -#define MALLOC PyMem_Malloc -#define FREE PyMem_Free +#define MALLOC PyObject_Malloc +#define FREE PyObject_Free /* This code should also work for ARM mixed-endian format on little-endian machines, where doubles have byte order 45670123 (in increasing address @@ -175,12 +175,6 @@ typedef PY_INT32_T Long; #define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);} #endif -#ifndef PRIVATE_MEM -#define PRIVATE_MEM 2304 -#endif -#define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double)) -static double private_mem[PRIVATE_mem], *pmem_next = private_mem; - #ifdef __cplusplus extern "C" { #endif @@ -335,82 +329,6 @@ Bigint { typedef struct Bigint Bigint; -#ifndef Py_USING_MEMORY_DEBUGGER - -/* Memory management: memory is allocated from, and returned to, Kmax+1 pools - of memory, where pool k (0 <= k <= Kmax) is for Bigints b with b->maxwds == - 1 << k. These pools are maintained as linked lists, with freelist[k] - pointing to the head of the list for pool k. - - On allocation, if there's no free slot in the appropriate pool, MALLOC is - called to get more memory. This memory is not returned to the system until - Python quits. There's also a private memory pool that's allocated from - in preference to using MALLOC. - - For Bigints with more than (1 << Kmax) digits (which implies at least 1233 - decimal digits), memory is directly allocated using MALLOC, and freed using - FREE. - - XXX: it would be easy to bypass this memory-management system and - translate each call to Balloc into a call to PyMem_Malloc, and each - Bfree to PyMem_Free. Investigate whether this has any significant - performance on impact. */ - -static Bigint *freelist[Kmax+1]; - -/* Allocate space for a Bigint with up to 1<next; - else { - x = 1 << k; - len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1) - /sizeof(double); - if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) { - rv = (Bigint*)pmem_next; - pmem_next += len; - } - else { - rv = (Bigint*)MALLOC(len*sizeof(double)); - if (rv == NULL) - return NULL; - } - rv->k = k; - rv->maxwds = x; - } - rv->sign = rv->wds = 0; - return rv; -} - -/* Free a Bigint allocated with Balloc */ - -static void -Bfree(Bigint *v) -{ - if (v) { - if (v->k > Kmax) - FREE((void*)v); - else { - v->next = freelist[v->k]; - freelist[v->k] = v; - } - } -} - -#else - -/* Alternative versions of Balloc and Bfree that use PyMem_Malloc and - PyMem_Free directly in place of the custom memory allocation scheme above. - These are provided for the benefit of memory debugging tools like - Valgrind. */ - /* Allocate space for a Bigint with up to 1<sign, (char *)&y->sign, \ y->wds*sizeof(Long) + 2*sizeof(int))