summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-09-29 07:40:20 (GMT)
committerGitHub <noreply@github.com>2024-09-29 07:40:20 (GMT)
commitd08c7888229e78533648191dfe42e2d2d3ecea25 (patch)
tree4b638a62a9e80d43573856ed8f081a65ae45ab8a /Include
parente0a41a5dd12cb6e9277b05abebac5c70be684dd7 (diff)
downloadcpython-d08c7888229e78533648191dfe42e2d2d3ecea25.zip
cpython-d08c7888229e78533648191dfe42e2d2d3ecea25.tar.gz
cpython-d08c7888229e78533648191dfe42e2d2d3ecea25.tar.bz2
gh-123497: New limit for Python integers on 64-bit platforms (GH-123724)
Instead of be limited just by the size of addressable memory (2**63 bytes), Python integers are now also limited by the number of bits, so the number of bit now always fit in a 64-bit integer. Both limits are much larger than what might be available in practice, so it doesn't affect users. _PyLong_NumBits() and _PyLong_Frexp() are now always successful.
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/longobject.h5
-rw-r--r--Include/internal/pycore_long.h11
2 files changed, 7 insertions, 9 deletions
diff --git a/Include/cpython/longobject.h b/Include/cpython/longobject.h
index 82f8cc8..b239f7c 100644
--- a/Include/cpython/longobject.h
+++ b/Include/cpython/longobject.h
@@ -71,10 +71,9 @@ PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);
absolute value of a long. For example, this returns 1 for 1 and -1, 2
for 2 and -2, and 2 for 3 and -3. It returns 0 for 0.
v must not be NULL, and must be a normalized long.
- (uint64_t)-1 is returned and OverflowError set if the true result doesn't
- fit in a size_t.
+ Always successful.
*/
-PyAPI_FUNC(uint64_t) _PyLong_NumBits(PyObject *v);
+PyAPI_FUNC(int64_t) _PyLong_NumBits(PyObject *v);
/* _PyLong_FromByteArray: View the n unsigned bytes as a binary integer in
base 256, and return a Python int with the same numeric value.
diff --git a/Include/internal/pycore_long.h b/Include/internal/pycore_long.h
index 8822147..196b415 100644
--- a/Include/internal/pycore_long.h
+++ b/Include/internal/pycore_long.h
@@ -79,11 +79,10 @@ static inline PyObject* _PyLong_FromUnsignedChar(unsigned char i)
}
// _PyLong_Frexp returns a double x and an exponent e such that the
-// true value is approximately equal to x * 2**e. e is >= 0. x is
+// true value is approximately equal to x * 2**e. x is
// 0.0 if and only if the input is 0 (in which case, e and x are both
-// zeroes); otherwise, 0.5 <= abs(x) < 1.0. On overflow, which is
-// possible if the number of bits doesn't fit into a Py_ssize_t, sets
-// OverflowError and returns -1.0 for x, 0 for e.
+// zeroes); otherwise, 0.5 <= abs(x) < 1.0.
+// Always successful.
//
// Export for 'math' shared extension
PyAPI_DATA(double) _PyLong_Frexp(PyLongObject *a, int64_t *e);
@@ -105,10 +104,10 @@ PyAPI_DATA(PyObject*) _PyLong_DivmodNear(PyObject *, PyObject *);
PyAPI_DATA(PyObject*) _PyLong_Format(PyObject *obj, int base);
// Export for 'math' shared extension
-PyAPI_DATA(PyObject*) _PyLong_Rshift(PyObject *, uint64_t);
+PyAPI_DATA(PyObject*) _PyLong_Rshift(PyObject *, int64_t);
// Export for 'math' shared extension
-PyAPI_DATA(PyObject*) _PyLong_Lshift(PyObject *, uint64_t);
+PyAPI_DATA(PyObject*) _PyLong_Lshift(PyObject *, int64_t);
PyAPI_FUNC(PyObject*) _PyLong_Add(PyLongObject *left, PyLongObject *right);
PyAPI_FUNC(PyObject*) _PyLong_Multiply(PyLongObject *left, PyLongObject *right);