119
119
120
120
#include "Python.h"
121
121
#include "pycore_dtoa.h" // _PY_SHORT_FLOAT_REPR
122
+ #include "pycore_pystate.h" // _PyInterpreterState_GET()
122
123
#include <stdlib.h> // exit()
123
124
124
125
/* if _PY_SHORT_FLOAT_REPR == 0, then don't even try to compile
156
157
#endif
157
158
158
159
159
- typedef uint32_t ULong ;
160
+ // ULong is defined in pycore_dtoa.h.
160
161
typedef int32_t Long ;
161
162
typedef uint64_t ULLong ;
162
163
@@ -171,12 +172,6 @@ typedef uint64_t ULLong;
171
172
#define Bug (x ) {fprintf(stderr, "%s\n", x); exit(1);}
172
173
#endif
173
174
174
- #ifndef PRIVATE_MEM
175
- #define PRIVATE_MEM 2304
176
- #endif
177
- #define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))
178
- static double private_mem [PRIVATE_mem ], * pmem_next = private_mem ;
179
-
180
175
#ifdef __cplusplus
181
176
extern "C" {
182
177
#endif
@@ -278,11 +273,6 @@ typedef union { double d; ULong L[2]; } U;
278
273
#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
279
274
#define Big1 0xffffffff
280
275
281
- /* Standard NaN used by _Py_dg_stdnan. */
282
-
283
- #define NAN_WORD0 0x7ff80000
284
- #define NAN_WORD1 0
285
-
286
276
/* Bits of the representation of positive infinity. */
287
277
288
278
#define POSINF_WORD0 0x7ff00000
@@ -298,8 +288,6 @@ BCinfo {
298
288
299
289
#define FFFFFFFF 0xffffffffUL
300
290
301
- #define Kmax 7
302
-
303
291
/* struct Bigint is used to represent arbitrary-precision integers. These
304
292
integers are stored in sign-magnitude format, with the magnitude stored as
305
293
an array of base 2**32 digits. Bigints are always normalized: if x is a
@@ -322,13 +310,7 @@ BCinfo {
322
310
significant (x[0]) to most significant (x[wds-1]).
323
311
*/
324
312
325
- struct
326
- Bigint {
327
- struct Bigint * next ;
328
- int k , maxwds , sign , wds ;
329
- ULong x [1 ];
330
- };
331
-
313
+ // struct Bigint is defined in pycore_dtoa.h.
332
314
typedef struct Bigint Bigint ;
333
315
334
316
#ifndef Py_USING_MEMORY_DEBUGGER
@@ -366,13 +348,15 @@ Balloc(int k)
366
348
unsigned int len ;
367
349
PyInterpreterState * interp = _PyInterpreterState_GET ();
368
350
369
- if (k <= Kmax && (rv = freelist [k ]))
351
+ if (k <= Bigint_Kmax && (rv = freelist [k ]))
370
352
freelist [k ] = rv -> next ;
371
353
else {
372
354
x = 1 << k ;
373
355
len = (sizeof (Bigint ) + (x - 1 )* sizeof (ULong ) + sizeof (double ) - 1 )
374
356
/sizeof (double );
375
- if (k <= Kmax && pmem_next - private_mem + len <= (Py_ssize_t )PRIVATE_mem ) {
357
+ if (k <= Bigint_Kmax &&
358
+ pmem_next - private_mem + len <= (Py_ssize_t )Bigint_PREALLOC_SIZE
359
+ ) {
376
360
rv = (Bigint * )pmem_next ;
377
361
pmem_next += len ;
378
362
}
@@ -394,7 +378,7 @@ static void
394
378
Bfree (Bigint * v )
395
379
{
396
380
if (v ) {
397
- if (v -> k > Kmax )
381
+ if (v -> k > Bigint_Kmax )
398
382
FREE ((void * )v );
399
383
else {
400
384
PyInterpreterState * interp = _PyInterpreterState_GET ();
@@ -404,6 +388,10 @@ Bfree(Bigint *v)
404
388
}
405
389
}
406
390
391
+ #undef pmem_next
392
+ #undef private_mem
393
+ #undef freelist
394
+
407
395
#else
408
396
409
397
/* Alternative versions of Balloc and Bfree that use PyMem_Malloc and
@@ -682,10 +670,6 @@ mult(Bigint *a, Bigint *b)
682
670
683
671
#ifndef Py_USING_MEMORY_DEBUGGER
684
672
685
- /* p5s is a linked list of powers of 5 of the form 5**(2**i), i >= 2 */
686
-
687
- static Bigint * p5s ;
688
-
689
673
/* multiply the Bigint b by 5**k. Returns a pointer to the result, or NULL on
690
674
failure; if the returned pointer is distinct from b then the original
691
675
Bigint b will have been Bfree'd. Ignores the sign of b. */
@@ -1410,35 +1394,6 @@ bigcomp(U *rv, const char *s0, BCinfo *bc)
1410
1394
return 0 ;
1411
1395
}
1412
1396
1413
- /* Return a 'standard' NaN value.
1414
-
1415
- There are exactly two quiet NaNs that don't arise by 'quieting' signaling
1416
- NaNs (see IEEE 754-2008, section 6.2.1). If sign == 0, return the one whose
1417
- sign bit is cleared. Otherwise, return the one whose sign bit is set.
1418
- */
1419
-
1420
- double
1421
- _Py_dg_stdnan (int sign )
1422
- {
1423
- U rv ;
1424
- word0 (& rv ) = NAN_WORD0 ;
1425
- word1 (& rv ) = NAN_WORD1 ;
1426
- if (sign )
1427
- word0 (& rv ) |= Sign_bit ;
1428
- return dval (& rv );
1429
- }
1430
-
1431
- /* Return positive or negative infinity, according to the given sign (0 for
1432
- * positive infinity, 1 for negative infinity). */
1433
-
1434
- double
1435
- _Py_dg_infinity (int sign )
1436
- {
1437
- U rv ;
1438
- word0 (& rv ) = POSINF_WORD0 ;
1439
- word1 (& rv ) = POSINF_WORD1 ;
1440
- return sign ? - dval (& rv ) : dval (& rv );
1441
- }
1442
1397
1443
1398
double
1444
1399
_Py_dg_strtod (const char * s00 , char * * se )
0 commit comments