summaryrefslogtreecommitdiffstats
path: root/Objects/longobject.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-102471, PEP 757: Add PyLong import and export API (#121339)Victor Stinner2024-12-131-0/+120
| | | | | 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>
* gh-126868: Add freelist for compact int objects (GH-126865)Pieter Eendebak2024-12-131-19/+59
|
* gh-126061: Add PyLong_IsPositive/Zero/Negative() functions (#126065)RUANG (James Roy)2024-11-121-0/+33
| | | | | 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>
* GH-126547: Pre-assign version numbers for a few common classes (GH-126551)Mark Shannon2024-11-081-0/+1
|
* Use _PyLong_GetOne() and _PyLong_GetZero() in long_invmod() (#125044)Victor Stinner2024-10-071-11/+2
| | | These functions cannot fail.
* gh-111178: Fix function signatures in longobject.c (#124895)Victor Stinner2024-10-021-100/+139
| | | | | | | | | | | | | | * 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).
* gh-123497: New limit for Python integers on 64-bit platforms (GH-123724)Serhiy Storchaka2024-09-291-129/+67
| | | | | | | | | | | 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.
* gh-121485: Always use 64-bit integers for integers bits count (GH-121486)Serhiy Storchaka2024-08-301-73/+52
| | | | | Use 64-bit integers instead of platform specific size_t or Py_ssize_t to represent the number of bits in Python integer.
* gh-120389: Add PyLong_FromInt64() and PyLong_AsInt64() (#120390)Victor Stinner2024-08-281-0/+66
| | | | | | | | | | | | 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()
* gh-111178: Avoid calling long_hash from incompatible pointer type (GH-122972)Bénédikt Tran2024-08-141-2/+3
| | | Make `long_hash` compatible with `hashfunc`.
* gh-121905: Consistently use "floating-point" instead of "floating point" ↵Serhiy Storchaka2024-07-191-1/+1
| | | | (GH-121907)
* gh-121153: Fix some errors with use of _PyLong_CompactValue() (GH-121154)Serhiy Storchaka2024-07-131-13/+55
| | | | | | * 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().
* gh-121115: Skip __index__ in PyLong_AsNativeBytes by default (GH-121118)Steve Dower2024-06-281-1/+5
|
* gh-120593: Fix const qualifier in _PyLong_CompactValue() (#121053)Victor Stinner2024-06-261-2/+2
| | | | | | | | | | | | | | | | | | 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));
* gh-120080: Accept ``None`` as a valid argument for direct call of the ↵Kirill Podoprigora2024-06-071-3/+3
| | | | | ``int.__round__`` (#120088) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* gh-119057: Use better error messages for zero division (#119066)Nikita Sobolev2024-06-031-3/+2
|
* gh-116560: Add PyLong_GetSign() public function (#116561)Sergey B Kirpichev2024-06-031-0/+12
| | | Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-119613: Use C99+ functions instead of Py_IS_NAN/INFINITY/FINITE (#119619)Sergey B Kirpichev2024-05-291-2/+2
|
* Tiny fix: Update link for HAC algorithm (gh-118546)Ayato Hayashi2024-05-231-2/+2
|
* fix formatting of literal in docstring of int.from_bytes and int.to_bytes ↵Jens Hedegaard Nielsen2024-04-181-4/+4
| | | | (#117847)
* gh-111140: PyLong_From/AsNativeBytes: Take *flags* rather than just ↵Steve Dower2024-04-051-24/+82
| | | | *endianness* (GH-116053)
* gh-110819: Fix ‘kind’ may be used uninitialized warning in `longobject` ↵Nikita Sobolev2024-03-121-28/+35
| | | | (#116599)
* gh-115827: Fix compile warning in `longobject.c` (#115828)Nikita Sobolev2024-02-221-1/+1
| | | Objects/longobject.c:1186:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
* gh-115391: Fix compiler warning in `Objects/longobject.c` (GH-115368)Kirill Podoprigora2024-02-131-1/+1
|
* gh-111140: Adds PyLong_AsNativeBytes and PyLong_FromNative[Unsigned]Bytes ↵Steve Dower2024-02-121-8/+208
| | | | functions (GH-114886)
* gh-114050: Fix crash when more than two arguments are passed to int() ↵kcatss2024-01-181-1/+1
| | | | | (GH-114067) Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
* GH-109369 Add vectorcall to `PyLong_Type` (GH-111642)Mark Shannon2023-11-021-0/+25
|
* gh-108765: Python.h no longer includes <ctype.h> (#108831)Victor Stinner2023-09-031-4/+2
| | | | | | | | | | | | | | | | | | | | | | | 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 b5047fd01948ab108edcc1b3c2c901d915814cfd in 2004 for MacOSX and FreeBSD. * Test removed by commit 52ddaefb6bab1a74ecffe8519c02735794ebfbe1 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 fb1f68ed7cc1536482d1debd70a53c5442135fe2 (in 2001).
* gh-108444: Add PyLong_AsInt() public function (#108445)Victor Stinner2023-08-241-1/+1
| | | | | | * Rename _PyLong_AsInt() to PyLong_AsInt(). * Add documentation. * Add test. * For now, keep _PyLong_AsInt() as an alias to PyLong_AsInt().
* GH-84436: Skip refcounting for known immortals (GH-107605)Brandt Bucher2023-08-041-3/+2
|
* gh-102509: Start initializing `ob_digit` of `_PyLongValue` (GH-102510)Illia Volochii2023-07-281-0/+3
|
* GH-101291: Add low level, unstable API for pylong (GH-101685)Mark Shannon2023-05-211-0/+14
| | | Co-authored-by: Petr Viktorin <encukou@gmail.com>
* gh-94673: Properly Initialize and Finalize Static Builtin Types for Each ↵Eric Snow2023-05-021-7/+4
| | | | | Interpreter (gh-104072) Until now, we haven't been initializing nor finalizing the per-interpreter state properly.
* gh-84436: Immortalize in _PyStructSequence_InitBuiltinWithFlags() (gh-104054)Eric Snow2023-05-011-2/+2
| | | This also does some cleanup.
* gh-94673: Ensure Builtin Static Types are Readied Properly (gh-103940)Eric Snow2023-04-271-12/+2
| | | There were cases where we do unnecessary work for builtin static types. This also simplifies some work necessary for a per-interpreter GIL.
* gh-84436: Implement Immortal Objects (gh-19474)Eddie Elizondo2023-04-221-3/+23
| | | | | | | | | This is the implementation of PEP683 Motivation: The PR introduces the ability to immortalize instances in CPython which bypasses reference counting. Tagging objects as immortal allows up to skip certain operations when we know that the object will be around for the entire execution of the runtime. Note that this by itself will bring a performance regression to the runtime due to the extra reference count checks. However, this brings the ability of having truly immutable objects that are useful in other contexts such as immutable data sharing between sub-interpreters.
* GH-101291: Rearrange the size bits in PyLongObject (GH-102464)Mark Shannon2023-03-221-373/+321
| | | | | | | | | | * Eliminate all remaining uses of Py_SIZE and Py_SET_SIZE on PyLongObject, adding asserts. * Change layout of size/sign bits in longobject to support future addition of immortal ints and tagged medium ints. * Add functions to hide some internals of long object, and for setting sign and digit count. * Replace uses of IS_MEDIUM_VALUE macro with _PyLong_IsCompact().
* gh-101825: Clarify that as_integer_ratio() output is always normalized (#101843)Sergey B Kirpichev2023-02-271-4/+3
| | | | | | | | | Make docstrings for `as_integer_ratio` consistent across types, and document that the returned pair is always normalized (coprime integers, with positive denominator). --------- Co-authored-by: Owain Davies <116417456+OTheDev@users.noreply.github.com> Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
* gh-101266: Fix __sizeof__ for subclasses of int (#101394)Mark Dickinson2023-02-051-7/+4
| | | | | | | Fix the behaviour of the `__sizeof__` method (and hence the results returned by `sys.getsizeof`) for subclasses of `int`. Previously, `int` subclasses gave identical results to the `int` base class, ignoring the presence of the instance dictionary. <!-- gh-issue-number: gh-101266 --> * Issue: gh-101266 <!-- /gh-issue-number -->
* GH-101291: Refactor the `PyLongObject` struct into object header and ↵Mark Shannon2023-01-301-178/+178
| | | | PyLongValue struct. (GH-101292)
* gh-101037: Fix potential memory underallocation for zeros of int subtypes ↵Mark Dickinson2023-01-211-0/+5
| | | | | | | | | (#101038) This PR fixes object allocation in long_subtype_new to ensure that there's at least one digit in all cases, and makes sure that the value of that digit is copied over from the source long. Needs backport to 3.11, but not any further: the change to require at least one digit was only introduced for Python 3.11. Fixes #101037.
* gh-100637: Fix int and bool __sizeof__ calculation to include the 1 element ↵Ionite2023-01-021-1/+4
| | | | | | | | ob_digit array for 0 and False (#100663) Fixes behaviour where int (and subtypes like bool) __sizeof__ under-reports true size as it did not take into account the size 1 `ob_digit` array for the zero int. Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
* gh-100268: Add is_integer method to int (#100439)Shantanu2022-12-241-0/+14
| | | This improves the lives of type annotation users of `float` - which type checkers implicitly treat as `int|float` because that is what most code actually wants. Before this change a `.is_integer()` method could not be assumed to exist on things annotated as `: float` due to the method not existing on both types.
* clarify the 4300-digit limit on int-str conversion (#100175)Ned Batchelder2022-12-121-2/+2
|
* gh-98724: Fix warnings on Py_SETREF() usage (#99781)Victor Stinner2022-11-251-1/+1
| | | Cast argument to the expected type.
* gh-99537: Use Py_SETREF() function in longobject C code (#99655)Victor Stinner2022-11-221-49/+24
| | | | Replace "Py_DECREF(var); var = new;" with "Py_SETREF(var, new);" in longobject.c and _testcapi/long.c.
* gh-99300: Use Py_NewRef() in Objects/ directory (#99351)Victor Stinner2022-11-101-31/+20
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in C files of the Objects/ directory.
* Correct some typos in comments (GH-98194)jonasdlindner2022-11-061-1/+1
| | | Automerge-Triggered-By: GH:AlexWaygood
* gh-90716: Fix pylong_int_from_string() refleak (#99094)Victor Stinner2022-11-041-0/+1
| | | | | | Fix validated by: $ ./python -m test -R 3:3 test_int Tests result: SUCCESS
* gh-90716: bugfixes and more tests for _pylong. (#99073)Gregory P. Smith2022-11-031-4/+11
| | | | | | | | | * Properly decref on _pylong import error. * Improve the error message on _pylong TypeError. * Fix the assertion error in pydebug builds to be a TypeError. * Tie the return value comments together. These are minor followups to issues not caught among the reviewers on https://github.com/python/cpython/pull/96673.