File tree Expand file tree Collapse file tree 5 files changed +35
-19
lines changed Expand file tree Collapse file tree 5 files changed +35
-19
lines changed Original file line number Diff line number Diff line change @@ -22,10 +22,35 @@ Bigint {
22
22
ULong x [1 ];
23
23
};
24
24
25
- #ifndef Py_USING_MEMORY_DEBUGGER
25
+ #ifdef Py_USING_MEMORY_DEBUGGER
26
+
27
+ struct _dtoa_runtime_state {
28
+ int _not_used ;
29
+ };
30
+ #define _dtoa_runtime_state_INIT {0}
31
+
32
+ #else // !Py_USING_MEMORY_DEBUGGER
33
+
26
34
/* The size of the Bigint freelist */
27
- # define Bigint_Kmax 7
35
+ #define Bigint_Kmax 7
36
+
37
+ #ifndef PRIVATE_MEM
38
+ #define PRIVATE_MEM 2304
28
39
#endif
40
+ #define Bigint_PREALLOC_SIZE \
41
+ ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))
42
+
43
+ struct _dtoa_runtime_state {
44
+ struct Bigint * freelist [Bigint_Kmax + 1 ];
45
+ double preallocated [Bigint_PREALLOC_SIZE ];
46
+ double * preallocated_next ;
47
+ };
48
+ #define _dtoa_runtime_state_INIT (runtime ) \
49
+ { \
50
+ .preallocated_next = runtime.dtoa.preallocated, \
51
+ }
52
+
53
+ #endif // !Py_USING_MEMORY_DEBUGGER
29
54
30
55
31
56
/* These functions are used by modules compiled as C extension like math:
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ extern "C" {
9
9
#endif
10
10
11
11
#include "pycore_atomic.h" /* _Py_atomic_address */
12
- #include "pycore_dtoa.h" // struct Bigint
12
+ #include "pycore_dtoa.h" // struct _dtoa_runtime_state
13
13
#include "pycore_gil.h" // struct _gil_runtime_state
14
14
#include "pycore_global_objects.h" // struct _Py_global_objects
15
15
#include "pycore_import.h" // struct _import_runtime_state
@@ -129,11 +129,7 @@ typedef struct pyruntimestate {
129
129
struct {
130
130
struct _PyTraceMalloc_Config config ;
131
131
} tracemalloc ;
132
- struct {
133
- #ifndef Py_USING_MEMORY_DEBUGGER
134
- struct Bigint * freelist [Bigint_Kmax + 1 ];
135
- #endif
136
- } dtoa ;
132
+ struct _dtoa_runtime_state dtoa ;
137
133
138
134
PyPreConfig preconfig ;
139
135
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ extern "C" {
39
39
.tracemalloc = { \
40
40
.config = _PyTraceMalloc_Config_INIT, \
41
41
}, \
42
+ .dtoa = _dtoa_runtime_state_INIT(runtime), \
42
43
.types = { \
43
44
.next_version_tag = 1, \
44
45
}, \
Original file line number Diff line number Diff line change @@ -172,12 +172,6 @@ typedef uint64_t ULLong;
172
172
#define Bug (x ) {fprintf(stderr, "%s\n", x); exit(1);}
173
173
#endif
174
174
175
- #ifndef PRIVATE_MEM
176
- #define PRIVATE_MEM 2304
177
- #endif
178
- #define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))
179
- static double private_mem [PRIVATE_mem ], * pmem_next = private_mem ;
180
-
181
175
#ifdef __cplusplus
182
176
extern "C" {
183
177
#endif
@@ -346,6 +340,8 @@ typedef struct Bigint Bigint;
346
340
performance on impact. */
347
341
348
342
#define freelist _PyRuntime.dtoa.freelist
343
+ #define private_mem _PyRuntime.dtoa.preallocated
344
+ #define pmem_next _PyRuntime.dtoa.preallocated_next
349
345
350
346
/* Allocate space for a Bigint with up to 1<<k digits */
351
347
@@ -363,7 +359,7 @@ Balloc(int k)
363
359
len = (sizeof (Bigint ) + (x - 1 )* sizeof (ULong ) + sizeof (double ) - 1 )
364
360
/sizeof (double );
365
361
if (k <= Bigint_Kmax &&
366
- pmem_next - private_mem + len <= (Py_ssize_t )PRIVATE_mem
362
+ pmem_next - private_mem + len <= (Py_ssize_t )Bigint_PREALLOC_SIZE
367
363
) {
368
364
rv = (Bigint * )pmem_next ;
369
365
pmem_next += len ;
@@ -395,6 +391,8 @@ Bfree(Bigint *v)
395
391
}
396
392
}
397
393
394
+ #undef pmem_next
395
+ #undef private_mem
398
396
#undef freelist
399
397
400
398
#else
Original file line number Diff line number Diff line change @@ -324,14 +324,10 @@ Objects/unicodeobject.c - ucnhash_capi -
324
324
# -----------------------
325
325
# state
326
326
327
- # pre-allocated memory
328
- Python/dtoa.c - private_mem -
329
-
330
327
# local buffer
331
328
Python/suggestions.c levenshtein_distance buffer -
332
329
333
330
# linked list
334
- Python/dtoa.c - pmem_next -
335
331
Python/getargs.c - static_arg_parsers -
336
332
337
333
# other
You can’t perform that action at this time.
0 commit comments