Index: Python/dtoa.c =================================================================== --- Python/dtoa.c (revision 77580) +++ Python/dtoa.c (working copy) @@ -329,8 +329,9 @@ static Bigint *freelist[Kmax+1]; + +#ifndef Py_USING_MEMORY_DEBUGGER /* Allocate space for a Bigint with up to 1<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) { + FREE((void*)v); + } +} +#endif /* Py_USING_MEMORY_DEBUGGER */ + + #define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \ y->wds*sizeof(Long) + 2*sizeof(int)) @@ -656,6 +691,7 @@ static Bigint *p5s; +#ifndef Py_USING_MEMORY_DEBUGGER /* multiply the Bigint b by 5**k. Returns a pointer to the result, or NULL on failure; if the returned pointer is distinct from b then the original Bigint b will have been Bfree'd. Ignores the sign of b. */ @@ -710,7 +746,59 @@ } return b; } +#else +/* Version of pow5mult that doesn't cache powers of 5; this makes + strtod and dtoa marginally less efficient in hard cases, but makes + it easier to match Balloc/Bfree counts in strtod and dtoa, for the + purposes of detecting memory leaks. */ +static Bigint * +pow5mult(Bigint *b, int k) +{ + Bigint *b1, *p5, *p51; + int i; + static int p05[3] = { 5, 25, 125 }; + + if ((i = k & 3)) { + b = multadd(b, p05[i-1], 0); + if (b == NULL) + return NULL; + } + + if (!(k>>= 2)) + return b; + p5 = i2b(625); + if (p5 == NULL) { + Bfree(b); + return NULL; + } + + for(;;) { + if (k & 1) { + b1 = mult(b, p5); + Bfree(b); + b = b1; + if (b == NULL) { + Bfree(p5); + return NULL; + } + } + if (!(k>>= 1)) + break; + p51 = mult(p5, p5); + Bfree(p5); + p5 = p51; + if (p5 == NULL) { + Bfree(b); + return NULL; + } + } + Bfree(p5); + return b; +} +#endif /* Py_USING_MEMORY_DEBUGGER */ + + /* shift a Bigint b left by k bits. Return a pointer to the shifted result, or NULL on failure. If the returned pointer is distinct from b then the original b will have been Bfree'd. Ignores the sign of b. */

AltStyle によって変換されたページ (->オリジナル) /