Skip to content

Commit 6b95722

Browse files
committed
Update Python inlined files: 3.12.7 (4.1.1)
1 parent 803dc3b commit 6b95722

File tree

3 files changed

+126
-62
lines changed

3 files changed

+126
-62
lines changed

graalpython/com.oracle.graal.python.cext/include/internal/pycore_dtoa.h

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,49 @@ extern "C" {
1111
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
1212

1313

14-
#if _PY_SHORT_FLOAT_REPR == 1
14+
typedef uint32_t ULong;
15+
16+
struct
17+
Bigint {
18+
struct Bigint *next;
19+
int k, maxwds, sign, wds;
20+
ULong x[1];
21+
};
22+
23+
#if defined(Py_USING_MEMORY_DEBUGGER) || _PY_SHORT_FLOAT_REPR == 0
24+
25+
struct _dtoa_state {
26+
int _not_used;
27+
};
28+
#define _dtoa_state_INIT(INTERP) \
29+
{0}
30+
31+
#else // !Py_USING_MEMORY_DEBUGGER && _PY_SHORT_FLOAT_REPR != 0
32+
33+
/* The size of the Bigint freelist */
34+
#define Bigint_Kmax 7
35+
36+
#ifndef PRIVATE_MEM
37+
#define PRIVATE_MEM 2304
38+
#endif
39+
#define Bigint_PREALLOC_SIZE \
40+
((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))
41+
42+
struct _dtoa_state {
43+
/* p5s is a linked list of powers of 5 of the form 5**(2**i), i >= 2 */
44+
// XXX This should be freed during runtime fini.
45+
struct Bigint *p5s;
46+
struct Bigint *freelist[Bigint_Kmax+1];
47+
double preallocated[Bigint_PREALLOC_SIZE];
48+
double *preallocated_next;
49+
};
50+
#define _dtoa_state_INIT(INTERP) \
51+
{ \
52+
.preallocated_next = (INTERP)->dtoa.preallocated, \
53+
}
54+
55+
#endif // !Py_USING_MEMORY_DEBUGGER
56+
1557

1658
/* These functions are used by modules compiled as C extension like math:
1759
they must be exported. */
@@ -20,10 +62,6 @@ PyAPI_FUNC(double) _Py_dg_strtod(const char *str, char **ptr);
2062
PyAPI_FUNC(char *) _Py_dg_dtoa(double d, int mode, int ndigits,
2163
int *decpt, int *sign, char **rve);
2264
PyAPI_FUNC(void) _Py_dg_freedtoa(char *s);
23-
PyAPI_FUNC(double) _Py_dg_stdnan(int sign);
24-
PyAPI_FUNC(double) _Py_dg_infinity(int sign);
25-
26-
#endif // _PY_SHORT_FLOAT_REPR == 1
2765

2866
#ifdef __cplusplus
2967
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#ifndef Py_INTERNAL_FLOATOBJECT_H
2+
#define Py_INTERNAL_FLOATOBJECT_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
11+
12+
/* runtime lifecycle */
13+
14+
extern void _PyFloat_InitState(PyInterpreterState *);
15+
extern PyStatus _PyFloat_InitTypes(PyInterpreterState *);
16+
extern void _PyFloat_Fini(PyInterpreterState *);
17+
extern void _PyFloat_FiniType(PyInterpreterState *);
18+
19+
20+
/* other API */
21+
22+
enum _py_float_format_type {
23+
_py_float_format_unknown,
24+
_py_float_format_ieee_big_endian,
25+
_py_float_format_ieee_little_endian,
26+
};
27+
28+
struct _Py_float_runtime_state {
29+
enum _py_float_format_type float_format;
30+
enum _py_float_format_type double_format;
31+
};
32+
33+
34+
#ifndef WITH_FREELISTS
35+
// without freelists
36+
# define PyFloat_MAXFREELIST 0
37+
#endif
38+
39+
#ifndef PyFloat_MAXFREELIST
40+
# define PyFloat_MAXFREELIST 100
41+
#endif
42+
43+
struct _Py_float_state {
44+
#if PyFloat_MAXFREELIST > 0
45+
/* Special free list
46+
free_list is a singly-linked list of available PyFloatObjects,
47+
linked via abuse of their ob_type members. */
48+
int numfree;
49+
PyFloatObject *free_list;
50+
#endif
51+
};
52+
53+
void _PyFloat_ExactDealloc(PyObject *op);
54+
55+
56+
PyAPI_FUNC(void) _PyFloat_DebugMallocStats(FILE* out);
57+
58+
59+
/* Format the object based on the format_spec, as defined in PEP 3101
60+
(Advanced String Formatting). */
61+
PyAPI_FUNC(int) _PyFloat_FormatAdvancedWriter(
62+
_PyUnicodeWriter *writer,
63+
PyObject *obj,
64+
PyObject *format_spec,
65+
Py_ssize_t start,
66+
Py_ssize_t end);
67+
68+
#ifdef __cplusplus
69+
}
70+
#endif
71+
#endif /* !Py_INTERNAL_FLOATOBJECT_H */

graalpython/com.oracle.graal.python.cext/src/dtoa.c

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119

120120
#include "Python.h"
121121
#include "pycore_dtoa.h" // _PY_SHORT_FLOAT_REPR
122+
#include "pycore_pystate.h" // _PyInterpreterState_GET()
122123
#include <stdlib.h> // exit()
123124

124125
/* if _PY_SHORT_FLOAT_REPR == 0, then don't even try to compile
@@ -156,7 +157,7 @@
156157
#endif
157158

158159

159-
typedef uint32_t ULong;
160+
// ULong is defined in pycore_dtoa.h.
160161
typedef int32_t Long;
161162
typedef uint64_t ULLong;
162163

@@ -171,12 +172,6 @@ typedef uint64_t ULLong;
171172
#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
172173
#endif
173174

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-
180175
#ifdef __cplusplus
181176
extern "C" {
182177
#endif
@@ -278,11 +273,6 @@ typedef union { double d; ULong L[2]; } U;
278273
#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
279274
#define Big1 0xffffffff
280275

281-
/* Standard NaN used by _Py_dg_stdnan. */
282-
283-
#define NAN_WORD0 0x7ff80000
284-
#define NAN_WORD1 0
285-
286276
/* Bits of the representation of positive infinity. */
287277

288278
#define POSINF_WORD0 0x7ff00000
@@ -298,8 +288,6 @@ BCinfo {
298288

299289
#define FFFFFFFF 0xffffffffUL
300290

301-
#define Kmax 7
302-
303291
/* struct Bigint is used to represent arbitrary-precision integers. These
304292
integers are stored in sign-magnitude format, with the magnitude stored as
305293
an array of base 2**32 digits. Bigints are always normalized: if x is a
@@ -322,13 +310,7 @@ BCinfo {
322310
significant (x[0]) to most significant (x[wds-1]).
323311
*/
324312

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.
332314
typedef struct Bigint Bigint;
333315

334316
#ifndef Py_USING_MEMORY_DEBUGGER
@@ -366,13 +348,15 @@ Balloc(int k)
366348
unsigned int len;
367349
PyInterpreterState *interp = _PyInterpreterState_GET();
368350

369-
if (k <= Kmax && (rv = freelist[k]))
351+
if (k <= Bigint_Kmax && (rv = freelist[k]))
370352
freelist[k] = rv->next;
371353
else {
372354
x = 1 << k;
373355
len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
374356
/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+
) {
376360
rv = (Bigint*)pmem_next;
377361
pmem_next += len;
378362
}
@@ -394,7 +378,7 @@ static void
394378
Bfree(Bigint *v)
395379
{
396380
if (v) {
397-
if (v->k > Kmax)
381+
if (v->k > Bigint_Kmax)
398382
FREE((void*)v);
399383
else {
400384
PyInterpreterState *interp = _PyInterpreterState_GET();
@@ -404,6 +388,10 @@ Bfree(Bigint *v)
404388
}
405389
}
406390

391+
#undef pmem_next
392+
#undef private_mem
393+
#undef freelist
394+
407395
#else
408396

409397
/* Alternative versions of Balloc and Bfree that use PyMem_Malloc and
@@ -682,10 +670,6 @@ mult(Bigint *a, Bigint *b)
682670

683671
#ifndef Py_USING_MEMORY_DEBUGGER
684672

685-
/* p5s is a linked list of powers of 5 of the form 5**(2**i), i >= 2 */
686-
687-
static Bigint *p5s;
688-
689673
/* multiply the Bigint b by 5**k. Returns a pointer to the result, or NULL on
690674
failure; if the returned pointer is distinct from b then the original
691675
Bigint b will have been Bfree'd. Ignores the sign of b. */
@@ -1410,35 +1394,6 @@ bigcomp(U *rv, const char *s0, BCinfo *bc)
14101394
return 0;
14111395
}
14121396

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-
}
14421397

14431398
double
14441399
_Py_dg_strtod(const char *s00, char **se)

0 commit comments

Comments
 (0)