diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-31 14:42:03 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-06-08 03:16:03 -0600 |
commit | d2e229a8961ace8907645f4068a9d9414d5a36ae (patch) | |
tree | fe521b2acc1643935f1a56a3497d3eeb27394f33 | |
parent | e3fd00bb4e2b7b4cabfb416e59fdf83e331a9374 (diff) |
libmisc: obj.h: Use LM_DEFAPPEND() to have lo_box_*_as_*() be macros
-rw-r--r-- | cmd/sbc_harness/fs_harness_flash_bin.h | 1 | ||||
-rw-r--r-- | cmd/sbc_harness/fs_harness_uptime_txt.h | 1 | ||||
-rw-r--r-- | lib9p/tests/test_server/fs_flush.h | 1 | ||||
-rw-r--r-- | lib9p/tests/test_server/fs_shutdown.h | 1 | ||||
-rw-r--r-- | lib9p/tests/test_server/fs_whoami.h | 1 | ||||
-rw-r--r-- | lib9p_util/include/util9p/static.h | 8 | ||||
-rw-r--r-- | 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 <lib9p/srv.h> -#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 /** |