mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-112075: Remove critical section in dict.get (gh-129336)
The `dict.get` implementation uses `_Py_dict_lookup_threadsafe`, which is thread-safe, so we remove the critical section from the argument clinic. Add a test for concurrent dict get and set operations.
This commit is contained in:
parent
a4459c34ea
commit
64c417dee5
3 changed files with 24 additions and 6 deletions
4
Objects/clinic/dictobject.c.h
generated
4
Objects/clinic/dictobject.c.h
generated
|
@ -94,9 +94,7 @@ dict_get(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
|||
}
|
||||
default_value = args[1];
|
||||
skip_optional:
|
||||
Py_BEGIN_CRITICAL_SECTION(self);
|
||||
return_value = dict_get_impl((PyDictObject *)self, key, default_value);
|
||||
Py_END_CRITICAL_SECTION();
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
|
@ -312,4 +310,4 @@ dict_values(PyObject *self, PyObject *Py_UNUSED(ignored))
|
|||
{
|
||||
return dict_values_impl((PyDictObject *)self);
|
||||
}
|
||||
/*[clinic end generated code: output=4956c5b276ea652f input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=0f04bf0e7e6b130f input=a9049054013a1b77]*/
|
||||
|
|
|
@ -4248,7 +4248,6 @@ dict___contains__(PyDictObject *self, PyObject *key)
|
|||
}
|
||||
|
||||
/*[clinic input]
|
||||
@critical_section
|
||||
dict.get
|
||||
|
||||
key: object
|
||||
|
@ -4260,7 +4259,7 @@ Return the value for key if key is in the dictionary, else default.
|
|||
|
||||
static PyObject *
|
||||
dict_get_impl(PyDictObject *self, PyObject *key, PyObject *default_value)
|
||||
/*[clinic end generated code: output=bba707729dee05bf input=a631d3f18f584c60]*/
|
||||
/*[clinic end generated code: output=bba707729dee05bf input=279ddb5790b6b107]*/
|
||||
{
|
||||
PyObject *val = NULL;
|
||||
Py_hash_t hash;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue