summaryrefslogtreecommitdiffstats
path: root/Modules/_collectionsmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-118362: Fix thread safety around lookups from the type cache in the face ↵Dino Viehland2024-05-061-2/+4
| | | | | | | of concurrent mutators (#118454) Add _PyType_LookupRef and use incref before setting attribute on type Makes setting an attribute on a class and signaling type modified atomic Avoid adding re-entrancy exposing the type cache in an inconsistent state by decrefing after type is updated
* gh-116322: Add Py_mod_gil module slot (#116882)Brett Simmers2024-05-031-0/+1
| | | | | | | | | | | | | | 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).
* gh-112050: Make collections.deque thread-safe in free-threaded builds (#113830)mpage2024-02-151-53/+186
| | | | | | | Use critical sections to make deque methods that operate on mutable state thread-safe when the GIL is disabled. This is mostly accomplished by using the @critical_section Argument Clinic directive, though there are a few places where this was not possible and critical sections had to be manually acquired/released.
* gh-115243: Fix crash in deque.index() when the deque is concurrently ↵kcatss2024-02-141-1/+2
| | | | modified (GH-115247)
* gh-112050: Adapt collections.deque to Argument Clinic (#113963)mpage2024-01-291-151/+261
|
* gh-106320: Remove private _PyDict functions (#108449)Victor Stinner2023-08-241-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Move private functions to the internal C API (pycore_dict.h): * _PyDictView_Intersect() * _PyDictView_New() * _PyDict_ContainsId() * _PyDict_DelItemId() * _PyDict_DelItem_KnownHash() * _PyDict_GetItemIdWithError() * _PyDict_GetItem_KnownHash() * _PyDict_HasSplitTable() * _PyDict_NewPresized() * _PyDict_Next() * _PyDict_Pop() * _PyDict_SetItemId() * _PyDict_SetItem_KnownHash() * _PyDict_SizeOf() No longer export most of these functions. Move also the _PyDictViewObject structure to the internal C API. Move dict_getitem_knownhash() function from _testcapi to the _testinternalcapi extension. Update test_capi.test_dict for this change.
* gh-106869: Use new PyMemberDef constant names (#106871)Victor Stinner2023-07-251-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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)
* gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205)Eric Snow2023-05-051-0/+1
| | | 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).
* gh-103092: Isolate `_collections` (#103093)Erlend E. Aasland2023-04-121-276/+279
| | | Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* GH-100989: remove annotation from docstring (GH-102991)Raymond Hettinger2023-03-241-2/+2
|
* GH-100989: Revert Improve the accuracy of collections.deque docstrings ↵Raymond Hettinger2023-03-241-24/+13
| | | | (GH-102979)
* gh-100989: Improve the accuracy of collections.deque docstrings (#100990)Timo Ludwig2023-03-221-13/+24
| | | Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
* gh-99845: Use size_t type in __sizeof__() methods (#99846)Victor Stinner2022-11-301-7/+5
| | | | | | | | 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-99537: Use Py_SETREF() function in C code (#99656)Victor Stinner2022-11-221-4/+1
| | | | | | | | | | | | | | | 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.
* gh-99300: Use Py_NewRef() in Modules/ directory (#99466)Victor Stinner2022-11-141-40/+20
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in test C files of the Modules/ directory.
* gh-91320: Use _PyCFunction_CAST() (#92251)Victor Stinner2022-05-031-3/+3
| | | | | | | | | | Replace "(PyCFunction)(void(*)(void))func" cast with _PyCFunction_CAST(func). Change generated by the command: sed -i -e \ 's!(PyCFunction)(void(\*)(void)) *\([A-Za-z0-9_]\+\)!_PyCFunction_CAST(\1)!g' \ $(find -name "*.c")
* Remove micro-optimization that no longer shows a benefit. (GH-32397)Raymond Hettinger2022-04-071-21/+1
|
* bpo-26579: Add object.__getstate__(). (GH-2821)Serhiy Storchaka2022-04-061-9/+6
| | | | | | | Copying and pickling instances of subclasses of builtin types bytearray, set, frozenset, collections.OrderedDict, collections.deque, weakref.WeakSet, and datetime.tzinfo now copies and pickles instance attributes implemented as slots.
* bpo-47164: Add _PyASCIIObject_CAST() macro (GH-32191)Victor Stinner2022-03-311-1/+1
| | | | | | | | | | | | Add macros to cast objects to PyASCIIObject*, PyCompactUnicodeObject* and PyUnicodeObject*: _PyASCIIObject_CAST(), _PyCompactUnicodeObject_CAST() and _PyUnicodeObject_CAST(). Using these new macros make the code more readable and check their argument with: assert(PyUnicode_Check(op)). Remove redundant assert(PyUnicode_Check(op)) in macros using directly or indirectly these new CAST macros. Replacing existing casts with these macros.
* bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow2022-02-081-11/+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-45723: Prepare support for autoconf 2.71 (GH-29441)Christian Heimes2021-11-081-5/+0
|
* bpo-45439: Move _PyObject_CallNoArgs() to pycore_call.h (GH-28895)Victor Stinner2021-10-121-0/+1
| | | | | | | * Move _PyObject_CallNoArgs() to pycore_call.h (internal C API). * _ssl, _sqlite and _testcapi extensions now call the public PyObject_CallNoArgs() function, rather than _PyObject_CallNoArgs(). * _lsprof extension is now built with Py_BUILD_CORE_MODULE macro defined to get access to internal _PyObject_CallNoArgs().
* bpo-45439: Rename _PyObject_CallNoArg() to _PyObject_CallNoArgs() (GH-28891)Victor Stinner2021-10-111-1/+1
| | | | | Fix typo in the private _PyObject_CallNoArg() function name: rename it to _PyObject_CallNoArgs() to be consistent with the public function PyObject_CallNoArgs().
* Clean up initialization __class_getitem__ with Py_GenericAlias. (GH-28450)Serhiy Storchaka2021-09-191-2/+2
| | | | | The cast to PyCFunction is redundant. Overuse of redundant casts can hide actual bugs.
* bpo-41621: Document defaultdict's default_factory parameter (GH-21945)Dennis Sweeney2021-06-221-1/+1
| | | It defaults to None and is positional only.
* bpo-40521: Convert deque freelist from global vars to instance vars (GH-25906)Raymond Hettinger2021-05-051-27/+32
|
* bpo-43977: Use tp_flags for collection matching (GH-25723)Mark Shannon2021-04-301-1/+2
| | | | | | | | | | | | | * 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.
* Revert "bpo-40521: Remove freelist from collections.deque() (GH-21073)" ↵Raymond Hettinger2021-03-251-2/+21
| | | | | | | | (GH-24944) This reverts commit 32f2eda85957365d208f499b730d30b7eb419741. It can be re-applied if the subinterpreter PEP is approved. Otherwise, the commit degraded performance with no offsetting benefit.
* bpo-41361: Optimized argument parsing for deque_rotate (GH-24796)Dennis Sweeney2021-03-161-1/+12
|
* bpo-25246: Optimize deque.remove() (GH-23898)Raymond Hettinger2020-12-231-32/+42
|
* bpo-42161: Micro-optimize _collections._count_elements() (GH-23008)Victor Stinner2020-10-271-4/+5
| | | Move the _PyLong_GetOne() call outside the fast-path loop.
* bpo-42161: Modules/ uses _PyLong_GetZero() and _PyLong_GetOne() (GH-22998)Victor Stinner2020-10-271-4/+7
| | | | | | Use _PyLong_GetZero() and _PyLong_GetOne() in Modules/ directory. _cursesmodule.c and zoneinfo.c are now built with Py_BUILD_CORE_MODULE macro defined.
* bpo-40521: Remove freelist from collections.deque() (GH-21073)Raymond Hettinger2020-06-231-21/+2
|
* bpo-40277: Add a repr() to namedtuple's _tuplegetter to aid with ↵Ammar Askar2020-04-151-1/+9
| | | | introspection (GH-19537)
* bpo-40268: Remove unused structmember.h includes (GH-19530)Victor Stinner2020-04-151-2/+2
| | | | | | If only offsetof() is needed: include stddef.h instead. When structmember.h is used, add a comment explaining that PyMemberDef is used.
* bpo-39481: Implementation for PEP 585 (#18239)Guido van Rossum2020-04-071-0/+4
| | | | | | | | | | | | 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-40024: Add PyModule_AddType() helper function (GH-19088)Dong-hee Na2020-03-221-11/+3
|
* bpo-1635741: Port _collections module to multiphase initialization (GH-19074)Dong-hee Na2020-03-191-42/+42
|
* Simplify defaultdict.__or__ (#18931)Brandt Bucher2020-03-121-5/+1
|
* bpo-36144: Implement defaultdict union (GH-18729)Brandt Bucher2020-03-061-6/+45
| | | For PEP 585 (this isn't in the PEP but is an obvious follow-up).
* bpo-39573: Finish converting to new Py_IS_TYPE() macro (GH-18601)Andy Lester2020-03-041-1/+1
|
* bpo-39245: Switch to public API for Vectorcall (GH-18460)Petr Viktorin2020-02-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The bulk of this patch was generated automatically with: for name in \ PyObject_Vectorcall \ Py_TPFLAGS_HAVE_VECTORCALL \ PyObject_VectorcallMethod \ PyVectorcall_Function \ PyObject_CallOneArg \ PyObject_CallMethodNoArgs \ PyObject_CallMethodOneArg \ ; do echo $name git grep -lwz _$name | xargs -0 sed -i "s/\b_$name\b/$name/g" done old=_PyObject_FastCallDict new=PyObject_VectorcallDict git grep -lwz $old | xargs -0 sed -i "s/\b$old\b/$new/g" and then cleaned up: - Revert changes to in docs & news - Revert changes to backcompat defines in headers - Nudge misaligned comments
* bpo-39590: make deque.__contains__ and deque.count hold strong references ↵sweeneyde2020-02-091-0/+4
| | | | (GH-18421)
* bpo-39573: Use Py_SET_SIZE() function (GH-18402)Victor Stinner2020-02-071-8/+8
| | | | Replace direct acccess to PyVarObject.ob_size with usage of the Py_SET_SIZE() function.
* bpo-39573: Use Py_TYPE() macro in Modules directory (GH-18393)Victor Stinner2020-02-071-2/+2
| | | Replace direct access to PyObject.ob_type with Py_TYPE().
* bpo-37337: Add _PyObject_CallMethodNoArgs() (GH-14267)Jeroen Demeyer2019-07-081-1/+1
|
* bpo-37493: use _PyObject_CallNoArg in more places (GH-14575)Jeroen Demeyer2019-07-041-1/+1
|
* bpo-37483: add _PyObject_CallOneArg() function (#14558)Jeroen Demeyer2019-07-041-2/+1
|
* bpo-37165: Convert _count_elements to the argument clinic (GH-13848)Raymond Hettinger2019-06-051-11/+16
|
* bpo-36974: tp_print -> tp_vectorcall_offset and tp_reserved -> tp_as_async ↵Jeroen Demeyer2019-05-311-10/+10
| | | | | | | | | (GH-13464) Automatically replace tp_print -> tp_vectorcall_offset tp_compare -> tp_as_async tp_reserved -> tp_as_async