Skip to content

Commit

Permalink
gh-117764: Use Argument Clinic for signal.set_wakeup_fd() (GH-117777)
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka authored Apr 12, 2024
1 parent 3a8c1ca commit 39a6b29
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 26 deletions.
1 change: 1 addition & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(version)
STRUCT_FOR_ID(volume)
STRUCT_FOR_ID(wait_all)
STRUCT_FOR_ID(warn_on_full_buffer)
STRUCT_FOR_ID(warnings)
STRUCT_FOR_ID(warnoptions)
STRUCT_FOR_ID(wbits)
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 76 additions & 1 deletion Modules/clinic/signalmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 24 additions & 25 deletions Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,35 +706,43 @@ signal_siginterrupt_impl(PyObject *module, int signalnum, int flag)
#endif


static PyObject*
signal_set_wakeup_fd(PyObject *self, PyObject *args, PyObject *kwds)
/*[clinic input]
signal.set_wakeup_fd
fd as fdobj: object
/
*
warn_on_full_buffer: bool = True
Sets the fd to be written to (with the signal number) when a signal comes in.
A library can use this to wakeup select or poll.
The previous fd or -1 is returned.
The fd must be non-blocking.
[clinic start generated code]*/

static PyObject *
signal_set_wakeup_fd_impl(PyObject *module, PyObject *fdobj,
int warn_on_full_buffer)
/*[clinic end generated code: output=2280d72dd2a54c4f input=5b545946a28b8339]*/
{
struct _Py_stat_struct status;
static char *kwlist[] = {
"", "warn_on_full_buffer", NULL,
};
int warn_on_full_buffer = 1;
#ifdef MS_WINDOWS
PyObject *fdobj;
SOCKET_T sockfd, old_sockfd;
int res;
int res_size = sizeof res;
PyObject *mod;
int is_socket;

if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|$p:set_wakeup_fd", kwlist,
&fdobj, &warn_on_full_buffer))
return NULL;

sockfd = PyLong_AsSocket_t(fdobj);
if (sockfd == (SOCKET_T)(-1) && PyErr_Occurred())
return NULL;
#else
int fd;

if (!PyArg_ParseTupleAndKeywords(args, kwds, "i|$p:set_wakeup_fd", kwlist,
&fd, &warn_on_full_buffer))
int fd = PyLong_AsInt(fdobj);
if (fd == -1 && PyErr_Occurred()) {
return NULL;
}
#endif

PyThreadState *tstate = _PyThreadState_GET();
Expand Down Expand Up @@ -820,15 +828,6 @@ signal_set_wakeup_fd(PyObject *self, PyObject *args, PyObject *kwds)
#endif
}

PyDoc_STRVAR(set_wakeup_fd_doc,
"set_wakeup_fd(fd, *, warn_on_full_buffer=True) -> fd\n\
\n\
Sets the fd to be written to (with the signal number) when a signal\n\
comes in. A library can use this to wakeup select or poll.\n\
The previous fd or -1 is returned.\n\
\n\
The fd must be non-blocking.");

/* C API for the same, without all the error checking */
int
PySignal_SetWakeupFd(int fd)
Expand Down Expand Up @@ -1344,7 +1343,7 @@ static PyMethodDef signal_methods[] = {
SIGNAL_RAISE_SIGNAL_METHODDEF
SIGNAL_STRSIGNAL_METHODDEF
SIGNAL_GETSIGNAL_METHODDEF
{"set_wakeup_fd", _PyCFunction_CAST(signal_set_wakeup_fd), METH_VARARGS | METH_KEYWORDS, set_wakeup_fd_doc},
SIGNAL_SET_WAKEUP_FD_METHODDEF
SIGNAL_SIGINTERRUPT_METHODDEF
SIGNAL_PAUSE_METHODDEF
SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF
Expand Down

0 comments on commit 39a6b29

Please sign in to comment.