mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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.
This commit is contained in:
parent
e0a41a5dd1
commit
d08c788822
8 changed files with 108 additions and 175 deletions
|
@ -2146,7 +2146,7 @@ save_long(PicklerObject *self, PyObject *obj)
|
|||
|
||||
if (self->proto >= 2) {
|
||||
/* Linear-time pickling. */
|
||||
uint64_t nbits;
|
||||
int64_t nbits;
|
||||
size_t nbytes;
|
||||
unsigned char *pdata;
|
||||
char header[5];
|
||||
|
@ -2161,8 +2161,8 @@ save_long(PicklerObject *self, PyObject *obj)
|
|||
return 0;
|
||||
}
|
||||
nbits = _PyLong_NumBits(obj);
|
||||
if (nbits == (uint64_t)-1 && PyErr_Occurred())
|
||||
goto error;
|
||||
assert(nbits >= 0);
|
||||
assert(!PyErr_Occurred());
|
||||
/* How many bytes do we need? There are nbits >> 3 full
|
||||
* bytes of data, and nbits & 7 leftover bits. If there
|
||||
* are any leftover bits, then we clearly need another
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue