From: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Date: Tue, 2 Sep 2025 17:53:44 +0000 (+0200) Subject: gh-116946: add `Py_TPFLAGS_IMMUTABLETYPE` to `select.poll` and `select.epoll` (#138340) X-Git-Tag: v3.15.0a1~529 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3ff00c76c9b02d56b448e1d2669ad9f154b427b3;p=thirdparty%2FPython%2Fcpython.git gh-116946: add `Py_TPFLAGS_IMMUTABLETYPE` to `select.poll` and `select.epoll` (#138340) --- diff --git a/Misc/NEWS.d/next/Library/2025-09-02-10-27-21.gh-issue-116946.VxXNGD.rst b/Misc/NEWS.d/next/Library/2025-09-02-10-27-21.gh-issue-116946.VxXNGD.rst new file mode 100644 index 000000000000..bb56cbb3fefa --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-09-02-10-27-21.gh-issue-116946.VxXNGD.rst @@ -0,0 +1,2 @@ +The types of :func:`select.poll` and :func:`select.epoll` objects are now +immutable. Patch by Bénédikt Tran. diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 99d96ebed2f7..107e674907cf 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -433,7 +433,7 @@ select_select_impl(PyObject *module, PyObject *rlist, PyObject *wlist, typedef struct { PyObject_HEAD - PyObject *dict; + PyObject *dict; // cannot create cycles as it only contains exact ints int ufd_uptodate; int ufd_len; struct pollfd *ufds; @@ -2483,7 +2483,11 @@ static PyType_Slot poll_Type_slots[] = { static PyType_Spec poll_Type_spec = { .name = "select.poll", .basicsize = sizeof(pollObject), - .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION, + .flags = ( + Py_TPFLAGS_DEFAULT + | Py_TPFLAGS_DISALLOW_INSTANTIATION + | Py_TPFLAGS_IMMUTABLETYPE + ), .slots = poll_Type_slots, }; @@ -2529,11 +2533,10 @@ static PyType_Slot pyEpoll_Type_slots[] = { }; static PyType_Spec pyEpoll_Type_spec = { - "select.epoll", - sizeof(pyEpoll_Object), - 0, - Py_TPFLAGS_DEFAULT, - pyEpoll_Type_slots + .name = "select.epoll", + .basicsize = sizeof(pyEpoll_Object), + .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE, + .slots = pyEpoll_Type_slots }; #endif /* HAVE_EPOLL */