Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d2d4900

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

File tree

Expand file treeCollapse file tree

1 file changed

+18
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-5
lines changed

‎Modules/selectmodule.c

Copy file name to clipboardExpand all lines: Modules/selectmodule.c
+18-5Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,14 +1922,27 @@ kqueue_event_init(PyObject *op, PyObject *args, PyObject *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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.