From 77383a70d81b91d5e0134941028e56a15d0a902c Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Mon, 20 May 2024 06:30:19 +0200 Subject: syscalls: use >= 3.10 support for eventfds in os module --- linuxnamespaces/syscalls.py | 16 ++++++---------- pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/linuxnamespaces/syscalls.py b/linuxnamespaces/syscalls.py index 11800c6..9d2b1ba 100644 --- a/linuxnamespaces/syscalls.py +++ b/linuxnamespaces/syscalls.py @@ -73,9 +73,9 @@ class EventFDFlags(enum.IntFlag): """This value may be supplied as flags to eventfd(2).""" NONE = 0 - CLOEXEC = 0o2000000 - NONBLOCK = 0o4000 - SEMAPHORE = 0o1 + CLOEXEC = os.EFD_CLOEXEC + NONBLOCK = os.EFD_NONBLOCK + SEMAPHORE = os.EFD_SEMAPHORE ALL_FLAGS = CLOEXEC | NONBLOCK | SEMAPHORE @@ -438,15 +438,13 @@ class EventFD: ) -> None: if flags & ~EventFDFlags.ALL_FLAGS: raise ValueError("invalid flags for eventfd") - self.fd = call_libc("eventfd", initval, int(flags)) + self.fd = os.eventfd(initval, int(flags)) def read(self) -> int: """Decrease the value of the eventfd using eventfd_read.""" if self.fd < 0: raise ValueError("attempt to read from closed eventfd") - cvalue = ctypes.c_ulonglong() - call_libc("eventfd_read", self.fd, ctypes.byref(cvalue)) - return cvalue.value + return os.eventfd_read(self.fd) def __handle_readable(self, fd: int, fut: asyncio.Future[int]) -> None: """Internal helper of aread.""" @@ -481,9 +479,7 @@ class EventFD: """Add the given value to the eventfd using eventfd_write.""" if self.fd < 0: raise ValueError("attempt to read from closed eventfd") - if value < 0 or (value >> 64): - raise ValueError("value for eventfd_write out of range") - call_libc("eventfd_write", self.fd, ctypes.c_ulonglong(value)) + os.eventfd_write(self.fd, value) def fileno(self) -> int: """Return the underlying file descriptor.""" diff --git a/pyproject.toml b/pyproject.toml index 04d6a5f..ac6be9e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ classifiers = [ "Typing :: Typed", "Programming Language :: Python :: 3", ] -requires-python = ">=3.9" +requires-python = ">=3.10" [project.optional-dependencies] # linuxnamespaces.systemd needs jeepney or dbussy, not both. -- cgit v1.2.3