diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 64f8fa9ab4041fb..f62972ac8e4901f 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -674,8 +674,18 @@ deque___copy___impl(dequeobject *deque) return deque_copy_impl(deque); } +/*[clinic input] +@critical_section +_collections.deque.__add__ as deque_concat + + deque: dequeobject + other: object + / +[clinic start generated code]*/ + static PyObject * -deque_concat_lock_held(dequeobject *deque, PyObject *other) +deque_concat_impl(dequeobject *deque, PyObject *other) +/*[clinic end generated code: output=fa6c28f7752f0b28 input=1816c51a4c6c4f05]*/ { PyObject *new_deque, *result; int rv; @@ -706,17 +716,6 @@ deque_concat_lock_held(dequeobject *deque, PyObject *other) return new_deque; } -static PyObject * -deque_concat(PyObject *self, PyObject *other) -{ - dequeobject *deque = dequeobject_CAST(self); - PyObject *result; - Py_BEGIN_CRITICAL_SECTION(deque); - result = deque_concat_lock_held(deque, other); - Py_END_CRITICAL_SECTION(); - return result; -} - static int deque_clear(PyObject *self) { diff --git a/Modules/clinic/_collectionsmodule.c.h b/Modules/clinic/_collectionsmodule.c.h index cef17347078fe4e..7545d22b21e655c 100644 --- a/Modules/clinic/_collectionsmodule.c.h +++ b/Modules/clinic/_collectionsmodule.c.h @@ -202,6 +202,21 @@ deque___copy__(PyObject *deque, PyObject *Py_UNUSED(ignored)) return return_value; } +static PyObject * +deque_concat_impl(dequeobject *deque, PyObject *other); + +static PyObject * +deque_concat(PyObject *deque, PyObject *other) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(deque); + return_value = deque_concat_impl((dequeobject *)deque, other); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + PyDoc_STRVAR(deque_clearmethod__doc__, "clear($self, /)\n" "--\n" @@ -662,4 +677,4 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=fe575846d0131efd input=a9049054013a1b77]*/ +/*[clinic end generated code: output=761d85edf8291792 input=a9049054013a1b77]*/ diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 5abd0fd235f030e..9c0127ee4751b60 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -403,11 +403,19 @@ bytearray_length(PyObject *op) return PyByteArray_GET_SIZE(op); } +/*[clinic input] +@critical_section +bytearray.__iadd__ as bytearray_iconcat + + other: object + / +[clinic start generated code]*/ + static PyObject * -bytearray_iconcat_lock_held(PyObject *op, PyObject *other) +bytearray_iconcat_impl(PyByteArrayObject *self, PyObject *other) +/*[clinic end generated code: output=ba172f2db8f7a8dd input=5b6fb07ab387084d]*/ { - _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op); - PyByteArrayObject *self = _PyByteArray_CAST(op); + _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self); Py_buffer vo; if (PyObject_GetBuffer(other, &vo, PyBUF_SIMPLE) != 0) { @@ -432,16 +440,6 @@ bytearray_iconcat_lock_held(PyObject *op, PyObject *other) return Py_NewRef(self); } -static PyObject * -bytearray_iconcat(PyObject *op, PyObject *other) -{ - PyObject *ret; - Py_BEGIN_CRITICAL_SECTION(op); - ret = bytearray_iconcat_lock_held(op, other); - Py_END_CRITICAL_SECTION(); - return ret; -} - /*[clinic input] @critical_section bytearray.__mul__ as bytearray_repeat diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index a41866b40f80555..e130ced76a93fe6 100644 --- a/Objects/clinic/bytearrayobject.c.h +++ b/Objects/clinic/bytearrayobject.c.h @@ -11,6 +11,21 @@ preserve #include "pycore_runtime.h" // _Py_SINGLETON() #include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL() +static PyObject * +bytearray_iconcat_impl(PyByteArrayObject *self, PyObject *other); + +static PyObject * +bytearray_iconcat(PyObject *self, PyObject *other) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(self); + return_value = bytearray_iconcat_impl((PyByteArrayObject *)self, other); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + static PyObject * bytearray_repeat_impl(PyByteArrayObject *self, Py_ssize_t count); @@ -2007,4 +2022,4 @@ bytearray_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return bytearray_sizeof_impl((PyByteArrayObject *)self); } -/*[clinic end generated code: output=a1a91ef777ab985f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f57debf4b0a990ca input=a9049054013a1b77]*/ diff --git a/Tools/clinic/libclinic/dsl_parser.py b/Tools/clinic/libclinic/dsl_parser.py index f40b17408ba1eb1..a3512b9522322ab 100644 --- a/Tools/clinic/libclinic/dsl_parser.py +++ b/Tools/clinic/libclinic/dsl_parser.py @@ -40,7 +40,6 @@ unsupported_special_methods: set[str] = set(""" __abs__ -__add__ __and__ __call__ __delitem__ @@ -54,7 +53,6 @@ __getitem__ __gt__ __hash__ -__iadd__ __iand__ __ifloordiv__ __ilshift__ diff --git a/Tools/clinic/libclinic/slots.py b/Tools/clinic/libclinic/slots.py index 4c14959d3598f0e..c5158cc57fc9407 100644 --- a/Tools/clinic/libclinic/slots.py +++ b/Tools/clinic/libclinic/slots.py @@ -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'), + '__add__': SlotSpec(return_converter='object'), + '__iadd__': SlotSpec(return_converter='object'), '__mul__': SlotSpec(return_converter='object'), '__imul__': SlotSpec(return_converter='object'), '__repr__': SlotSpec(return_converter='object'),