Skip to content

Commit 5a17b2e

Browse files
gh-114258: Use Argument Clinic for __add__/__iadd__ (GH-160051)
1 parent dbd0d9b commit 5a17b2e

6 files changed

Lines changed: 56 additions & 29 deletions

File tree

‎Modules/_collectionsmodule.c‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,18 @@ deque___copy___impl(dequeobject *deque)
674674
return deque_copy_impl(deque);
675675
}
676676

677+
/*[clinic input]
678+
@critical_section
679+
_collections.deque.__add__ as deque_concat
680+
681+
deque: dequeobject
682+
other: object
683+
/
684+
[clinic start generated code]*/
685+
677686
static PyObject *
678-
deque_concat_lock_held(dequeobject *deque, PyObject *other)
687+
deque_concat_impl(dequeobject *deque, PyObject *other)
688+
/*[clinic end generated code: output=fa6c28f7752f0b28 input=1816c51a4c6c4f05]*/
679689
{
680690
PyObject *new_deque, *result;
681691
int rv;
@@ -706,17 +716,6 @@ deque_concat_lock_held(dequeobject *deque, PyObject *other)
706716
return new_deque;
707717
}
708718

709-
static PyObject *
710-
deque_concat(PyObject *self, PyObject *other)
711-
{
712-
dequeobject *deque = dequeobject_CAST(self);
713-
PyObject *result;
714-
Py_BEGIN_CRITICAL_SECTION(deque);
715-
result = deque_concat_lock_held(deque, other);
716-
Py_END_CRITICAL_SECTION();
717-
return result;
718-
}
719-
720719
static int
721720
deque_clear(PyObject *self)
722721
{

‎Modules/clinic/_collectionsmodule.c.h‎

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Objects/bytearrayobject.c‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,19 @@ bytearray_length(PyObject *op)
403403
return PyByteArray_GET_SIZE(op);
404404
}
405405

406+
/*[clinic input]
407+
@critical_section
408+
bytearray.__iadd__ as bytearray_iconcat
409+
410+
other: object
411+
/
412+
[clinic start generated code]*/
413+
406414
static PyObject *
407-
bytearray_iconcat_lock_held(PyObject *op, PyObject *other)
415+
bytearray_iconcat_impl(PyByteArrayObject *self, PyObject *other)
416+
/*[clinic end generated code: output=ba172f2db8f7a8dd input=5b6fb07ab387084d]*/
408417
{
409-
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);
410-
PyByteArrayObject *self = _PyByteArray_CAST(op);
418+
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
411419

412420
Py_buffer vo;
413421
if (PyObject_GetBuffer(other, &vo, PyBUF_SIMPLE) != 0) {
@@ -432,16 +440,6 @@ bytearray_iconcat_lock_held(PyObject *op, PyObject *other)
432440
return Py_NewRef(self);
433441
}
434442

435-
static PyObject *
436-
bytearray_iconcat(PyObject *op, PyObject *other)
437-
{
438-
PyObject *ret;
439-
Py_BEGIN_CRITICAL_SECTION(op);
440-
ret = bytearray_iconcat_lock_held(op, other);
441-
Py_END_CRITICAL_SECTION();
442-
return ret;
443-
}
444-
445443
/*[clinic input]
446444
@critical_section
447445
bytearray.__mul__ as bytearray_repeat

‎Objects/clinic/bytearrayobject.c.h‎

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Tools/clinic/libclinic/dsl_parser.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
unsupported_special_methods: set[str] = set("""
4141
4242
__abs__
43-
__add__
4443
__and__
4544
__call__
4645
__delitem__
@@ -54,7 +53,6 @@
5453
__getitem__
5554
__gt__
5655
__hash__
57-
__iadd__
5856
__iand__
5957
__ifloordiv__
6058
__ilshift__

‎Tools/clinic/libclinic/slots.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def make_return_converter(self) -> CReturnConverter:
4040
SLOTS: Final[dict[str, SlotSpec]] = {
4141
'__next__': SlotSpec(return_converter='object'),
4242
'__len__': SlotSpec(return_converter='Py_ssize_t'),
43+
'__add__': SlotSpec(return_converter='object'),
44+
'__iadd__': SlotSpec(return_converter='object'),
4345
'__mul__': SlotSpec(return_converter='object'),
4446
'__imul__': SlotSpec(return_converter='object'),
4547
'__repr__': SlotSpec(return_converter='object'),

0 commit comments

Comments
 (0)