| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
| |
This fixes a crash in `_PyObject_TryGetInstanceAttribute` due to the use
of `_PyDictKeys_StringLookup` on an unlocked dictionary that may be
concurrently modified.
The underlying bug was already fixed in 3.14 and the main branch.
(partially cherry picked from commit 1b15c89a17ca3de6b05de5379b8717e9738c51ef)
|
| |
|
|
| |
(GH-133617)
|
| |
|
| |
(cherry picked from commit 92337f666e8a076a68305a8d6dc8bc9c095000e9)
|
| |
|
|
|
|
|
|
|
|
|
| |
(gh-133686)
The function `dict_set_fromkeys()` adds elements of a set to an existing
dictionary. The size of the expanded dictionary was estimated with
`PySet_GET_SIZE(iterable)`, which did not take into account the size of the
existing dictionary.
(cherry picked from commit 421ba589d02b53131f793889d221ef3b1f1410a4)
Co-authored-by: Angela Liss <59097311+angela-tarantula@users.noreply.github.com>
|
| |
|
|
|
|
|
| |
The clearing of the key, hash, and value need to use atomic operations
to avoid a data race with concurrent read operations.
(cherry picked from commit c00ac578241b3213ceb79c1f32bc83ea471f02da)
Co-authored-by: Sam Gross <colesbury@gmail.com>
|
| |
|
|
|
|
|
|
| |
(gh-130778) (gh-130833)
gh-130547: Fix race between dict_dealloc and split_keys_entry_added (gh-130778)
(cherry picked from commit 80e6d3ec4972220587c8b883161311a49ea8d0ff)
Co-authored-by: Donghee Na <donghee.na@python.org>
|
| |
|
|
|
|
| |
Found while running `test_load_attr_module` from `test_opcache` under TSan.
(cherry picked from commit 34379d0a593e5a76e2f754cdd7fccb79f25a4613)
Co-authored-by: Sam Gross <colesbury@gmail.com>
|
| |
|
|
|
|
|
|
| |
(GH-127798)
This fixes a UBSan failure (unaligned zero-size memcpy) in `dictobject.c`.
(cherry picked from commit 9af96f440618304e7cc609c246e1f8c8b2d7a119)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
(GH-127612) (GH-127659)
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.
(cherry picked from commit f4f530804b9d8f089eba0f157ec2144c03b13651)
|
| |
|
|
|
|
|
|
| |
free-threading (GH-127399) (#127422)
gh-127316: fix incorrect assertion in setting `__class__` in free-threading (GH-127399)
(cherry picked from commit 45c5cba318a19dda3ee6f9fc84781cc7a2fbde80)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
|
| |
|
|
|
|
|
|
|
| |
from `dict` documentation (GH-125421) (#126150)
gh-116938: Fix `dict.update` docstring and remove erraneous full stop from `dict` documentation (GH-125421)
(cherry picked from commit 5527c4051c0b58218ce69044f92b45f1d66ed43f)
Co-authored-by: Prometheus3375 <35541026+Prometheus3375@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
|
| |
|
|
|
|
|
|
|
|
| |
(GH-125611) (GH-125982)
Dictionary watchers on an object's attributes dictionary
(`object.__dict__`) were not triggered when the managed dictionary used
the object's inline values.
(cherry picked from commit 5989eb74463c26780632f17f221d6bf4c9372a01)
Co-authored-by: Sam Gross <colesbury@gmail.com>
|
| |
|
|
|
|
|
|
|
|
| |
(GH-124643) (#124798)
gh-124642: Dictionaries aren't marking objects as weakref'd (GH-124643)
Dictionaries aren't marking objects as weakref'd
(cherry picked from commit 077e7ef6a0abbf9e04b9aa11b4f621031004c31f)
Co-authored-by: Dino Viehland <dinoviehland@meta.com>
|
| |
|
|
|
|
|
|
| |
object dealloc (GH-124627) (#124714)
GH-124547: Clear instance dictionary if memory error occurs during object dealloc (GH-124627)
(cherry picked from commit 0e21cc6cf820679439d72e3ebd06227ee2a085f9)
Co-authored-by: Mark Shannon <mark@hotpy.org>
|
| |
|
|
|
|
| |
(#123235)
[3.13] gh-123083: Fix a potential use-after-free in ``STORE_ATTR_WITH_HINT`` (gh-123092)
(cherry picked from commit 297f2e093ec95800ae2184330b8408c875523467)
|
| |
|
|
|
|
|
|
|
|
| |
build (GH-122317) (#122612)
gh-120974: Make asyncio `swap_current_task` safe in free-threaded build (GH-122317)
* gh-120974: Make asyncio `swap_current_task` safe in free-threaded build
(cherry picked from commit b5e6fb39a246bf7ee470d58632cdf588bb9d0298)
Co-authored-by: Sam Gross <colesbury@gmail.com>
|
| |
|
|
|
| |
(#122326)
Don't delivery PyDict_EVENT_ADDED until it can't fail
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
build (GH-122139) (#122186)
gh-120974: Make _asyncio._leave_task atomic in the free-threaded build (GH-122139)
* 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.
(cherry picked from commit a15feded71dd47202db169613effdafc468a8cf3)
Co-authored-by: Sam Gross <colesbury@gmail.com>
|
| |
|
|
|
|
|
|
|
|
| |
gh-121266: Remove Py_ALWAYS_INLINE in dictobject.c (GH-121493)
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.
(cherry picked from commit c5a6b9afd82cad3f6abd9dc71cd5fdd5781a53f5)
Co-authored-by: Victor Stinner <vstinner@python.org>
|
| |
|
|
|
|
|
|
| |
(#121949)
gh-121266: Change dict check_lookup() return type to int (GH-121581)
(cherry picked from commit 51da3dfbf3782ad678624e720ec3fc8dfff27d16)
Co-authored-by: Victor Stinner <vstinner@python.org>
|
| |
|
|
|
|
|
|
|
| |
(#121867)
The object's inline values may be marked invalid if the materialized
dict was already initialized and then deleted.
(cherry picked from commit 162b41f57757c1df40eb377985e2e877fb0f0ea3)
Co-authored-by: Sam Gross <colesbury@gmail.com>
|
| |
|
|
|
| |
build (#121591)
(cherry-picked from commit 3bfc9c8)
|
| |
|
|
|
|
|
|
|
| |
(#121590)
The only remaining race in dictobject.c was in _PyDict_CheckConsistency
when the dictionary has shared keys.
(cherry picked from commit 3ec719fabf936ea7a012a76445b860759155de86)
Co-authored-by: Sam Gross <colesbury@gmail.com>
|
| |
|
|
|
| |
(cherry picked from commit f0ed1863bd7a0b9d021fb59e156663a7ec553f0e)
Co-authored-by: Germán Méndez Bravo <kronuz@fb.com>
|
| |
|
|
|
|
|
|
|
|
|
| |
(GH-120914) (#121240)
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.
(cherry picked from commit 294e72496439da984cb8dba9100d3613c8cc8a6d)
Co-authored-by: AN Long <aisk@users.noreply.github.com>
|
| |
|
|
|
|
|
|
|
|
|
|
| |
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.
(cherry picked from commit 375b723d5873f948696c7e85a97f4778d9e00ff0)
Co-authored-by: Sam Gross <colesbury@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
issues (GH-120520) (GH-120945)
* 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>
|
| |
|
|
|
|
|
|
|
|
|
| |
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.
(cherry picked from commit 8f17d69b7bc906e8407095317842cc0fd52cd84a)
|
| |
|
|
|
|
|
|
| |
gh-117657: Fix missing atomic in dict_resize (GH-119312)
Fix missing atomic in dict_resize
(cherry picked from commit 2b3fb767bea1f96c9e0523f6cc341b40f0fa1ca1)
Co-authored-by: Dino Viehland <dinoviehland@meta.com>
|
| |
|
|
|
|
|
|
| |
`dictobject.c` (GH-118850) (#118859)
gh-118849: Fix "code will never be executed" warning in `dictobject.c` (GH-118850)
(cherry picked from commit 82abe75e77129bebb3c13d807e8040f6924194f6)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
|
| | |
|
| |
|
|
|
|
|
| |
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
|
| |
|
|
|
| |
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.
|
| |
|
|
|
| |
Lock shared keys in `Py_dict_lookup` and use thread-safe lookup in `insertdict`
Co-authored-by: Sam Gross <colesbury@gmail.com>
|
| |
|
|
| |
Fixup TSAN errors for dict
|
| |
|
|
|
| |
(#114742)
Make instance attributes stored in inline "dict" thread safe on free-threaded builds
|
| | |
|
| |
|
| |
Use relaxed load to check if dictkeys are immortal
|
| | |
|
| |
|
|
| |
attached (GH-117808)
|
| | |
|
| |
|
|
|
| |
This keeps track of the per-thread total reference count operations in
PyThreadState in the free-threaded builds. The count is merged into the
interpreter's total when the thread exits.
|
| |
|
|
|
|
|
|
|
| |
Most mutable data is protected by a striped lock that is keyed on the
referenced object's address. The weakref's hash is protected using the
weakref's per-object lock.
Note that this only affects free-threaded builds. Apart from some minor
refactoring, the added code is all either gated by `ifdef`s or is a no-op
(e.g. `Py_BEGIN_CRITICAL_SECTION`).
|
| |
|
| |
Make _PyDict_LoadGlobal threadsafe
|
| |
|
|
| |
objects. (GH-116115)
|
| |
|
|
| |
(GH-116336)
|
| | |
|
| | |
|
| | |
|
| |
|
|
| |
lock-free (#115786)
|