@@ -5029,7 +5029,7 @@ dictiter_iternextkey(PyObject *self)
5029
5029
5030
5030
PyObject * value ;
5031
5031
#ifdef Py_GIL_DISABLED
5032
- if (!dictiter_iternext_threadsafe (d , self , & value , NULL )) {
5032
+ if (!dictiter_iternext_threadsafe (d , self , & value , NULL ) == 0 ) {
5033
5033
value = NULL ;
5034
5034
}
5035
5035
#else
@@ -5152,7 +5152,7 @@ dictiter_iternextvalue(PyObject *self)
5152
5152
5153
5153
PyObject * value ;
5154
5154
#ifdef Py_GIL_DISABLED
5155
- if (!dictiter_iternext_threadsafe (d , self , NULL , & value )) {
5155
+ if (!dictiter_iternext_threadsafe (d , self , NULL , & value ) == 0 ) {
5156
5156
value = NULL ;
5157
5157
}
5158
5158
#else
@@ -5209,7 +5209,7 @@ dictiter_iternextitem_lock_held(PyDictObject *d, PyObject *self,
5209
5209
PyErr_SetString (PyExc_RuntimeError ,
5210
5210
"dictionary changed size during iteration" );
5211
5211
di -> di_used = -1 ; /* Make this state sticky */
5212
- return 0 ;
5212
+ return -1 ;
5213
5213
}
5214
5214
5215
5215
i = FT_ATOMIC_LOAD_SSIZE_RELAXED (di -> di_pos );
@@ -5262,12 +5262,12 @@ dictiter_iternextitem_lock_held(PyDictObject *d, PyObject *self,
5262
5262
if (out_value != NULL ) {
5263
5263
* out_value = Py_NewRef (value );
5264
5264
}
5265
- return 1 ;
5265
+ return 0 ;
5266
5266
5267
5267
fail :
5268
5268
di -> di_dict = NULL ;
5269
5269
Py_DECREF (d );
5270
- return 0 ;
5270
+ return -1 ;
5271
5271
}
5272
5272
5273
5273
#ifdef Py_GIL_DISABLED
@@ -5319,7 +5319,7 @@ dictiter_iternext_threadsafe(PyDictObject *d, PyObject *self,
5319
5319
PyErr_SetString (PyExc_RuntimeError ,
5320
5320
"dictionary changed size during iteration" );
5321
5321
di -> di_used = -1 ; /* Make this state sticky */
5322
- return 0 ;
5322
+ return -1 ;
5323
5323
}
5324
5324
5325
5325
ensure_shared_on_read (d );
@@ -5329,12 +5329,14 @@ dictiter_iternext_threadsafe(PyDictObject *d, PyObject *self,
5329
5329
assert (i >= 0 );
5330
5330
if (_PyDict_HasSplitTable (d )) {
5331
5331
PyDictValues * values = _Py_atomic_load_ptr_relaxed (& d -> ma_values );
5332
- if (values == NULL )
5332
+ if (values == NULL ) {
5333
5333
goto concurrent_modification ;
5334
+ }
5334
5335
5335
5336
Py_ssize_t used = load_values_used_size (values );
5336
- if (i >= used )
5337
+ if (i >= used ) {
5337
5338
goto fail ;
5339
+ }
5338
5340
5339
5341
// We're racing against writes to the order from delete_index_from_values, but
5340
5342
// single threaded can suffer from concurrent modification to those as well and
@@ -5391,7 +5393,7 @@ dictiter_iternext_threadsafe(PyDictObject *d, PyObject *self,
5391
5393
5392
5394
_Py_atomic_store_ssize_relaxed (& di -> di_pos , i + 1 );
5393
5395
_Py_atomic_store_ssize_relaxed (& di -> len , len - 1 );
5394
- return 1 ;
5396
+ return 0 ;
5395
5397
5396
5398
concurrent_modification :
5397
5399
PyErr_SetString (PyExc_RuntimeError ,
@@ -5400,14 +5402,14 @@ dictiter_iternext_threadsafe(PyDictObject *d, PyObject
8000
*self,
5400
5402
fail :
5401
5403
di -> di_dict = NULL ;
5402
5404
Py_DECREF (d );
5403
- return 0 ;
5405
+ return -1 ;
5404
5406
5405
- int success ;
5407
+ int res ;
5406
5408
try_locked :
5407
5409
Py_BEGIN_CRITICAL_SECTION (d );
5408
- success = dictiter_iternextitem_lock_held (d , self , out_key , out_value );
5410
+ res = dictiter_iternextitem_lock_held (d , self , out_key , out_value );
5409
5411
Py_END_CRITICAL_SECTION ();
5410
- return success ;
5412
+ return res ;
5411
5413
}
5412
5414
5413
5415
#endif
@@ -5427,11 +5429,7 @@ has_unique_reference(PyObject *op)
5427
5429
static bool
5428
5430
acquire_iter_result (PyObject * result )
5429
5431
{
5430
- #ifdef Py_GIL_DISABLED
5431
5432
if (has_unique_reference (result )) {
5432
- #else
5433
- if (Py_REFCNT (result ) == 1 ) {
5434
- #endif
5435
5433
Py_INCREF (result );
5436
5434
return true;
5437
5435
}
@@ -5449,9 +5447,9 @@ dictiter_iternextitem(PyObject *self)
5449
5447
5450
5448
PyObject * key , * value ;
5451
5449
#ifdef Py_GIL_DISABLED
5452
- if (dictiter_iternext_threadsafe (d , self , & key , & value )) {
5450
+ if (dictiter_iternext_threadsafe (d , self , & key , & value ) == 0 ) {
5453
5451
#else
5454
- if (dictiter_iternextitem_lock_held (d , self , & key , & value )) {
5452
+ if (dictiter_iternextitem_lock_held (d , self , & key , & value ) == 0 ) {
5455
5453
5456
5454
#endif
5457
5455
PyObject * result = di -> di_result ;
0 commit comments