Skip to content

Commit 1500d17

Browse files
committed
remove complex result struct for try_store_instance_attr_status.
1 parent ed54dbf commit 1500d17

1 file changed

Lines changed: 15 additions & 21 deletions

File tree

Objects/dictobject.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7514,18 +7514,14 @@ typedef enum {
75147514
TRY_STORE_ATTR_ALREADY_VALID = 2
75157515
} try_store_instance_attr_status;
75167516

7517-
typedef struct {
7518-
try_store_instance_attr_status try_status;
7519-
int res;
7520-
} try_store_instance_attr_result_t;
7521-
7522-
static try_store_instance_attr_result_t
7517+
static try_store_instance_attr_status
75237518
try_store_instance_attr_invalid_inline(PyObject *obj, PyObject *name,
7524-
PyObject *value)
7519+
PyObject *value, int *res)
75257520
{
75267521
bool valid;
75277522
PyDictObject *dict;
75287523
PyDictValues *values = _PyObject_InlineValues(obj);
7524+
*res = 0;
75297525
Py_BEGIN_CRITICAL_SECTION(obj);
75307526
if (!(valid = FT_ATOMIC_LOAD_UINT8(values->valid))) {
75317527
dict = _PyObject_GetManagedDict(obj);
@@ -7536,35 +7532,32 @@ try_store_instance_attr_invalid_inline(PyObject *obj, PyObject *name,
75367532
Py_END_CRITICAL_SECTION();
75377533

75387534
if (valid) {
7539-
return (try_store_instance_attr_result_t){TRY_STORE_ATTR_ALREADY_VALID, 0};
7535+
return TRY_STORE_ATTR_ALREADY_VALID;
75407536
}
75417537

75427538
if (dict == NULL) {
75437539
// PyObject_GenericGetDict may lock the object,
75447540
// so we need to do it outside of the critical section.
75457541
dict = (PyDictObject *)PyObject_GenericGetDict(obj, NULL);
75467542
if (dict == NULL) {
7547-
return (try_store_instance_attr_result_t){TRY_STORE_ATTR_FAILURE, -1};
7543+
*res = -1;
7544+
return TRY_STORE_ATTR_FAILURE;
75487545
}
75497546
}
75507547

7551-
int res;
75527548
bool success = false;
75537549
Py_BEGIN_CRITICAL_SECTION2(obj, dict);
75547550
PyDictObject *current_dict = _PyObject_GetManagedDict(obj);
75557551
if (current_dict == dict && !(valid = FT_ATOMIC_LOAD_UINT8(values->valid))) {
75567552
success = true;
7557-
res = store_instance_attr_with_dict_lock_held(obj, dict, name, value);
7553+
*res = store_instance_attr_with_dict_lock_held(obj, dict, name, value);
75587554
}
75597555
Py_END_CRITICAL_SECTION2();
75607556
Py_DECREF(dict);
75617557
if (success) {
7562-
return (try_store_instance_attr_result_t){TRY_STORE_ATTR_DONE, res};
7558+
return TRY_STORE_ATTR_DONE;
75637559
}
7564-
if (valid) {
7565-
return (try_store_instance_attr_result_t){TRY_STORE_ATTR_ALREADY_VALID, 0};
7566-
}
7567-
return (try_store_instance_attr_result_t){TRY_STORE_ATTR_RETRY, 0};
7560+
return valid ? TRY_STORE_ATTR_ALREADY_VALID : TRY_STORE_ATTR_RETRY;
75687561
}
75697562
#endif
75707563

@@ -7574,18 +7567,19 @@ _PyObject_StoreInstanceAttribute(PyObject *obj, PyObject *name, PyObject *value)
75747567
PyDictValues *values = _PyObject_InlineValues(obj);
75757568
#ifdef Py_GIL_DISABLED
75767569
uint8_t valid;
7577-
try_store_instance_attr_result_t try_res = {TRY_STORE_ATTR_ALREADY_VALID, 0};
7570+
int res;
7571+
try_store_instance_attr_status try_status = TRY_STORE_ATTR_ALREADY_VALID;
75787572
while (!(valid = FT_ATOMIC_LOAD_UINT8(values->valid))) {
75797573
// Retry if the managed dict changes before we can lock and validate it.
7580-
try_res = try_store_instance_attr_invalid_inline(obj, name, value);
7581-
if (try_res.try_status != TRY_STORE_ATTR_RETRY) {
7574+
try_status = try_store_instance_attr_invalid_inline(obj, name, value, &res);
7575+
if (try_status != TRY_STORE_ATTR_RETRY) {
75827576
break;
75837577
}
75847578
}
7585-
switch (try_res.try_status) {
7579+
switch (try_status) {
75867580
case TRY_STORE_ATTR_FAILURE:
75877581
case TRY_STORE_ATTR_DONE:
7588-
return try_res.res;
7582+
return res;
75897583
case TRY_STORE_ATTR_ALREADY_VALID:
75907584
break;
75917585
case TRY_STORE_ATTR_RETRY:

0 commit comments

Comments
 (0)