summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
Commit message (Collapse)AuthorAgeFilesLines
* GH-127058: Make `PySequence_Tuple` safer and probably faster. (#127758)Mark Shannon2024-12-111-0/+19
| | | | * Use a small buffer, then list when constructing a tuple from an arbitrary sequence.
* gh-127536: Add missing locks in listobject.c (GH-127580)Sam Gross2024-12-041-10/+40
| | | | We were missing locks around some list operations in the free threading build.
* gh-127521: Mark list as "shared" before resizing if necessary (#127524)Sam Gross2024-12-021-0/+20
| | | | | | | | | In the free threading build, if a non-owning thread resizes a list, it must use QSBR to free the old list array because there may be a concurrent access (without a lock) from the owning thread. To match the pattern in dictobject.c, we just mark the list as "shared" before resizing if it's from a non-owning thread and not already marked as shared.
* gh-115999: Add partial free-thread specialization for BINARY_SUBSCR (gh-127227)Donghee Na2024-12-021-0/+6
|
* GH-126547: Pre-assign version numbers for a few common classes (GH-126551)Mark Shannon2024-11-081-0/+1
|
* gh-125196: PyUnicodeWriter_Discard(NULL) does nothing (#125222)Victor Stinner2024-10-091-3/+1
|
* gh-125196: Use PyUnicodeWriter for repr(list) (#125202)Victor Stinner2024-10-091-22/+23
| | | | | | Replace the private _PyUnicodeWriter with the public PyUnicodeWriter. Replace PyObject_Repr() + _PyUnicodeWriter_WriteStr() with PyUnicodeWriter_WriteRepr().
* gh-123990: Good bye WITH_FREELISTS macro (gh-124358)Donghee Na2024-09-241-2/+0
|
* gh-117139: Replace _PyList_FromArraySteal with stack ref variant (#122830)Sam Gross2024-08-121-3/+5
| | | | | | | This replaces `_PyList_FromArraySteal` with `_PyList_FromStackRefSteal`. It's functionally equivalent, but takes a `_PyStackRef` array instead of an array of `PyObject` pointers. Co-authored-by: Ken Jin <kenjin@python.org>
* gh-100240: Use a consistent implementation for freelists (#121934)Sam Gross2024-07-221-50/+9
| | | | | | | | This combines and updates our freelist handling to use a consistent implementation. Objects in the freelist are linked together using the first word of memory block. If configured with freelists disabled, these operations are essentially no-ops.
* gh-121288: Make error message for index() methods consistent (GH-121395)Serhiy Storchaka2024-07-051-1/+1
| | | | | | | | | Make error message for index() methods consistent Remove the repr of the searched value (which can be arbitrary large) from ValueError messages for list.index(), range.index(), deque.index(), deque.remove() and ShareableList.index(). Make the error messages consistent with error messages for other index() and remove() methods.
* Fix typos in comments (#120821)Xie Yanbo2024-06-241-2/+2
|
* gh-119344: Make critical section API public (#119353)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.
* gh-120384: Fix array-out-of-bounds crash in `list_ass_subscript` (#120442)Nikita Sobolev2024-06-211-12/+33
|
* gh-120298: Fix use-after-free in `list_richcompare_impl` (#120303)Nikita Sobolev2024-06-111-1/+8
| | | Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-119053: Implement the fast path for list.__getitem__ (gh-119112)Donghee Na2024-05-211-5/+10
|
* gh-118561: Fix crash involving list.extend in free-threaded build (#118723)Sam Gross2024-05-091-1/+2
| | | | | | | 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.
* 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
|