Serhiy Storchaka
68784fed78
gh-133489: Remove size restrictions on getrandbits() and randbytes() (GH-133658)
...
random.getrandbits() can now generate more that 2**31 bits.
random.randbytes() can now generate more that 256 MiB.
2025-05-31 11:23:01 +03:00
Serhiy Storchaka
4c914e7a36
gh-133583: Add support for fixed size unsigned integers in argument parsing (GH-133584)
...
* Add Argument Clinic converters: uint8, uint16, uint32, uint64.
* Add private C API: _PyLong_UInt8_Converter(),
_PyLong_UInt16_Converter(), _PyLong_UInt32_Converter(),
_PyLong_UInt64_Converter().
2025-05-08 12:27:50 +03:00
Serhiy Storchaka
6677c2c165
gh-132987: Support __index__() for unsigned integers in Argument Clinic (GH-133011)
2025-04-28 11:02:18 +03:00
Sergey B Kirpichev
95800fe6e7
Correct _PyLong_Frexp() description in comments (GH-132716)
...
This amends d08c788822
, now this function always successful.
2025-04-19 07:42:20 +00:00
Chris Eibl
80295a8f9b
GH-131296: fix clang-cl warning on Windows in `Objects/longobject.c` for 32bit builds ( #131604 )
2025-04-18 10:45:30 +02:00
Bénédikt Tran
edbf7fb129
gh-111178: remove redundant casts for functions with correct signatures ( #131673 )
2025-04-01 17:18:11 +02:00
Chris Eibl
a175d64e30
GH-129149: Add fast path for medium-sized integers in `PyLong_From*` functions ( #131211 )
...
Add a fast path for medium-sized integers in `PyLong_FromInt{32,64}` and `PyLong_FromUInt{32,64}`.
2025-03-30 10:12:42 +02:00
Victor Stinner
34c1ea3109
gh-111178: Fix function signatures for multiple tests ( #131496 )
2025-03-20 12:27:03 +01:00
Mark Shannon
a45f25361d
GH-131238: More refactoring of core header files (GH-131351)
...
Adds new pycore_stats.h header file to help break dependencies involving the pycore_code.h header.
2025-03-17 14:41:05 +00:00
Chris Eibl
119bcfad9c
gh-129149: Add fast path for medium-sized integers in `PyLong_FromSsize_t()` ( #129301 )
...
The implementation of `PyLong_FromLong()`, `PyLong_FromLongLong()` and `PyLong_FromSsize_t()`
are now handled by a common macro `PYLONG_FROM_INT` which contains fast paths depending on the
size of the integer to convert. Consequently, `PyLong_FromSsize_t()` for medium-sized integers is faster
by roughly 25%.
---------
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2025-03-13 12:06:56 +01:00
Neil Schemenauer
813bc5694b
gh-130599: use static constants str-to-int conversion (gh-130714)
...
Avoid a data race in free-threaded builds due to mutating global arrays at
runtime. Instead, compute the constants with an external Python script and
then define them as static global constant arrays. These constants are
used by `long_from_non_binary_base()`.
2025-03-03 19:00:50 -08:00
Pieter Eendebak
a29221675e
gh-127119: Faster check for small ints in long_dealloc (GH-127620)
2025-01-29 15:22:18 +00:00
Victor Stinner
7ec17429d4
gh-102471: Change PyLongWriter_Discard(NULL) to do nothing ( #129339 )
...
It's convenient to be able to call PyLongWriter_Discard(NULL) in
error handling code.
2025-01-27 10:51:16 +00:00
Sergey B Kirpichev
233fd00f0a
gh-128863: Deprecate _PyLong_FromDigits() function ( #127939 )
2025-01-24 13:17:10 +01:00
Srinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్ రెడ్డి)
ab353b31bb
gh-129149: Add fast path in PYLONG_FROM_UINT macro for compact integers ( #129168 )
...
Add fast path in PyLong_From*() functions for compact integers.
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-01-23 14:36:52 +00:00
Sergey B Kirpichev
5c9a63f62c
gh-128863: Deprecate _PyLong_New() function ( #129212 )
2025-01-23 13:50:34 +01:00
Victor Stinner
1d485db953
gh-128863: Deprecate _PyLong_Sign() function ( #129176 )
...
Replace _PyLong_Sign() with PyLong_GetSign().
2025-01-23 03:11:53 +01:00
Pieter Eendebak
3bd7730bbd
gh-126868: Add freelist for compact ints to `_PyLong_New` ( #128181 )
...
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2024-12-26 15:17:22 +00:00
Victor Stinner
6446408d42
gh-102471, PEP 757: Add PyLong import and export API ( #121339 )
...
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Steve Dower <steve.dower@microsoft.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-12-13 14:24:48 +01:00
Pieter Eendebak
5fc6bb2754
gh-126868: Add freelist for compact int objects (GH-126865)
2024-12-13 10:06:26 +00:00
RUANG (James Roy)
8ff7efb46d
gh-126061: Add PyLong_IsPositive/Zero/Negative() functions ( #126065 )
...
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-11-12 14:18:06 +01:00
Mark Shannon
fa40922597
GH-126547: Pre-assign version numbers for a few common classes (GH-126551)
2024-11-08 16:44:44 +00:00
Victor Stinner
03775472cc
Use _PyLong_GetOne() and _PyLong_GetZero() in long_invmod() ( #125044 )
...
These functions cannot fail.
2024-10-07 19:54:42 +02:00
Victor Stinner
113b2d7583
gh-111178: Fix function signatures in longobject.c ( #124895 )
...
* Add _PyLong_CAST() macro.
* Move forward declarations to the top of longobject.c.
* Change long_add(), long_sub(), long_mul(), long_neg(),
long_lshift(), long_abs() to take PyLongObject* and return
PyLongObject*. Avoid CHECK_BINOP() test.
* Add long_add_method(), long_sub_method(), long_mul_method(),
long_neg_method(), long_lshift_method(), and long_abs_method()
which take PyObject* and return PyObject*. Implement CHECK_BINOP()
test.
* Add long_lshift_int64() function.
* _PyLong_DivmodNear() calls long_lshift_int64(obj, 1) instead of
long_lshift_obj(obj, one).
2024-10-02 17:41:19 +02:00
Serhiy Storchaka
d08c788822
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.
2024-09-29 10:40:20 +03:00
Serhiy Storchaka
32c7dbb2bc
gh-121485: Always use 64-bit integers for integers bits count (GH-121486)
...
Use 64-bit integers instead of platform specific size_t or Py_ssize_t
to represent the number of bits in Python integer.
2024-08-30 08:13:24 +03:00
Victor Stinner
4c6dca8292
gh-120389: Add PyLong_FromInt64() and PyLong_AsInt64() ( #120390 )
...
Add new functions to convert C <stdint.h> numbers from/to Python int:
* PyLong_FromInt32()
* PyLong_FromUInt32()
* PyLong_FromInt64()
* PyLong_FromUInt64()
* PyLong_AsInt32()
* PyLong_AsUInt32()
* PyLong_AsInt64()
* PyLong_AsUInt64()
2024-08-28 10:16:13 +00:00
Bénédikt Tran
fe3e623562
gh-111178: Avoid calling long_hash from incompatible pointer type (GH-122972)
...
Make `long_hash` compatible with `hashfunc`.
2024-08-14 11:50:35 +02:00
Serhiy Storchaka
1a0c7b9ba4
gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907)
2024-07-19 08:06:02 +00:00
Serhiy Storchaka
18015451d0
gh-121153: Fix some errors with use of _PyLong_CompactValue() (GH-121154)
...
* The result has type Py_ssize_t, not intptr_t.
* Type cast between unsigned and signdet integer types should be explicit.
* Downcasting should be explicit.
* Fix integer overflow check in sum().
2024-07-13 13:40:44 +03:00
Steve Dower
2894aa14f2
gh-121115: Skip __index__ in PyLong_AsNativeBytes by default (GH-121118)
2024-06-28 16:26:21 +01:00
Victor Stinner
e51e880e75
gh-120593: Fix const qualifier in _PyLong_CompactValue() ( #121053 )
...
Remove the const qualifier of the argument of functions:
* _PyLong_IsCompact()
* _PyLong_CompactValue()
Py_TYPE() argument is not const.
Fix the compiler warning:
Include/cpython/longintrepr.h: In function ‘_PyLong_CompactValue’:
Include/pyport.h:19:31: error: cast discards ‘const’ qualifier from
pointer target type [-Werror=cast-qual]
(...)
Include/cpython/longintrepr.h:133:30: note: in expansion of macro
‘Py_TYPE’
assert(PyType_HasFeature(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS));
2024-06-26 20:11:21 +02:00
Kirill Podoprigora
57ad769076
gh-120080: Accept ``None`` as a valid argument for direct call of the ``int.__round__`` ( #120088 )
...
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2024-06-07 10:03:28 +02:00
Nikita Sobolev
1d4c2e4a87
gh-119057: Use better error messages for zero division ( #119066 )
2024-06-03 19:03:56 +03:00
Sergey B Kirpichev
61d3ab32da
gh-116560: Add PyLong_GetSign() public function ( #116561 )
...
Co-authored-by: Victor Stinner <vstinner@python.org>
2024-06-03 14:06:31 +02:00
Sergey B Kirpichev
cd11ff12ac
gh-119613: Use C99+ functions instead of Py_IS_NAN/INFINITY/FINITE ( #119619 )
2024-05-29 09:51:19 +02:00
Ayato Hayashi
43807fec8d
Tiny fix: Update link for HAC algorithm (gh-118546)
2024-05-23 02:11:11 +00:00
Jens Hedegaard Nielsen
1539854c3d
fix formatting of literal in docstring of int.from_bytes and int.to_bytes ( #117847 )
2024-04-18 09:01:58 +00:00
Steve Dower
687616877b
gh-111140: PyLong_From/AsNativeBytes: Take *flags* rather than just *endianness* (GH-116053)
2024-04-05 16:21:16 +02:00
Nikita Sobolev
eb947cdc13
gh-110819: Fix ‘kind’ may be used uninitialized warning in `longobject` ( #116599 )
2024-03-12 13:50:06 +03:00
Nikita Sobolev
465df8855e
gh-115827: Fix compile warning in `longobject.c` ( #115828 )
...
Objects/longobject.c:1186:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
2024-02-22 17:57:12 +00:00
Kirill Podoprigora
206f73dc5f
gh-115391: Fix compiler warning in `Objects/longobject.c` (GH-115368)
2024-02-13 20:49:13 +00:00
Steve Dower
7861dfd26a
gh-111140: Adds PyLong_AsNativeBytes and PyLong_FromNative[Unsigned]Bytes functions (GH-114886)
2024-02-12 20:13:13 +00:00
kcatss
a571a2fd3f
gh-114050: Fix crash when more than two arguments are passed to int() (GH-114067)
...
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2024-01-18 13:27:44 +02:00
Mark Shannon
0887b9ce8b
GH-109369 Add vectorcall to `PyLong_Type` (GH-111642)
2023-11-02 15:07:47 +00:00
Victor Stinner
03c4080c71
gh-108765: Python.h no longer includes <ctype.h> ( #108831 )
...
Remove <ctype.h> in C files which don't use it; only sre.c and
_decimal.c still use it.
Remove _PY_PORT_CTYPE_UTF8_ISSUE code from pyport.h:
* Code added by commit b5047fd019
in 2004 for MacOSX and FreeBSD.
* Test removed by commit 52ddaefb6b
in 2007, since Python str type now uses locale independent
functions like Py_ISALPHA() and Py_TOLOWER() and the Unicode
database.
Modules/_sre/sre.c replaces _PY_PORT_CTYPE_UTF8_ISSUE with new
functions: sre_isalnum(), sre_tolower(), sre_toupper().
Remove unused includes:
* _localemodule.c: remove <stdio.h>.
* getargs.c: remove <float.h>.
* dynload_win.c: remove <direct.h>, it no longer calls _getcwd()
since commit fb1f68ed7c
(in 2001).
2023-09-03 18:54:27 +02:00
Victor Stinner
be436e08b8
gh-108444: Add PyLong_AsInt() public function ( #108445 )
...
* Rename _PyLong_AsInt() to PyLong_AsInt().
* Add documentation.
* Add test.
* For now, keep _PyLong_AsInt() as an alias to PyLong_AsInt().
2023-08-24 23:55:30 +02:00
Brandt Bucher
05a824f294
GH-84436: Skip refcounting for known immortals (GH-107605)
2023-08-04 16:24:50 -07:00
Illia Volochii
fc130c47da
gh-102509: Start initializing `ob_digit` of `_PyLongValue` (GH-102510)
2023-07-28 14:39:54 +01:00
Mark Shannon
93923793f6
GH-101291: Add low level, unstable API for pylong (GH-101685)
...
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2023-05-21 14:45:48 +01:00