Sergey Miryanov
32c264982e
gh-140061: Use _PyObject_IsUniquelyReferenced()
to check if objects are uniquely referenced (gh-140062)
...
The previous `Py_REFCNT(x) == 1` checks can have data races in the free
threaded build. `_PyObject_IsUniquelyReferenced(x)` is a more conservative
check that is safe in the free threaded build and is identical to
`Py_REFCNT(x) == 1` in the default GIL-enabled build.
2025-10-15 09:48:21 -04:00
Victor Stinner
166cdaa6fb
gh-111489: Remove _PyTuple_FromArray() alias ( #139973 )
...
Replace _PyTuple_FromArray() with PyTuple_FromArray().
Remove pycore_tuple.h includes.
2025-10-11 22:58:14 +02:00
Adam Turner
98b4cd6fe9
GH-135763: AC: Use `Py_ssize_t(allow_negative=False)
` ( #138394 )
2025-09-02 21:29:05 +01:00
Adam Turner
918e3ba6c0
GH-137623: Use an AC decorator for docstring line length enforcement ( #137690 )
2025-08-18 18:29:00 +01:00
Pieter Eendebak
847d1c2cb4
gh-123471: Make itertools.product and itertools.combinations thread-safe ( #132814 )
...
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-06-30 11:31:59 +00:00
Pieter Eendebak
0533c1faf2
gh-123471: Make itertools.chain thread-safe ( #135689 )
2025-06-30 16:36:58 +05:30
Pieter Eendebak
26a1cd4e8c
gh-123471: make concurrent iteration over itertools.cycle
safe under free-threading ( #131212 )
...
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-06-02 20:13:32 +05:30
Pieter Eendebak
9d127e83b9
gh-123471: Make concurrent iteration over itertools.repeat safe under free-threading ( #131247 )
2025-04-13 13:26:58 +05:30
Michael Droettboom
8614f86b71
gh-131525: Cache the result of tuple_hash ( #131529 )
...
* gh-131525: Cache the result of tuple_hash
* Fix debug builds
* Add blurb
* Fix formatting
* Pre-compute empty tuple singleton
* Mostly set the cache within tuple_alloc
* Fixes for TSAN
* Pre-compute empty tuple singleton
* Fix for 32-bit platforms
* Assert that op != NULL in _PyTuple_RESET_HASH_CACHE
* Use FT_ATOMIC_STORE_SSIZE_RELAXED macro
* Update Include/internal/pycore_tuple.h
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* Fix alignment
* atomic load
* Update Objects/tupleobject.c
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
---------
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
2025-03-27 09:57:06 -04:00
Victor Stinner
061da44bac
gh-111178: Change Argument Clinic signature for @classmethod
( #131157 )
...
Use "PyObject*", instead of "PyTypeObject*", for `@classmethod`
functions to fix an undefined behavior.
2025-03-12 17:42:07 +01:00
Pieter Eendebak
405a2d74cb
gh-123471: make itertools.batched
thread-safe ( #129416 )
2025-03-12 15:30:33 +05:30
Bénédikt Tran
f8c041bff9
gh-111178: fix UBSan failures in Modules/itertoolsmodule.c
(GH-129780)
2025-02-19 11:58:47 +01:00
Sergey B Kirpichev
930ba0ce60
gh-126618: fix repr(itertools.count(sys.maxsize)) ( #127048 )
...
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-12-02 14:14:40 +01:00
Bénédikt Tran
6e3bb8a913
gh-126595: fix a crash when calling itertools.count(sys.maxsize)
( #126617 )
2024-11-12 14:10:10 +01:00
Raymond Hettinger
909c6f7189
gh-123884 Tee of tee was not producing n independent iterators (gh-124490)
2024-09-25 13:38:05 -07:00
Arnon Yaari
87939bd579
gh-117657: Fix itertools.count thread safety ( #119268 )
...
Fix itertools.count in free-threading mode
2024-05-21 10:16:34 -07:00
Raymond Hettinger
e8cbcf4955
GH-101588: Remove deprecated pickle/copy/deepcopy from itertools (gh-118816)
2024-05-09 03:31:47 -05:00
Brett Simmers
c2627d6eea
gh-116322: Add Py_mod_gil module slot ( #116882 )
...
This PR adds the ability to enable the GIL if it was disabled at
interpreter startup, and modifies the multi-phase module initialization
path to enable the GIL when loading a module, unless that module's spec
includes a slot indicating it can run safely without the GIL.
PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went
with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148.
A warning will be issued up to once per interpreter for the first
GIL-using module that is loaded. If `-v` is given, a shorter message
will be printed to stderr every time a GIL-using module is loaded
(including the first one that issues a warning).
2024-05-03 11:30:55 -04:00
Shantanu
6999d68d28
gh-118218: Reuse return tuple in itertools.pairwise (GH-118219)
2024-04-30 23:16:52 +03:00
Serhiy Storchaka
49af71a04a
gh-117764: Add signatures for some objects in the itertools module (GH-117774)
2024-04-12 12:36:27 +03:00
Erlend E. Aasland
e2fcaf19d3
gh-115874: Don't use module state in teedataobject tp_dealloc ( #116204 )
...
Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
2024-03-18 13:24:24 +01:00
Raymond Hettinger
15dc2979bc
Consistently spell out *predicate* instead of *pred*. (gh-116308)
2024-03-04 15:51:29 +00:00
Raymond Hettinger
1583c40be9
gh-113202: Add a strict option to itertools.batched() (gh-113203)
2023-12-16 09:13:50 -06:00
Serhiy Storchaka
6ca9d3e017
gh-109786: Fix leaks and crash when re-enter itertools.pairwise.__next__() (GH-109788)
2023-12-04 11:47:55 +00:00
Victor Stinner
c494fb333b
gh-106320: Remove private _PyEval function ( #108433 )
...
Move private _PyEval functions to the internal C API
(pycore_ceval.h):
* _PyEval_GetBuiltin()
* _PyEval_GetBuiltinId()
* _PyEval_GetSwitchInterval()
* _PyEval_MakePendingCalls()
* _PyEval_SetProfile()
* _PyEval_SetSwitchInterval()
* _PyEval_SetTrace()
No longer export most of these functions.
2023-08-24 20:25:22 +02:00
Victor Stinner
1a3faba9f1
gh-106869: Use new PyMemberDef constant names ( #106871 )
...
* Remove '#include "structmember.h"'.
* If needed, add <stddef.h> to get offsetof() function.
* Update Parser/asdl_c.py to regenerate Python/Python-ast.c.
* Replace:
* T_SHORT => Py_T_SHORT
* T_INT => Py_T_INT
* T_LONG => Py_T_LONG
* T_FLOAT => Py_T_FLOAT
* T_DOUBLE => Py_T_DOUBLE
* T_STRING => Py_T_STRING
* T_OBJECT => _Py_T_OBJECT
* T_CHAR => Py_T_CHAR
* T_BYTE => Py_T_BYTE
* T_UBYTE => Py_T_UBYTE
* T_USHORT => Py_T_USHORT
* T_UINT => Py_T_UINT
* T_ULONG => Py_T_ULONG
* T_STRING_INPLACE => Py_T_STRING_INPLACE
* T_BOOL => Py_T_BOOL
* T_OBJECT_EX => Py_T_OBJECT_EX
* T_LONGLONG => Py_T_LONGLONG
* T_ULONGLONG => Py_T_ULONGLONG
* T_PYSSIZET => Py_T_PYSSIZET
* T_NONE => _Py_T_NONE
* READONLY => Py_READONLY
* PY_AUDIT_READ => Py_AUDIT_READ
* READ_RESTRICTED => Py_AUDIT_READ
* PY_WRITE_RESTRICTED => _Py_WRITE_RESTRICTED
* RESTRICTED => (READ_RESTRICTED | _Py_WRITE_RESTRICTED)
2023-07-25 15:28:30 +02:00
Serhiy Storchaka
be1b968dc1
gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)
2023-07-12 08:57:10 +03:00
Inada Naoki
d5bd32fb48
gh-104922: remove PY_SSIZE_T_CLEAN ( #106315 )
2023-07-02 15:07:46 +09:00
Raymond Hettinger
f339ec5ddf
Fix grammar and improve clarity for an deprecation message. (GH-105457)
2023-06-07 11:29:04 -05:00
Raymond Hettinger
402ee5a68b
GH-101588: Deprecate pickle/copy/deepcopy support in itertools (GH-104965)
2023-05-26 15:32:53 -05:00
Eric Snow
a9c6e0618f
gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205)
...
Here we are doing no more than adding the value for Py_mod_multiple_interpreters and using it for stdlib modules. We will start checking for it in gh-104206 (once PyInterpreterState.ceval.own_gil is added in gh-104204).
2023-05-05 21:11:27 +00:00
Erlend E. Aasland
ccd98a3146
gh-101476: Add _PyType_GetModuleState (GH-101477)
...
For fast module state access from heap type methods.
2023-02-23 13:42:15 -08:00
Erlend E. Aasland
826bf0e695
gh-101277: Finalise isolating itertools (GH-101305)
...
Add repeat, islice, chain, tee, teedataobject, and batched types to module state.
Automerge-Triggered-By: GH:erlend-aasland
2023-02-10 03:58:14 -08:00
Erlend E. Aasland
de3669ebcb
gh-101277: Port more itertools static types to heap types ( #101304 )
...
Add accumulate, compress, count, filterfalse, pairwise, product,
and zip_longest types to module state.
2023-02-08 21:25:42 +01:00
Erlend E. Aasland
a52cc9853f
gh-101277: Port more itertools
static types to heap types ( #101303 )
...
Add dropwhile, takewhile, starmap, combinations*, and permutations types to module state.
2023-02-03 15:24:27 +05:30
Erlend E. Aasland
2b3e02a705
gh-101277: Isolate itertools, add group and _grouper types to module state ( #101302 )
...
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2023-02-01 12:41:30 +01:00
Raymond Hettinger
8c215466db
GH-98363: Shrink the physical size as well as the logical size (GH-100138)
2022-12-09 11:02:35 -06:00
Raymond Hettinger
35cc0ea736
GH-98363: Have batched() return tuples (GH-100118)
2022-12-08 15:08:16 -06:00
Serhiy Storchaka
922a6cf6c2
gh-60203: Revert changes in cycle.__setstate__ ( #99982 )
...
In case if only True/False be supported as boolean arguments in future,
we should continue to support 1/0 here.
2022-12-05 17:27:40 +01:00
Serhiy Storchaka
a87c46eab3
bpo-15999: Accept arbitrary values for boolean parameters. ( #15609 )
...
builtins and extension module functions and methods that expect boolean values for parameters now accept any Python object rather than just a bool or int type. This is more consistent with how native Python code itself behaves.
2022-12-03 11:52:21 -08:00
Victor Stinner
85dd6cb6df
gh-99845: Use size_t type in __sizeof__() methods ( #99846 )
...
The implementation of __sizeof__() methods using _PyObject_SIZE() now
use an unsigned type (size_t) to compute the size, rather than a signed
type (Py_ssize_t).
Cast explicitly signed (Py_ssize_t) values to unsigned type
(Py_ssize_t).
2022-11-30 17:22:52 +01:00
Victor Stinner
7e3f09cad9
gh-99537: Use Py_SETREF() function in C code ( #99656 )
...
Fix potential race condition in code patterns:
* Replace "Py_DECREF(var); var = new;" with "Py_SETREF(var, new);"
* Replace "Py_XDECREF(var); var = new;" with "Py_XSETREF(var, new);"
* Replace "Py_CLEAR(var); var = new;" with "Py_XSETREF(var, new);"
Other changes:
* Replace "old = var; var = new; Py_DECREF(var)"
with "Py_SETREF(var, new);"
* Replace "old = var; var = new; Py_XDECREF(var)"
with "Py_XSETREF(var, new);"
* And remove the "old" variable.
2022-11-22 14:22:22 +01:00
Victor Stinner
0bedc28d14
gh-99300: Use Py_NewRef() in Modules/itertoolsmodule.c ( #99439 )
...
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
Py_XNewRef() in Modules/itertoolsmodule.c.
2022-11-13 16:04:22 +01:00
Raymond Hettinger
5871e19942
GH-98363: Slicing isn't necessary. A size reduction will suffice. (GH-98538)
2022-10-22 07:21:06 -05:00
Raymond Hettinger
8d574234d4
GH-98363: Use better accessor macro ( #98535 )
2022-10-21 18:44:49 -05:00
Raymond Hettinger
a5ff80c8bc
GH-98363: Fix exception handling in batched() (GH-98523)
2022-10-21 12:31:52 -05:00
Raymond Hettinger
c1e02d4e4e
GH-98363: Presize the list for batched() (GH-98419)
2022-10-20 02:28:17 -05:00
Raymond Hettinger
9608bef84a
Fix typos in comments (GH-98375)
2022-10-17 21:01:28 -05:00
Raymond Hettinger
de3ece769a
GH-98363: Add itertools.batched() (GH-98364)
2022-10-17 18:53:45 -05:00
DongGeon Lee
278fdd3e3a
bpo-46728: fix docstring of combinations_with_replacement for consistency (GH-31293)
2022-02-15 09:02:21 +09:00