Skip to content

Commit 4883b47

Browse files
authored
Merge branch 'main' into compiler_error_handling
2 parents 542b60e + c1b1f51 commit 4883b47

18 files changed

+421
-338
lines changed

Include/cpython/longintrepr.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,14 @@ typedef long stwodigits; /* signed variant of twodigits */
7979
aware that ints abuse ob_size's sign bit.
8080
*/
8181

82-
struct _longobject {
83-
PyObject_VAR_HEAD
82+
typedef struct _PyLongValue {
83+
Py_ssize_t ob_size; /* Number of items in variable part */
8484
digit ob_digit[1];
85+
} _PyLongValue;
86+
87+
struct _longobject {
88+
PyObject_HEAD
89+
_PyLongValue long_value;
8590
};
8691

8792
PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);

Include/internal/pycore_runtime_init.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ extern "C" {
149149

150150
#define _PyLong_DIGIT_INIT(val) \
151151
{ \
152-
_PyVarObject_IMMORTAL_INIT(&PyLong_Type, \
153-
((val) == 0 ? 0 : ((val) > 0 ? 1 : -1))), \
154-
.ob_digit = { ((val) >= 0 ? (val) : -(val)) }, \
152+
.ob_base = _PyObject_IMMORTAL_INIT(&PyLong_Type), \
153+
.long_value = { \
154+
((val) == 0 ? 0 : ((val) > 0 ? 1 : -1)), \
155+
{ ((val) >= 0 ? (val) : -(val)) }, \
156+
} \
155157
}
156158

157159
#define _PyBytes_SIMPLE_INIT(CH, LEN) \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Refactor the ``PyLongObject`` struct into a normal Python object header and
2+
a ``PyLongValue`` struct.

Modules/_decimal/_decimal.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -2171,16 +2171,16 @@ dec_from_long(PyTypeObject *type, PyObject *v,
21712171
}
21722172

21732173
if (len == 1) {
2174-
_dec_settriple(dec, sign, *l->ob_digit, 0);
2174+
_dec_settriple(dec, sign, *l->long_value.ob_digit, 0);
21752175
mpd_qfinalize(MPD(dec), ctx, status);
21762176
return dec;
21772177
}
21782178

21792179
#if PYLONG_BITS_IN_DIGIT == 30
2180-
mpd_qimport_u32(MPD(dec), l->ob_digit, len, sign, PyLong_BASE,
2180+
mpd_qimport_u32(MPD(dec), l->long_value.ob_digit, len, sign, PyLong_BASE,
21812181
ctx, status);
21822182
#elif PYLONG_BITS_IN_DIGIT == 15
2183-
mpd_qimport_u16(MPD(dec), l->ob_digit, len, sign, PyLong_BASE,
2183+
mpd_qimport_u16(MPD(dec), l->long_value.ob_digit, len, sign, PyLong_BASE,
21842184
ctx, status);
21852185
#else
21862186
#error "PYLONG_BITS_IN_DIGIT should be 15 or 30"
@@ -3543,11 +3543,11 @@ dec_as_long(PyObject *dec, PyObject *context, int round)
35433543
return NULL;
35443544
}
35453545

3546-
memcpy(pylong->ob_digit, ob_digit, n * sizeof(digit));
3546+
memcpy(pylong->long_value.ob_digit, ob_digit, n * sizeof(digit));
35473547
mpd_free(ob_digit);
35483548

35493549
i = n;
3550-
while ((i > 0) && (pylong->ob_digit[i-1] == 0)) {
3550+
while ((i > 0) && (pylong->long_value.ob_digit[i-1] == 0)) {
35513551
i--;
35523552
}
35533553

Objects/boolobject.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ PyTypeObject PyBool_Type = {
195195
/* The objects representing bool values False and True */
196196

197197
struct _longobject _Py_FalseStruct = {
198-
PyVarObject_HEAD_INIT(&PyBool_Type, 0)
199-
{ 0 }
198+
PyObject_HEAD_INIT(&PyBool_Type)
199+
{ 0, { 0 } }
200200
};
201201

202202
struct _longobject _Py_TrueStruct = {
203-
PyVarObject_HEAD_INIT(&PyBool_Type, 1)
204-
{ 1 }
203+
PyObject_HEAD_INIT(&PyBool_Type)
204+
{ 1, { 1 } }
205205
};

Objects/listobject.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2155,8 +2155,8 @@ unsafe_long_compare(PyObject *v, PyObject *w, MergeState *ms)
21552155
vl = (PyLongObject*)v;
21562156
wl = (PyLongObject*)w;
21572157

2158-
v0 = Py_SIZE(vl) == 0 ? 0 : (sdigit)vl->ob_digit[0];
2159-
w0 = Py_SIZE(wl) == 0 ? 0 : (sdigit)wl->ob_digit[0];
2158+
v0 = Py_SIZE(vl) == 0 ? 0 : (sdigit)vl->long_value.ob_digit[0];
2159+
w0 = Py_SIZE(wl) == 0 ? 0 : (sdigit)wl->long_value.ob_digit[0];
21602160

21612161
if (Py_SIZE(vl) < 0)
21622162
v0 = -v0;

0 commit comments

Comments
 (0)