summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
Commit message (Collapse)AuthorAgeFilesLines
* 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)
* GH-101291: Refactor the `PyLongObject` struct into object header and ↵Mark Shannon2023-01-301-2/+2
| | | | PyLongValue struct. (GH-101292)
* gh-100146: Steal references from stack when building a list (#100147)L. A. F. Pereira2023-01-031-0/+21
| | | | | | | | | | When executing the BUILD_LIST opcode, steal the references from the stack, in a manner similar to the BUILD_TUPLE opcode. Implement this by offloading the logic to a new private API, _PyList_FromArraySteal(), that works similarly to _PyTuple_FromArraySteal(). This way, instead of performing multiple stack pointer adjustments while the list is being initialized, the stack is adjusted only once and a fast memory copy operation is performed in one fell swoop.
* gh-94603: micro optimize list.pop (gh-94604)Pieter Eendebak2022-12-271-12/+20
|
* bpo-15999: Accept arbitrary values for boolean parameters. (#15609)Serhiy Storchaka2022-12-031-2/+2
| | | 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.
* gh-99845: Use size_t type in __sizeof__() methods (#99846)Victor Stinner2022-11-301-4/+3
| | | | | | | | 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).
* gh-99300: Use Py_NewRef() in Objects/listobject.c (#99336)Victor Stinner2022-11-101-40/+20
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in Objects/listobject.c.
* gh-97616: list_resize() checks for integer overflow (#97617)Victor Stinner2022-09-281-2/+8
| | | | | | | | Fix multiplying a list by an integer (list *= int): detect the integer overflow when the new allocated length is close to the maximum size. Issue reported by Jordan Limor. list_resize() now checks for integer overflow before multiplying the new allocated length by the list item size (sizeof(PyObject*)).
* gh-96364: Fix text signatures of `__getitem__` for `list` and `dict` (GH-96365)Nikita Sobolev2022-09-091-1/+2
|
* gh-91247: Use memcpy for list and tuple repeat (#91482)Pieter Eendebak2022-07-261-42/+31
| | | | | | | * Add _Py_memory_repeat function to pycore_list * Add _Py_RefcntAdd function to pycore_object * Use the new functions in tuplerepeat, list_repeat, and list_inplace_repeat
* gh-95173: Revert commit 51ed2c56a1852cd6b09c85ba81312dc9782772ce (#95176)Pablo Galindo Salgado2022-07-241-64/+13
|
* GH-91432: Specialize FOR_ITER (GH-91713)Dennis Sweeney2022-06-211-23/+17
| | | | | * Adds FOR_ITER_LIST and FOR_ITER_RANGE specializations. * Adds _PyLong_AssignValue() internal function to avoid temporary boxing of ints.
* gh-92914: Round the allocated size for lists up to the even number (GH-92915)Serhiy Storchaka2022-05-191-0/+6
|
* Issues/88027: A potential double free in list_sort_impl (#92367)Tim Peters2022-05-061-1/+3
| | | merge_freemem(): set keys to NULL do it's harmless to call this again.
* Add more stats for freelist use and allocations. (GH-92211)Mark Shannon2022-05-031-0/+2
|
* bpo-47009: Streamline list.append for the common case (GH-31864)Dennis Sweeney2022-04-011-18/+18
|
* bpo-39829: Fix `__len__()` is called twice in list() constructor (GH-31816)Crowthebird2022-03-141-17/+12
|
* bpo-46765: Replace Locally Cached Strings with Statically Initialized ↵Eric Snow2022-02-231-19/+4
| | | | | Objects (gh-31366) https://bugs.python.org/issue46765
* bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow2022-02-081-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | global objects. (gh-30928) We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code. It is still used in a number of non-builtin stdlib modules. The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime. A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings). https://bugs.python.org/issue46541#msg411799 explains the rationale for this change. The core of the change is in: * (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros * Include/internal/pycore_runtime_init.h - added the static initializers for the global strings * Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState * Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings. That check is added to the PR CI config. The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()). This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *. The following are not changed (yet): * stop using _Py_IDENTIFIER() in the stdlib modules * (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API * (maybe) intern the strings during runtime init https://bugs.python.org/issue46541
* bpo-46417: _PyList_Fini() clears indexerr (GH-30815)Victor Stinner2022-01-231-2/+6
| | | _PyList_Fini() now clears the 'indexerr' error message.
* bpo-46417: Use _PyType_CAST() in Objects directory (GH-30764)Victor Stinner2022-01-211-2/+1
|
* bpo-46235: Do all ref-counting at once during list/tuple multiplication ↵Dennis Sweeney2022-01-081-17/+22
| | | | | | | | | | (GH-30346) When multiplying lists and tuples by `n`, increment each element's refcount, by `n`, just once. Saves `n-1` increments per element, and allows for a leaner & faster copying loop. Code by sweeneyde (Dennis Sweeney).
* bpo-46008: Make runtime-global object/type lifecycle functions and state ↵Eric Snow2021-12-091-0/+1
| | | | | | | | | | | | consistent. (gh-29998) This change is strictly renames and moving code around. It helps in the following ways: * ensures type-related init functions focus strictly on one of the three aspects (state, objects, types) * passes in PyInterpreterState * to all those functions, simplifying work on moving types/objects/state to the interpreter * consistent naming conventions help make what's going on more clear * keeping API related to a type in the corresponding header file makes it more obvious where to look for it https://bugs.python.org/issue46008
* bpo-45723: Prepare support for autoconf 2.71 (GH-29441)Christian Heimes2021-11-081-5/+0
|
* bpo-45530: speed listobject.c's unsafe_tuple_compare() (GH-29076)Tim Peters2021-10-251-13/+64
| | | | | | | | Keep track of whether unsafe_tuple_compare() calls are resolved by the very first tuple elements, and adjust strategy accordingly. This can significantly cut the number of calls made to the full-blown PyObject_RichCompareBool(), and especially when duplicates are rare. Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-45522: Allow to disable freelists on build time (GH-29056)Christian Heimes2021-10-211-6/+18
| | | | | | | | Freelists for object structs can now be disabled. A new ``configure`` option ``--without-freelists`` can be used to disable all freelists except empty tuple singleton. Internal Py*_MAXFREELIST macros can now be defined as 0 without causing compiler warnings and segfaults. Signed-off-by: Christian Heimes <christian@python.org>
* Fix typos in the Objects directory (GH-28766)Christian Clauss2021-10-061-2/+2
|
* Clean up initialization __class_getitem__ with Py_GenericAlias. (GH-28450)Serhiy Storchaka2021-09-191-1/+1
| | | | | The cast to PyCFunction is redundant. Overuse of redundant casts can hide actual bugs.
* bpo-34561: Switch to Munro & Wild "powersort" merge strategy. (#28108)Tim Peters2021-09-061-33/+79
| | | | | For list.sort(), replace our ad hoc merge ordering strategy with the principled, elegant, and provably near-optimal one from Munro and Wild's "powersort".
* bpo-44707: Fix an undefined behavior of the null pointer arithmetic (GH-27292)Serhiy Storchaka2021-07-291-2/+9
|
* bpo-43977: Use tp_flags for collection matching (GH-25723)Mark Shannon2021-04-301-1/+1
| | | | | | | | | | | | | * Add Py_TPFLAGS_SEQUENCE and Py_TPFLAGS_MAPPING, add to all relevant standard builtin classes. * Set relevant flags on collections.abc.Sequence and Mapping. * Use flags in MATCH_SEQUENCE and MATCH_MAPPING opcodes. * Inherit Py_TPFLAGS_SEQUENCE and Py_TPFLAGS_MAPPING. * Add NEWS * Remove interpreter-state map_abc and seq_abc fields.
* bpo-42128: Structural Pattern Matching (PEP 634) (GH-22917)Brandt Bucher2021-02-261-1/+2
| | | | | Co-authored-by: Guido van Rossum <guido@python.org> Co-authored-by: Talin <viridia@gmail.com> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* bpo-43268: Pass interp rather than tstate to internal functions (GH-24580)Victor Stinner2021-02-191-5/+5
| | | | | | | | | | | | | | | Pass the current interpreter (interp) rather than the current Python thread state (tstate) to internal functions which only use the interpreter. Modified functions: * _PyXXX_Fini() and _PyXXX_ClearFreeList() functions * _PyEval_SignalAsyncExc(), make_pending_calls() * _PySys_GetObject(), sys_set_object(), sys_set_object_id(), sys_set_object_str() * should_audit(), set_flags_from_config(), make_flags() * _PyAtExit_Call() * init_stdio_encoding() * etc.
* bpo-42519: Replace PyMem_MALLOC() with PyMem_Malloc() (GH-23586)Victor Stinner2020-12-011-12/+12
| | | | | | | | | | | No longer use deprecated aliases to functions: * Replace PyMem_MALLOC() with PyMem_Malloc() * Replace PyMem_REALLOC() with PyMem_Realloc() * Replace PyMem_FREE() with PyMem_Free() * Replace PyMem_Del() with PyMem_Free() * Replace PyMem_DEL() with PyMem_Free() Modify also the PyMem_DEL() macro to use directly PyMem_Free().
* Fix typo in Object/listobject.c (GH-21079)Jeong Ukjae2020-06-291-1/+1
|
* bpo-40521: Cleanup code of free lists (GH-21082)Victor Stinner2020-06-231-6/+12
| | | Add get_xxx_state() function to factorize duplicated code.
* bpo-41078: Rename pycore_tupleobject.h to pycore_tuple.h (GH-21056)Victor Stinner2020-06-221-4/+4
|
* bpo-40887: Don't use finalized free lists (GH-20700)Victor Stinner2020-06-081-0/+12
| | | | | | In debug mode, ensure that free lists are no longer used after being finalized. Set numfree to -1 in finalization functions (eg. _PyList_Fini()), and then check that numfree is not equal to -1 before using a free list (e.g list_dealloc()).
* bpo-40521: Make list free list per-interpreter (GH-20642)Victor Stinner2020-06-051-31/+29
| | | | | | | | | | | | Each interpreter now has its own list free list: * Move list numfree and free_list into PyInterpreterState. * Add _Py_list_state structure. * Add tstate parameter to _PyList_ClearFreeList() and _PyList_Fini(). * Remove "#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS". * _PyGC_Fini() clears gcstate->garbage list which can be stored in the list free list. Call _PyGC_Fini() before _PyList_Fini() to prevent leaking this list.
* bpo-34397: Remove redundant overflow checks in list and tuple ↵Sergey Fedoseev2020-05-251-13/+3
| | | | implementation. (GH-8757)
* bpo-40521: Disable list free list in subinterpreters (GH-19959)Victor Stinner2020-05-061-1/+8
| | | | | | When Python is built with experimental isolated interpreters, disable the list free list. Temporary workaround until this cache is made per-interpreter.
* bpo-40428: Remove PyTuple_ClearFreeList() function (GH-19769)Victor Stinner2020-04-291-7/+4
| | | | | | | | | | | | | | | | | | | Remove the following function from the C API: * PyAsyncGen_ClearFreeLists() * PyContext_ClearFreeList() * PyDict_ClearFreeList() * PyFloat_ClearFreeList() * PyFrame_ClearFreeList() * PyList_ClearFreeList() * PySet_ClearFreeList() * PyTuple_ClearFreeList() Make these functions private, move them to the internal C API and change their return type to void. Call explicitly PyGC_Collect() to free all free lists. Note: PySet_ClearFreeList() did nothing.
* bpo-40268: Remove a few pycore_pystate.h includes (GH-19510)Victor Stinner2020-04-141-1/+0
|
* bpo-40170: Add _PyIndex_Check() internal function (GH-19426)Victor Stinner2020-04-081-2/+3
| | | | | | | | | Add _PyIndex_Check() function to the internal C API: fast inlined verson of PyIndex_Check(). Add Include/internal/pycore_abstract.h header file. Replace PyIndex_Check() with _PyIndex_Check() in C files of Objects and Python subdirectories.
* bpo-39481: Implementation for PEP 585 (#18239)Guido van Rossum2020-04-071-0/+1
| | | | | | | | | | | | This implements things like `list[int]`, which returns an object of type `types.GenericAlias`. This object mostly acts as a proxy for `list`, but has attributes `__origin__` and `__args__` that allow recovering the parts (with values `list` and `(int,)`. There is also an approximate notion of type variables; e.g. `list[T]` has a `__parameters__` attribute equal to `(T,)`. Type variables are objects of type `typing.TypeVar`.
* bpo-37207: Use vectorcall for list() (GH-18928)Petr Viktorin2020-03-301-0/+28
| | | | | | | Speed up calls to list() by using the PEP 590 vectorcall calling convention. Patch by Mark Shannon. Co-authored-by: Mark Shannon <mark@hotpy.org> Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
* bpo-38373: Change list overallocating strategy. (GH-18952)Serhiy Storchaka2020-03-171-6/+8
| | | | | * Add padding to make the allocated size multiple of 4. * Do not overallocate if the new size is closer to overalocated size than to the old size.
* bpo-39573: Finish converting to new Py_IS_TYPE() macro (GH-18601)Andy Lester2020-03-041-11/+11
|