From e3fd00bb4e2b7b4cabfb416e59fdf83e331a9374 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sun, 8 Jun 2025 00:32:13 -0600 Subject: libmisc: obj.h: Fix boxing from one interface to another --- libmisc/include/libmisc/obj.h | 14 +++++++------- libmisc/tests/test_obj_nest.c | 9 +++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/libmisc/include/libmisc/obj.h b/libmisc/include/libmisc/obj.h index 48695af..04438f6 100644 --- a/libmisc/include/libmisc/obj.h +++ b/libmisc/include/libmisc/obj.h @@ -60,13 +60,13 @@ #define _LO_IFACE_VTABLE2(...) _LM_DEFER2(_LO_IFACE_VTABLE_indirect)()(__VA_ARGS__) #define _LO_IFACE_PROTO(_ARG_iface_name, _tuple_typ, ...) _LO_IFACE_PROTO_##_tuple_typ(_ARG_iface_name, __VA_ARGS__) -#define _LO_IFACE_PROTO_lo_nest(_ARG_iface_name, _ARG_child_iface_name) \ - LM_ALWAYS_INLINE static lo_interface _ARG_child_iface_name \ - box_##_ARG_iface_name##_as_##_ARG_child_iface_name(lo_interface _ARG_iface_name obj) { \ - return (lo_interface _ARG_child_iface_name){ \ - .self = obj.self, \ - .vtable = obj.vtable->_lo_##_ARG_child_iface_name##_vtable, \ - }; \ +#define _LO_IFACE_PROTO_lo_nest(_ARG_iface_name, _ARG_child_iface_name) \ + LM_ALWAYS_INLINE static lo_interface _ARG_child_iface_name \ + lo_box_##_ARG_iface_name##_as_##_ARG_child_iface_name(lo_interface _ARG_iface_name obj) { \ + return (lo_interface _ARG_child_iface_name){ \ + .self = obj.self, \ + .vtable = obj.vtable->_lo_##_ARG_child_iface_name##_vtable, \ + }; \ } #define _LO_IFACE_PROTO_lo_func(_ARG_iface_name, _ARG_ret_type, _ARG_func_name, ...) \ /* empty */ diff --git a/libmisc/tests/test_obj_nest.c b/libmisc/tests/test_obj_nest.c index d5e563e..66c1efd 100644 --- a/libmisc/tests/test_obj_nest.c +++ b/libmisc/tests/test_obj_nest.c @@ -69,5 +69,14 @@ int main() { char buf[6] = {}; test_assert(LO_CALL(obj, read, buf, 3) == 3); test_assert(memcmp(buf, "Hel\0\0\0", 6) == 0); + + lo_interface reader rd = lo_box_myclass_as_reader(&_obj); + rd = lo_box_read_writer_as_reader(obj); + (void) rd; + + lo_interface writer wr = lo_box_myclass_as_writer(&_obj); + wr = lo_box_read_writer_as_writer(obj); + (void) wr; + return 0; } -- cgit v1.2.3-2-g168b From d2e229a8961ace8907645f4068a9d9414d5a36ae Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 31 May 2025 14:42:03 -0600 Subject: libmisc: obj.h: Use LM_DEFAPPEND() to have lo_box_*_as_*() be macros --- cmd/sbc_harness/fs_harness_flash_bin.h | 1 - cmd/sbc_harness/fs_harness_uptime_txt.h | 1 - lib9p/tests/test_server/fs_flush.h | 1 - lib9p/tests/test_server/fs_shutdown.h | 1 - lib9p/tests/test_server/fs_whoami.h | 1 - lib9p_util/include/util9p/static.h | 8 -------- libmisc/include/libmisc/obj.h | 13 ++++++------- 7 files changed, 6 insertions(+), 20 deletions(-) diff --git a/cmd/sbc_harness/fs_harness_flash_bin.h b/cmd/sbc_harness/fs_harness_flash_bin.h index 36382be..148a446 100644 --- a/cmd/sbc_harness/fs_harness_flash_bin.h +++ b/cmd/sbc_harness/fs_harness_flash_bin.h @@ -25,6 +25,5 @@ struct flash_file { END_PRIVATE(FS_HARNESS_FLASH_BIN); }; LO_IMPLEMENTATION_H(lib9p_srv_file, struct flash_file, flash_file); -#define lo_box_flash_file_as_lib9p_srv_file(obj) util9p_box(flash_file, obj) #endif /* _SBC_HARNESS_FS_HARNESS_FLASH_BIN_H_ */ diff --git a/cmd/sbc_harness/fs_harness_uptime_txt.h b/cmd/sbc_harness/fs_harness_uptime_txt.h index 7bf2945..c575580 100644 --- a/cmd/sbc_harness/fs_harness_uptime_txt.h +++ b/cmd/sbc_harness/fs_harness_uptime_txt.h @@ -14,6 +14,5 @@ struct uptime_file { uint64_t pathnum; }; LO_IMPLEMENTATION_H(lib9p_srv_file, struct uptime_file, uptime_file); -#define lo_box_uptime_file_as_lib9p_srv_file(obj) util9p_box(uptime_file, obj) #endif /* _SBC_HARNESS_FS_HARNESS_UPTIME_TXT_H_ */ diff --git a/lib9p/tests/test_server/fs_flush.h b/lib9p/tests/test_server/fs_flush.h index 2b08850..023434b 100644 --- a/lib9p/tests/test_server/fs_flush.h +++ b/lib9p/tests/test_server/fs_flush.h @@ -22,6 +22,5 @@ struct flush_file { } flush_behavior; }; LO_IMPLEMENTATION_H(lib9p_srv_file, struct flush_file, flush_file); -#define lo_box_flush_file_as_lib9p_srv_file(obj) util9p_box(flush_file, obj) #endif /* _LIB9P_TESTS_TEST_SERVER_FS_FLUSH_H_ */ diff --git a/lib9p/tests/test_server/fs_shutdown.h b/lib9p/tests/test_server/fs_shutdown.h index 6b8683c..7b8d327 100644 --- a/lib9p/tests/test_server/fs_shutdown.h +++ b/lib9p/tests/test_server/fs_shutdown.h @@ -18,6 +18,5 @@ struct shutdown_file { size_t nlisteners; }; LO_IMPLEMENTATION_H(lib9p_srv_file, struct shutdown_file, shutdown_file); -#define lo_box_shutdown_file_as_lib9p_srv_file(obj) util9p_box(shutdown_file, obj) #endif /* _LIB9P_TESTS_TEST_SERVER_FS_SHUTDOWN_H_ */ diff --git a/lib9p/tests/test_server/fs_whoami.h b/lib9p/tests/test_server/fs_whoami.h index 5e1aee9..518e11d 100644 --- a/lib9p/tests/test_server/fs_whoami.h +++ b/lib9p/tests/test_server/fs_whoami.h @@ -15,6 +15,5 @@ struct whoami_file { uint64_t pathnum; }; LO_IMPLEMENTATION_H(lib9p_srv_file, struct whoami_file, whoami_file); -#define lo_box_whoami_file_as_lib9p_srv_file(obj) util9p_box(whoami_file, obj) #endif /* _LIB9P_TESTS_TEST_SERVER_FS_WHOAMI_H_ */ diff --git a/lib9p_util/include/util9p/static.h b/lib9p_util/include/util9p/static.h index 5454c24..4bb24c4 100644 --- a/lib9p_util/include/util9p/static.h +++ b/lib9p_util/include/util9p/static.h @@ -9,12 +9,6 @@ #include -#define util9p_box(nam, obj) \ - ((struct lib9p_srv_file){ \ - .self = obj, \ - .vtable = (void*)&_lo_##nam##_lib9p_srv_file_vtable, \ - }) - #define UTIL9P_ATIME 1728337905 #define UTIL9P_MTIME 1728337904 @@ -56,7 +50,6 @@ struct util9p_static_dir { lo_interface lib9p_srv_file members[]; }; LO_IMPLEMENTATION_H(lib9p_srv_file, struct util9p_static_dir, util9p_static_dir); -#define lo_box_util9p_static_dir_as_lib9p_srv_file(obj) util9p_box(util9p_static_dir, obj) #define UTIL9P_STATIC_DIR(PATH, STRNAME, ...) \ lo_box_util9p_static_dir_as_lib9p_srv_file(&((struct util9p_static_dir){ \ @@ -74,7 +67,6 @@ struct util9p_static_file { size_t data_size; /* only used if .data_end==NULL */ }; LO_IMPLEMENTATION_H(lib9p_srv_file, struct util9p_static_file, util9p_static_file); -#define lo_box_util9p_static_file_as_lib9p_srv_file(obj) util9p_box(util9p_static_file, obj) #define UTIL9P_STATIC_FILE(PATH, STRNAME, ...) \ lo_box_util9p_static_file_as_lib9p_srv_file(&((struct util9p_static_file){ \ diff --git a/libmisc/include/libmisc/obj.h b/libmisc/include/libmisc/obj.h index 04438f6..993bb1a 100644 --- a/libmisc/include/libmisc/obj.h +++ b/libmisc/include/libmisc/obj.h @@ -100,7 +100,7 @@ * interface with functions named `{impl_name}_{method_name}`. * * This will also define a `lo_box_{impl_name}_as_{iface_name}(obj)` - * function. + * const-expr macro. * * You must also call the LO_IMPLEMENTATION_C in a single .c file. */ @@ -109,13 +109,12 @@ extern const struct _lo_##_ARG_iface_name##_vtable \ _lo_##_ARG_impl_name##_##_ARG_iface_name##_vtable; \ /* Boxing. */ \ - LM_ALWAYS_INLINE static lo_interface _ARG_iface_name \ - lo_box_##_ARG_impl_name##_as_##_ARG_iface_name(_ARG_impl_type *self) { \ - return (lo_interface _ARG_iface_name){ \ - .self = self, \ + LM_DEFAPPEND(lo_box_##_ARG_impl_name##_as_##_ARG_iface_name(_ARG_self), ( \ + (lo_interface _ARG_iface_name){ \ + .self = (_ARG_self), \ .vtable = &_lo_##_ARG_impl_name##_##_ARG_iface_name##_vtable, \ - }; \ - } \ + } \ + )); \ LM_FORCE_SEMICOLON /** -- cgit v1.2.3-2-g168b From c3a0b37bf0229c89bd78b5ddf140188410aa3597 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sun, 8 Jun 2025 03:33:42 -0600 Subject: libmisc: obj.h: Fuss with whitespace --- libmisc/include/libmisc/obj.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libmisc/include/libmisc/obj.h b/libmisc/include/libmisc/obj.h index 993bb1a..749a9fc 100644 --- a/libmisc/include/libmisc/obj.h +++ b/libmisc/include/libmisc/obj.h @@ -52,19 +52,22 @@ _LO_IFACE_PROTO, _ARG_iface_name) \ LM_FORCE_SEMICOLON -#define _LO_IFACE_VTABLE(_tuple_typ, ...) _LO_IFACE_VTABLE_##_tuple_typ(__VA_ARGS__) -#define _LO_IFACE_VTABLE_lo_nest(_ARG_child_iface_name) const struct _lo_##_ARG_child_iface_name##_vtable *_lo_##_ARG_child_iface_name##_vtable; LM_FOREACH_TUPLE2(_ARG_child_iface_name##_LO_IFACE, _LO_IFACE_VTABLE2) -#define _LO_IFACE_VTABLE_lo_func(_ARG_ret_type, _ARG_func_name, ...) _ARG_ret_type (*_ARG_func_name)(void * __VA_OPT__(,) __VA_ARGS__); +#define _LO_IFACE_VTABLE(_tuple_typ, ...) _LO_IFACE_VTABLE_##_tuple_typ(__VA_ARGS__) +#define _LO_IFACE_VTABLE_lo_nest(_ARG_child_iface_name) \ + const struct _lo_##_ARG_child_iface_name##_vtable *_lo_##_ARG_child_iface_name##_vtable; \ + LM_FOREACH_TUPLE2(_ARG_child_iface_name##_LO_IFACE, _LO_IFACE_VTABLE2) +#define _LO_IFACE_VTABLE_lo_func(_ARG_ret_type, _ARG_func_name, ...) \ + _ARG_ret_type (*_ARG_func_name)(void * __VA_OPT__(,) __VA_ARGS__); #define _LO_IFACE_VTABLE_indirect() _LO_IFACE_VTABLE #define _LO_IFACE_VTABLE2(...) _LM_DEFER2(_LO_IFACE_VTABLE_indirect)()(__VA_ARGS__) -#define _LO_IFACE_PROTO(_ARG_iface_name, _tuple_typ, ...) _LO_IFACE_PROTO_##_tuple_typ(_ARG_iface_name, __VA_ARGS__) +#define _LO_IFACE_PROTO(_ARG_iface_name, _tuple_typ, ...) _LO_IFACE_PROTO_##_tuple_typ(_ARG_iface_name, __VA_ARGS__) #define _LO_IFACE_PROTO_lo_nest(_ARG_iface_name, _ARG_child_iface_name) \ LM_ALWAYS_INLINE static lo_interface _ARG_child_iface_name \ lo_box_##_ARG_iface_name##_as_##_ARG_child_iface_name(lo_interface _ARG_iface_name obj) { \ return (lo_interface _ARG_child_iface_name){ \ - .self = obj.self, \ + .self = obj.self, \ .vtable = obj.vtable->_lo_##_ARG_child_iface_name##_vtable, \ }; \ } -- cgit v1.2.3-2-g168b From 121994d85648469ea498b52cef83e4609496a7b7 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 31 May 2025 14:42:03 -0600 Subject: libmisc: obj.h: Use LM_DEFAPPEND() to implement magic LO_BOX() --- .editorconfig | 2 +- GNUmakefile | 4 ++ libmisc/CMakeLists.txt | 1 + libmisc/include/libmisc/obj.h | 23 ++++++++++ libmisc/tests/test_obj_autobox.c | 83 ++++++++++++++++++++++++++++++++++++ libmisc/tests/test_obj_autobox.c.gen | 17 ++++++++ 6 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 libmisc/tests/test_obj_autobox.c create mode 100755 libmisc/tests/test_obj_autobox.c.gen diff --git a/.editorconfig b/.editorconfig index b7ad057..565f8b9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -45,7 +45,7 @@ _mode = gitignore # By specific filename (non-lib9p) ############################################# -[{build-aux/embed-sources.h.gen,build-aux/valgrind}] +[{build-aux/embed-sources.h.gen,build-aux/valgrind,libmisc/tests/test_obj_autobox.c.gen}] _mode = sh [{build-aux/lint-{src,bin},build-aux/gcov-prune,libusb/include/libusb/tusb_helpers.h.gen}] diff --git a/GNUmakefile b/GNUmakefile index fa76266..c2cf709 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -33,6 +33,10 @@ generate/files += 3rd-party/COPYING.newlib.txt 3rd-party/COPYING.newlib.txt: /usr/share/licenses/arm-none-eabi-newlib/COPYING.NEWLIB cp $< $@ +generate/files += libmisc/tests/test_obj_autobox.c +libmisc/tests/test_obj_autobox.c: %: %.gen libmisc/tests/test_obj_nest.c + $^ $@ + generate/files += 3rd-party/linux-errno.txt 3rd-party/linux-errno.txt: lib9p/linux-errno.txt.gen $< $(linux.git) $@ diff --git a/libmisc/CMakeLists.txt b/libmisc/CMakeLists.txt index 07f154b..ef254f9 100644 --- a/libmisc/CMakeLists.txt +++ b/libmisc/CMakeLists.txt @@ -33,5 +33,6 @@ add_lib_test(libmisc test_macro) add_lib_test(libmisc test_map) add_lib_test(libmisc test_obj) add_lib_test(libmisc test_obj_nest) +add_lib_test(libmisc test_obj_autobox) add_lib_test(libmisc test_private) add_lib_test(libmisc test_rand) diff --git a/libmisc/include/libmisc/obj.h b/libmisc/include/libmisc/obj.h index 749a9fc..3467d5b 100644 --- a/libmisc/include/libmisc/obj.h +++ b/libmisc/include/libmisc/obj.h @@ -64,6 +64,8 @@ #define _LO_IFACE_PROTO(_ARG_iface_name, _tuple_typ, ...) _LO_IFACE_PROTO_##_tuple_typ(_ARG_iface_name, __VA_ARGS__) #define _LO_IFACE_PROTO_lo_nest(_ARG_iface_name, _ARG_child_iface_name) \ + LM_DEFAPPEND(_LO_REGISTRY_##_ARG_child_iface_name, \ + (lo_interface _ARG_iface_name, _ARG_iface_name)); \ LM_ALWAYS_INLINE static lo_interface _ARG_child_iface_name \ lo_box_##_ARG_iface_name##_as_##_ARG_child_iface_name(lo_interface _ARG_iface_name obj) { \ return (lo_interface _ARG_child_iface_name){ \ @@ -74,6 +76,25 @@ #define _LO_IFACE_PROTO_lo_func(_ARG_iface_name, _ARG_ret_type, _ARG_func_name, ...) \ /* empty */ +/** + * `LO_BOX(iface_name, obj)` boxes `obj` as a `lo_interface + * iface_name`; if `obj` is not already a `lo_interface iface_name` + * box, then it simply calls the appropriate + * lo_box_{XXX}_as_{iface_name}() function/macro. + */ +#define LO_BOX(_ARG_iface_name, obj) _Generic((obj), \ + lo_interface _ARG_iface_name: obj \ + LM_FOREACH_TUPLE(_LO_REGISTRY_##_ARG_iface_name, \ + _LO_BOX, _ARG_iface_name, obj)) +#define LO_BOX2(_ARG_iface_name, obj) _Generic((obj), \ + lo_interface _ARG_iface_name: obj \ + LM_FOREACH_TUPLE2(_LO_REGISTRY_##_ARG_iface_name, \ + _LO_BOX, _ARG_iface_name, obj)) +#define _LO_BOX(_ARG_iface_name, _ARG_obj, _ARG_typ, _ARG_typnam) \ + , _ARG_typ: lo_box_##_ARG_typnam##_as_##_ARG_iface_name(_LO_coerce(_ARG_typ, _ARG_obj)) +#define _LO_coerce(typ, obj) \ + _Generic((obj), typ: (obj), default: *((typ*)0)) + /** * `LO_NULL(iface_name)` is the null/nil/zero value for `lo_interface {iface_name}`. */ @@ -112,6 +133,8 @@ extern const struct _lo_##_ARG_iface_name##_vtable \ _lo_##_ARG_impl_name##_##_ARG_iface_name##_vtable; \ /* Boxing. */ \ + LM_DEFAPPEND(_LO_REGISTRY_##_ARG_iface_name, \ + (_ARG_impl_type *, _ARG_impl_name)); \ LM_DEFAPPEND(lo_box_##_ARG_impl_name##_as_##_ARG_iface_name(_ARG_self), ( \ (lo_interface _ARG_iface_name){ \ .self = (_ARG_self), \ diff --git a/libmisc/tests/test_obj_autobox.c b/libmisc/tests/test_obj_autobox.c new file mode 100644 index 0000000..1bf442d --- /dev/null +++ b/libmisc/tests/test_obj_autobox.c @@ -0,0 +1,83 @@ +/* libmisc/tests/test_obj_autobox.c - Generated by `libmisc/tests/test_obj_nest.c libmisc/tests/test_obj_autobox.c`. DO NOT EDIT! */ +/* libmisc/tests/test_obj_nest.c - Tests for nesting + * + * Copyright (C) 2025 Luke T. Shumaker + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#include /* for memcpy() */ + +#include + +#include "test.h" + +/* interfaces *****************************************************************/ + +#define reader_LO_IFACE \ + LO_FUNC(ssize_t, read, void *, size_t) +LO_INTERFACE(reader); + +#define writer_LO_IFACE \ + LO_FUNC(ssize_t, write, void *, size_t) +LO_INTERFACE(writer); + +#define read_writer_LO_IFACE \ + LO_NEST(reader) \ + LO_NEST(writer) +LO_INTERFACE(read_writer); + +/* implementation header ******************************************************/ + +struct myclass { + size_t len; + char buf[512]; +}; +LO_IMPLEMENTATION_H(reader, struct myclass, myclass); +LO_IMPLEMENTATION_H(writer, struct myclass, myclass); +LO_IMPLEMENTATION_H(read_writer, struct myclass, myclass); + +/* implementation main ********************************************************/ + +LO_IMPLEMENTATION_C(reader, struct myclass, myclass, static); +LO_IMPLEMENTATION_C(writer, struct myclass, myclass, static); +LO_IMPLEMENTATION_C(read_writer, struct myclass, myclass, static); + +static ssize_t myclass_read(struct myclass *self, void *buf, size_t count) { + test_assert(self); + if (count > self->len) + count = self->len; + memcpy(buf, self->buf, count); + return count; +} + +static ssize_t myclass_write(struct myclass *self, void *buf, size_t count) { + test_assert(self); + if (self->len) + return -1; + if (count > sizeof(self->buf)) + count = sizeof(self->buf); + memcpy(self->buf, buf, count); + self->len = count; + return count; +} + +/* main test body *************************************************************/ + +int main() { + struct myclass _obj = {}; + lo_interface read_writer obj = LO_BOX(read_writer, &_obj); + test_assert(LO_CALL(obj, write, "Hello", 6) == 6); + char buf[6] = {}; + test_assert(LO_CALL(obj, read, buf, 3) == 3); + test_assert(memcmp(buf, "Hel\0\0\0", 6) == 0); + + lo_interface reader rd = LO_BOX(reader, &_obj); + rd = LO_BOX(reader, obj); + (void) rd; + + lo_interface writer wr = LO_BOX(writer, &_obj); + wr = LO_BOX(writer, obj); + (void) wr; + + return 0; +} diff --git a/libmisc/tests/test_obj_autobox.c.gen b/libmisc/tests/test_obj_autobox.c.gen new file mode 100755 index 0000000..3cfa3d4 --- /dev/null +++ b/libmisc/tests/test_obj_autobox.c.gen @@ -0,0 +1,17 @@ +#!/bin/sh +# libmisc/tests/test_obj_autobox.c.gen - Generate tests for LO_BOX() +# +# Copyright (C) 2025 Luke T. Shumaker +# SPDX-License-Identifier: AGPL-3.0-or-later + +infile=$1 +outfile=$2 + +grep --quiet lo_box_ -- "$infile" + +{ + echo "/* ${outfile} - Generated by \`$*\`. DO NOT EDIT! */" + sed -E 's/lo_box_([a-z0-9_]+)_as_([a-z0-9_]+)\(/LO_BOX(\2, /g' <"$infile" +} >"$outfile" + +! grep -H lo_box_ -- "$outfile" -- cgit v1.2.3-2-g168b From 5367159e1babccb60c634aa6e32937cfe9bdb7a1 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 31 May 2025 14:42:03 -0600 Subject: tree-wide: Use LO_BOX() where it doesn't explode the post-preprocessed size --- cmd/sbc_harness/fs_harness_flash_bin.c | 2 +- cmd/sbc_harness/fs_harness_uptime_txt.c | 2 +- cmd/sbc_harness/main.c | 6 +++--- lib9p/tests/test_server/fs_flush.c | 2 +- lib9p/tests/test_server/fs_shutdown.c | 4 ++-- lib9p/tests/test_server/fs_whoami.c | 2 +- lib9p/tests/test_server/main.c | 4 ++-- lib9p_util/static.c | 4 ++-- libdhcp/tests/test_client.c | 6 +++--- libhw_cr/host_net.c | 2 +- libhw_cr/rp2040_hwtimer.c | 2 +- libhw_cr/w5500.c | 8 ++++---- 12 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cmd/sbc_harness/fs_harness_flash_bin.c b/cmd/sbc_harness/fs_harness_flash_bin.c index 5e6f49c..8bd144e 100644 --- a/cmd/sbc_harness/fs_harness_flash_bin.c +++ b/cmd/sbc_harness/fs_harness_flash_bin.c @@ -201,7 +201,7 @@ static lo_interface lib9p_srv_fio flash_file_fopen(struct flash_file *self, stru self->wbuf.ok = false; } - return lo_box_flash_file_as_lib9p_srv_fio(self); + return LO_BOX(lib9p_srv_fio, self); } /* srv_fio ********************************************************************/ diff --git a/cmd/sbc_harness/fs_harness_uptime_txt.c b/cmd/sbc_harness/fs_harness_uptime_txt.c index 339b410..23ac9d4 100644 --- a/cmd/sbc_harness/fs_harness_uptime_txt.c +++ b/cmd/sbc_harness/fs_harness_uptime_txt.c @@ -89,7 +89,7 @@ static lo_interface lib9p_srv_fio uptime_file_fopen(struct uptime_file *self, st ret->parent = self; ret->buf_len = 0; - return lo_box_uptime_fio_as_lib9p_srv_fio(ret); + return LO_BOX(lib9p_srv_fio, ret); } /* srv_fio ********************************************************************/ diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c index 71c39b2..0605ae2 100644 --- a/cmd/sbc_harness/main.c +++ b/cmd/sbc_harness/main.c @@ -149,7 +149,7 @@ struct { static COROUTINE dhcp_cr(void *) { cr_begin(); - dhcp_client_main(lo_box_w5500_if_as_net_iface(&globals.dev_w5500), "harness"); + dhcp_client_main(LO_BOX(net_iface, &globals.dev_w5500), "harness"); cr_end(); } @@ -157,7 +157,7 @@ static COROUTINE dhcp_cr(void *) { static COROUTINE read9p_cr(void *) { cr_begin(); - lo_interface net_iface iface = lo_box_w5500_if_as_net_iface(&globals.dev_w5500); + lo_interface net_iface iface = LO_BOX(net_iface, &globals.dev_w5500); lo_interface net_stream_listener listener = LO_CALL(iface, tcp_listen, LIB9P_DEFAULT_PORT_9FS); lib9p_srv_accept_and_read_loop(&globals.srv, listener); @@ -204,7 +204,7 @@ COROUTINE init_cr(void *) { 17, /* PIN_CS */ 0, 1, 2, 3); /* DMA channels */ w5500_init(&globals.dev_w5500, "W5500", - lo_box_rp2040_hwspi_as_spi(&globals.dev_spi), + LO_BOX(spi, &globals.dev_spi), 21, /* PIN_INTR */ 20, /* PIN_RESET */ ((struct net_eth_addr){{ diff --git a/lib9p/tests/test_server/fs_flush.c b/lib9p/tests/test_server/fs_flush.c index e6408d7..fade0a1 100644 --- a/lib9p/tests/test_server/fs_flush.c +++ b/lib9p/tests/test_server/fs_flush.c @@ -67,7 +67,7 @@ static lo_interface lib9p_srv_fio flush_file_fopen(struct flush_file *self, stru struct flush_fio *ret = heap_alloc(1, struct flush_fio); ret->parent = self; - return lo_box_flush_fio_as_lib9p_srv_fio(ret); + return LO_BOX(lib9p_srv_fio, ret); } /* srv_fio ********************************************************************/ diff --git a/lib9p/tests/test_server/fs_shutdown.c b/lib9p/tests/test_server/fs_shutdown.c index d4ae67e..0dd473d 100644 --- a/lib9p/tests/test_server/fs_shutdown.c +++ b/lib9p/tests/test_server/fs_shutdown.c @@ -66,7 +66,7 @@ static lo_interface lib9p_srv_fio shutdown_file_fopen(struct shutdown_file *self struct shutdown_fio *ret = heap_alloc(1, struct shutdown_fio); ret->parent = self; - return lo_box_shutdown_fio_as_lib9p_srv_fio(ret); + return LO_BOX(lib9p_srv_fio, ret); } /* srv_fio ********************************************************************/ @@ -94,7 +94,7 @@ static uint32_t shutdown_fio_pwrite(struct shutdown_fio *self, struct lib9p_srv_ if (byte_count == 0) return 0; for (size_t i = 0; i < self->parent->nlisteners; i++) - LO_CALL(lo_box_hostnet_tcplist_as_net_stream_listener(&self->parent->listeners[i]), close); + LO_CALL(LO_BOX(net_stream_listener, &self->parent->listeners[i]), close); return byte_count; } static void shutdown_fio_pread(struct shutdown_fio *LM_UNUSED(self), struct lib9p_srv_ctx *LM_UNUSED(ctx), diff --git a/lib9p/tests/test_server/fs_whoami.c b/lib9p/tests/test_server/fs_whoami.c index 7e1d635..6cc46ac 100644 --- a/lib9p/tests/test_server/fs_whoami.c +++ b/lib9p/tests/test_server/fs_whoami.c @@ -92,7 +92,7 @@ static lo_interface lib9p_srv_fio whoami_file_fopen(struct whoami_file *self, st ret->buf_len = 0; ret->buf = NULL; - return lo_box_whoami_fio_as_lib9p_srv_fio(ret); + return LO_BOX(lib9p_srv_fio, ret); } /* srv_fio ********************************************************************/ diff --git a/lib9p/tests/test_server/main.c b/lib9p/tests/test_server/main.c index f2a73bf..2ce8346 100644 --- a/lib9p/tests/test_server/main.c +++ b/lib9p/tests/test_server/main.c @@ -96,7 +96,7 @@ static COROUTINE read_cr(void *_i) { hostnet_tcp_listener_init(&globals.listeners[i], globals.port); - lib9p_srv_accept_and_read_loop(&globals.srv, lo_box_hostnet_tcplist_as_net_stream_listener(&globals.listeners[i])); + lib9p_srv_accept_and_read_loop(&globals.srv, LO_BOX(net_stream_listener, &globals.listeners[i])); cr_end(); } @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) { struct hostclock clock_monotonic = { .clock_id = CLOCK_MONOTONIC, }; - bootclock = lo_box_hostclock_as_alarmclock(&clock_monotonic); + bootclock = LO_BOX(alarmclock, &clock_monotonic); coroutine_add("init", init_cr, NULL); coroutine_main(); fclose(globals.logstream); diff --git a/lib9p_util/static.c b/lib9p_util/static.c index c35d28c..40810b5 100644 --- a/lib9p_util/static.c +++ b/lib9p_util/static.c @@ -100,7 +100,7 @@ LIB9P_SRV_NOTFILE(struct util9p_static_dir, util9p_static_dir); static lo_interface lib9p_srv_dio util9p_static_dir_dopen(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); - return lo_box_util9p_static_dir_as_lib9p_srv_dio(self); + return LO_BOX(lib9p_srv_dio, self); } static void util9p_static_dir_iofree(struct util9p_static_dir *self) { assert(self); @@ -191,7 +191,7 @@ static lo_interface lib9p_srv_fio util9p_static_file_fopen(struct util9p_static_ assert(rd); assert(!wr); assert(!trunc); - return lo_box_util9p_static_file_as_lib9p_srv_fio(self); + return LO_BOX(lib9p_srv_fio, self); } static void util9p_static_file_iofree(struct util9p_static_file *self) { assert(self); diff --git a/libdhcp/tests/test_client.c b/libdhcp/tests/test_client.c index 24b3af6..09557e5 100644 --- a/libdhcp/tests/test_client.c +++ b/libdhcp/tests/test_client.c @@ -99,7 +99,7 @@ static lo_interface net_packet_conn test_udp_conn(struct test_iface *self, uint1 test_assert(local_port == 68); test_assert(!once); once = true; - return lo_box_test_udp_as_net_packet_conn(&self->conn); + return LO_BOX(net_packet_conn, &self->conn); } /******************************************************************************/ @@ -107,7 +107,7 @@ static lo_interface net_packet_conn test_udp_conn(struct test_iface *self, uint1 COROUTINE dhcp_cr(void *) { cr_begin(); struct test_iface iface = {}; - dhcp_client_main(lo_box_test_as_net_iface(&iface), "test-client"); + dhcp_client_main(LO_BOX(net_iface, &iface), "test-client"); cr_end(); } @@ -115,7 +115,7 @@ int main() { struct hostclock clock_monotonic = { .clock_id = CLOCK_MONOTONIC, }; - bootclock = lo_box_hostclock_as_alarmclock(&clock_monotonic); + bootclock = LO_BOX(alarmclock, &clock_monotonic); coroutine_add("dhcp", dhcp_cr, NULL); coroutine_main(); diff --git a/libhw_cr/host_net.c b/libhw_cr/host_net.c index 8016787..c8d4472 100644 --- a/libhw_cr/host_net.c +++ b/libhw_cr/host_net.c @@ -187,7 +187,7 @@ static lo_interface net_stream_conn hostnet_tcplist_accept(struct hostnet_tcp_li listener->active_conn.fd = ret_connfd; listener->active_conn.read_deadline_ns = 0; - return lo_box_hostnet_tcp_as_net_stream_conn(&listener->active_conn); + return LO_BOX(net_stream_conn, &listener->active_conn); } /* TCP listener close() *******************************************************/ diff --git a/libhw_cr/rp2040_hwtimer.c b/libhw_cr/rp2040_hwtimer.c index 8227abb..d9f0a24 100644 --- a/libhw_cr/rp2040_hwtimer.c +++ b/libhw_cr/rp2040_hwtimer.c @@ -44,7 +44,7 @@ static_assert(sizeof(hwtimers)/sizeof(hwtimers[0]) == _RP2040_HWALARM_NUM); lo_interface alarmclock rp2040_hwtimer(enum rp2040_hwalarm_instance alarm_num) { assert(alarm_num < _RP2040_HWALARM_NUM); - return lo_box_rp2040_hwtimer_as_alarmclock(&hwtimers[alarm_num]); + return LO_BOX(alarmclock, &hwtimers[alarm_num]); } diff --git a/libhw_cr/w5500.c b/libhw_cr/w5500.c index 76b8dec..58715c9 100644 --- a/libhw_cr/w5500.c +++ b/libhw_cr/w5500.c @@ -459,7 +459,7 @@ static lo_interface net_stream_listener w5500_if_tcp_listen(struct w5500 *chip, sock->read_deadline_ns = 0; sock->list_open = true; - return lo_box_w5500_tcplist_as_net_stream_listener(sock); + return LO_BOX(net_stream_listener, sock); } static lo_interface net_stream_conn w5500_if_tcp_dial(struct w5500 *chip, @@ -509,7 +509,7 @@ static lo_interface net_stream_conn w5500_if_tcp_dial(struct w5500 *chip, cr_yield(); break; case STATE_TCP_ESTABLISHED: - return lo_box_w5500_tcp_as_net_stream_conn(socket); + return LO_BOX(net_stream_conn, socket); default: goto restart; } @@ -545,7 +545,7 @@ static lo_interface net_packet_conn w5500_if_udp_conn(struct w5500 *chip, uint16 cr_yield(); cr_mutex_unlock(&chip->mu); - return lo_box_w5500_udp_as_net_packet_conn(socket); + return LO_BOX(net_packet_conn, socket); } static bool w5500_if_arp_ping(struct w5500 *chip, struct net_ip4_addr addr) { @@ -601,7 +601,7 @@ static lo_interface net_stream_conn w5500_tcplist_accept(struct _w5500_socket *s [[fallthrough]]; case STATE_TCP_CLOSE_WAIT: socket->write_open = true; - return lo_box_w5500_tcp_as_net_stream_conn(socket); + return LO_BOX(net_stream_conn, socket); default: goto restart; } -- cgit v1.2.3-2-g168b