-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Description
int PyDict_SetDefaultRef(PyObject *p, PyObject *key, PyObject *default_value, PyObject **result)
It is similar to existing API PyObject *PyDict_SetDefault(PyObject *p, PyObject *key, PyObject *default_value)
, but have slightly different interface and returns a strong reference.
With the GIL it is virtually equivalent to PyDict_SetDefault()
followed by Py_XINCREF()
:
int PyDict_SetDefaultRef(PyObject *p, PyObject *key, PyObject *default_value, PyObject **result)
{
*result = PyDict_SetDefault(p, key, default_value);
Py_XINCREF(*result);
return *result ? 0 : -1;
}
But it holds a strong reference internally, so it has larger chance to be made thread-safe in GIL-less build (this still requires a lot of work and may be not worth to do). PyDict_SetDefault()
is not thread-safe without the GIL in principle, because the weak reference can became invalid between PyDict_SetDefault()
and Py_XINCREF()
.
- @gvanrossum
- @encukou (+1)
- @vstinner (+1)
- @zooba
- @iritkatriel
Metadata
Metadata
Assignees
Labels
No labels