summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-06-08 00:32:13 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-06-08 03:09:05 -0600
commite3fd00bb4e2b7b4cabfb416e59fdf83e331a9374 (patch)
treec36f298b5e4ca8a920b571fb7cdbacef99dd6ee3
parentf428acdaf8c8851323391a949f0a9cbcf521adda (diff)
libmisc: obj.h: Fix boxing from one interface to another
-rw-r--r--libmisc/include/libmisc/obj.h14
-rw-r--r--libmisc/tests/test_obj_nest.c9
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;
}