Skip to content

Commit 3ff00c7

Browse files
authored
gh-116946: add Py_TPFLAGS_IMMUTABLETYPE to select.poll and select.epoll (#138340)
1 parent 5493b46 commit 3ff00c7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The types of :func:`select.poll` and :func:`select.epoll` objects are now
2+
immutable. Patch by Bénédikt Tran.

Modules/selectmodule.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ select_select_impl(PyObject *module, PyObject *rlist, PyObject *wlist,
433433

434434
typedef struct {
435435
PyObject_HEAD
436-
PyObject *dict;
436+
PyObject *dict; // cannot create cycles as it only contains exact ints
437437
int ufd_uptodate;
438438
int ufd_len;
439439
struct pollfd *ufds;
@@ -2483,7 +2483,11 @@ static PyType_Slot poll_Type_slots[] = {
24832483
static PyType_Spec poll_Type_spec = {
24842484
.name = "select.poll",
24852485
.basicsize = sizeof(pollObject),
2486-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
2486+
.flags = (
2487+
Py_TPFLAGS_DEFAULT
2488+
| Py_TPFLAGS_DISALLOW_INSTANTIATION
2489+
| Py_TPFLAGS_IMMUTABLETYPE
2490+
),
24872491
.slots = poll_Type_slots,
24882492
};
24892493

@@ -2529,11 +2533,10 @@ static PyType_Slot pyEpoll_Type_slots[] = {
25292533
};
25302534

25312535
static PyType_Spec pyEpoll_Type_spec = {
2532-
"select.epoll",
2533-
sizeof(pyEpoll_Object),
2534-
0,
2535-
Py_TPFLAGS_DEFAULT,
2536-
pyEpoll_Type_slots
2536+
.name = "select.epoll",
2537+
.basicsize = sizeof(pyEpoll_Object),
2538+
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
2539+
.slots = pyEpoll_Type_slots
25372540
};
25382541

25392542
#endif /* HAVE_EPOLL */

0 commit comments

Comments
 (0)