]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-116946: add `Py_TPFLAGS_IMMUTABLETYPE` to `select.poll` and `select.epoll` (#138340)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Tue, 2 Sep 2025 17:53:44 +0000 (19:53 +0200)
committerGitHub <noreply@github.com>
Tue, 2 Sep 2025 17:53:44 +0000 (17:53 +0000)
Misc/NEWS.d/next/Library/2025-09-02-10-27-21.gh-issue-116946.VxXNGD.rst [new file with mode: 0644]
Modules/selectmodule.c

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 (file)
index 0000000..bb56cbb
--- /dev/null
@@ -0,0 +1,2 @@
+The types of :func:`select.poll` and :func:`select.epoll` objects are now
+immutable. Patch by Bénédikt Tran.
index 99d96ebed2f7b1cc115947d4cf309af9e71d7289..107e674907cf732ceee41ce95485e64583915459 100644 (file)
@@ -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 */