diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-02-02 02:01:30 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-02-09 23:56:16 -0700 |
commit | a51875001eb672d73c9d84d44bb32abce327b931 (patch) | |
tree | bf2b4a8225fe0d6f00084a1577c70bb564a20600 | |
parent | 3f81fba2750222d633f972cd61b4e06f01f52482 (diff) |
libmisc: Drop vcall.h
-rwxr-xr-x | build-aux/stack.c.gen | 6 | ||||
-rw-r--r-- | libmisc/CMakeLists.txt | 5 | ||||
-rw-r--r-- | libmisc/include/libmisc/vcall.h | 28 | ||||
-rw-r--r-- | libmisc/tests/test_vcall.c | 74 |
4 files changed, 4 insertions, 109 deletions
diff --git a/build-aux/stack.c.gen b/build-aux/stack.c.gen index 3ef5628..e327298 100755 --- a/build-aux/stack.c.gen +++ b/build-aux/stack.c.gen @@ -401,9 +401,7 @@ def main( typ = m.group("typ") lib9p_msgs.add(typ) - re_call_objcall = re.compile( - r"(?:VCALL|LO_CALL)\((?P<obj>[^,]+), (?P<meth>[^,)]+)[,)].*" - ) + re_call_objcall = re.compile(r"LO_CALL\((?P<obj>[^,]+), (?P<meth>[^,)]+)[,)].*") def sbc_indirect_callees(loc: str, line: str) -> list[str] | None: if "/3rd-party/" in loc: @@ -411,7 +409,7 @@ def main( if m := re_call_objcall.fullmatch(line): if m.group("meth") in objcalls: return sorted(objcalls[m.group("meth")]) - return [f"__indirect_call:{m.group('obj')}->vtable->{m.group('meth')}"] + return [f"__indirect_call:{m.group('obj')}.vtable->{m.group('meth')}"] if "trigger->cb(trigger->cb_arg)" in line: return [ "alarmclock_sleep_intrhandler", diff --git a/libmisc/CMakeLists.txt b/libmisc/CMakeLists.txt index 8d842c3..f8f15bc 100644 --- a/libmisc/CMakeLists.txt +++ b/libmisc/CMakeLists.txt @@ -1,6 +1,6 @@ -# libmisc/CMakeLists.txt - A simple Go-ish object system built on GCC -fplan9-extensions +# libmisc/CMakeLists.txt - TODO # -# Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> +# Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com> # SPDX-License-Identifier: AGPL-3.0-or-later add_library(libmisc INTERFACE) @@ -20,4 +20,3 @@ add_lib_test(libmisc test_log) add_lib_test(libmisc test_macro) add_lib_test(libmisc test_private) add_lib_test(libmisc test_rand) -add_lib_test(libmisc test_vcall) diff --git a/libmisc/include/libmisc/vcall.h b/libmisc/include/libmisc/vcall.h deleted file mode 100644 index 31a8c7e..0000000 --- a/libmisc/include/libmisc/vcall.h +++ /dev/null @@ -1,28 +0,0 @@ -/* libmisc/vcall.h - A simple Go-ish object system built on GCC -fplan9-extensions - * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -#ifndef _LIBMISC_VCALL_H_ -#define _LIBMISC_VCALL_H_ - -#include <stddef.h> /* for offsetof() */ - -#include <libmisc/assert.h> - -#define VCALL(o, m, ...) \ - ({ \ - assert(o); \ - (o)->vtable->m(o __VA_OPT__(,) __VA_ARGS__); \ - }) - -#define VCALL_SELF(obj_typ, iface_typ, iface_ptr) \ - ({ \ - static_assert(_Generic(iface_ptr, iface_typ *: 1, default: 0), \ - "typeof("#iface_ptr") != "#iface_typ" *"); \ - assert(iface_ptr); \ - ((obj_typ*)(((void*)iface_ptr)-offsetof(obj_typ,iface_typ))); \ - }) - -#endif /* _LIBMISC_VCALL_H_ */ diff --git a/libmisc/tests/test_vcall.c b/libmisc/tests/test_vcall.c deleted file mode 100644 index f36fc4b..0000000 --- a/libmisc/tests/test_vcall.c +++ /dev/null @@ -1,74 +0,0 @@ -/* libmisc/tests/test_vcall.c - Tests for <libmisc/vcall.h> - * - * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -#include <libmisc/assert.h> -#include <libmisc/vcall.h> - -#include "test.h" - -/******************************************************************************/ - -struct frobber_vtable; - -typedef struct { - struct frobber_vtable *vtable; -} implements_frobber; - -struct frobber_vtable { - int (*frob)(implements_frobber *); - int (*frob1)(implements_frobber *, int); - void (*frob0)(implements_frobber *); -}; - -/******************************************************************************/ - -struct myclass { - int a; - implements_frobber; -}; -static_assert(offsetof(struct myclass, implements_frobber) != 0); - -static int myclass_frob(implements_frobber *_self) { - struct myclass *self = VCALL_SELF(struct myclass, implements_frobber, _self); - test_assert(self); - test_assert((void*)self != (void*)_self); - return self->a; -} - -static int myclass_frob1(implements_frobber *_self, int arg) { - struct myclass *self = VCALL_SELF(struct myclass, implements_frobber, _self); - test_assert(self); - test_assert((void*)self != (void*)_self); - return arg; -} - -static void myclass_frob0(implements_frobber *_self) { - struct myclass *self = VCALL_SELF(struct myclass, implements_frobber, _self); - test_assert(self); - test_assert((void*)self != (void*)_self); -} - -struct frobber_vtable myclass_vtable = { - .frob = myclass_frob, - .frob1 = myclass_frob1, - .frob0 = myclass_frob0, -}; - -/******************************************************************************/ - -#define MAGIC1 909837 -#define MAGIC2 657441 - -int main() { - struct myclass obj = { - .implements_frobber = { .vtable = &myclass_vtable }, - .a = MAGIC1, - }; - test_assert(VCALL(&obj, frob) == MAGIC1); - test_assert(VCALL(&obj, frob1, MAGIC2) == MAGIC2); - VCALL(&obj, frob0); - return 0; -} |