diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 8293003f8ce925c..1860d9eae95e29c 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -34,7 +34,7 @@ from libclinic.return_converters import return_converters, int_return_converter from libclinic.block_parser import Block, BlockParser from libclinic.codegen import BlockPrinter, Destination - from libclinic.dsl_parser import DSLParser, unsupported_special_methods + from libclinic.dsl_parser import DSLParser from libclinic.slots import SlotSpec, SLOTS from libclinic.cli import parse_file, Clinic @@ -3368,8 +3368,8 @@ class Foo "FooObject *" "" self.assertIn("METH_COEXIST", function.methoddef_flags) def test_slot_parameters(self): - # __getitem__ is not supported yet; its parameter gives the slot - # (Py_ssize_t for sq_item, object for mp_subscript) and is not parsed. + # The parameter of __getitem__ gives the slot (Py_ssize_t for + # sq_item, object for mp_subscript) and is not parsed. block = """ module foo class Foo "FooObject *" "" @@ -3383,21 +3383,17 @@ class Foo "FooObject *" "" ("Foo.__getitem__\n key: object = None\n /", "The parameters of '__getitem__' cannot have a default value"), ] - supported = unsupported_special_methods - {'__getitem__'} - with (mock.patch.dict(SLOTS, {'__getitem__': SlotSpec(return_converter='object')}), - mock.patch.object(libclinic.dsl_parser, - 'unsupported_special_methods', supported)): - for converter in "Py_ssize_t", "object": - with self.subTest(converter=converter): - function = self.parse_function( - block.format(converter=converter), - signatures_in_block=3, function_index=2) - self.assertIs(function.kind, FunctionKind.SLOT) - self.assertEqual(list(function.parameters), ["self", "key"]) - for body, err in errors: - with self.subTest(block=body): - body = 'class Foo "FooObject *" "&Foo_Type"\n' + body - self.expect_failure(body, err) + for converter in ["Py_ssize_t", "object"]: + with self.subTest(converter=converter): + function = self.parse_function( + block.format(converter=converter), + signatures_in_block=3, function_index=2) + self.assertIs(function.kind, FunctionKind.SLOT) + self.assertEqual(list(function.parameters), ["self", "key"]) + for body, err in errors: + with self.subTest(block=body): + body = 'class Foo "FooObject *" "&Foo_Type"\n' + body + self.expect_failure(body, err) def test_slot_errors(self): cases = [ diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 1d8181e9299f144..0626cc6a70bc8f7 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -1376,8 +1376,17 @@ valid_index(Py_ssize_t i, Py_ssize_t limit) return (size_t) i < (size_t) limit; } +/*[clinic input] +@critical_section +_collections.deque.__getitem__ as deque_item + deque: dequeobject + i: Py_ssize_t + / +[clinic start generated code]*/ + static PyObject * -deque_item_lock_held(dequeobject *deque, Py_ssize_t i) +deque_item_impl(dequeobject *deque, Py_ssize_t i) +/*[clinic end generated code: output=52e62af1427d61ef input=89f14f06b29122a1]*/ { block *b; PyObject *item; @@ -1415,17 +1424,6 @@ deque_item_lock_held(dequeobject *deque, Py_ssize_t i) return Py_NewRef(item); } -static PyObject * -deque_item(PyObject *self, Py_ssize_t i) -{ - dequeobject *deque = dequeobject_CAST(self); - PyObject *result; - Py_BEGIN_CRITICAL_SECTION(deque); - result = deque_item_lock_held(deque, i); - Py_END_CRITICAL_SECTION(); - return result; -} - static int deque_del_item(dequeobject *deque, Py_ssize_t i) { diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index af3748a0124ec51..bbd744cdba8b38e 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -5026,8 +5026,17 @@ Array_init(PyObject *self, PyObject *args, PyObject *kw) return 0; } +/*[clinic input] +@critical_section +_ctypes.Array.__getitem__ as Array_item + myself: self + index: Py_ssize_t + / +[clinic start generated code]*/ + static PyObject * -Array_item_lock_held(PyObject *myself, Py_ssize_t index) +Array_item_impl(PyObject *myself, Py_ssize_t index) +/*[clinic end generated code: output=d038162d727d7d9b input=68fa9889c77bb8c9]*/ { _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(myself); @@ -5056,18 +5065,17 @@ Array_item_lock_held(PyObject *myself, Py_ssize_t index) index, size, self->b_ptr + offset); } -static PyObject * -Array_item(PyObject *myself, Py_ssize_t index) -{ - PyObject *result; - Py_BEGIN_CRITICAL_SECTION(myself); - result = Array_item_lock_held(myself, index); - Py_END_CRITICAL_SECTION(); - return result; -} +/*[clinic input] +@critical_section +_ctypes.Array.__getitem__ as Array_subscript + myself: self + item: object + / +[clinic start generated code]*/ static PyObject * -Array_subscript_lock_held(PyObject *myself, PyObject *item) +Array_subscript_impl(PyObject *myself, PyObject *item) +/*[clinic end generated code: output=5c88d612ad5c8a1a input=510935495a857cac]*/ { _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(myself); @@ -5080,7 +5088,7 @@ Array_subscript_lock_held(PyObject *myself, PyObject *item) return NULL; if (i < 0) i += self->b_length; - return Array_item_lock_held(myself, i); + return Array_item_impl(myself, i); } else if (PySlice_Check(item)) { PyObject *proto; @@ -5168,7 +5176,7 @@ Array_subscript_lock_held(PyObject *myself, PyObject *item) for (cur = start, i = 0; i < slicelen; cur += step, i++) { - PyObject *v = Array_item_lock_held(myself, cur); + PyObject *v = Array_item_impl(myself, cur); if (v == NULL) { Py_DECREF(np); return NULL; @@ -5185,16 +5193,6 @@ Array_subscript_lock_held(PyObject *myself, PyObject *item) } -static PyObject * -Array_subscript(PyObject *myself, PyObject *item) -{ - PyObject *result; - Py_BEGIN_CRITICAL_SECTION(myself); - result = Array_subscript_lock_held(myself, item); - Py_END_CRITICAL_SECTION(); - return result; -} - /*[clinic input] @critical_section _ctypes.Array.__setitem__ as Array_ass_item @@ -5577,8 +5575,22 @@ static PyType_Spec pycsimple_spec = { /* PyCPointer_Type */ +/*[clinic input] +class _ctypes._Pointer "PyObject *" "clinic_state()->PyCPointer_Type" +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=452695db70aa7c3e]*/ + +/*[clinic input] +@critical_section +_ctypes._Pointer.__getitem__ as Pointer_item + myself: self + index: Py_ssize_t + / +[clinic start generated code]*/ + static PyObject * -Pointer_item_lock_held(PyObject *myself, Py_ssize_t index) +Pointer_item_impl(PyObject *myself, Py_ssize_t index) +/*[clinic end generated code: output=4ae9d566e8038853 input=17943427cd04ed08]*/ { CDataObject *self = _CDataObject_CAST(myself); _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self); @@ -5617,21 +5629,6 @@ Pointer_item_lock_held(PyObject *myself, Py_ssize_t index) index, size, (char *)((char *)deref + offset)); } -static PyObject * -Pointer_item(PyObject *self, Py_ssize_t index) -{ - PyObject *res; - Py_BEGIN_CRITICAL_SECTION(self); - res = Pointer_item_lock_held(self, index); - Py_END_CRITICAL_SECTION(); - return res; -} - -/*[clinic input] -class _ctypes._Pointer "PyObject *" "clinic_state()->PyCPointer_Type" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=452695db70aa7c3e]*/ - /*[clinic input] @critical_section _ctypes._Pointer.__setitem__ as Pointer_ass_item @@ -5824,7 +5821,7 @@ copy_pointer_to_list_lock_held(PyObject *myself, PyObject *np, Py_ssize_t len, Py_ssize_t i; size_t cur; for (cur = start, i = 0; i < len; cur += step, i++) { - PyObject *v = Pointer_item_lock_held(myself, cur); + PyObject *v = Pointer_item_impl(myself, cur); if (!v) { return -1; } diff --git a/Modules/_ctypes/clinic/_ctypes.c.h b/Modules/_ctypes/clinic/_ctypes.c.h index 4eb89baab4b809f..adc1a6011b230b3 100644 --- a/Modules/_ctypes/clinic/_ctypes.c.h +++ b/Modules/_ctypes/clinic/_ctypes.c.h @@ -746,6 +746,36 @@ _ctypes_CFuncPtr_argtypes_get(PyObject *self, void *Py_UNUSED(context)) return return_value; } +static PyObject * +Array_item_impl(PyObject *myself, Py_ssize_t index); + +static PyObject * +Array_item(PyObject *myself, Py_ssize_t index) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(myself); + return_value = Array_item_impl(myself, index); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + +static PyObject * +Array_subscript_impl(PyObject *myself, PyObject *item); + +static PyObject * +Array_subscript(PyObject *myself, PyObject *item) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(myself); + return_value = Array_subscript_impl(myself, item); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + static int Array_ass_item_impl(PyObject *myself, Py_ssize_t index, PyObject *value); @@ -835,6 +865,21 @@ Simple_from_outparm(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py return Simple_from_outparm_impl(self, cls); } +static PyObject * +Pointer_item_impl(PyObject *myself, Py_ssize_t index); + +static PyObject * +Pointer_item(PyObject *myself, Py_ssize_t index) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(myself); + return_value = Pointer_item_impl(myself, index); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + static int Pointer_ass_item_impl(PyObject *myself, Py_ssize_t index, PyObject *value); @@ -863,4 +908,4 @@ Pointer_ass_item(PyObject *myself, Py_ssize_t index, PyObject *value) #define _CTYPES_SIMPLE_VALUE_GETSETDEF {"value", (getter)_ctypes_Simple_value_get, (setter)_ctypes_Simple_value_set, NULL}, -/*[clinic end generated code: output=f01123efc29f8ae0 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8fc24edc31ab60b5 input=a9049054013a1b77]*/ diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c index 7201973bf7f6ba8..4e9f7f1e2ccb5cb 100644 --- a/Modules/_dbmmodule.c +++ b/Modules/_dbmmodule.c @@ -187,12 +187,20 @@ dbm_bool(PyObject *self) return result; } +/*[clinic input] +@critical_section +_dbm.dbm.__getitem__ as dbm_subscript + key: object + / +[clinic start generated code]*/ + static PyObject * -dbm_subscript_lock_held(PyObject *self, PyObject *key) +dbm_subscript_impl(dbmobject *self, PyObject *key) +/*[clinic end generated code: output=6278465f3ff37eaa input=e748b684a0870527]*/ { datum drec, krec; Py_ssize_t tmp_size; - dbmobject *dp = dbmobject_CAST(self); + dbmobject *dp = self; _dbm_state *state = PyType_GetModuleState(Py_TYPE(dp)); assert(state != NULL); if (!PyArg_Parse(key, "s#", &krec.dptr, &tmp_size)) { @@ -214,16 +222,6 @@ dbm_subscript_lock_held(PyObject *self, PyObject *key) return PyBytes_FromStringAndSize(drec.dptr, drec.dsize); } -static PyObject * -dbm_subscript(PyObject *self, PyObject *key) -{ - PyObject *result; - Py_BEGIN_CRITICAL_SECTION(self); - result = dbm_subscript_lock_held(self, key); - Py_END_CRITICAL_SECTION(); - return result; -} - /*[clinic input] @critical_section _dbm.dbm.__setitem__ as dbm_ass_sub diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c index 69bad7e137e24a7..e730645cfac9e66 100644 --- a/Modules/_gdbmmodule.c +++ b/Modules/_gdbmmodule.c @@ -250,12 +250,20 @@ parse_datum(PyObject *o, datum *d, const char *failmsg) return 1; } +/*[clinic input] +@critical_section +_gdbm.gdbm.__getitem__ as gdbm_subscript + key: object + / +[clinic start generated code]*/ + static PyObject * -gdbm_subscript_lock_held(PyObject *op, PyObject *key) +gdbm_subscript_impl(gdbmobject *self, PyObject *key) +/*[clinic end generated code: output=e96388d53678e967 input=8324d90d97ae98f0]*/ { PyObject *v; datum drec, krec; - gdbmobject *dp = _gdbmobject_CAST(op); + gdbmobject *dp = self; _gdbm_state *state = PyType_GetModuleState(Py_TYPE(dp)); if (!parse_datum(key, &krec, NULL)) { @@ -276,16 +284,6 @@ gdbm_subscript_lock_held(PyObject *op, PyObject *key) return v; } -static PyObject * -gdbm_subscript(PyObject *op, PyObject *key) -{ - PyObject *result; - Py_BEGIN_CRITICAL_SECTION(op); - result = gdbm_subscript_lock_held(op, key); - Py_END_CRITICAL_SECTION(); - return result; -} - /*[clinic input] _gdbm.gdbm.get diff --git a/Modules/clinic/_collectionsmodule.c.h b/Modules/clinic/_collectionsmodule.c.h index a5f4962ccf4cb8c..2966d68aa3813b5 100644 --- a/Modules/clinic/_collectionsmodule.c.h +++ b/Modules/clinic/_collectionsmodule.c.h @@ -455,6 +455,21 @@ deque_insert(PyObject *deque, PyObject *const *args, Py_ssize_t nargs) return return_value; } +static PyObject * +deque_item_impl(dequeobject *deque, Py_ssize_t i); + +static PyObject * +deque_item(PyObject *deque, Py_ssize_t i) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(deque); + return_value = deque_item_impl((dequeobject *)deque, i); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + PyDoc_STRVAR(deque_remove__doc__, "remove($self, value, /)\n" "--\n" @@ -692,4 +707,4 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=fca551851f7a658e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=de400069cf6f11a4 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_dbmmodule.c.h b/Modules/clinic/_dbmmodule.c.h index d71aa1362a4d345..294730c7c90c8f5 100644 --- a/Modules/clinic/_dbmmodule.c.h +++ b/Modules/clinic/_dbmmodule.c.h @@ -21,6 +21,21 @@ dbm_length(PyObject *self) return return_value; } +static PyObject * +dbm_subscript_impl(dbmobject *self, PyObject *key); + +static PyObject * +dbm_subscript(PyObject *self, PyObject *key) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(self); + return_value = dbm_subscript_impl((dbmobject *)self, key); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + static int dbm_ass_sub_impl(dbmobject *self, PyObject *v, PyObject *w); @@ -294,4 +309,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=6ff4681a893c22ad input=a9049054013a1b77]*/ +/*[clinic end generated code: output=23fc8f92cd569b86 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_gdbmmodule.c.h b/Modules/clinic/_gdbmmodule.c.h index 062b6b0374664a2..6c3c8329b59bd85 100644 --- a/Modules/clinic/_gdbmmodule.c.h +++ b/Modules/clinic/_gdbmmodule.c.h @@ -21,6 +21,21 @@ gdbm_length(PyObject *self) return return_value; } +static PyObject * +gdbm_subscript_impl(gdbmobject *self, PyObject *key); + +static PyObject * +gdbm_subscript(PyObject *self, PyObject *key) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(self); + return_value = gdbm_subscript_impl((gdbmobject *)self, key); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + PyDoc_STRVAR(_gdbm_gdbm_get__doc__, "get($self, key, default=None, /)\n" "--\n" @@ -446,4 +461,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=10c193b33298877a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=8cc26c8a6790ecac input=a9049054013a1b77]*/ diff --git a/Modules/clinic/mmapmodule.c.h b/Modules/clinic/mmapmodule.c.h index 04c0aaff020d297..ece08c0fb6007c0 100644 --- a/Modules/clinic/mmapmodule.c.h +++ b/Modules/clinic/mmapmodule.c.h @@ -892,6 +892,36 @@ mmap_length(PyObject *self) return return_value; } +static PyObject * +mmap_item_impl(mmap_object *self, Py_ssize_t i); + +static PyObject * +mmap_item(PyObject *self, Py_ssize_t i) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(self); + return_value = mmap_item_impl((mmap_object *)self, i); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + +static PyObject * +mmap_subscript_impl(mmap_object *self, PyObject *item); + +static PyObject * +mmap_subscript(PyObject *self, PyObject *item) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(self); + return_value = mmap_subscript_impl((mmap_object *)self, item); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + static int mmap_ass_item_impl(mmap_object *self, Py_ssize_t i, PyObject *v); @@ -937,4 +967,4 @@ mmap_ass_subscript(PyObject *self, PyObject *item, PyObject *value) #ifndef MMAP_MMAP_MADVISE_METHODDEF #define MMAP_MMAP_MADVISE_METHODDEF #endif /* !defined(MMAP_MMAP_MADVISE_METHODDEF) */ -/*[clinic end generated code: output=fd4738a3d64fcb0a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=90a906cde591ab92 input=a9049054013a1b77]*/ diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 0bc959a28f6f718..ce5c59cb0212707 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -1498,10 +1498,17 @@ mmap_length_impl(mmap_object *self) return self->size; } +/*[clinic input] +@critical_section +mmap.mmap.__getitem__ as mmap_item + i: Py_ssize_t + / +[clinic start generated code]*/ + static PyObject * -mmap_item_lock_held(PyObject *op, Py_ssize_t i) +mmap_item_impl(mmap_object *self, Py_ssize_t i) +/*[clinic end generated code: output=70bd231b581a7bc1 input=af6ad504b5fcd499]*/ { - mmap_object *self = mmap_object_CAST(op); CHECK_VALID(NULL); if (i < 0 || i >= self->size) { PyErr_SetString(PyExc_IndexError, "mmap index out of range"); @@ -1515,19 +1522,17 @@ mmap_item_lock_held(PyObject *op, Py_ssize_t i) return PyBytes_FromStringAndSize(&dest, 1); } -static PyObject * -mmap_item(PyObject *op, Py_ssize_t i) { - PyObject *result; - Py_BEGIN_CRITICAL_SECTION(op); - result = mmap_item_lock_held(op, i); - Py_END_CRITICAL_SECTION(); - return result; -} +/*[clinic input] +@critical_section +mmap.mmap.__getitem__ as mmap_subscript + item: object + / +[clinic start generated code]*/ static PyObject * -mmap_subscript_lock_held(PyObject *op, PyObject *item) +mmap_subscript_impl(mmap_object *self, PyObject *item) +/*[clinic end generated code: output=cd6ccc1eb3399f98 input=72f708669823dbba]*/ { - mmap_object *self = mmap_object_CAST(op); CHECK_VALID(NULL); if (PyIndex_Check(item)) { Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); @@ -1587,16 +1592,6 @@ mmap_subscript_lock_held(PyObject *op, PyObject *item) } } -static PyObject * -mmap_subscript(PyObject *op, PyObject *item) -{ - PyObject *result; - Py_BEGIN_CRITICAL_SECTION(op); - result = mmap_subscript_lock_held(op, item); - Py_END_CRITICAL_SECTION(); - return result; -} - /*[clinic input] @critical_section mmap.mmap.__setitem__ as mmap_ass_item diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 9c0127ee4751b60..4a2f088a246c3e7 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -505,11 +505,18 @@ bytearray_irepeat_impl(PyByteArrayObject *self, Py_ssize_t count) return Py_NewRef(self); } +/*[clinic input] +@critical_section +bytearray.__getitem__ as bytearray_getitem + i: Py_ssize_t + / +[clinic start generated code]*/ + static PyObject * -bytearray_getitem_lock_held(PyObject *op, Py_ssize_t i) +bytearray_getitem_impl(PyByteArrayObject *self, Py_ssize_t i) +/*[clinic end generated code: output=743cb7a5f892f7ed input=f90e2c70f80e2917]*/ { - _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op); - PyByteArrayObject *self = _PyByteArray_CAST(op); + _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self); if (i < 0 || i >= Py_SIZE(self)) { PyErr_SetString(PyExc_IndexError, "bytearray index out of range"); return NULL; @@ -517,16 +524,6 @@ bytearray_getitem_lock_held(PyObject *op, Py_ssize_t i) return _PyLong_FromUnsignedChar((unsigned char)(self->ob_start[i])); } -static PyObject * -bytearray_getitem(PyObject *op, Py_ssize_t i) -{ - PyObject *ret; - Py_BEGIN_CRITICAL_SECTION(op); - ret = bytearray_getitem_lock_held(op, i); - Py_END_CRITICAL_SECTION(); - return ret; -} - static PyObject * bytearray_subscript_lock_held(PyObject *op, PyObject *index) { diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index e130ced76a93fe6..e57d71cc398b413 100644 --- a/Objects/clinic/bytearrayobject.c.h +++ b/Objects/clinic/bytearrayobject.c.h @@ -56,6 +56,21 @@ bytearray_irepeat(PyObject *self, Py_ssize_t count) return return_value; } +static PyObject * +bytearray_getitem_impl(PyByteArrayObject *self, Py_ssize_t i); + +static PyObject * +bytearray_getitem(PyObject *self, Py_ssize_t i) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(self); + return_value = bytearray_getitem_impl((PyByteArrayObject *)self, i); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + static int bytearray_setitem_impl(PyByteArrayObject *self, Py_ssize_t i, PyObject *value); @@ -2022,4 +2037,4 @@ bytearray_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return bytearray_sizeof_impl((PyByteArrayObject *)self); } -/*[clinic end generated code: output=f57debf4b0a990ca input=a9049054013a1b77]*/ +/*[clinic end generated code: output=fbd9a012eb61b372 input=a9049054013a1b77]*/ diff --git a/Tools/clinic/libclinic/dsl_parser.py b/Tools/clinic/libclinic/dsl_parser.py index c27a883de36a41c..af12c28b9c5045e 100644 --- a/Tools/clinic/libclinic/dsl_parser.py +++ b/Tools/clinic/libclinic/dsl_parser.py @@ -50,7 +50,6 @@ __ge__ __getattr__ __getattribute__ -__getitem__ __gt__ __hash__ __iand__ diff --git a/Tools/clinic/libclinic/slots.py b/Tools/clinic/libclinic/slots.py index 2138a6e780b2457..8bb9d7a586d1f8b 100644 --- a/Tools/clinic/libclinic/slots.py +++ b/Tools/clinic/libclinic/slots.py @@ -40,6 +40,7 @@ def make_return_converter(self) -> CReturnConverter: SLOTS: Final[dict[str, SlotSpec]] = { '__add__': SlotSpec(return_converter='object'), '__contains__': SlotSpec(return_converter='int'), + '__getitem__': SlotSpec(return_converter='object'), '__iadd__': SlotSpec(return_converter='object'), '__imul__': SlotSpec(return_converter='object'), '__len__': SlotSpec(return_converter='Py_ssize_t'),