summaryrefslogtreecommitdiffstats
path: root/Objects/setobject.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-132657: Use stronger memory ordering for so->mask. (gh-142735)Neil Schemenauer2025-12-151-5/+5
| | | | | We need to use release/acquire ordering for the 'mask' member of the set structure. Without this, `set_lookkey_threadsafe()` could be looking at the old value of `table` but the new value of `mask`.
* gh-132657: Add lock-free set contains implementation (#132290)Neil Schemenauer2025-12-131-113/+316
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This roughly follows what was done for dictobject to make a lock-free lookup operation. With this change, the set contains operation scales much better when used from multiple-threads. The frozenset contains performance seems unchanged (as already lock-free). Summary of changes: * refactor set_lookkey() into set_do_lookup() which now takes a function pointer that does the entry comparison. This is similar to dictobject and do_lookup(). In an optimized build, the comparison function is inlined and there should be no performance cost to this. * change set_do_lookup() to return a status separately from the entry value * add set_compare_frozenset() and use if the object is a frozenset. For the free-threaded build, this avoids some overhead (locking, atomic operations, incref/decref on key) * use FT_ATOMIC_* macros as needed for atomic loads and stores * use a deferred free on the set table array, if shared (only on free-threaded build, normal build always does an immediate free) * for free-threaded build, use explicit for loop to zero the table, rather than memcpy() * when mutating the set, assign so->table to NULL while the change is a happening. Assign the real table array after the change is done.
* gh-140476: optimize `PySet_Add` for `frozenset` in free-threading (#140440)Alper2025-11-111-9/+16
| | | | | Avoids critical section in `PySet_Add` when adding items to newly created frozensets. Co-authored-by: Kumar Aditya <kumaraditya@python.org>
* gh-132657: optimize `PySet_Contains` for `frozenset` (#141183)Kumar Aditya2025-11-111-1/+3
|
* gh-140061: Use `_PyObject_IsUniquelyReferenced()` to check if objects are ↵Sergey Miryanov2025-10-151-2/+2
| | | | | | | | | 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.
* gh-132657: avoid locks and refcounting in `frozenset` lookups (#136107)Pieter Eendebak2025-08-301-10/+25
|
* GH-137623: Use an AC decorator for docstring line length enforcement (#137690)Adam Turner2025-08-181-1/+2
|
* gh-135607: remove null checking of weakref list in dealloc of extension ↵Xuanteng Huang2025-06-301-2/+2
| | | | | | modules and objects (#135614) Co-authored-by: Kumar Aditya <kumaraditya@python.org> Co-authored-by: Victor Stinner <vstinner@python.org>
* GH-124715: Move trashcan mechanism into `Py_Dealloc` (GH-132280)Mark Shannon2025-04-301-2/+0
|
* gh-132825: Fix typo in dict_unhashable_type() name (#132847)Victor Stinner2025-04-231-5/+5
|
* gh-132825: Enhance unhashable error messages for dict and set (#132828)Victor Stinner2025-04-231-0/+20
|
* gh-132657: Avoid locking in frozenset.__contains__ (#132659)Pieter Eendebak2025-04-181-1/+23
|
* gh-132213: use relaxed atomics for set hash (#132215)Kumar Aditya2025-04-071-7/+9
|
* gh-132013: use relaxed atomics in hash of frozenset (#132014)Kumar Aditya2025-04-021-3/+3
| | | Use relaxed atomics in hash of `frozenset` to fix TSAN warning.
* gh-130312: SET_ADD should not lock (#130136)Dino Viehland2025-03-211-7/+22
| | | SET_ADD should not lock
* gh-111178: Fix function signatures for multiple tests (#131496)Victor Stinner2025-03-201-4/+7
|
* gh-111178: Change Argument Clinic signature for METH_O (#130682)Victor Stinner2025-03-111-10/+10
| | | Use "PyObject*" for METH_O functions to fix an undefined behavior.
* gh-129967: Fix race condition in `repr(set)` (gh-129978)Sam Gross2025-02-111-2/+11
| | | | | | | | The call to `PySequence_List()` could temporarily unlock and relock the set, allowing the items to be cleared and return the incorrect notation `{}` for a empty set (it should be `set()`). Co-authored-by: T. Wouters <thomas@python.org>
* gh-111178: Generate correct signature for most self converters (#128447)Erlend E. Aasland2025-01-201-9/+8
|
* GH-126547: Pre-assign version numbers for a few common classes (GH-126551)Mark Shannon2024-11-081-0/+2
|
* gh-122943: Rework support of var-positional parameter in Argument Clinic ↵Serhiy Storchaka2024-11-071-36/+38
| | | | | | | | | | | | | | | | | | (GH-122945) Move creation of a tuple for var-positional parameter out of _PyArg_UnpackKeywordsWithVararg(). Merge _PyArg_UnpackKeywordsWithVararg() with _PyArg_UnpackKeywords(). Add a new parameter in _PyArg_UnpackKeywords(). The "parameters" and "converters" attributes of ParseArgsCodeGen no longer contain the var-positional parameter. It is now available as the "varpos" attribute. Optimize code generation for var-positional parameter and reuse the same generating code for functions with and without keyword parameters. Add special converters for var-positional parameter. "tuple" represents it as a Python tuple and "array" represents it as a continuous array of PyObject*. "object" is a temporary alias of "tuple".
* gh-90370: Argument Clinic: avoid temporary tuple creation for varargs (#126064)Sergey B Kirpichev2024-10-311-26/+30
| | | | | | | Avoid temporary tuple creation when all arguments either positional-only or vararg. Objects/setobject.c and Modules/gcmodule.c adapted. This fixes slight performance regression for set methods, introduced by gh-115112.
* gh-124502: Remove _PyUnicode_EQ() function (#125114)Victor Stinner2024-10-091-2/+4
| | | | | | * Replace unicode_compare_eq() with unicode_eq(). * Use unicode_eq() in setobject.c. * Replace _PyUnicode_EQ() with _PyUnicode_Equal(). * Remove unicode_compare_eq() and _PyUnicode_EQ().
* gh-111178: Fix function signatures in setobject.c (#124888)Victor Stinner2024-10-021-68/+90
|
* gh-122688: Fix support of var-positional parameter in Argument Clinic ↵Serhiy Storchaka2024-08-091-12/+6
| | | | | | | | | (GH-122689) * Parameters after the var-positional parameter are now keyword-only instead of positional-or-keyword. * Correctly calculate min_kw_only. * Raise errors for invalid combinations of the var-positional parameter with "*", "/" and deprecation markers.
* gh-121795: Improve performance of set membership testing from set arguments ↵HarryLHW2024-07-221-23/+36
| | | | (#121796)
* gh-117657: Fix TSAN races in setobject.c (#121511)Sam Gross2024-07-091-8/+10
| | | | | The `used` field must be written using atomic stores because `set_len` and iterators may access the field concurrently without holding the per-object lock.
* gh-117657: Fix data races reported by TSAN in some set methods (#120914)AN Long2024-07-011-21/+9
| | | | | | Refactor the fast Unicode hash check into `_PyObject_HashFast` and use relaxed atomic loads in the free-threaded build. After this change, the TSAN doesn't report data races for this method.
* gh-118527: Intern code consts in free-threaded build (#118667)Sam Gross2024-05-071-0/+6
| | | | | | We already intern and immortalize most string constants. In the free-threaded build, other constants can be a source of reference count contention because they are shared by all threads running the same code objects.
* gh-112069: Do not require lock if the set has never been exposed. (gh-118069)Donghee Na2024-04-251-0/+7
|
* setobject: remove out of date docstring info (GH-118048)Rostyslav Lobov2024-04-191-1/+1
|
* gh-112069: Make PySet_GET_SIZE to be atomic safe. (gh-118053)Donghee Na2024-04-181-1/+0
| | | gh-112069: Make PySet_GET_SIZE to be atomic operation
* gh-112069: Add _PySet_NextEntryRef to be thread-safe. (gh-117990)Donghee Na2024-04-181-1/+17
|
* gh-112069: Make setiter_iternext to be thread-safe (gh-117935)Donghee Na2024-04-161-12/+17
|
* gh-112069: Make sets thread-safe with the GIL disabled (#113800)Tomas R2024-03-081-145/+334
| | | | | | This makes nearly all the operations on set thread-safe in the free-threaded build, with the exception of `_PySet_NextEntry` and `setiter_iternext`. Co-authored-by: Sam Gross <colesbury@gmail.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* gh-116381: Specialize CONTAINS_OP (GH-116385)Ken Jin2024-03-061-4/+4
| | | | | | | | | | | * 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-112069: Adapt set/frozenset methods to Argument Clinic (#115112)Tomas R2024-02-081-157/+259
|
* gh-112075: Add critical sections for most dict APIs (#114508)Dino Viehland2024-02-061-27/+51
| | | | | | | | | Starts adding thread safety to dict objects. Use @critical_section for APIs which are exposed via argument clinic and don't directly correlate with a public C API which needs to acquire the lock Use a _lock_held suffix for keeping changes to complicated functions simple and just wrapping them with a critical section Acquire and release the lock in an existing function where it won't be overly disruptive to the existing logic
* gh-113560: Improve docstrings for set.issubset() and set.issuperset() ↵Charlie Zhao2024-01-271-2/+10
| | | | (GH-113562)
* gh-111999: Add signatures and improve docstrings for builtins (GH-112000)Serhiy Storchaka2023-11-131-16/+32
|
* gh-110481: Implement biased reference counting (gh-110764)Sam Gross2023-10-301-4/+1
|
* gh-110525: Delete `test_c_api` method from `set` object (#110688)Nikita Sobolev2023-10-131-153/+0
|
* gh-108634: Py_TRACE_REFS uses a hash table (#108663)Victor Stinner2023-08-311-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Python built with "configure --with-trace-refs" (tracing references) is now ABI compatible with Python release build and debug build. Moreover, it now also supports the Limited API. Change Py_TRACE_REFS build: * Remove _PyObject_EXTRA_INIT macro. * The PyObject structure no longer has two extra members (_ob_prev and _ob_next). * Use a hash table (_Py_hashtable_t) to trace references (all objects): PyInterpreterState.object_state.refchain. * Py_TRACE_REFS build is now ABI compatible with release build and debug build. * Limited C API extensions can now be built with Py_TRACE_REFS: xxlimited, xxlimited_35, _testclinic_limited. * No longer rename PyModule_Create2() and PyModule_FromDefAndSpec2() functions to PyModule_Create2TraceRefs() and PyModule_FromDefAndSpec2TraceRefs(). * _Py_PrintReferenceAddresses() is now called before finalize_interp_delete() which deletes the refchain hash table. * test_tracemalloc find_trace() now also filters by size to ignore the memory allocated by _PyRefchain_Trace(). Test changes for Py_TRACE_REFS: * Add test.support.Py_TRACE_REFS constant. * Add test_sys.test_getobjects() to test sys.getobjects() function. * test_exceptions skips test_recursion_normalizing_with_no_memory() and test_memory_error_in_PyErr_PrintEx() if Python is built with Py_TRACE_REFS. * test_repl skips test_no_memory(). * test_capi skisp test_set_nomemory().
* gh-106320: Remove private _PyErr_SetKeyError() (#108607)Victor Stinner2023-08-291-0/+1
| | | | Move the private _PyErr_SetKeyError() function to the internal C API (pycore_pyerrors.h).
* 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 _PyDict C API (#107145)Victor Stinner2023-07-241-0/+1
| | | | | | | | | | | | | Move private _PyDict functions to the internal C API (pycore_dict.h): * _PyDict_Contains_KnownHash() * _PyDict_DebugMallocStats() * _PyDict_DelItemIf() * _PyDict_GetItemWithError() * _PyDict_HasOnlyStringKeys() * _PyDict_MaybeUntrack() * _PyDict_MergeEx() No longer export these functions.
* gh-106320: Move private _PySet API to the internal API (#107041)Victor Stinner2023-07-221-0/+1
| | | | | | | | * Add pycore_setobject.h header file. * Move the following API to the internal C API: * _PySet_Dummy * _PySet_NextEntry() * _PySet_Update()
* 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-84436: Implement Immortal Objects (gh-19474)Eddie Elizondo2023-04-221-2/+3
| | | | | | | | | This is the implementation of PEP683 Motivation: The PR introduces the ability to immortalize instances in CPython which bypasses reference counting. Tagging objects as immortal allows up to skip certain operations when we know that the object will be around for the entire execution of the runtime. Note that this by itself will bring a performance regression to the runtime due to the extra reference count checks. However, this brings the ability of having truly immutable objects that are useful in other contexts such as immutable data sharing between sub-interpreters.
* gh-99845: Use size_t type in __sizeof__() methods (#99846)Victor Stinner2022-11-301-6/+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).