• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 #  include "pycore_gc.h"          // PyGC_Head
7 #  include "pycore_runtime.h"     // _Py_ID()
8 #endif
9 #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
10 #include "pycore_long.h"          // _PyLong_UnsignedShort_Converter()
11 #include "pycore_modsupport.h"    // _PyArg_CheckPositional()
12 
13 PyDoc_STRVAR(select_select__doc__,
14 "select($module, rlist, wlist, xlist, timeout=None, /)\n"
15 "--\n"
16 "\n"
17 "Wait until one or more file descriptors are ready for some kind of I/O.\n"
18 "\n"
19 "The first three arguments are iterables of file descriptors to be waited for:\n"
20 "rlist -- wait until ready for reading\n"
21 "wlist -- wait until ready for writing\n"
22 "xlist -- wait for an \"exceptional condition\"\n"
23 "If only one kind of condition is required, pass [] for the other lists.\n"
24 "\n"
25 "A file descriptor is either a socket or file object, or a small integer\n"
26 "gotten from a fileno() method call on one of those.\n"
27 "\n"
28 "The optional 4th argument specifies a timeout in seconds; it may be\n"
29 "a floating-point number to specify fractions of seconds.  If it is absent\n"
30 "or None, the call will never time out.\n"
31 "\n"
32 "The return value is a tuple of three lists corresponding to the first three\n"
33 "arguments; each contains the subset of the corresponding file descriptors\n"
34 "that are ready.\n"
35 "\n"
36 "*** IMPORTANT NOTICE ***\n"
37 "On Windows, only sockets are supported; on Unix, all file\n"
38 "descriptors can be used.");
39 
40 #define SELECT_SELECT_METHODDEF    \
41     {"select", _PyCFunction_CAST(select_select), METH_FASTCALL, select_select__doc__},
42 
43 static PyObject *
44 select_select_impl(PyObject *module, PyObject *rlist, PyObject *wlist,
45                    PyObject *xlist, PyObject *timeout_obj);
46 
47 static PyObject *
select_select(PyObject * module,PyObject * const * args,Py_ssize_t nargs)48 select_select(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
49 {
50     PyObject *return_value = NULL;
51     PyObject *rlist;
52     PyObject *wlist;
53     PyObject *xlist;
54     PyObject *timeout_obj = Py_None;
55 
56     if (!_PyArg_CheckPositional("select", nargs, 3, 4)) {
57         goto exit;
58     }
59     rlist = args[0];
60     wlist = args[1];
61     xlist = args[2];
62     if (nargs < 4) {
63         goto skip_optional;
64     }
65     timeout_obj = args[3];
66 skip_optional:
67     return_value = select_select_impl(module, rlist, wlist, xlist, timeout_obj);
68 
69 exit:
70     return return_value;
71 }
72 
73 #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL))
74 
75 PyDoc_STRVAR(select_poll_register__doc__,
76 "register($self, fd,\n"
77 "         eventmask=select.POLLIN | select.POLLPRI | select.POLLOUT, /)\n"
78 "--\n"
79 "\n"
80 "Register a file descriptor with the polling object.\n"
81 "\n"
82 "  fd\n"
83 "    either an integer, or an object with a fileno() method returning an int\n"
84 "  eventmask\n"
85 "    an optional bitmask describing the type of events to check for");
86 
87 #define SELECT_POLL_REGISTER_METHODDEF    \
88     {"register", _PyCFunction_CAST(select_poll_register), METH_FASTCALL, select_poll_register__doc__},
89 
90 static PyObject *
91 select_poll_register_impl(pollObject *self, int fd, unsigned short eventmask);
92 
93 static PyObject *
select_poll_register(pollObject * self,PyObject * const * args,Py_ssize_t nargs)94 select_poll_register(pollObject *self, PyObject *const *args, Py_ssize_t nargs)
95 {
96     PyObject *return_value = NULL;
97     int fd;
98     unsigned short eventmask = POLLIN | POLLPRI | POLLOUT;
99 
100     if (!_PyArg_CheckPositional("register", nargs, 1, 2)) {
101         goto exit;
102     }
103     fd = PyObject_AsFileDescriptor(args[0]);
104     if (fd < 0) {
105         goto exit;
106     }
107     if (nargs < 2) {
108         goto skip_optional;
109     }
110     if (!_PyLong_UnsignedShort_Converter(args[1], &eventmask)) {
111         goto exit;
112     }
113 skip_optional:
114     Py_BEGIN_CRITICAL_SECTION(self);
115     return_value = select_poll_register_impl(self, fd, eventmask);
116     Py_END_CRITICAL_SECTION();
117 
118 exit:
119     return return_value;
120 }
121 
122 #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) */
123 
124 #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL))
125 
126 PyDoc_STRVAR(select_poll_modify__doc__,
127 "modify($self, fd, eventmask, /)\n"
128 "--\n"
129 "\n"
130 "Modify an already registered file descriptor.\n"
131 "\n"
132 "  fd\n"
133 "    either an integer, or an object with a fileno() method returning\n"
134 "    an int\n"
135 "  eventmask\n"
136 "    a bitmask describing the type of events to check for");
137 
138 #define SELECT_POLL_MODIFY_METHODDEF    \
139     {"modify", _PyCFunction_CAST(select_poll_modify), METH_FASTCALL, select_poll_modify__doc__},
140 
141 static PyObject *
142 select_poll_modify_impl(pollObject *self, int fd, unsigned short eventmask);
143 
144 static PyObject *
select_poll_modify(pollObject * self,PyObject * const * args,Py_ssize_t nargs)145 select_poll_modify(pollObject *self, PyObject *const *args, Py_ssize_t nargs)
146 {
147     PyObject *return_value = NULL;
148     int fd;
149     unsigned short eventmask;
150 
151     if (!_PyArg_CheckPositional("modify", nargs, 2, 2)) {
152         goto exit;
153     }
154     fd = PyObject_AsFileDescriptor(args[0]);
155     if (fd < 0) {
156         goto exit;
157     }
158     if (!_PyLong_UnsignedShort_Converter(args[1], &eventmask)) {
159         goto exit;
160     }
161     Py_BEGIN_CRITICAL_SECTION(self);
162     return_value = select_poll_modify_impl(self, fd, eventmask);
163     Py_END_CRITICAL_SECTION();
164 
165 exit:
166     return return_value;
167 }
168 
169 #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) */
170 
171 #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL))
172 
173 PyDoc_STRVAR(select_poll_unregister__doc__,
174 "unregister($self, fd, /)\n"
175 "--\n"
176 "\n"
177 "Remove a file descriptor being tracked by the polling object.");
178 
179 #define SELECT_POLL_UNREGISTER_METHODDEF    \
180     {"unregister", (PyCFunction)select_poll_unregister, METH_O, select_poll_unregister__doc__},
181 
182 static PyObject *
183 select_poll_unregister_impl(pollObject *self, int fd);
184 
185 static PyObject *
select_poll_unregister(pollObject * self,PyObject * arg)186 select_poll_unregister(pollObject *self, PyObject *arg)
187 {
188     PyObject *return_value = NULL;
189     int fd;
190 
191     fd = PyObject_AsFileDescriptor(arg);
192     if (fd < 0) {
193         goto exit;
194     }
195     Py_BEGIN_CRITICAL_SECTION(self);
196     return_value = select_poll_unregister_impl(self, fd);
197     Py_END_CRITICAL_SECTION();
198 
199 exit:
200     return return_value;
201 }
202 
203 #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) */
204 
205 #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL))
206 
207 PyDoc_STRVAR(select_poll_poll__doc__,
208 "poll($self, timeout=None, /)\n"
209 "--\n"
210 "\n"
211 "Polls the set of registered file descriptors.\n"
212 "\n"
213 "  timeout\n"
214 "    The maximum time to wait in milliseconds, or else None (or a negative\n"
215 "    value) to wait indefinitely.\n"
216 "\n"
217 "Returns a list containing any descriptors that have events or errors to\n"
218 "report, as a list of (fd, event) 2-tuples.");
219 
220 #define SELECT_POLL_POLL_METHODDEF    \
221     {"poll", _PyCFunction_CAST(select_poll_poll), METH_FASTCALL, select_poll_poll__doc__},
222 
223 static PyObject *
224 select_poll_poll_impl(pollObject *self, PyObject *timeout_obj);
225 
226 static PyObject *
select_poll_poll(pollObject * self,PyObject * const * args,Py_ssize_t nargs)227 select_poll_poll(pollObject *self, PyObject *const *args, Py_ssize_t nargs)
228 {
229     PyObject *return_value = NULL;
230     PyObject *timeout_obj = Py_None;
231 
232     if (!_PyArg_CheckPositional("poll", nargs, 0, 1)) {
233         goto exit;
234     }
235     if (nargs < 1) {
236         goto skip_optional;
237     }
238     timeout_obj = args[0];
239 skip_optional:
240     Py_BEGIN_CRITICAL_SECTION(self);
241     return_value = select_poll_poll_impl(self, timeout_obj);
242     Py_END_CRITICAL_SECTION();
243 
244 exit:
245     return return_value;
246 }
247 
248 #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) */
249 
250 #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H)
251 
252 PyDoc_STRVAR(select_devpoll_register__doc__,
253 "register($self, fd,\n"
254 "         eventmask=select.POLLIN | select.POLLPRI | select.POLLOUT, /)\n"
255 "--\n"
256 "\n"
257 "Register a file descriptor with the polling object.\n"
258 "\n"
259 "  fd\n"
260 "    either an integer, or an object with a fileno() method returning\n"
261 "    an int\n"
262 "  eventmask\n"
263 "    an optional bitmask describing the type of events to check for");
264 
265 #define SELECT_DEVPOLL_REGISTER_METHODDEF    \
266     {"register", _PyCFunction_CAST(select_devpoll_register), METH_FASTCALL, select_devpoll_register__doc__},
267 
268 static PyObject *
269 select_devpoll_register_impl(devpollObject *self, int fd,
270                              unsigned short eventmask);
271 
272 static PyObject *
select_devpoll_register(devpollObject * self,PyObject * const * args,Py_ssize_t nargs)273 select_devpoll_register(devpollObject *self, PyObject *const *args, Py_ssize_t nargs)
274 {
275     PyObject *return_value = NULL;
276     int fd;
277     unsigned short eventmask = POLLIN | POLLPRI | POLLOUT;
278 
279     if (!_PyArg_CheckPositional("register", nargs, 1, 2)) {
280         goto exit;
281     }
282     fd = PyObject_AsFileDescriptor(args[0]);
283     if (fd < 0) {
284         goto exit;
285     }
286     if (nargs < 2) {
287         goto skip_optional;
288     }
289     if (!_PyLong_UnsignedShort_Converter(args[1], &eventmask)) {
290         goto exit;
291     }
292 skip_optional:
293     Py_BEGIN_CRITICAL_SECTION(self);
294     return_value = select_devpoll_register_impl(self, fd, eventmask);
295     Py_END_CRITICAL_SECTION();
296 
297 exit:
298     return return_value;
299 }
300 
301 #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) */
302 
303 #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H)
304 
305 PyDoc_STRVAR(select_devpoll_modify__doc__,
306 "modify($self, fd,\n"
307 "       eventmask=select.POLLIN | select.POLLPRI | select.POLLOUT, /)\n"
308 "--\n"
309 "\n"
310 "Modify a possible already registered file descriptor.\n"
311 "\n"
312 "  fd\n"
313 "    either an integer, or an object with a fileno() method returning\n"
314 "    an int\n"
315 "  eventmask\n"
316 "    an optional bitmask describing the type of events to check for");
317 
318 #define SELECT_DEVPOLL_MODIFY_METHODDEF    \
319     {"modify", _PyCFunction_CAST(select_devpoll_modify), METH_FASTCALL, select_devpoll_modify__doc__},
320 
321 static PyObject *
322 select_devpoll_modify_impl(devpollObject *self, int fd,
323                            unsigned short eventmask);
324 
325 static PyObject *
select_devpoll_modify(devpollObject * self,PyObject * const * args,Py_ssize_t nargs)326 select_devpoll_modify(devpollObject *self, PyObject *const *args, Py_ssize_t nargs)
327 {
328     PyObject *return_value = NULL;
329     int fd;
330     unsigned short eventmask = POLLIN | POLLPRI | POLLOUT;
331 
332     if (!_PyArg_CheckPositional("modify", nargs, 1, 2)) {
333         goto exit;
334     }
335     fd = PyObject_AsFileDescriptor(args[0]);
336     if (fd < 0) {
337         goto exit;
338     }
339     if (nargs < 2) {
340         goto skip_optional;
341     }
342     if (!_PyLong_UnsignedShort_Converter(args[1], &eventmask)) {
343         goto exit;
344     }
345 skip_optional:
346     Py_BEGIN_CRITICAL_SECTION(self);
347     return_value = select_devpoll_modify_impl(self, fd, eventmask);
348     Py_END_CRITICAL_SECTION();
349 
350 exit:
351     return return_value;
352 }
353 
354 #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) */
355 
356 #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H)
357 
358 PyDoc_STRVAR(select_devpoll_unregister__doc__,
359 "unregister($self, fd, /)\n"
360 "--\n"
361 "\n"
362 "Remove a file descriptor being tracked by the polling object.");
363 
364 #define SELECT_DEVPOLL_UNREGISTER_METHODDEF    \
365     {"unregister", (PyCFunction)select_devpoll_unregister, METH_O, select_devpoll_unregister__doc__},
366 
367 static PyObject *
368 select_devpoll_unregister_impl(devpollObject *self, int fd);
369 
370 static PyObject *
select_devpoll_unregister(devpollObject * self,PyObject * arg)371 select_devpoll_unregister(devpollObject *self, PyObject *arg)
372 {
373     PyObject *return_value = NULL;
374     int fd;
375 
376     fd = PyObject_AsFileDescriptor(arg);
377     if (fd < 0) {
378         goto exit;
379     }
380     Py_BEGIN_CRITICAL_SECTION(self);
381     return_value = select_devpoll_unregister_impl(self, fd);
382     Py_END_CRITICAL_SECTION();
383 
384 exit:
385     return return_value;
386 }
387 
388 #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) */
389 
390 #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H)
391 
392 PyDoc_STRVAR(select_devpoll_poll__doc__,
393 "poll($self, timeout=None, /)\n"
394 "--\n"
395 "\n"
396 "Polls the set of registered file descriptors.\n"
397 "\n"
398 "  timeout\n"
399 "    The maximum time to wait in milliseconds, or else None (or a negative\n"
400 "    value) to wait indefinitely.\n"
401 "\n"
402 "Returns a list containing any descriptors that have events or errors to\n"
403 "report, as a list of (fd, event) 2-tuples.");
404 
405 #define SELECT_DEVPOLL_POLL_METHODDEF    \
406     {"poll", _PyCFunction_CAST(select_devpoll_poll), METH_FASTCALL, select_devpoll_poll__doc__},
407 
408 static PyObject *
409 select_devpoll_poll_impl(devpollObject *self, PyObject *timeout_obj);
410 
411 static PyObject *
select_devpoll_poll(devpollObject * self,PyObject * const * args,Py_ssize_t nargs)412 select_devpoll_poll(devpollObject *self, PyObject *const *args, Py_ssize_t nargs)
413 {
414     PyObject *return_value = NULL;
415     PyObject *timeout_obj = Py_None;
416 
417     if (!_PyArg_CheckPositional("poll", nargs, 0, 1)) {
418         goto exit;
419     }
420     if (nargs < 1) {
421         goto skip_optional;
422     }
423     timeout_obj = args[0];
424 skip_optional:
425     Py_BEGIN_CRITICAL_SECTION(self);
426     return_value = select_devpoll_poll_impl(self, timeout_obj);
427     Py_END_CRITICAL_SECTION();
428 
429 exit:
430     return return_value;
431 }
432 
433 #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) */
434 
435 #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H)
436 
437 PyDoc_STRVAR(select_devpoll_close__doc__,
438 "close($self, /)\n"
439 "--\n"
440 "\n"
441 "Close the devpoll file descriptor.\n"
442 "\n"
443 "Further operations on the devpoll object will raise an exception.");
444 
445 #define SELECT_DEVPOLL_CLOSE_METHODDEF    \
446     {"close", (PyCFunction)select_devpoll_close, METH_NOARGS, select_devpoll_close__doc__},
447 
448 static PyObject *
449 select_devpoll_close_impl(devpollObject *self);
450 
451 static PyObject *
select_devpoll_close(devpollObject * self,PyObject * Py_UNUSED (ignored))452 select_devpoll_close(devpollObject *self, PyObject *Py_UNUSED(ignored))
453 {
454     PyObject *return_value = NULL;
455 
456     Py_BEGIN_CRITICAL_SECTION(self);
457     return_value = select_devpoll_close_impl(self);
458     Py_END_CRITICAL_SECTION();
459 
460     return return_value;
461 }
462 
463 #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) */
464 
465 #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H)
466 
467 PyDoc_STRVAR(select_devpoll_fileno__doc__,
468 "fileno($self, /)\n"
469 "--\n"
470 "\n"
471 "Return the file descriptor.");
472 
473 #define SELECT_DEVPOLL_FILENO_METHODDEF    \
474     {"fileno", (PyCFunction)select_devpoll_fileno, METH_NOARGS, select_devpoll_fileno__doc__},
475 
476 static PyObject *
477 select_devpoll_fileno_impl(devpollObject *self);
478 
479 static PyObject *
select_devpoll_fileno(devpollObject * self,PyObject * Py_UNUSED (ignored))480 select_devpoll_fileno(devpollObject *self, PyObject *Py_UNUSED(ignored))
481 {
482     PyObject *return_value = NULL;
483 
484     Py_BEGIN_CRITICAL_SECTION(self);
485     return_value = select_devpoll_fileno_impl(self);
486     Py_END_CRITICAL_SECTION();
487 
488     return return_value;
489 }
490 
491 #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) */
492 
493 #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL))
494 
495 PyDoc_STRVAR(select_poll__doc__,
496 "poll($module, /)\n"
497 "--\n"
498 "\n"
499 "Returns a polling object.\n"
500 "\n"
501 "This object supports registering and unregistering file descriptors, and then\n"
502 "polling them for I/O events.");
503 
504 #define SELECT_POLL_METHODDEF    \
505     {"poll", (PyCFunction)select_poll, METH_NOARGS, select_poll__doc__},
506 
507 static PyObject *
508 select_poll_impl(PyObject *module);
509 
510 static PyObject *
select_poll(PyObject * module,PyObject * Py_UNUSED (ignored))511 select_poll(PyObject *module, PyObject *Py_UNUSED(ignored))
512 {
513     return select_poll_impl(module);
514 }
515 
516 #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) */
517 
518 #if (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H)
519 
520 PyDoc_STRVAR(select_devpoll__doc__,
521 "devpoll($module, /)\n"
522 "--\n"
523 "\n"
524 "Returns a polling object.\n"
525 "\n"
526 "This object supports registering and unregistering file descriptors, and then\n"
527 "polling them for I/O events.");
528 
529 #define SELECT_DEVPOLL_METHODDEF    \
530     {"devpoll", (PyCFunction)select_devpoll, METH_NOARGS, select_devpoll__doc__},
531 
532 static PyObject *
533 select_devpoll_impl(PyObject *module);
534 
535 static PyObject *
select_devpoll(PyObject * module,PyObject * Py_UNUSED (ignored))536 select_devpoll(PyObject *module, PyObject *Py_UNUSED(ignored))
537 {
538     return select_devpoll_impl(module);
539 }
540 
541 #endif /* (defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)) && defined(HAVE_SYS_DEVPOLL_H) */
542 
543 #if defined(HAVE_EPOLL)
544 
545 PyDoc_STRVAR(select_epoll__doc__,
546 "epoll(sizehint=-1, flags=0)\n"
547 "--\n"
548 "\n"
549 "Returns an epolling object.\n"
550 "\n"
551 "  sizehint\n"
552 "    The expected number of events to be registered.  It must be positive,\n"
553 "    or -1 to use the default.  It is only used on older systems where\n"
554 "    epoll_create1() is not available; otherwise it has no effect (though its\n"
555 "    value is still checked).\n"
556 "  flags\n"
557 "    Deprecated and completely ignored.  However, when supplied, its value\n"
558 "    must be 0 or select.EPOLL_CLOEXEC, otherwise OSError is raised.");
559 
560 static PyObject *
561 select_epoll_impl(PyTypeObject *type, int sizehint, int flags);
562 
563 static PyObject *
select_epoll(PyTypeObject * type,PyObject * args,PyObject * kwargs)564 select_epoll(PyTypeObject *type, PyObject *args, PyObject *kwargs)
565 {
566     PyObject *return_value = NULL;
567     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
568 
569     #define NUM_KEYWORDS 2
570     static struct {
571         PyGC_Head _this_is_not_used;
572         PyObject_VAR_HEAD
573         PyObject *ob_item[NUM_KEYWORDS];
574     } _kwtuple = {
575         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
576         .ob_item = { &_Py_ID(sizehint), &_Py_ID(flags), },
577     };
578     #undef NUM_KEYWORDS
579     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
580 
581     #else  // !Py_BUILD_CORE
582     #  define KWTUPLE NULL
583     #endif  // !Py_BUILD_CORE
584 
585     static const char * const _keywords[] = {"sizehint", "flags", NULL};
586     static _PyArg_Parser _parser = {
587         .keywords = _keywords,
588         .fname = "epoll",
589         .kwtuple = KWTUPLE,
590     };
591     #undef KWTUPLE
592     PyObject *argsbuf[2];
593     PyObject * const *fastargs;
594     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
595     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
596     int sizehint = -1;
597     int flags = 0;
598 
599     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);
600     if (!fastargs) {
601         goto exit;
602     }
603     if (!noptargs) {
604         goto skip_optional_pos;
605     }
606     if (fastargs[0]) {
607         sizehint = PyLong_AsInt(fastargs[0]);
608         if (sizehint == -1 && PyErr_Occurred()) {
609             goto exit;
610         }
611         if (!--noptargs) {
612             goto skip_optional_pos;
613         }
614     }
615     flags = PyLong_AsInt(fastargs[1]);
616     if (flags == -1 && PyErr_Occurred()) {
617         goto exit;
618     }
619 skip_optional_pos:
620     return_value = select_epoll_impl(type, sizehint, flags);
621 
622 exit:
623     return return_value;
624 }
625 
626 #endif /* defined(HAVE_EPOLL) */
627 
628 #if defined(HAVE_EPOLL)
629 
630 PyDoc_STRVAR(select_epoll_close__doc__,
631 "close($self, /)\n"
632 "--\n"
633 "\n"
634 "Close the epoll control file descriptor.\n"
635 "\n"
636 "Further operations on the epoll object will raise an exception.");
637 
638 #define SELECT_EPOLL_CLOSE_METHODDEF    \
639     {"close", (PyCFunction)select_epoll_close, METH_NOARGS, select_epoll_close__doc__},
640 
641 static PyObject *
642 select_epoll_close_impl(pyEpoll_Object *self);
643 
644 static PyObject *
select_epoll_close(pyEpoll_Object * self,PyObject * Py_UNUSED (ignored))645 select_epoll_close(pyEpoll_Object *self, PyObject *Py_UNUSED(ignored))
646 {
647     PyObject *return_value = NULL;
648 
649     Py_BEGIN_CRITICAL_SECTION(self);
650     return_value = select_epoll_close_impl(self);
651     Py_END_CRITICAL_SECTION();
652 
653     return return_value;
654 }
655 
656 #endif /* defined(HAVE_EPOLL) */
657 
658 #if defined(HAVE_EPOLL)
659 
660 PyDoc_STRVAR(select_epoll_fileno__doc__,
661 "fileno($self, /)\n"
662 "--\n"
663 "\n"
664 "Return the epoll control file descriptor.");
665 
666 #define SELECT_EPOLL_FILENO_METHODDEF    \
667     {"fileno", (PyCFunction)select_epoll_fileno, METH_NOARGS, select_epoll_fileno__doc__},
668 
669 static PyObject *
670 select_epoll_fileno_impl(pyEpoll_Object *self);
671 
672 static PyObject *
select_epoll_fileno(pyEpoll_Object * self,PyObject * Py_UNUSED (ignored))673 select_epoll_fileno(pyEpoll_Object *self, PyObject *Py_UNUSED(ignored))
674 {
675     return select_epoll_fileno_impl(self);
676 }
677 
678 #endif /* defined(HAVE_EPOLL) */
679 
680 #if defined(HAVE_EPOLL)
681 
682 PyDoc_STRVAR(select_epoll_fromfd__doc__,
683 "fromfd($type, fd, /)\n"
684 "--\n"
685 "\n"
686 "Create an epoll object from a given control fd.");
687 
688 #define SELECT_EPOLL_FROMFD_METHODDEF    \
689     {"fromfd", (PyCFunction)select_epoll_fromfd, METH_O|METH_CLASS, select_epoll_fromfd__doc__},
690 
691 static PyObject *
692 select_epoll_fromfd_impl(PyTypeObject *type, int fd);
693 
694 static PyObject *
select_epoll_fromfd(PyTypeObject * type,PyObject * arg)695 select_epoll_fromfd(PyTypeObject *type, PyObject *arg)
696 {
697     PyObject *return_value = NULL;
698     int fd;
699 
700     fd = PyLong_AsInt(arg);
701     if (fd == -1 && PyErr_Occurred()) {
702         goto exit;
703     }
704     return_value = select_epoll_fromfd_impl(type, fd);
705 
706 exit:
707     return return_value;
708 }
709 
710 #endif /* defined(HAVE_EPOLL) */
711 
712 #if defined(HAVE_EPOLL)
713 
714 PyDoc_STRVAR(select_epoll_register__doc__,
715 "register($self, /, fd,\n"
716 "         eventmask=select.EPOLLIN | select.EPOLLPRI | select.EPOLLOUT)\n"
717 "--\n"
718 "\n"
719 "Registers a new fd or raises an OSError if the fd is already registered.\n"
720 "\n"
721 "  fd\n"
722 "    the target file descriptor of the operation\n"
723 "  eventmask\n"
724 "    a bit set composed of the various EPOLL constants\n"
725 "\n"
726 "The epoll interface supports all file descriptors that support poll.");
727 
728 #define SELECT_EPOLL_REGISTER_METHODDEF    \
729     {"register", _PyCFunction_CAST(select_epoll_register), METH_FASTCALL|METH_KEYWORDS, select_epoll_register__doc__},
730 
731 static PyObject *
732 select_epoll_register_impl(pyEpoll_Object *self, int fd,
733                            unsigned int eventmask);
734 
735 static PyObject *
select_epoll_register(pyEpoll_Object * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)736 select_epoll_register(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
737 {
738     PyObject *return_value = NULL;
739     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
740 
741     #define NUM_KEYWORDS 2
742     static struct {
743         PyGC_Head _this_is_not_used;
744         PyObject_VAR_HEAD
745         PyObject *ob_item[NUM_KEYWORDS];
746     } _kwtuple = {
747         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
748         .ob_item = { &_Py_ID(fd), &_Py_ID(eventmask), },
749     };
750     #undef NUM_KEYWORDS
751     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
752 
753     #else  // !Py_BUILD_CORE
754     #  define KWTUPLE NULL
755     #endif  // !Py_BUILD_CORE
756 
757     static const char * const _keywords[] = {"fd", "eventmask", NULL};
758     static _PyArg_Parser _parser = {
759         .keywords = _keywords,
760         .fname = "register",
761         .kwtuple = KWTUPLE,
762     };
763     #undef KWTUPLE
764     PyObject *argsbuf[2];
765     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
766     int fd;
767     unsigned int eventmask = EPOLLIN | EPOLLPRI | EPOLLOUT;
768 
769     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
770     if (!args) {
771         goto exit;
772     }
773     fd = PyObject_AsFileDescriptor(args[0]);
774     if (fd < 0) {
775         goto exit;
776     }
777     if (!noptargs) {
778         goto skip_optional_pos;
779     }
780     eventmask = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
781     if (eventmask == (unsigned int)-1 && PyErr_Occurred()) {
782         goto exit;
783     }
784 skip_optional_pos:
785     return_value = select_epoll_register_impl(self, fd, eventmask);
786 
787 exit:
788     return return_value;
789 }
790 
791 #endif /* defined(HAVE_EPOLL) */
792 
793 #if defined(HAVE_EPOLL)
794 
795 PyDoc_STRVAR(select_epoll_modify__doc__,
796 "modify($self, /, fd, eventmask)\n"
797 "--\n"
798 "\n"
799 "Modify event mask for a registered file descriptor.\n"
800 "\n"
801 "  fd\n"
802 "    the target file descriptor of the operation\n"
803 "  eventmask\n"
804 "    a bit set composed of the various EPOLL constants");
805 
806 #define SELECT_EPOLL_MODIFY_METHODDEF    \
807     {"modify", _PyCFunction_CAST(select_epoll_modify), METH_FASTCALL|METH_KEYWORDS, select_epoll_modify__doc__},
808 
809 static PyObject *
810 select_epoll_modify_impl(pyEpoll_Object *self, int fd,
811                          unsigned int eventmask);
812 
813 static PyObject *
select_epoll_modify(pyEpoll_Object * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)814 select_epoll_modify(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
815 {
816     PyObject *return_value = NULL;
817     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
818 
819     #define NUM_KEYWORDS 2
820     static struct {
821         PyGC_Head _this_is_not_used;
822         PyObject_VAR_HEAD
823         PyObject *ob_item[NUM_KEYWORDS];
824     } _kwtuple = {
825         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
826         .ob_item = { &_Py_ID(fd), &_Py_ID(eventmask), },
827     };
828     #undef NUM_KEYWORDS
829     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
830 
831     #else  // !Py_BUILD_CORE
832     #  define KWTUPLE NULL
833     #endif  // !Py_BUILD_CORE
834 
835     static const char * const _keywords[] = {"fd", "eventmask", NULL};
836     static _PyArg_Parser _parser = {
837         .keywords = _keywords,
838         .fname = "modify",
839         .kwtuple = KWTUPLE,
840     };
841     #undef KWTUPLE
842     PyObject *argsbuf[2];
843     int fd;
844     unsigned int eventmask;
845 
846     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
847     if (!args) {
848         goto exit;
849     }
850     fd = PyObject_AsFileDescriptor(args[0]);
851     if (fd < 0) {
852         goto exit;
853     }
854     eventmask = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
855     if (eventmask == (unsigned int)-1 && PyErr_Occurred()) {
856         goto exit;
857     }
858     return_value = select_epoll_modify_impl(self, fd, eventmask);
859 
860 exit:
861     return return_value;
862 }
863 
864 #endif /* defined(HAVE_EPOLL) */
865 
866 #if defined(HAVE_EPOLL)
867 
868 PyDoc_STRVAR(select_epoll_unregister__doc__,
869 "unregister($self, /, fd)\n"
870 "--\n"
871 "\n"
872 "Remove a registered file descriptor from the epoll object.\n"
873 "\n"
874 "  fd\n"
875 "    the target file descriptor of the operation");
876 
877 #define SELECT_EPOLL_UNREGISTER_METHODDEF    \
878     {"unregister", _PyCFunction_CAST(select_epoll_unregister), METH_FASTCALL|METH_KEYWORDS, select_epoll_unregister__doc__},
879 
880 static PyObject *
881 select_epoll_unregister_impl(pyEpoll_Object *self, int fd);
882 
883 static PyObject *
select_epoll_unregister(pyEpoll_Object * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)884 select_epoll_unregister(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
885 {
886     PyObject *return_value = NULL;
887     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
888 
889     #define NUM_KEYWORDS 1
890     static struct {
891         PyGC_Head _this_is_not_used;
892         PyObject_VAR_HEAD
893         PyObject *ob_item[NUM_KEYWORDS];
894     } _kwtuple = {
895         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
896         .ob_item = { &_Py_ID(fd), },
897     };
898     #undef NUM_KEYWORDS
899     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
900 
901     #else  // !Py_BUILD_CORE
902     #  define KWTUPLE NULL
903     #endif  // !Py_BUILD_CORE
904 
905     static const char * const _keywords[] = {"fd", NULL};
906     static _PyArg_Parser _parser = {
907         .keywords = _keywords,
908         .fname = "unregister",
909         .kwtuple = KWTUPLE,
910     };
911     #undef KWTUPLE
912     PyObject *argsbuf[1];
913     int fd;
914 
915     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
916     if (!args) {
917         goto exit;
918     }
919     fd = PyObject_AsFileDescriptor(args[0]);
920     if (fd < 0) {
921         goto exit;
922     }
923     return_value = select_epoll_unregister_impl(self, fd);
924 
925 exit:
926     return return_value;
927 }
928 
929 #endif /* defined(HAVE_EPOLL) */
930 
931 #if defined(HAVE_EPOLL)
932 
933 PyDoc_STRVAR(select_epoll_poll__doc__,
934 "poll($self, /, timeout=None, maxevents=-1)\n"
935 "--\n"
936 "\n"
937 "Wait for events on the epoll file descriptor.\n"
938 "\n"
939 "  timeout\n"
940 "    the maximum time to wait in seconds (as float);\n"
941 "    a timeout of None or -1 makes poll wait indefinitely\n"
942 "  maxevents\n"
943 "    the maximum number of events returned; -1 means no limit\n"
944 "\n"
945 "Returns a list containing any descriptors that have events to report,\n"
946 "as a list of (fd, events) 2-tuples.");
947 
948 #define SELECT_EPOLL_POLL_METHODDEF    \
949     {"poll", _PyCFunction_CAST(select_epoll_poll), METH_FASTCALL|METH_KEYWORDS, select_epoll_poll__doc__},
950 
951 static PyObject *
952 select_epoll_poll_impl(pyEpoll_Object *self, PyObject *timeout_obj,
953                        int maxevents);
954 
955 static PyObject *
select_epoll_poll(pyEpoll_Object * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)956 select_epoll_poll(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
957 {
958     PyObject *return_value = NULL;
959     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
960 
961     #define NUM_KEYWORDS 2
962     static struct {
963         PyGC_Head _this_is_not_used;
964         PyObject_VAR_HEAD
965         PyObject *ob_item[NUM_KEYWORDS];
966     } _kwtuple = {
967         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
968         .ob_item = { &_Py_ID(timeout), &_Py_ID(maxevents), },
969     };
970     #undef NUM_KEYWORDS
971     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
972 
973     #else  // !Py_BUILD_CORE
974     #  define KWTUPLE NULL
975     #endif  // !Py_BUILD_CORE
976 
977     static const char * const _keywords[] = {"timeout", "maxevents", NULL};
978     static _PyArg_Parser _parser = {
979         .keywords = _keywords,
980         .fname = "poll",
981         .kwtuple = KWTUPLE,
982     };
983     #undef KWTUPLE
984     PyObject *argsbuf[2];
985     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
986     PyObject *timeout_obj = Py_None;
987     int maxevents = -1;
988 
989     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
990     if (!args) {
991         goto exit;
992     }
993     if (!noptargs) {
994         goto skip_optional_pos;
995     }
996     if (args[0]) {
997         timeout_obj = args[0];
998         if (!--noptargs) {
999             goto skip_optional_pos;
1000         }
1001     }
1002     maxevents = PyLong_AsInt(args[1]);
1003     if (maxevents == -1 && PyErr_Occurred()) {
1004         goto exit;
1005     }
1006 skip_optional_pos:
1007     return_value = select_epoll_poll_impl(self, timeout_obj, maxevents);
1008 
1009 exit:
1010     return return_value;
1011 }
1012 
1013 #endif /* defined(HAVE_EPOLL) */
1014 
1015 #if defined(HAVE_EPOLL)
1016 
1017 PyDoc_STRVAR(select_epoll___enter____doc__,
1018 "__enter__($self, /)\n"
1019 "--\n"
1020 "\n");
1021 
1022 #define SELECT_EPOLL___ENTER___METHODDEF    \
1023     {"__enter__", (PyCFunction)select_epoll___enter__, METH_NOARGS, select_epoll___enter____doc__},
1024 
1025 static PyObject *
1026 select_epoll___enter___impl(pyEpoll_Object *self);
1027 
1028 static PyObject *
select_epoll___enter__(pyEpoll_Object * self,PyObject * Py_UNUSED (ignored))1029 select_epoll___enter__(pyEpoll_Object *self, PyObject *Py_UNUSED(ignored))
1030 {
1031     return select_epoll___enter___impl(self);
1032 }
1033 
1034 #endif /* defined(HAVE_EPOLL) */
1035 
1036 #if defined(HAVE_EPOLL)
1037 
1038 PyDoc_STRVAR(select_epoll___exit____doc__,
1039 "__exit__($self, exc_type=None, exc_value=None, exc_tb=None, /)\n"
1040 "--\n"
1041 "\n");
1042 
1043 #define SELECT_EPOLL___EXIT___METHODDEF    \
1044     {"__exit__", _PyCFunction_CAST(select_epoll___exit__), METH_FASTCALL, select_epoll___exit____doc__},
1045 
1046 static PyObject *
1047 select_epoll___exit___impl(pyEpoll_Object *self, PyObject *exc_type,
1048                            PyObject *exc_value, PyObject *exc_tb);
1049 
1050 static PyObject *
select_epoll___exit__(pyEpoll_Object * self,PyObject * const * args,Py_ssize_t nargs)1051 select_epoll___exit__(pyEpoll_Object *self, PyObject *const *args, Py_ssize_t nargs)
1052 {
1053     PyObject *return_value = NULL;
1054     PyObject *exc_type = Py_None;
1055     PyObject *exc_value = Py_None;
1056     PyObject *exc_tb = Py_None;
1057 
1058     if (!_PyArg_CheckPositional("__exit__", nargs, 0, 3)) {
1059         goto exit;
1060     }
1061     if (nargs < 1) {
1062         goto skip_optional;
1063     }
1064     exc_type = args[0];
1065     if (nargs < 2) {
1066         goto skip_optional;
1067     }
1068     exc_value = args[1];
1069     if (nargs < 3) {
1070         goto skip_optional;
1071     }
1072     exc_tb = args[2];
1073 skip_optional:
1074     return_value = select_epoll___exit___impl(self, exc_type, exc_value, exc_tb);
1075 
1076 exit:
1077     return return_value;
1078 }
1079 
1080 #endif /* defined(HAVE_EPOLL) */
1081 
1082 #if defined(HAVE_KQUEUE)
1083 
1084 PyDoc_STRVAR(select_kqueue__doc__,
1085 "kqueue()\n"
1086 "--\n"
1087 "\n"
1088 "Kqueue syscall wrapper.\n"
1089 "\n"
1090 "For example, to start watching a socket for input:\n"
1091 ">>> kq = kqueue()\n"
1092 ">>> sock = socket()\n"
1093 ">>> sock.connect((host, port))\n"
1094 ">>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_ADD)], 0)\n"
1095 "\n"
1096 "To wait one second for it to become writeable:\n"
1097 ">>> kq.control(None, 1, 1000)\n"
1098 "\n"
1099 "To stop listening:\n"
1100 ">>> kq.control([kevent(sock, KQ_FILTER_WRITE, KQ_EV_DELETE)], 0)");
1101 
1102 static PyObject *
1103 select_kqueue_impl(PyTypeObject *type);
1104 
1105 static PyObject *
select_kqueue(PyTypeObject * type,PyObject * args,PyObject * kwargs)1106 select_kqueue(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1107 {
1108     PyObject *return_value = NULL;
1109     PyTypeObject *base_tp = _selectstate_by_type(type)->kqueue_queue_Type;
1110 
1111     if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
1112         !_PyArg_NoPositional("kqueue", args)) {
1113         goto exit;
1114     }
1115     if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
1116         !_PyArg_NoKeywords("kqueue", kwargs)) {
1117         goto exit;
1118     }
1119     return_value = select_kqueue_impl(type);
1120 
1121 exit:
1122     return return_value;
1123 }
1124 
1125 #endif /* defined(HAVE_KQUEUE) */
1126 
1127 #if defined(HAVE_KQUEUE)
1128 
1129 PyDoc_STRVAR(select_kqueue_close__doc__,
1130 "close($self, /)\n"
1131 "--\n"
1132 "\n"
1133 "Close the kqueue control file descriptor.\n"
1134 "\n"
1135 "Further operations on the kqueue object will raise an exception.");
1136 
1137 #define SELECT_KQUEUE_CLOSE_METHODDEF    \
1138     {"close", (PyCFunction)select_kqueue_close, METH_NOARGS, select_kqueue_close__doc__},
1139 
1140 static PyObject *
1141 select_kqueue_close_impl(kqueue_queue_Object *self);
1142 
1143 static PyObject *
select_kqueue_close(kqueue_queue_Object * self,PyObject * Py_UNUSED (ignored))1144 select_kqueue_close(kqueue_queue_Object *self, PyObject *Py_UNUSED(ignored))
1145 {
1146     PyObject *return_value = NULL;
1147 
1148     Py_BEGIN_CRITICAL_SECTION(self);
1149     return_value = select_kqueue_close_impl(self);
1150     Py_END_CRITICAL_SECTION();
1151 
1152     return return_value;
1153 }
1154 
1155 #endif /* defined(HAVE_KQUEUE) */
1156 
1157 #if defined(HAVE_KQUEUE)
1158 
1159 PyDoc_STRVAR(select_kqueue_fileno__doc__,
1160 "fileno($self, /)\n"
1161 "--\n"
1162 "\n"
1163 "Return the kqueue control file descriptor.");
1164 
1165 #define SELECT_KQUEUE_FILENO_METHODDEF    \
1166     {"fileno", (PyCFunction)select_kqueue_fileno, METH_NOARGS, select_kqueue_fileno__doc__},
1167 
1168 static PyObject *
1169 select_kqueue_fileno_impl(kqueue_queue_Object *self);
1170 
1171 static PyObject *
select_kqueue_fileno(kqueue_queue_Object * self,PyObject * Py_UNUSED (ignored))1172 select_kqueue_fileno(kqueue_queue_Object *self, PyObject *Py_UNUSED(ignored))
1173 {
1174     return select_kqueue_fileno_impl(self);
1175 }
1176 
1177 #endif /* defined(HAVE_KQUEUE) */
1178 
1179 #if defined(HAVE_KQUEUE)
1180 
1181 PyDoc_STRVAR(select_kqueue_fromfd__doc__,
1182 "fromfd($type, fd, /)\n"
1183 "--\n"
1184 "\n"
1185 "Create a kqueue object from a given control fd.");
1186 
1187 #define SELECT_KQUEUE_FROMFD_METHODDEF    \
1188     {"fromfd", (PyCFunction)select_kqueue_fromfd, METH_O|METH_CLASS, select_kqueue_fromfd__doc__},
1189 
1190 static PyObject *
1191 select_kqueue_fromfd_impl(PyTypeObject *type, int fd);
1192 
1193 static PyObject *
select_kqueue_fromfd(PyTypeObject * type,PyObject * arg)1194 select_kqueue_fromfd(PyTypeObject *type, PyObject *arg)
1195 {
1196     PyObject *return_value = NULL;
1197     int fd;
1198 
1199     fd = PyLong_AsInt(arg);
1200     if (fd == -1 && PyErr_Occurred()) {
1201         goto exit;
1202     }
1203     return_value = select_kqueue_fromfd_impl(type, fd);
1204 
1205 exit:
1206     return return_value;
1207 }
1208 
1209 #endif /* defined(HAVE_KQUEUE) */
1210 
1211 #if defined(HAVE_KQUEUE)
1212 
1213 PyDoc_STRVAR(select_kqueue_control__doc__,
1214 "control($self, changelist, maxevents, timeout=None, /)\n"
1215 "--\n"
1216 "\n"
1217 "Calls the kernel kevent function.\n"
1218 "\n"
1219 "  changelist\n"
1220 "    Must be an iterable of kevent objects describing the changes to be made\n"
1221 "    to the kernel\'s watch list or None.\n"
1222 "  maxevents\n"
1223 "    The maximum number of events that the kernel will return.\n"
1224 "  timeout\n"
1225 "    The maximum time to wait in seconds, or else None to wait forever.\n"
1226 "    This accepts floats for smaller timeouts, too.");
1227 
1228 #define SELECT_KQUEUE_CONTROL_METHODDEF    \
1229     {"control", _PyCFunction_CAST(select_kqueue_control), METH_FASTCALL, select_kqueue_control__doc__},
1230 
1231 static PyObject *
1232 select_kqueue_control_impl(kqueue_queue_Object *self, PyObject *changelist,
1233                            int maxevents, PyObject *otimeout);
1234 
1235 static PyObject *
select_kqueue_control(kqueue_queue_Object * self,PyObject * const * args,Py_ssize_t nargs)1236 select_kqueue_control(kqueue_queue_Object *self, PyObject *const *args, Py_ssize_t nargs)
1237 {
1238     PyObject *return_value = NULL;
1239     PyObject *changelist;
1240     int maxevents;
1241     PyObject *otimeout = Py_None;
1242 
1243     if (!_PyArg_CheckPositional("control", nargs, 2, 3)) {
1244         goto exit;
1245     }
1246     changelist = args[0];
1247     maxevents = PyLong_AsInt(args[1]);
1248     if (maxevents == -1 && PyErr_Occurred()) {
1249         goto exit;
1250     }
1251     if (nargs < 3) {
1252         goto skip_optional;
1253     }
1254     otimeout = args[2];
1255 skip_optional:
1256     return_value = select_kqueue_control_impl(self, changelist, maxevents, otimeout);
1257 
1258 exit:
1259     return return_value;
1260 }
1261 
1262 #endif /* defined(HAVE_KQUEUE) */
1263 
1264 #ifndef SELECT_POLL_REGISTER_METHODDEF
1265     #define SELECT_POLL_REGISTER_METHODDEF
1266 #endif /* !defined(SELECT_POLL_REGISTER_METHODDEF) */
1267 
1268 #ifndef SELECT_POLL_MODIFY_METHODDEF
1269     #define SELECT_POLL_MODIFY_METHODDEF
1270 #endif /* !defined(SELECT_POLL_MODIFY_METHODDEF) */
1271 
1272 #ifndef SELECT_POLL_UNREGISTER_METHODDEF
1273     #define SELECT_POLL_UNREGISTER_METHODDEF
1274 #endif /* !defined(SELECT_POLL_UNREGISTER_METHODDEF) */
1275 
1276 #ifndef SELECT_POLL_POLL_METHODDEF
1277     #define SELECT_POLL_POLL_METHODDEF
1278 #endif /* !defined(SELECT_POLL_POLL_METHODDEF) */
1279 
1280 #ifndef SELECT_DEVPOLL_REGISTER_METHODDEF
1281     #define SELECT_DEVPOLL_REGISTER_METHODDEF
1282 #endif /* !defined(SELECT_DEVPOLL_REGISTER_METHODDEF) */
1283 
1284 #ifndef SELECT_DEVPOLL_MODIFY_METHODDEF
1285     #define SELECT_DEVPOLL_MODIFY_METHODDEF
1286 #endif /* !defined(SELECT_DEVPOLL_MODIFY_METHODDEF) */
1287 
1288 #ifndef SELECT_DEVPOLL_UNREGISTER_METHODDEF
1289     #define SELECT_DEVPOLL_UNREGISTER_METHODDEF
1290 #endif /* !defined(SELECT_DEVPOLL_UNREGISTER_METHODDEF) */
1291 
1292 #ifndef SELECT_DEVPOLL_POLL_METHODDEF
1293     #define SELECT_DEVPOLL_POLL_METHODDEF
1294 #endif /* !defined(SELECT_DEVPOLL_POLL_METHODDEF) */
1295 
1296 #ifndef SELECT_DEVPOLL_CLOSE_METHODDEF
1297     #define SELECT_DEVPOLL_CLOSE_METHODDEF
1298 #endif /* !defined(SELECT_DEVPOLL_CLOSE_METHODDEF) */
1299 
1300 #ifndef SELECT_DEVPOLL_FILENO_METHODDEF
1301     #define SELECT_DEVPOLL_FILENO_METHODDEF
1302 #endif /* !defined(SELECT_DEVPOLL_FILENO_METHODDEF) */
1303 
1304 #ifndef SELECT_POLL_METHODDEF
1305     #define SELECT_POLL_METHODDEF
1306 #endif /* !defined(SELECT_POLL_METHODDEF) */
1307 
1308 #ifndef SELECT_DEVPOLL_METHODDEF
1309     #define SELECT_DEVPOLL_METHODDEF
1310 #endif /* !defined(SELECT_DEVPOLL_METHODDEF) */
1311 
1312 #ifndef SELECT_EPOLL_CLOSE_METHODDEF
1313     #define SELECT_EPOLL_CLOSE_METHODDEF
1314 #endif /* !defined(SELECT_EPOLL_CLOSE_METHODDEF) */
1315 
1316 #ifndef SELECT_EPOLL_FILENO_METHODDEF
1317     #define SELECT_EPOLL_FILENO_METHODDEF
1318 #endif /* !defined(SELECT_EPOLL_FILENO_METHODDEF) */
1319 
1320 #ifndef SELECT_EPOLL_FROMFD_METHODDEF
1321     #define SELECT_EPOLL_FROMFD_METHODDEF
1322 #endif /* !defined(SELECT_EPOLL_FROMFD_METHODDEF) */
1323 
1324 #ifndef SELECT_EPOLL_REGISTER_METHODDEF
1325     #define SELECT_EPOLL_REGISTER_METHODDEF
1326 #endif /* !defined(SELECT_EPOLL_REGISTER_METHODDEF) */
1327 
1328 #ifndef SELECT_EPOLL_MODIFY_METHODDEF
1329     #define SELECT_EPOLL_MODIFY_METHODDEF
1330 #endif /* !defined(SELECT_EPOLL_MODIFY_METHODDEF) */
1331 
1332 #ifndef SELECT_EPOLL_UNREGISTER_METHODDEF
1333     #define SELECT_EPOLL_UNREGISTER_METHODDEF
1334 #endif /* !defined(SELECT_EPOLL_UNREGISTER_METHODDEF) */
1335 
1336 #ifndef SELECT_EPOLL_POLL_METHODDEF
1337     #define SELECT_EPOLL_POLL_METHODDEF
1338 #endif /* !defined(SELECT_EPOLL_POLL_METHODDEF) */
1339 
1340 #ifndef SELECT_EPOLL___ENTER___METHODDEF
1341     #define SELECT_EPOLL___ENTER___METHODDEF
1342 #endif /* !defined(SELECT_EPOLL___ENTER___METHODDEF) */
1343 
1344 #ifndef SELECT_EPOLL___EXIT___METHODDEF
1345     #define SELECT_EPOLL___EXIT___METHODDEF
1346 #endif /* !defined(SELECT_EPOLL___EXIT___METHODDEF) */
1347 
1348 #ifndef SELECT_KQUEUE_CLOSE_METHODDEF
1349     #define SELECT_KQUEUE_CLOSE_METHODDEF
1350 #endif /* !defined(SELECT_KQUEUE_CLOSE_METHODDEF) */
1351 
1352 #ifndef SELECT_KQUEUE_FILENO_METHODDEF
1353     #define SELECT_KQUEUE_FILENO_METHODDEF
1354 #endif /* !defined(SELECT_KQUEUE_FILENO_METHODDEF) */
1355 
1356 #ifndef SELECT_KQUEUE_FROMFD_METHODDEF
1357     #define SELECT_KQUEUE_FROMFD_METHODDEF
1358 #endif /* !defined(SELECT_KQUEUE_FROMFD_METHODDEF) */
1359 
1360 #ifndef SELECT_KQUEUE_CONTROL_METHODDEF
1361     #define SELECT_KQUEUE_CONTROL_METHODDEF
1362 #endif /* !defined(SELECT_KQUEUE_CONTROL_METHODDEF) */
1363 /*[clinic end generated code: output=f99427b75cbe6d44 input=a9049054013a1b77]*/
1364