diff --git a/Modules/clinic/mmapmodule.c.h b/Modules/clinic/mmapmodule.c.h index 4bb40541b254b8a..04c0aaff020d297 100644 --- a/Modules/clinic/mmapmodule.c.h +++ b/Modules/clinic/mmapmodule.c.h @@ -701,6 +701,21 @@ mmap_mmap___exit__(PyObject *self, PyObject *const *args, Py_ssize_t nargs) return return_value; } +static PyObject * +mmap__repr__method_impl(PyObject *op); + +static PyObject * +mmap__repr__method(PyObject *op) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(op); + return_value = mmap__repr__method_impl(op); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + #if defined(MS_WINDOWS) PyDoc_STRVAR(mmap_mmap___sizeof____doc__, @@ -922,4 +937,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=eb09e5d722968cef input=a9049054013a1b77]*/ +/*[clinic end generated code: output=fd4738a3d64fcb0a input=a9049054013a1b77]*/ diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 4ea628b5d4a7525..0bc959a28f6f718 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -1256,8 +1256,16 @@ mmap_mmap___exit___impl(mmap_object *self, PyObject *exc_type, return mmap_mmap_close_impl(self); } +/*[clinic input] +@critical_section +mmap.mmap.__repr__ as mmap__repr__method + + op: self(type="PyObject *") +[clinic start generated code]*/ + static PyObject * -mmap__repr__method_lock_held(PyObject *op) +mmap__repr__method_impl(PyObject *op) +/*[clinic end generated code: output=c896c8c4cd07228c input=a030361fbcfe851a]*/ { mmap_object *mobj = mmap_object_CAST(op); @@ -1301,16 +1309,6 @@ mmap__repr__method_lock_held(PyObject *op) } } -static PyObject * -mmap__repr__method(PyObject *op) -{ - PyObject *result; - Py_BEGIN_CRITICAL_SECTION(op); - result = mmap__repr__method_lock_held(op); - Py_END_CRITICAL_SECTION(); - return result; -} - #ifdef MS_WINDOWS /*[clinic input] @critical_section diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index a8e35d217dc54da..61077866872bcdd 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -1182,8 +1182,16 @@ bytearray___init___impl(PyByteArrayObject *self, PyObject *arg, return -1; } +/*[clinic input] +@critical_section +bytearray.__repr__ + + op: self(type="PyObject *") +[clinic start generated code]*/ + static PyObject * -bytearray_repr_lock_held(PyObject *op) +bytearray_repr_impl(PyObject *op) +/*[clinic end generated code: output=4086ab6928ebab1d input=d46ad3c1f3071b27]*/ { _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op); const char *className = _PyType_Name(Py_TYPE(op)); @@ -1198,16 +1206,6 @@ bytearray_repr_lock_held(PyObject *op) return res; } -static PyObject * -bytearray_repr(PyObject *op) -{ - PyObject *ret; - Py_BEGIN_CRITICAL_SECTION(op); - ret = bytearray_repr_lock_held(op); - Py_END_CRITICAL_SECTION(); - return ret; -} - static PyObject * bytearray_str(PyObject *op) { diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index 83cfa00d59044e9..451308d99112a16 100644 --- a/Objects/clinic/bytearrayobject.c.h +++ b/Objects/clinic/bytearrayobject.c.h @@ -195,6 +195,21 @@ bytearray_vectorcall(PyObject *type, PyObject *const *args, return return_value; } +static PyObject * +bytearray_repr_impl(PyObject *op); + +static PyObject * +bytearray_repr(PyObject *op) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(op); + return_value = bytearray_repr_impl(op); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + PyDoc_STRVAR(bytearray_find__doc__, "find($self, sub[, start[, end]], /)\n" "--\n" @@ -1962,4 +1977,4 @@ bytearray_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return bytearray_sizeof_impl((PyByteArrayObject *)self); } -/*[clinic end generated code: output=a16aaa01f1fcf5a6 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5cfb062cb3307f31 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/dictobject.c.h b/Objects/clinic/dictobject.c.h index 15b8705d9c78e3c..038f56d62b6d8c5 100644 --- a/Objects/clinic/dictobject.c.h +++ b/Objects/clinic/dictobject.c.h @@ -5,6 +5,21 @@ preserve #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() +static PyObject * +dict_repr_impl(PyObject *self); + +static PyObject * +dict_repr(PyObject *self) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(self); + return_value = dict_repr_impl(self); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + PyDoc_STRVAR(dict_fromkeys__doc__, "fromkeys($type, iterable, value=None, /)\n" "--\n" @@ -341,4 +356,4 @@ frozendict_copy(PyObject *self, PyObject *Py_UNUSED(ignored)) { return frozendict_copy_impl((PyFrozenDictObject *)self); } -/*[clinic end generated code: output=f4c88a3464928ae3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=46d2d00147dd7917 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h index dc76baa17de7b9f..787f575a1ac272d 100644 --- a/Objects/clinic/listobject.c.h +++ b/Objects/clinic/listobject.c.h @@ -10,6 +10,21 @@ preserve #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_CheckPositional() +static PyObject * +list_repr_impl(PyListObject *v); + +static PyObject * +list_repr(PyObject *v) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(v); + return_value = list_repr_impl((PyListObject *)v); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + static int list_ass_item_impl(PyListObject *a, Py_ssize_t i, PyObject *v); @@ -483,4 +498,4 @@ list___reversed__(PyObject *self, PyObject *Py_UNUSED(ignored)) { return list___reversed___impl((PyListObject *)self); } -/*[clinic end generated code: output=ef8a058598f58f7e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c7ed86d2a453ec78 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/setobject.c.h b/Objects/clinic/setobject.c.h index 098c4bcb53d3fb1..8c9beaadccde866 100644 --- a/Objects/clinic/setobject.c.h +++ b/Objects/clinic/setobject.c.h @@ -4,6 +4,21 @@ preserve #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() +static PyObject * +set_repr_impl(PySetObject *so); + +static PyObject * +set_repr(PyObject *so) +{ + PyObject *return_value = NULL; + + Py_BEGIN_CRITICAL_SECTION(so); + return_value = set_repr_impl((PySetObject *)so); + Py_END_CRITICAL_SECTION(); + + return return_value; +} + PyDoc_STRVAR(set_pop__doc__, "pop($self, /)\n" "--\n" @@ -552,4 +567,4 @@ set___sizeof__(PyObject *so, PyObject *Py_UNUSED(ignored)) return return_value; } -/*[clinic end generated code: output=5800c0bf136a5a0a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5d794137d2614aaf input=a9049054013a1b77]*/ diff --git a/Objects/dictobject.c b/Objects/dictobject.c index bff543d9fdede4e..b3e6323fb793354 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -3772,23 +3772,21 @@ anydict_repr_impl(PyObject *self) return NULL; } +/*[clinic input] +@critical_section +dict.__repr__ + + self: self(type="PyObject *") +[clinic start generated code]*/ + static PyObject * -dict_repr_lock_held(PyObject *self) +dict_repr_impl(PyObject *self) +/*[clinic end generated code: output=059263af818a321d input=f9c423cbdf534674]*/ { ASSERT_DICT_LOCKED((PyDictObject *)self); return anydict_repr_impl(self); } -static PyObject * -dict_repr(PyObject *self) -{ - PyObject *res; - Py_BEGIN_CRITICAL_SECTION(self); - res = dict_repr_lock_held(self); - Py_END_CRITICAL_SECTION(); - return res; -} - static Py_ssize_t dict_length(PyObject *self) { diff --git a/Objects/listobject.c b/Objects/listobject.c index f974b3ba1200086..37744b6972039f4 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -632,9 +632,21 @@ list_dealloc(PyObject *self) } } +/*[clinic input] +@critical_section +list.__repr__ + + v: self(type="PyListObject *") +[clinic start generated code]*/ + static PyObject * list_repr_impl(PyListObject *v) +/*[clinic end generated code: output=c5ffe3b9cfee36ce input=f4b85c550d11de32]*/ { + if (PyList_GET_SIZE(v) == 0) { + return PyUnicode_FromString("[]"); + } + int res = Py_ReprEnter((PyObject*)v); if (res != 0) { return (res > 0 ? PyUnicode_FromString("[...]") : NULL); @@ -687,20 +699,6 @@ list_repr_impl(PyListObject *v) return NULL; } -static PyObject * -list_repr(PyObject *self) -{ - if (PyList_GET_SIZE(self) == 0) { - return PyUnicode_FromString("[]"); - } - PyListObject *v = (PyListObject *)self; - PyObject *ret = NULL; - Py_BEGIN_CRITICAL_SECTION(v); - ret = list_repr_impl(v); - Py_END_CRITICAL_SECTION(); - return ret; -} - static Py_ssize_t list_length(PyObject *a) { diff --git a/Objects/setobject.c b/Objects/setobject.c index 8fdd1eb26118c0a..a762edf5933e185 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -753,8 +753,16 @@ set_dealloc(PyObject *self) Py_TYPE(so)->tp_free(so); } +/*[clinic input] +@critical_section +set.__repr__ + + so: setobject +[clinic start generated code]*/ + static PyObject * -set_repr_lock_held(PySetObject *so) +set_repr_impl(PySetObject *so) +/*[clinic end generated code: output=5dfbb5e7f7c947ad input=f6743ec76163d7b3]*/ { PyObject *result=NULL, *keys, *listrepr, *tmp; int status = Py_ReprEnter((PyObject*)so); @@ -807,17 +815,6 @@ set_repr_lock_held(PySetObject *so) return result; } -static PyObject * -set_repr(PyObject *self) -{ - PySetObject *so = _PySet_CAST(self); - PyObject *result; - Py_BEGIN_CRITICAL_SECTION(so); - result = set_repr_lock_held(so); - Py_END_CRITICAL_SECTION(); - return result; -} - static Py_ssize_t set_len(PyObject *self) { diff --git a/Tools/clinic/libclinic/dsl_parser.py b/Tools/clinic/libclinic/dsl_parser.py index 819851dcb78aaad..a52cd92ed7f78fd 100644 --- a/Tools/clinic/libclinic/dsl_parser.py +++ b/Tools/clinic/libclinic/dsl_parser.py @@ -84,7 +84,6 @@ __radd__ __rand__ __rdivmod__ -__repr__ __rfloordiv__ __rlshift__ __rmatmul__ diff --git a/Tools/clinic/libclinic/slots.py b/Tools/clinic/libclinic/slots.py index 6f7c9954a6d02a2..0e2a04f98126347 100644 --- a/Tools/clinic/libclinic/slots.py +++ b/Tools/clinic/libclinic/slots.py @@ -40,5 +40,6 @@ def make_return_converter(self) -> CReturnConverter: SLOTS: Final[dict[str, SlotSpec]] = { '__next__': SlotSpec(return_converter='object'), '__len__': SlotSpec(return_converter='Py_ssize_t'), + '__repr__': SlotSpec(return_converter='object'), '__setitem__': SlotSpec(return_converter='int'), }