diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2025-04-29 16:55:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-29 13:55:14 +0000 |
commit | d2d490064d8acc7534a0729ef7710b9b013a459f (patch) | |
tree | 26fb8399519508b8831a3884f1662d5c5c0df285 /Modules | |
parent | 0fb4c38c273213394b6c5e28432a3dcfc752d289 (diff) | |
download | cpython-d2d490064d8acc7534a0729ef7710b9b013a459f.tar.gz cpython-d2d490064d8acc7534a0729ef7710b9b013a459f.zip |
gh-132987: Support __index__() in the select.kqueue_event constructor (GH-133094)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/selectmodule.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index d701026b508..d234d504cb5 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -1922,14 +1922,27 @@ kqueue_event_init(PyObject *op, PyObject *args, PyObject *kwds) return -1; } - if (PyLong_Check(pfd)) { - self->e.ident = PyLong_AsSize_t(pfd); + if (PyIndex_Check(pfd)) { + Py_ssize_t bytes = PyLong_AsNativeBytes(pfd, + &self->e.ident, sizeof(self->e.ident), + Py_ASNATIVEBYTES_NATIVE_ENDIAN | + Py_ASNATIVEBYTES_ALLOW_INDEX | + Py_ASNATIVEBYTES_REJECT_NEGATIVE | + Py_ASNATIVEBYTES_UNSIGNED_BUFFER); + if (bytes < 0) { + return -1; + } + if ((size_t)bytes > sizeof(self->e.ident)) { + PyErr_SetString(PyExc_OverflowError, + "Python int too large for C kqueue event identifier"); + return -1; + } } else { self->e.ident = PyObject_AsFileDescriptor(pfd); - } - if (PyErr_Occurred()) { - return -1; + if (PyErr_Occurred()) { + return -1; + } } return 0; } |