Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 12 additions & 13 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,18 @@ deque_clearmethod_impl(dequeobject *deque)
Py_RETURN_NONE;
}

/*[clinic input]
@critical_section
_collections.deque.__imul__ as deque_inplace_repeat

deque: dequeobject
n: Py_ssize_t
/
[clinic start generated code]*/

static PyObject *
deque_inplace_repeat_lock_held(dequeobject *deque, Py_ssize_t n)
deque_inplace_repeat_impl(dequeobject *deque, Py_ssize_t n)
/*[clinic end generated code: output=e9052495a8eb46f9 input=0ebbaedad03b8abf]*/
{
Py_ssize_t i, m, size;
PyObject *seq;
Expand Down Expand Up @@ -896,17 +906,6 @@ deque_inplace_repeat_lock_held(dequeobject *deque, Py_ssize_t n)
return (PyObject *)deque;
}

static PyObject *
deque_inplace_repeat(PyObject *self, Py_ssize_t n)
{
dequeobject *deque = dequeobject_CAST(self);
PyObject *result;
Py_BEGIN_CRITICAL_SECTION(deque);
result = deque_inplace_repeat_lock_held(deque, n);
Py_END_CRITICAL_SECTION();
return result;
}

static PyObject *
deque_repeat(PyObject *self, Py_ssize_t n)
{
Expand All @@ -921,7 +920,7 @@ deque_repeat(PyObject *self, Py_ssize_t n)
return NULL;
// It's safe to not acquire the per-object lock for new_deque; it's
// invisible to other threads.
rv = deque_inplace_repeat_lock_held(new_deque, n);
rv = deque_inplace_repeat_impl(new_deque, n);
Py_DECREF(new_deque);
return rv;
}
Expand Down
17 changes: 16 additions & 1 deletion Modules/clinic/_collectionsmodule.c.h

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

46 changes: 21 additions & 25 deletions Objects/bytearrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,19 @@ bytearray_iconcat(PyObject *op, PyObject *other)
return ret;
}

/*[clinic input]
@critical_section
bytearray.__mul__ as bytearray_repeat

count: Py_ssize_t
/
[clinic start generated code]*/

static PyObject *
bytearray_repeat_lock_held(PyObject *op, Py_ssize_t count)
bytearray_repeat_impl(PyByteArrayObject *self, Py_ssize_t count)
/*[clinic end generated code: output=0889e9ebbe61890a input=3363528e6db1f39b]*/
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);
PyByteArrayObject *self = _PyByteArray_CAST(op);
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
if (count < 0) {
count = 0;
}
Expand All @@ -464,21 +472,19 @@ bytearray_repeat_lock_held(PyObject *op, Py_ssize_t count)
return (PyObject *)result;
}

static PyObject *
bytearray_repeat(PyObject *op, Py_ssize_t count)
{
PyObject *ret;
Py_BEGIN_CRITICAL_SECTION(op);
ret = bytearray_repeat_lock_held(op, count);
Py_END_CRITICAL_SECTION();
return ret;
}
/*[clinic input]
@critical_section
bytearray.__imul__ as bytearray_irepeat

count: Py_ssize_t
/
[clinic start generated code]*/

static PyObject *
bytearray_irepeat_lock_held(PyObject *op, Py_ssize_t count)
bytearray_irepeat_impl(PyByteArrayObject *self, Py_ssize_t count)
/*[clinic end generated code: output=4cfee919b3489219 input=e12991c89153490b]*/
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);
PyByteArrayObject *self = _PyByteArray_CAST(op);
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
if (count < 0) {
count = 0;
}
Expand All @@ -501,16 +507,6 @@ bytearray_irepeat_lock_held(PyObject *op, Py_ssize_t count)
return Py_NewRef(self);
}

static PyObject *
bytearray_irepeat(PyObject *op, Py_ssize_t count)
{
PyObject *ret;
Py_BEGIN_CRITICAL_SECTION(op);
ret = bytearray_irepeat_lock_held(op, count);
Py_END_CRITICAL_SECTION();
return ret;
}

static PyObject *
bytearray_getitem_lock_held(PyObject *op, Py_ssize_t i)
{
Expand Down
32 changes: 31 additions & 1 deletion Objects/clinic/bytearrayobject.c.h

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

32 changes: 31 additions & 1 deletion Objects/clinic/listobject.c.h

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

45 changes: 23 additions & 22 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,18 @@ _PyList_Concat(PyObject *aa, PyObject *bb)
return ret;
}

/*[clinic input]
@critical_section
list.__mul__ as list_repeat

a: self(type="PyListObject *")
n: Py_ssize_t
/
[clinic start generated code]*/

static PyObject *
list_repeat_lock_held(PyListObject *a, Py_ssize_t n)
list_repeat_impl(PyListObject *a, Py_ssize_t n)
/*[clinic end generated code: output=65bb40ed76d3e733 input=dfef16e067b2abb6]*/
{
const Py_ssize_t input_size = Py_SIZE(a);
if (input_size == 0 || n <= 0)
Expand Down Expand Up @@ -911,17 +921,6 @@ list_repeat_lock_held(PyListObject *a, Py_ssize_t n)
return (PyObject *) np;
}

static PyObject *
list_repeat(PyObject *aa, Py_ssize_t n)
{
PyObject *ret;
PyListObject *a = (PyListObject *)aa;
Py_BEGIN_CRITICAL_SECTION(a);
ret = list_repeat_lock_held(a, n);
Py_END_CRITICAL_SECTION();
return ret;
}

static void
list_clear_impl(PyListObject *a, bool is_resize)
{
Expand Down Expand Up @@ -1171,20 +1170,22 @@ list_inplace_repeat_lock_held(PyListObject *self, Py_ssize_t n)
return 0;
}

/*[clinic input]
@critical_section
list.__imul__ as list_inplace_repeat

n: Py_ssize_t
/
[clinic start generated code]*/

static PyObject *
list_inplace_repeat(PyObject *_self, Py_ssize_t n)
list_inplace_repeat_impl(PyListObject *self, Py_ssize_t n)
/*[clinic end generated code: output=d318a9f047b4fcaf input=530d74de0e4a61f0]*/
{
PyObject *ret;
PyListObject *self = (PyListObject *) _self;
Py_BEGIN_CRITICAL_SECTION(self);
if (list_inplace_repeat_lock_held(self, n) < 0) {
ret = NULL;
}
else {
ret = Py_NewRef(self);
return NULL;
}
Py_END_CRITICAL_SECTION();
return ret;
return Py_NewRef(self);
}

/*[clinic input]
Expand Down
2 changes: 0 additions & 2 deletions Tools/clinic/libclinic/dsl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
__ilshift__
__imatmul__
__imod__
__imul__
__index__
__int__
__invert__
Expand All @@ -76,7 +75,6 @@
__lt__
__matmul__
__mod__
__mul__
__neg__
__or__
__pos__
Expand Down
2 changes: 2 additions & 0 deletions Tools/clinic/libclinic/slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def make_return_converter(self) -> CReturnConverter:
SLOTS: Final[dict[str, SlotSpec]] = {
'__next__': SlotSpec(return_converter='object'),
'__len__': SlotSpec(return_converter='Py_ssize_t'),
'__mul__': SlotSpec(return_converter='object'),
'__imul__': SlotSpec(return_converter='object'),
'__repr__': SlotSpec(return_converter='object'),
'__setitem__': SlotSpec(return_converter='int'),
}
Loading