| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
| |
(#120963)
Moves the logic to update the type's dictionary to its own function in order
to make the lock scoping more clear.
Also, ensure that `name` is decref'd on the error path.
(cherry picked from commit dee63cb35971b87a09ddda5d6f29cd941f570720)
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
remove from public API/ABI (GH-119680, GH-120955) (GH-120944)
- gh-119521: Rename IncompleteInputError to _IncompleteInputError and remove from public API/ABI (GH-119680)
(cherry picked from commit ce1064e4c9bcfd673323ad690e60f86e1ab907bb)
- gh-119521: Use `PyAPI_DATA`, not `extern`, for `_PyExc_IncompleteInputError` (GH-120955)
(cherry picked from commit ac61d58db0753a3b37de21dbc6e86b38f2a93f1b)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Petr Viktorin <encukou@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-120442) (#120826)
gh-120384: Fix array-out-of-bounds crash in `list_ass_subscript` (GH-120442)
(cherry picked from commit 8334a1b55c93068f5d243852029baa83377ff6c9)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
|
|
|
|
|
| |
(#120800)
(cherry picked from commit 3af7263037de1d0ef63b070fc7bfc2cf042eaebe)
|
|
|
|
|
| |
GH-120731. (#120748)
* Remove uses of Py_TPFLAGS_VALID_VERSION_TAG
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
(GH-118807) (#120695)
This exposes `PyUnstable_Object_ClearWeakRefsNoCallbacks` as an unstable
C-API function to provide a thread-safe mechanism for clearing weakrefs
without executing callbacks.
Some C-API extensions need to clear weakrefs without calling callbacks,
such as after running finalizers like we do in subtype_dealloc.
Previously they could use `_PyWeakref_ClearRef` on each weakref, but
that's not thread-safe in the free-threaded build.
(cherry picked from commit e8752d7b80775ec2a348cd4bf38cbe26a4a07615)
Co-authored-by: Sam Gross <colesbury@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
|
|
|
|
|
|
|
|
|
| |
_PyRuntime.types.managed_static.types[i].interp_count (gh-120657)
gh-120182 added new global state (interp_count), but didn't add thread-safety for it. This change eliminates the possible race.
(cherry picked from commit 2c66318cdc0545da37e7046533dfe74bde129d91, AKA gh-120529)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
|
|
|
|
|
|
|
|
|
|
| |
(GH-120484) (#120554)
gh-117657: Make PyType_HasFeature (exported version) atomic (GH-120484)
Make PyType_HasFeature (exported version) atomic
(cherry picked from commit 6f63dfff6f493b405f3422210a168369e1e7a35d)
Co-authored-by: Ken Jin <kenjin@python.org>
|
|
|
|
|
|
|
|
|
|
|
| |
In gh-120009 I used an atexit hook to finalize the _datetime module's static types at interpreter shutdown. However, atexit hooks are executed very early in finalization, which is a problem in the few cases where a subclass of one of those static types is still alive until the final GC collection. The static builtin types don't have this probably because they are finalized toward the end, after the final GC collection. To avoid the problem for _datetime, I have applied a similar approach here.
Also, credit goes to @mgorny and @neonene for the new tests.
FYI, I would have liked to take a slightly cleaner approach with managed static types, but wanted to get a smaller fix in first for the sake of backporting. I'll circle back to the cleaner approach with a future change on the main branch.
(cherry picked from commit b2e71ff4f8fa5b7d8117dd8125137aee3d01f015, AKA gh-120182)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
|
|
|
|
|
|
|
|
|
|
| |
(GH-120403)
gh-117657: Make Py_TYPE and Py_SET_TYPE thread safe (GH-120165)
(cherry picked from commit e16aed63f64b18a26859eff3de976ded373e66b8)
Co-authored-by: Ken Jin <kenjin@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Nadeshiko Manju <me@manjusaka.me>
|
|
|
|
|
|
|
| |
active (GH-120195)
(cherry picked from commit 203565b2f9c74656ba519780049b46d4e5afcba1)
Co-authored-by: Ken Jin <kenjin@python.org>
|
|
|
|
|
|
|
|
| |
correctly (GH-2487) (GH-120305)
(cherry picked from commit 4829522b8d3e1a28930f1cccfcc9635e035a0eb4)
Co-authored-by: E. M. Bray <erik.bray@lri.fr>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
|
|
|
|
|
|
|
|
| |
(#120340)
gh-120298: Fix use-after-free in `list_richcompare_impl` (GH-120303)
(cherry picked from commit 141babad9b4eceb83371bf19ba3a36b50dd05250)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
(GH-120228) (#120238)
gh-120155: Fix copy/paste error in HAVE_SUBOFFSETS_IN_LAST_DIM() (GH-120228)
Don't hardcode 'dest' in HAVE_SUBOFFSETS_IN_LAST_DIM() macro of
memoryobject.c, but use its 'view' parameter instead.
Fix the Coverity issue:
Error: COPY_PASTE_ERROR (CWE-398):
Python-3.12.2/Objects/memoryobject.c:273:14: original: ""dest->suboffsets + (dest->ndim - 1)"" looks like the original copy.
Python-3.12.2/Objects/memoryobject.c:274:14: copy_paste_error: ""dest"" in ""src->suboffsets + (dest->ndim - 1)"" looks like a copy-paste error.
Python-3.12.2/Objects/memoryobject.c:274:14: remediation: Should it say ""src"" instead?
GH- 272| assert(dest->ndim > 0 && src->ndim > 0);
GH- 273| return (!HAVE_SUBOFFSETS_IN_LAST_DIM(dest) &&
GH- 274|-> !HAVE_SUBOFFSETS_IN_LAST_DIM(src) &&
GH- 275| dest->strides[dest->ndim-1] == dest->itemsize &&
GH- 276| src->strides[src->ndim-1] == src->itemsize);
(cherry picked from commit 90b75405260467814c93738a3325645918d4ea51)
Co-authored-by: Victor Stinner <vstinner@python.org>
|
|
|
|
|
|
|
|
|
|
|
| |
`_Py_ExplicitMergeRefcount` (GH-120000) (#120073)
We need to write to `ob_ref_local` and `ob_tid` before `ob_ref_shared`.
Once we mark `ob_ref_shared` as merged, some other thread may free the
object because the caller also passes in `-1` as `extra` to give up its
only reference.
(cherry picked from commit 4055577221f5f52af329e87f31d81bb8fb02c504)
Co-authored-by: Sam Gross <colesbury@gmail.com>
|
|
|
|
|
|
| |
gh-111389: Add PyHASH_MULTIPLIER constant (GH-119214)
(cherry picked from commit f6da790122fdae1a28f444edfbb55202d6829cd1)
Co-authored-by: Victor Stinner <vstinner@python.org>
|
|
|
|
|
|
|
|
|
|
|
| |
(gh-120009)
We make use of the same mechanism that we use for the static builtin types. This required a few tweaks.
This change is the final piece needed to make _datetime support multiple interpreters. I've updated the module slot accordingly.
(cherry picked from commit 105f22ea46ac16866e6df18ebae2a8ba422b7f45, AKA gh-119929)
Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
| |
The free-threaded build currently immortalizes objects that use deferred
reference counting (see gh-117783). This typically happens once the
first non-main thread is created, but the behavior can be suppressed for
tests, in subinterpreters, or during a compile() call.
This fixes a race condition involving the tracking of whether the
behavior is suppressed.
(cherry picked from commit 47fb4327b5c405da6df066dcaa01b7c1aefab313)
|
|
|
|
|
|
|
|
| |
(gh-119963)
gh-117657: Fix data races report by TSAN unicode-hash (gh-119907)
(cherry picked from commit 0594a27e5f1d87d59fa8a761dd8ca9df4e42816d)
Co-authored-by: Donghee Na <donghee.na@python.org>
|
|
|
|
|
|
|
|
|
|
|
| |
* Add docs for new APIs
* Add soft-deprecation notices
* Add What's New porting entries
* Update comments referencing `PyFrame_LocalsToFast()` to mention the proxy instead
* Other related cleanups found when looking for refs to the deprecated APIs
(cherry picked from commit 3859e09e3d92d004978dd838f0511364e7edfb94)
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
(GH-119687) (GH-119803)
* Remove the equivalence with real+imag*1j which can be incorrect in corner
cases (non-finite numbers, the sign of zeroes).
* Separately document the three roles of the constructor: parsing a string,
converting a number, and constructing a complex from components.
* Document positional-only parameters of complex(), float(), int() and bool()
as positional-only.
* Add examples for complex() and int().
* Specify the grammar of the string for complex().
* Improve the grammar of the string for float().
* Describe more explicitly the behavior when real and/or imag arguments are
complex numbers. (This will be deprecated in future.)
(cherry picked from commit ec1ba264607b2b7b98d2602f5536a1d02981efc6)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
(#119746)
The deadlock only affected the free-threaded build and only occurred
when the GIL was enabled at runtime. The `Py_DECREF(old_name)` call
might temporarily release the GIL while holding the type seqlock.
Another thread may spin trying to acquire the seqlock while holding the
GIL.
The deadlock occurred roughly 1 in ~1,000 runs of `pool_in_threads.py`
from `test_multiprocessing_pool_circular_import`.
(cherry picked from commit c22323cd1c200ca1b22c47af95f67c4b2d661fe7)
Co-authored-by: Sam Gross <colesbury@gmail.com>
|
|
|
|
|
|
|
| |
(GH-119296) (#119678)
(cherry picked from commit 6b240c2308a044e38623900ccb8fa58c3549d4ae)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
|
|
|
|
|
| |
(cherry picked from commit 08e65430aafa1047029e6f132a5f748c415bda14)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
|
|
|
| |
(GH-119456)
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
| |
build (GH-119315) (#119419)
Add `Py_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST` and
`Py_END_CRITICAL_SECTION_SEQUENCE_FAST` macros and update `str.join` to use
them. Also add a regression test that would crash reliably without this
patch.
(cherry picked from commit baf347d91643a83483bae110092750d39471e0c2)
Co-authored-by: Josh {*()} Rosenberg <26495692+MojoVampire@users.noreply.github.com>
|
|
|
|
|
|
|
|
| |
(gh-119309)
gh-119053: Implement the fast path for list.__getitem__ (gh-119112)
(cherry picked from commit ab4263a82abe8b684d8ad1edf7c7c6ec286ff756)
Co-authored-by: Donghee Na <donghee.na@python.org>
|
|
|
|
|
|
|
| |
(#118933)
(cherry picked from commit 35c436186b849f8f2f9fb866c59015c9d034d448)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
|
|
|
|
|
|
|
|
| |
(#118898)
Rename `notimplemented_methods` into `nodefault_methods` (GH-118896)
(cherry picked from commit 004db2170ecfc27fc8ceea29fee0a10c1b7dafdf)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
|
|
|
|
|
| |
(cherry picked from commit 7e6fcab20003b07621dc02ea78d6ea2fda500371)
Co-authored-by: Steve Dower <steve.dower@python.org>
|
|
|
|
|
|
|
|
|
|
|
|
| |
(GH-118723) (#118863)
The `list_preallocate_exact` function did not zero initialize array
contents. In the free-threaded build, this could expose uninitialized
memory to concurrent readers between the call to
`list_preallocate_exact` and the filling of the array contents with
items.
(cherry picked from commit 2402715e10d00ef60fad2948d8461559d084eb36)
Co-authored-by: Sam Gross <colesbury@gmail.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>
|
|
|
|
|
|
|
|
|
|
| |
(GH-118292) (#118796)
Use relaxed atomics when reading / writing to the field. There are still a
few places in the GC where we do not use atomics. Those should be safe as
the world is stopped.
(cherry picked from commit cb6f75a32ca2649c6cc1cabb0301eb783efbd55b)
Co-authored-by: mpage <mpage@meta.com>
|
|
|
|
| |
We don't know how to create an unoptimized frame with f_locals == NULL,
but they are seen in the wild, and this fixes the crash.
|
| |
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
| |
Interned and non-interned strings are treated differently by `marshal`,
so be consistent between the default and free-threaded build.
|
|
|
|
|
| |
frame.f_locals (#118639)
Also fix unrelated assert in debug Tier2/JIT builds.
|
|
|
|
|
|
|
| |
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-117906)
* GH-117714: replace athrow().close() and asend().close() stubs with implimentations
* test athrow().close() and asend().close() raises RuntimeError
* 📜🤖 Added by blurb_it.
* Update Objects/genobject.c
Co-authored-by: Petr Viktorin <encukou@gmail.com>
---------
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
|
|
|
|
| |
(GH-118645)
|
| |
|
|
|
| |
Properly implement the `sq_contains` slot for frame locals proxy containment checks.
|
|
|
| |
Also add some error checks.
|
|
|
|
| |
With tests.
|