summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-127563: use `dk_log2_index_bytes=3` in empty dicts (GH-127568)Bénédikt Tran2024-12-101-1/+4
| | | | This fixes a UBSan failure (unaligned zero-size memcpy) in `dictobject.c`.
* gh-126491: Revert "GH-126491: Lower heap size limit with faster marking ↵Petr Viktorin2024-12-101-1/+3
| | | | | | | | (GH-127519)" (GH-127770) Revert "GH-126491: Lower heap size limit with faster marking (GH-127519)" This reverts commit 023b7d2141467017abc27de864f3f44677768cb3, which introduced a refleak.
* GH-126491: Lower heap size limit with faster marking (GH-127519)Mark Shannon2024-12-061-3/+1
| | | | | | | * Faster marking of reachable objects * Changes calculation of work to do and work done. * Merges transitive closure calculations
* gh-127582: Make object resurrection thread-safe for free threading. (GH-127612)Sam Gross2024-12-051-5/+2
| | | | | | | | | | | | Objects may be temporarily "resurrected" in destructors when calling finalizers or watcher callbacks. We previously undid the resurrection by decrementing the reference count using `Py_SET_REFCNT`. This was not thread-safe because other threads might be accessing the object (modifying its reference count) if it was exposed by the finalizer, watcher callback, or temporarily accessed by a racy dictionary or list access. This adds internal-only thread-safe functions for temporary object resurrection during destructors.
* gh-127316: fix incorrect assertion in setting `__class__` in free-threading ↵Kumar Aditya2024-11-291-1/+1
| | | | (#127399)
* gh-115999: Specialize `LOAD_GLOBAL` in free-threaded builds (#126607)mpage2024-11-211-10/+58
| | | | | | | | | | | | | | Enable specialization of LOAD_GLOBAL in free-threaded builds. Thread-safety of specialization in free-threaded builds is provided by the following: A critical section is held on both the globals and builtins objects during specialization. This ensures we get an atomic view of both builtins and globals during specialization. Generation of new keys versions is made atomic in free-threaded builds. Existing helpers are used to atomically modify the opcode. Thread-safety of specialized instructions in free-threaded builds is provided by the following: Relaxed atomics are used when loading and storing dict keys versions. This avoids potential data races as the dict keys versions are read without holding the dictionary's per-object lock in version guards. Dicts keys objects are passed from keys version guards to the downstream uops. This ensures that we are loading from the correct offset in the keys object. Once a unicode key has been stored in a keys object for a combined dictionary in free-threaded builds, the offset that it is stored in will never be reused for a different key. Once the version guard passes, we know that we are reading from the correct offset. The dictionary read fast-path is used to read values from the dictionary once we know the correct offset.
* gh-124470: Fix crash when reading from object instance dictionary while ↵Dino Viehland2024-11-211-32/+132
| | | | | replacing it (#122489) Delay free a dictionary when replacing it
* GH-127010: Don't lazily track and untrack dicts (GH-127027)Mark Shannon2024-11-201-92/+19
|
* Revert "GH-126491: GC: Mark objects reachable from roots before doing cycle ↵Hugo van Kemenade2024-11-191-19/+96
| | | | collection (GH-126502)" (#126983)
* GH-126491: GC: Mark objects reachable from roots before doing cycle ↵Mark Shannon2024-11-181-96/+19
| | | | | | | | | | | | | | | | collection (GH-126502) * Mark almost all reachable objects before doing collection phase * Add stats for objects marked * Visit new frames before each increment * Remove lazy dict tracking * Update docs * Clearer calculation of work to do.
* GH-126547: Pre-assign version numbers for a few common classes (GH-126551)Mark Shannon2024-11-081-0/+1
|
* gh-116938: Fix `dict.update` docstring and remove erraneous full stop from ↵Prometheus33752024-10-291-2/+2
| | | | | `dict` documentation (#125421) Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
* gh-124218: Avoid refcount contention on builtins module (GH-125847)Sam Gross2024-10-241-0/+34
| | | | | | | This replaces `_PyEval_BuiltinsFromGlobals` with `_PyDict_LoadBuiltinsFromGlobals`, which returns a new reference instead of a borrowed reference. Internally, the new function uses per-thread reference counting when possible to avoid contention on the refcount fields on the builtins module.
* fix grammar in comment in dictobject.c (#125822)Arjun Singh2024-10-221-1/+1
|
* gh-124218: Use per-thread reference counting for globals and builtins (#125713)Sam Gross2024-10-211-0/+18
| | | | Use per-thread refcounting for the reference from function objects to the globals and builtins dictionaries.
* gh-125608: Trigger dictionary watchers when inline values change (#125611)Sam Gross2024-10-211-6/+15
| | | | | Dictionary watchers on an object's attributes dictionary (`object.__dict__`) were not triggered when the managed dictionary used the object's inline values.
* gh-125196: Use PyUnicodeWriter for repr(dict) (#125270)Victor Stinner2024-10-101-36/+36
|
* GH-125174: Make immortal objects more robust, following design from PEP 683 ↵Mark Shannon2024-10-101-3/+7
| | | | (GH-125251)
* gh-124296: Remove private dictionary version tag (PEP 699) (#124472)Sam Gross2024-10-011-42/+21
|
* gh-124642: Dictionaries aren't marking objects as weakref'd (#124643)Dino Viehland2024-09-301-3/+3
| | | Dictionaries aren't marking objects as weakref'd
* GH-124547: Clear instance dictionary if memory error occurs during object ↵Mark Shannon2024-09-271-2/+9
| | | | dealloc (GH-124627)
* gh-123990: Good bye WITH_FREELISTS macro (gh-124358)Donghee Na2024-09-241-2/+0
|
* gh-121459: Add missing return to _PyDict_LoadGlobalStackRef (#124085)Sam Gross2024-09-141-2/+7
| | | | | | | | We need to return immediately if there's an error during dictionary lookup. Also avoid the conditional-if operator. MSVC versions through v19.27 miscompile compound literals with side effects within a conditional operator. This caused crashes in the Windows10 buildbot.
* gh-121459: Deferred LOAD_GLOBAL (GH-123128)Ken Jin2024-09-131-0/+74
| | | | Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Sam Gross <655866+colesbury@users.noreply.github.com>
* GH-115775: Use `__static_attributes__` to initialize shared keys (GH-118468)Mark Shannon2024-08-271-1/+16
|
* gh-123083: Fix a potential use-after-free in ``STORE_ATTR_WITH_HINT`` ↵Donghee Na2024-08-221-0/+2
| | | | (gh-123092)
* gh-120974: Make asyncio `swap_current_task` safe in free-threaded build ↵Sam Gross2024-08-021-16/+38
| | | | | (#122317) * gh-120974: Make asyncio `swap_current_task` safe in free-threaded build
* gh-122208: Don't delivery PyDict_EVENT_ADDED until it can't fail (#122207)Dino Viehland2024-07-241-11/+8
| | | Don't delivery PyDict_EVENT_ADDED until it can't fail
* gh-120974: Make _asyncio._leave_task atomic in the free-threaded build (#122139)Sam Gross2024-07-231-15/+15
| | | | | | | * gh-120974: Make _asyncio._leave_task atomic in the free-threaded build Update `_PyDict_DelItemIf` to allow for an argument to be passed to the predicate.
* gh-100240: Use a consistent implementation for freelists (#121934)Sam Gross2024-07-221-84/+19
| | | | | | | | 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-121266: Remove Py_ALWAYS_INLINE in dictobject.c (#121493)Victor Stinner2024-07-181-3/+3
| | | | | compare_unicode_generic(), compare_unicode_unicode() and compare_generic() are callbacks used by do_lookup(). When enabling assertions, it's not possible to inline these functions.
* gh-121266: Change dict check_lookup() return type to int (#121581)Victor Stinner2024-07-171-11/+11
|
* gh-121860: Fix crash when materializing managed dict (#121866)Sam Gross2024-07-161-5/+12
| | | | The object's inline values may be marked invalid if the materialized dict was already initialized and then deleted.
* gh-117657: Fix TSan race in _PyDict_CheckConsistency (#121551)Sam Gross2024-07-101-9/+15
| | | | The only remaining race in dictobject.c was in _PyDict_CheckConsistency when the dictionary has shared keys.
* gh-120198: Stop the world when setting __class__ on free-threaded build ↵Ken Jin2024-07-101-5/+10
| | | | (GH-120672)
* gh-117657: Fix data races reported by TSAN in some set methods (#120914)AN Long2024-07-011-84/+51
| | | | | | 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-120858: PyDict_Next should not lock the dict (#120859)Sam Gross2024-06-241-7/+1
| | | | | | | | | PyDict_Next no longer locks the dictionary in the free-threaded build. Locking around individual PyDict_Next calls is not sufficient because the function returns borrowed references and because it allows concurrent modifications during the iteraiton loop. The internal locking also interferes with correct external synchronization because it may suspend outer critical sections created by the caller.
* Fix typos in comments (#120821)Xie Yanbo2024-06-241-1/+1
|
* 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-113993: Allow interned strings to be mortal, and fix related issues ↵Petr Viktorin2024-06-211-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-120520) * Add an InternalDocs file describing how interning should work and how to use it. * Add internal functions to *explicitly* request what kind of interning is done: - `_PyUnicode_InternMortal` - `_PyUnicode_InternImmortal` - `_PyUnicode_InternStatic` * Switch uses of `PyUnicode_InternInPlace` to those. * Disallow using `_Py_SetImmortal` on strings directly. You should use `_PyUnicode_InternImmortal` instead: - Strings should be interned before immortalization, otherwise you're possibly interning a immortalizing copy. - `_Py_SetImmortal` doesn't handle the `SSTATE_INTERNED_MORTAL` to `SSTATE_INTERNED_IMMORTAL` update, and those flags can't be changed in backports, as they are now part of public API and version-specific ABI. * Add private `_only_immortal` argument for `sys.getunicodeinternedsize`, used in refleak test machinery. * Make sure the statically allocated string singletons are unique. This means these sets are now disjoint: - `_Py_ID` - `_Py_STR` (including the empty string) - one-character latin-1 singletons Now, when you intern a singleton, that exact singleton will be interned. * Add a `_Py_LATIN1_CHR` macro, use it instead of `_Py_ID`/`_Py_STR` for one-character latin-1 singletons everywhere (including Clinic). * Intern `_Py_STR` singletons at startup. * For free-threaded builds, intern `_Py_LATIN1_CHR` singletons at startup. * Beef up the tests. Cover internal details (marked with `@cpython_only`). * Add lots of assertions Co-Authored-By: Eric Snow <ericsnowcurrently@gmail.com>
* gh-83754: Use the Py_TYPE() macro (#120599)Victor Stinner2024-06-171-1/+1
| | | | Don't access directly PyObject.ob_type, but use the Py_TYPE() macro instead.
* gh-112075: Fix dict thread safety issues (#119288)Germán Méndez Bravo2024-05-241-25/+41
| | | Fix dict thread safety issues
* gh-117657: Fix missing atomic in dict_resize (#119312)Dino Viehland2024-05-221-1/+1
| | | Fix missing atomic in dict_resize
* gh-118849: Fix "code will never be executed" warning in `dictobject.c` (#118850)Nikita Sobolev2024-05-091-1/+1
|
* gh-112075: Fix race in constructing dict for instance (#118499)Dino Viehland2024-05-061-69/+71
|
* gh-118362: Fix thread safety around lookups from the type cache in the face ↵Dino Viehland2024-05-061-11/+39
| | | | | | | 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-118331: Handle errors in _PyObject_SetManagedDict (#118334)Sam Gross2024-04-291-11/+18
| | | | | When detaching a dict, the `copy_values` call may fail due to out-of-memory errors. This can be triggered by test_no_memory in test_repl.
* gh-112075: _Py_dict_lookup needs to lock shared keys (#117528)Dino Viehland2024-04-251-127/+158
| | | | | Lock shared keys in `Py_dict_lookup` and use thread-safe lookup in `insertdict` Co-authored-by: Sam Gross <colesbury@gmail.com>
* gh-117657: Fixes a few small TSAN issues in dictobject (#118200)Dino Viehland2024-04-251-11/+14
| | | | Fixup TSAN errors for dict
* gh-112075: Make instance attributes stored in inline "dict" thread safe ↵Dino Viehland2024-04-221-70/+315
| | | | | (#114742) Make instance attributes stored in inline "dict" thread safe on free-threaded builds