8000 gh-132987: Support __index__() in the select.kqueue_event constructor… · python/cpython@d2d4900 · GitHub
[go: up one dir, main page]

Skip to content

Commit d2d4900

Browse files
gh-132987: Support __index__() in the select.kqueue_event constructor (GH-133094)
1 parent 0fb4c38 commit d2d4900

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Modules/selectmodule.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,14 +1922,27 @@ kqueue_event_init(PyObject *op, PyObject *args, PyO 8000 bject *kwds)
19221922
return -1;
19231923
}
19241924

1925-
if (PyLong_Check(pfd)) {
1926-
self->e.ident = PyLong_AsSize_t(pfd);
1925+
if (PyIndex_Check(pfd)) {
1926+
Py_ssize_t bytes = PyLong_AsNativeBytes(pfd,
1927+
&self->e.ident, sizeof(self->e.ident),
1928+
Py_ASNATIVEBYTES_NATIVE_ENDIAN |
1929+
Py_ASNATIVEBYTES_ALLOW_INDEX |
1930+
Py_ASNATIVEBYTES_REJECT_NEGATIVE |
1931+
Py_ASNATIVEBYTES_UNSIGNED_BUFFER);
1932+
if (bytes < 0) {
1933+
return -1;
1934+
}
1935+
if ((size_t)bytes > sizeof(self->e.ident)) {
1936+
PyErr_SetString(PyExc_OverflowError,
1937+
"Python int too large for C kqueue event identifier");
1938+
return -1;
1939+
}
19271940
}
19281941
else {
19291942
self->e.ident = PyObject_AsFileDescriptor(pfd);
1930-
}
1931-
if (PyErr_Occurred()) {
1932-
return -1;
1943+
if (PyErr_Occurred()) {
1944+
return -1;
1945+
}
19331946
}
19341947
return 0;
19351948
}

0 commit comments

Comments
 (0)
0