Skip to content

Commit ffe4273

Browse files
committed
Convert methods that take *args
1 parent 44694c0 commit ffe4273

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

Objects/setobject.c

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,11 @@ set_update_impl(PySetObject *so, PyObject *args)
979979

980980
for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
981981
PyObject *other = PyTuple_GET_ITEM(args, i);
982-
if (set_update_internal(so, other))
982+
int rv;
983+
Py_BEGIN_CRITICAL_SECTION2(so, other);
984+
rv = set_update_internal(so, other);
985+
Py_END_CRITICAL_SECTION2();
986+
if (rv)
983987
return NULL;
984988
}
985989
Py_RETURN_NONE;
@@ -1198,15 +1202,21 @@ set_union_impl(PySetObject *so, PyObject *args)
11981202
PyObject *other;
11991203
Py_ssize_t i;
12001204

1205+
Py_BEGIN_CRITICAL_SECTION(so);
12011206
result = (PySetObject *)set_copy(so, NULL);
1207+
Py_END_CRITICAL_SECTION();
12021208
if (result == NULL)
12031209
return NULL;
12041210

12051211
for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
1212+
int rv;
12061213
other = PyTuple_GET_ITEM(args, i);
12071214
if ((PyObject *)so == other)
12081215
continue;
1209-
if (set_update_internal(result, other)) {
1216+
Py_BEGIN_CRITICAL_SECTION(other);
1217+
rv = set_update_internal(result, other);
1218+
Py_END_CRITICAL_SECTION();
1219+
if (rv) {
12101220
Py_DECREF(result);
12111221
return NULL;
12121222
}
@@ -1355,13 +1365,21 @@ set_intersection_multi_impl(PySetObject *so, PyObject *args)
13551365
{
13561366
Py_ssize_t i;
13571367

1358-
if (PyTuple_GET_SIZE(args) == 0)
1359-
return set_copy(so, NULL);
1368+
if (PyTuple_GET_SIZE(args) == 0) {
1369+
PyObject *result;
1370+
Py_BEGIN_CRITICAL_SECTION(so);
1371+
result = set_copy(so, NULL);
1372+
Py_END_CRITICAL_SECTION();
1373+
return result;
1374+
}
13601375

13611376
PyObject *result = Py_NewRef(so);
13621377
for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
13631378
PyObject *other = PyTuple_GET_ITEM(args, i);
1364-
PyObject *newresult = set_intersection((PySetObject *)result, other);
1379+
PyObject *newresult;
1380+
Py_BEGIN_CRITICAL_SECTION2(result, other);
1381+
newresult = set_intersection((PySetObject *)result, other);
1382+
Py_END_CRITICAL_SECTION2();
13651383
if (newresult == NULL) {
13661384
Py_DECREF(result);
13671385
return NULL;
@@ -1402,7 +1420,9 @@ set_intersection_update_multi_impl(PySetObject *so, PyObject *args)
14021420
tmp = set_intersection_multi_impl(so, args);
14031421
if (tmp == NULL)
14041422
return NULL;
1423+
Py_BEGIN_CRITICAL_SECTION(so);
14051424
set_swap_bodies(so, (PySetObject *)tmp);
1425+
Py_END_CRITICAL_SECTION();
14061426
Py_DECREF(tmp);
14071427
Py_RETURN_NONE;
14081428
}
@@ -1585,8 +1605,13 @@ set_difference_update_impl(PySetObject *so, PyObject *args)
15851605

15861606
for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
15871607
PyObject *other = PyTuple_GET_ITEM(args, i);
1588-
if (set_difference_update_internal(so, other))
1608+
int rv;
1609+
Py_BEGIN_CRITICAL_SECTION2(so, other);
1610+
rv = set_difference_update_internal(so, other);
1611+
Py_END_CRITICAL_SECTION2();
1612+
if (rv) {
15891613
return NULL;
1614+
}
15901615
}
15911616
Py_RETURN_NONE;
15921617
}
@@ -1697,17 +1722,27 @@ set_difference_multi_impl(PySetObject *so, PyObject *args)
16971722
Py_ssize_t i;
16981723
PyObject *result, *other;
16991724

1700-
if (PyTuple_GET_SIZE(args) == 0)
1701-
return set_copy(so, NULL);
1725+
if (PyTuple_GET_SIZE(args) == 0) {
1726+
Py_BEGIN_CRITICAL_SECTION(so);
1727+
result = set_copy(so, NULL);
1728+
Py_END_CRITICAL_SECTION();
1729+
return result;
1730+
}
17021731

17031732
other = PyTuple_GET_ITEM(args, 0);
1733+
Py_BEGIN_CRITICAL_SECTION2(so, other);
17041734
result = set_difference(so, other);
1735+
Py_END_CRITICAL_SECTION2();
17051736
if (result == NULL)
17061737
return NULL;
17071738

17081739
for (i=1 ; i<PyTuple_GET_SIZE(args) ; i++) {
17091740
other = PyTuple_GET_ITEM(args, i);
1710-
if (set_difference_update_internal((PySetObject *)result, other)) {
1741+
int rv;
1742+
Py_BEGIN_CRITICAL_SECTION(other);
1743+
rv = set_difference_update_internal((PySetObject *)result, other);
1744+
Py_END_CRITICAL_SECTION();
1745+
if (rv) {
17111746
Py_DECREF(result);
17121747
return NULL;
17131748
}

0 commit comments

Comments
 (0)