summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Include/cpython/longintrepr.h6
-rw-r--r--Include/internal/pycore_long.h164
-rw-r--r--Include/internal/pycore_object.h3
-rw-r--r--Include/internal/pycore_runtime_init.h10
-rw-r--r--Include/object.h8
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2023-03-06-10-02-22.gh-issue-101291.0FT2QS.rst7
-rw-r--r--Modules/_decimal/_decimal.c43
-rw-r--r--Modules/_testcapi/mem.c2
-rw-r--r--Modules/_tkinter.c7
-rw-r--r--Modules/mathmodule.c19
-rw-r--r--Objects/abstract.c3
-rw-r--r--Objects/boolobject.c9
-rw-r--r--Objects/listobject.c20
-rw-r--r--Objects/longobject.c694
-rw-r--r--Objects/rangeobject.c2
-rw-r--r--Objects/sliceobject.c6
-rw-r--r--Objects/typeobject.c3
-rw-r--r--Python/ast_opt.c13
-rw-r--r--Python/bltinmodule.c16
-rw-r--r--Python/bytecodes.c19
-rw-r--r--Python/generated_cases.c.h773
-rw-r--r--Python/marshal.c9
-rw-r--r--Python/specialize.c8
-rw-r--r--Tools/build/deepfreeze.py10
-rwxr-xr-xTools/gdb/libpython.py26
25 files changed, 982 insertions, 898 deletions
diff --git a/Include/cpython/longintrepr.h b/Include/cpython/longintrepr.h
index 810daa8..c4cf820 100644
--- a/Include/cpython/longintrepr.h
+++ b/Include/cpython/longintrepr.h
@@ -80,7 +80,7 @@ typedef long stwodigits; /* signed variant of twodigits */
*/
typedef struct _PyLongValue {
- Py_ssize_t ob_size; /* Number of items in variable part */
+ uintptr_t lv_tag; /* Number of digits, sign and flags */
digit ob_digit[1];
} _PyLongValue;
@@ -94,6 +94,10 @@ PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);
/* Return a copy of src. */
PyAPI_FUNC(PyObject *) _PyLong_Copy(PyLongObject *src);
+PyAPI_FUNC(PyLongObject *)
+_PyLong_FromDigits(int negative, Py_ssize_t digit_count, digit *digits);
+
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/internal/pycore_long.h b/Include/internal/pycore_long.h
index 8c1d017..137a046 100644
--- a/Include/internal/pycore_long.h
+++ b/Include/internal/pycore_long.h
@@ -82,8 +82,6 @@ PyObject *_PyLong_Add(PyLongObject *left, PyLongObject *right);
PyObject *_PyLong_Multiply(PyLongObject *left, PyLongObject *right);
PyObject *_PyLong_Subtract(PyLongObject *left, PyLongObject *right);
-int _PyLong_AssignValue(PyObject **target, Py_ssize_t value);
-
/* Used by Python/mystrtoul.c, _PyBytes_FromHex(),
_PyBytes_DecodeEscape(), etc. */
PyAPI_DATA(unsigned char) _PyLong_DigitValue[256];
@@ -110,25 +108,155 @@ PyAPI_FUNC(char*) _PyLong_FormatBytesWriter(
int base,
int alternate);
-/* Return 1 if the argument is positive single digit int */
+/* Long value tag bits:
+ * 0-1: Sign bits value = (1-sign), ie. negative=2, positive=0, zero=1.
+ * 2: Reserved for immortality bit
+ * 3+ Unsigned digit count
+ */
+#define SIGN_MASK 3
+#define SIGN_ZERO 1
+#define SIGN_NEGATIVE 2
+#define NON_SIZE_BITS 3
+
+/* All *compact" values are guaranteed to fit into
+ * a Py_ssize_t with at least one bit to spare.
+ * In other words, for 64 bit machines, compact
+ * will be signed 63 (or fewer) bit values
+ */
+
+/* Return 1 if the argument is compact int */
+static inline int
+_PyLong_IsNonNegativeCompact(const PyLongObject* op) {
+ assert(PyLong_Check(op));
+ return op->long_value.lv_tag <= (1 << NON_SIZE_BITS);
+}
+
+static inline int
+_PyLong_IsCompact(const PyLongObject* op) {
+ assert(PyLong_Check(op));
+ return op->long_value.lv_tag < (2 << NON_SIZE_BITS);
+}
+
static inline int
-_PyLong_IsPositiveSingleDigit(PyObject* sub) {
- /* For a positive single digit int, the value of Py_SIZE(sub) is 0 or 1.
-
- We perform a fast check using a single comparison by casting from int
- to uint which casts negative numbers to large positive numbers.
- For details see Section 14.2 "Bounds Checking" in the Agner Fog
- optimization manual found at:
- https://www.agner.org/optimize/optimizing_cpp.pdf
-
- The function is not affected by -fwrapv, -fno-wrapv and -ftrapv
- compiler options of GCC and clang
- */
- assert(PyLong_CheckExact(sub));
- Py_ssize_t signed_size = Py_SIZE(sub);
- return ((size_t)signed_size) <= 1;
+_PyLong_BothAreCompact(const PyLongObject* a, const PyLongObject* b) {
+ assert(PyLong_Check(a));
+ assert(PyLong_Check(b));
+ return (a->long_value.lv_tag | b->long_value.lv_tag) < (2 << NON_SIZE_BITS);
+}
+
+/* Returns a *compact* value, iff `_PyLong_IsCompact` is true for `op`.
+ *
+ * "Compact" values have at least one bit to spare,
+ * so that addition and subtraction can be performed on the values
+ * without risk of overflow.
+ */
+static inline Py_ssize_t
+_PyLong_CompactValue(const PyLongObject *op)
+{
+ assert(PyLong_Check(op));
+ assert(_PyLong_IsCompact(op));
+ Py_ssize_t sign = 1 - (op->long_value.lv_tag & SIGN_MASK);
+ return sign * (Py_ssize_t)op->long_value.ob_digit[0];
+}
+
+static inline bool
+_PyLong_IsZero(const PyLongObject *op)
+{
+ return (op->long_value.lv_tag & SIGN_MASK) == SIGN_ZERO;
+}
+
+static inline bool
+_PyLong_IsNegative(const PyLongObject *op)
+{
+ return (op->long_value.lv_tag & SIGN_MASK) == SIGN_NEGATIVE;
+}
+
+static inline bool
+_PyLong_IsPositive(const PyLongObject *op)
+{
+ return (op->long_value.lv_tag & SIGN_MASK) == 0;
+}
+
+static inline Py_ssize_t
+_PyLong_DigitCount(const PyLongObject *op)
+{
+ assert(PyLong_Check(op));
+ return op->long_value.lv_tag >> NON_SIZE_BITS;
}
+/* Equivalent to _PyLong_DigitCount(op) * _PyLong_NonCompactSign(op) */
+static inline Py_ssize_t
+_PyLong_SignedDigitCount(const PyLongObject *op)
+{
+ assert(PyLong_Check(op));
+ Py_ssize_t sign = 1 - (op->long_value.lv_tag & SIGN_MASK);
+ return sign * (Py_ssize_t)(op->long_value.lv_tag >> NON_SIZE_BITS);
+}
+
+static inline int
+_PyLong_CompactSign(const PyLongObject *op)
+{
+ assert(PyLong_Check(op));
+ assert(_PyLong_IsCompact(op));
+ return 1 - (op->long_value.lv_tag & SIGN_MASK);
+}
+
+static inline int
+_PyLong_NonCompactSign(const PyLongObject *op)
+{
+ assert(PyLong_Check(op));
+ assert(!_PyLong_IsCompact(op));
+ return 1 - (op->long_value.lv_tag & SIGN_MASK);
+}
+
+/* Do a and b have the same sign? */
+static inline int
+_PyLong_SameSign(const PyLongObject *a, const PyLongObject *b)
+{
+ return (a->long_value.lv_tag & SIGN_MASK) == (b->long_value.lv_tag & SIGN_MASK);
+}
+
+#define TAG_FROM_SIGN_AND_SIZE(sign, size) ((1 - (sign)) | ((size) << NON_SIZE_BITS))
+
+static inline void
+_PyLong_SetSignAndDigitCount(PyLongObject *op, int sign, Py_ssize_t size)
+{
+ assert(size >= 0);
+ assert(-1 <= sign && sign <= 1);
+ assert(sign != 0 || size == 0);
+ op->long_value.lv_tag = TAG_FROM_SIGN_AND_SIZE(sign, (size_t)size);
+}
+
+static inline void
+_PyLong_SetDigitCount(PyLongObject *op, Py_ssize_t size)
+{
+ assert(size >= 0);
+ op->long_value.lv_tag = (((size_t)size) << NON_SIZE_BITS) | (op->long_value.lv_tag & SIGN_MASK);
+}
+
+#define NON_SIZE_MASK ~((1 << NON_SIZE_BITS) - 1)
+
+static inline void
+_PyLong_FlipSign(PyLongObject *op) {
+ unsigned int flipped_sign = 2 - (op->long_value.lv_tag & SIGN_MASK);
+ op->long_value.lv_tag &= NON_SIZE_MASK;
+ op->long_value.lv_tag |= flipped_sign;
+}
+
+#define _PyLong_DIGIT_INIT(val) \
+ { \
+ .ob_base = _PyObject_IMMORTAL_INIT(&PyLong_Type), \
+ .long_value = { \
+ .lv_tag = TAG_FROM_SIGN_AND_SIZE( \
+ (val) == 0 ? 0 : ((val) < 0 ? -1 : 1), \
+ (val) == 0 ? 0 : 1), \
+ { ((val) >= 0 ? (val) : -(val)) }, \
+ } \
+ }
+
+#define _PyLong_FALSE_TAG TAG_FROM_SIGN_AND_SIZE(0, 0)
+#define _PyLong_TRUE_TAG TAG_FROM_SIGN_AND_SIZE(1, 1)
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index d6bbafd..e18e7874 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -137,8 +137,9 @@ static inline void
_PyObject_InitVar(PyVarObject *op, PyTypeObject *typeobj, Py_ssize_t size)
{
assert(op != NULL);
- Py_SET_SIZE(op, size);
+ assert(typeobj != &PyLong_Type);
_PyObject_Init((PyObject *)op, typeobj);
+ Py_SET_SIZE(op, size);
}
diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h
index bdecac9..7cfa7c0 100644
--- a/Include/internal/pycore_runtime_init.h
+++ b/Include/internal/pycore_runtime_init.h
@@ -8,6 +8,7 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif
+#include "pycore_long.h"
#include "pycore_object.h"
#include "pycore_parser.h"
#include "pycore_pymem_init.h"
@@ -130,15 +131,6 @@ extern PyTypeObject _PyExc_MemoryError;
// global objects
-#define _PyLong_DIGIT_INIT(val) \
- { \
- .ob_base = _PyObject_IMMORTAL_INIT(&PyLong_Type), \
- .long_value = { \
- ((val) == 0 ? 0 : ((val) > 0 ? 1 : -1)), \
- { ((val) >= 0 ? (val) : -(val)) }, \
- } \
- }
-
#define _PyBytes_SIMPLE_INIT(CH, LEN) \
{ \
_PyVarObject_IMMORTAL_INIT(&PyBytes_Type, (LEN)), \
diff --git a/Include/object.h b/Include/object.h
index fc57735..2943a60 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -138,8 +138,13 @@ static inline PyTypeObject* Py_TYPE(PyObject *ob) {
# define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
#endif
+PyAPI_DATA(PyTypeObject) PyLong_Type;
+PyAPI_DATA(PyTypeObject) PyBool_Type;
+
// bpo-39573: The Py_SET_SIZE() function must be used to set an object size.
static inline Py_ssize_t Py_SIZE(PyObject *ob) {
+ assert(ob->ob_type != &PyLong_Type);
+ assert(ob->ob_type != &PyBool_Type);
PyVarObject *var_ob = _PyVarObject_CAST(ob);
return var_ob->ob_size;
}
@@ -171,8 +176,9 @@ static inline void Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {
# define Py_SET_TYPE(ob, type) Py_SET_TYPE(_PyObject_CAST(ob), type)
#endif
-
static inline void Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) {
+ assert(ob->ob_base.ob_type != &PyLong_Type);
+ assert(ob->ob_base.ob_type != &PyBool_Type);
ob->ob_size = size;
}
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-03-06-10-02-22.gh-issue-101291.0FT2QS.rst b/Misc/NEWS.d/next/Core and Builtins/2023-03-06-10-02-22.gh-issue-101291.0FT2QS.rst
new file mode 100644
index 0000000..46f0f32
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2023-03-06-10-02-22.gh-issue-101291.0FT2QS.rst
@@ -0,0 +1,7 @@
+Rearrage bits in first field (after header) of PyLongObject.
+* Bits 0 and 1: 1 - sign. I.e. 0 for positive numbers, 1 for zero and 2 for negative numbers.
+* Bit 2 reserved (probably for the immortal bit)
+* Bits 3+ the unsigned size.
+
+This makes a few operations slightly more efficient, and will enable a more
+compact and faster 2s-complement representation of most ints in future.
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
index 5936fba..0e11c87 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -30,6 +30,7 @@
#endif
#include <Python.h>
+#include "pycore_long.h" // _PyLong_IsZero()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "complexobject.h"
#include "mpdecimal.h"
@@ -2146,35 +2147,25 @@ dec_from_long(PyTypeObject *type, PyObject *v,
{
PyObject *dec;
PyLongObject *l = (PyLongObject *)v;
- Py_ssize_t ob_size;
- size_t len;
- uint8_t sign;
dec = PyDecType_New(type);
if (dec == NULL) {
return NULL;
}
- ob_size = Py_SIZE(l);
- if (ob_size == 0) {
+ if (_PyLong_IsZero(l)) {
_dec_settriple(dec, MPD_POS, 0, 0);
return dec;
}
- if (ob_size < 0) {
- len = -ob_size;
- sign = MPD_NEG;
- }
- else {
- len = ob_size;
- sign = MPD_POS;
- }
+ uint8_t sign = _PyLong_IsNegative(l) ? MPD_NEG : MPD_POS;
- if (len == 1) {
- _dec_settriple(dec, sign, *l->long_value.ob_digit, 0);
+ if (_PyLong_IsCompact(l)) {
+ _dec_settriple(dec, sign, l->long_value.ob_digit[0], 0);
mpd_qfinalize(MPD(dec), ctx, status);
return dec;
}
+ size_t len = _PyLong_DigitCount(l);
#if PYLONG_BITS_IN_DIGIT == 30
mpd_qimport_u32(MPD(dec), l->long_value.ob_digit, len, sign, PyLong_BASE,
@@ -3482,7 +3473,6 @@ dec_as_long(PyObject *dec, PyObject *context, int round)
PyLongObject *pylong;
digit *ob_digit;
size_t n;
- Py_ssize_t i;
mpd_t *x;
mpd_context_t workctx;
uint32_t status = 0;
@@ -3536,26 +3526,9 @@ dec_as_long(PyObject *dec, PyObject *context, int round)
}
assert(n > 0);
- pylong = _PyLong_New(n);
- if (pylong == NULL) {
- mpd_free(ob_digit);
- mpd_del(x);
- return NULL;
- }
-
- memcpy(pylong->long_value.ob_digit, ob_digit, n * sizeof(digit));
+ assert(!mpd_iszero(x));
+ pylong = _PyLong_FromDigits(mpd_isnegative(x), n, ob_digit);
mpd_free(ob_digit);
-
- i = n;
- while ((i > 0) && (pylong->long_value.ob_digit[i-1] == 0)) {
- i--;
- }
-
- Py_SET_SIZE(pylong, i);
- if (mpd_isnegative(x) && !mpd_iszero(x)) {
- Py_SET_SIZE(pylong, -i);
- }
-
mpd_del(x);
return (PyObject *) pylong;
}
diff --git a/Modules/_testcapi/mem.c b/Modules/_testcapi/mem.c
index ae3f7a4..af32e96 100644
--- a/Modules/_testcapi/mem.c
+++ b/Modules/_testcapi/mem.c
@@ -347,7 +347,7 @@ test_pyobject_new(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *obj;
PyTypeObject *type = &PyBaseObject_Type;
- PyTypeObject *var_type = &PyLong_Type;
+ PyTypeObject *var_type = &PyBytes_Type;
// PyObject_New()
obj = PyObject_New(PyObject, type);
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 1608939..606e578 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -32,6 +32,8 @@ Copyright (C) 1994 Steen Lumholt.
# include "pycore_fileutils.h" // _Py_stat()
#endif
+#include "pycore_long.h"
+
#ifdef MS_WINDOWS
#include <windows.h>
#endif
@@ -886,7 +888,8 @@ asBignumObj(PyObject *value)
const char *hexchars;
mp_int bigValue;
- neg = Py_SIZE(value) < 0;
+ assert(PyLong_Check(value));
+ neg = _PyLong_IsNegative((PyLongObject *)value);
hexstr = _PyLong_Format(value, 16);
if (hexstr == NULL)
return NULL;
@@ -1950,7 +1953,7 @@ _tkinter_tkapp_getboolean(TkappObject *self, PyObject *arg)
int v;
if (PyLong_Check(arg)) { /* int or bool */
- return PyBool_FromLong(Py_SIZE(arg) != 0);
+ return PyBool_FromLong(!_PyLong_IsZero((PyLongObject *)arg));
}
if (PyTclObject_Check(arg)) {
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 473936e..eddc1a3 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -836,7 +836,7 @@ long_lcm(PyObject *a, PyObject *b)
{
PyObject *g, *m, *f, *ab;
- if (Py_SIZE(a) == 0 || Py_SIZE(b) == 0) {
+ if (_PyLong_IsZero((PyLongObject *)a) || _PyLong_IsZero((PyLongObject *)b)) {
return PyLong_FromLong(0);
}
g = _PyLong_GCD(a, b);
@@ -1726,13 +1726,13 @@ math_isqrt(PyObject *module, PyObject *n)
return NULL;
}
- if (_PyLong_Sign(n) < 0) {
+ if (_PyLong_IsNegative((PyLongObject *)n)) {
PyErr_SetString(
PyExc_ValueError,
"isqrt() argument must be nonnegative");
goto error;
}
- if (_PyLong_Sign(n) == 0) {
+ if (_PyLong_IsZero((PyLongObject *)n)) {
Py_DECREF(n);
return PyLong_FromLong(0);
}
@@ -2254,7 +2254,7 @@ loghelper(PyObject* arg, double (*func)(double))
Py_ssize_t e;
/* Negative or zero inputs give a ValueError. */
- if (Py_SIZE(arg) <= 0) {
+ if (!_PyLong_IsPositive((PyLongObject *)arg)) {
PyErr_SetString(PyExc_ValueError,
"math domain error");
return NULL;
@@ -3716,12 +3716,12 @@ math_perm_impl(PyObject *module, PyObject *n, PyObject *k)
}
assert(PyLong_CheckExact(n) && PyLong_CheckExact(k));
- if (Py_SIZE(n) < 0) {
+ if (_PyLong_IsNegative((PyLongObject *)n)) {
PyErr_SetString(PyExc_ValueError,
"n must be a non-negative integer");
goto error;
}
- if (Py_SIZE(k) < 0) {
+ if (_PyLong_IsNegative((PyLongObject *)k)) {
PyErr_SetString(PyExc_ValueError,
"k must be a non-negative integer");
goto error;
@@ -3808,12 +3808,12 @@ math_comb_impl(PyObject *module, PyObject *n, PyObject *k)
}
assert(PyLong_CheckExact(n) && PyLong_CheckExact(k));
- if (Py_SIZE(n) < 0) {
+ if (_PyLong_IsNegative((PyLongObject *)n)) {
PyErr_SetString(PyExc_ValueError,
"n must be a non-negative integer");
goto error;
}
- if (Py_SIZE(k) < 0) {
+ if (_PyLong_IsNegative((PyLongObject *)k)) {
PyErr_SetString(PyExc_ValueError,
"k must be a non-negative integer");
goto error;
@@ -3845,7 +3845,8 @@ math_comb_impl(PyObject *module, PyObject *n, PyObject *k)
if (temp == NULL) {
goto error;
}
- if (Py_SIZE(temp) < 0) {
+ assert(PyLong_Check(temp));
+ if (_PyLong_IsNegative((PyLongObject *)temp)) {
Py_DECREF(temp);
result = PyLong_FromLong(0);
goto done;
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 9dc74fb..e957859 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -5,6 +5,7 @@
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _Py_EnterRecursiveCallTstate()
#include "pycore_object.h" // _Py_CheckSlotResult()
+#include "pycore_long.h" // _Py_IsNegative
#include "pycore_pyerrors.h" // _PyErr_Occurred()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_unionobject.h" // _PyUnion_Check()
@@ -1483,7 +1484,7 @@ PyNumber_AsSsize_t(PyObject *item, PyObject *err)
/* Whether or not it is less than or equal to
zero is determined by the sign of ob_size
*/
- if (_PyLong_Sign(value) < 0)
+ if (_PyLong_IsNegative((PyLongObject *)value))
result = PY_SSIZE_T_MIN;
else
result = PY_SSIZE_T_MAX;
diff --git a/Objects/boolobject.c b/Objects/boolobject.c
index a035f46..9d8e956 100644
--- a/Objects/boolobject.c
+++ b/Objects/boolobject.c
@@ -2,6 +2,7 @@
#include "Python.h"
#include "pycore_object.h" // _Py_FatalRefcountError()
+#include "pycore_long.h" // FALSE_TAG TRUE_TAG
#include "pycore_runtime.h" // _Py_ID()
#include <stddef.h>
@@ -198,10 +199,14 @@ PyTypeObject PyBool_Type = {
struct _longobject _Py_FalseStruct = {
PyObject_HEAD_INIT(&PyBool_Type)
- { 0, { 0 } }
+ { .lv_tag = _PyLong_FALSE_TAG,
+ { 0 }
+ }
};
struct _longobject _Py_TrueStruct = {
PyObject_HEAD_INIT(&PyBool_Type)
- { 1, { 1 } }
+ { .lv_tag = _PyLong_TRUE_TAG,
+ { 1 }
+ }
};
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 1a210e7..f1edfb3 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -4,6 +4,7 @@
#include "pycore_abstract.h" // _PyIndex_Check()
#include "pycore_interp.h" // PyInterpreterState.list
#include "pycore_list.h" // struct _Py_list_state, _PyListIterObject
+#include "pycore_long.h" // _PyLong_DigitCount
#include "pycore_object.h" // _PyObject_GC_TRACK()
#include "pycore_tuple.h" // _PyTuple_FromArray()
#include <stddef.h>
@@ -2144,24 +2145,21 @@ unsafe_latin_compare(PyObject *v, PyObject *w, MergeState *ms)
static int
unsafe_long_compare(PyObject *v, PyObject *w, MergeState *ms)
{
- PyLongObject *vl, *wl; sdigit v0, w0; int res;
+ PyLongObject *vl, *wl;
+ intptr_t v0, w0;
+ int res;
/* Modified from Objects/longobject.c:long_compare, assuming: */
assert(Py_IS_TYPE(v, &PyLong_Type));
assert(Py_IS_TYPE(w, &PyLong_Type));
- assert(Py_ABS(Py_SIZE(v)) <= 1);
- assert(Py_ABS(Py_SIZE(w)) <= 1);
+ assert(_PyLong_IsCompact((PyLongObject *)v));
+ assert(_PyLong_IsCompact((PyLongObject *)w));
vl = (PyLongObject*)v;
wl = (PyLongObject*)w;
- v0 = Py_SIZE(vl) == 0 ? 0 : (sdigit)vl->long_value.ob_digit[0];
- w0 = Py_SIZE(wl) == 0 ? 0 : (sdigit)wl->long_value.ob_digit[0];
-
- if (Py_SIZE(vl) < 0)
- v0 = -v0;
- if (Py_SIZE(wl) < 0)
- w0 = -w0;
+ v0 = _PyLong_CompactValue(vl);
+ w0 = _PyLong_CompactValue(wl);
res = v0 < w0;
assert(res == PyObject_RichCompareBool(v, w, Py_LT));
@@ -2359,7 +2357,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
if (keys_are_all_same_type) {
if (key_type == &PyLong_Type &&
ints_are_bounded &&
- Py_ABS(Py_SIZE(key)) > 1) {
+ !_PyLong_IsCompact((PyLongObject *)key)) {
ints_are_bounded = 0;
}
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 51655cd..bb4eac0 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -6,7 +6,7 @@
#include "pycore_bitutils.h" // _Py_popcount32()
#include "pycore_initconfig.h" // _PyStatus_OK()
#include "pycore_long.h" // _Py_SmallInts
-#include "pycore_object.h" // _PyObject_InitVar()
+#include "pycore_object.h" // _PyObject_Init()
#include "pycore_pystate.h" // _Py_IsMainInterpreter()
#include "pycore_runtime.h" // _PY_NSMALLPOSINTS
#include "pycore_structseq.h" // _PyStructSequence_FiniType()
@@ -22,16 +22,7 @@ class int "PyObject *" "&PyLong_Type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=ec0275e3422a36e3]*/
-/* Is this PyLong of size 1, 0 or -1? */
-#define IS_MEDIUM_VALUE(x) (((size_t)Py_SIZE(x)) + 1U < 3U)
-
-/* convert a PyLong of size 1, 0 or -1 to a C integer */
-static inline stwodigits
-medium_value(PyLongObject *x)
-{
- assert(IS_MEDIUM_VALUE(x));
- return ((stwodigits)Py_SIZE(x)) * x->long_value.ob_digit[0];
-}
+#define medium_value(x) ((stwodigits)_PyLong_CompactValue(x))
#define IS_SMALL_INT(ival) (-_PY_NSMALLNEGINTS <= (ival) && (ival) < _PY_NSMALLPOSINTS)
#define IS_SMALL_UINT(ival) ((ival) < _PY_NSMALLPOSINTS)
@@ -68,7 +59,7 @@ get_small_int(sdigit ival)
static PyLongObject *
maybe_small_long(PyLongObject *v)
{
- if (v && IS_MEDIUM_VALUE(v)) {
+ if (v && _PyLong_IsCompact(v)) {
stwodigits ival = medium_value(v);
if (IS_SMALL_INT(ival)) {
_Py_DECREF_INT(v);
@@ -126,13 +117,18 @@ maybe_small_long(PyLongObject *v)
static PyLongObject *
long_normalize(PyLongObject *v)
{
- Py_ssize_t j = Py_ABS(Py_SIZE(v));
+ Py_ssize_t j = _PyLong_DigitCount(v);
Py_ssize_t i = j;
while (i > 0 && v->long_value.ob_digit[i-1] == 0)
--i;
if (i != j) {
- Py_SET_SIZE(v, (Py_SIZE(v) < 0) ? -(i) : i);
+ if (i == 0) {
+ _PyLong_SetSignAndDigitCount(v, 0, 0);
+ }
+ else {
+ _PyLong_SetDigitCount(v, i);
+ }
}
return v;
}
@@ -146,6 +142,7 @@ long_normalize(PyLongObject *v)
PyLongObject *
_PyLong_New(Py_ssize_t size)
{
+ assert(size >= 0);
PyLongObject *result;
if (size > (Py_ssize_t)MAX_LONG_DIGITS) {
PyErr_SetString(PyExc_OverflowError,
@@ -157,8 +154,8 @@ _PyLong_New(Py_ssize_t size)
Py_ssize_t ndigits = size ? size : 1;
/* Number of bytes needed is: offsetof(PyLongObject, ob_digit) +
sizeof(digit)*size. Previous incarnations of this code used
- sizeof(PyVarObject) instead of the offsetof, but this risks being
- incorrect in the presence of padding between the PyVarObject header
+ sizeof() instead of the offsetof, but this risks being
+ incorrect in the presence of padding between the header
and the digits. */
result = PyObject_Malloc(offsetof(PyLongObject, long_value.ob_digit) +
ndigits*sizeof(digit));
@@ -166,34 +163,41 @@ _PyLong_New(Py_ssize_t size)
PyErr_NoMemory();
return NULL;
}
- _PyObject_InitVar((PyVarObject*)result, &PyLong_Type, size);
+ _PyLong_SetSignAndDigitCount(result, size != 0, size);
+ _PyObject_Init((PyObject*)result, &PyLong_Type);
+ return result;
+}
+
+PyLongObject *
+_PyLong_FromDigits(int negative, Py_ssize_t digit_count, digit *digits)
+{
+ assert(digit_count >= 0);
+ if (digit_count == 0) {
+ return (PyLongObject *)Py_NewRef(_PyLong_GetZero());
+ }
+ PyLongObject *result = _PyLong_New(digit_count);
+ if (result == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ _PyLong_SetSignAndDigitCount(result, negative?-1:1, digit_count);
+ memcpy(result->long_value.ob_digit, digits, digit_count * sizeof(digit));
return result;
}
PyObject *
_PyLong_Copy(PyLongObject *src)
{
- PyLongObject *result;
- Py_ssize_t i;
-
assert(src != NULL);
- i = Py_SIZE(src);
- if (i < 0)
- i = -(i);
- if (i < 2) {
+
+ if (_PyLong_IsCompact(src)) {
stwodigits ival = medium_value(src);
if (IS_SMALL_INT(ival)) {
return get_small_int((sdigit)ival);
}
}
- result = _PyLong_New(i);
- if (result != NULL) {
- Py_SET_SIZE(result, Py_SIZE(src));
- while (--i >= 0) {
- result->long_value.ob_digit[i] = src->long_value.ob_digit[i];
- }
- }
- return (PyObject *)result;
+ Py_ssize_t size = _PyLong_DigitCount(src);
+ return (PyObject *)_PyLong_FromDigits(_PyLong_IsNegative(src), size, src->long_value.ob_digit);
}
static PyObject *
@@ -207,9 +211,9 @@ _PyLong_FromMedium(sdigit x)
PyErr_NoMemory();
return NULL;
}
- Py_ssize_t sign = x < 0 ? -1: 1;
digit abs_x = x < 0 ? -x : x;
- _PyObject_InitVar((PyVarObject*)v, &PyLong_Type, sign);
+ _PyLong_SetSignAndDigitCount(v, x<0?-1:1, 1);
+ _PyObject_Init((PyObject*)v, &PyLong_Type);
v->long_value.ob_digit[0] = abs_x;
return (PyObject*)v;
}
@@ -242,7 +246,7 @@ _PyLong_FromLarge(stwodigits ival)
PyLongObject *v = _PyLong_New(ndigits);
if (v != NULL) {
digit *p = v->long_value.ob_digit;
- Py_SET_SIZE(v, ndigits * sign);
+ _PyLong_SetSignAndDigitCount(v, sign, ndigits);
t = abs_ival;
while (t) {
*p++ = Py_SAFE_DOWNCAST(
@@ -267,38 +271,6 @@ _PyLong_FromSTwoDigits(stwodigits x)
return _PyLong_FromLarge(x);
}
-int
-_PyLong_AssignValue(PyObject **target, Py_ssize_t value)
-{
- PyObject *old = *target;
- if (IS_SMALL_INT(value)) {
- *target = get_small_int(Py_SAFE_DOWNCAST(value, Py_ssize_t, sdigit));
- Py_XDECREF(old);
- return 0;
- }
- else if (old != NULL && PyLong_CheckExact(old) &&
- Py_REFCNT(old) == 1 && Py_SIZE(old) == 1 &&
- (size_t)value <= PyLong_MASK)
- {
- // Mutate in place if there are no other references the old
- // object. This avoids an allocation in a common case.
- // Since the primary use-case is iterating over ranges, which
- // are typically positive, only do this optimization
- // for positive integers (for now).
- ((PyLongObject *)old)->long_value.ob_digit[0] =
- Py_SAFE_DOWNCAST(value, Py_ssize_t, digit);
- return 0;
- }
- else {
- *target = PyLong_FromSsize_t(value);
- Py_XDECREF(old);
- if (*target == NULL) {
- return -1;
- }
- return 0;
- }
-}
-
/* If a freshly-allocated int is already shared, it must
be a small integer, so negating it must go to PyLong_FromLong */
Py_LOCAL_INLINE(void)
@@ -308,7 +280,7 @@ _PyLong_Negate(PyLongObject **x_p)
x = (PyLongObject *)*x_p;
if (Py_REFCNT(x) == 1) {
- Py_SET_SIZE(x, -Py_SIZE(x));
+ _PyLong_FlipSign(x);
return;
}
@@ -347,7 +319,7 @@ PyLong_FromLong(long ival)
v = _PyLong_New(ndigits);
if (v != NULL) {
digit *p = v->long_value.ob_digit;
- Py_SET_SIZE(v, ival < 0 ? -ndigits : ndigits);
+ _PyLong_SetSignAndDigitCount(v, ival < 0 ? -1 : 1, ndigits);
t = abs_ival;
while (t) {
*p++ = (digit)(t & PyLong_MASK);
@@ -457,7 +429,7 @@ PyLong_FromDouble(double dval)
frac = ldexp(frac, PyLong_SHIFT);
}
if (neg) {
- Py_SET_SIZE(v, -(Py_SIZE(v)));
+ _PyLong_FlipSign(v);
}
return (PyObject *)v;
}
@@ -510,27 +482,22 @@ PyLong_AsLongAndOverflow(PyObject *vv, int *overflow)
return -1;
do_decref = 1;
}
-
- res = -1;
- i = Py_SIZE(v);
-
- switch (i) {
- case -1:
- res = -(sdigit)v->long_value.ob_digit[0];
- break;
- case 0:
- res = 0;
- break;
- case 1:
- res = v->long_value.ob_digit[0];
- break;
- default:
- sign = 1;
- x = 0;
- if (i < 0) {
- sign = -1;
- i = -(i);
+ if (_PyLong_IsCompact(v)) {
+#if SIZEOF_LONG < SIZEOF_VOID_P
+ intptr_t tmp = _PyLong_CompactValue(v);
+ res = (long)tmp;
+ if (res != tmp) {
+ *overflow = tmp < 0 ? -1 : 1;
}
+#else
+ res = _PyLong_CompactValue(v);
+#endif
+ }
+ else {
+ res = -1;
+ i = _PyLong_DigitCount(v);
+ sign = _PyLong_NonCompactSign(v);
+ x = 0;
while (--i >= 0) {
prev = x;
x = (x << PyLong_SHIFT) | v->long_value.ob_digit[i];
@@ -540,8 +507,8 @@ PyLong_AsLongAndOverflow(PyObject *vv, int *overflow)
}
}
/* Haven't lost any bits, but casting to long requires extra
- * care (see comment above).
- */
+ * care (see comment above).
+ */
if (x <= (unsigned long)LONG_MAX) {
res = (long)x * sign;
}
@@ -615,18 +582,12 @@ PyLong_AsSsize_t(PyObject *vv) {
}
v = (PyLongObject *)vv;
- i = Py_SIZE(v);
- switch (i) {
- case -1: return -(sdigit)v->long_value.ob_digit[0];
- case 0: return 0;
- case 1: return v->long_value.ob_digit[0];
+ if (_PyLong_IsCompact(v)) {
+ return _PyLong_CompactValue(v);
}
- sign = 1;
+ i = _PyLong_DigitCount(v);
+ sign = _PyLong_NonCompactSign(v);
x = 0;
- if (i < 0) {
- sign = -1;
- i = -(i);
- }
while (--i >= 0) {
prev = x;
x = (x << PyLong_SHIFT) | v->long_value.ob_digit[i];
@@ -670,28 +631,37 @@ PyLong_AsUnsignedLong(PyObject *vv)
}
v = (PyLongObject *)vv;
- i = Py_SIZE(v);
- x = 0;
- if (i < 0) {
+ if (_PyLong_IsNonNegativeCompact(v)) {
+#if SIZEOF_LONG < SIZEOF_VOID_P
+ intptr_t tmp = _PyLong_CompactValue(v);
+ unsigned long res = (unsigned long)tmp;
+ if (res != tmp) {
+ goto overflow;
+ }
+#else
+ return _PyLong_CompactValue(v);
+#endif
+ }
+ if (_PyLong_IsNegative(v)) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to unsigned int");
return (unsigned long) -1;
}
- switch (i) {
- case 0: return 0;
- case 1: return v->long_value.ob_digit[0];
- }
+ i = _PyLong_DigitCount(v);
+ x = 0;
while (--i >= 0) {
prev = x;
x = (x << PyLong_SHIFT) | v->long_value.ob_digit[i];
if ((x >> PyLong_SHIFT) != prev) {
- PyErr_SetString(PyExc_OverflowError,
- "Python int too large to convert "
- "to C unsigned long");
- return (unsigned long) -1;
+ goto overflow;
}
}
return x;
+overflow:
+ PyErr_SetString(PyExc_OverflowError,
+ "Python int too large to convert "
+ "to C unsigned long");
+ return (unsigned long) -1;
}
/* Get a C size_t from an int object. Returns (size_t)-1 and sets
@@ -714,17 +684,16 @@ PyLong_AsSize_t(PyObject *vv)
}
v = (PyLongObject *)vv;
- i = Py_SIZE(v);
- x = 0;
- if (i < 0) {
+ if (_PyLong_IsNonNegativeCompact(v)) {
+ return _PyLong_CompactValue(v);
+ }
+ if (_PyLong_IsNegative(v)) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to size_t");
return (size_t) -1;
}
- switch (i) {
- case 0: return 0;
- case 1: return v->long_value.ob_digit[0];
- }
+ i = _PyLong_DigitCount(v);
+ x = 0;
while (--i >= 0) {
prev = x;
x = (x << PyLong_SHIFT) | v->long_value.ob_digit[i];
@@ -746,24 +715,18 @@ _PyLong_AsUnsignedLongMask(PyObject *vv)
PyLongObject *v;
unsigned long x;
Py_ssize_t i;
- int sign;
if (vv == NULL || !PyLong_Check(vv)) {
PyErr_BadInternalCall();
return (unsigned long) -1;
}
v = (PyLongObject *)vv;
- i = Py_SIZE(v);
- switch (i) {
- case 0: return 0;
- case 1: return v->long_value.ob_digit[0];
+ if (_PyLong_IsCompact(v)) {
+ return (unsigned long)_PyLong_CompactValue(v);
}
- sign = 1;
+ i = _PyLong_DigitCount(v);
+ int sign = _PyLong_NonCompactSign(v);
x = 0;
- if (i < 0) {
- sign = -1;
- i = -i;
- }
while (--i >= 0) {
x = (x << PyLong_SHIFT) | v->long_value.ob_digit[i];
}
@@ -801,8 +764,10 @@ _PyLong_Sign(PyObject *vv)
assert(v != NULL);
assert(PyLong_Check(v));
-
- return Py_SIZE(v) == 0 ? 0 : (Py_SIZE(v) < 0 ? -1 : 1);
+ if (_PyLong_IsCompact(v)) {
+ return _PyLong_CompactSign(v);
+ }
+ return _PyLong_NonCompactSign(v);
}
static int
@@ -825,7 +790,7 @@ _PyLong_NumBits(PyObject *vv)
assert(v != NULL);
assert(PyLong_Check(v));
- ndigits = Py_ABS(Py_SIZE(v));
+ ndigits = _PyLong_DigitCount(v);
assert(ndigits == 0 || v->long_value.ob_digit[ndigits - 1] != 0);
if (ndigits > 0) {
digit msd = v->long_value.ob_digit[ndigits - 1];
@@ -952,7 +917,11 @@ _PyLong_FromByteArray(const unsigned char* bytes, size_t n,
}
}
- Py_SET_SIZE(v, is_signed ? -idigit : idigit);
+ int sign = is_signed ? -1: 1;
+ if (idigit == 0) {
+ sign = 0;
+ }
+ _PyLong_SetSignAndDigitCount(v, sign, idigit);
return (PyObject *)maybe_small_long(long_normalize(v));
}
@@ -962,7 +931,7 @@ _PyLong_AsByteArray(PyLongObject* v,
int little_endian, int is_signed)
{
Py_ssize_t i; /* index into v->long_value.ob_digit */
- Py_ssize_t ndigits; /* |v->ob_size| */
+ Py_ssize_t ndigits; /* number of digits */
twodigits accum; /* sliding register */
unsigned int accumbits; /* # bits in accum */
int do_twos_comp; /* store 2's-comp? is_signed and v < 0 */
@@ -973,8 +942,8 @@ _PyLong_AsByteArray(PyLongObject* v,
assert(v != NULL && PyLong_Check(v));
- if (Py_SIZE(v) < 0) {
- ndigits = -(Py_SIZE(v));
+ ndigits = _PyLong_DigitCount(v);
+ if (_PyLong_IsNegative(v)) {
if (!is_signed) {
PyErr_SetString(PyExc_OverflowError,
"can't convert negative int to unsigned");
@@ -983,7 +952,6 @@ _PyLong_AsByteArray(PyLongObject* v,
do_twos_comp = 1;
}
else {
- ndigits = Py_SIZE(v);
do_twos_comp = 0;
}
@@ -1114,10 +1082,12 @@ PyLong_AsVoidPtr(PyObject *vv)
#if SIZEOF_VOID_P <= SIZEOF_LONG
long x;
- if (PyLong_Check(vv) && _PyLong_Sign(vv) < 0)
+ if (PyLong_Check(vv) && _PyLong_IsNegative((PyLongObject *)vv)) {
x = PyLong_AsLong(vv);
- else
+ }
+ else {
x = PyLong_AsUnsignedLong(vv);
+ }
#else
#if SIZEOF_LONG_LONG < SIZEOF_VOID_P
@@ -1125,10 +1095,12 @@ PyLong_AsVoidPtr(PyObject *vv)
#endif
long long x;
- if (PyLong_Check(vv) && _PyLong_Sign(vv) < 0)
+ if (PyLong_Check(vv) && _PyLong_IsNegative((PyLongObject *)vv)) {
x = PyLong_AsLongLong(vv);
- else
+ }
+ else {
x = PyLong_AsUnsignedLongLong(vv);
+ }
#endif /* SIZEOF_VOID_P <= SIZEOF_LONG */
@@ -1174,7 +1146,7 @@ PyLong_FromLongLong(long long ival)
v = _PyLong_New(ndigits);
if (v != NULL) {
digit *p = v->long_value.ob_digit;
- Py_SET_SIZE(v, ival < 0 ? -ndigits : ndigits);
+ _PyLong_SetSignAndDigitCount(v, ival < 0 ? -1 : 1, ndigits);
t = abs_ival;
while (t) {
*p++ = (digit)(t & PyLong_MASK);
@@ -1217,7 +1189,7 @@ PyLong_FromSsize_t(Py_ssize_t ival)
v = _PyLong_New(ndigits);
if (v != NULL) {
digit *p = v->long_value.ob_digit;
- Py_SET_SIZE(v, negative ? -ndigits : ndigits);
+ _PyLong_SetSignAndDigitCount(v, negative ? -1 : 1, ndigits);
t = abs_ival;
while (t) {
*p++ = (digit)(t & PyLong_MASK);
@@ -1253,18 +1225,11 @@ PyLong_AsLongLong(PyObject *vv)
do_decref = 1;
}
- res = 0;
- switch(Py_SIZE(v)) {
- case -1:
- bytes = -(sdigit)v->long_value.ob_digit[0];
- break;
- case 0:
- bytes = 0;
- break;
- case 1:
- bytes = v->long_value.ob_digit[0];
- break;
- default:
+ if (_PyLong_IsCompact(v)) {
+ res = 0;
+ bytes = _PyLong_CompactValue(v);
+ }
+ else {
res = _PyLong_AsByteArray((PyLongObject *)v, (unsigned char *)&bytes,
SIZEOF_LONG_LONG, PY_LITTLE_ENDIAN, 1);
}
@@ -1299,13 +1264,14 @@ PyLong_AsUnsignedLongLong(PyObject *vv)
}
v = (PyLongObject*)vv;
- switch(Py_SIZE(v)) {
- case 0: return 0;
- case 1: return v->long_value.ob_digit[0];
+ if (_PyLong_IsNonNegativeCompact(v)) {
+ res = 0;
+ bytes = _PyLong_CompactValue(v);
}
-
- res = _PyLong_AsByteArray((PyLongObject *)vv, (unsigned char *)&bytes,
+ else {
+ res = _PyLong_AsByteArray((PyLongObject *)vv, (unsigned char *)&bytes,
SIZEOF_LONG_LONG, PY_LITTLE_ENDIAN, 0);
+ }
/* Plan 9 can't handle long long in ? : expressions */
if (res < 0)
@@ -1330,17 +1296,12 @@ _PyLong_AsUnsignedLongLongMask(PyObject *vv)
return (unsigned long long) -1;
}
v = (PyLongObject *)vv;
- switch(Py_SIZE(v)) {
- case 0: return 0;
- case 1: return v->long_value.ob_digit[0];
+ if (_PyLong_IsCompact(v)) {
+ return (unsigned long long)(signed long long)_PyLong_CompactValue(v);
}
- i = Py_SIZE(v);
- sign = 1;
+ i = _PyLong_DigitCount(v);
+ sign = _PyLong_NonCompactSign(v);
x = 0;
- if (i < 0) {
- sign = -1;
- i = -i;
- }
while (--i >= 0) {
x = (x << PyLong_SHIFT) | v->long_value.ob_digit[i];
}
@@ -1407,32 +1368,19 @@ PyLong_AsLongLongAndOverflow(PyObject *vv, int *overflow)
return -1;
do_decref = 1;
}
-
- res = -1;
- i = Py_SIZE(v);
-
- switch (i) {
- case -1:
- res = -(sdigit)v->long_value.ob_digit[0];
- break;
- case 0:
- res = 0;
- break;
- case 1:
- res = v->long_value.ob_digit[0];
- break;
- default:
- sign = 1;
+ if (_PyLong_IsCompact(v)) {
+ res = _PyLong_CompactValue(v);
+ }
+ else {
+ i = _PyLong_DigitCount(v);
+ sign = _PyLong_NonCompactSign(v);
x = 0;
- if (i < 0) {
- sign = -1;
- i = -(i);
- }
while (--i >= 0) {
prev = x;
x = (x << PyLong_SHIFT) + v->long_value.ob_digit[i];
if ((x >> PyLong_SHIFT) != prev) {
*overflow = sign;
+ res = -1;
goto exit;
}
}
@@ -1447,7 +1395,7 @@ PyLong_AsLongLongAndOverflow(PyObject *vv, int *overflow)
}
else {
*overflow = sign;
- /* res is already set to -1 */
+ res = -1;
}
}
exit:
@@ -1462,7 +1410,7 @@ _PyLong_UnsignedShort_Converter(PyObject *obj, void *ptr)
{
unsigned long uval;
- if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) {
+ if (PyLong_Check(obj) && _PyLong_IsNegative((PyLongObject *)obj)) {
PyErr_SetString(PyExc_ValueError, "value must be positive");
return 0;
}
@@ -1484,7 +1432,7 @@ _PyLong_UnsignedInt_Converter(PyObject *obj, void *ptr)
{
unsigned long uval;
- if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) {
+ if (PyLong_Check(obj) && _PyLong_IsNegative((PyLongObject *)obj)) {
PyErr_SetString(PyExc_ValueError, "value must be positive");
return 0;
}
@@ -1506,7 +1454,7 @@ _PyLong_UnsignedLong_Converter(PyObject *obj, void *ptr)
{
unsigned long uval;
- if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) {
+ if (PyLong_Check(obj) && _PyLong_IsNegative((PyLongObject *)obj)) {
PyErr_SetString(PyExc_ValueError, "value must be positive");
return 0;
}
@@ -1523,7 +1471,7 @@ _PyLong_UnsignedLongLong_Converter(PyObject *obj, void *ptr)
{
unsigned long long uval;
- if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) {
+ if (PyLong_Check(obj) && _PyLong_IsNegative((PyLongObject *)obj)) {
PyErr_SetString(PyExc_ValueError, "value must be positive");
return 0;
}
@@ -1540,7 +1488,7 @@ _PyLong_Size_t_Converter(PyObject *obj, void *ptr)
{
size_t uval;
- if (PyLong_Check(obj) && _PyLong_Sign(obj) < 0) {
+ if (PyLong_Check(obj) && _PyLong_IsNegative((PyLongObject *)obj)) {
PyErr_SetString(PyExc_ValueError, "value must be positive");
return 0;
}
@@ -1694,7 +1642,7 @@ inplace_divrem1(digit *pout, digit *pin, Py_ssize_t size, digit n)
static PyLongObject *
divrem1(PyLongObject *a, digit n, digit *prem)
{
- const Py_ssize_t size = Py_ABS(Py_SIZE(a));
+ const Py_ssize_t size = _PyLong_DigitCount(a);
PyLongObject *z;
assert(n > 0 && n <= PyLong_MASK);
@@ -1726,7 +1674,7 @@ inplace_rem1(digit *pin, Py_ssize_t size, digit n)
static PyLongObject *
rem1(PyLongObject *a, digit n)
{
- const Py_ssize_t size = Py_ABS(Py_SIZE(a));
+ const Py_ssize_t size = _PyLong_DigitCount(a);
assert(n > 0 && n <= PyLong_MASK);
return (PyLongObject *)PyLong_FromLong(
@@ -1824,8 +1772,8 @@ long_to_decimal_string_internal(PyObject *aa,
PyErr_BadInternalCall();
return -1;
}
- size_a = Py_ABS(Py_SIZE(a));
- negative = Py_SIZE(a) < 0;
+ size_a = _PyLong_DigitCount(a);
+ negative = _PyLong_IsNegative(a);
/* quick and dirty pre-check for overflowing the decimal digit limit,
based on the inequality 10/3 >= log2(10)
@@ -2055,8 +2003,8 @@ long_format_binary(PyObject *aa, int base, int alternate,
PyErr_BadInternalCall();
return -1;
}
- size_a = Py_ABS(Py_SIZE(a));
- negative = Py_SIZE(a) < 0;
+ size_a = _PyLong_DigitCount(a);
+ negative = _PyLong_IsNegative(a);
/* Compute a rough upper bound for the length of the string */
switch (base) {
@@ -2532,7 +2480,7 @@ long_from_non_binary_base(const char *start, const char *end, Py_ssize_t digits,
*res = NULL;
return 0;
}
- Py_SET_SIZE(z, 0);
+ _PyLong_SetSignAndDigitCount(z, 0, 0);
/* `convwidth` consecutive input digits are treated as a single
* digit in base `convmultmax`.
@@ -2572,7 +2520,7 @@ long_from_non_binary_base(const char *start, const char *end, Py_ssize_t digits,
/* Multiply z by convmult, and add c. */
pz = z->long_value.ob_digit;
- pzstop = pz + Py_SIZE(z);
+ pzstop = pz + _PyLong_DigitCount(z);
for (; pz < pzstop; ++pz) {
c += (twodigits)*pz * convmult;
*pz = (digit)(c & PyLong_MASK);
@@ -2581,14 +2529,15 @@ long_from_non_binary_base(const char *start, const char *end, Py_ssize_t digits,
/* carry off the current end? */
if (c) {
assert(c < PyLong_BASE);
- if (Py_SIZE(z) < size_z) {
+ if (_PyLong_DigitCount(z) < size_z) {
*pz = (digit)c;
- Py_SET_SIZE(z, Py_SIZE(z) + 1);
+ assert(!_PyLong_IsNegative(z));
+ _PyLong_SetSignAndDigitCount(z, 1, _PyLong_DigitCount(z) + 1);
}
else {
PyLongObject *tmp;
/* Extremely rare. Get more space. */
- assert(Py_SIZE(z) == size_z);
+ assert(_PyLong_DigitCount(z) == size_z);
tmp = _PyLong_New(size_z + 1);
if (tmp == NULL) {
Py_DECREF(z);
@@ -2790,7 +2739,7 @@ PyLong_FromString(const char *str, char **pend, int base)
/* reset the base to 0, else the exception message
doesn't make too much sense */
base = 0;
- if (Py_SIZE(z) != 0) {
+ if (!_PyLong_IsZero(z)) {
goto onError;
}
/* there might still be other problems, therefore base
@@ -2799,7 +2748,7 @@ PyLong_FromString(const char *str, char **pend, int base)
/* Set sign and normalize */
if (sign < 0) {
- Py_SET_SIZE(z, -(Py_SIZE(z)));
+ _PyLong_FlipSign(z);
}
long_normalize(z);
z = maybe_small_long(z);
@@ -2891,7 +2840,7 @@ static int
long_divrem(PyLongObject *a, PyLongObject *b,
PyLongObject **pdiv, PyLongObject **prem)
{
- Py_ssize_t size_a = Py_ABS(Py_SIZE(a)), size_b = Py_ABS(Py_SIZE(b));
+ Py_ssize_t size_a = _PyLong_DigitCount(a), size_b = _PyLong_DigitCount(b);
PyLongObject *z;
if (size_b == 0) {
@@ -2932,14 +2881,14 @@ long_divrem(PyLongObject *a, PyLongObject *b,
The quotient z has the sign of a*b;
the remainder r has the sign of a,
so a = b*z + r. */
- if ((Py_SIZE(a) < 0) != (Py_SIZE(b) < 0)) {
+ if ((_PyLong_IsNegative(a)) != (_PyLong_IsNegative(b))) {
_PyLong_Negate(&z);
if (z == NULL) {
Py_CLEAR(*prem);
return -1;
}
}
- if (Py_SIZE(a) < 0 && Py_SIZE(*prem) != 0) {
+ if (_PyLong_IsNegative(a) && !_PyLong_IsZero(*prem)) {
_PyLong_Negate(prem);
if (*prem == NULL) {
Py_DECREF(z);
@@ -2956,7 +2905,7 @@ long_divrem(PyLongObject *a, PyLongObject *b,
static int
long_rem(PyLongObject *a, PyLongObject *b, PyLongObject **prem)
{
- Py_ssize_t size_a = Py_ABS(Py_SIZE(a)), size_b = Py_ABS(Py_SIZE(b));
+ Py_ssize_t size_a = _PyLong_DigitCount(a), size_b = _PyLong_DigitCount(b);
if (size_b == 0) {
PyErr_SetString(PyExc_ZeroDivisionError,
@@ -2983,7 +2932,7 @@ long_rem(PyLongObject *a, PyLongObject *b, PyLongObject **prem)
return -1;
}
/* Set the sign. */
- if (Py_SIZE(a) < 0 && Py_SIZE(*prem) != 0) {
+ if (_PyLong_IsNegative(a) && !_PyLong_IsZero(*prem)) {
_PyLong_Negate(prem);
if (*prem == NULL) {
Py_CLEAR(*prem);
@@ -2994,7 +2943,7 @@ long_rem(PyLongObject *a, PyLongObject *b, PyLongObject **prem)
}
/* Unsigned int division with remainder -- the algorithm. The arguments v1
- and w1 should satisfy 2 <= Py_ABS(Py_SIZE(w1)) <= Py_ABS(Py_SIZE(v1)). */
+ and w1 should satisfy 2 <= _PyLong_DigitCount(w1) <= _PyLong_DigitCount(v1). */
static PyLongObject *
x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
@@ -3014,8 +2963,8 @@ x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
that won't overflow a digit. */
/* allocate space; w will also be used to hold the final remainder */
- size_v = Py_ABS(Py_SIZE(v1));
- size_w = Py_ABS(Py_SIZE(w1));
+ size_v = _PyLong_DigitCount(v1);
+ size_w = _PyLong_DigitCount(w1);
assert(size_v >= size_w && size_w >= 2); /* Assert checks by div() */
v = _PyLong_New(size_v+1);
if (v == NULL) {
@@ -3154,7 +3103,7 @@ _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e)
multiple of 4, rounding ties to a multiple of 8. */
static const int half_even_correction[8] = {0, -1, -2, 1, 0, -1, 2, 1};
- a_size = Py_ABS(Py_SIZE(a));
+ a_size = _PyLong_DigitCount(a);
if (a_size == 0) {
/* Special case for 0: significand 0.0, exponent 0. */
*e = 0;
@@ -3240,7 +3189,7 @@ _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e)
}
*e = a_bits;
- return Py_SIZE(a) < 0 ? -dx : dx;
+ return _PyLong_IsNegative(a) ? -dx : dx;
overflow:
/* exponent > PY_SSIZE_T_MAX */
@@ -3267,7 +3216,7 @@ PyLong_AsDouble(PyObject *v)
PyErr_SetString(PyExc_TypeError, "an integer is required");
return -1.0;
}
- if (IS_MEDIUM_VALUE(v)) {
+ if (_PyLong_IsCompact((PyLongObject *)v)) {
/* Fast path; single digit long (31 bits) will cast safely
to double. This improves performance of FP/long operations
by 20%.
@@ -3292,9 +3241,12 @@ PyLong_AsDouble(PyObject *v)
static Py_ssize_t
long_compare(PyLongObject *a, PyLongObject *b)
{
- Py_ssize_t sign = Py_SIZE(a) - Py_SIZE(b);
+ if (_PyLong_BothAreCompact(a, b)) {
+ return _PyLong_CompactValue(a) - _PyLong_CompactValue(b);
+ }
+ Py_ssize_t sign = _PyLong_SignedDigitCount(a) - _PyLong_SignedDigitCount(b);
if (sign == 0) {
- Py_ssize_t i = Py_ABS(Py_SIZE(a));
+ Py_ssize_t i = _PyLong_DigitCount(a);
sdigit diff = 0;
while (--i >= 0) {
diff = (sdigit) a->long_value.ob_digit[i] - (sdigit) b->long_value.ob_digit[i];
@@ -3302,7 +3254,7 @@ long_compare(PyLongObject *a, PyLongObject *b)
break;
}
}
- sign = Py_SIZE(a) < 0 ? -diff : diff;
+ sign = _PyLong_IsNegative(a) ? -diff : diff;
}
return sign;
}
@@ -3326,18 +3278,16 @@ long_hash(PyLongObject *v)
Py_ssize_t i;
int sign;
- i = Py_SIZE(v);
- switch(i) {
- case -1: return v->long_value.ob_digit[0]==1 ? -2 : -(sdigit)v->long_value.ob_digit[0];
- case 0: return 0;
- case 1: return v->long_value.ob_digit[0];
+ if (_PyLong_IsCompact(v)) {
+ x = _PyLong_CompactValue(v);
+ if (x == (Py_uhash_t)-1) {
+ x = (Py_uhash_t)-2;
+ }
+ return x;
}
- sign = 1;
+ i = _PyLong_DigitCount(v);
+ sign = _PyLong_NonCompactSign(v);
x = 0;
- if (i < 0) {
- sign = -1;
- i = -(i);
- }
while (--i >= 0) {
/* Here x is a quantity in the range [0, _PyHASH_MODULUS); we
want to compute x * 2**PyLong_SHIFT + v->long_value.ob_digit[i] modulo
@@ -3382,7 +3332,7 @@ long_hash(PyLongObject *v)
static PyLongObject *
x_add(PyLongObject *a, PyLongObject *b)
{
- Py_ssize_t size_a = Py_ABS(Py_SIZE(a)), size_b = Py_ABS(Py_SIZE(b));
+ Py_ssize_t size_a = _PyLong_DigitCount(a), size_b = _PyLong_DigitCount(b);
PyLongObject *z;
Py_ssize_t i;
digit carry = 0;
@@ -3416,7 +3366,7 @@ x_add(PyLongObject *a, PyLongObject *b)
static PyLongObject *
x_sub(PyLongObject *a, PyLongObject *b)
{
- Py_ssize_t size_a = Py_ABS(Py_SIZE(a)), size_b = Py_ABS(Py_SIZE(b));
+ Py_ssize_t size_a = _PyLong_DigitCount(a), size_b = _PyLong_DigitCount(b);
PyLongObject *z;
Py_ssize_t i;
int sign = 1;
@@ -3462,7 +3412,7 @@ x_sub(PyLongObject *a, PyLongObject *b)
}
assert(borrow == 0);
if (sign < 0) {
- Py_SET_SIZE(z, -Py_SIZE(z));
+ _PyLong_FlipSign(z);
}
return maybe_small_long(long_normalize(z));
}
@@ -3470,13 +3420,13 @@ x_sub(PyLongObject *a, PyLongObject *b)
PyObject *
_PyLong_Add(PyLongObject *a, PyLongObject *b)
{
- if (IS_MEDIUM_VALUE(a) && IS_MEDIUM_VALUE(b)) {
+ if (_PyLong_BothAreCompact(a, b)) {
return _PyLong_FromSTwoDigits(medium_value(a) + medium_value(b));
}
PyLongObject *z;
- if (Py_SIZE(a) < 0) {
- if (Py_SIZE(b) < 0) {
+ if (_PyLong_IsNegative(a)) {
+ if (_PyLong_IsNegative(b)) {
z = x_add(a, b);
if (z != NULL) {
/* x_add received at least one multiple-digit int,
@@ -3484,14 +3434,14 @@ _PyLong_Add(PyLongObject *a, PyLongObject *b)
That also means z is not an element of
small_ints, so negating it in-place is safe. */
assert(Py_REFCNT(z) == 1);
- Py_SET_SIZE(z, -(Py_SIZE(z)));
+ _PyLong_FlipSign(z);
}
}
else
z = x_sub(b, a);
}
else {
- if (Py_SIZE(b) < 0)
+ if (_PyLong_IsNegative(b))
z = x_sub(a, b);
else
z = x_add(a, b);
@@ -3511,23 +3461,23 @@ _PyLong_Subtract(PyLongObject *a, PyLongObject *b)
{
PyLongObject *z;
- if (IS_MEDIUM_VALUE(a) && IS_MEDIUM_VALUE(b)) {
+ if (_PyLong_BothAreCompact(a, b)) {
return _PyLong_FromSTwoDigits(medium_value(a) - medium_value(b));
}
- if (Py_SIZE(a) < 0) {
- if (Py_SIZE(b) < 0) {
+ if (_PyLong_IsNegative(a)) {
+ if (_PyLong_IsNegative(b)) {
z = x_sub(b, a);
}
else {
z = x_add(a, b);
if (z != NULL) {
- assert(Py_SIZE(z) == 0 || Py_REFCNT(z) == 1);
- Py_SET_SIZE(z, -(Py_SIZE(z)));
+ assert(_PyLong_IsZero(z) || Py_REFCNT(z) == 1);
+ _PyLong_FlipSign(z);
}
}
}
else {
- if (Py_SIZE(b) < 0)
+ if (_PyLong_IsNegative(b))
z = x_add(a, b);
else
z = x_sub(a, b);
@@ -3549,15 +3499,15 @@ static PyLongObject *
x_mul(PyLongObject *a, PyLongObject *b)
{
PyLongObject *z;
- Py_ssize_t size_a = Py_ABS(Py_SIZE(a));
- Py_ssize_t size_b = Py_ABS(Py_SIZE(b));
+ Py_ssize_t size_a = _PyLong_DigitCount(a);
+ Py_ssize_t size_b = _PyLong_DigitCount(b);
Py_ssize_t i;
z = _PyLong_New(size_a + size_b);
if (z == NULL)
return NULL;
- memset(z->long_value.ob_digit, 0, Py_SIZE(z) * sizeof(digit));
+ memset(z->long_value.ob_digit, 0, _PyLong_DigitCount(z) * sizeof(digit));
if (a == b) {
/* Efficient squaring per HAC, Algorithm 14.16:
* http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf
@@ -3658,7 +3608,7 @@ kmul_split(PyLongObject *n,
{
PyLongObject *hi, *lo;
Py_ssize_t size_lo, size_hi;
- const Py_ssize_t size_n = Py_ABS(Py_SIZE(n));
+ const Py_ssize_t size_n = _PyLong_DigitCount(n);
size_lo = Py_MIN(size_n, size);
size_hi = size_n - size_lo;
@@ -3687,8 +3637,8 @@ static PyLongObject *k_lopsided_mul(PyLongObject *a, PyLongObject *b);
static PyLongObject *
k_mul(PyLongObject *a, PyLongObject *b)
{
- Py_ssize_t asize = Py_ABS(Py_SIZE(a));
- Py_ssize_t bsize = Py_ABS(Py_SIZE(b));
+ Py_ssize_t asize = _PyLong_DigitCount(a);
+ Py_ssize_t bsize = _PyLong_DigitCount(b);
PyLongObject *ah = NULL;
PyLongObject *al = NULL;
PyLongObject *bh = NULL;
@@ -3731,7 +3681,7 @@ k_mul(PyLongObject *a, PyLongObject *b)
/* If a is small compared to b, splitting on b gives a degenerate
* case with ah==0, and Karatsuba may be (even much) less efficient
* than "grade school" then. However, we can still win, by viewing
- * b as a string of "big digits", each of width a->ob_size. That
+ * b as a string of "big digits", each of the same width as a. That
* leads to a sequence of balanced calls to k_mul.
*/
if (2 * asize <= bsize)
@@ -3740,7 +3690,7 @@ k_mul(PyLongObject *a, PyLongObject *b)
/* Split a & b into hi & lo pieces. */
shift = bsize >> 1;
if (kmul_split(a, shift, &ah, &al) < 0) goto fail;
- assert(Py_SIZE(ah) > 0); /* the split isn't degenerate */
+ assert(_PyLong_IsPositive(ah)); /* the split isn't degenerate */
if (a == b) {
bh = (PyLongObject*)Py_NewRef(ah);
@@ -3769,20 +3719,20 @@ k_mul(PyLongObject *a, PyLongObject *b)
if (ret == NULL) goto fail;
#ifdef Py_DEBUG
/* Fill with trash, to catch reference to uninitialized digits. */
- memset(ret->long_value.ob_digit, 0xDF, Py_SIZE(ret) * sizeof(digit));
+ memset(ret->long_value.ob_digit, 0xDF, _PyLong_DigitCount(ret) * sizeof(digit));
#endif
/* 2. t1 <- ah*bh, and copy into high digits of result. */
if ((t1 = k_mul(ah, bh)) == NULL) goto fail;
- assert(Py_SIZE(t1) >= 0);
- assert(2*shift + Py_SIZE(t1) <= Py_SIZE(ret));
+ assert(!_PyLong_IsNegative(t1));
+ assert(2*shift + _PyLong_DigitCount(t1) <= _PyLong_DigitCount(ret));
memcpy(ret->long_value.ob_digit + 2*shift, t1->long_value.ob_digit,
- Py_SIZE(t1) * sizeof(digit));
+ _PyLong_DigitCount(t1) * sizeof(digit));
/* Zero-out the digits higher than the ah*bh copy. */
- i = Py_SIZE(ret) - 2*shift - Py_SIZE(t1);
+ i = _PyLong_DigitCount(ret) - 2*shift - _PyLong_DigitCount(t1);
if (i)
- memset(ret->long_value.ob_digit + 2*shift + Py_SIZE(t1), 0,
+ memset(ret->long_value.ob_digit + 2*shift + _PyLong_DigitCount(t1), 0,
i * sizeof(digit));
/* 3. t2 <- al*bl, and copy into the low digits. */
@@ -3790,23 +3740,23 @@ k_mul(PyLongObject *a, PyLongObject *b)
Py_DECREF(t1);
goto fail;
}
- assert(Py_SIZE(t2) >= 0);
- assert(Py_SIZE(t2) <= 2*shift); /* no overlap with high digits */
- memcpy(ret->long_value.ob_digit, t2->long_value.ob_digit, Py_SIZE(t2) * sizeof(digit));
+ assert(!_PyLong_IsNegative(t2));
+ assert(_PyLong_DigitCount(t2) <= 2*shift); /* no overlap with high digits */
+ memcpy(ret->long_value.ob_digit, t2->long_value.ob_digit, _PyLong_DigitCount(t2) * sizeof(digit));
/* Zero out remaining digits. */
- i = 2*shift - Py_SIZE(t2); /* number of uninitialized digits */
+ i = 2*shift - _PyLong_DigitCount(t2); /* number of uninitialized digits */
if (i)
- memset(ret->long_value.ob_digit + Py_SIZE(t2), 0, i * sizeof(digit));
+ memset(ret->long_value.ob_digit + _PyLong_DigitCount(t2), 0, i * sizeof(digit));
/* 4 & 5. Subtract ah*bh (t1) and al*bl (t2). We do al*bl first
* because it's fresher in cache.
*/
- i = Py_SIZE(ret) - shift; /* # digits after shift */
- (void)v_isub(ret->long_value.ob_digit + shift, i, t2->long_value.ob_digit, Py_SIZE(t2));
+ i = _PyLong_DigitCount(ret) - shift; /* # digits after shift */
+ (void)v_isub(ret->long_value.ob_digit + shift, i, t2->long_value.ob_digit, _PyLong_DigitCount(t2));
_Py_DECREF_INT(t2);
- (void)v_isub(ret->long_value.ob_digit + shift, i, t1->long_value.ob_digit, Py_SIZE(t1));
+ (void)v_isub(ret->long_value.ob_digit + shift, i, t1->long_value.ob_digit, _PyLong_DigitCount(t1));
_Py_DECREF_INT(t1);
/* 6. t3 <- (ah+al)(bh+bl), and add into result. */
@@ -3830,12 +3780,12 @@ k_mul(PyLongObject *a, PyLongObject *b)
_Py_DECREF_INT(t1);
_Py_DECREF_INT(t2);
if (t3 == NULL) goto fail;
- assert(Py_SIZE(t3) >= 0);
+ assert(!_PyLong_IsNegative(t3));
/* Add t3. It's not obvious why we can't run out of room here.
* See the (*) comment after this function.
*/
- (void)v_iadd(ret->long_value.ob_digit + shift, i, t3->long_value.ob_digit, Py_SIZE(t3));
+ (void)v_iadd(ret->long_value.ob_digit + shift, i, t3->long_value.ob_digit, _PyLong_DigitCount(t3));
_Py_DECREF_INT(t3);
return long_normalize(ret);
@@ -3896,17 +3846,17 @@ ah*bh and al*bl too.
/* b has at least twice the digits of a, and a is big enough that Karatsuba
* would pay off *if* the inputs had balanced sizes. View b as a sequence
- * of slices, each with a->ob_size digits, and multiply the slices by a,
- * one at a time. This gives k_mul balanced inputs to work with, and is
- * also cache-friendly (we compute one double-width slice of the result
+ * of slices, each with the same number of digits as a, and multiply the
+ * slices by a, one at a time. This gives k_mul balanced inputs to work with,
+ * and is also cache-friendly (we compute one double-width slice of the result
* at a time, then move on, never backtracking except for the helpful
* single-width slice overlap between successive partial sums).
*/
static PyLongObject *
k_lopsided_mul(PyLongObject *a, PyLongObject *b)
{
- const Py_ssize_t asize = Py_ABS(Py_SIZE(a));
- Py_ssize_t bsize = Py_ABS(Py_SIZE(b));
+ const Py_ssize_t asize = _PyLong_DigitCount(a);
+ Py_ssize_t bsize = _PyLong_DigitCount(b);
Py_ssize_t nbdone; /* # of b digits already multiplied */
PyLongObject *ret;
PyLongObject *bslice = NULL;
@@ -3918,7 +3868,7 @@ k_lopsided_mul(PyLongObject *a, PyLongObject *b)
ret = _PyLong_New(asize + bsize);
if (ret == NULL)
return NULL;
- memset(ret->long_value.ob_digit, 0, Py_SIZE(ret) * sizeof(digit));
+ memset(ret->long_value.ob_digit, 0, _PyLong_DigitCount(ret) * sizeof(digit));
/* Successive slices of b are copied into bslice. */
bslice = _PyLong_New(asize);
@@ -3933,14 +3883,15 @@ k_lopsided_mul(PyLongObject *a, PyLongObject *b)
/* Multiply the next slice of b by a. */
memcpy(bslice->long_value.ob_digit, b->long_value.ob_digit + nbdone,
nbtouse * sizeof(digit));
- Py_SET_SIZE(bslice, nbtouse);
+ assert(nbtouse >= 0);
+ _PyLong_SetSignAndDigitCount(bslice, 1, nbtouse);
product = k_mul(a, bslice);
if (product == NULL)
goto fail;
/* Add into result. */
- (void)v_iadd(ret->long_value.ob_digit + nbdone, Py_SIZE(ret) - nbdone,
- product->long_value.ob_digit, Py_SIZE(product));
+ (void)v_iadd(ret->long_value.ob_digit + nbdone, _PyLong_DigitCount(ret) - nbdone,
+ product->long_value.ob_digit, _PyLong_DigitCount(product));
_Py_DECREF_INT(product);
bsize -= nbtouse;
@@ -3962,14 +3913,14 @@ _PyLong_Multiply(PyLongObject *a, PyLongObject *b)
PyLongObject *z;
/* fast path for single-digit multiplication */
- if (IS_MEDIUM_VALUE(a) && IS_MEDIUM_VALUE(b)) {
+ if (_PyLong_BothAreCompact(a, b)) {
stwodigits v = medium_value(a) * medium_value(b);
return _PyLong_FromSTwoDigits(v);
}
z = k_mul(a, b);
/* Negate if exactly one of the inputs is negative. */
- if (((Py_SIZE(a) ^ Py_SIZE(b)) < 0) && z) {
+ if (!_PyLong_SameSign(a, b) && z) {
_PyLong_Negate(&z);
if (z == NULL)
return NULL;
@@ -3992,11 +3943,10 @@ fast_mod(PyLongObject *a, PyLongObject *b)
sdigit right = b->long_value.ob_digit[0];
sdigit mod;
- assert(Py_ABS(Py_SIZE(a)) == 1);
- assert(Py_ABS(Py_SIZE(b)) == 1);
-
- if (Py_SIZE(a) == Py_SIZE(b)) {
- /* 'a' and 'b' have the same sign. */
+ assert(_PyLong_DigitCount(a) == 1);
+ assert(_PyLong_DigitCount(b) == 1);
+ sdigit sign = _PyLong_CompactSign(b);
+ if (_PyLong_SameSign(a, b)) {
mod = left % right;
}
else {
@@ -4004,7 +3954,7 @@ fast_mod(PyLongObject *a, PyLongObject *b)
mod = right - 1 - (left - 1) % right;
}
- return PyLong_FromLong(mod * (sdigit)Py_SIZE(b));
+ return PyLong_FromLong(mod * sign);
}
/* Fast floor division for single-digit longs. */
@@ -4015,11 +3965,10 @@ fast_floor_div(PyLongObject *a, PyLongObject *b)
sdigit right = b->long_value.ob_digit[0];
sdigit div;
- assert(Py_ABS(Py_SIZE(a)) == 1);
- assert(Py_ABS(Py_SIZE(b)) == 1);
+ assert(_PyLong_DigitCount(a) == 1);
+ assert(_PyLong_DigitCount(b) == 1);
- if (Py_SIZE(a) == Py_SIZE(b)) {
- /* 'a' and 'b' have the same sign. */
+ if (_PyLong_SameSign(a, b)) {
div = left / right;
}
else {
@@ -4097,7 +4046,7 @@ l_divmod(PyLongObject *v, PyLongObject *w,
{
PyLongObject *div, *mod;
- if (Py_ABS(Py_SIZE(v)) == 1 && Py_ABS(Py_SIZE(w)) == 1) {
+ if (_PyLong_DigitCount(v) == 1 && _PyLong_DigitCount(w) == 1) {
/* Fast path for single-digit longs */
div = NULL;
if (pdiv != NULL) {
@@ -4122,8 +4071,8 @@ l_divmod(PyLongObject *v, PyLongObject *w,
return 0;
}
#if WITH_PYLONG_MODULE
- Py_ssize_t size_v = Py_ABS(Py_SIZE(v)); /* digits in numerator */
- Py_ssize_t size_w = Py_ABS(Py_SIZE(w)); /* digits in denominator */
+ Py_ssize_t size_v = _PyLong_DigitCount(v); /* digits in numerator */
+ Py_ssize_t size_w = _PyLong_DigitCount(w); /* digits in denominator */
if (size_w > 300 && (size_v - size_w) > 150) {
/* Switch to _pylong.int_divmod(). If the quotient is small then
"schoolbook" division is linear-time so don't use in that case.
@@ -4135,8 +4084,8 @@ l_divmod(PyLongObject *v, PyLongObject *w,
#endif
if (long_divrem(v, w, &div, &mod) < 0)
return -1;
- if ((Py_SIZE(mod) < 0 && Py_SIZE(w) > 0) ||
- (Py_SIZE(mod) > 0 && Py_SIZE(w) < 0)) {
+ if ((_PyLong_IsNegative(mod) && _PyLong_IsPositive(w)) ||
+ (_PyLong_IsPositive(mod) && _PyLong_IsNegative(w))) {
PyLongObject *temp;
temp = (PyLongObject *) long_add(mod, w);
Py_SETREF(mod, temp);
@@ -4175,15 +4124,15 @@ l_mod(PyLongObject *v, PyLongObject *w, PyLongObject **pmod)
PyLongObject *mod;
assert(pmod);
- if (Py_ABS(Py_SIZE(v)) == 1 && Py_ABS(Py_SIZE(w)) == 1) {
+ if (_PyLong_DigitCount(v) == 1 && _PyLong_DigitCount(w) == 1) {
/* Fast path for single-digit longs */
*pmod = (PyLongObject *)fast_mod(v, w);
return -(*pmod == NULL);
}
if (long_rem(v, w, &mod) < 0)
return -1;
- if ((Py_SIZE(mod) < 0 && Py_SIZE(w) > 0) ||
- (Py_SIZE(mod) > 0 && Py_SIZE(w) < 0)) {
+ if ((_PyLong_IsNegative(mod) && _PyLong_IsPositive(w)) ||
+ (_PyLong_IsPositive(mod) && _PyLong_IsNegative(w))) {
PyLongObject *temp;
temp = (PyLongObject *) long_add(mod, w);
Py_SETREF(mod, temp);
@@ -4202,7 +4151,7 @@ long_div(PyObject *a, PyObject *b)
CHECK_BINOP(a, b);
- if (Py_ABS(Py_SIZE(a)) == 1 && Py_ABS(Py_SIZE(b)) == 1) {
+ if (_PyLong_DigitCount((PyLongObject*)a) == 1 && _PyLong_DigitCount((PyLongObject*)b) == 1) {
return fast_floor_div((PyLongObject*)a, (PyLongObject*)b);
}
@@ -4317,9 +4266,9 @@ long_true_divide(PyObject *v, PyObject *w)
*/
/* Reduce to case where a and b are both positive. */
- a_size = Py_ABS(Py_SIZE(a));
- b_size = Py_ABS(Py_SIZE(b));
- negate = (Py_SIZE(a) < 0) ^ (Py_SIZE(b) < 0);
+ a_size = _PyLong_DigitCount(a);
+ b_size = _PyLong_DigitCount(b);
+ negate = (_PyLong_IsNegative(a)) != (_PyLong_IsNegative(b));
if (b_size == 0) {
PyErr_SetString(PyExc_ZeroDivisionError,
"division by zero");
@@ -4412,7 +4361,7 @@ long_true_divide(PyObject *v, PyObject *w)
inexact = 1;
}
long_normalize(x);
- x_size = Py_SIZE(x);
+ x_size = _PyLong_SignedDigitCount(x);
/* x //= b. If the remainder is nonzero, set inexact. We own the only
reference to x, so it's safe to modify it in-place. */
@@ -4429,11 +4378,11 @@ long_true_divide(PyObject *v, PyObject *w)
Py_SETREF(x, div);
if (x == NULL)
goto error;
- if (Py_SIZE(rem))
+ if (!_PyLong_IsZero(rem))
inexact = 1;
Py_DECREF(rem);
}
- x_size = Py_ABS(Py_SIZE(x));
+ x_size = _PyLong_DigitCount(x);
assert(x_size > 0); /* result of division is never zero */
x_bits = (x_size-1)*PyLong_SHIFT+bit_length_digit(x->long_value.ob_digit[x_size-1]);
@@ -4535,7 +4484,7 @@ long_invmod(PyLongObject *a, PyLongObject *n)
PyLongObject *b, *c;
/* Should only ever be called for positive n */
- assert(Py_SIZE(n) > 0);
+ assert(_PyLong_IsPositive(n));
b = (PyLongObject *)PyLong_FromLong(1L);
if (b == NULL) {
@@ -4550,7 +4499,7 @@ long_invmod(PyLongObject *a, PyLongObject *n)
Py_INCREF(n);
/* references now owned: a, b, c, n */
- while (Py_SIZE(n) != 0) {
+ while (!_PyLong_IsZero(n)) {
PyLongObject *q, *r, *s, *t;
if (l_divmod(a, n, &q, &r) == -1) {
@@ -4636,7 +4585,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
Py_RETURN_NOTIMPLEMENTED;
}
- if (Py_SIZE(b) < 0 && c == NULL) {
+ if (_PyLong_IsNegative(b) && c == NULL) {
/* if exponent is negative and there's no modulus:
return a float. This works because we know
that this calls float_pow() which converts its
@@ -4649,7 +4598,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
if (c) {
/* if modulus == 0:
raise ValueError() */
- if (Py_SIZE(c) == 0) {
+ if (_PyLong_IsZero(c)) {
PyErr_SetString(PyExc_ValueError,
"pow() 3rd argument cannot be 0");
goto Error;
@@ -4658,7 +4607,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
/* if modulus < 0:
negativeOutput = True
modulus = -modulus */
- if (Py_SIZE(c) < 0) {
+ if (_PyLong_IsNegative(c)) {
negativeOutput = 1;
temp = (PyLongObject *)_PyLong_Copy(c);
if (temp == NULL)
@@ -4672,14 +4621,14 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
/* if modulus == 1:
return 0 */
- if ((Py_SIZE(c) == 1) && (c->long_value.ob_digit[0] == 1)) {
+ if (_PyLong_IsNonNegativeCompact(c) && (c->long_value.ob_digit[0] == 1)) {
z = (PyLongObject *)PyLong_FromLong(0L);
goto Done;
}
/* if exponent is negative, negate the exponent and
replace the base with a modular inverse */
- if (Py_SIZE(b) < 0) {
+ if (_PyLong_IsNegative(b)) {
temp = (PyLongObject *)_PyLong_Copy(b);
if (temp == NULL)
goto Error;
@@ -4705,7 +4654,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
base % modulus instead.
We could _always_ do this reduction, but l_mod() isn't cheap,
so we only do it when it buys something. */
- if (Py_SIZE(a) < 0 || Py_SIZE(a) > Py_SIZE(c)) {
+ if (_PyLong_IsNegative(a) || _PyLong_DigitCount(a) > _PyLong_DigitCount(c)) {
if (l_mod(a, c, &temp) < 0)
goto Error;
Py_SETREF(a, temp);
@@ -4747,7 +4696,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
REDUCE(result); \
} while(0)
- i = Py_SIZE(b);
+ i = _PyLong_SignedDigitCount(b);
digit bi = i ? b->long_value.ob_digit[i-1] : 0;
digit bit;
if (i <= 1 && bi <= 3) {
@@ -4839,7 +4788,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
pending = 0; \
} while(0)
- for (i = Py_SIZE(b) - 1; i >= 0; --i) {
+ for (i = _PyLong_SignedDigitCount(b) - 1; i >= 0; --i) {
const digit bi = b->long_value.ob_digit[i];
for (j = PyLong_SHIFT - 1; j >= 0; --j) {
const int bit = (bi >> j) & 1;
@@ -4857,7 +4806,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
ABSORB_PENDING;
}
- if (negativeOutput && (Py_SIZE(z) != 0)) {
+ if (negativeOutput && !_PyLong_IsZero(z)) {
temp = (PyLongObject *)long_sub(z, c);
if (temp == NULL)
goto Error;
@@ -4885,14 +4834,14 @@ long_invert(PyLongObject *v)
{
/* Implement ~x as -(x+1) */
PyLongObject *x;
- if (IS_MEDIUM_VALUE(v))
+ if (_PyLong_IsCompact(v))
return _PyLong_FromSTwoDigits(~medium_value(v));
x = (PyLongObject *) long_add(v, (PyLongObject *)_PyLong_GetOne());
if (x == NULL)
return NULL;
_PyLong_Negate(&x);
- /* No need for maybe_small_long here, since any small
- longs will have been caught in the Py_SIZE <= 1 fast path. */
+ /* No need for maybe_small_long here, since any small longs
+ will have been caught in the _PyLong_IsCompact() fast path. */
return (PyObject *)x;
}
@@ -4900,18 +4849,18 @@ static PyObject *
long_neg(PyLongObject *v)
{
PyLongObject *z;
- if (IS_MEDIUM_VALUE(v))
+ if (_PyLong_IsCompact(v))
return _PyLong_FromSTwoDigits(-medium_value(v));
z = (PyLongObject *)_PyLong_Copy(v);
if (z != NULL)
- Py_SET_SIZE(z, -(Py_SIZE(v)));
+ _PyLong_FlipSign(z);
return (PyObject *)z;
}
static PyObject *
long_abs(PyLongObject *v)
{
- if (Py_SIZE(v) < 0)
+ if (_PyLong_IsNegative(v))
return long_neg(v);
else
return long_long((PyObject *)v);
@@ -4920,7 +4869,7 @@ long_abs(PyLongObject *v)
static int
long_bool(PyLongObject *v)
{
- return Py_SIZE(v) != 0;
+ return !_PyLong_IsZero(v);
}
/* wordshift, remshift = divmod(shiftby, PyLong_SHIFT) */
@@ -4928,14 +4877,14 @@ static int
divmod_shift(PyObject *shiftby, Py_ssize_t *wordshift, digit *remshift)
{
assert(PyLong_Check(shiftby));
- assert(Py_SIZE(shiftby) >= 0);
+ assert(!_PyLong_IsNegative((PyLongObject *)shiftby));
Py_ssize_t lshiftby = PyLong_AsSsize_t((PyObject *)shiftby);
if (lshiftby >= 0) {
*wordshift = lshiftby / PyLong_SHIFT;
*remshift = lshiftby % PyLong_SHIFT;
return 0;
}
- /* PyLong_Check(shiftby) is true and Py_SIZE(shiftby) >= 0, so it must
+ /* PyLong_Check(shiftby) is true and shiftby is not negative, so it must
be that PyLong_AsSsize_t raised an OverflowError. */
assert(PyErr_ExceptionMatches(PyExc_OverflowError));
PyErr_Clear();
@@ -4973,7 +4922,7 @@ long_rshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift)
assert(remshift < PyLong_SHIFT);
/* Fast path for small a. */
- if (IS_MEDIUM_VALUE(a)) {
+ if (_PyLong_IsCompact(a)) {
stwodigits m, x;
digit shift;
m = medium_value(a);
@@ -4982,8 +4931,8 @@ long_rshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift)
return _PyLong_FromSTwoDigits(x);
}
- a_negative = Py_SIZE(a) < 0;
- size_a = Py_ABS(Py_SIZE(a));
+ a_negative = _PyLong_IsNegative(a);
+ size_a = _PyLong_DigitCount(a);
if (a_negative) {
/* For negative 'a', adjust so that 0 < remshift <= PyLong_SHIFT,
@@ -5024,7 +4973,7 @@ long_rshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift)
significant `wordshift` digits of `a` is nonzero. Digit `wordshift`
of `2**shift - 1` has value `PyLong_MASK >> hishift`.
*/
- Py_SET_SIZE(z, -newsize);
+ _PyLong_SetSignAndDigitCount(z, -1, newsize);
digit sticky = 0;
for (Py_ssize_t j = 0; j < wordshift; j++) {
@@ -5054,11 +5003,11 @@ long_rshift(PyObject *a, PyObject *b)
CHECK_BINOP(a, b);
- if (Py_SIZE(b) < 0) {
+ if (_PyLong_IsNegative((PyLongObject *)b)) {
PyErr_SetString(PyExc_ValueError, "negative shift count");
return NULL;
}
- if (Py_SIZE(a) == 0) {
+ if (_PyLong_IsZero((PyLongObject *)a)) {
return PyLong_FromLong(0);
}
if (divmod_shift(b, &wordshift, &remshift) < 0)
@@ -5074,7 +5023,7 @@ _PyLong_Rshift(PyObject *a, size_t shiftby)
digit remshift;
assert(PyLong_Check(a));
- if (Py_SIZE(a) == 0) {
+ if (_PyLong_IsZero((PyLongObject *)a)) {
return PyLong_FromLong(0);
}
wordshift = shiftby / PyLong_SHIFT;
@@ -5089,23 +5038,23 @@ long_lshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift)
Py_ssize_t oldsize, newsize, i, j;
twodigits accum;
- if (wordshift == 0 && IS_MEDIUM_VALUE(a)) {
+ if (wordshift == 0 && _PyLong_IsCompact(a)) {
stwodigits m = medium_value(a);
// bypass undefined shift operator behavior
stwodigits x = m < 0 ? -(-m << remshift) : m << remshift;
return _PyLong_FromSTwoDigits(x);
}
- oldsize = Py_ABS(Py_SIZE(a));
+ oldsize = _PyLong_DigitCount(a);
newsize = oldsize + wordshift;
if (remshift)
++newsize;
z = _PyLong_New(newsize);
if (z == NULL)
return NULL;
- if (Py_SIZE(a) < 0) {
+ if (_PyLong_IsNegative(a)) {
assert(Py_REFCNT(z) == 1);
- Py_SET_SIZE(z, -Py_SIZE(z));
+ _PyLong_FlipSign(z);
}
for (i = 0; i < wordshift; i++)
z->long_value.ob_digit[i] = 0;
@@ -5131,11 +5080,11 @@ long_lshift(PyObject *a, PyObject *b)
CHECK_BINOP(a, b);
- if (Py_SIZE(b) < 0) {
+ if (_PyLong_IsNegative((PyLongObject *)b)) {
PyErr_SetString(PyExc_ValueError, "negative shift count");
return NULL;
}
- if (Py_SIZE(a) == 0) {
+ if (_PyLong_IsZero((PyLongObject *)a)) {
return PyLong_FromLong(0);
}
if (divmod_shift(b, &wordshift, &remshift) < 0)
@@ -5151,7 +5100,7 @@ _PyLong_Lshift(PyObject *a, size_t shiftby)
digit remshift;
assert(PyLong_Check(a));
- if (Py_SIZE(a) == 0) {
+ if (_PyLong_IsZero((PyLongObject *)a)) {
return PyLong_FromLong(0);
}
wordshift = shiftby / PyLong_SHIFT;
@@ -5193,8 +5142,8 @@ long_bitwise(PyLongObject *a,
result back to sign-magnitude at the end. */
/* If a is negative, replace it by its two's complement. */
- size_a = Py_ABS(Py_SIZE(a));
- nega = Py_SIZE(a) < 0;
+ size_a = _PyLong_DigitCount(a);
+ nega = _PyLong_IsNegative(a);
if (nega) {
z = _PyLong_New(size_a);
if (z == NULL)
@@ -5207,8 +5156,8 @@ long_bitwise(PyLongObject *a,
Py_INCREF(a);
/* Same for b. */
- size_b = Py_ABS(Py_SIZE(b));
- negb = Py_SIZE(b) < 0;
+ size_b = _PyLong_DigitCount(b);
+ negb = _PyLong_IsNegative(b);
if (negb) {
z = _PyLong_New(size_b);
if (z == NULL) {
@@ -5289,7 +5238,7 @@ long_bitwise(PyLongObject *a,
/* Complement result if negative. */
if (negz) {
- Py_SET_SIZE(z, -(Py_SIZE(z)));
+ _PyLong_FlipSign(z);
z->long_value.ob_digit[size_z] = PyLong_MASK;
v_complement(z->long_value.ob_digit, z->long_value.ob_digit, size_z+1);
}
@@ -5305,7 +5254,7 @@ long_and(PyObject *a, PyObject *b)
CHECK_BINOP(a, b);
PyLongObject *x = (PyLongObject*)a;
PyLongObject *y = (PyLongObject*)b;
- if (IS_MEDIUM_VALUE(x) && IS_MEDIUM_VALUE(y)) {
+ if (_PyLong_IsCompact(x) && _PyLong_IsCompact(y)) {
return _PyLong_FromSTwoDigits(medium_value(x) & medium_value(y));
}
return long_bitwise(x, '&', y);
@@ -5317,7 +5266,7 @@ long_xor(PyObject *a, PyObject *b)
CHECK_BINOP(a, b);
PyLongObject *x = (PyLongObject*)a;
PyLongObject *y = (PyLongObject*)b;
- if (IS_MEDIUM_VALUE(x) && IS_MEDIUM_VALUE(y)) {
+ if (_PyLong_IsCompact(x) && _PyLong_IsCompact(y)) {
return _PyLong_FromSTwoDigits(medium_value(x) ^ medium_value(y));
}
return long_bitwise(x, '^', y);
@@ -5329,7 +5278,7 @@ long_or(PyObject *a, PyObject *b)
CHECK_BINOP(a, b);
PyLongObject *x = (PyLongObject*)a;
PyLongObject *y = (PyLongObject*)b;
- if (IS_MEDIUM_VALUE(x) && IS_MEDIUM_VALUE(y)) {
+ if (_PyLong_IsCompact(x) && _PyLong_IsCompact(y)) {
return _PyLong_FromSTwoDigits(medium_value(x) | medium_value(y));
}
return long_bitwise(x, '|', y);
@@ -5353,14 +5302,11 @@ _PyLong_GCD(PyObject *aarg, PyObject *barg)
stwodigits x, y, q, s, t, c_carry, d_carry;
stwodigits A, B, C, D, T;
int nbits, k;
- Py_ssize_t size_a, size_b, alloc_a, alloc_b;
digit *a_digit, *b_digit, *c_digit, *d_digit, *a_end, *b_end;
a = (PyLongObject *)aarg;
b = (PyLongObject *)barg;
- size_a = Py_SIZE(a);
- size_b = Py_SIZE(b);
- if (-2 <= size_a && size_a <= 2 && -2 <= size_b && size_b <= 2) {
+ if (_PyLong_DigitCount(a) <= 2 && _PyLong_DigitCount(b) <= 2) {
Py_INCREF(a);
Py_INCREF(b);
goto simple;
@@ -5382,14 +5328,15 @@ _PyLong_GCD(PyObject *aarg, PyObject *barg)
}
/* We now own references to a and b */
- alloc_a = Py_SIZE(a);
- alloc_b = Py_SIZE(b);
+ Py_ssize_t size_a, size_b, alloc_a, alloc_b;
+ alloc_a = _PyLong_DigitCount(a);
+ alloc_b = _PyLong_DigitCount(b);
/* reduce until a fits into 2 digits */
- while ((size_a = Py_SIZE(a)) > 2) {
+ while ((size_a = _PyLong_DigitCount(a)) > 2) {
nbits = bit_length_digit(a->long_value.ob_digit[size_a-1]);
/* extract top 2*PyLong_SHIFT bits of a into x, along with
corresponding bits of b into y */
- size_b = Py_SIZE(b);
+ size_b = _PyLong_DigitCount(b);
assert(size_b <= size_a);
if (size_b == 0) {
if (size_a < alloc_a) {
@@ -5433,7 +5380,7 @@ _PyLong_GCD(PyObject *aarg, PyObject *barg)
Py_SETREF(a, b);
b = r;
alloc_a = alloc_b;
- alloc_b = Py_SIZE(b);
+ alloc_b = _PyLong_DigitCount(b);
continue;
}
@@ -5446,7 +5393,8 @@ _PyLong_GCD(PyObject *aarg, PyObject *barg)
T = -C; C = -D; D = T;
}
if (c != NULL) {
- Py_SET_SIZE(c, size_a);
+ assert(size_a >= 0);
+ _PyLong_SetSignAndDigitCount(c, 1, size_a);
}
else if (Py_REFCNT(a) == 1) {
c = (PyLongObject*)Py_NewRef(a);
@@ -5459,11 +5407,13 @@ _PyLong_GCD(PyObject *aarg, PyObject *barg)
}
if (d != NULL) {
- Py_SET_SIZE(d, size_a);
+ assert(size_a >= 0);
+ _PyLong_SetSignAndDigitCount(d, 1, size_a);
}
else if (Py_REFCNT(b) == 1 && size_a <= alloc_b) {
d = (PyLongObject*)Py_NewRef(b);
- Py_SET_SIZE(d, size_a);
+ assert(size_a >= 0);
+ _PyLong_SetSignAndDigitCount(d, 1, size_a);
}
else {
alloc_b = size_a;
@@ -5635,9 +5585,7 @@ long_subtype_new(PyTypeObject *type, PyObject *x, PyObject *obase)
if (tmp == NULL)
return NULL;
assert(PyLong_Check(tmp));
- n = Py_SIZE(tmp);
- if (n < 0)
- n = -n;
+ n = _PyLong_DigitCount(tmp);
/* Fast operations for single digit integers (including zero)
* assume that there is always at least one digit present. */
if (n == 0) {
@@ -5649,7 +5597,7 @@ long_subtype_new(PyTypeObject *type, PyObject *x, PyObject *obase)
return NULL;
}
assert(PyLong_Check(newobj));
- Py_SET_SIZE(newobj, Py_SIZE(tmp));
+ newobj->long_value.lv_tag = tmp->long_value.lv_tag;
for (i = 0; i < n; i++) {
newobj->long_value.ob_digit[i] = tmp->long_value.ob_digit[i];
}
@@ -5743,7 +5691,7 @@ _PyLong_DivmodNear(PyObject *a, PyObject *b)
}
/* Do a and b have different signs? If so, quotient is negative. */
- quo_is_neg = (Py_SIZE(a) < 0) != (Py_SIZE(b) < 0);
+ quo_is_neg = (_PyLong_IsNegative((PyLongObject *)a)) != (_PyLong_IsNegative((PyLongObject *)b));
if (long_divrem((PyLongObject*)a, (PyLongObject*)b, &quo, &rem) < 0)
goto error;
@@ -5763,8 +5711,8 @@ _PyLong_DivmodNear(PyObject *a, PyObject *b)
cmp = long_compare((PyLongObject *)twice_rem, (PyLongObject *)b);
Py_DECREF(twice_rem);
- quo_is_odd = Py_SIZE(quo) != 0 && ((quo->long_value.ob_digit[0] & 1) != 0);
- if ((Py_SIZE(b) < 0 ? cmp < 0 : cmp > 0) || (cmp == 0 && quo_is_odd)) {
+ quo_is_odd = (quo->long_value.ob_digit[0] & 1) != 0;
+ if ((_PyLong_IsNegative((PyLongObject *)b) ? cmp < 0 : cmp > 0) || (cmp == 0 && quo_is_odd)) {
/* fix up quotient */
if (quo_is_neg)
temp = long_sub(quo, (PyLongObject *)one);
@@ -5837,7 +5785,7 @@ int___round___impl(PyObject *self, PyObject *o_ndigits)
return NULL;
/* if ndigits >= 0 then no rounding is necessary; return self unchanged */
- if (Py_SIZE(ndigits) >= 0) {
+ if (!_PyLong_IsNegative((PyLongObject *)ndigits)) {
Py_DECREF(ndigits);
return long_long(self);
}
@@ -5883,8 +5831,8 @@ int___sizeof___impl(PyObject *self)
/*[clinic end generated code: output=3303f008eaa6a0a5 input=9b51620c76fc4507]*/
{
/* using Py_MAX(..., 1) because we always allocate space for at least
- one digit, even though the integer zero has a Py_SIZE of 0 */
- Py_ssize_t ndigits = Py_MAX(Py_ABS(Py_SIZE(self)), 1);
+ one digit, even though the integer zero has a digit count of 0 */
+ Py_ssize_t ndigits = Py_MAX(_PyLong_DigitCount((PyLongObject *)self), 1);
return Py_TYPE(self)->tp_basicsize + Py_TYPE(self)->tp_itemsize * ndigits;
}
@@ -5911,7 +5859,7 @@ int_bit_length_impl(PyObject *self)
assert(self != NULL);
assert(PyLong_Check(self));
- ndigits = Py_ABS(Py_SIZE(self));
+ ndigits = _PyLong_DigitCount((PyLongObject *)self);
if (ndigits == 0)
return PyLong_FromLong(0);
@@ -5980,7 +5928,7 @@ int_bit_count_impl(PyObject *self)
assert(PyLong_Check(self));
PyLongObject *z = (PyLongObject *)self;
- Py_ssize_t ndigits = Py_ABS(Py_SIZE(z));
+ Py_ssize_t ndigits = _PyLong_DigitCount(z);
Py_ssize_t bit_count = 0;
/* Each digit has up to PyLong_SHIFT ones, so the accumulated bit count
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
index b4d0bbf..beb86b9 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -33,7 +33,7 @@ validate_step(PyObject *step)
return PyLong_FromLong(1);
step = PyNumber_Index(step);
- if (step && _PyLong_Sign(step) == 0) {
+ if (step && _PyLong_IsZero((PyLongObject *)step)) {
PyErr_SetString(PyExc_ValueError,
"range() arg 3 must not be zero");
Py_CLEAR(step);
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index 5d2e6ad..584ebce 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -445,7 +445,7 @@ _PySlice_GetLongIndices(PySliceObject *self, PyObject *length,
if (start == NULL)
goto error;
- if (_PyLong_Sign(start) < 0) {
+ if (_PyLong_IsNegative((PyLongObject *)start)) {
/* start += length */
PyObject *tmp = PyNumber_Add(start, length);
Py_SETREF(start, tmp);
@@ -478,7 +478,7 @@ _PySlice_GetLongIndices(PySliceObject *self, PyObject *length,
if (stop == NULL)
goto error;
- if (_PyLong_Sign(stop) < 0) {
+ if (_PyLong_IsNegative((PyLongObject *)stop)) {
/* stop += length */
PyObject *tmp = PyNumber_Add(stop, length);
Py_SETREF(stop, tmp);
@@ -533,7 +533,7 @@ slice_indices(PySliceObject* self, PyObject* len)
if (length == NULL)
return NULL;
- if (_PyLong_Sign(length) < 0) {
+ if (_PyLong_IsNegative((PyLongObject *)length)) {
PyErr_SetString(PyExc_ValueError,
"length should not be negative");
Py_DECREF(length);
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index a37f97c..69e8474 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -8,6 +8,7 @@
#include "pycore_initconfig.h" // _PyStatus_OK()
#include "pycore_moduleobject.h" // _PyModule_GetDef()
#include "pycore_object.h" // _PyType_HasFeature()
+#include "pycore_long.h" // _PyLong_IsNegative()
#include "pycore_pyerrors.h" // _PyErr_Occurred()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_typeobject.h" // struct type_cache
@@ -7865,7 +7866,7 @@ slot_sq_length(PyObject *self)
return -1;
assert(PyLong_Check(res));
- if (Py_SIZE(res) < 0) {
+ if (_PyLong_IsNegative((PyLongObject *)res)) {
Py_DECREF(res);
PyErr_SetString(PyExc_ValueError,
"__len__() should return >= 0");
diff --git a/Python/ast_opt.c b/Python/ast_opt.c
index 1a0b2a0..8270fa8 100644
--- a/Python/ast_opt.c
+++ b/Python/ast_opt.c
@@ -2,6 +2,7 @@
#include "Python.h"
#include "pycore_ast.h" // _PyAST_GetDocString()
#include "pycore_compile.h" // _PyASTOptimizeState
+#include "pycore_long.h" // _PyLong
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_format.h" // F_LJUST
@@ -152,7 +153,9 @@ check_complexity(PyObject *obj, Py_ssize_t limit)
static PyObject *
safe_multiply(PyObject *v, PyObject *w)
{
- if (PyLong_Check(v) && PyLong_Check(w) && Py_SIZE(v) && Py_SIZE(w)) {
+ if (PyLong_Check(v) && PyLong_Check(w) &&
+ !_PyLong_IsZero((PyLongObject *)v) && !_PyLong_IsZero((PyLongObject *)w)
+ ) {
size_t vbits = _PyLong_NumBits(v);
size_t wbits = _PyLong_NumBits(w);
if (vbits == (size_t)-1 || wbits == (size_t)-1) {
@@ -198,7 +201,9 @@ safe_multiply(PyObject *v, PyObject *w)
static PyObject *
safe_power(PyObject *v, PyObject *w)
{
- if (PyLong_Check(v) && PyLong_Check(w) && Py_SIZE(v) && Py_SIZE(w) > 0) {
+ if (PyLong_Check(v) && PyLong_Check(w) &&
+ !_PyLong_IsZero((PyLongObject *)v) && _PyLong_IsPositive((PyLongObject *)w)
+ ) {
size_t vbits = _PyLong_NumBits(v);
size_t wbits = PyLong_AsSize_t(w);
if (vbits == (size_t)-1 || wbits == (size_t)-1) {
@@ -215,7 +220,9 @@ safe_power(PyObject *v, PyObject *w)
static PyObject *
safe_lshift(PyObject *v, PyObject *w)
{
- if (PyLong_Check(v) && PyLong_Check(w) && Py_SIZE(v) && Py_SIZE(w)) {
+ if (PyLong_Check(v) && PyLong_Check(w) &&
+ !_PyLong_IsZero((PyLongObject *)v) && !_PyLong_IsZero((PyLongObject *)w)
+ ) {
size_t vbits = _PyLong_NumBits(v);
size_t wbits = PyLong_AsSize_t(w);
if (vbits == (size_t)-1 || wbits == (size_t)-1) {
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 12ca0ba..55fd364 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -5,6 +5,7 @@
#include "pycore_ast.h" // _PyAST_Validate()
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_compile.h" // _PyAST_Compile()
+#include "pycore_long.h" // _PyLong_CompactValue
#include "pycore_object.h" // _Py_AddToAllObjects()
#include "pycore_pyerrors.h" // _PyErr_NoMemory()
#include "pycore_pystate.h" // _PyThreadState_GET()
@@ -2491,7 +2492,7 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
*/
if (PyLong_CheckExact(result)) {
int overflow;
- long i_result = PyLong_AsLongAndOverflow(result, &overflow);
+ Py_ssize_t i_result = PyLong_AsLongAndOverflow(result, &overflow);
/* If this already overflowed, don't even enter the loop. */
if (overflow == 0) {
Py_SETREF(result, NULL);
@@ -2505,15 +2506,14 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
return PyLong_FromLong(i_result);
}
if (PyLong_CheckExact(item) || PyBool_Check(item)) {
- long b;
+ Py_ssize_t b;
overflow = 0;
/* Single digits are common, fast, and cannot overflow on unpacking. */
- switch (Py_SIZE(item)) {
- case -1: b = -(sdigit) ((PyLongObject*)item)->long_value.ob_digit[0]; break;
- // Note: the continue goes to the top of the "while" loop that iterates over the elements
- case 0: Py_DECREF(item); continue;
- case 1: b = ((PyLongObject*)item)->long_value.ob_digit[0]; break;
- default: b = PyLong_AsLongAndOverflow(item, &overflow); break;
+ if (_PyLong_IsCompact((PyLongObject *)item)) {
+ b = _PyLong_CompactValue((PyLongObject *)item);
+ }
+ else {
+ b = PyLong_AsLongAndOverflow(item, &overflow);
}
if (overflow == 0 &&
(i_result >= 0 ? (b <= LONG_MAX - i_result)
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index ce2a58b..f1fec0b 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -345,8 +345,7 @@ dummy_func(
DEOPT_IF(!PyList_CheckExact(list), BINARY_SUBSCR);
// Deopt unless 0 <= sub < PyList_Size(list)
- DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), BINARY_SUBSCR);
- assert(((PyLongObject *)_PyLong_GetZero())->long_value.ob_digit[0] == 0);
+ DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub), BINARY_SUBSCR);
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
DEOPT_IF(index >= PyList_GET_SIZE(list), BINARY_SUBSCR);
STAT_INC(BINARY_SUBSCR, hit);
@@ -363,8 +362,7 @@ dummy_func(
DEOPT_IF(!PyTuple_CheckExact(tuple), BINARY_SUBSCR);
// Deopt unless 0 <= sub < PyTuple_Size(list)
- DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), BINARY_SUBSCR);
- assert(((PyLongObject *)_PyLong_GetZero())->long_value.ob_digit[0] == 0);
+ DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub), BINARY_SUBSCR);
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
DEOPT_IF(index >= PyTuple_GET_SIZE(tuple), BINARY_SUBSCR);
STAT_INC(BINARY_SUBSCR, hit);
@@ -456,7 +454,7 @@ dummy_func(
DEOPT_IF(!PyList_CheckExact(list), STORE_SUBSCR);
// Ensure nonnegative, zero-or-one-digit ints.
- DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), STORE_SUBSCR);
+ DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub), STORE_SUBSCR);
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
// Ensure index < len(list)
DEOPT_IF(index >= PyList_GET_SIZE(list), STORE_SUBSCR);
@@ -1755,12 +1753,13 @@ dummy_func(
assert(cframe.use_tracing == 0);
DEOPT_IF(!PyLong_CheckExact(left), COMPARE_AND_BRANCH);
DEOPT_IF(!PyLong_CheckExact(right), COMPARE_AND_BRANCH);
- DEOPT_IF((size_t)(Py_SIZE(left) + 1) > 2, COMPARE_AND_BRANCH);
- DEOPT_IF((size_t)(Py_SIZE(right) + 1) > 2, COMPARE_AND_BRANCH);
+ DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)left), COMPARE_AND_BRANCH);
+ DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)right), COMPARE_AND_BRANCH);
STAT_INC(COMPARE_AND_BRANCH, hit);
- assert(Py_ABS(Py_SIZE(left)) <= 1 && Py_ABS(Py_SIZE(right)) <= 1);
- Py_ssize_t ileft = Py_SIZE(left) * ((PyLongObject *)left)->long_value.ob_digit[0];
- Py_ssize_t iright = Py_SIZE(right) * ((PyLongObject *)right)->long_value.ob_digit[0];
+ assert(_PyLong_DigitCount((PyLongObject *)left) <= 1 &&
+ _PyLong_DigitCount((PyLongObject *)right) <= 1);
+ Py_ssize_t ileft = _PyLong_CompactValue((PyLongObject *)left);
+ Py_ssize_t iright = _PyLong_CompactValue((PyLongObject *)right);
// 2 if <, 4 if >, 8 if ==; this matches the low 4 bits of the oparg
int sign_ish = COMPARISON_BIT(ileft, iright);
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 34b608f..e9f28b0 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -547,8 +547,7 @@
DEOPT_IF(!PyList_CheckExact(list), BINARY_SUBSCR);
// Deopt unless 0 <= sub < PyList_Size(list)
- DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), BINARY_SUBSCR);
- assert(((PyLongObject *)_PyLong_GetZero())->long_value.ob_digit[0] == 0);
+ DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub), BINARY_SUBSCR);
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
DEOPT_IF(index >= PyList_GET_SIZE(list), BINARY_SUBSCR);
STAT_INC(BINARY_SUBSCR, hit);
@@ -557,7 +556,7 @@
Py_INCREF(res);
_Py_DECREF_SPECIALIZED(sub, (destructor)PyObject_Free);
Py_DECREF(list);
- #line 561 "Python/generated_cases.c.h"
+ #line 560 "Python/generated_cases.c.h"
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
@@ -568,14 +567,13 @@
PyObject *sub = stack_pointer[-1];
PyObject *tuple = stack_pointer[-2];
PyObject *res;
- #line 361 "Python/bytecodes.c"
+ #line 360 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
DEOPT_IF(!PyLong_CheckExact(sub), BINARY_SUBSCR);
DEOPT_IF(!PyTuple_CheckExact(tuple), BINARY_SUBSCR);
// Deopt unless 0 <= sub < PyTuple_Size(list)
- DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), BINARY_SUBSCR);
- assert(((PyLongObject *)_PyLong_GetZero())->long_value.ob_digit[0] == 0);
+ DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub), BINARY_SUBSCR);
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
DEOPT_IF(index >= PyTuple_GET_SIZE(tuple), BINARY_SUBSCR);
STAT_INC(BINARY_SUBSCR, hit);
@@ -584,7 +582,7 @@
Py_INCREF(res);
_Py_DECREF_SPECIALIZED(sub, (destructor)PyObject_Free);
Py_DECREF(tuple);
- #line 588 "Python/generated_cases.c.h"
+ #line 586 "Python/generated_cases.c.h"
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 4;
@@ -595,7 +593,7 @@
PyObject *sub = stack_pointer[-1];
PyObject *dict = stack_pointer[-2];
PyObject *res;
- #line 379 "Python/bytecodes.c"
+ #line 377 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
DEOPT_IF(!PyDict_CheckExact(dict), BINARY_SUBSCR);
STAT_INC(BINARY_SUBSCR, hit);
@@ -604,14 +602,14 @@
if (!_PyErr_Occurred(tstate)) {
_PyErr_SetKeyError(sub);
}
- #line 608 "Python/generated_cases.c.h"
+ #line 606 "Python/generated_cases.c.h"
Py_DECREF(dict);
Py_DECREF(sub);
- #line 388 "Python/bytecodes.c"
+ #line 386 "Python/bytecodes.c"
if (true) goto pop_2_error;
}
Py_INCREF(res); // Do this before DECREF'ing dict, sub
- #line 615 "Python/generated_cases.c.h"
+ #line 613 "Python/generated_cases.c.h"
Py_DECREF(dict);
Py_DECREF(sub);
STACK_SHRINK(1);
@@ -625,7 +623,7 @@
PyObject *container = stack_pointer[-2];
uint32_t type_version = read_u32(&next_instr[1].cache);
uint16_t func_version = read_u16(&next_instr[3].cache);
- #line 395 "Python/bytecodes.c"
+ #line 393 "Python/bytecodes.c"
PyTypeObject *tp = Py_TYPE(container);
DEOPT_IF(tp->tp_version_tag != type_version, BINARY_SUBSCR);
assert(tp->tp_flags & Py_TPFLAGS_HEAPTYPE);
@@ -644,15 +642,15 @@
new_frame->localsplus[1] = sub;
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
DISPATCH_INLINED(new_frame);
- #line 648 "Python/generated_cases.c.h"
+ #line 646 "Python/generated_cases.c.h"
}
TARGET(LIST_APPEND) {
PyObject *v = stack_pointer[-1];
PyObject *list = stack_pointer[-(2 + (oparg-1))];
- #line 416 "Python/bytecodes.c"
+ #line 414 "Python/bytecodes.c"
if (_PyList_AppendTakeRef((PyListObject *)list, v) < 0) goto pop_1_error;
- #line 656 "Python/generated_cases.c.h"
+ #line 654 "Python/generated_cases.c.h"
STACK_SHRINK(1);
PREDICT(JUMP_BACKWARD);
DISPATCH();
@@ -661,13 +659,13 @@
TARGET(SET_ADD) {
PyObject *v = stack_pointer[-1];
PyObject *set = stack_pointer[-(2 + (oparg-1))];
- #line 421 "Python/bytecodes.c"
+ #line 419 "Python/bytecodes.c"
int err = PySet_Add(set, v);
- #line 667 "Python/generated_cases.c.h"
+ #line 665 "Python/generated_cases.c.h"
Py_DECREF(v);
- #line 423 "Python/bytecodes.c"
+ #line 421 "Python/bytecodes.c"
if (err) goto pop_1_error;
- #line 671 "Python/generated_cases.c.h"
+ #line 669 "Python/generated_cases.c.h"
STACK_SHRINK(1);
PREDICT(JUMP_BACKWARD);
DISPATCH();
@@ -680,7 +678,7 @@
PyObject *container = stack_pointer[-2];
PyObject *v = stack_pointer[-3];
uint16_t counter = read_u16(&next_instr[0].cache);
- #line 434 "Python/bytecodes.c"
+ #line 432 "Python/bytecodes.c"
#if ENABLE_SPECIALIZATION
if (ADAPTIVE_COUNTER_IS_ZERO(counter)) {
assert(cframe.use_tracing == 0);
@@ -696,13 +694,13 @@
#endif /* ENABLE_SPECIALIZATION */
/* container[sub] = v */
int err = PyObject_SetItem(container, sub, v);
- #line 700 "Python/generated_cases.c.h"
+ #line 698 "Python/generated_cases.c.h"
Py_DECREF(v);
Py_DECREF(container);
Py_DECREF(sub);
- #line 450 "Python/bytecodes.c"
+ #line 448 "Python/bytecodes.c"
if (err) goto pop_3_error;
- #line 706 "Python/generated_cases.c.h"
+ #line 704 "Python/generated_cases.c.h"
STACK_SHRINK(3);
next_instr += 1;
DISPATCH();
@@ -712,13 +710,13 @@
PyObject *sub = stack_pointer[-1];
PyObject *list = stack_pointer[-2];
PyObject *value = stack_pointer[-3];
- #line 454 "Python/bytecodes.c"
+ #line 452 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
DEOPT_IF(!PyLong_CheckExact(sub), STORE_SUBSCR);
DEOPT_IF(!PyList_CheckExact(list), STORE_SUBSCR);
// Ensure nonnegative, zero-or-one-digit ints.
- DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), STORE_SUBSCR);
+ DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub), STORE_SUBSCR);
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
// Ensure index < len(list)
DEOPT_IF(index >= PyList_GET_SIZE(list), STORE_SUBSCR);
@@ -730,7 +728,7 @@
Py_DECREF(old_value);
_Py_DECREF_SPECIALIZED(sub, (destructor)PyObject_Free);
Py_DECREF(list);
- #line 734 "Python/generated_cases.c.h"
+ #line 732 "Python/generated_cases.c.h"
STACK_SHRINK(3);
next_instr += 1;
DISPATCH();
@@ -740,14 +738,14 @@
PyObject *sub = stack_pointer[-1];
PyObject *dict = stack_pointer[-2];
PyObject *value = stack_pointer[-3];
- #line 474 "Python/bytecodes.c"
+ #line 472 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
DEOPT_IF(!PyDict_CheckExact(dict), STORE_SUBSCR);
STAT_INC(STORE_SUBSCR, hit);
int err = _PyDict_SetItem_Take2((PyDictObject *)dict, sub, value);
Py_DECREF(dict);
if (err) goto pop_3_error;
- #line 751 "Python/generated_cases.c.h"
+ #line 749 "Python/generated_cases.c.h"
STACK_SHRINK(3);
next_instr += 1;
DISPATCH();
@@ -756,15 +754,15 @@
TARGET(DELETE_SUBSCR) {
PyObject *sub = stack_pointer[-1];
PyObject *container = stack_pointer[-2];
- #line 483 "Python/bytecodes.c"
+ #line 481 "Python/bytecodes.c"
/* del container[sub] */
int err = PyObject_DelItem(container, sub);
- #line 763 "Python/generated_cases.c.h"
+ #line 761 "Python/generated_cases.c.h"
Py_DECREF(container);
Py_DECREF(sub);
- #line 486 "Python/bytecodes.c"
+ #line 484 "Python/bytecodes.c"
if (err) goto pop_2_error;
- #line 768 "Python/generated_cases.c.h"
+ #line 766 "Python/generated_cases.c.h"
STACK_SHRINK(2);
DISPATCH();
}
@@ -772,14 +770,14 @@
TARGET(CALL_INTRINSIC_1) {
PyObject *value = stack_pointer[-1];
PyObject *res;
- #line 490 "Python/bytecodes.c"
+ #line 488 "Python/bytecodes.c"
assert(oparg <= MAX_INTRINSIC_1);
res = _PyIntrinsics_UnaryFunctions[oparg](tstate, value);
- #line 779 "Python/generated_cases.c.h"
+ #line 777 "Python/generated_cases.c.h"
Py_DECREF(value);
- #line 493 "Python/bytecodes.c"
+ #line 491 "Python/bytecodes.c"
if (res == NULL) goto pop_1_error;
- #line 783 "Python/generated_cases.c.h"
+ #line 781 "Python/generated_cases.c.h"
stack_pointer[-1] = res;
DISPATCH();
}
@@ -788,15 +786,15 @@
PyObject *value1 = stack_pointer[-1];
PyObject *value2 = stack_pointer[-2];
PyObject *res;
- #line 497 "Python/bytecodes.c"
+ #line 495 "Python/bytecodes.c"
assert(oparg <= MAX_INTRINSIC_2);
res = _PyIntrinsics_BinaryFunctions[oparg](tstate, value2, value1);
- #line 795 "Python/generated_cases.c.h"
+ #line 793 "Python/generated_cases.c.h"
Py_DECREF(value2);
Py_DECREF(value1);
- #line 500 "Python/bytecodes.c"
+ #line 498 "Python/bytecodes.c"
if (res == NULL) goto pop_2_error;
- #line 800 "Python/generated_cases.c.h"
+ #line 798 "Python/generated_cases.c.h"
STACK_SHRINK(1);
stack_pointer[-1] = res;
DISPATCH();
@@ -804,7 +802,7 @@
TARGET(RAISE_VARARGS) {
PyObject **args = (stack_pointer - oparg);
- #line 504 "Python/bytecodes.c"
+ #line 502 "Python/bytecodes.c"
PyObject *cause = NULL, *exc = NULL;
switch (oparg) {
case 2:
@@ -822,12 +820,12 @@
break;
}
if (true) { STACK_SHRINK(oparg); goto error; }
- #line 826 "Python/generated_cases.c.h"
+ #line 824 "Python/generated_cases.c.h"
}
TARGET(INTERPRETER_EXIT) {
PyObject *retval = stack_pointer[-1];
- #line 524 "Python/bytecodes.c"
+ #line 522 "Python/bytecodes.c"
assert(frame == &entry_frame);
assert(_PyFrame_IsIncomplete(frame));
STACK_SHRINK(1); // Since we're not going to DISPATCH()
@@ -839,12 +837,12 @@
assert(!_PyErr_Occurred(tstate));
_Py_LeaveRecursiveCallTstate(tstate);
return retval;
- #line 843 "Python/generated_cases.c.h"
+ #line 841 "Python/generated_cases.c.h"
}
TARGET(RETURN_VALUE) {
PyObject *retval = stack_pointer[-1];
- #line 538 "Python/bytecodes.c"
+ #line 536 "Python/bytecodes.c"
STACK_SHRINK(1);
assert(EMPTY());
_PyFrame_SetStackPointer(frame, stack_pointer);
@@ -858,11 +856,11 @@
_PyEvalFrameClearAndPop(tstate, dying);
_PyFrame_StackPush(frame, retval);
goto resume_frame;
- #line 862 "Python/generated_cases.c.h"
+ #line 860 "Python/generated_cases.c.h"
}
TARGET(RETURN_CONST) {
- #line 554 "Python/bytecodes.c"
+ #line 552 "Python/bytecodes.c"
PyObject *retval = GETITEM(frame->f_code->co_consts, oparg);
Py_INCREF(retval);
assert(EMPTY());
@@ -877,13 +875,13 @@
_PyEvalFrameClearAndPop(tstate, dying);
_PyFrame_StackPush(frame, retval);
goto resume_frame;
- #line 881 "Python/generated_cases.c.h"
+ #line 879 "Python/generated_cases.c.h"
}
TARGET(GET_AITER) {
PyObject *obj = stack_pointer[-1];
PyObject *iter;
- #line 571 "Python/bytecodes.c"
+ #line 569 "Python/bytecodes.c"
unaryfunc getter = NULL;
PyTypeObject *type = Py_TYPE(obj);
@@ -896,16 +894,16 @@
"'async for' requires an object with "
"__aiter__ method, got %.100s",
type->tp_name);
- #line 900 "Python/generated_cases.c.h"
+ #line 898 "Python/generated_cases.c.h"
Py_DECREF(obj);
- #line 584 "Python/bytecodes.c"
+ #line 582 "Python/bytecodes.c"
if (true) goto pop_1_error;
}
iter = (*getter)(obj);
- #line 907 "Python/generated_cases.c.h"
+ #line 905 "Python/generated_cases.c.h"
Py_DECREF(obj);
- #line 589 "Python/bytecodes.c"
+ #line 587 "Python/bytecodes.c"
if (iter == NULL) goto pop_1_error;
if (Py_TYPE(iter)->tp_as_async == NULL ||
@@ -918,7 +916,7 @@
Py_DECREF(iter);
if (true) goto pop_1_error;
}
- #line 922 "Python/generated_cases.c.h"
+ #line 920 "Python/generated_cases.c.h"
stack_pointer[-1] = iter;
DISPATCH();
}
@@ -926,7 +924,7 @@
TARGET(GET_ANEXT) {
PyObject *aiter = stack_pointer[-1];
PyObject *awaitable;
- #line 604 "Python/bytecodes.c"
+ #line 602 "Python/bytecodes.c"
unaryfunc getter = NULL;
PyObject *next_iter = NULL;
PyTypeObject *type = Py_TYPE(aiter);
@@ -970,7 +968,7 @@
}
}
- #line 974 "Python/generated_cases.c.h"
+ #line 972 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = awaitable;
PREDICT(LOAD_CONST);
@@ -981,16 +979,16 @@
PREDICTED(GET_AWAITABLE);
PyObject *iterable = stack_pointer[-1];
PyObject *iter;
- #line 651 "Python/bytecodes.c"
+ #line 649 "Python/bytecodes.c"
iter = _PyCoro_GetAwaitableIter(iterable);
if (iter == NULL) {
format_awaitable_error(tstate, Py_TYPE(iterable), oparg);
}
- #line 992 "Python/generated_cases.c.h"
+ #line 990 "Python/generated_cases.c.h"
Py_DECREF(iterable);
- #line 658 "Python/bytecodes.c"
+ #line 656 "Python/bytecodes.c"
if (iter != NULL && PyCoro_CheckExact(iter)) {
PyObject *yf = _PyGen_yf((PyGenObject*)iter);
@@ -1008,7 +1006,7 @@
if (iter == NULL) goto pop_1_error;
- #line 1012 "Python/generated_cases.c.h"
+ #line 1010 "Python/generated_cases.c.h"
stack_pointer[-1] = iter;
PREDICT(LOAD_CONST);
DISPATCH();
@@ -1019,7 +1017,7 @@
PyObject *v = stack_pointer[-1];
PyObject *receiver = stack_pointer[-2];
PyObject *retval;
- #line 684 "Python/bytecodes.c"
+ #line 682 "Python/bytecodes.c"
#if ENABLE_SPECIALIZATION
_PySendCache *cache = (_PySendCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -1055,7 +1053,7 @@
assert(retval != NULL);
}
Py_DECREF(v);
- #line 1059 "Python/generated_cases.c.h"
+ #line 1057 "Python/generated_cases.c.h"
stack_pointer[-1] = retval;
next_instr += 1;
DISPATCH();
@@ -1064,7 +1062,7 @@
TARGET(SEND_GEN) {
PyObject *v = stack_pointer[-1];
PyObject *receiver = stack_pointer[-2];
- #line 722 "Python/bytecodes.c"
+ #line 720 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
PyGenObject *gen = (PyGenObject *)receiver;
DEOPT_IF(Py_TYPE(gen) != &PyGen_Type &&
@@ -1080,12 +1078,12 @@
tstate->exc_info = &gen->gi_exc_state;
JUMPBY(INLINE_CACHE_ENTRIES_SEND + oparg);
DISPATCH_INLINED(gen_frame);
- #line 1084 "Python/generated_cases.c.h"
+ #line 1082 "Python/generated_cases.c.h"
}
TARGET(YIELD_VALUE) {
PyObject *retval = stack_pointer[-1];
- #line 740 "Python/bytecodes.c"
+ #line 738 "Python/bytecodes.c"
// NOTE: It's important that YIELD_VALUE never raises an exception!
// The compiler treats any exception raised here as a failed close()
// or throw() call.
@@ -1104,15 +1102,15 @@
frame->prev_instr -= frame->yield_offset;
_PyFrame_StackPush(frame, retval);
goto resume_frame;
- #line 1108 "Python/generated_cases.c.h"
+ #line 1106 "Python/generated_cases.c.h"
}
TARGET(POP_EXCEPT) {
PyObject *exc_value = stack_pointer[-1];
- #line 761 "Python/bytecodes.c"
+ #line 759 "Python/bytecodes.c"
_PyErr_StackItem *exc_info = tstate->exc_info;
Py_XSETREF(exc_info->exc_value, exc_value);
- #line 1116 "Python/generated_cases.c.h"
+ #line 1114 "Python/generated_cases.c.h"
STACK_SHRINK(1);
DISPATCH();
}
@@ -1120,7 +1118,7 @@
TARGET(RERAISE) {
PyObject *exc = stack_pointer[-1];
PyObject **values = (stack_pointer - (1 + oparg));
- #line 766 "Python/bytecodes.c"
+ #line 764 "Python/bytecodes.c"
assert(oparg >= 0 && oparg <= 2);
if (oparg) {
PyObject *lasti = values[0];
@@ -1138,26 +1136,26 @@
Py_INCREF(exc);
_PyErr_SetRaisedException(tstate, exc);
goto exception_unwind;
- #line 1142 "Python/generated_cases.c.h"
+ #line 1140 "Python/generated_cases.c.h"
}
TARGET(END_ASYNC_FOR) {
PyObject *exc = stack_pointer[-1];
PyObject *awaitable = stack_pointer[-2];
- #line 786 "Python/bytecodes.c"
+ #line 784 "Python/bytecodes.c"
assert(exc && PyExceptionInstance_Check(exc));
if (PyErr_GivenExceptionMatches(exc, PyExc_StopAsyncIteration)) {
- #line 1151 "Python/generated_cases.c.h"
+ #line 1149 "Python/generated_cases.c.h"
Py_DECREF(awaitable);
Py_DECREF(exc);
- #line 789 "Python/bytecodes.c"
+ #line 787 "Python/bytecodes.c"
}
else {
Py_INCREF(exc);
_PyErr_SetRaisedException(tstate, exc);
goto exception_unwind;
}
- #line 1161 "Python/generated_cases.c.h"
+ #line 1159 "Python/generated_cases.c.h"
STACK_SHRINK(2);
DISPATCH();
}
@@ -1168,23 +1166,23 @@
PyObject *sub_iter = stack_pointer[-3];
PyObject *none;
PyObject *value;
- #line 798 "Python/bytecodes.c"
+ #line 796 "Python/bytecodes.c"
assert(throwflag);
assert(exc_value && PyExceptionInstance_Check(exc_value));
if (PyErr_GivenExceptionMatches(exc_value, PyExc_StopIteration)) {
value = Py_NewRef(((PyStopIterationObject *)exc_value)->value);
- #line 1177 "Python/generated_cases.c.h"
+ #line 1175 "Python/generated_cases.c.h"
Py_DECREF(sub_iter);
Py_DECREF(last_sent_val);
Py_DECREF(exc_value);
- #line 803 "Python/bytecodes.c"
+ #line 801 "Python/bytecodes.c"
none = Py_NewRef(Py_None);
}
else {
_PyErr_SetRaisedException(tstate, Py_NewRef(exc_value));
goto exception_unwind;
}
- #line 1188 "Python/generated_cases.c.h"
+ #line 1186 "Python/generated_cases.c.h"
STACK_SHRINK(1);
stack_pointer[-1] = value;
stack_pointer[-2] = none;
@@ -1193,9 +1191,9 @@
TARGET(LOAD_ASSERTION_ERROR) {
PyObject *value;
- #line 812 "Python/bytecodes.c"
+ #line 810 "Python/bytecodes.c"
value = Py_NewRef(PyExc_AssertionError);
- #line 1199 "Python/generated_cases.c.h"
+ #line 1197 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = value;
DISPATCH();
@@ -1203,7 +1201,7 @@
TARGET(LOAD_BUILD_CLASS) {
PyObject *bc;
- #line 816 "Python/bytecodes.c"
+ #line 814 "Python/bytecodes.c"
if (PyDict_CheckExact(BUILTINS())) {
bc = _PyDict_GetItemWithError(BUILTINS(),
&_Py_ID(__build_class__));
@@ -1225,7 +1223,7 @@
if (true) goto error;
}
}
- #line 1229 "Python/generated_cases.c.h"
+ #line 1227 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = bc;
DISPATCH();
@@ -1233,33 +1231,33 @@
TARGET(STORE_NAME) {
PyObject *v = stack_pointer[-1];
- #line 840 "Python/bytecodes.c"
+ #line 838 "Python/bytecodes.c"
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
PyObject *ns = LOCALS();
int err;
if (ns == NULL) {
_PyErr_Format(tstate, PyExc_SystemError,
"no locals found when storing %R", name);
- #line 1244 "Python/generated_cases.c.h"
+ #line 1242 "Python/generated_cases.c.h"
Py_DECREF(v);
- #line 847 "Python/bytecodes.c"
+ #line 845 "Python/bytecodes.c"
if (true) goto pop_1_error;
}
if (PyDict_CheckExact(ns))
err = PyDict_SetItem(ns, name, v);
else
err = PyObject_SetItem(ns, name, v);
- #line 1253 "Python/generated_cases.c.h"
+ #line 1251 "Python/generated_cases.c.h"
Py_DECREF(v);
- #line 854 "Python/bytecodes.c"
+ #line 852 "Python/bytecodes.c"
if (err) goto pop_1_error;
- #line 1257 "Python/generated_cases.c.h"
+ #line 1255 "Python/generated_cases.c.h"
STACK_SHRINK(1);
DISPATCH();
}
TARGET(DELETE_NAME) {
- #line 858 "Python/bytecodes.c"
+ #line 856 "Python/bytecodes.c"
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
PyObject *ns = LOCALS();
int err;
@@ -1276,7 +1274,7 @@
name);
goto error;
}
- #line 1280 "Python/generated_cases.c.h"
+ #line 1278 "Python/generated_cases.c.h"
DISPATCH();
}
@@ -1284,7 +1282,7 @@
PREDICTED(UNPACK_SEQUENCE);
static_assert(INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE == 1, "incorrect cache size");
PyObject *seq = stack_pointer[-1];
- #line 884 "Python/bytecodes.c"
+ #line 882 "Python/bytecodes.c"
#if ENABLE_SPECIALIZATION
_PyUnpackSequenceCache *cache = (_PyUnpackSequenceCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -1298,11 +1296,11 @@
#endif /* ENABLE_SPECIALIZATION */
PyObject **top = stack_pointer + oparg - 1;
int res = unpack_iterable(tstate, seq, oparg, -1, top);
- #line 1302 "Python/generated_cases.c.h"
+ #line 1300 "Python/generated_cases.c.h"
Py_DECREF(seq);
- #line 898 "Python/bytecodes.c"
+ #line 896 "Python/bytecodes.c"
if (res == 0) goto pop_1_error;
- #line 1306 "Python/generated_cases.c.h"
+ #line 1304 "Python/generated_cases.c.h"
STACK_SHRINK(1);
STACK_GROW(oparg);
next_instr += 1;
@@ -1312,14 +1310,14 @@
TARGET(UNPACK_SEQUENCE_TWO_TUPLE) {
PyObject *seq = stack_pointer[-1];
PyObject **values = stack_pointer - (1);
- #line 902 "Python/bytecodes.c"
+ #line 900 "Python/bytecodes.c"
DEOPT_IF(!PyTuple_CheckExact(seq), UNPACK_SEQUENCE);
DEOPT_IF(PyTuple_GET_SIZE(seq) != 2, UNPACK_SEQUENCE);
assert(oparg == 2);
STAT_INC(UNPACK_SEQUENCE, hit);
values[0] = Py_NewRef(PyTuple_GET_ITEM(seq, 1));
values[1] = Py_NewRef(PyTuple_GET_ITEM(seq, 0));
- #line 1323 "Python/generated_cases.c.h"
+ #line 1321 "Python/generated_cases.c.h"
Py_DECREF(seq);
STACK_SHRINK(1);
STACK_GROW(oparg);
@@ -1330,7 +1328,7 @@
TARGET(UNPACK_SEQUENCE_TUPLE) {
PyObject *seq = stack_pointer[-1];
PyObject **values = stack_pointer - (1);
- #line 912 "Python/bytecodes.c"
+ #line 910 "Python/bytecodes.c"
DEOPT_IF(!PyTuple_CheckExact(seq), UNPACK_SEQUENCE);
DEOPT_IF(PyTuple_GET_SIZE(seq) != oparg, UNPACK_SEQUENCE);
STAT_INC(UNPACK_SEQUENCE, hit);
@@ -1338,7 +1336,7 @@
for (int i = oparg; --i >= 0; ) {
*values++ = Py_NewRef(items[i]);
}
- #line 1342 "Python/generated_cases.c.h"
+ #line 1340 "Python/generated_cases.c.h"
Py_DECREF(seq);
STACK_SHRINK(1);
STACK_GROW(oparg);
@@ -1349,7 +1347,7 @@
TARGET(UNPACK_SEQUENCE_LIST) {
PyObject *seq = stack_pointer[-1];
PyObject **values = stack_pointer - (1);
- #line 923 "Python/bytecodes.c"
+ #line 921 "Python/bytecodes.c"
DEOPT_IF(!PyList_CheckExact(seq), UNPACK_SEQUENCE);
DEOPT_IF(PyList_GET_SIZE(seq) != oparg, UNPACK_SEQUENCE);
STAT_INC(UNPACK_SEQUENCE, hit);
@@ -1357,7 +1355,7 @@
for (int i = oparg; --i >= 0; ) {
*values++ = Py_NewRef(items[i]);
}
- #line 1361 "Python/generated_cases.c.h"
+ #line 1359 "Python/generated_cases.c.h"
Py_DECREF(seq);
STACK_SHRINK(1);
STACK_GROW(oparg);
@@ -1367,15 +1365,15 @@
TARGET(UNPACK_EX) {
PyObject *seq = stack_pointer[-1];
- #line 934 "Python/bytecodes.c"
+ #line 932 "Python/bytecodes.c"
int totalargs = 1 + (oparg & 0xFF) + (oparg >> 8);
PyObject **top = stack_pointer + totalargs - 1;
int res = unpack_iterable(tstate, seq, oparg & 0xFF, oparg >> 8, top);
- #line 1375 "Python/generated_cases.c.h"
+ #line 1373 "Python/generated_cases.c.h"
Py_DECREF(seq);
- #line 938 "Python/bytecodes.c"
+ #line 936 "Python/bytecodes.c"
if (res == 0) goto pop_1_error;
- #line 1379 "Python/generated_cases.c.h"
+ #line 1377 "Python/generated_cases.c.h"
STACK_GROW((oparg & 0xFF) + (oparg >> 8));
DISPATCH();
}
@@ -1386,7 +1384,7 @@
PyObject *owner = stack_pointer[-1];
PyObject *v = stack_pointer[-2];
uint16_t counter = read_u16(&next_instr[0].cache);
- #line 949 "Python/bytecodes.c"
+ #line 947 "Python/bytecodes.c"
#if ENABLE_SPECIALIZATION
if (ADAPTIVE_COUNTER_IS_ZERO(counter)) {
assert(cframe.use_tracing == 0);
@@ -1403,12 +1401,12 @@
#endif /* ENABLE_SPECIALIZATION */
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
int err = PyObject_SetAttr(owner, name, v);
- #line 1407 "Python/generated_cases.c.h"
+ #line 1405 "Python/generated_cases.c.h"
Py_DECREF(v);
Py_DECREF(owner);
- #line 966 "Python/bytecodes.c"
+ #line 964 "Python/bytecodes.c"
if (err) goto pop_2_error;
- #line 1412 "Python/generated_cases.c.h"
+ #line 1410 "Python/generated_cases.c.h"
STACK_SHRINK(2);
next_instr += 4;
DISPATCH();
@@ -1416,34 +1414,34 @@
TARGET(DELETE_ATTR) {
PyObject *owner = stack_pointer[-1];
- #line 970 "Python/bytecodes.c"
+ #line 968 "Python/bytecodes.c"
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
int err = PyObject_SetAttr(owner, name, (PyObject *)NULL);
- #line 1423 "Python/generated_cases.c.h"
+ #line 1421 "Python/generated_cases.c.h"
Py_DECREF(owner);
- #line 973 "Python/bytecodes.c"
+ #line 971 "Python/bytecodes.c"
if (err) goto pop_1_error;
- #line 1427 "Python/generated_cases.c.h"
+ #line 1425 "Python/generated_cases.c.h"
STACK_SHRINK(1);
DISPATCH();
}
TARGET(STORE_GLOBAL) {
PyObject *v = stack_pointer[-1];
- #line 977 "Python/bytecodes.c"
+ #line 975 "Python/bytecodes.c"
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
int err = PyDict_SetItem(GLOBALS(), name, v);
- #line 1437 "Python/generated_cases.c.h"
+ #line 1435 "Python/generated_cases.c.h"
Py_DECREF(v);
- #line 980 "Python/bytecodes.c"
+ #line 978 "Python/bytecodes.c"
if (err) goto pop_1_error;
- #line 1441 "Python/generated_cases.c.h"
+ #line 1439 "Python/generated_cases.c.h"
STACK_SHRINK(1);
DISPATCH();
}
TARGET(DELETE_GLOBAL) {
- #line 984 "Python/bytecodes.c"
+ #line 982 "Python/bytecodes.c"
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
int err;
err = PyDict_DelItem(GLOBALS(), name);
@@ -1455,13 +1453,13 @@
}
goto error;
}
- #line 1459 "Python/generated_cases.c.h"
+ #line 1457 "Python/generated_cases.c.h"
DISPATCH();
}
TARGET(LOAD_NAME) {
PyObject *v;
- #line 998 "Python/bytecodes.c"
+ #line 996 "Python/bytecodes.c"
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
PyObject *locals = LOCALS();
if (locals == NULL) {
@@ -1520,7 +1518,7 @@
}
}
}
- #line 1524 "Python/generated_cases.c.h"
+ #line 1522 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = v;
DISPATCH();
@@ -1531,7 +1529,7 @@
static_assert(INLINE_CACHE_ENTRIES_LOAD_GLOBAL == 4, "incorrect cache size");
PyObject *null = NULL;
PyObject *v;
- #line 1065 "Python/bytecodes.c"
+ #line 1063 "Python/bytecodes.c"
#if ENABLE_SPECIALIZATION
_PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -1584,7 +1582,7 @@
}
}
null = NULL;
- #line 1588 "Python/generated_cases.c.h"
+ #line 1586 "Python/generated_cases.c.h"
STACK_GROW(1);
STACK_GROW(((oparg & 1) ? 1 : 0));
stack_pointer[-1] = v;
@@ -1598,7 +1596,7 @@
PyObject *res;
uint16_t index = read_u16(&next_instr[1].cache);
uint16_t version = read_u16(&next_instr[2].cache);
- #line 1120 "Python/bytecodes.c"
+ #line 1118 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL);
PyDictObject *dict = (PyDictObject *)GLOBALS();
@@ -1610,7 +1608,7 @@
Py_INCREF(res);
STAT_INC(LOAD_GLOBAL, hit);
null = NULL;
- #line 1614 "Python/generated_cases.c.h"
+ #line 1612 "Python/generated_cases.c.h"
STACK_GROW(1);
STACK_GROW(((oparg & 1) ? 1 : 0));
stack_pointer[-1] = res;
@@ -1625,7 +1623,7 @@
uint16_t index = read_u16(&next_instr[1].cache);
uint16_t mod_version = read_u16(&next_instr[2].cache);
uint16_t bltn_version = read_u16(&next_instr[3].cache);
- #line 1134 "Python/bytecodes.c"
+ #line 1132 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL);
DEOPT_IF(!PyDict_CheckExact(BUILTINS()), LOAD_GLOBAL);
@@ -1640,7 +1638,7 @@
Py_INCREF(res);
STAT_INC(LOAD_GLOBAL, hit);
null = NULL;
- #line 1644 "Python/generated_cases.c.h"
+ #line 1642 "Python/generated_cases.c.h"
STACK_GROW(1);
STACK_GROW(((oparg & 1) ? 1 : 0));
stack_pointer[-1] = res;
@@ -1650,16 +1648,16 @@
}
TARGET(DELETE_FAST) {
- #line 1151 "Python/bytecodes.c"
+ #line 1149 "Python/bytecodes.c"
PyObject *v = GETLOCAL(oparg);
if (v == NULL) goto unbound_local_error;
SETLOCAL(oparg, NULL);
- #line 1658 "Python/generated_cases.c.h"
+ #line 1656 "Python/generated_cases.c.h"
DISPATCH();
}
TARGET(MAKE_CELL) {
- #line 1157 "Python/bytecodes.c"
+ #line 1155 "Python/bytecodes.c"
// "initial" is probably NULL but not if it's an arg (or set
// via PyFrame_LocalsToFast() before MAKE_CELL has run).
PyObject *initial = GETLOCAL(oparg);
@@ -1668,12 +1666,12 @@
goto resume_with_error;
}
SETLOCAL(oparg, cell);
- #line 1672 "Python/generated_cases.c.h"
+ #line 1670 "Python/generated_cases.c.h"
DISPATCH();
}
TARGET(DELETE_DEREF) {
- #line 1168 "Python/bytecodes.c"
+ #line 1166 "Python/bytecodes.c"
PyObject *cell = GETLOCAL(oparg);
PyObject *oldobj = PyCell_GET(cell);
// Can't use ERROR_IF here.
@@ -1684,13 +1682,13 @@
}
PyCell_SET(cell, NULL);
Py_DECREF(oldobj);
- #line 1688 "Python/generated_cases.c.h"
+ #line 1686 "Python/generated_cases.c.h"
DISPATCH();
}
TARGET(LOAD_CLASSDEREF) {
PyObject *value;
- #line 1181 "Python/bytecodes.c"
+ #line 1179 "Python/bytecodes.c"
PyObject *name, *locals = LOCALS();
assert(locals);
assert(oparg >= 0 && oparg < frame->f_code->co_nlocalsplus);
@@ -1722,7 +1720,7 @@
}
Py_INCREF(value);
}
- #line 1726 "Python/generated_cases.c.h"
+ #line 1724 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = value;
DISPATCH();
@@ -1730,7 +1728,7 @@
TARGET(LOAD_DEREF) {
PyObject *value;
- #line 1215 "Python/bytecodes.c"
+ #line 1213 "Python/bytecodes.c"
PyObject *cell = GETLOCAL(oparg);
value = PyCell_GET(cell);
if (value == NULL) {
@@ -1738,7 +1736,7 @@
if (true) goto error;
}
Py_INCREF(value);
- #line 1742 "Python/generated_cases.c.h"
+ #line 1740 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = value;
DISPATCH();
@@ -1746,18 +1744,18 @@
TARGET(STORE_DEREF) {
PyObject *v = stack_pointer[-1];
- #line 1225 "Python/bytecodes.c"
+ #line 1223 "Python/bytecodes.c"
PyObject *cell = GETLOCAL(oparg);
PyObject *oldobj = PyCell_GET(cell);
PyCell_SET(cell, v);
Py_XDECREF(oldobj);
- #line 1755 "Python/generated_cases.c.h"
+ #line 1753 "Python/generated_cases.c.h"
STACK_SHRINK(1);
DISPATCH();
}
TARGET(COPY_FREE_VARS) {
- #line 1232 "Python/bytecodes.c"
+ #line 1230 "Python/bytecodes.c"
/* Copy closure variables to free variables */
PyCodeObject *co = frame->f_code;
assert(PyFunction_Check(frame->f_funcobj));
@@ -1768,22 +1766,22 @@
PyObject *o = PyTuple_GET_ITEM(closure, i);
frame->localsplus[offset + i] = Py_NewRef(o);
}
- #line 1772 "Python/generated_cases.c.h"
+ #line 1770 "Python/generated_cases.c.h"
DISPATCH();
}
TARGET(BUILD_STRING) {
PyObject **pieces = (stack_pointer - oparg);
PyObject *str;
- #line 1245 "Python/bytecodes.c"
+ #line 1243 "Python/bytecodes.c"
str = _PyUnicode_JoinArray(&_Py_STR(empty), pieces, oparg);
- #line 1781 "Python/generated_cases.c.h"
+ #line 1779 "Python/generated_cases.c.h"
for (int _i = oparg; --_i >= 0;) {
Py_DECREF(pieces[_i]);
}
- #line 1247 "Python/bytecodes.c"
+ #line 1245 "Python/bytecodes.c"
if (str == NULL) { STACK_SHRINK(oparg); goto error; }
- #line 1787 "Python/generated_cases.c.h"
+ #line 1785 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_GROW(1);
stack_pointer[-1] = str;
@@ -1793,10 +1791,10 @@
TARGET(BUILD_TUPLE) {
PyObject **values = (stack_pointer - oparg);
PyObject *tup;
- #line 1251 "Python/bytecodes.c"
+ #line 1249 "Python/bytecodes.c"
tup = _PyTuple_FromArraySteal(values, oparg);
if (tup == NULL) { STACK_SHRINK(oparg); goto error; }
- #line 1800 "Python/generated_cases.c.h"
+ #line 1798 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_GROW(1);
stack_pointer[-1] = tup;
@@ -1806,10 +1804,10 @@
TARGET(BUILD_LIST) {
PyObject **values = (stack_pointer - oparg);
PyObject *list;
- #line 1256 "Python/bytecodes.c"
+ #line 1254 "Python/bytecodes.c"
list = _PyList_FromArraySteal(values, oparg);
if (list == NULL) { STACK_SHRINK(oparg); goto error; }
- #line 1813 "Python/generated_cases.c.h"
+ #line 1811 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_GROW(1);
stack_pointer[-1] = list;
@@ -1819,7 +1817,7 @@
TARGET(LIST_EXTEND) {
PyObject *iterable = stack_pointer[-1];
PyObject *list = stack_pointer[-(2 + (oparg-1))];
- #line 1261 "Python/bytecodes.c"
+ #line 1259 "Python/bytecodes.c"
PyObject *none_val = _PyList_Extend((PyListObject *)list, iterable);
if (none_val == NULL) {
if (_PyErr_ExceptionMatches(tstate, PyExc_TypeError) &&
@@ -1830,13 +1828,13 @@
"Value after * must be an iterable, not %.200s",
Py_TYPE(iterable)->tp_name);
}
- #line 1834 "Python/generated_cases.c.h"
+ #line 1832 "Python/generated_cases.c.h"
Py_DECREF(iterable);
- #line 1272 "Python/bytecodes.c"
+ #line 1270 "Python/bytecodes.c"
if (true) goto pop_1_error;
}
Py_DECREF(none_val);
- #line 1840 "Python/generated_cases.c.h"
+ #line 1838 "Python/generated_cases.c.h"
Py_DECREF(iterable);
STACK_SHRINK(1);
DISPATCH();
@@ -1845,13 +1843,13 @@
TARGET(SET_UPDATE) {
PyObject *iterable = stack_pointer[-1];
PyObject *set = stack_pointer[-(2 + (oparg-1))];
- #line 1279 "Python/bytecodes.c"
+ #line 1277 "Python/bytecodes.c"
int err = _PySet_Update(set, iterable);
- #line 1851 "Python/generated_cases.c.h"
+ #line 1849 "Python/generated_cases.c.h"
Py_DECREF(iterable);
- #line 1281 "Python/bytecodes.c"
+ #line 1279 "Python/bytecodes.c"
if (err < 0) goto pop_1_error;
- #line 1855 "Python/generated_cases.c.h"
+ #line 1853 "Python/generated_cases.c.h"
STACK_SHRINK(1);
DISPATCH();
}
@@ -1859,7 +1857,7 @@
TARGET(BUILD_SET) {
PyObject **values = (stack_pointer - oparg);
PyObject *set;
- #line 1285 "Python/bytecodes.c"
+ #line 1283 "Python/bytecodes.c"
set = PySet_New(NULL);
if (set == NULL)
goto error;
@@ -1874,7 +1872,7 @@
Py_DECREF(set);
if (true) { STACK_SHRINK(oparg); goto error; }
}
- #line 1878 "Python/generated_cases.c.h"
+ #line 1876 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_GROW(1);
stack_pointer[-1] = set;
@@ -1884,7 +1882,7 @@
TARGET(BUILD_MAP) {
PyObject **values = (stack_pointer - oparg*2);
PyObject *map;
- #line 1302 "Python/bytecodes.c"
+ #line 1300 "Python/bytecodes.c"
map = _PyDict_FromItems(
values, 2,
values+1, 2,
@@ -1892,13 +1890,13 @@
if (map == NULL)
goto error;
- #line 1896 "Python/generated_cases.c.h"
+ #line 1894 "Python/generated_cases.c.h"
for (int _i = oparg*2; --_i >= 0;) {
Py_DECREF(values[_i]);
}
- #line 1310 "Python/bytecodes.c"
+ #line 1308 "Python/bytecodes.c"
if (map == NULL) { STACK_SHRINK(oparg*2); goto error; }
- #line 1902 "Python/generated_cases.c.h"
+ #line 1900 "Python/generated_cases.c.h"
STACK_SHRINK(oparg*2);
STACK_GROW(1);
stack_pointer[-1] = map;
@@ -1906,7 +1904,7 @@
}
TARGET(SETUP_ANNOTATIONS) {
- #line 1314 "Python/bytecodes.c"
+ #line 1312 "Python/bytecodes.c"
int err;
PyObject *ann_dict;
if (LOCALS() == NULL) {
@@ -1946,7 +1944,7 @@
Py_DECREF(ann_dict);
}
}
- #line 1950 "Python/generated_cases.c.h"
+ #line 1948 "Python/generated_cases.c.h"
DISPATCH();
}
@@ -1954,7 +1952,7 @@
PyObject *keys = stack_pointer[-1];
PyObject **values = (stack_pointer - (1 + oparg));
PyObject *map;
- #line 1356 "Python/bytecodes.c"
+ #line 1354 "Python/bytecodes.c"
if (!PyTuple_CheckExact(keys) ||
PyTuple_GET_SIZE(keys) != (Py_ssize_t)oparg) {
_PyErr_SetString(tstate, PyExc_SystemError,
@@ -1964,14 +1962,14 @@
map = _PyDict_FromItems(
&PyTuple_GET_ITEM(keys, 0), 1,
values, 1, oparg);
- #line 1968 "Python/generated_cases.c.h"
+ #line 1966 "Python/generated_cases.c.h"
for (int _i = oparg; --_i >= 0;) {
Py_DECREF(values[_i]);
}
Py_DECREF(keys);
- #line 1366 "Python/bytecodes.c"
+ #line 1364 "Python/bytecodes.c"
if (map == NULL) { STACK_SHRINK(oparg); goto pop_1_error; }
- #line 1975 "Python/generated_cases.c.h"
+ #line 1973 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
stack_pointer[-1] = map;
DISPATCH();
@@ -1979,7 +1977,7 @@
TARGET(DICT_UPDATE) {
PyObject *update = stack_pointer[-1];
- #line 1370 "Python/bytecodes.c"
+ #line 1368 "Python/bytecodes.c"
PyObject *dict = PEEK(oparg + 1); // update is still on the stack
if (PyDict_Update(dict, update) < 0) {
if (_PyErr_ExceptionMatches(tstate, PyExc_AttributeError)) {
@@ -1987,12 +1985,12 @@
"'%.200s' object is not a mapping",
Py_TYPE(update)->tp_name);
}
- #line 1991 "Python/generated_cases.c.h"
+ #line 1989 "Python/generated_cases.c.h"
Py_DECREF(update);
- #line 1378 "Python/bytecodes.c"
+ #line 1376 "Python/bytecodes.c"
if (true) goto pop_1_error;
}
- #line 1996 "Python/generated_cases.c.h"
+ #line 1994 "Python/generated_cases.c.h"
Py_DECREF(update);
STACK_SHRINK(1);
DISPATCH();
@@ -2000,17 +1998,17 @@
TARGET(DICT_MERGE) {
PyObject *update = stack_pointer[-1];
- #line 1384 "Python/bytecodes.c"
+ #line 1382 "Python/bytecodes.c"
PyObject *dict = PEEK(oparg + 1); // update is still on the stack
if (_PyDict_MergeEx(dict, update, 2) < 0) {
format_kwargs_error(tstate, PEEK(3 + oparg), update);
- #line 2009 "Python/generated_cases.c.h"
+ #line 2007 "Python/generated_cases.c.h"
Py_DECREF(update);
- #line 1389 "Python/bytecodes.c"
+ #line 1387 "Python/bytecodes.c"
if (true) goto pop_1_error;
}
- #line 2014 "Python/generated_cases.c.h"
+ #line 2012 "Python/generated_cases.c.h"
Py_DECREF(update);
STACK_SHRINK(1);
PREDICT(CALL_FUNCTION_EX);
@@ -2020,13 +2018,13 @@
TARGET(MAP_ADD) {
PyObject *value = stack_pointer[-1];
PyObject *key = stack_pointer[-2];
- #line 1396 "Python/bytecodes.c"
+ #line 1394 "Python/bytecodes.c"
PyObject *dict = PEEK(oparg + 2); // key, value are still on the stack
assert(PyDict_CheckExact(dict));
/* dict[key] = value */
// Do not DECREF INPUTS because the function steals the references
if (_PyDict_SetItem_Take2((PyDictObject *)dict, key, value) != 0) goto pop_2_error;
- #line 2030 "Python/generated_cases.c.h"
+ #line 2028 "Python/generated_cases.c.h"
STACK_SHRINK(2);
PREDICT(JUMP_BACKWARD);
DISPATCH();
@@ -2038,7 +2036,7 @@
PyObject *owner = stack_pointer[-1];
PyObject *res2 = NULL;
PyObject *res;
- #line 1419 "Python/bytecodes.c"
+ #line 1417 "Python/bytecodes.c"
#if ENABLE_SPECIALIZATION
_PyAttrCache *cache = (_PyAttrCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -2073,9 +2071,9 @@
NULL | meth | arg1 | ... | argN
*/
- #line 2077 "Python/generated_cases.c.h"
+ #line 2075 "Python/generated_cases.c.h"
Py_DECREF(owner);
- #line 1454 "Python/bytecodes.c"
+ #line 1452 "Python/bytecodes.c"
if (meth == NULL) goto pop_1_error;
res2 = NULL;
res = meth;
@@ -2084,12 +2082,12 @@
else {
/* Classic, pushes one value. */
res = PyObject_GetAttr(owner, name);
- #line 2088 "Python/generated_cases.c.h"
+ #line 2086 "Python/generated_cases.c.h"
Py_DECREF(owner);
- #line 1463 "Python/bytecodes.c"
+ #line 1461 "Python/bytecodes.c"
if (res == NULL) goto pop_1_error;
}
- #line 2093 "Python/generated_cases.c.h"
+ #line 2091 "Python/generated_cases.c.h"
STACK_GROW(((oparg & 1) ? 1 : 0));
stack_pointer[-1] = res;
if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; }
@@ -2103,7 +2101,7 @@
PyObject *res;
uint32_t type_version = read_u32(&next_instr[1].cache);
uint16_t index = read_u16(&next_instr[3].cache);
- #line 1468 "Python/bytecodes.c"
+ #line 1466 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
PyTypeObject *tp = Py_TYPE(owner);
assert(type_version != 0);
@@ -2117,7 +2115,7 @@
STAT_INC(LOAD_ATTR, hit);
Py_INCREF(res);
res2 = NULL;
- #line 2121 "Python/generated_cases.c.h"
+ #line 2119 "Python/generated_cases.c.h"
Py_DECREF(owner);
STACK_GROW(((oparg & 1) ? 1 : 0));
stack_pointer[-1] = res;
@@ -2132,7 +2130,7 @@
PyObject *res;
uint32_t type_version = read_u32(&next_instr[1].cache);
uint16_t index = read_u16(&next_instr[3].cache);
- #line 1485 "Python/bytecodes.c"
+ #line 1483 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
DEOPT_IF(!PyModule_CheckExact(owner), LOAD_ATTR);
PyDictObject *dict = (PyDictObject *)((PyModuleObject *)owner)->md_dict;
@@ -2146,7 +2144,7 @@
STAT_INC(LOAD_ATTR, hit);
Py_INCREF(res);
res2 = NULL;
- #line 2150 "Python/generated_cases.c.h"
+ #line 2148 "Python/generated_cases.c.h"
Py_DECREF(owner);
STACK_GROW(((oparg & 1) ? 1 : 0));
stack_pointer[-1] = res;
@@ -2161,7 +2159,7 @@
PyObject *res;
uint32_t type_version = read_u32(&next_instr[1].cache);
uint16_t index = read_u16(&next_instr[3].cache);
- #line 1502 "Python/bytecodes.c"
+ #line 1500 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
PyTypeObject *tp = Py_TYPE(owner);
assert(type_version != 0);
@@ -2189,7 +2187,7 @@
STAT_INC(LOAD_ATTR, hit);
Py_INCREF(res);
res2 = NULL;
- #line 2193 "Python/generated_cases.c.h"
+ #line 2191 "Python/generated_cases.c.h"
Py_DECREF(owner);
STACK_GROW(((oparg & 1) ? 1 : 0));
stack_pointer[-1] = res;
@@ -2204,7 +2202,7 @@
PyObject *res;
uint32_t type_version = read_u32(&next_instr[1].cache);
uint16_t index = read_u16(&next_instr[3].cache);
- #line 1533 "Python/bytecodes.c"
+ #line 1531 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
PyTypeObject *tp = Py_TYPE(owner);
assert(type_version != 0);
@@ -2215,7 +2213,7 @@
STAT_INC(LOAD_ATTR, hit);
Py_INCREF(res);
res2 = NULL;
- #line 2219 "Python/generated_cases.c.h"
+ #line 2217 "Python/generated_cases.c.h"
Py_DECREF(owner);
STACK_GROW(((oparg & 1) ? 1 : 0));
stack_pointer[-1] = res;
@@ -2230,7 +2228,7 @@
PyObject *res;
uint32_t type_version = read_u32(&next_instr[1].cache);
PyObject *descr = read_obj(&next_instr[5].cache);
- #line 1547 "Python/bytecodes.c"
+ #line 1545 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
DEOPT_IF(!PyType_Check(cls), LOAD_ATTR);
@@ -2243,7 +2241,7 @@
res = descr;
assert(res != NULL);
Py_INCREF(res);
- #line 2247 "Python/generated_cases.c.h"
+ #line 2245 "Python/generated_cases.c.h"
Py_DECREF(cls);
STACK_GROW(((oparg & 1) ? 1 : 0));
stack_pointer[-1] = res;
@@ -2257,7 +2255,7 @@
uint32_t type_version = read_u32(&next_instr[1].cache);
uint32_t func_version = read_u32(&next_instr[3].cache);
PyObject *fget = read_obj(&next_instr[5].cache);
- #line 1563 "Python/bytecodes.c"
+ #line 1561 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
DEOPT_IF(tstate->interp->eval_frame, LOAD_ATTR);
@@ -2281,7 +2279,7 @@
new_frame->localsplus[0] = owner;
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
DISPATCH_INLINED(new_frame);
- #line 2285 "Python/generated_cases.c.h"
+ #line 2283 "Python/generated_cases.c.h"
}
TARGET(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN) {
@@ -2289,7 +2287,7 @@
uint32_t type_version = read_u32(&next_instr[1].cache);
uint32_t func_version = read_u32(&next_instr[3].cache);
PyObject *getattribute = read_obj(&next_instr[5].cache);
- #line 1589 "Python/bytecodes.c"
+ #line 1587 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
DEOPT_IF(tstate->interp->eval_frame, LOAD_ATTR);
PyTypeObject *cls = Py_TYPE(owner);
@@ -2315,7 +2313,7 @@
new_frame->localsplus[1] = Py_NewRef(name);
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
DISPATCH_INLINED(new_frame);
- #line 2319 "Python/generated_cases.c.h"
+ #line 2317 "Python/generated_cases.c.h"
}
TARGET(STORE_ATTR_INSTANCE_VALUE) {
@@ -2323,7 +2321,7 @@
PyObject *value = stack_pointer[-2];
uint32_t type_version = read_u32(&next_instr[1].cache);
uint16_t index = read_u16(&next_instr[3].cache);
- #line 1617 "Python/bytecodes.c"
+ #line 1615 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
PyTypeObject *tp = Py_TYPE(owner);
assert(type_version != 0);
@@ -2342,7 +2340,7 @@
Py_DECREF(old_value);
}
Py_DECREF(owner);
- #line 2346 "Python/generated_cases.c.h"
+ #line 2344 "Python/generated_cases.c.h"
STACK_SHRINK(2);
next_instr += 4;
DISPATCH();
@@ -2353,7 +2351,7 @@
PyObject *value = stack_pointer[-2];
uint32_t type_version = read_u32(&next_instr[1].cache);
uint16_t hint = read_u16(&next_instr[3].cache);
- #line 1638 "Python/bytecodes.c"
+ #line 1636 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
PyTypeObject *tp = Py_TYPE(owner);
assert(type_version != 0);
@@ -2393,7 +2391,7 @@
/* PEP 509 */
dict->ma_version_tag = new_version;
Py_DECREF(owner);
- #line 2397 "Python/generated_cases.c.h"
+ #line 2395 "Python/generated_cases.c.h"
STACK_SHRINK(2);
next_instr += 4;
DISPATCH();
@@ -2404,7 +2402,7 @@
PyObject *value = stack_pointer[-2];
uint32_t type_version = read_u32(&next_instr[1].cache);
uint16_t index = read_u16(&next_instr[3].cache);
- #line 1680 "Python/bytecodes.c"
+ #line 1678 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
PyTypeObject *tp = Py_TYPE(owner);
assert(type_version != 0);
@@ -2415,7 +2413,7 @@
*(PyObject **)addr = value;
Py_XDECREF(old_value);
Py_DECREF(owner);
- #line 2419 "Python/generated_cases.c.h"
+ #line 2417 "Python/generated_cases.c.h"
STACK_SHRINK(2);
next_instr += 4;
DISPATCH();
@@ -2425,16 +2423,16 @@
PyObject *right = stack_pointer[-1];
PyObject *left = stack_pointer[-2];
PyObject *res;
- #line 1693 "Python/bytecodes.c"
+ #line 1691 "Python/bytecodes.c"
STAT_INC(COMPARE_OP, deferred);
assert((oparg >> 4) <= Py_GE);
res = PyObject_RichCompare(left, right, oparg>>4);
- #line 2433 "Python/generated_cases.c.h"
+ #line 2431 "Python/generated_cases.c.h"
Py_DECREF(left);
Py_DECREF(right);
- #line 1697 "Python/bytecodes.c"
+ #line 1695 "Python/bytecodes.c"
if (res == NULL) goto pop_2_error;
- #line 2438 "Python/generated_cases.c.h"
+ #line 2436 "Python/generated_cases.c.h"
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 1;
@@ -2445,7 +2443,7 @@
PREDICTED(COMPARE_AND_BRANCH);
PyObject *right = stack_pointer[-1];
PyObject *left = stack_pointer[-2];
- #line 1709 "Python/bytecodes.c"
+ #line 1707 "Python/bytecodes.c"
#if ENABLE_SPECIALIZATION
_PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -2459,10 +2457,10 @@
#endif /* ENABLE_SPECIALIZATION */
assert((oparg >> 4) <= Py_GE);
PyObject *cond = PyObject_RichCompare(left, right, oparg>>4);
- #line 2463 "Python/generated_cases.c.h"
+ #line 2461 "Python/generated_cases.c.h"
Py_DECREF(left);
Py_DECREF(right);
- #line 1723 "Python/bytecodes.c"
+ #line 1721 "Python/bytecodes.c"
if (cond == NULL) goto pop_2_error;
assert(next_instr[1].op.code == POP_JUMP_IF_FALSE ||
next_instr[1].op.code == POP_JUMP_IF_TRUE);
@@ -2474,7 +2472,7 @@
if (jump_on_true == (err != 0)) {
JUMPBY(offset);
}
- #line 2478 "Python/generated_cases.c.h"
+ #line 2476 "Python/generated_cases.c.h"
STACK_SHRINK(2);
next_instr += 2;
DISPATCH();
@@ -2483,7 +2481,7 @@
TARGET(COMPARE_AND_BRANCH_FLOAT) {
PyObject *right = stack_pointer[-1];
PyObject *left = stack_pointer[-2];
- #line 1737 "Python/bytecodes.c"
+ #line 1735 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
DEOPT_IF(!PyFloat_CheckExact(left), COMPARE_AND_BRANCH);
DEOPT_IF(!PyFloat_CheckExact(right), COMPARE_AND_BRANCH);
@@ -2498,7 +2496,7 @@
int offset = next_instr[1].op.arg;
JUMPBY(offset);
}
- #line 2502 "Python/generated_cases.c.h"
+ #line 2500 "Python/generated_cases.c.h"
STACK_SHRINK(2);
next_instr += 2;
DISPATCH();
@@ -2507,16 +2505,17 @@
TARGET(COMPARE_AND_BRANCH_INT) {
PyObject *right = stack_pointer[-1];
PyObject *left = stack_pointer[-2];
- #line 1755 "Python/bytecodes.c"
+ #line 1753 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
DEOPT_IF(!PyLong_CheckExact(left), COMPARE_AND_BRANCH);
DEOPT_IF(!PyLong_CheckExact(right), COMPARE_AND_BRANCH);
- DEOPT_IF((size_t)(Py_SIZE(left) + 1) > 2, COMPARE_AND_BRANCH);
- DEOPT_IF((size_t)(Py_SIZE(right) + 1) > 2, COMPARE_AND_BRANCH);
+ DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)left), COMPARE_AND_BRANCH);
+ DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)right), COMPARE_AND_BRANCH);
STAT_INC(COMPARE_AND_BRANCH, hit);
- assert(Py_ABS(Py_SIZE(left)) <= 1 && Py_ABS(Py_SIZE(right)) <= 1);
- Py_ssize_t ileft = Py_SIZE(left) * ((PyLongObject *)left)->long_value.ob_digit[0];
- Py_ssize_t iright = Py_SIZE(right) * ((PyLongObject *)right)->long_value.ob_digit[0];
+ assert(_PyLong_DigitCount((PyLongObject *)left) <= 1 &&
+ _PyLong_DigitCount((PyLongObject *)right) <= 1);
+ Py_ssize_t ileft = _PyLong_CompactValue((PyLongObject *)left);
+ Py_ssize_t iright = _PyLong_CompactValue((PyLongObject *)right);
// 2 if <, 4 if >, 8 if ==; this matches the low 4 bits of the oparg
int sign_ish = COMPARISON_BIT(ileft, iright);
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
@@ -2525,7 +2524,7 @@
int offset = next_instr[1].op.arg;
JUMPBY(offset);
}
- #line 2529 "Python/generated_cases.c.h"
+ #line 2528 "Python/generated_cases.c.h"
STACK_SHRINK(2);
next_instr += 2;
DISPATCH();
@@ -2534,7 +2533,7 @@
TARGET(COMPARE_AND_BRANCH_STR) {
PyObject *right = stack_pointer[-1];
PyObject *left = stack_pointer[-2];
- #line 1776 "Python/bytecodes.c"
+ #line 1775 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_AND_BRANCH);
DEOPT_IF(!PyUnicode_CheckExact(right), COMPARE_AND_BRANCH);
@@ -2550,7 +2549,7 @@
int offset = next_instr[1].op.arg;
JUMPBY(offset);
}
- #line 2554 "Python/generated_cases.c.h"
+ #line 2553 "Python/generated_cases.c.h"
STACK_SHRINK(2);
next_instr += 2;
DISPATCH();
@@ -2560,14 +2559,14 @@
PyObject *right = stack_pointer[-1];
PyObject *left = stack_pointer[-2];
PyObject *b;
- #line 1794 "Python/bytecodes.c"
+ #line 1793 "Python/bytecodes.c"
int res = Py_Is(left, right) ^ oparg;
- #line 2566 "Python/generated_cases.c.h"
+ #line 2565 "Python/generated_cases.c.h"
Py_DECREF(left);
Py_DECREF(right);
- #line 1796 "Python/bytecodes.c"
+ #line 1795 "Python/bytecodes.c"
b = Py_NewRef(res ? Py_True : Py_False);
- #line 2571 "Python/generated_cases.c.h"
+ #line 2570 "Python/generated_cases.c.h"
STACK_SHRINK(1);
stack_pointer[-1] = b;
DISPATCH();
@@ -2577,15 +2576,15 @@
PyObject *right = stack_pointer[-1];
PyObject *left = stack_pointer[-2];
PyObject *b;
- #line 1800 "Python/bytecodes.c"
+ #line 1799 "Python/bytecodes.c"
int res = PySequence_Contains(right, left);
- #line 2583 "Python/generated_cases.c.h"
+ #line 2582 "Python/generated_cases.c.h"
Py_DECREF(left);
Py_DECREF(right);
- #line 1802 "Python/bytecodes.c"
+ #line 1801 "Python/bytecodes.c"
if (res < 0) goto pop_2_error;
b = Py_NewRef((res^oparg) ? Py_True : Py_False);
- #line 2589 "Python/generated_cases.c.h"
+ #line 2588 "Python/generated_cases.c.h"
STACK_SHRINK(1);
stack_pointer[-1] = b;
DISPATCH();
@@ -2596,12 +2595,12 @@
PyObject *exc_value = stack_pointer[-2];
PyObject *rest;
PyObject *match;
- #line 1807 "Python/bytecodes.c"
+ #line 1806 "Python/bytecodes.c"
if (check_except_star_type_valid(tstate, match_type) < 0) {
- #line 2602 "Python/generated_cases.c.h"
+ #line 2601 "Python/generated_cases.c.h"
Py_DECREF(exc_value);
Py_DECREF(match_type);
- #line 1809 "Python/bytecodes.c"
+ #line 1808 "Python/bytecodes.c"
if (true) goto pop_2_error;
}
@@ -2609,10 +2608,10 @@
rest = NULL;
int res = exception_group_match(exc_value, match_type,
&match, &rest);
- #line 2613 "Python/generated_cases.c.h"
+ #line 2612 "Python/generated_cases.c.h"
Py_DECREF(exc_value);
Py_DECREF(match_type);
- #line 1817 "Python/bytecodes.c"
+ #line 1816 "Python/bytecodes.c"
if (res < 0) goto pop_2_error;
assert((match == NULL) == (rest == NULL));
@@ -2621,7 +2620,7 @@
if (!Py_IsNone(match)) {
PyErr_SetExcInfo(NULL, Py_NewRef(match), NULL);
}
- #line 2625 "Python/generated_cases.c.h"
+ #line 2624 "Python/generated_cases.c.h"
stack_pointer[-1] = match;
stack_pointer[-2] = rest;
DISPATCH();
@@ -2631,21 +2630,21 @@
PyObject *right = stack_pointer[-1];
PyObject *left = stack_pointer[-2];
PyObject *b;
- #line 1828 "Python/bytecodes.c"
+ #line 1827 "Python/bytecodes.c"
assert(PyExceptionInstance_Check(left));
if (check_except_type_valid(tstate, right) < 0) {
- #line 2638 "Python/generated_cases.c.h"
+ #line 2637 "Python/generated_cases.c.h"
Py_DECREF(right);
- #line 1831 "Python/bytecodes.c"
+ #line 1830 "Python/bytecodes.c"
if (true) goto pop_1_error;
}
int res = PyErr_GivenExceptionMatches(left, right);
- #line 2645 "Python/generated_cases.c.h"
+ #line 2644 "Python/generated_cases.c.h"
Py_DECREF(right);
- #line 1836 "Python/bytecodes.c"
+ #line 1835 "Python/bytecodes.c"
b = Py_NewRef(res ? Py_True : Py_False);
- #line 2649 "Python/generated_cases.c.h"
+ #line 2648 "Python/generated_cases.c.h"
stack_pointer[-1] = b;
DISPATCH();
}
@@ -2654,15 +2653,15 @@
PyObject *fromlist = stack_pointer[-1];
PyObject *level = stack_pointer[-2];
PyObject *res;
- #line 1840 "Python/bytecodes.c"
+ #line 1839 "Python/bytecodes.c"
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
res = import_name(tstate, frame, name, fromlist, level);
- #line 2661 "Python/generated_cases.c.h"
+ #line 2660 "Python/generated_cases.c.h"
Py_DECREF(level);
Py_DECREF(fromlist);
- #line 1843 "Python/bytecodes.c"
+ #line 1842 "Python/bytecodes.c"
if (res == NULL) goto pop_2_error;
- #line 2666 "Python/generated_cases.c.h"
+ #line 2665 "Python/generated_cases.c.h"
STACK_SHRINK(1);
stack_pointer[-1] = res;
DISPATCH();
@@ -2671,29 +2670,29 @@
TARGET(IMPORT_FROM) {
PyObject *from = stack_pointer[-1];
PyObject *res;
- #line 1847 "Python/bytecodes.c"
+ #line 1846 "Python/bytecodes.c"
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
res = import_from(tstate, from, name);
if (res == NULL) goto error;
- #line 2679 "Python/generated_cases.c.h"
+ #line 2678 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = res;
DISPATCH();
}
TARGET(JUMP_FORWARD) {
- #line 1853 "Python/bytecodes.c"
+ #line 1852 "Python/bytecodes.c"
JUMPBY(oparg);
- #line 2688 "Python/generated_cases.c.h"
+ #line 2687 "Python/generated_cases.c.h"
DISPATCH();
}
TARGET(JUMP_BACKWARD) {
PREDICTED(JUMP_BACKWARD);
- #line 1857 "Python/bytecodes.c"
+ #line 1856 "Python/bytecodes.c"
assert(oparg < INSTR_OFFSET());
JUMPBY(-oparg);
- #line 2697 "Python/generated_cases.c.h"
+ #line 2696 "Python/generated_cases.c.h"
CHECK_EVAL_BREAKER();
DISPATCH();
}
@@ -2701,7 +2700,7 @@
TARGET(POP_JUMP_IF_FALSE) {
PREDICTED(POP_JUMP_IF_FALSE);
PyObject *cond = stack_pointer[-1];
- #line 1863 "Python/bytecodes.c"
+ #line 1862 "Python/bytecodes.c"
if (Py_IsTrue(cond)) {
_Py_DECREF_NO_DEALLOC(cond);
}
@@ -2711,9 +2710,9 @@
}
else {
int err = PyObject_IsTrue(cond);
- #line 2715 "Python/generated_cases.c.h"
+ #line 2714 "Python/generated_cases.c.h"
Py_DECREF(cond);
- #line 1873 "Python/bytecodes.c"
+ #line 1872 "Python/bytecodes.c"
if (err == 0) {
JUMPBY(oparg);
}
@@ -2721,14 +2720,14 @@
if (err < 0) goto pop_1_error;
}
}
- #line 2725 "Python/generated_cases.c.h"
+ #line 2724 "Python/generated_cases.c.h"
STACK_SHRINK(1);
DISPATCH();
}
TARGET(POP_JUMP_IF_TRUE) {
PyObject *cond = stack_pointer[-1];
- #line 1883 "Python/bytecodes.c"
+ #line 1882 "Python/bytecodes.c"
if (Py_IsFalse(cond)) {
_Py_DECREF_NO_DEALLOC(cond);
}
@@ -2738,9 +2737,9 @@
}
else {
int err = PyObject_IsTrue(cond);
- #line 2742 "Python/generated_cases.c.h"
+ #line 2741 "Python/generated_cases.c.h"
Py_DECREF(cond);
- #line 1893 "Python/bytecodes.c"
+ #line 1892 "Python/bytecodes.c"
if (err > 0) {
JUMPBY(oparg);
}
@@ -2748,48 +2747,48 @@
if (err < 0) goto pop_1_error;
}
}
- #line 2752 "Python/generated_cases.c.h"
+ #line 2751 "Python/generated_cases.c.h"
STACK_SHRINK(1);
DISPATCH();
}
TARGET(POP_JUMP_IF_NOT_NONE) {
PyObject *value = stack_pointer[-1];
- #line 1903 "Python/bytecodes.c"
+ #line 1902 "Python/bytecodes.c"
if (!Py_IsNone(value)) {
- #line 2761 "Python/generated_cases.c.h"
+ #line 2760 "Python/generated_cases.c.h"
Py_DECREF(value);
- #line 1905 "Python/bytecodes.c"
+ #line 1904 "Python/bytecodes.c"
JUMPBY(oparg);
}
else {
_Py_DECREF_NO_DEALLOC(value);
}
- #line 2769 "Python/generated_cases.c.h"
+ #line 2768 "Python/generated_cases.c.h"
STACK_SHRINK(1);
DISPATCH();
}
TARGET(POP_JUMP_IF_NONE) {
PyObject *value = stack_pointer[-1];
- #line 1913 "Python/bytecodes.c"
+ #line 1912 "Python/bytecodes.c"
if (Py_IsNone(value)) {
_Py_DECREF_NO_DEALLOC(value);
JUMPBY(oparg);
}
else {
- #line 2782 "Python/generated_cases.c.h"
+ #line 2781 "Python/generated_cases.c.h"
Py_DECREF(value);
- #line 1919 "Python/bytecodes.c"
+ #line 1918 "Python/bytecodes.c"
}
- #line 2786 "Python/generated_cases.c.h"
+ #line 2785 "Python/generated_cases.c.h"
STACK_SHRINK(1);
DISPATCH();
}
TARGET(JUMP_IF_FALSE_OR_POP) {
PyObject *cond = stack_pointer[-1];
- #line 1923 "Python/bytecodes.c"
+ #line 1922 "Python/bytecodes.c"
bool jump = false;
int err;
if (Py_IsTrue(cond)) {
@@ -2812,7 +2811,7 @@
goto error;
}
}
- #line 2816 "Python/generated_cases.c.h"
+ #line 2815 "Python/generated_cases.c.h"
STACK_SHRINK(1);
STACK_GROW((jump ? 1 : 0));
DISPATCH();
@@ -2820,7 +2819,7 @@
TARGET(JUMP_IF_TRUE_OR_POP) {
PyObject *cond = stack_pointer[-1];
- #line 1948 "Python/bytecodes.c"
+ #line 1947 "Python/bytecodes.c"
bool jump = false;
int err;
if (Py_IsFalse(cond)) {
@@ -2843,34 +2842,34 @@
goto error;
}
}
- #line 2847 "Python/generated_cases.c.h"
+ #line 2846 "Python/generated_cases.c.h"
STACK_SHRINK(1);
STACK_GROW((jump ? 1 : 0));
DISPATCH();
}
TARGET(JUMP_BACKWARD_NO_INTERRUPT) {
- #line 1973 "Python/bytecodes.c"
+ #line 1972 "Python/bytecodes.c"
/* This bytecode is used in the `yield from` or `await` loop.
* If there is an interrupt, we want it handled in the innermost
* generator or coroutine, so we deliberately do not check it here.
* (see bpo-30039).
*/
JUMPBY(-oparg);
- #line 2861 "Python/generated_cases.c.h"
+ #line 2860 "Python/generated_cases.c.h"
DISPATCH();
}
TARGET(GET_LEN) {
PyObject *obj = stack_pointer[-1];
PyObject *len_o;
- #line 1982 "Python/bytecodes.c"
+ #line 1981 "Python/bytecodes.c"
// PUSH(len(TOS))
Py_ssize_t len_i = PyObject_Length(obj);
if (len_i < 0) goto error;
len_o = PyLong_FromSsize_t(len_i);
if (len_o == NULL) goto error;
- #line 2874 "Python/generated_cases.c.h"
+ #line 2873 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = len_o;
DISPATCH();
@@ -2881,16 +2880,16 @@
PyObject *type = stack_pointer[-2];
PyObject *subject = stack_pointer[-3];
PyObject *attrs;
- #line 1990 "Python/bytecodes.c"
+ #line 1989 "Python/bytecodes.c"
// Pop TOS and TOS1. Set TOS to a tuple of attributes on success, or
// None on failure.
assert(PyTuple_CheckExact(names));
attrs = match_class(tstate, subject, type, oparg, names);
- #line 2890 "Python/generated_cases.c.h"
+ #line 2889 "Python/generated_cases.c.h"
Py_DECREF(subject);
Py_DECREF(type);
Py_DECREF(names);
- #line 1995 "Python/bytecodes.c"
+ #line 1994 "Python/bytecodes.c"
if (attrs) {
assert(PyTuple_CheckExact(attrs)); // Success!
}
@@ -2898,7 +2897,7 @@
if (_PyErr_Occurred(tstate)) goto pop_3_error;
attrs = Py_NewRef(Py_None); // Failure!
}
- #line 2902 "Python/generated_cases.c.h"
+ #line 2901 "Python/generated_cases.c.h"
STACK_SHRINK(2);
stack_pointer[-1] = attrs;
DISPATCH();
@@ -2907,10 +2906,10 @@
TARGET(MATCH_MAPPING) {
PyObject *subject = stack_pointer[-1];
PyObject *res;
- #line 2005 "Python/bytecodes.c"
+ #line 2004 "Python/bytecodes.c"
int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_MAPPING;
res = Py_NewRef(match ? Py_True : Py_False);
- #line 2914 "Python/generated_cases.c.h"
+ #line 2913 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = res;
PREDICT(POP_JUMP_IF_FALSE);
@@ -2920,10 +2919,10 @@
TARGET(MATCH_SEQUENCE) {
PyObject *subject = stack_pointer[-1];
PyObject *res;
- #line 2011 "Python/bytecodes.c"
+ #line 2010 "Python/bytecodes.c"
int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_SEQUENCE;
res = Py_NewRef(match ? Py_True : Py_False);
- #line 2927 "Python/generated_cases.c.h"
+ #line 2926 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = res;
PREDICT(POP_JUMP_IF_FALSE);
@@ -2934,11 +2933,11 @@
PyObject *keys = stack_pointer[-1];
PyObject *subject = stack_pointer[-2];
PyObject *values_or_none;
- #line 2017 "Python/bytecodes.c"
+ #line 2016 "Python/bytecodes.c"
// On successful match, PUSH(values). Otherwise, PUSH(None).
values_or_none = match_keys(tstate, subject, keys);
if (values_or_none == NULL) goto error;
- #line 2942 "Python/generated_cases.c.h"
+ #line 2941 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = values_or_none;
DISPATCH();
@@ -2947,14 +2946,14 @@
TARGET(GET_ITER) {
PyObject *iterable = stack_pointer[-1];
PyObject *iter;
- #line 2023 "Python/bytecodes.c"
+ #line 2022 "Python/bytecodes.c"
/* before: [obj]; after [getiter(obj)] */
iter = PyObject_GetIter(iterable);
- #line 2954 "Python/generated_cases.c.h"
+ #line 2953 "Python/generated_cases.c.h"
Py_DECREF(iterable);
- #line 2026 "Python/bytecodes.c"
+ #line 2025 "Python/bytecodes.c"
if (iter == NULL) goto pop_1_error;
- #line 2958 "Python/generated_cases.c.h"
+ #line 2957 "Python/generated_cases.c.h"
stack_pointer[-1] = iter;
DISPATCH();
}
@@ -2962,7 +2961,7 @@
TARGET(GET_YIELD_FROM_ITER) {
PyObject *iterable = stack_pointer[-1];
PyObject *iter;
- #line 2030 "Python/bytecodes.c"
+ #line 2029 "Python/bytecodes.c"
/* before: [obj]; after [getiter(obj)] */
if (PyCoro_CheckExact(iterable)) {
/* `iterable` is a coroutine */
@@ -2985,11 +2984,11 @@
if (iter == NULL) {
goto error;
}
- #line 2989 "Python/generated_cases.c.h"
+ #line 2988 "Python/generated_cases.c.h"
Py_DECREF(iterable);
- #line 2053 "Python/bytecodes.c"
+ #line 2052 "Python/bytecodes.c"
}
- #line 2993 "Python/generated_cases.c.h"
+ #line 2992 "Python/generated_cases.c.h"
stack_pointer[-1] = iter;
PREDICT(LOAD_CONST);
DISPATCH();
@@ -3000,7 +2999,7 @@
static_assert(INLINE_CACHE_ENTRIES_FOR_ITER == 1, "incorrect cache size");
PyObject *iter = stack_pointer[-1];
PyObject *next;
- #line 2072 "Python/bytecodes.c"
+ #line 2071 "Python/bytecodes.c"
#if ENABLE_SPECIALIZATION
_PyForIterCache *cache = (_PyForIterCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -3033,7 +3032,7 @@
DISPATCH();
}
// Common case: no jump, leave it to the code generator
- #line 3037 "Python/generated_cases.c.h"
+ #line 3036 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = next;
next_instr += 1;
@@ -3043,7 +3042,7 @@
TARGET(FOR_ITER_LIST) {
PyObject *iter = stack_pointer[-1];
PyObject *next;
- #line 2107 "Python/bytecodes.c"
+ #line 2106 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
DEOPT_IF(Py_TYPE(iter) != &PyListIter_Type, FOR_ITER);
_PyListIterObject *it = (_PyListIterObject *)iter;
@@ -3064,7 +3063,7 @@
DISPATCH();
end_for_iter_list:
// Common case: no jump, leave it to the code generator
- #line 3068 "Python/generated_cases.c.h"
+ #line 3067 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = next;
next_instr += 1;
@@ -3074,7 +3073,7 @@
TARGET(FOR_ITER_TUPLE) {
PyObject *iter = stack_pointer[-1];
PyObject *next;
- #line 2130 "Python/bytecodes.c"
+ #line 2129 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
_PyTupleIterObject *it = (_PyTupleIterObject *)iter;
DEOPT_IF(Py_TYPE(it) != &PyTupleIter_Type, FOR_ITER);
@@ -3095,7 +3094,7 @@
DISPATCH();
end_for_iter_tuple:
// Common case: no jump, leave it to the code generator
- #line 3099 "Python/generated_cases.c.h"
+ #line 3098 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = next;
next_instr += 1;
@@ -3105,7 +3104,7 @@
TARGET(FOR_ITER_RANGE) {
PyObject *iter = stack_pointer[-1];
PyObject *next;
- #line 2153 "Python/bytecodes.c"
+ #line 2152 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
_PyRangeIterObject *r = (_PyRangeIterObject *)iter;
DEOPT_IF(Py_TYPE(r) != &PyRangeIter_Type, FOR_ITER);
@@ -3124,7 +3123,7 @@
if (next == NULL) {
goto error;
}
- #line 3128 "Python/generated_cases.c.h"
+ #line 3127 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = next;
next_instr += 1;
@@ -3133,7 +3132,7 @@
TARGET(FOR_ITER_GEN) {
PyObject *iter = stack_pointer[-1];
- #line 2174 "Python/bytecodes.c"
+ #line 2173 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
PyGenObject *gen = (PyGenObject *)iter;
DEOPT_IF(Py_TYPE(gen) != &PyGen_Type, FOR_ITER);
@@ -3148,14 +3147,14 @@
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg);
assert(next_instr->op.code == END_FOR);
DISPATCH_INLINED(gen_frame);
- #line 3152 "Python/generated_cases.c.h"
+ #line 3151 "Python/generated_cases.c.h"
}
TARGET(BEFORE_ASYNC_WITH) {
PyObject *mgr = stack_pointer[-1];
PyObject *exit;
PyObject *res;
- #line 2191 "Python/bytecodes.c"
+ #line 2190 "Python/bytecodes.c"
PyObject *enter = _PyObject_LookupSpecial(mgr, &_Py_ID(__aenter__));
if (enter == NULL) {
if (!_PyErr_Occurred(tstate)) {
@@ -3178,16 +3177,16 @@
Py_DECREF(enter);
goto error;
}
- #line 3182 "Python/generated_cases.c.h"
+ #line 3181 "Python/generated_cases.c.h"
Py_DECREF(mgr);
- #line 2214 "Python/bytecodes.c"
+ #line 2213 "Python/bytecodes.c"
res = _PyObject_CallNoArgs(enter);
Py_DECREF(enter);
if (res == NULL) {
Py_DECREF(exit);
if (true) goto pop_1_error;
}
- #line 3191 "Python/generated_cases.c.h"
+ #line 3190 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = res;
stack_pointer[-2] = exit;
@@ -3199,7 +3198,7 @@
PyObject *mgr = stack_pointer[-1];
PyObject *exit;
PyObject *res;
- #line 2224 "Python/bytecodes.c"
+ #line 2223 "Python/bytecodes.c"
/* pop the context manager, push its __exit__ and the
* value returned from calling its __enter__
*/
@@ -3225,16 +3224,16 @@
Py_DECREF(enter);
goto error;
}
- #line 3229 "Python/generated_cases.c.h"
+ #line 3228 "Python/generated_cases.c.h"
Py_DECREF(mgr);
- #line 2250 "Python/bytecodes.c"
+ #line 2249 "Python/bytecodes.c"
res = _PyObject_CallNoArgs(enter);
Py_DECREF(enter);
if (res == NULL) {
Py_DECREF(exit);
if (true) goto pop_1_error;
}
- #line 3238 "Python/generated_cases.c.h"
+ #line 3237 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = res;
stack_pointer[-2] = exit;
@@ -3246,7 +3245,7 @@
PyObject *lasti = stack_pointer[-3];
PyObject *exit_func = stack_pointer[-4];
PyObject *res;
- #line 2259 "Python/bytecodes.c"
+ #line 2258 "Python/bytecodes.c"
/* At the top of the stack are 4 values:
- val: TOP = exc_info()
- unused: SECOND = previous exception
@@ -3267,7 +3266,7 @@
res = PyObject_Vectorcall(exit_func, stack + 1,
3 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
if (res == NULL) goto error;
- #line 3271 "Python/generated_cases.c.h"
+ #line 3270 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = res;
DISPATCH();
@@ -3276,7 +3275,7 @@
TARGET(PUSH_EXC_INFO) {
PyObject *new_exc = stack_pointer[-1];
PyObject *prev_exc;
- #line 2282 "Python/bytecodes.c"
+ #line 2281 "Python/bytecodes.c"
_PyErr_StackItem *exc_info = tstate->exc_info;
if (exc_info->exc_value != NULL) {
prev_exc = exc_info->exc_value;
@@ -3286,7 +3285,7 @@
}
assert(PyExceptionInstance_Check(new_exc));
exc_info->exc_value = Py_NewRef(new_exc);
- #line 3290 "Python/generated_cases.c.h"
+ #line 3289 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = new_exc;
stack_pointer[-2] = prev_exc;
@@ -3300,7 +3299,7 @@
uint32_t type_version = read_u32(&next_instr[1].cache);
uint32_t keys_version = read_u32(&next_instr[3].cache);
PyObject *descr = read_obj(&next_instr[5].cache);
- #line 2294 "Python/bytecodes.c"
+ #line 2293 "Python/bytecodes.c"
/* Cached method object */
assert(cframe.use_tracing == 0);
PyTypeObject *self_cls = Py_TYPE(self);
@@ -3318,7 +3317,7 @@
assert(_PyType_HasFeature(Py_TYPE(res2), Py_TPFLAGS_METHOD_DESCRIPTOR));
res = self;
assert(oparg & 1);
- #line 3322 "Python/generated_cases.c.h"
+ #line 3321 "Python/generated_cases.c.h"
STACK_GROW(((oparg & 1) ? 1 : 0));
stack_pointer[-1] = res;
if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; }
@@ -3332,7 +3331,7 @@
PyObject *res;
uint32_t type_version = read_u32(&next_instr[1].cache);
PyObject *descr = read_obj(&next_instr[5].cache);
- #line 2314 "Python/bytecodes.c"
+ #line 2313 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
PyTypeObject *self_cls = Py_TYPE(self);
DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR);
@@ -3343,7 +3342,7 @@
res2 = Py_NewRef(descr);
res = self;
assert(oparg & 1);
- #line 3347 "Python/generated_cases.c.h"
+ #line 3346 "Python/generated_cases.c.h"
STACK_GROW(((oparg & 1) ? 1 : 0));
stack_pointer[-1] = res;
if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; }
@@ -3357,7 +3356,7 @@
PyObject *res;
uint32_t type_version = read_u32(&next_instr[1].cache);
PyObject *descr = read_obj(&next_instr[5].cache);
- #line 2327 "Python/bytecodes.c"
+ #line 2326 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
PyTypeObject *self_cls = Py_TYPE(self);
DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR);
@@ -3372,7 +3371,7 @@
res2 = Py_NewRef(descr);
res = self;
assert(oparg & 1);
- #line 3376 "Python/generated_cases.c.h"
+ #line 3375 "Python/generated_cases.c.h"
STACK_GROW(((oparg & 1) ? 1 : 0));
stack_pointer[-1] = res;
if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; }
@@ -3381,11 +3380,11 @@
}
TARGET(KW_NAMES) {
- #line 2344 "Python/bytecodes.c"
+ #line 2343 "Python/bytecodes.c"
assert(kwnames == NULL);
assert(oparg < PyTuple_GET_SIZE(frame->f_code->co_consts));
kwnames = GETITEM(frame->f_code->co_consts, oparg);
- #line 3389 "Python/generated_cases.c.h"
+ #line 3388 "Python/generated_cases.c.h"
DISPATCH();
}
@@ -3396,7 +3395,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
- #line 2380 "Python/bytecodes.c"
+ #line 2379 "Python/bytecodes.c"
int is_meth = method != NULL;
int total_args = oparg;
if (is_meth) {
@@ -3468,7 +3467,7 @@
Py_DECREF(args[i]);
}
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
- #line 3472 "Python/generated_cases.c.h"
+ #line 3471 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -3480,7 +3479,7 @@
TARGET(CALL_BOUND_METHOD_EXACT_ARGS) {
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
- #line 2458 "Python/bytecodes.c"
+ #line 2457 "Python/bytecodes.c"
DEOPT_IF(method != NULL, CALL);
DEOPT_IF(Py_TYPE(callable) != &PyMethod_Type, CALL);
STAT_INC(CALL, hit);
@@ -3490,7 +3489,7 @@
PEEK(oparg + 2) = Py_NewRef(meth); // method
Py_DECREF(callable);
GO_TO_INSTRUCTION(CALL_PY_EXACT_ARGS);
- #line 3494 "Python/generated_cases.c.h"
+ #line 3493 "Python/generated_cases.c.h"
}
TARGET(CALL_PY_EXACT_ARGS) {
@@ -3499,7 +3498,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
uint32_t func_version = read_u32(&next_instr[1].cache);
- #line 2470 "Python/bytecodes.c"
+ #line 2469 "Python/bytecodes.c"
assert(kwnames == NULL);
DEOPT_IF(tstate->interp->eval_frame, CALL);
int is_meth = method != NULL;
@@ -3524,7 +3523,7 @@
STACK_SHRINK(oparg + 2);
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
DISPATCH_INLINED(new_frame);
- #line 3528 "Python/generated_cases.c.h"
+ #line 3527 "Python/generated_cases.c.h"
}
TARGET(CALL_PY_WITH_DEFAULTS) {
@@ -3533,7 +3532,7 @@
PyObject *method = stack_pointer[-(2 + oparg)];
uint32_t func_version = read_u32(&next_instr[1].cache);
uint16_t min_args = read_u16(&next_instr[3].cache);
- #line 2497 "Python/bytecodes.c"
+ #line 2496 "Python/bytecodes.c"
assert(kwnames == NULL);
DEOPT_IF(tstate->interp->eval_frame, CALL);
int is_meth = method != NULL;
@@ -3563,7 +3562,7 @@
STACK_SHRINK(oparg + 2);
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
DISPATCH_INLINED(new_frame);
- #line 3567 "Python/generated_cases.c.h"
+ #line 3566 "Python/generated_cases.c.h"
}
TARGET(CALL_NO_KW_TYPE_1) {
@@ -3571,7 +3570,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *null = stack_pointer[-(2 + oparg)];
PyObject *res;
- #line 2529 "Python/bytecodes.c"
+ #line 2528 "Python/bytecodes.c"
assert(kwnames == NULL);
assert(cframe.use_tracing == 0);
assert(oparg == 1);
@@ -3582,7 +3581,7 @@
res = Py_NewRef(Py_TYPE(obj));
Py_DECREF(obj);
Py_DECREF(&PyType_Type); // I.e., callable
- #line 3586 "Python/generated_cases.c.h"
+ #line 3585 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -3595,7 +3594,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *null = stack_pointer[-(2 + oparg)];
PyObject *res;
- #line 2542 "Python/bytecodes.c"
+ #line 2541 "Python/bytecodes.c"
assert(kwnames == NULL);
assert(cframe.use_tracing == 0);
assert(oparg == 1);
@@ -3607,7 +3606,7 @@
Py_DECREF(arg);
Py_DECREF(&PyUnicode_Type); // I.e., callable
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
- #line 3611 "Python/generated_cases.c.h"
+ #line 3610 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -3621,7 +3620,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *null = stack_pointer[-(2 + oparg)];
PyObject *res;
- #line 2557 "Python/bytecodes.c"
+ #line 2556 "Python/bytecodes.c"
assert(kwnames == NULL);
assert(oparg == 1);
DEOPT_IF(null != NULL, CALL);
@@ -3632,7 +3631,7 @@
Py_DECREF(arg);
Py_DECREF(&PyTuple_Type); // I.e., tuple
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
- #line 3636 "Python/generated_cases.c.h"
+ #line 3635 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -3646,7 +3645,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
- #line 2571 "Python/bytecodes.c"
+ #line 2570 "Python/bytecodes.c"
int is_meth = method != NULL;
int total_args = oparg;
if (is_meth) {
@@ -3668,7 +3667,7 @@
}
Py_DECREF(tp);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
- #line 3672 "Python/generated_cases.c.h"
+ #line 3671 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -3682,7 +3681,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
- #line 2596 "Python/bytecodes.c"
+ #line 2595 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
/* Builtin METH_O functions */
assert(kwnames == NULL);
@@ -3711,7 +3710,7 @@
Py_DECREF(arg);
Py_DECREF(callable);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
- #line 3715 "Python/generated_cases.c.h"
+ #line 3714 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -3725,7 +3724,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
- #line 2628 "Python/bytecodes.c"
+ #line 2627 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
/* Builtin METH_FASTCALL functions, without keywords */
assert(kwnames == NULL);
@@ -3758,7 +3757,7 @@
'invalid'). In those cases an exception is set, so we must
handle it.
*/
- #line 3762 "Python/generated_cases.c.h"
+ #line 3761 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -3772,7 +3771,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
- #line 2664 "Python/bytecodes.c"
+ #line 2663 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
/* Builtin METH_FASTCALL | METH_KEYWORDS functions */
int is_meth = method != NULL;
@@ -3805,7 +3804,7 @@
}
Py_DECREF(callable);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
- #line 3809 "Python/generated_cases.c.h"
+ #line 3808 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -3819,7 +3818,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
- #line 2700 "Python/bytecodes.c"
+ #line 2699 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
assert(kwnames == NULL);
/* len(o) */
@@ -3845,7 +3844,7 @@
Py_DECREF(callable);
Py_DECREF(arg);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
- #line 3849 "Python/generated_cases.c.h"
+ #line 3848 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -3858,7 +3857,7 @@
PyObject *callable = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
- #line 2728 "Python/bytecodes.c"
+ #line 2727 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
assert(kwnames == NULL);
/* isinstance(o, o2) */
@@ -3886,7 +3885,7 @@
Py_DECREF(cls);
Py_DECREF(callable);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
- #line 3890 "Python/generated_cases.c.h"
+ #line 3889 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -3898,7 +3897,7 @@
PyObject **args = (stack_pointer - oparg);
PyObject *self = stack_pointer[-(1 + oparg)];
PyObject *method = stack_pointer[-(2 + oparg)];
- #line 2759 "Python/bytecodes.c"
+ #line 2758 "Python/bytecodes.c"
assert(cframe.use_tracing == 0);
assert(kwnames == NULL);
assert(oparg == 1);
@@ -3917,14 +3916,14 @@
JUMPBY(INLINE_CACHE_ENTRIES_CALL + 1);
assert(next_instr[-1].op.code == POP_TOP);
DISPATCH();
- #line 3921 "Python/generated_cases.c.h"
+ #line 3920 "Python/generated_cases.c.h"
}
TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_O) {
PyObject **args = (stack_pointer - oparg);
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
- #line 2780 "Python/bytecodes.c"
+ #line 2779 "Python/bytecodes.c"
assert(kwnames == NULL);
int is_meth = method != NULL;
int total_args = oparg;
@@ -3955,7 +3954,7 @@
Py_DECREF(arg);
Py_DECREF(callable);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
- #line 3959 "Python/generated_cases.c.h"
+ #line 3958 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -3968,7 +3967,7 @@
PyObject **args = (stack_pointer - oparg);
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
- #line 2814 "Python/bytecodes.c"
+ #line 2813 "Python/bytecodes.c"
int is_meth = method != NULL;
int total_args = oparg;
if (is_meth) {
@@ -3997,7 +3996,7 @@
}
Py_DECREF(callable);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
- #line 4001 "Python/generated_cases.c.h"
+ #line 4000 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -4010,7 +4009,7 @@
PyObject **args = (stack_pointer - oparg);
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
- #line 2846 "Python/bytecodes.c"
+ #line 2845 "Python/bytecodes.c"
assert(kwnames == NULL);
assert(oparg == 0 || oparg == 1);
int is_meth = method != NULL;
@@ -4039,7 +4038,7 @@
Py_DECREF(self);
Py_DECREF(callable);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
- #line 4043 "Python/generated_cases.c.h"
+ #line 4042 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -4052,7 +4051,7 @@
PyObject **args = (stack_pointer - oparg);
PyObject *method = stack_pointer[-(2 + oparg)];
PyObject *res;
- #line 2878 "Python/bytecodes.c"
+ #line 2877 "Python/bytecodes.c"
assert(kwnames == NULL);
int is_meth = method != NULL;
int total_args = oparg;
@@ -4080,7 +4079,7 @@
}
Py_DECREF(callable);
if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; }
- #line 4084 "Python/generated_cases.c.h"
+ #line 4083 "Python/generated_cases.c.h"
STACK_SHRINK(oparg);
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -4095,7 +4094,7 @@
PyObject *callargs = stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))];
PyObject *func = stack_pointer[-(2 + ((oparg & 1) ? 1 : 0))];
PyObject *result;
- #line 2909 "Python/bytecodes.c"
+ #line 2908 "Python/bytecodes.c"
if (oparg & 1) {
// DICT_MERGE is called before this opcode if there are kwargs.
// It converts all dict subtypes in kwargs into regular dicts.
@@ -4114,15 +4113,15 @@
assert(PyTuple_CheckExact(callargs));
result = do_call_core(tstate, func, callargs, kwargs, cframe.use_tracing);
- #line 4118 "Python/generated_cases.c.h"
+ #line 4117 "Python/generated_cases.c.h"
Py_DECREF(func);
Py_DECREF(callargs);
Py_XDECREF(kwargs);
- #line 2928 "Python/bytecodes.c"
+ #line 2927 "Python/bytecodes.c"
assert(PEEK(3 + (oparg & 1)) == NULL);
if (result == NULL) { STACK_SHRINK(((oparg & 1) ? 1 : 0)); goto pop_3_error; }
- #line 4126 "Python/generated_cases.c.h"
+ #line 4125 "Python/generated_cases.c.h"
STACK_SHRINK(((oparg & 1) ? 1 : 0));
STACK_SHRINK(2);
stack_pointer[-1] = result;
@@ -4137,7 +4136,7 @@
PyObject *kwdefaults = (oparg & 0x02) ? stack_pointer[-(1 + ((oparg & 0x08) ? 1 : 0) + ((oparg & 0x04) ? 1 : 0) + ((oparg & 0x02) ? 1 : 0))] : NULL;
PyObject *defaults = (oparg & 0x01) ? stack_pointer[-(1 + ((oparg & 0x08) ? 1 : 0) + ((oparg & 0x04) ? 1 : 0) + ((oparg & 0x02) ? 1 : 0) + ((oparg & 0x01) ? 1 : 0))] : NULL;
PyObject *func;
- #line 2939 "Python/bytecodes.c"
+ #line 2938 "Python/bytecodes.c"
PyFunctionObject *func_obj = (PyFunctionObject *)
PyFunction_New(codeobj, GLOBALS());
@@ -4166,14 +4165,14 @@
func_obj->func_version = ((PyCodeObject *)codeobj)->co_version;
func = (PyObject *)func_obj;
- #line 4170 "Python/generated_cases.c.h"
+ #line 4169 "Python/generated_cases.c.h"
STACK_SHRINK(((oparg & 0x01) ? 1 : 0) + ((oparg & 0x02) ? 1 : 0) + ((oparg & 0x04) ? 1 : 0) + ((oparg & 0x08) ? 1 : 0));
stack_pointer[-1] = func;
DISPATCH();
}
TARGET(RETURN_GENERATOR) {
- #line 2970 "Python/bytecodes.c"
+ #line 2969 "Python/bytecodes.c"
assert(PyFunction_Check(frame->f_funcobj));
PyFunctionObject *func = (PyFunctionObject *)frame->f_funcobj;
PyGenObject *gen = (PyGenObject *)_Py_MakeCoro(func);
@@ -4194,7 +4193,7 @@
frame = cframe.current_frame = prev;
_PyFrame_StackPush(frame, (PyObject *)gen);
goto resume_frame;
- #line 4198 "Python/generated_cases.c.h"
+ #line 4197 "Python/generated_cases.c.h"
}
TARGET(BUILD_SLICE) {
@@ -4202,15 +4201,15 @@
PyObject *stop = stack_pointer[-(1 + ((oparg == 3) ? 1 : 0))];
PyObject *start = stack_pointer[-(2 + ((oparg == 3) ? 1 : 0))];
PyObject *slice;
- #line 2993 "Python/bytecodes.c"
+ #line 2992 "Python/bytecodes.c"
slice = PySlice_New(start, stop, step);
- #line 4208 "Python/generated_cases.c.h"
+ #line 4207 "Python/generated_cases.c.h"
Py_DECREF(start);
Py_DECREF(stop);
Py_XDECREF(step);
- #line 2995 "Python/bytecodes.c"
+ #line 2994 "Python/bytecodes.c"
if (slice == NULL) { STACK_SHRINK(((oparg == 3) ? 1 : 0)); goto pop_2_error; }
- #line 4214 "Python/generated_cases.c.h"
+ #line 4213 "Python/generated_cases.c.h"
STACK_SHRINK(((oparg == 3) ? 1 : 0));
STACK_SHRINK(1);
stack_pointer[-1] = slice;
@@ -4221,7 +4220,7 @@
PyObject *fmt_spec = ((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? stack_pointer[-((((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0))] : NULL;
PyObject *value = stack_pointer[-(1 + (((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0))];
PyObject *result;
- #line 2999 "Python/bytecodes.c"
+ #line 2998 "Python/bytecodes.c"
/* Handles f-string value formatting. */
PyObject *(*conv_fn)(PyObject *);
int which_conversion = oparg & FVC_MASK;
@@ -4256,7 +4255,7 @@
Py_DECREF(value);
Py_XDECREF(fmt_spec);
if (result == NULL) { STACK_SHRINK((((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0)); goto pop_1_error; }
- #line 4260 "Python/generated_cases.c.h"
+ #line 4259 "Python/generated_cases.c.h"
STACK_SHRINK((((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0));
stack_pointer[-1] = result;
DISPATCH();
@@ -4265,10 +4264,10 @@
TARGET(COPY) {
PyObject *bottom = stack_pointer[-(1 + (oparg-1))];
PyObject *top;
- #line 3036 "Python/bytecodes.c"
+ #line 3035 "Python/bytecodes.c"
assert(oparg > 0);
top = Py_NewRef(bottom);
- #line 4272 "Python/generated_cases.c.h"
+ #line 4271 "Python/generated_cases.c.h"
STACK_GROW(1);
stack_pointer[-1] = top;
DISPATCH();
@@ -4280,7 +4279,7 @@
PyObject *rhs = stack_pointer[-1];
PyObject *lhs = stack_pointer[-2];
PyObject *res;
- #line 3041 "Python/bytecodes.c"
+ #line 3040 "Python/bytecodes.c"
#if ENABLE_SPECIALIZATION
_PyBinaryOpCache *cache = (_PyBinaryOpCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -4296,12 +4295,12 @@
assert((unsigned)oparg < Py_ARRAY_LENGTH(binary_ops));
assert(binary_ops[oparg]);
res = binary_ops[oparg](lhs, rhs);
- #line 4300 "Python/generated_cases.c.h"
+ #line 4299 "Python/generated_cases.c.h"
Py_DECREF(lhs);
Py_DECREF(rhs);
- #line 3057 "Python/bytecodes.c"
+ #line 3056 "Python/bytecodes.c"
if (res == NULL) goto pop_2_error;
- #line 4305 "Python/generated_cases.c.h"
+ #line 4304 "Python/generated_cases.c.h"
STACK_SHRINK(1);
stack_pointer[-1] = res;
next_instr += 1;
@@ -4311,27 +4310,27 @@
TARGET(SWAP) {
PyObject *top = stack_pointer[-1];
PyObject *bottom = stack_pointer[-(2 + (oparg-2))];
- #line 3062 "Python/bytecodes.c"
+ #line 3061 "Python/bytecodes.c"
assert(oparg >= 2);
- #line 4317 "Python/generated_cases.c.h"
+ #line 4316 "Python/generated_cases.c.h"
stack_pointer[-1] = bottom;
stack_pointer[-(2 + (oparg-2))] = top;
DISPATCH();
}
TARGET(EXTENDED_ARG) {
- #line 3066 "Python/bytecodes.c"
+ #line 3065 "Python/bytecodes.c"
assert(oparg);
assert(cframe.use_tracing == 0);
opcode = next_instr->op.code;
oparg = oparg << 8 | next_instr->op.arg;
PRE_DISPATCH_GOTO();
DISPATCH_GOTO();
- #line 4331 "Python/generated_cases.c.h"
+ #line 4330 "Python/generated_cases.c.h"
}
TARGET(CACHE) {
- #line 3075 "Python/bytecodes.c"
+ #line 3074 "Python/bytecodes.c"
Py_UNREACHABLE();
- #line 4337 "Python/generated_cases.c.h"
+ #line 4336 "Python/generated_cases.c.h"
}
diff --git a/Python/marshal.c b/Python/marshal.c
index 94e79d4..2966139 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -11,6 +11,7 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_code.h" // _PyCode_New()
+#include "pycore_long.h" // _PyLong_DigitCount
#include "pycore_hashtable.h" // _Py_hashtable_t
#include "marshal.h" // Py_MARSHAL_VERSION
@@ -232,13 +233,13 @@ w_PyLong(const PyLongObject *ob, char flag, WFILE *p)
digit d;
W_TYPE(TYPE_LONG, p);
- if (Py_SIZE(ob) == 0) {
+ if (_PyLong_IsZero(ob)) {
w_long((long)0, p);
return;
}
/* set l to number of base PyLong_MARSHAL_BASE digits */
- n = Py_ABS(Py_SIZE(ob));
+ n = _PyLong_DigitCount(ob);
l = (n-1) * PyLong_MARSHAL_RATIO;
d = ob->long_value.ob_digit[n-1];
assert(d != 0); /* a PyLong is always normalized */
@@ -251,7 +252,7 @@ w_PyLong(const PyLongObject *ob, char flag, WFILE *p)
p->error = WFERR_UNMARSHALLABLE;
return;
}
- w_long((long)(Py_SIZE(ob) > 0 ? l : -l), p);
+ w_long((long)(_PyLong_IsNegative(ob) ? -l : l), p);
for (i=0; i < n-1; i++) {
d = ob->long_value.ob_digit[i];
@@ -839,7 +840,7 @@ r_PyLong(RFILE *p)
if (ob == NULL)
return NULL;
- Py_SET_SIZE(ob, n > 0 ? size : -size);
+ _PyLong_SetSignAndDigitCount(ob, n < 0 ? -1 : 1, size);
for (i = 0; i < size-1; i++) {
d = 0;
diff --git a/Python/specialize.c b/Python/specialize.c
index 719bd5b..2e93ab1 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -1308,7 +1308,7 @@ _Py_Specialize_BinarySubscr(
PyTypeObject *container_type = Py_TYPE(container);
if (container_type == &PyList_Type) {
if (PyLong_CheckExact(sub)) {
- if (Py_SIZE(sub) == 0 || Py_SIZE(sub) == 1) {
+ if (_PyLong_IsNonNegativeCompact((PyLongObject *)sub)) {
instr->op.code = BINARY_SUBSCR_LIST_INT;
goto success;
}
@@ -1321,7 +1321,7 @@ _Py_Specialize_BinarySubscr(
}
if (container_type == &PyTuple_Type) {
if (PyLong_CheckExact(sub)) {
- if (Py_SIZE(sub) == 0 || Py_SIZE(sub) == 1) {
+ if (_PyLong_IsNonNegativeCompact((PyLongObject *)sub)) {
instr->op.code = BINARY_SUBSCR_TUPLE_INT;
goto success;
}
@@ -1389,7 +1389,7 @@ _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *ins
PyTypeObject *container_type = Py_TYPE(container);
if (container_type == &PyList_Type) {
if (PyLong_CheckExact(sub)) {
- if ((Py_SIZE(sub) == 0 || Py_SIZE(sub) == 1)
+ if (_PyLong_IsNonNegativeCompact((PyLongObject *)sub)
&& ((PyLongObject *)sub)->long_value.ob_digit[0] < (size_t)PyList_GET_SIZE(container))
{
instr->op.code = STORE_SUBSCR_LIST_INT;
@@ -2007,7 +2007,7 @@ _Py_Specialize_CompareAndBranch(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *inst
goto success;
}
if (PyLong_CheckExact(lhs)) {
- if (Py_ABS(Py_SIZE(lhs)) <= 1 && Py_ABS(Py_SIZE(rhs)) <= 1) {
+ if (_PyLong_IsCompact((PyLongObject *)lhs) && _PyLong_IsCompact((PyLongObject *)rhs)) {
instr->op.code = COMPARE_AND_BRANCH_INT;
goto success;
}
diff --git a/Tools/build/deepfreeze.py b/Tools/build/deepfreeze.py
index 511b26a..ec80852 100644
--- a/Tools/build/deepfreeze.py
+++ b/Tools/build/deepfreeze.py
@@ -309,7 +309,7 @@ class Printer:
return f"& {name}._object.ob_base.ob_base"
def _generate_int_for_bits(self, name: str, i: int, digit: int) -> None:
- sign = -1 if i < 0 else 0 if i == 0 else +1
+ sign = (i > 0) - (i < 0)
i = abs(i)
digits: list[int] = []
while i:
@@ -318,10 +318,12 @@ class Printer:
self.write("static")
with self.indent():
with self.block("struct"):
- self.write("PyObject_VAR_HEAD")
+ self.write("PyObject ob_base;")
+ self.write("uintptr_t lv_tag;")
self.write(f"digit ob_digit[{max(1, len(digits))}];")
with self.block(f"{name} =", ";"):
- self.object_var_head("PyLong_Type", sign*len(digits))
+ self.object_head("PyLong_Type")
+ self.write(f".lv_tag = TAG_FROM_SIGN_AND_SIZE({sign}, {len(digits)}),")
if digits:
ds = ", ".join(map(str, digits))
self.write(f".ob_digit = {{ {ds} }},")
@@ -345,7 +347,7 @@ class Printer:
self.write('#error "PYLONG_BITS_IN_DIGIT should be 15 or 30"')
self.write("#endif")
# If neither clause applies, it won't compile
- return f"& {name}.ob_base.ob_base"
+ return f"& {name}.ob_base"
def generate_float(self, name: str, x: float) -> str:
with self.block(f"static PyFloatObject {name} =", ";"):
diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py
index 56d6970..e38bd59 100755
--- a/Tools/gdb/libpython.py
+++ b/Tools/gdb/libpython.py
@@ -882,10 +882,16 @@ class PyLongObjectPtr(PyObjectPtr):
def proxyval(self, visited):
'''
Python's Include/longobjrep.h has this declaration:
- struct _longobject {
- PyObject_VAR_HEAD
- digit ob_digit[1];
- };
+
+ typedef struct _PyLongValue {
+ uintptr_t lv_tag; /* Number of digits, sign and flags */
+ digit ob_digit[1];
+ } _PyLongValue;
+
+ struct _longobject {
+ PyObject_HEAD
+ _PyLongValue long_value;
+ };
with this description:
The absolute value of a number is equal to
@@ -897,11 +903,13 @@ class PyLongObjectPtr(PyObjectPtr):
#define PyLong_SHIFT 30
#define PyLong_SHIFT 15
'''
- ob_size = int(self.field('ob_size'))
- if ob_size == 0:
+ long_value = self.field('long_value')
+ lv_tag = int(long_value['lv_tag'])
+ size = lv_tag >> 3
+ if size == 0:
return 0
- ob_digit = self.field('long_value')['ob_digit']
+ ob_digit = long_value['ob_digit']
if gdb.lookup_type('digit').sizeof == 2:
SHIFT = 15
@@ -909,9 +917,9 @@ class PyLongObjectPtr(PyObjectPtr):
SHIFT = 30
digits = [int(ob_digit[i]) * 2**(SHIFT*i)
- for i in safe_range(abs(ob_size))]
+ for i in safe_range(size)]
result = sum(digits)
- if ob_size < 0:
+ if (lv_tag & 3) == 2:
result = -result
return result