From 9139210db67f0148abf761e0034b4f8b5ac77549 Mon Sep 17 00:00:00 2001 From: Malek Date: Mon, 13 Sep 2021 08:34:02 +0200 Subject: [PATCH] version 1.5.1 --- docs/conf.py | 2 +- mood/__init__.py | 2 +- setup.py | 131 ++++++++++++++-------------- src/Async.c | 28 ++++-- src/Check.c | 16 ++-- src/Child.c | 77 +++++++++++------ src/Embed.c | 60 +++++++++---- src/Fork.c | 16 ++-- src/Idle.c | 16 ++-- src/Io.c | 66 +++++++++----- src/Loop.c | 220 ++++++++++++++++++++++++++++++++--------------- src/Periodic.c | 140 ++++++++++++++++++++---------- src/Prepare.c | 16 ++-- src/Signal.c | 54 ++++++++---- src/Timer.c | 69 ++++++++++----- src/Watcher.c | 88 +++++++++++++------ src/event.c | 91 +++++++++++++------- src/event.h | 7 +- 18 files changed, 726 insertions(+), 373 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index c579bb4..6fbc4f8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -47,7 +47,7 @@ # General information about the project. project = 'mood.event' -copyright = '2020, lekma' +copyright = '2021, lekma' author = 'lekma' # The version info for the project you're documenting, acts as replacement for diff --git a/mood/__init__.py b/mood/__init__.py index 6a577ad..de3b521 100644 --- a/mood/__init__.py +++ b/mood/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. diff --git a/setup.py b/setup.py index 8d0b7bc..ee8c659 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -33,7 +33,7 @@ # pkg pkg_name = "mood.event" -pkg_version = "1.5.0" +pkg_version = "1.5.1" pkg_desc = "Python libev interface" PKG_VERSION = ("PKG_VERSION", "\"{0}\"".format(pkg_version)) @@ -41,8 +41,10 @@ err_msg = "Aborted: {0}-{1} requires {{0}} >= {{1}}".format(pkg_name, pkg_version) def check_version(current_version, minimum_version, name): - if (not current_version or - (LooseVersion(current_version) < LooseVersion(minimum_version))): + if ( + not current_version or + (LooseVersion(current_version) < LooseVersion(minimum_version)) + ): raise SystemExit(err_msg.format(name, minimum_version)) @@ -54,8 +56,9 @@ def libev_version(): libev_dll_name = find_library(libev_name) if libev_dll_name: libev_dll = cdll.LoadLibrary(libev_dll_name) - return "{0}.{1}".format(libev_dll.ev_version_major(), - libev_dll.ev_version_minor()) + return "{0}.{1}".format( + libev_dll.ev_version_major(), libev_dll.ev_version_minor() + ) # setup @@ -63,62 +66,64 @@ def libev_version(): check_version(libev_version(), libev_min_version, "libev") setup( - name=pkg_name, - version=pkg_version, - description=pkg_desc, - long_description=open(abspath("README.txt"), encoding="utf-8").read(), - long_description_content_type="text", - - url="https://github.com/lekma/mood.event", - download_url="https://github.com/lekma/mood.event/releases", - project_urls={ - "Documentation": "https://mood.readthedocs.io/projects/event/", - "Bug Tracker": "https://github.com/lekma/mood.event/issues" - }, - author="Malek Hadj-Ali", - author_email="lekmalek@gmail.com", - license="GNU General Public License v3 (GPLv3)", - platforms=["POSIX"], - keywords="libev event", - - setup_requires = ["setuptools>=24.2.0"], - python_requires="~=3.8", - packages=find_packages(), - namespace_packages=["mood"], - zip_safe=False, - - ext_package="mood", - ext_modules=[ - Extension("event", - [ - "src/helpers/helpers.c", - "src/Loop.c", - "src/Watcher.c", - "src/Io.c", - "src/Timer.c", - "src/Periodic.c", - "src/Signal.c", - "src/Child.c", - "src/Idle.c", - "src/Prepare.c", - "src/Check.c", - "src/Embed.c", - "src/Fork.c", - "src/Async.c", - "src/event.c", - ], - define_macros=[PKG_VERSION], - libraries=[libev_name]) - ], - - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "Intended Audience :: System Administrators", - "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", - "Operating System :: POSIX", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: Implementation :: CPython" - ] + name=pkg_name, + version=pkg_version, + description=pkg_desc, + long_description=open(abspath("README.txt"), encoding="utf-8").read(), + long_description_content_type="text", + + url="https://github.com/lekma/mood.event", + download_url="https://github.com/lekma/mood.event/releases", + project_urls={ + "Documentation": "https://mood.readthedocs.io/projects/event/", + "Bug Tracker": "https://github.com/lekma/mood.event/issues" + }, + author="Malek Hadj-Ali", + author_email="lekmalek@gmail.com", + license="GNU General Public License v3 (GPLv3)", + platforms=["POSIX"], + keywords="libev event", + + setup_requires = ["setuptools>=24.2.0"], + python_requires="~=3.8", + packages=find_packages(), + namespace_packages=["mood"], + zip_safe=False, + + ext_package="mood", + ext_modules=[ + Extension( + "event", + [ + "src/helpers/helpers.c", + "src/Loop.c", + "src/Watcher.c", + "src/Io.c", + "src/Timer.c", + "src/Periodic.c", + "src/Signal.c", + "src/Child.c", + "src/Idle.c", + "src/Prepare.c", + "src/Check.c", + "src/Embed.c", + "src/Fork.c", + "src/Async.c", + "src/event.c", + ], + define_macros=[PKG_VERSION], + libraries=[libev_name] + ) + ], + + classifiers=[ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Intended Audience :: System Administrators", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Operating System :: POSIX", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: Implementation :: CPython" + ] ) diff --git a/src/Async.c b/src/Async.c index aa260a1..eb9210b 100644 --- a/src/Async.c +++ b/src/Async.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -58,8 +58,10 @@ Async_send(Watcher *self) /* Async_Type.tp_methods */ static PyMethodDef Async_tp_methods[] = { - {"send", (PyCFunction)Async_send, METH_NOARGS, - "send()"}, + { + "send", (PyCFunction)Async_send, + METH_NOARGS, "send()" + }, {NULL} /* Sentinel */ }; @@ -74,8 +76,10 @@ Async_sent_getter(Watcher *self, void *closure) /* Async_Type.tp_getsets */ static PyGetSetDef Async_tp_getsets[] = { - {"sent", (getter)Async_sent_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, + { + "sent", (getter)Async_sent_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, {NULL} /* Sentinel */ }; @@ -97,16 +101,22 @@ PyTypeObject Async_Type = { Watcher * Async_New(Loop *loop, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"callback", "data", "priority", NULL}; + static char *kwlist[] = { + "callback", "data", "priority", NULL + }; PyObject *callback = NULL, *data = Py_None; int priority = 0; Watcher *self = NULL; - if (PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oi:async", kwlist, - &callback, &data, &priority) && + if ( + PyArg_ParseTupleAndKeywords( + args, kwargs, "O|Oi:async", kwlist, + &callback, &data, &priority + ) && (self = __Async_New(&Async_Type)) && - Watcher_Init(self, loop, callback, data, priority)) { + Watcher_Init(self, loop, callback, data, priority) + ) { Py_CLEAR(self); } return self; diff --git a/src/Check.c b/src/Check.c index ec36199..8d04397 100644 --- a/src/Check.c +++ b/src/Check.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -62,16 +62,22 @@ PyTypeObject Check_Type = { Watcher * Check_New(Loop *loop, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"callback", "data", "priority", NULL}; + static char *kwlist[] = { + "callback", "data", "priority", NULL + }; PyObject *callback = NULL, *data = Py_None; int priority = 0; Watcher *self = NULL; - if (PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oi:check", kwlist, - &callback, &data, &priority) && + if ( + PyArg_ParseTupleAndKeywords( + args, kwargs, "O|Oi:check", kwlist, + &callback, &data, &priority + ) && (self = __Check_New(&Check_Type)) && - Watcher_Init(self, loop, callback, data, priority)) { + Watcher_Init(self, loop, callback, data, priority) + ) { Py_CLEAR(self); } return self; diff --git a/src/Child.c b/src/Child.c index 3c0d114..2ea8ba6 100644 --- a/src/Child.c +++ b/src/Child.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -33,7 +33,8 @@ __Child_CheckLoop(Loop *loop) { if (!ev_is_default_loop(loop->loop)) { PyErr_SetString( - Error, "Child watchers are only supported in the 'default loop'"); + Error, "Child watchers are only supported in the 'default loop'" + ); return -1; } return 0; @@ -73,21 +74,29 @@ Child_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) static int Child_tp_init(Watcher *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"pid", "trace", - "loop", "callback", "data", "priority", NULL}; + static char *kwlist[] = { + "pid", "trace", + "loop", "callback", "data", "priority", NULL + }; int pid = 0, trace = 0; Loop *loop = NULL; PyObject *callback = NULL, *data = Py_None; int priority = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ipO!O|Oi:__init__", kwlist, + if ( + !PyArg_ParseTupleAndKeywords( + args, kwargs, "ipO!O|Oi:__init__", kwlist, &pid, &trace, - &Loop_Type, &loop, &callback, &data, &priority)) { + &Loop_Type, &loop, &callback, &data, &priority + ) + ) { return -1; } - if (__Child_CheckLoop(loop) || - Watcher_Init(self, loop, callback, data, priority)) { + if ( + __Child_CheckLoop(loop) || + Watcher_Init(self, loop, callback, data, priority) + ) { return -1; } return __Child_Set(self, pid, trace); @@ -100,9 +109,11 @@ Child_set(Watcher *self, PyObject *args) { int pid = 0, trace = 0; - if (Watcher_CannotSet(self) || + if ( + Watcher_CannotSet(self) || !PyArg_ParseTuple(args, "ip:set", &pid, &trace) || - __Child_Set(self, pid, trace)) { + __Child_Set(self, pid, trace) + ) { return NULL; } Py_RETURN_NONE; @@ -111,8 +122,10 @@ Child_set(Watcher *self, PyObject *args) /* Child_Type.tp_methods */ static PyMethodDef Child_tp_methods[] = { - {"set", (PyCFunction)Child_set, METH_VARARGS, - "set(pid, trace)"}, + { + "set", (PyCFunction)Child_set, + METH_VARARGS, "set(pid, trace)" + }, {NULL} /* Sentinel */ }; @@ -169,12 +182,18 @@ Child_pid_getter(Watcher *self, void *closure) /* Child_Type.tp_getsets */ static PyGetSetDef Child_tp_getsets[] = { - {"rpid", (getter)Child_rpid_getter, - (setter)Child_rpid_setter, NULL, NULL}, - {"rstatus", (getter)Child_rstatus_getter, - (setter)Child_rstatus_setter, NULL, NULL}, - {"pid", (getter)Child_pid_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, + { + "rpid", (getter)Child_rpid_getter, + (setter)Child_rpid_setter, NULL, NULL + }, + { + "rstatus", (getter)Child_rstatus_getter, + (setter)Child_rstatus_setter, NULL, NULL + }, + { + "pid", (getter)Child_pid_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, {NULL} /* Sentinel */ }; @@ -197,21 +216,29 @@ PyTypeObject Child_Type = { Watcher * Child_New(Loop *loop, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"pid", "trace", - "callback", "data", "priority", NULL}; + static char *kwlist[] = { + "pid", "trace", + "callback", "data", "priority", NULL + }; int pid = 0, trace = 0; PyObject *callback = NULL, *data = Py_None; int priority = 0; Watcher *self = NULL; - if (!__Child_CheckLoop(loop) && - PyArg_ParseTupleAndKeywords(args, kwargs, "ipO|Oi:child", kwlist, + if ( + !__Child_CheckLoop(loop) && + PyArg_ParseTupleAndKeywords( + args, kwargs, "ipO|Oi:child", kwlist, &pid, &trace, - &callback, &data, &priority) && + &callback, &data, &priority + ) && (self = __Child_New(&Child_Type)) && - (Watcher_Init(self, loop, callback, data, priority) || - __Child_Set(self, pid, trace))) { + ( + Watcher_Init(self, loop, callback, data, priority) || + __Child_Set(self, pid, trace) + ) + ) { Py_CLEAR(self); } return self; diff --git a/src/Embed.c b/src/Embed.c index 72c2dca..7a4c077 100644 --- a/src/Embed.c +++ b/src/Embed.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -100,16 +100,22 @@ Embed_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) static int Embed_tp_init(Embed *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"other", - "loop", "callback", "data", "priority", NULL}; + static char *kwlist[] = { + "other", + "loop", "callback", "data", "priority", NULL + }; Loop *other = NULL, *loop = NULL; PyObject *callback = Py_None, *data = Py_None; int priority = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!O!|OOi:__init__", kwlist, + if ( + !PyArg_ParseTupleAndKeywords( + args, kwargs, "O!O!|OOi:__init__", kwlist, &Loop_Type, &other, - &Loop_Type, &loop, &callback, &data, &priority)) { + &Loop_Type, &loop, &callback, &data, &priority + ) + ) { return -1; } if (Watcher_Init((Watcher *)self, loop, callback, data, priority)) { @@ -154,9 +160,11 @@ Embed_set(Embed *self, PyObject *args) { Loop *other = NULL; - if (Watcher_CannotSet((Watcher *)self) || + if ( + Watcher_CannotSet((Watcher *)self) || !PyArg_ParseTuple(args, "O!:set", &Loop_Type, &other) || - __Embed_Set(self, other)) { + __Embed_Set(self, other) + ) { return NULL; } Py_RETURN_NONE; @@ -177,10 +185,14 @@ Embed_sweep(Watcher *self) /* Embed_Type.tp_methods */ static PyMethodDef Embed_tp_methods[] = { - {"set", (PyCFunction)Embed_set, METH_VARARGS, - "set(other)"}, - {"sweep", (PyCFunction)Embed_sweep, METH_NOARGS, - "sweep()"}, + { + "set", (PyCFunction)Embed_set, + METH_VARARGS, "set(other)" + }, + { + "sweep", (PyCFunction)Embed_sweep, + METH_NOARGS, "sweep()" + }, {NULL} /* Sentinel */ }; @@ -195,8 +207,10 @@ Embed_other_getter(Embed *self, void *closure) /* Embed_Type.tp_getsets */ static PyGetSetDef Embed_tp_getsets[] = { - {"other", (getter)Embed_other_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, + { + "other", (getter)Embed_other_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, {NULL} /* Sentinel */ }; @@ -222,20 +236,28 @@ PyTypeObject Embed_Type = { Embed * Embed_New(Loop *loop, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"other", - "callback", "data", "priority", NULL}; + static char *kwlist[] = { + "other", + "callback", "data", "priority", NULL + }; Loop *other = NULL; PyObject *callback = Py_None, *data = Py_None; int priority = 0; Embed *self = NULL; - if (PyArg_ParseTupleAndKeywords(args, kwargs, "O!|OOi:embed", kwlist, + if ( + PyArg_ParseTupleAndKeywords( + args, kwargs, "O!|OOi:embed", kwlist, &Loop_Type, &other, - &callback, &data, &priority) && + &callback, &data, &priority + ) && (self = __Embed_New(&Embed_Type)) && - (Watcher_Init((Watcher *)self, loop, callback, data, priority) || - __Embed_Set(self, other))) { + ( + Watcher_Init((Watcher *)self, loop, callback, data, priority) || + __Embed_Set(self, other) + ) + ) { Py_CLEAR(self); } return self; diff --git a/src/Fork.c b/src/Fork.c index deb4976..7b3a581 100644 --- a/src/Fork.c +++ b/src/Fork.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -62,16 +62,22 @@ PyTypeObject Fork_Type = { Watcher * Fork_New(Loop *loop, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"callback", "data", "priority", NULL}; + static char *kwlist[] = { + "callback", "data", "priority", NULL + }; PyObject *callback = NULL, *data = Py_None; int priority = 0; Watcher *self = NULL; - if (PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oi:fork", kwlist, - &callback, &data, &priority) && + if ( + PyArg_ParseTupleAndKeywords( + args, kwargs, "O|Oi:fork", kwlist, + &callback, &data, &priority + ) && (self = __Fork_New(&Fork_Type)) && - Watcher_Init(self, loop, callback, data, priority)) { + Watcher_Init(self, loop, callback, data, priority) + ) { Py_CLEAR(self); } return self; diff --git a/src/Idle.c b/src/Idle.c index b92ddc2..a4389db 100644 --- a/src/Idle.c +++ b/src/Idle.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -62,16 +62,22 @@ PyTypeObject Idle_Type = { Watcher * Idle_New(Loop *loop, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"callback", "data", "priority", NULL}; + static char *kwlist[] = { + "callback", "data", "priority", NULL + }; PyObject *callback = NULL, *data = Py_None; int priority = 0; Watcher *self = NULL; - if (PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oi:idle", kwlist, - &callback, &data, &priority) && + if ( + PyArg_ParseTupleAndKeywords( + args, kwargs, "O|Oi:idle", kwlist, + &callback, &data, &priority + ) && (self = __Idle_New(&Idle_Type)) && - Watcher_Init(self, loop, callback, data, priority)) { + Watcher_Init(self, loop, callback, data, priority) + ) { Py_CLEAR(self); } return self; diff --git a/src/Io.c b/src/Io.c index e023ea8..02554d7 100644 --- a/src/Io.c +++ b/src/Io.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -74,8 +74,10 @@ Io_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) static int Io_tp_init(Watcher *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"fd", "events", - "loop", "callback", "data", "priority", NULL}; + static char *kwlist[] = { + "fd", "events", + "loop", "callback", "data", "priority", NULL + }; PyObject *fd = NULL; int events = 0; @@ -83,9 +85,13 @@ Io_tp_init(Watcher *self, PyObject *args, PyObject *kwargs) PyObject *callback = NULL, *data = Py_None; int priority = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OiO!O|Oi:__init__", kwlist, + if ( + !PyArg_ParseTupleAndKeywords( + args, kwargs, "OiO!O|Oi:__init__", kwlist, &fd, &events, - &Loop_Type, &loop, &callback, &data, &priority)) { + &Loop_Type, &loop, &callback, &data, &priority + ) + ) { return -1; } if (Watcher_Init(self, loop, callback, data, priority)) { @@ -102,9 +108,11 @@ Io_set(Watcher *self, PyObject *args) PyObject *fd = NULL; int events = 0; - if (Watcher_CannotSet(self) || + if ( + Watcher_CannotSet(self) || !PyArg_ParseTuple(args, "Oi:set", &fd, &events) || - __Io_Set(self, fd, events)) { + __Io_Set(self, fd, events) + ) { return NULL; } Py_RETURN_NONE; @@ -113,8 +121,10 @@ Io_set(Watcher *self, PyObject *args) /* Io_Type.tp_methods */ static PyMethodDef Io_tp_methods[] = { - {"set", (PyCFunction)Io_set, METH_VARARGS, - "set(fd, events)"}, + { + "set", (PyCFunction)Io_set, + METH_VARARGS, "set(fd, events)" + }, {NULL} /* Sentinel */ }; @@ -135,8 +145,10 @@ Io_events_setter(Watcher *self, PyObject *value, void *closure) if (Watcher_IsActive(self, "set the 'events' of an Io")) { return -1; } - if ((((events = _PyLong_AsInt(value)) == -1) && PyErr_Occurred()) || - __Io_CheckEvents(events)) { + if ( + (((events = _PyLong_AsInt(value)) == -1) && PyErr_Occurred()) || + __Io_CheckEvents(events) + ) { return -1; } ev_io_modify((ev_io *)self->watcher, events); @@ -154,10 +166,14 @@ Io_fd_getter(Watcher *self, void *closure) /* Io_Type.tp_getsets */ static PyGetSetDef Io_tp_getsets[] = { - {"events", (getter)Io_events_getter, - (setter)Io_events_setter, NULL, NULL}, - {"fd", (getter)Io_fd_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, + { + "events", (getter)Io_events_getter, + (setter)Io_events_setter, NULL, NULL + }, + { + "fd", (getter)Io_fd_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, {NULL} /* Sentinel */ }; @@ -180,8 +196,10 @@ PyTypeObject Io_Type = { Watcher * Io_New(Loop *loop, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"fd", "events", - "callback", "data", "priority", NULL}; + static char *kwlist[] = { + "fd", "events", + "callback", "data", "priority", NULL + }; PyObject *fd = NULL; int events = 0; @@ -189,12 +207,18 @@ Io_New(Loop *loop, PyObject *args, PyObject *kwargs) int priority = 0; Watcher *self = NULL; - if (PyArg_ParseTupleAndKeywords(args, kwargs, "OiO|Oi:io", kwlist, + if ( + PyArg_ParseTupleAndKeywords( + args, kwargs, "OiO|Oi:io", kwlist, &fd, &events, - &callback, &data, &priority) && + &callback, &data, &priority + ) && (self = __Io_New(&Io_Type)) && - (Watcher_Init(self, loop, callback, data, priority) || - __Io_Set(self, fd, events))) { + ( + Watcher_Init(self, loop, callback, data, priority) || + __Io_Set(self, fd, events) + ) + ) { Py_CLEAR(self); } return self; diff --git a/src/Loop.c b/src/Loop.c index 685660a..2831aef 100644 --- a/src/Loop.c +++ b/src/Loop.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -51,8 +51,10 @@ __Loop_WarnOrStop(ev_loop *loop, PyObject *context) { Loop *self = ev_userdata(loop); - if (!__Loop_Fatal(context) && (self->callback == Py_None) && - PyErr_ExceptionMatches(PyExc_Exception)) { + if ( + !__Loop_Fatal(context) && (self->callback == Py_None) && + PyErr_ExceptionMatches(PyExc_Exception) + ) { PyErr_WriteUnraisable(context); } } @@ -119,15 +121,19 @@ __Loop_Alloc(PyTypeObject *type) static inline int __Loop_Setup(Loop *self, PyObject *args, PyObject *kwargs, int _default) { - static char *kwlist[] = {"flags", "callback", "data", - "io_interval", "timeout_interval", NULL}; + static char *kwlist[] = { + "flags", "callback", "data", "io_interval", "timeout_interval", NULL + }; unsigned int flags = EVFLAG_AUTO; PyObject *callback = Py_None, *data = Py_None; double io_ival = 0.0, timeout_ival = 0.0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|IOOdd:__new__", kwlist, - &flags, &callback, &data, - &io_ival, &timeout_ival)) { + if ( + !PyArg_ParseTupleAndKeywords( + args, kwargs, "|IOOdd:__new__", kwlist, + &flags, &callback, &data, &io_ival, &timeout_ival + ) + ) { return -1; } if (!(self->loop = _default ? ev_default_loop(flags) : ev_loop_new(flags))) { @@ -363,70 +369,126 @@ Loop_verify(Loop *self) /* Loop_Type.tp_methods */ static PyMethodDef Loop_tp_methods[] = { - {"start", (PyCFunction)Loop_start, METH_VARARGS, - "start([flags]) -> bool"}, - {"stop", (PyCFunction)Loop_stop, METH_VARARGS, - "stop([how])"}, - {"now", (PyCFunction)Loop_now, METH_VARARGS, - "now([update]) -> float"}, - {"invoke", (PyCFunction)Loop_invoke, METH_NOARGS, - "invoke()"}, - {"reset", (PyCFunction)Loop_reset, METH_NOARGS, - "reset()"}, - {"suspend", (PyCFunction)Loop_suspend, METH_NOARGS, - "suspend()"}, - {"resume", (PyCFunction)Loop_resume, METH_NOARGS, - "resume()"}, - {"incref", (PyCFunction)Loop_incref, METH_NOARGS, - "incref()"}, - {"decref", (PyCFunction)Loop_decref, METH_NOARGS, - "decref()"}, - {"verify", (PyCFunction)Loop_verify, METH_NOARGS, - "verify()"}, + { + "start", (PyCFunction)Loop_start, + METH_VARARGS, "start([flags]) -> bool" + }, + { + "stop", (PyCFunction)Loop_stop, + METH_VARARGS, "stop([how])" + }, + { + "now", (PyCFunction)Loop_now, + METH_VARARGS, "now([update]) -> float" + }, + { + "invoke", (PyCFunction)Loop_invoke, + METH_NOARGS, "invoke()" + }, + { + "reset", (PyCFunction)Loop_reset, + METH_NOARGS, "reset()" + }, + { + "suspend", (PyCFunction)Loop_suspend, + METH_NOARGS, "suspend()" + }, + { + "resume", (PyCFunction)Loop_resume, + METH_NOARGS, "resume()" + }, + { + "incref", (PyCFunction)Loop_incref, + METH_NOARGS, "incref()" + }, + { + "decref", (PyCFunction)Loop_decref, + METH_NOARGS, "decref()" + }, + { + "verify", (PyCFunction)Loop_verify, + METH_NOARGS, "verify()" + }, /* watcher methods */ - {"io", (PyCFunction)Io_New, METH_VARARGS | METH_KEYWORDS, - "io(fd, events, callback[, data=None, priority=0]) -> Io"}, - {"timer", (PyCFunction)Timer_New, METH_VARARGS | METH_KEYWORDS, - "timer(after, repeat, callback[, data=None, priority=0]) -> Timer"}, + { + "io", (PyCFunction)Io_New, + METH_VARARGS | METH_KEYWORDS, + "io(fd, events, callback[, data=None, priority=0]) -> Io" + }, + { + "timer", (PyCFunction)Timer_New, + METH_VARARGS | METH_KEYWORDS, + "timer(after, repeat, callback[, data=None, priority=0]) -> Timer" + }, #if EV_PERIODIC_ENABLE - {"periodic", (PyCFunction)Periodic_New, METH_VARARGS | METH_KEYWORDS, - "periodic(offset, interval, callback[, data=None, priority=0]) -> Periodic"}, + { + "periodic", (PyCFunction)Periodic_New, + METH_VARARGS | METH_KEYWORDS, + "periodic(offset, interval, callback[, data=None, priority=0]) -> Periodic" + }, #if EV_PREPARE_ENABLE - {"scheduler", (PyCFunction)Scheduler_New, METH_VARARGS | METH_KEYWORDS, - "scheduler(reschedule, callback[, data=None, priority=0]) -> Scheduler"}, + { + "scheduler", (PyCFunction)Scheduler_New, + METH_VARARGS | METH_KEYWORDS, + "scheduler(reschedule, callback[, data=None, priority=0]) -> Scheduler" + }, #endif #endif #if EV_SIGNAL_ENABLE - {"signal", (PyCFunction)Signal_New, METH_VARARGS | METH_KEYWORDS, - "signal(signum, callback[, data=None, priority=0]) -> Signal"}, + { + "signal", (PyCFunction)Signal_New, + METH_VARARGS | METH_KEYWORDS, + "signal(signum, callback[, data=None, priority=0]) -> Signal" + }, #endif #if EV_CHILD_ENABLE - {"child", (PyCFunction)Child_New, METH_VARARGS | METH_KEYWORDS, - "child(pid, trace, callback[, data=None, priority=0]) -> Child"}, + { + "child", (PyCFunction)Child_New, + METH_VARARGS | METH_KEYWORDS, + "child(pid, trace, callback[, data=None, priority=0]) -> Child" + }, #endif #if EV_IDLE_ENABLE - {"idle", (PyCFunction)Idle_New, METH_VARARGS | METH_KEYWORDS, - "idle(callback[, data=None, priority=0]) -> Idle"}, + { + "idle", (PyCFunction)Idle_New, + METH_VARARGS | METH_KEYWORDS, + "idle(callback[, data=None, priority=0]) -> Idle" + }, #endif #if EV_PREPARE_ENABLE - {"prepare", (PyCFunction)Prepare_New, METH_VARARGS | METH_KEYWORDS, - "prepare(callback[, data=None, priority=0]) -> Prepare"}, + { + "prepare", (PyCFunction)Prepare_New, + METH_VARARGS | METH_KEYWORDS, + "prepare(callback[, data=None, priority=0]) -> Prepare" + }, #endif #if EV_CHECK_ENABLE - {"check", (PyCFunction)Check_New, METH_VARARGS | METH_KEYWORDS, - "check(callback[, data=None, priority=0]) -> Check"}, + { + "check", (PyCFunction)Check_New, + METH_VARARGS | METH_KEYWORDS, + "check(callback[, data=None, priority=0]) -> Check" + }, #endif #if EV_EMBED_ENABLE - {"embed", (PyCFunction)Embed_New, METH_VARARGS | METH_KEYWORDS, - "embed(other[, callback=None, data=None, priority=0]) -> Embed"}, + { + "embed", (PyCFunction)Embed_New, + METH_VARARGS | METH_KEYWORDS, + "embed(other[, callback=None, data=None, priority=0]) -> Embed" + }, #endif #if EV_FORK_ENABLE - {"fork", (PyCFunction)Fork_New, METH_VARARGS | METH_KEYWORDS, - "fork(callback[, data=None, priority=0]) -> Fork"}, + { + "fork", (PyCFunction)Fork_New, + METH_VARARGS | METH_KEYWORDS, + "fork(callback[, data=None, priority=0]) -> Fork" + }, #endif #if EV_ASYNC_ENABLE - {"async", (PyCFunction)Async_New, METH_VARARGS | METH_KEYWORDS, - "async(callback[, data=None, priority=0]) -> Async"}, + { + "async", (PyCFunction)Async_New, + METH_VARARGS | METH_KEYWORDS, + "async(callback[, data=None, priority=0]) -> Async" + }, #endif {NULL} /* Sentinel */ }; @@ -534,24 +596,42 @@ Loop_pending_getter(Loop *self, void *closure) /* Loop_Type.tp_getsets */ static PyGetSetDef Loop_tp_getsets[] = { - {"callback", (getter)Loop_callback_getter, - (setter)Loop_callback_setter, NULL, NULL}, - {"data", (getter)Loop_data_getter, - (setter)Loop_data_setter, NULL, NULL}, - {"io_interval", (getter)Loop_interval_getter, - (setter)Loop_interval_setter, NULL, Py_True}, - {"timeout_interval", (getter)Loop_interval_getter, - (setter)Loop_interval_setter, NULL, NULL}, - {"default", (getter)Loop_default_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, - {"iteration", (getter)Loop_iteration_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, - {"depth", (getter)Loop_depth_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, - {"backend", (getter)Loop_backend_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, - {"pending", (getter)Loop_pending_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, + { + "callback", (getter)Loop_callback_getter, + (setter)Loop_callback_setter, NULL, NULL + }, + { + "data", (getter)Loop_data_getter, + (setter)Loop_data_setter, NULL, NULL + }, + { + "io_interval", (getter)Loop_interval_getter, + (setter)Loop_interval_setter, NULL, Py_True + }, + { + "timeout_interval", (getter)Loop_interval_getter, + (setter)Loop_interval_setter, NULL, NULL + }, + { + "default", (getter)Loop_default_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, + { + "iteration", (getter)Loop_iteration_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, + { + "depth", (getter)Loop_depth_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, + { + "backend", (getter)Loop_backend_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, + { + "pending", (getter)Loop_pending_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, {NULL} /* Sentinel */ }; diff --git a/src/Periodic.c b/src/Periodic.c index 0d7de17..3b8dabb 100644 --- a/src/Periodic.c +++ b/src/Periodic.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -85,17 +85,23 @@ Periodic_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) static int Periodic_tp_init(Watcher *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"offset", "interval", - "loop", "callback", "data", "priority", NULL}; + static char *kwlist[] = { + "offset", "interval", + "loop", "callback", "data", "priority", NULL + }; double offset = 0.0, interval = 0.0; Loop *loop = NULL; PyObject *callback = NULL, *data = Py_None; int priority = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ddO!O|Oi:__init__", kwlist, + if ( + !PyArg_ParseTupleAndKeywords( + args, kwargs, "ddO!O|Oi:__init__", kwlist, &offset, &interval, - &Loop_Type, &loop, &callback, &data, &priority)) { + &Loop_Type, &loop, &callback, &data, &priority + ) + ) { return -1; } if (Watcher_Init(self, loop, callback, data, priority)) { @@ -111,9 +117,11 @@ Periodic_set(Watcher *self, PyObject *args) { double offset = 0.0, interval = 0.0; - if (Watcher_CannotSet(self) || + if ( + Watcher_CannotSet(self) || !PyArg_ParseTuple(args, "dd:set", &offset, &interval) || - __Periodic_Set(self, offset, interval)) { + __Periodic_Set(self, offset, interval) + ) { return NULL; } Py_RETURN_NONE; @@ -134,10 +142,14 @@ Periodic_reset(Watcher *self) /* Periodic_Type.tp_methods */ static PyMethodDef Periodic_tp_methods[] = { - {"set", (PyCFunction)Periodic_set, METH_VARARGS, - "set(offset, interval)"}, - {"reset", (PyCFunction)Periodic_reset, METH_NOARGS, - Periodic_reset_doc}, + { + "set", (PyCFunction)Periodic_set, + METH_VARARGS, "set(offset, interval)" + }, + { + "reset", (PyCFunction)Periodic_reset, + METH_NOARGS, Periodic_reset_doc + }, {NULL} /* Sentinel */ }; @@ -200,12 +212,18 @@ Periodic_at_getter(Watcher *self, void *closure) /* Periodic_Type.tp_getsets */ static PyGetSetDef Periodic_tp_getsets[] = { - {"offset", (getter)Periodic_offset_getter, - (setter)Periodic_offset_setter, NULL, NULL}, - {"interval", (getter)Periodic_interval_getter, - (setter)Periodic_interval_setter, NULL, NULL}, - {"at", (getter)Periodic_at_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, + { + "offset", (getter)Periodic_offset_getter, + (setter)Periodic_offset_setter, NULL, NULL + }, + { + "interval", (getter)Periodic_interval_getter, + (setter)Periodic_interval_setter, NULL, NULL + }, + { + "at", (getter)Periodic_at_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, {NULL} /* Sentinel */ }; @@ -228,20 +246,28 @@ PyTypeObject Periodic_Type = { Watcher * Periodic_New(Loop *loop, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"offset", "interval", - "callback", "data", "priority", NULL}; + static char *kwlist[] = { + "offset", "interval", + "callback", "data", "priority", NULL + }; double offset = 0.0, interval = 0.0; PyObject *callback = NULL, *data = Py_None; int priority = 0; Watcher *self = NULL; - if (PyArg_ParseTupleAndKeywords(args, kwargs, "ddO|Oi:periodic", kwlist, + if ( + PyArg_ParseTupleAndKeywords( + args, kwargs, "ddO|Oi:periodic", kwlist, &offset, &interval, - &callback, &data, &priority) && + &callback, &data, &priority + ) && (self = __Periodic_New(&Periodic_Type)) && - (Watcher_Init(self, loop, callback, data, priority) || - __Periodic_Set(self, offset, interval))) { + ( + Watcher_Init(self, loop, callback, data, priority) || + __Periodic_Set(self, offset, interval) + ) + ) { Py_CLEAR(self); } return self; @@ -298,8 +324,10 @@ __Scheduler_Reschedule(ev_periodic *periodic, double now) PyObject *pynow = NULL, *pyresult = NULL; double result = -1.0; - if (_Py_INVOKE_VERIFY(self->reschedule, "reschedule callback") || - !(pynow = PyFloat_FromDouble(now))) { + if ( + _Py_INVOKE_VERIFY(self->reschedule, "reschedule callback") || + !(pynow = PyFloat_FromDouble(now)) + ) { self->err_fatal = 1; goto fail; } @@ -314,8 +342,10 @@ __Scheduler_Reschedule(ev_periodic *periodic, double now) goto fail; } if (result < now) { - PyErr_Format(Error, "%R must return a value >= to the 'now' argument", - self->reschedule); + PyErr_Format( + Error, "%R must return a value >= to the 'now' argument", + self->reschedule + ); goto fail; } goto end; @@ -367,7 +397,9 @@ __Scheduler_Setup(Scheduler *self, int ev_type, size_t size) ev_prepare_init(self->prepare, __Scheduler_Stop); ev_set_priority(self->prepare, EV_MAXPRI); self->prepare->data = self; - ev_periodic_set((ev_periodic *)watcher->watcher, .0, .0, __Scheduler_Reschedule); + ev_periodic_set( + (ev_periodic *)watcher->watcher, .0, .0, __Scheduler_Reschedule + ); return 0; } @@ -455,17 +487,23 @@ Scheduler_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) static int Scheduler_tp_init(Scheduler *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"reschedule", - "loop", "callback", "data", "priority", NULL}; + static char *kwlist[] = { + "reschedule", + "loop", "callback", "data", "priority", NULL + }; PyObject *reschedule = NULL; Loop *loop = NULL; PyObject *callback = NULL, *data = Py_None; int priority = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO!O|Oi:__init__", kwlist, + if ( + !PyArg_ParseTupleAndKeywords( + args, kwargs, "OO!O|Oi:__init__", kwlist, &reschedule, - &Loop_Type, &loop, &callback, &data, &priority)) { + &Loop_Type, &loop, &callback, &data, &priority + ) + ) { return -1; } if (Watcher_Init((Watcher *)self, loop, callback, data, priority)) { @@ -514,8 +552,10 @@ Scheduler_tp_dealloc(Scheduler *self) /* Scheduler_Type.tp_methods */ static PyMethodDef Scheduler_tp_methods[] = { - {"reset", (PyCFunction)Periodic_reset, METH_NOARGS, - Periodic_reset_doc}, + { + "reset", (PyCFunction)Periodic_reset, + METH_NOARGS, Periodic_reset_doc + }, {NULL} /* Sentinel */ }; @@ -537,10 +577,14 @@ Scheduler_reschedule_setter(Scheduler *self, PyObject *value, void *closure) /* Scheduler_Type.tp_getsets */ static PyGetSetDef Scheduler_tp_getsets[] = { - {"reschedule", (getter)Scheduler_reschedule_getter, - (setter)Scheduler_reschedule_setter, NULL, NULL}, - {"at", (getter)Periodic_at_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, + { + "reschedule", (getter)Scheduler_reschedule_getter, + (setter)Scheduler_reschedule_setter, NULL, NULL + }, + { + "at", (getter)Periodic_at_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, {NULL} /* Sentinel */ }; @@ -567,20 +611,28 @@ PyTypeObject Scheduler_Type = { Scheduler * Scheduler_New(Loop *loop, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"reschedule", - "callback", "data", "priority", NULL}; + static char *kwlist[] = { + "reschedule", + "callback", "data", "priority", NULL + }; PyObject *reschedule = NULL; PyObject *callback = NULL, *data = Py_None; int priority = 0; Scheduler *self = NULL; - if (PyArg_ParseTupleAndKeywords(args, kwargs, "OO|Oi:scheduler", kwlist, + if ( + PyArg_ParseTupleAndKeywords( + args, kwargs, "OO|Oi:scheduler", kwlist, &reschedule, - &callback, &data, &priority) && + &callback, &data, &priority + ) && (self = __Scheduler_New(&Scheduler_Type)) && - (Watcher_Init((Watcher *)self, loop, callback, data, priority) || - __Scheduler_Set(self, reschedule))) { + ( + Watcher_Init((Watcher *)self, loop, callback, data, priority) || + __Scheduler_Set(self, reschedule) + ) + ) { Py_CLEAR(self); } return self; diff --git a/src/Prepare.c b/src/Prepare.c index 3dcb556..8e37b04 100644 --- a/src/Prepare.c +++ b/src/Prepare.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -62,16 +62,22 @@ PyTypeObject Prepare_Type = { Watcher * Prepare_New(Loop *loop, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"callback", "data", "priority", NULL}; + static char *kwlist[] = { + "callback", "data", "priority", NULL + }; PyObject *callback = NULL, *data = Py_None; int priority = 0; Watcher *self = NULL; - if (PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oi:prepare", kwlist, - &callback, &data, &priority) && + if ( + PyArg_ParseTupleAndKeywords( + args, kwargs, "O|Oi:prepare", kwlist, + &callback, &data, &priority + ) && (self = __Prepare_New(&Prepare_Type)) && - Watcher_Init(self, loop, callback, data, priority)) { + Watcher_Init(self, loop, callback, data, priority) + ) { Py_CLEAR(self); } return self; diff --git a/src/Signal.c b/src/Signal.c index 69fcb88..2548dd4 100644 --- a/src/Signal.c +++ b/src/Signal.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -59,17 +59,23 @@ Signal_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) static int Signal_tp_init(Watcher *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"signum", - "loop", "callback", "data", "priority", NULL}; + static char *kwlist[] = { + "signum", + "loop", "callback", "data", "priority", NULL + }; int signum = 0; Loop *loop = NULL; PyObject *callback = NULL, *data = Py_None; int priority = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iO!O|Oi:__init__", kwlist, + if ( + !PyArg_ParseTupleAndKeywords( + args, kwargs, "iO!O|Oi:__init__", kwlist, &signum, - &Loop_Type, &loop, &callback, &data, &priority)) { + &Loop_Type, &loop, &callback, &data, &priority + ) + ) { return -1; } if (Watcher_Init(self, loop, callback, data, priority)) { @@ -85,9 +91,11 @@ Signal_set(Watcher *self, PyObject *args) { int signum = 0; - if (Watcher_CannotSet(self) || + if ( + Watcher_CannotSet(self) || !PyArg_ParseTuple(args, "i:set", &signum) || - __Signal_Set(self, signum)) { + __Signal_Set(self, signum) + ) { return NULL; } Py_RETURN_NONE; @@ -96,8 +104,10 @@ Signal_set(Watcher *self, PyObject *args) /* Signal_Type.tp_methods */ static PyMethodDef Signal_tp_methods[] = { - {"set", (PyCFunction)Signal_set, METH_VARARGS, - "set(signum)"}, + { + "set", (PyCFunction)Signal_set, + METH_VARARGS, "set(signum)" + }, {NULL} /* Sentinel */ }; @@ -112,8 +122,10 @@ Signal_signum_getter(Watcher *self, void *closure) /* Signal_Type.tp_getsets */ static PyGetSetDef Signal_tp_getsets[] = { - {"signum", (getter)Signal_signum_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, + { + "signum", (getter)Signal_signum_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, {NULL} /* Sentinel */ }; @@ -136,20 +148,28 @@ PyTypeObject Signal_Type = { Watcher * Signal_New(Loop *loop, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"signum", - "callback", "data", "priority", NULL}; + static char *kwlist[] = { + "signum", + "callback", "data", "priority", NULL + }; int signum = 0; PyObject *callback = NULL, *data = Py_None; int priority = 0; Watcher *self = NULL; - if (PyArg_ParseTupleAndKeywords(args, kwargs, "iO|Oi:signal", kwlist, + if ( + PyArg_ParseTupleAndKeywords( + args, kwargs, "iO|Oi:signal", kwlist, &signum, - &callback, &data, &priority) && + &callback, &data, &priority + ) && (self = __Signal_New(&Signal_Type)) && - (Watcher_Init(self, loop, callback, data, priority) || - __Signal_Set(self, signum))) { + ( + Watcher_Init(self, loop, callback, data, priority) || + __Signal_Set(self, signum) + ) + ) { Py_CLEAR(self); } return self; diff --git a/src/Timer.c b/src/Timer.c index a9f54f1..8f189fd 100644 --- a/src/Timer.c +++ b/src/Timer.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -57,17 +57,23 @@ Timer_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) static int Timer_tp_init(Watcher *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"after", "repeat", - "loop", "callback", "data", "priority", NULL}; + static char *kwlist[] = { + "after", "repeat", + "loop", "callback", "data", "priority", NULL + }; double after = 0.0, repeat = 0.0; Loop *loop = NULL; PyObject *callback = NULL, *data = Py_None; int priority = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ddO!O|Oi:__init__", kwlist, + if ( + !PyArg_ParseTupleAndKeywords( + args, kwargs, "ddO!O|Oi:__init__", kwlist, &after, &repeat, - &Loop_Type, &loop, &callback, &data, &priority)) { + &Loop_Type, &loop, &callback, &data, &priority + ) + ) { return -1; } if (Watcher_Init(self, loop, callback, data, priority)) { @@ -83,9 +89,11 @@ Timer_set(Watcher *self, PyObject *args) { double after = 0.0, repeat = 0.0; - if (Watcher_CannotSet(self) || + if ( + Watcher_CannotSet(self) || !PyArg_ParseTuple(args, "dd:set", &after, &repeat) || - __Timer_Set(self, after, repeat)) { + __Timer_Set(self, after, repeat) + ) { return NULL; } Py_RETURN_NONE; @@ -103,10 +111,14 @@ Timer_reset(Watcher *self) /* Timer_Type.tp_methods */ static PyMethodDef Timer_tp_methods[] = { - {"set", (PyCFunction)Timer_set, METH_VARARGS, - "set(after, repeat)"}, - {"reset", (PyCFunction)Timer_reset, METH_NOARGS, - "reset()"}, + { + "set", (PyCFunction)Timer_set, + METH_VARARGS, "set(after, repeat)" + }, + { + "reset", (PyCFunction)Timer_reset, + METH_NOARGS, "reset()" + }, {NULL} /* Sentinel */ }; @@ -138,16 +150,21 @@ static PyObject * Timer_remaining_getter(Watcher *self, void *closure) { return PyFloat_FromDouble( - ev_timer_remaining(self->loop->loop, (ev_timer *)self->watcher)); + ev_timer_remaining(self->loop->loop, (ev_timer *)self->watcher) + ); } /* Timer_Type.tp_getsets */ static PyGetSetDef Timer_tp_getsets[] = { - {"repeat", (getter)Timer_repeat_getter, - (setter)Timer_repeat_setter, NULL, NULL}, - {"remaining", (getter)Timer_remaining_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, + { + "repeat", (getter)Timer_repeat_getter, + (setter)Timer_repeat_setter, NULL, NULL + }, + { + "remaining", (getter)Timer_remaining_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, {NULL} /* Sentinel */ }; @@ -170,20 +187,28 @@ PyTypeObject Timer_Type = { Watcher * Timer_New(Loop *loop, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"after", "repeat", - "callback", "data", "priority", NULL}; + static char *kwlist[] = { + "after", "repeat", + "callback", "data", "priority", NULL + }; double after = 0.0, repeat = 0.0; PyObject *callback = NULL, *data = Py_None; int priority = 0; Watcher *self = NULL; - if (PyArg_ParseTupleAndKeywords(args, kwargs, "ddO|Oi:timer", kwlist, + if ( + PyArg_ParseTupleAndKeywords( + args, kwargs, "ddO|Oi:timer", kwlist, &after, &repeat, - &callback, &data, &priority) && + &callback, &data, &priority + ) && (self = __Timer_New(&Timer_Type)) && - (Watcher_Init(self, loop, callback, data, priority) || - __Timer_Set(self, after, repeat))) { + ( + Watcher_Init(self, loop, callback, data, priority) || + __Timer_Set(self, after, repeat) + ) + ) { Py_CLEAR(self); } return self; diff --git a/src/Watcher.c b/src/Watcher.c index 187205a..1d6954b 100644 --- a/src/Watcher.c +++ b/src/Watcher.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -188,7 +188,9 @@ ___Watcher_ExecCallback(ev_loop *loop, ev_watcher *watcher, int revents) else if (!_Py_INVOKE_VERIFY(self->callback, "watcher callback")) { if (self->callback != Py_None) { if ((pyrevents = PyLong_FromLong(revents))) { - pyresult = _PyObject_Callback(self->callback, self, pyrevents, NULL); + pyresult = _PyObject_Callback( + self->callback, self, pyrevents, NULL + ); if (pyresult) { Py_DECREF(pyresult); } @@ -298,7 +300,9 @@ __Watcher_New(PyTypeObject *type, int ev_type, size_t size) static inline int -__Watcher_Init(Watcher *self, Loop *loop, PyObject *callback, PyObject *data, int priority) +__Watcher_Init( + Watcher *self, Loop *loop, PyObject *callback, PyObject *data, int priority +) { __Watcher_CheckAllStates(self, "init a", -1); __Watcher_CheckCallback(self, callback, -1); @@ -367,8 +371,12 @@ Watcher_tp_init(Watcher *self, PyObject *args, PyObject *kwargs) PyObject *callback = NULL, *data = Py_None; int priority = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!O|Oi:__init__", kwlist, - &Loop_Type, &loop, &callback, &data, &priority)) { + if ( + !PyArg_ParseTupleAndKeywords( + args, kwargs, "O!O|Oi:__init__", kwlist, + &Loop_Type, &loop, &callback, &data, &priority + ) + ) { return -1; } return __Watcher_Init(self, loop, callback, data, priority); @@ -474,16 +482,26 @@ Watcher_clear(Watcher *self) /* Watcher_Type.tp_methods */ static PyMethodDef Watcher_tp_methods[] = { - {"start", (PyCFunction)Watcher_start, METH_NOARGS, - "start()"}, - {"stop", (PyCFunction)Watcher_stop, METH_NOARGS, - "stop()"}, - {"invoke", (PyCFunction)Watcher_invoke, METH_VARARGS, - "invoke(revents)"}, - {"feed", (PyCFunction)Watcher_feed, METH_VARARGS, - "feed(revents)"}, - {"clear", (PyCFunction)Watcher_clear, METH_NOARGS, - "clear() -> int"}, + { + "start", (PyCFunction)Watcher_start, + METH_NOARGS, "start()" + }, + { + "stop", (PyCFunction)Watcher_stop, + METH_NOARGS, "stop()" + }, + { + "invoke", (PyCFunction)Watcher_invoke, + METH_VARARGS, "invoke(revents)" + }, + { + "feed", (PyCFunction)Watcher_feed, + METH_VARARGS, "feed(revents)" + }, + { + "clear", (PyCFunction)Watcher_clear, + METH_NOARGS, "clear() -> int" + }, {NULL} /* Sentinel */ }; @@ -569,18 +587,30 @@ Watcher_pending_getter(Watcher *self, void *closure) /* Watcher_Type.tp_getsets */ static PyGetSetDef Watcher_tp_getsets[] = { - {"callback", (getter)Watcher_callback_getter, - (setter)Watcher_callback_setter, NULL, NULL}, - {"data", (getter)Watcher_data_getter, - (setter)Watcher_data_setter, NULL, NULL}, - {"priority", (getter)Watcher_priority_getter, - (setter)Watcher_priority_setter, NULL, NULL}, - {"loop", (getter)Watcher_loop_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, - {"active", (getter)Watcher_active_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, - {"pending", (getter)Watcher_pending_getter, - _Py_READONLY_ATTRIBUTE, NULL, NULL}, + { + "callback", (getter)Watcher_callback_getter, + (setter)Watcher_callback_setter, NULL, NULL + }, + { + "data", (getter)Watcher_data_getter, + (setter)Watcher_data_setter, NULL, NULL + }, + { + "priority", (getter)Watcher_priority_getter, + (setter)Watcher_priority_setter, NULL, NULL + }, + { + "loop", (getter)Watcher_loop_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, + { + "active", (getter)Watcher_active_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, + { + "pending", (getter)Watcher_pending_getter, + _Py_READONLY_ATTRIBUTE, NULL, NULL + }, }; @@ -623,7 +653,9 @@ Watcher_New(PyTypeObject *type, int ev_type, size_t size) int -Watcher_Init(Watcher *self, Loop *loop, PyObject *callback, PyObject *data, int priority) +Watcher_Init( + Watcher *self, Loop *loop, PyObject *callback, PyObject *data, int priority +) { return __Watcher_Init(self, loop, callback, data, priority); } diff --git a/src/event.c b/src/event.c index 5cfa55e..349f104 100644 --- a/src/event.c +++ b/src/event.c @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -46,7 +46,8 @@ _Py_INVOKE_VERIFY(PyObject *callback, const char *alt) } _PyErr_FormatFromCause( PyExc_SystemError, "trying to invoke %V with an error set", - repr, alt ? alt : "a callback"); + repr, alt ? alt : "a callback" + ); Py_XDECREF(repr); } return -1; @@ -87,9 +88,13 @@ event_loop(PyObject *module, PyObject *args, PyObject *kwargs) DefaultLoop = Loop_New(args, kwargs, 1); } else { - if (PyErr_WarnEx(PyExc_RuntimeWarning, - "returning the 'default loop' created earlier, " - "arguments ignored (if provided).", 1)) { + if ( + PyErr_WarnEx( + PyExc_RuntimeWarning, + "returning the 'default loop' created earlier, " + "arguments ignored (if provided).", 1 + ) + ) { return NULL; } Py_INCREF(DefaultLoop); @@ -105,8 +110,10 @@ event_fatal(PyObject *module, PyObject *args) _Py_IDENTIFIER(__err_fatal__); PyObject *obj; - if (!PyArg_ParseTuple(args, "O:fatal", &obj) || - _PyObject_SetAttrId(obj, &PyId___err_fatal__, Py_True)) { + if ( + !PyArg_ParseTuple(args, "O:fatal", &obj) || + _PyObject_SetAttrId(obj, &PyId___err_fatal__, Py_True) + ) { return NULL; } return __Py_INCREF(obj); @@ -131,10 +138,14 @@ event_sleep(PyObject *module, PyObject *args) if (!PyArg_ParseTuple(args, "d:sleep", &interval)) { return NULL; } - if (interval > day && - PyErr_WarnEx(PyExc_RuntimeWarning, - "'interval' bigger than a day (86400.0), " - "this is not garanteed to work", 1)) { + if ( + (interval > day) && + PyErr_WarnEx( + PyExc_RuntimeWarning, + "'interval' bigger than a day (86400.0), " + "this is not garanteed to work", 1 + ) + ) { return NULL; } Py_BEGIN_ALLOW_THREADS @@ -197,25 +208,45 @@ event_feed_signal(PyObject *module, PyObject *args) /* event_def.m_methods */ static PyMethodDef event_m_methods[] = { - {"loop", (PyCFunction)event_loop, METH_VARARGS | METH_KEYWORDS, - "loop([flags=EVFLAG_AUTO, callback=None, data=None, io_interval=0.0, timeout_interval=0.0]) -> 'default loop'"}, - {"fatal", (PyCFunction)event_fatal, METH_VARARGS, - "fatal decorator"}, - {"time", (PyCFunction)event_time, METH_NOARGS, - "time() -> float"}, - {"sleep", (PyCFunction)event_sleep, METH_VARARGS, - "sleep(interval)"}, - {"abi_version", (PyCFunction)event_abi_version, METH_NOARGS, - "abi_version() -> (int, int)"}, - {"supported_backends", (PyCFunction)event_supported_backends, METH_NOARGS, - "supported_backends() -> int"}, - {"recommended_backends", (PyCFunction)event_recommended_backends, METH_NOARGS, - "recommended_backends() -> int"}, - {"embeddable_backends", (PyCFunction)event_embeddable_backends, METH_NOARGS, - "embeddable_backends() -> int"}, + { + "loop", (PyCFunction)event_loop, + METH_VARARGS | METH_KEYWORDS, + "loop([flags=EVFLAG_AUTO, callback=None, data=None, io_interval=0.0, " + "timeout_interval=0.0]) -> 'default loop'" + }, + { + "fatal", (PyCFunction)event_fatal, + METH_VARARGS, "fatal decorator" + }, + { + "time", (PyCFunction)event_time, + METH_NOARGS, "time() -> float" + }, + { + "sleep", (PyCFunction)event_sleep, + METH_VARARGS, "sleep(interval)" + }, + { + "abi_version", (PyCFunction)event_abi_version, + METH_NOARGS, "abi_version() -> (int, int)" + }, + { + "supported_backends", (PyCFunction)event_supported_backends, + METH_NOARGS, "supported_backends() -> int" + }, + { + "recommended_backends", (PyCFunction)event_recommended_backends, + METH_NOARGS, "recommended_backends() -> int" + }, + { + "embeddable_backends", (PyCFunction)event_embeddable_backends, + METH_NOARGS, "embeddable_backends() -> int" + }, #if EV_SIGNAL_ENABLE - {"feed_signal", (PyCFunction)event_feed_signal, METH_VARARGS, - "feed_signal(signum)"}, + { + "feed_signal", (PyCFunction)event_feed_signal, + METH_VARARGS, "feed_signal(signum)" + }, #endif {NULL} /* Sentinel */ }; @@ -368,7 +399,7 @@ _module_init(PyObject *module) // additional events _PyModule_AddIntMacro(module, EV_CUSTOM) || _PyModule_AddIntMacro(module, EV_ERROR) - ) { + ) { return -1; } // setup libev diff --git a/src/event.h b/src/event.h index 707251b..3b36a20 100644 --- a/src/event.h +++ b/src/event.h @@ -1,6 +1,6 @@ /* # -# Copyright © 2020 Malek Hadj-Ali +# Copyright © 2021 Malek Hadj-Ali # All rights reserved. # # This file is part of mood. @@ -64,8 +64,9 @@ extern "C" { #define _Py_CHECK_POSITIVE_OR_ZERO_FLOAT(v, r) \ do { \ if ((v) < 0.0) { \ - PyErr_SetString(PyExc_ValueError, \ - "a positive float or 0.0 is required"); \ + PyErr_SetString( \ + PyExc_ValueError, "a positive float or 0.0 is required" \ + ); \ return (r); \ } \ } while (0)