Skip to content

Commit

Permalink
Fix style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoV committed Feb 21, 2024
1 parent cb1f8bd commit e2a13a2
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5029,7 +5029,7 @@ dictiter_iternextkey(PyObject *self)

PyObject *value;
#ifdef Py_GIL_DISABLED
if (!dictiter_iternext_threadsafe(d, self, &value, NULL)) {
if (!dictiter_iternext_threadsafe(d, self, &value, NULL) == 0) {
value = NULL;
}
#else
Expand Down Expand Up @@ -5152,7 +5152,7 @@ dictiter_iternextvalue(PyObject *self)

PyObject *value;
#ifdef Py_GIL_DISABLED
if (!dictiter_iternext_threadsafe(d, self, NULL, &value)) {
if (!dictiter_iternext_threadsafe(d, self, NULL, &value) == 0) {
value = NULL;
}
#else
Expand Down Expand Up @@ -5209,7 +5209,7 @@ dictiter_iternextitem_lock_held(PyDictObject *d, PyObject *self,
PyErr_SetString(PyExc_RuntimeError,
"dictionary changed size during iteration");
di->di_used = -1; /* Make this state sticky */
return 0;
return -1;
}

i = FT_ATOMIC_LOAD_SSIZE_RELAXED(di->di_pos);
Expand Down Expand Up @@ -5262,12 +5262,12 @@ dictiter_iternextitem_lock_held(PyDictObject *d, PyObject *self,
if (out_value != NULL) {
*out_value = Py_NewRef(value);
}
return 1;
return 0;

fail:
di->di_dict = NULL;
Py_DECREF(d);
return 0;
return -1;
}

#ifdef Py_GIL_DISABLED
Expand Down Expand Up @@ -5319,7 +5319,7 @@ dictiter_iternext_threadsafe(PyDictObject *d, PyObject *self,
PyErr_SetString(PyExc_RuntimeError,
"dictionary changed size during iteration");
di->di_used = -1; /* Make this state sticky */
return 0;
return -1;
}

ensure_shared_on_read(d);
Expand All @@ -5329,12 +5329,14 @@ dictiter_iternext_threadsafe(PyDictObject *d, PyObject *self,
assert(i >= 0);
if (_PyDict_HasSplitTable(d)) {
PyDictValues *values = _Py_atomic_load_ptr_relaxed(&d->ma_values);
if (values == NULL)
if (values == NULL) {
goto concurrent_modification;
}

Py_ssize_t used = load_values_used_size(values);
if (i >= used)
if (i >= used) {
goto fail;
}

// We're racing against writes to the order from delete_index_from_values, but
// single threaded can suffer from concurrent modification to those as well and
Expand Down Expand Up @@ -5400,14 +5402,14 @@ dictiter_iternext_threadsafe(PyDictObject *d, PyObject *self,
fail:
di->di_dict = NULL;
Py_DECREF(d);
return 0;
return -1;

int success;
int res;
try_locked:
Py_BEGIN_CRITICAL_SECTION(d);
success = dictiter_iternextitem_lock_held(d, self, out_key, out_value);
res = dictiter_iternextitem_lock_held(d, self, out_key, out_value);
Py_END_CRITICAL_SECTION();
return success;
return res;
}

#endif
Expand All @@ -5427,11 +5429,7 @@ has_unique_reference(PyObject *op)
static bool
acquire_iter_result(PyObject *result)
{
#ifdef Py_GIL_DISABLED
if (has_unique_reference(result)) {
#else
if (Py_REFCNT(result) == 1) {
#endif
Py_INCREF(result);
return true;
}
Expand All @@ -5449,9 +5447,9 @@ dictiter_iternextitem(PyObject *self)

PyObject *key, *value;
#ifdef Py_GIL_DISABLED
if (dictiter_iternext_threadsafe(d, self, &key, &value)) {
if (dictiter_iternext_threadsafe(d, self, &key, &value) == 0) {
#else
if (dictiter_iternextitem_lock_held(d, self, &key, &value)) {
if (dictiter_iternextitem_lock_held(d, self, &key, &value) == 0) {

#endif
PyObject *result = di->di_result;
Expand Down

0 comments on commit e2a13a2

Please sign in to comment.