Skip to content

Commit 5f352a3

Browse files
committed
make ob_exports non-atomic everywhere
1 parent cc8d715 commit 5f352a3

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

Modules/arraymodule.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ array_resize(arrayobject *self, Py_ssize_t newsize)
151151
char *items;
152152
size_t _new_size;
153153

154-
if (FT_ATOMIC_LOAD_SSIZE_RELAXED(self->ob_exports) > 0 &&
155-
newsize != Py_SIZE(self)) {
154+
if (self->ob_exports > 0 && newsize != Py_SIZE(self)) {
156155
PyErr_SetString(PyExc_BufferError,
157156
"cannot resize an array that is exporting buffers");
158157
return -1;
@@ -746,7 +745,7 @@ array_dealloc(PyObject *op)
746745
PyObject_GC_UnTrack(op);
747746

748747
arrayobject *self = arrayobject_CAST(op);
749-
if (FT_ATOMIC_LOAD_SSIZE_RELAXED(self->ob_exports) > 0) {
748+
if (self->ob_exports > 0) {
750749
PyErr_SetString(PyExc_SystemError,
751750
"deallocated array object has exported buffers");
752751
PyErr_Print();
@@ -1093,7 +1092,7 @@ array_del_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
10931092
/* Issue #4509: If the array has exported buffers and the slice
10941093
assignment would change the size of the array, fail early to make
10951094
sure we don't modify it. */
1096-
if (d != 0 && FT_ATOMIC_LOAD_SSIZE_RELAXED(a->ob_exports) > 0) {
1095+
if (d != 0 && a->ob_exports > 0) {
10971096
PyErr_SetString(PyExc_BufferError,
10981097
"cannot resize an array that is exporting buffers");
10991098
return -1;
@@ -2726,8 +2725,7 @@ array_ass_subscr_lock_held(PyObject *op, PyObject* item, PyObject* value)
27262725
/* Issue #4509: If the array has exported buffers and the slice
27272726
assignment would change the size of the array, fail early to make
27282727
sure we don't modify it. */
2729-
if ((needed == 0 || slicelength != needed) &&
2730-
FT_ATOMIC_LOAD_SSIZE_RELAXED(self->ob_exports) > 0) {
2728+
if ((needed == 0 || slicelength != needed) && self->ob_exports > 0) {
27312729
PyErr_SetString(PyExc_BufferError,
27322730
"cannot resize an array that is exporting buffers");
27332731
return -1;
@@ -2864,11 +2862,7 @@ array_buffer_getbuf_lock_held(PyObject *op, Py_buffer *view, int flags)
28642862
#endif
28652863
}
28662864

2867-
#ifdef Py_GIL_DISABLED
2868-
_Py_atomic_add_ssize(&self->ob_exports, 1);
2869-
#else
28702865
self->ob_exports++;
2871-
#endif
28722866
return 0;
28732867
}
28742868

@@ -2885,13 +2879,11 @@ array_buffer_getbuf(PyObject *op, Py_buffer *view, int flags)
28852879
static void
28862880
array_buffer_relbuf(PyObject *op, Py_buffer *Py_UNUSED(view))
28872881
{
2882+
Py_BEGIN_CRITICAL_SECTION(op);
28882883
arrayobject *self = arrayobject_CAST(op);
2889-
#ifdef Py_GIL_DISABLED
2890-
assert(_Py_atomic_add_ssize(&self->ob_exports, -1) >= 1);
2891-
#else
28922884
self->ob_exports--;
28932885
assert(self->ob_exports >= 0);
2894-
#endif
2886+
Py_END_CRITICAL_SECTION();
28952887
}
28962888

28972889
static PyObject *

0 commit comments

Comments
 (0)