Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7c8edcd
gh-128942: make arraymodule.c free-thread safe
tom-pytel Jan 17, 2025
b4c38d6
📜🤖 Added by blurb_it.
blurb-it[bot] Jan 17, 2025
523c049
Update 2025-01-17-13-53-32.gh-issue-128942.DxzaIg.rst
tom-pytel Jan 17, 2025
714da01
Update 2025-01-17-13-53-32.gh-issue-128942.DxzaIg.rst
tom-pytel Jan 17, 2025
6893468
refactor array methods to established patterns
tom-pytel Jan 17, 2025
65b4a63
made arrayiter freethread safe
tom-pytel Jan 17, 2025
761d27a
cleanup to match other segfault fix PR
tom-pytel Jan 17, 2025
0bcd3c7
style nit from other PR
tom-pytel Jan 17, 2025
5676c92
add _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED()
tom-pytel Jan 17, 2025
c18290c
misc style
tom-pytel Jan 17, 2025
6ee2303
misc cleanups
tom-pytel Jan 18, 2025
7d5de1f
misc
tom-pytel Jan 18, 2025
02fc79c
Merge branch 'main' into fix-issue-128942
tom-pytel Jan 18, 2025
0ad9800
3 og 4 requested changes
tom-pytel Jan 18, 2025
325c241
not locking bytes
tom-pytel Jan 18, 2025
7958c55
array_array_frombytes get buffer from clinic
tom-pytel Jan 18, 2025
0532d93
more safe
tom-pytel Jan 19, 2025
6afec34
protect ob_exports exclusively with critical section
tom-pytel Jan 20, 2025
f0d5824
Merge branch 'main' into fix-issue-128942
tom-pytel Jan 20, 2025
f4058c5
Merge branch 'main' into fix-issue-128942
tom-pytel Jan 20, 2025
1bf45fc
fix clinic stuff that seems to have changed
tom-pytel Jan 20, 2025
6e7b65a
Merge branch 'main' into fix-issue-128942
tom-pytel Jan 20, 2025
bb4bf90
iterator safe from multi-crit deadlocks
tom-pytel Jan 20, 2025
4d5bb3a
remove unnecessary crit sect in setstate
tom-pytel Jan 21, 2025
e50e653
protect ob_exports atomically
tom-pytel Jan 22, 2025
841a870
2 missed misc atomic writes
tom-pytel Jan 23, 2025
a0e36db
Merge branch 'main' into fix-issue-128942
tom-pytel Feb 12, 2025
d80c1a5
misc tweaks
tom-pytel Feb 12, 2025
9aa4540
Merge branch 'main' into fix-issue-128942
tom-pytel Feb 12, 2025
dffc9cd
add test
tom-pytel Feb 12, 2025
b3665fd
misc fix, b'\xdd' -> 0xdd
tom-pytel Feb 12, 2025
3814e53
use support.Py_GIL_DISABLED
tom-pytel Feb 14, 2025
cb0345f
Merge branch 'main' into fix-issue-128942
tom-pytel Feb 15, 2025
4a5c568
add critical section held assertions
tom-pytel Feb 15, 2025
cc8d715
Py_CLEAR(it->ao)
tom-pytel Feb 15, 2025
5f352a3
make ob_exports non-atomic everywhere
tom-pytel Feb 15, 2025
98f1433
check type before lock in array_ass_subscr()
tom-pytel Feb 16, 2025
2a45a44
Merge branch 'main' into fix-issue-128942
tom-pytel Feb 16, 2025
c0799be
Merge branch 'main' into fix-issue-128942
kumaraditya303 Feb 27, 2025
0bcde5c
simplify array_arrayiterator___reduce___impl
kumaraditya303 Feb 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
misc cleanups
  • Loading branch information
tom-pytel committed Jan 18, 2025
commit 6ee23038929b8fcdd0881adcc077144b6fcea1bd
51 changes: 20 additions & 31 deletions Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1236,18 +1236,6 @@ array_inplace_repeat(arrayobject *self, Py_ssize_t n)
}


static PyObject *
ins(arrayobject *self, Py_ssize_t where, PyObject *v)
{
int res;
Py_BEGIN_CRITICAL_SECTION(self);
res = ins1(self, where, v);
Py_END_CRITICAL_SECTION();
if (res != 0)
return NULL;
Py_RETURN_NONE;
}

/*[clinic input]
@critical_section
array.array.count
Expand Down Expand Up @@ -1457,6 +1445,7 @@ array_array_extend_impl(arrayobject *self, PyTypeObject *cls, PyObject *bb)
}

/*[clinic input]
@critical_section
array.array.insert

i: Py_ssize_t
Expand All @@ -1468,9 +1457,11 @@ Insert a new item v into the array before position i.

static PyObject *
array_array_insert_impl(arrayobject *self, Py_ssize_t i, PyObject *v)
/*[clinic end generated code: output=5a3648e278348564 input=5577d1b4383e9313]*/
/*[clinic end generated code: output=5a3648e278348564 input=3c922bbd81462978]*/
{
return ins(self, i, v);
if (ins1(self, i, v) != 0)
return NULL;
Py_RETURN_NONE;
}

/*[clinic input]
Expand Down Expand Up @@ -1511,6 +1502,7 @@ array_array_buffer_info_impl(arrayobject *self)
}

/*[clinic input]
@critical_section
array.array.append

v: object
Expand All @@ -1520,10 +1512,12 @@ Append new value v to the end of the array.
[clinic start generated code]*/

static PyObject *
array_array_append(arrayobject *self, PyObject *v)
/*[clinic end generated code: output=745a0669bf8db0e2 input=0b98d9d78e78f0fa]*/
array_array_append_impl(arrayobject *self, PyObject *v)
/*[clinic end generated code: output=2f1e8cbad70c2a8b input=9cdd897c66a40c3f]*/
{
return ins(self, Py_SIZE(self), v);
if (ins1(self, Py_SIZE(self), v) != 0)
return NULL;
Py_RETURN_NONE;
}

/*[clinic input]
Expand Down Expand Up @@ -1810,7 +1804,7 @@ array_array_tolist_impl(arrayobject *self)


static PyObject *
frombytes_lock_held(arrayobject *self, PyObject *bytes)
array_array_frombytes_lock_held(arrayobject *self, PyObject *bytes)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(bytes);
Expand Down Expand Up @@ -1851,17 +1845,8 @@ frombytes_lock_held(arrayobject *self, PyObject *bytes)
Py_RETURN_NONE;
}

static PyObject *
frombytes(arrayobject *self, PyObject *bytes)
{
PyObject *ret;
Py_BEGIN_CRITICAL_SECTION2(self, bytes);
ret = frombytes_lock_held(self, bytes);
Py_END_CRITICAL_SECTION2();
return ret;
}

/*[clinic input]
@critical_section self bytes
array.array.frombytes

bytes: object
Comment thread
tom-pytel marked this conversation as resolved.
Outdated
Expand All @@ -1871,10 +1856,10 @@ Appends items from the string, interpreting it as an array of machine values, as
[clinic start generated code]*/

static PyObject *
array_array_frombytes(arrayobject *self, PyObject *bytes)
/*[clinic end generated code: output=3d8413868a91ec1f input=9fcb15a49b73d960]*/
array_array_frombytes_impl(arrayobject *self, PyObject *bytes)
/*[clinic end generated code: output=8a48da6fa2f9dcde input=f8d97acc9f269f7b]*/
{
return frombytes(self, bytes);
return array_array_frombytes_lock_held(self, bytes);
}

/*[clinic input]
Expand Down Expand Up @@ -2651,9 +2636,11 @@ static int
array_ass_subscr_lock_held(arrayobject* self, PyObject* item, PyObject* value)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
#ifdef Py_DEBUG
if (value != NULL) {
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(value);
}
#endif
Py_ssize_t start, stop, step, slicelength, needed;
array_state* state = find_array_state_by_type(Py_TYPE(self));
arrayobject* other;
Expand Down Expand Up @@ -2880,9 +2867,11 @@ array_buffer_relbuf(arrayobject *self, Py_buffer *view)
static PyObject *
array_new_internal_lock_held(PyTypeObject *type, PyObject *initial, int c)
{
#ifdef Py_DEBUG
if (initial != NULL) {
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(initial);
}
#endif
array_state *state = find_array_state_by_type(type);
PyObject *it = NULL;
const struct arraydescr *descr;
Expand Down
34 changes: 33 additions & 1 deletion Modules/clinic/arraymodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.