syscalls: support identifiers lookup
authorDmitry Selyutin <ghostmansd@gmail.com>
Tue, 19 Sep 2023 17:14:20 +0000 (20:14 +0300)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 26 Sep 2023 21:08:32 +0000 (22:08 +0100)
src/openpower/syscalls/__init__.py

index 9f3e8474ae0f7d73c859c5e2d6cb41a5541cda08..053e45f3d10fcb2b3213614ca327f92430c70b69 100644 (file)
@@ -54,6 +54,15 @@ class Dispatcher:
 
         return super().__init__()
 
+    def __getitem__(self, identifier):
+        if not isinstance(identifier, int):
+            raise ValueError(identifier)
+
+        identifier = str(identifier)
+        entry = self.__guest[identifier][1][0]
+
+        return getattr(self, entry)
+
     def __getattr__(self, entry):
         if entry.startswith("compat_sys_"):
             identifier = entry[len("compat_sys_"):]
@@ -98,11 +107,6 @@ class Dispatcher:
         return syscall
 
     def __call__(self, identifier, *arguments):
-        if not isinstance(identifier, int):
-            raise ValueError(identifier)
-
-        identifier = str(identifier)
-        entry = self.__guest[identifier][1][0]
-        syscall = getattr(self, entry)
+        syscall = self[identifier]
 
         return syscall(*arguments)