Revert "bpo-40521: Make dtoa bigint free list per-interpreter (GH-24821)" (GH-24964)

This reverts commit 5bd1059184.
This commit is contained in:
Victor Stinner 2021-03-22 11:58:59 +01:00 committed by GitHub
parent 86883d40e9
commit 39f643614d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 39 deletions

View File

@ -1,6 +1,4 @@
#ifndef PY_NO_SHORT_FLOAT_REPR #ifndef PY_NO_SHORT_FLOAT_REPR
#ifndef Py_INTERNAL_DTOA_H
#define Py_INTERNAL_DTOA_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -19,21 +17,7 @@ PyAPI_FUNC(void) _Py_dg_freedtoa(char *s);
PyAPI_FUNC(double) _Py_dg_stdnan(int sign); PyAPI_FUNC(double) _Py_dg_stdnan(int sign);
PyAPI_FUNC(double) _Py_dg_infinity(int sign); PyAPI_FUNC(double) _Py_dg_infinity(int sign);
#define _PyDtoa_Kmax 7
typedef uint32_t _PyDtoa_ULong;
typedef int32_t _PyDtoa_Long;
typedef uint64_t _PyDtoa_ULLong;
struct
_PyDtoa_Bigint {
struct _PyDtoa_Bigint *next;
int k, maxwds, sign, wds;
_PyDtoa_ULong x[1];
};
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* !Py_INTERNAL_DTOA_H */
#endif /* !PY_NO_SHORT_FLOAT_REPR */ #endif /* !PY_NO_SHORT_FLOAT_REPR */

View File

@ -13,7 +13,6 @@ extern "C" {
#include "pycore_gil.h" // struct _gil_runtime_state #include "pycore_gil.h" // struct _gil_runtime_state
#include "pycore_gc.h" // struct _gc_runtime_state #include "pycore_gc.h" // struct _gc_runtime_state
#include "pycore_warnings.h" // struct _warnings_runtime_state #include "pycore_warnings.h" // struct _warnings_runtime_state
#include "pycore_dtoa.h"
struct _pending_calls { struct _pending_calls {
PyThread_type_lock lock; PyThread_type_lock lock;
@ -322,9 +321,6 @@ struct _is {
struct ast_state ast; struct ast_state ast;
struct type_cache type_cache; struct type_cache type_cache;
#ifndef PY_NO_SHORT_FLOAT_REPR
struct _PyDtoa_Bigint *dtoa_freelist[_PyDtoa_Kmax + 1];
#endif
}; };
extern void _PyInterpreterState_ClearModules(PyInterpreterState *interp); extern void _PyInterpreterState_ClearModules(PyInterpreterState *interp);

View File

@ -119,16 +119,6 @@
#include "Python.h" #include "Python.h"
#include "pycore_dtoa.h" #include "pycore_dtoa.h"
#include "pycore_interp.h"
#include "pycore_pystate.h"
#define ULong _PyDtoa_ULong
#define Long _PyDtoa_Long
#define ULLong _PyDtoa_ULLong
#define Kmax _PyDtoa_Kmax
typedef struct _PyDtoa_Bigint Bigint;
/* if PY_NO_SHORT_FLOAT_REPR is defined, then don't even try to compile /* if PY_NO_SHORT_FLOAT_REPR is defined, then don't even try to compile
the following code */ the following code */
@ -164,6 +154,11 @@ typedef struct _PyDtoa_Bigint Bigint;
#error "doubles and ints have incompatible endianness" #error "doubles and ints have incompatible endianness"
#endif #endif
typedef uint32_t ULong;
typedef int32_t Long;
typedef uint64_t ULLong;
#undef DEBUG #undef DEBUG
#ifdef Py_DEBUG #ifdef Py_DEBUG
#define DEBUG #define DEBUG
@ -302,6 +297,8 @@ BCinfo {
#define FFFFFFFF 0xffffffffUL #define FFFFFFFF 0xffffffffUL
#define Kmax 7
/* struct Bigint is used to represent arbitrary-precision integers. These /* struct Bigint is used to represent arbitrary-precision integers. These
integers are stored in sign-magnitude format, with the magnitude stored as integers are stored in sign-magnitude format, with the magnitude stored as
an array of base 2**32 digits. Bigints are always normalized: if x is a an array of base 2**32 digits. Bigints are always normalized: if x is a
@ -324,6 +321,14 @@ BCinfo {
significant (x[0]) to most significant (x[wds-1]). significant (x[0]) to most significant (x[wds-1]).
*/ */
struct
Bigint {
struct Bigint *next;
int k, maxwds, sign, wds;
ULong x[1];
};
typedef struct Bigint Bigint;
#ifndef Py_USING_MEMORY_DEBUGGER #ifndef Py_USING_MEMORY_DEBUGGER
@ -346,13 +351,7 @@ BCinfo {
Bfree to PyMem_Free. Investigate whether this has any significant Bfree to PyMem_Free. Investigate whether this has any significant
performance on impact. */ performance on impact. */
static Bigint *freelist[Kmax+1];
/* Get Bigint freelist from interpreter */
static Bigint **
get_freelist(void) {
PyInterpreterState *interp = _PyInterpreterState_GET();
return interp->dtoa_freelist;
}
/* Allocate space for a Bigint with up to 1<<k digits */ /* Allocate space for a Bigint with up to 1<<k digits */
@ -362,7 +361,7 @@ Balloc(int k)
int x; int x;
Bigint *rv; Bigint *rv;
unsigned int len; unsigned int len;
Bigint **freelist = get_freelist();
if (k <= Kmax && (rv = freelist[k])) if (k <= Kmax && (rv = freelist[k]))
freelist[k] = rv->next; freelist[k] = rv->next;
else { else {
@ -394,7 +393,6 @@ Bfree(Bigint *v)
if (v->k > Kmax) if (v->k > Kmax)
FREE((void*)v); FREE((void*)v);
else { else {
Bigint **freelist = get_freelist();
v->next = freelist[v->k]; v->next = freelist[v->k];
freelist[v->k] = v; freelist[v->k] = v;
} }