summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
Commit message (Collapse)AuthorAgeFilesLines
* [3.13] gh-119344: Make critical section API public (GH-119353) (#120856)Sam Gross2024-06-211-1/+1
| | | | | | | | | | | This makes the following macros public as part of the non-limited C-API for locking a single object or two objects at once. * `Py_BEGIN_CRITICAL_SECTION(op)` / `Py_END_CRITICAL_SECTION()` * `Py_BEGIN_CRITICAL_SECTION2(a, b)` / `Py_END_CRITICAL_SECTION2()` The supporting functions and structs used by the macros are also exposed for cases where C macros are not available. (cherry picked from commit 8f17d69b7bc906e8407095317842cc0fd52cd84a)
* [3.13] gh-120384: Fix array-out-of-bounds crash in `list_ass_subscript` ↵Miss Islington (bot)2024-06-211-12/+33
| | | | | | | | (GH-120442) (#120826) gh-120384: Fix array-out-of-bounds crash in `list_ass_subscript` (GH-120442) (cherry picked from commit 8334a1b55c93068f5d243852029baa83377ff6c9) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* [3.13] gh-120298: Fix use-after-free in `list_richcompare_impl` (GH-120303) ↵Miss Islington (bot)2024-06-111-1/+8
| | | | | | | | | (#120340) gh-120298: Fix use-after-free in `list_richcompare_impl` (GH-120303) (cherry picked from commit 141babad9b4eceb83371bf19ba3a36b50dd05250) Co-authored-by: Nikita Sobolev <mail@sobolevn.me> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.13] gh-119053: Implement the fast path for list.__getitem__ (gh-119112) ↵Miss Islington (bot)2024-05-211-5/+10
| | | | | | | | (gh-119309) gh-119053: Implement the fast path for list.__getitem__ (gh-119112) (cherry picked from commit ab4263a82abe8b684d8ad1edf7c7c6ec286ff756) Co-authored-by: Donghee Na <donghee.na@python.org>
* [3.13] gh-118561: Fix crash involving list.extend in free-threaded build ↵Miss Islington (bot)2024-05-091-1/+2
| | | | | | | | | | | | (GH-118723) (#118863) The `list_preallocate_exact` function did not zero initialize array contents. In the free-threaded build, this could expose uninitialized memory to concurrent readers between the call to `list_preallocate_exact` and the filling of the array contents with items. (cherry picked from commit 2402715e10d00ef60fad2948d8461559d084eb36) Co-authored-by: Sam Gross <colesbury@gmail.com>
* gh-117657: Fix TSAN list set failure (#118260)Dino Viehland2024-05-021-3/+6
| | | | | | | | | | | * Fix TSAN list set failure * Relaxed atomic is sufficient, add targetted test * More list * Remove atomic assign in list * Fixup white space
* gh-112069: Add _PySet_NextEntryRef to be thread-safe. (gh-117990)Donghee Na2024-04-181-2/+1
|
* gh-112087: Make `list.extend(dict)` behave atomically (#117438)Sam Gross2024-04-021-0/+5
| | | | | | | | Add a special case for `list.extend(dict)` and `list(dict)` so that those patterns behave atomically with respect to modifications to the list or dictionary. This is required by multiprocessing, which assumes that `list(_finalizer_registry)` is atomic.
* GH-116939: Rewrite binarysort() (#116940)Tim Peters2024-03-221-57/+131
| | | | | | | | | | | | | | | | | | | | | | | | Rewrote binarysort() for clarity. Also changed the signature to be more coherent (it was mixing sortslice with raw pointers). No change in method or functionality. However, I left some experiments in, disabled for now via `#if` tricks. Since this code was first written, some kinds of comparisons have gotten enormously faster (like for lists of floats), which changes the tradeoffs. For example, plain insertion sort's simpler innermost loop and highly predictable branches leave it very competitive (even beating, by a bit) binary insertion when comparisons are very cheap, despite that it can do many more compares. And it wins big on runs that are already sorted (moving the next one in takes only 1 compare then). So I left code for a plain insertion sort, to make future experimenting easier. Also made the maximum value of minrun a `#define` (``MAX_MINRUN`) to make experimenting with that easier too. And another bit of `#if``-disabled code rewrites binary insertion's innermost loop to remove its unpredictable branch. Surprisingly, this doesn't really seem to help overall. I'm unclear on why not. It certainly adds more instructions, but they're very simple, and it's hard to be believe they cost as much as a branch miss.
* gh-116621: Specialize list.extend for dict items (gh-116888)Donghee Na2024-03-191-3/+36
|
* Revert "gh-96844: Improve error message of list.remove (gh-106455)" (#116956)Victor Stinner2024-03-181-1/+1
| | | This reverts commit 217f47d6e5e56bca78b8556e910cd00890f6f84a.
* gh-116621: Specialize list.extend for dict keys/values (gh-116816)Donghee Na2024-03-151-0/+37
|
* GH-116554: Relax list.sort()'s notion of "descending" runs (#116578)Tim Peters2024-03-131-54/+103
| | | | | | | | | | | | | | | | | | | | * GH-116554: Relax list.sort()'s notion of "descending" run Rewrote `count_run()` so that sub-runs of equal elements no longer end a descending run. Both ascending and descending runs can have arbitrarily many sub-runs of arbitrarily many equal elements now. This is tricky, because we only use ``<`` comparisons, so checking for equality doesn't come "for free". Surprisingly, it turned out there's a very cheap (one comparison) way to determine whether an ascending run consisted of all-equal elements. That sealed the deal. In addition, after a descending run is reversed in-place, we now go on to see whether it can be extended by an ascending run that just happens to be adjacent. This succeeds in finding at least one additional element to append about half the time, and so appears to more than repay its cost (the savings come from getting to skip a binary search, when a short run is artificially forced to length MIINRUN later, for each new element `count_run()` can add to the initial run). While these have been in the back of my mind for years, a question on StackOverflow pushed it to action: https://stackoverflow.com/questions/78108792/ They were wondering why it took about 4x longer to sort a list like: [999_999, 999_999, ..., 2, 2, 1, 1, 0, 0] than "similar" lists. Of course that runs very much faster after this patch. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
* gh-116621: Set manual critical section for list.extend (gh-116657)Donghee Na2024-03-121-45/+93
|
* gh-112087: Make list.sort to be thread-safe for PEP 703. (gh-116553)Donghee Na2024-03-101-4/+7
|
* gh-112087: Store memory allocation information into _PyListArray (gh-116529)Donghee Na2024-03-091-14/+112
|
* gh-116381: Remove bad specializations, add fail stats (GH-116464)Ken Jin2024-03-071-3/+3
| | | * Remove bad specializations, add fail stats
* gh-116381: Specialize CONTAINS_OP (GH-116385)Ken Jin2024-03-061-3/+3
| | | | | | | | | | | * Specialize CONTAINS_OP * 📜🤖 Added by blurb_it. * Add PyAPI_FUNC for JIT --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* gh-112087: Update list_get_item_ref to optimistically avoid locking (gh-116353)Donghee Na2024-03-051-11/+60
| | | Co-authored-by: Sam Gross <colesbury@gmail.com>
* gh-112087: Make list_{slice, ass_slice, subscript} to be threadsafe (gh-116233)Donghee Na2024-03-051-50/+82
|
* gh-112087: Use QSBR technique for list_new/clear for free-thread build ↵Donghee Na2024-03-011-6/+29
| | | | (gh-115875)
* gh-112087: Make list_{concat, repeat, inplace_repeat, ass_item) to be ↵Donghee Na2024-02-211-40/+82
| | | | thread-safe (gh-115605)
* gh-115733: Fix crash involving exhausted list iterator (#115740)Sam Gross2024-02-201-3/+3
| | | | | * gh-115733: Fix crash involving exhausted iterator * Add blurb
* gh-111968: Split _Py_dictkeys_freelist out of _Py_dict_freelist (gh-115505)Donghee Na2024-02-161-3/+3
|
* gh-112087: Make __sizeof__ and listiter_{len, next} to be threadsafe (gh-114843)Donghee Na2024-02-141-50/+52
|
* gh-111968: Rename freelist related struct names to Eric's suggestion (gh-115329)Donghee Na2024-02-141-17/+17
|
* gh-111968: Refactor _PyXXX_Fini to integrate with _PyObject_ClearFreeLists ↵Donghee Na2024-02-101-10/+0
| | | | (gh-114899)
* gh-112087: Make list_{count, index, contains} to be thread-safe. (gh-114916)Donghee Na2024-02-061-19/+33
|
* gh-114329: Add `PyList_GetItemRef` function (GH-114504)Sam Gross2024-02-021-0/+15
| | | | | | | The new `PyList_GetItemRef` is similar to `PyList_GetItem`, but returns a strong reference instead of a borrowed reference. Additionally, if the passed "list" object is not a list, the function sets a `TypeError` instead of calling `PyErr_BadInternalCall()`.
* gh-111968: Use per-thread freelists for dict in free-threading (gh-114323)Donghee Na2024-02-011-0/+4
|
* gh-112087: Make PyList_{Append,Size,GetSlice} to be thread-safe (gh-114651)Donghee Na2024-01-311-7/+15
|
* gh-112087: Make list_repr and list_length to be thread-safe (gh-114582)Donghee Na2024-01-261-10/+17
|
* gh-111968: Unify freelist naming schema to Eric's suggestion (gh-114581)Donghee Na2024-01-261-2/+2
|
* gh-112087: Remove duplicated critical_section (gh-114268)Donghee Na2024-01-181-6/+3
|
* gh-112087: Update list impl to be thread-safe with manual CS (gh-113863)Donghee Na2024-01-161-16/+53
|
* gh-111968: Explicit handling for finalized freelist (gh-113929)Donghee Na2024-01-121-15/+7
|
* gh-111968: Unify naming scheme for freelist (gh-113919)Donghee Na2024-01-101-2/+2
|
* gh-111968: Introduce _PyFreeListState and _PyFreeListState_GET API (gh-113584)Donghee Na2024-01-091-11/+11
|
* gh-112087: Update list.{pop,clear,reverse,remove} to use CS (gh-113764)Donghee Na2024-01-091-6/+11
|
* gh-111178: Avoid calling functions from incompatible pointer types in ↵Christopher Chavez2024-01-021-72/+92
| | | | | | | | | | listobject.c (GH-112820) Fix undefined behavior warnings (UBSan -fsanitize=function), for example: Objects/object.c:674:11: runtime error: call to function list_repr through pointer to incorrect function type 'struct _object *(*)(struct _object *)' listobject.c:382: note: list_repr defined here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/object.c:674:11 in
* gh-111138: Add PyList_Extend() and PyList_Clear() functions (#111862)Victor Stinner2023-11-131-112/+167
| | | | | | * Split list_extend() into two sub-functions: list_extend_fast() and list_extend_iter(). * list_inplace_concat() no longer has to call Py_DECREF() on the list_extend() result, since list_extend() now returns an int.
* gh-106168: Revert the "size before item" setting (#111683)scoder2023-11-031-1/+1
| | | | gh-106168: Update the size only after setting the item, to avoid temporary inconsistencies. Also remove the "what's new" sentence regarding the size setting since tuples cannot grow after allocation.
* gh-106320: Remove private _PyEval function (#108433)Victor Stinner2023-08-241-0/+1
| | | | | | | | | | | | | | 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.
* gh-106320: Remove private _PyObject C API (#107147)Victor Stinner2023-07-231-1/+1
| | | | | | | | | | | | | | | | Move private debug _PyObject functions to the internal C API (pycore_object.h): * _PyDebugAllocatorStats() * _PyObject_CheckConsistency() * _PyObject_DebugTypeStats() * _PyObject_IsFreed() No longer export most of these functions, except of _PyObject_IsFreed(). Move test functions using _PyObject_IsFreed() from _testcapi to _testinternalcapi. check_pyobject_is_freed() test no longer catch _testcapi.error: the tested function cannot raise _testcapi.error.
* gh-96844: Improve error message of list.remove (gh-106455)Dong-hee Na2023-07-051-1/+1
|
* gh-106320: Create pycore_modsupport.h header file (#106355)Victor Stinner2023-07-031-0/+1
| | | | | | | | | | Remove the following functions from the C API, move them to the internal C API: add a new pycore_modsupport.h internal header file: * PyModule_CreateInitialized() * _PyArg_NoKwnames() * _Py_VaBuildStack() No longer export these functions.
* gh-106168: PyTuple_SET_ITEM() now checks the index (#106164)Victor Stinner2023-06-281-2/+3
| | | | | | | | | | | | | PyTuple_SET_ITEM() and PyList_SET_ITEM() now check the index argument with an assertion if Python is built in debug mode or is built with assertions. * list_extend() and _PyList_AppendTakeRef() now set the list size before calling PyList_SET_ITEM(). * PyStructSequence_GetItem() and PyStructSequence_SetItem() now check the index argument: must be lesser than REAL_SIZE(op). * PyStructSequence_GET_ITEM() and PyStructSequence_SET_ITEM() are now aliases to PyStructSequence_GetItem() and PyStructSequence_SetItem().
* GH-101291: Rearrange the size bits in PyLongObject (GH-102464)Mark Shannon2023-03-221-11/+9
| | | | | | | | | | * 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-101765: Fix refcount issues in list and unicode pickling (#102265)Jelle Zijlstra2023-02-261-0/+8
| | | Followup from #101769.
* gh-101765: Fix SystemError / segmentation fault in iter `__reduce__` when ↵Ionite2023-02-241-4/+8
| | | | internal access of `builtins.__dict__` exhausts the iterator (#101769)