Skip to content

Commit 39f6436

Browse files
authored
Revert "bpo-40521: Make dtoa bigint free list per-interpreter (GH-24821)" (GH-24964)
This reverts commit 5bd1059.
1 parent 86883d4 commit 39f6436

File tree

3 files changed

+17
-39
lines changed

3 files changed

+17
-39
lines changed

Include/internal/pycore_dtoa.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#ifndef PY_NO_SHORT_FLOAT_REPR
2-
#ifndef Py_INTERNAL_DTOA_H
3-
#define Py_INTERNAL_DTOA_H
42
#ifdef __cplusplus
53
extern "C" {
64
#endif
@@ -19,21 +17,7 @@ PyAPI_FUNC(void) _Py_dg_freedtoa(char *s);
1917
PyAPI_FUNC(double) _Py_dg_stdnan(int sign);
2018
PyAPI_FUNC(double) _Py_dg_infinity(int sign);
2119

22-
#define _PyDtoa_Kmax 7
23-
24-
typedef uint32_t _PyDtoa_ULong;
25-
typedef int32_t _PyDtoa_Long;
26-
typedef uint64_t _PyDtoa_ULLong;
27-
28-
struct
29-
_PyDtoa_Bigint {
30-
struct _PyDtoa_Bigint *next;
31-
int k, maxwds, sign, wds;
32-
_PyDtoa_ULong x[1];
33-
};
34-
3520
#ifdef __cplusplus
3621
}
3722
#endif
38-
#endif /* !Py_INTERNAL_DTOA_H */
3923
#endif /* !PY_NO_SHORT_FLOAT_REPR */

Include/internal/pycore_interp.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ extern "C" {
1313
#include "pycore_gil.h" // struct _gil_runtime_state
1414
#include "pycore_gc.h" // struct _gc_runtime_state
1515
#include "pycore_warnings.h" // struct _warnings_runtime_state
16-
#include "pycore_dtoa.h"
1716

1817
struct _pending_calls {
1918
PyThread_type_lock lock;
@@ -322,9 +321,6 @@ struct _is {
322321

323322
struct ast_state ast;
324323
struct type_cache type_cache;
325-
#ifndef PY_NO_SHORT_FLOAT_REPR
326-
struct _PyDtoa_Bigint *dtoa_freelist[_PyDtoa_Kmax + 1];
327-
#endif
328324
};
329325

330326
extern void _PyInterpreterState_ClearModules(PyInterpreterState *interp);

Python/dtoa.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,6 @@
119119

120120
#include "Python.h"
121121
#include "pycore_dtoa.h"
122-
#include "pycore_interp.h"
123-
#include "pycore_pystate.h"
124-
125-
#define ULong _PyDtoa_ULong
126-
#define Long _PyDtoa_Long
127-
#define ULLong _PyDtoa_ULLong
128-
#define Kmax _PyDtoa_Kmax
129-
130-
typedef struct _PyDtoa_Bigint Bigint;
131-
132122

133123
/* if PY_NO_SHORT_FLOAT_REPR is defined, then don't even try to compile
134124
the following code */
@@ -164,6 +154,11 @@ typedef struct _PyDtoa_Bigint Bigint;
164154
#error "doubles and ints have incompatible endianness"
165155
#endif
166156

157+
158+
typedef uint32_t ULong;
159+
typedef int32_t Long;
160+
typedef uint64_t ULLong;
161+
167162
#undef DEBUG
168163
#ifdef Py_DEBUG
169164
#define DEBUG
@@ -302,6 +297,8 @@ BCinfo {
302297

303298
#define FFFFFFFF 0xffffffffUL
304299

300+
#define Kmax 7
301+
305302
/* struct Bigint is used to represent arbitrary-precision integers. These
306303
integers are stored in sign-magnitude format, with the magnitude stored as
307304
an array of base 2**32 digits. Bigints are always normalized: if x is a
@@ -324,6 +321,14 @@ BCinfo {
324321
significant (x[0]) to most significant (x[wds-1]).
325322
*/
326323

324+
struct
325+
Bigint {
326+
struct Bigint *next;
327+
int k, maxwds, sign, wds;
328+
ULong x[1];
329+
};
330+
331+
typedef struct Bigint Bigint;
327332

328333
#ifndef Py_USING_MEMORY_DEBUGGER
329334

@@ -346,13 +351,7 @@ BCinfo {
346351
Bfree to PyMem_Free. Investigate whether this has any significant
347352
performance on impact. */
348353

349-
350-
/* Get Bigint freelist from interpreter */
351-
static Bigint **
352-
get_freelist(void) {
353-
PyInterpreterState *interp = _PyInterpreterState_GET();
354-
return interp->dtoa_freelist;
355-
}
354+
static Bigint *freelist[Kmax+1];
356355

357356
/* Allocate space for a Bigint with up to 1<<k digits */
358357

@@ -362,7 +361,7 @@ Balloc(int k)
362361
int x;
363362
Bigint *rv;
364363
unsigned int len;
365-
Bigint **freelist = get_freelist();
364+
366365
if (k <= Kmax && (rv = freelist[k]))
367366
freelist[k] = rv->next;
368367
else {
@@ -394,7 +393,6 @@ Bfree(Bigint *v)
394393
if (v->k > Kmax)
395394
FREE((void*)v);
396395
else {
397-
Bigint **freelist = get_freelist();
398396
v->next = freelist[v->k];
399397
freelist[v->k] = v;
400398
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy