Skip to content

Commit 44694c0

Browse files
committed
Convert all number methods
1 parent b06292a commit 44694c0

File tree

1 file changed

+60
-11
lines changed

1 file changed

+60
-11
lines changed

Objects/setobject.c

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,31 +1217,43 @@ set_union_impl(PySetObject *so, PyObject *args)
12171217
static PyObject *
12181218
set_or(PySetObject *so, PyObject *other)
12191219
{
1220-
PySetObject *result;
1220+
PySetObject *result = NULL;
12211221

12221222
if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
12231223
Py_RETURN_NOTIMPLEMENTED;
12241224

1225+
Py_BEGIN_CRITICAL_SECTION2(so, other);
12251226
result = (PySetObject *)set_copy(so, NULL);
1226-
if (result == NULL)
1227-
return NULL;
1228-
if ((PyObject *)so == other)
1229-
return (PyObject *)result;
1227+
if (result == NULL) {
1228+
goto done;
1229+
}
1230+
if ((PyObject *)so == other) {
1231+
goto done;
1232+
}
12301233
if (set_update_internal(result, other)) {
12311234
Py_DECREF(result);
1232-
return NULL;
1235+
result = NULL;
12331236
}
1237+
done:
1238+
Py_END_CRITICAL_SECTION2();
12341239
return (PyObject *)result;
12351240
}
12361241

12371242
static PyObject *
12381243
set_ior(PySetObject *so, PyObject *other)
12391244
{
1245+
int rv;
1246+
12401247
if (!PyAnySet_Check(other))
12411248
Py_RETURN_NOTIMPLEMENTED;
12421249

1243-
if (set_update_internal(so, other))
1250+
Py_BEGIN_CRITICAL_SECTION2(so, other);
1251+
rv = set_update_internal(so, other);
1252+
Py_END_CRITICAL_SECTION2();
1253+
1254+
if(rv) {
12441255
return NULL;
1256+
}
12451257
return Py_NewRef(so);
12461258
}
12471259

@@ -1398,9 +1410,16 @@ set_intersection_update_multi_impl(PySetObject *so, PyObject *args)
13981410
static PyObject *
13991411
set_and(PySetObject *so, PyObject *other)
14001412
{
1413+
PyObject *rv;
1414+
14011415
if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
14021416
Py_RETURN_NOTIMPLEMENTED;
1403-
return set_intersection(so, other);
1417+
1418+
Py_BEGIN_CRITICAL_SECTION2(so, other);
1419+
rv = set_intersection(so, other);
1420+
Py_END_CRITICAL_SECTION2();
1421+
1422+
return rv;
14041423
}
14051424

14061425
static PyObject *
@@ -1410,7 +1429,11 @@ set_iand(PySetObject *so, PyObject *other)
14101429

14111430
if (!PyAnySet_Check(other))
14121431
Py_RETURN_NOTIMPLEMENTED;
1432+
1433+
Py_BEGIN_CRITICAL_SECTION2(so, other);
14131434
result = set_intersection_update(so, other);
1435+
Py_END_CRITICAL_SECTION2();
1436+
14141437
if (result == NULL)
14151438
return NULL;
14161439
Py_DECREF(result);
@@ -1695,18 +1718,33 @@ set_difference_multi_impl(PySetObject *so, PyObject *args)
16951718
static PyObject *
16961719
set_sub(PySetObject *so, PyObject *other)
16971720
{
1721+
PyObject *rv;
1722+
16981723
if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
16991724
Py_RETURN_NOTIMPLEMENTED;
1700-
return set_difference(so, other);
1725+
1726+
Py_BEGIN_CRITICAL_SECTION2(so, other);
1727+
rv = set_difference(so, other);
1728+
Py_END_CRITICAL_SECTION2();
1729+
1730+
return rv;
17011731
}
17021732

17031733
static PyObject *
17041734
set_isub(PySetObject *so, PyObject *other)
17051735
{
1736+
int rv;
1737+
17061738
if (!PyAnySet_Check(other))
17071739
Py_RETURN_NOTIMPLEMENTED;
1708-
if (set_difference_update_internal(so, other))
1740+
1741+
Py_BEGIN_CRITICAL_SECTION2(so, other);
1742+
rv = set_difference_update_internal(so, other);
1743+
Py_END_CRITICAL_SECTION2();
1744+
1745+
if(rv) {
17091746
return NULL;
1747+
}
17101748
return Py_NewRef(so);
17111749
}
17121750

@@ -1834,9 +1872,16 @@ set_symmetric_difference_impl(PySetObject *so, PyObject *other)
18341872
static PyObject *
18351873
set_xor(PySetObject *so, PyObject *other)
18361874
{
1875+
PyObject *rv;
1876+
18371877
if (!PyAnySet_Check(so) || !PyAnySet_Check(other))
18381878
Py_RETURN_NOTIMPLEMENTED;
1839-
return set_symmetric_difference(so, other);
1879+
1880+
Py_BEGIN_CRITICAL_SECTION2(so, other);
1881+
rv = set_symmetric_difference(so, other);
1882+
Py_END_CRITICAL_SECTION2();
1883+
1884+
return rv;
18401885
}
18411886

18421887
static PyObject *
@@ -1846,7 +1891,11 @@ set_ixor(PySetObject *so, PyObject *other)
18461891

18471892
if (!PyAnySet_Check(other))
18481893
Py_RETURN_NOTIMPLEMENTED;
1894+
1895+
Py_BEGIN_CRITICAL_SECTION2(so, other);
18491896
result = set_symmetric_difference_update(so, other);
1897+
Py_END_CRITICAL_SECTION2();
1898+
18501899
if (result == NULL)
18511900
return NULL;
18521901
Py_DECREF(result);

0 commit comments

Comments
 (0)