Germán Méndez Bravo
f0ed1863bd
gh-112075: Fix dict thread safety issues ( #119288 )
...
Fix dict thread safety issues
2024-05-24 10:39:06 -07:00
Dino Viehland
2b3fb767be
gh-117657: Fix missing atomic in dict_resize ( #119312 )
...
Fix missing atomic in dict_resize
2024-05-22 10:38:56 -07:00
Nikita Sobolev
82abe75e77
gh-118849: Fix "code will never be executed" warning in `dictobject.c` ( #118850 )
2024-05-09 20:15:14 +03:00
Dino Viehland
636b8d94c9
gh-112075: Fix race in constructing dict for instance ( #118499 )
2024-05-06 23:31:09 +00:00
Dino Viehland
5a1618a2c8
gh-118362: Fix thread safety around lookups from the type cache in the face 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
2024-05-06 10:50:35 -07:00
Sam Gross
79688b5b0e
gh-118331: Handle errors in _PyObject_SetManagedDict ( #118334 )
...
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.
2024-04-29 15:49:01 -04:00
Dino Viehland
d5df25268b
gh-112075: _Py_dict_lookup needs to lock shared keys ( #117528 )
...
Lock shared keys in `Py_dict_lookup` and use thread-safe lookup in `insertdict`
Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-04-25 15:34:05 -07:00
Dino Viehland
5da0280648
gh-117657: Fixes a few small TSAN issues in dictobject ( #118200 )
...
Fixup TSAN errors for dict
2024-04-25 08:53:29 -07:00
Dino Viehland
8b541c017e
gh-112075: Make instance attributes stored in inline "dict" thread safe ( #114742 )
...
Make instance attributes stored in inline "dict" thread safe on free-threaded builds
2024-04-21 22:57:05 -07:00
Noah Kim
b624490dee
Fix a typo in dictobject.c documentation ( #117515 )
2024-04-19 19:19:12 +00:00
Dino Viehland
1e4a4c4897
gh-117657: use relaxed loads for checking dict keys immortality ( #118067 )
...
Use relaxed load to check if dictkeys are immortal
2024-04-19 09:25:08 -07:00
Donghee Na
94444ea45a
gh-112069: Add _PySet_NextEntryRef to be thread-safe. (gh-117990)
2024-04-19 00:18:22 +09:00
Mark Shannon
784e076a10
GH-117750: When clearing object's dict, clear inline values but leave dict attached (GH-117808)
2024-04-15 14:45:05 +01:00
Donghee Na
7bcc257e97
gh-117826: Remove lookdict_index from delitemif_lock_held (gh-117869)
2024-04-15 14:26:59 +09:00
Sam Gross
1a6594f661
gh-117439: Make refleak checking thread-safe without the GIL ( #117469 )
...
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.
2024-04-08 12:11:36 -04:00
mpage
df73179048
gh-111926: Make weakrefs thread-safe in free-threaded builds ( #117168 )
...
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`).
2024-04-08 10:58:38 -04:00
Dino Viehland
434bc593df
gh-112075: Make _PyDict_LoadGlobal thread safe ( #117529 )
...
Make _PyDict_LoadGlobal threadsafe
2024-04-04 12:26:07 -07:00
Mark Shannon
c32dc47aca
GH-115776: Embed the values array into the object, for "normal" Python objects. (GH-116115)
2024-04-02 11:59:21 +01:00
Dino Viehland
ffcc450a9b
gh-112075: Enable freeing with qsbr and fallback to lock on key changed (GH-116336)
2024-03-05 09:08:18 +00:00
Sam Gross
58c7919d05
gh-116029: Fix unused function warning on macOS ( #116340 )
2024-03-04 22:06:21 -05:00
Humbulani
5e0c7bc1d3
gh-115941: fixes in dictobject.c doc block( #116196 )
2024-03-01 12:48:26 -07:00
Dino Viehland
556749c3e3
gh-112075: Avoid locking shared keys on every assignment ( #116087 )
2024-02-29 13:38:50 -08:00
Dino Viehland
81c79961d2
gh-112075: Use relaxed stores for places where we may race with when reading lock-free ( #115786 )
2024-02-28 14:53:19 -08:00
Donghee Na
f58f8cef74
gh-112075: Remove compiler warning from apple clang (gh-115855)
2024-02-29 02:51:59 +09:00
Dino Viehland
1002fbe12e
gh-112075: Iterating a dict shouldn't require locks ( #115108 )
...
Makes iteration of a dict be lock free for the forward iteration case.
2024-02-22 12:02:39 -08:00
Dino Viehland
54071460d7
gh-112075: Accessing a single element should optimistically avoid locking ( #115109 )
...
Makes accessing a single element thread safe and typically lock free
2024-02-20 17:08:14 -08:00
Dino Viehland
176df09adb
gh-112075: Make PyDictKeysObject thread-safe ( #114741 )
...
Adds locking for shared PyDictKeysObject's for dictionaries
2024-02-20 16:40:37 -08:00
Donghee Na
321d13fd2b
gh-111968: Split _Py_dictkeys_freelist out of _Py_dict_freelist (gh-115505)
2024-02-16 01:01:36 +00:00
Donghee Na
f15795c9a0
gh-111968: Rename freelist related struct names to Eric's suggestion (gh-115329)
2024-02-14 00:32:51 +00:00
Sam Gross
a3af3cb4f4
gh-110481: Implement inter-thread queue for biased reference counting ( #114824 )
...
Biased reference counting maintains two refcount fields in each object:
`ob_ref_local` and `ob_ref_shared`. The true refcount is the sum of these two
fields. In some cases, when refcounting operations are split across threads,
the ob_ref_shared field can be negative (although the total refcount must be
at least zero). In this case, the thread that decremented the refcount
requests that the owning thread give up ownership and merge the refcount
fields.
2024-02-09 17:08:32 -05:00
Dino Viehland
92abb01240
gh-112075: Add critical sections for most dict APIs ( #114508 )
...
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
2024-02-06 14:03:43 -08:00
Sam Gross
de61d4bd4d
gh-112066: Add `PyDict_SetDefaultRef` function. ( #112123 )
...
The `PyDict_SetDefaultRef` function is similar to `PyDict_SetDefault`,
but returns a strong reference through the optional `**result` pointer
instead of a borrowed reference.
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2024-02-06 11:36:23 -05:00
Mark Shannon
0e71a295e9
GH-113710: Add a "globals to constants" pass (GH-114592)
...
Converts specializations of `LOAD_GLOBAL` into constants during tier 2 optimization.
2024-02-02 12:14:34 +00:00
Donghee Na
13907968d7
gh-111968: Use per-thread freelists for dict in free-threading (gh-114323)
2024-02-01 20:53:53 +00:00
Dino Viehland
0990d55725
gh-112075: refactor dictionary lookup functions for better re-usability ( #114629 )
...
Refactor dict lookup functions to use force inline helpers
2024-01-30 09:33:36 -08:00
Dino Viehland
3d716655d2
gh-112075: Use PyMem_* for allocating dict keys objects ( #114543 )
...
Use PyMem_* for keys allocation
2024-01-29 09:38:03 -08:00
Dino Viehland
afe8f376c0
gh-112075: Adapt more dict methods to Argument Clinic ( #114256 )
...
* Move more dict objects to argument clinic
* Improve doc strings
* More doc string improvements
* Update Objects/dictobject.c
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* Update Objects/dictobject.c
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* Update Objects/dictobject.c
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* Update Objects/dictobject.c
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* Update Objects/dictobject.c
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* Update Objects/dictobject.c
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* Update Objects/dictobject.c
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
---------
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2024-01-23 22:10:04 +00:00
Christopher Chavez
a1eea1d032
gh-111178: Avoid calling functions from incompatible pointer types in dictobject.c ( #112892 )
...
Fix undefined behavior warnings (UBSan -fsanitize=function).
2024-01-02 15:32:37 +01:00
Victor Stinner
bd2f1485b0
gh-112026: Restore removed _PyDict_GetItemStringWithError() ( #112119 )
...
Restore the removed _PyDict_GetItemStringWithError() function. It is
used by numpy.
2023-11-15 17:10:06 +00:00
Victor Stinner
58469244be
gh-112026: Restore removed private C API ( #112115 )
...
Restore removed private C API functions, macros and structures which
have no simple replacement for now:
* _PyDict_GetItem_KnownHash()
* _PyDict_NewPresized()
* _PyHASH_BITS
* _PyHASH_IMAG
* _PyHASH_INF
* _PyHASH_MODULUS
* _PyHASH_MULTIPLIER
* _PyLong_Copy()
* _PyLong_FromDigits()
* _PyLong_New()
* _PyLong_Sign()
* _PyObject_CallMethodId()
* _PyObject_CallMethodNoArgs()
* _PyObject_CallMethodOneArg()
* _PyObject_CallOneArg()
* _PyObject_EXTRA_INIT
* _PyObject_FastCallDict()
* _PyObject_GetAttrId()
* _PyObject_Vectorcall()
* _PyObject_VectorcallMethod()
* _PyStack_AsDict()
* _PyThread_CurrentFrames()
* _PyUnicodeWriter structure
* _PyUnicodeWriter_Dealloc()
* _PyUnicodeWriter_Finish()
* _PyUnicodeWriter_Init()
* _PyUnicodeWriter_Prepare()
* _PyUnicodeWriter_PrepareKind()
* _PyUnicodeWriter_WriteASCIIString()
* _PyUnicodeWriter_WriteChar()
* _PyUnicodeWriter_WriteLatin1String()
* _PyUnicodeWriter_WriteStr()
* _PyUnicodeWriter_WriteSubstring()
* _PyUnicode_AsString()
* _PyUnicode_FromId()
* _PyVectorcall_Function()
* _Py_HashDouble()
* _Py_HashPointer()
* _Py_IDENTIFIER()
* _Py_c_abs()
* _Py_c_diff()
* _Py_c_neg()
* _Py_c_pow()
* _Py_c_prod()
* _Py_c_quot()
* _Py_c_sum()
* _Py_static_string()
* _Py_static_string_init()
2023-11-15 16:38:31 +00:00
Victor Stinner
4f04172c92
gh-111262: Add PyDict_Pop() function ( #112028 )
...
_PyDict_Pop_KnownHash(): remove the default value and the return type
becomes an int.
Co-authored-by: Stefan Behnel <stefan_ml@behnel.de>
Co-authored-by: Antoine Pitrou <pitrou@free.fr>
2023-11-14 12:51:00 +00:00
Serhiy Storchaka
f55cb44359
gh-106672: C API: Report indiscriminately ignored errors (GH-106674)
...
Functions which indiscriminately ignore all errors now report them as
unraisable errors.
2023-11-07 15:58:04 +02:00
Serhiy Storchaka
970e719a7a
gh-108082: Use PyErr_FormatUnraisable() (GH-111580)
...
Replace most of calls of _PyErr_WriteUnraisableMsg() and some
calls of PyErr_WriteUnraisable(NULL) with PyErr_FormatUnraisable().
Co-authored-by: Victor Stinner <vstinner@python.org>
2023-11-02 09:16:34 +00:00
Victor Stinner
fc2cb86d21
gh-107073: Make PyObject_VisitManagedDict() public ( #108763 )
...
Make PyObject_VisitManagedDict() and PyObject_ClearManagedDict()
functions public in Python 3.13 C API.
* Rename _PyObject_VisitManagedDict() to PyObject_VisitManagedDict().
* Rename _PyObject_ClearManagedDict() to PyObject_ClearManagedDict().
* Document these functions.
2023-10-02 19:24:08 +02:00
Serhiy Storchaka
add16f1a5e
gh-108511: Add C API functions which do not silently ignore errors (GH-109025)
...
Add the following functions:
* PyObject_HasAttrWithError()
* PyObject_HasAttrStringWithError()
* PyMapping_HasKeyWithError()
* PyMapping_HasKeyStringWithError()
2023-09-17 14:23:31 +03:00
Nikita Sobolev
47af188593
Add missing `PyDoc_STR` calls ( #109393 )
...
In files:
* Modules/_ctypes/cfield.c
* Modules/_struct.c
* Objects/dictobject.c
* Objects/typevarobject.c
* Objects/unionobject.c
2023-09-15 15:10:48 +02:00
Victor Stinner
c494fb333b
gh-106320: Remove private _PyEval function ( #108433 )
...
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.
2023-08-24 20:25:22 +02:00
Victor Stinner
52c6a6e48a
gh-108308: Remove _PyDict_GetItemStringWithError() function ( #108426 )
...
Remove the internal _PyDict_GetItemStringWithError() function. It can
now be replaced with the new public PyDict_ContainsString() and
PyDict_GetItemStringRef() functions.
getargs.c now now uses a strong reference for current_arg.
find_keyword() returns a strong reference.
2023-08-24 17:34:22 +02:00
Victor Stinner
6726626646
gh-108314: Add PyDict_ContainsString() function ( #108323 )
2023-08-24 15:59:12 +02:00
Mark Shannon
666b68e8f2
GH-106485: Create object's dict-values instead of creating __dict__, when we can. (GH-107843)
2023-08-11 20:05:56 +01:00