diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-04-22 20:30:40 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-06 11:50:46 -0600 |
commit | b3ee525e9e0d49485714770d898cf9c28769313a (patch) | |
tree | 86a2f47d6e25db61fc94d625f17aafdffe368f3d | |
parent | 6178ffcd1f911c19f33f1efe9a24d106806ce8dd (diff) |
Drop -fplan9-extensions
-rw-r--r-- | HACKING.md | 2 | ||||
-rw-r--r-- | lib9p_util/include/util9p/static.h | 24 | ||||
-rw-r--r-- | lib9p_util/static.c | 32 | ||||
-rw-r--r-- | libmisc/CMakeLists.txt | 1 | ||||
-rw-r--r-- | libmisc/include/libmisc/macro.h | 17 | ||||
-rw-r--r-- | libobj/CMakeLists.txt | 1 | ||||
-rw-r--r-- | libobj/include/libobj/obj.h | 57 |
7 files changed, 87 insertions, 47 deletions
@@ -7,7 +7,7 @@ # Source Layout -Our own "flavor" of C: GNU C plus `-fplan9-extensions`, making use of: +Our own "flavor" of C: GNU C, plus making use of: - `libobj/`: For Go-like object-oriented programming - `libmisc/`: Low-level C programming utilities; sort of an augmented diff --git a/lib9p_util/include/util9p/static.h b/lib9p_util/include/util9p/static.h index 0b391b8..5454c24 100644 --- a/lib9p_util/include/util9p/static.h +++ b/lib9p_util/include/util9p/static.h @@ -20,7 +20,7 @@ /* Common *********************************************************************/ -typedef struct { +struct _util9p_static_common { char *u_name; uint32_t u_num; char *g_name; @@ -32,7 +32,7 @@ typedef struct { char *name; lib9p_dm_t perm; uint32_t atime, mtime; -} _util9p_static_common; +}; #define UTIL9P_STATIC_COMMON(PATH, STRNAME, MODE) \ { \ @@ -50,7 +50,7 @@ typedef struct { /* Dir ************************************************************************/ struct util9p_static_dir { - _util9p_static_common; + struct _util9p_static_common c; /* NULL-terminated */ lo_interface lib9p_srv_file members[]; @@ -58,16 +58,16 @@ struct util9p_static_dir { 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){ \ - ._util9p_static_common = UTIL9P_STATIC_COMMON(PATH, STRNAME, 0555), \ - .members = { __VA_ARGS__ LO_NULL(lib9p_srv_file) }, \ +#define UTIL9P_STATIC_DIR(PATH, STRNAME, ...) \ + lo_box_util9p_static_dir_as_lib9p_srv_file(&((struct util9p_static_dir){ \ + .c = UTIL9P_STATIC_COMMON(PATH, STRNAME, 0555), \ + .members = { __VA_ARGS__ LO_NULL(lib9p_srv_file) }, \ })) /* File ***********************************************************************/ struct util9p_static_file { - _util9p_static_common; + struct _util9p_static_common c; char *data_start; /* must not be NULL */ char *data_end; /* may be NULL, in which case data_size is used */ @@ -76,10 +76,10 @@ struct util9p_static_file { 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){ \ - ._util9p_static_common = UTIL9P_STATIC_COMMON(PATH, STRNAME, 0444), \ - __VA_ARGS__ \ +#define UTIL9P_STATIC_FILE(PATH, STRNAME, ...) \ + lo_box_util9p_static_file_as_lib9p_srv_file(&((struct util9p_static_file){ \ + .c = UTIL9P_STATIC_COMMON(PATH, STRNAME, 0444), \ + __VA_ARGS__ \ })) #endif /* _UTIL9P_STATIC_H_ */ diff --git a/lib9p_util/static.c b/lib9p_util/static.c index 1726319..c35d28c 100644 --- a/lib9p_util/static.c +++ b/lib9p_util/static.c @@ -29,7 +29,7 @@ static struct lib9p_qid util9p_static_dir_qid(struct util9p_static_dir *self) { return (struct lib9p_qid){ .type = LIB9P_QT_DIR, .vers = 1, - .path = self->pathnum, + .path = self->c.pathnum, }; } @@ -39,14 +39,14 @@ static struct lib9p_srv_stat util9p_static_dir_stat(struct util9p_static_dir *se return (struct lib9p_srv_stat){ .qid = util9p_static_dir_qid(self), - .mode = LIB9P_DM_DIR | (self->perm & 0555), - .atime_sec = self->atime, - .mtime_sec = self->mtime, + .mode = LIB9P_DM_DIR | (self->c.perm & 0555), + .atime_sec = self->c.atime, + .mtime_sec = self->c.mtime, .size = 0, - .name = lib9p_str(self->name), - .owner_uid = { .name = lib9p_str(self->u_name), .num = self->u_num }, - .owner_gid = { .name = lib9p_str(self->g_name), .num = self->g_num }, - .last_modifier_uid = { .name = lib9p_str(self->m_name), .num = self->m_num }, + .name = lib9p_str(self->c.name), + .owner_uid = { .name = lib9p_str(self->c.u_name), .num = self->c.u_num }, + .owner_gid = { .name = lib9p_str(self->c.g_name), .num = self->c.g_num }, + .last_modifier_uid = { .name = lib9p_str(self->c.m_name), .num = self->c.m_num }, .extension = lib9p_str(NULL), }; } @@ -135,7 +135,7 @@ static struct lib9p_qid util9p_static_file_qid(struct util9p_static_file *self) return (struct lib9p_qid){ .type = LIB9P_QT_FILE, .vers = 1, - .path = self->pathnum, + .path = self->c.pathnum, }; } @@ -157,14 +157,14 @@ static struct lib9p_srv_stat util9p_static_file_stat(struct util9p_static_file * return (struct lib9p_srv_stat){ .qid = util9p_static_file_qid(self), - .mode = self->perm & 0444, - .atime_sec = self->atime, - .mtime_sec = self->mtime, + .mode = self->c.perm & 0444, + .atime_sec = self->c.atime, + .mtime_sec = self->c.mtime, .size = (uint64_t)util9p_static_file_size(self), - .name = lib9p_str(self->name), - .owner_uid = { .name = lib9p_str(self->u_name), .num = self->u_num }, - .owner_gid = { .name = lib9p_str(self->g_name), .num = self->g_num }, - .last_modifier_uid = { .name = lib9p_str(self->m_name), .num = self->m_num }, + .name = lib9p_str(self->c.name), + .owner_uid = { .name = lib9p_str(self->c.u_name), .num = self->c.u_num }, + .owner_gid = { .name = lib9p_str(self->c.g_name), .num = self->c.g_num }, + .last_modifier_uid = { .name = lib9p_str(self->c.m_name), .num = self->c.m_num }, .extension = lib9p_str(NULL), }; } diff --git a/libmisc/CMakeLists.txt b/libmisc/CMakeLists.txt index fdbe949..1bce759 100644 --- a/libmisc/CMakeLists.txt +++ b/libmisc/CMakeLists.txt @@ -12,7 +12,6 @@ target_sources(libmisc INTERFACE log.c map.c ) -target_compile_options(libmisc INTERFACE "$<$<COMPILE_LANGUAGE:C>:-fplan9-extensions>") add_lib_test(libmisc test_assert) add_lib_test(libmisc test_assert_min) diff --git a/libmisc/include/libmisc/macro.h b/libmisc/include/libmisc/macro.h index 93286c6..ae204ae 100644 --- a/libmisc/include/libmisc/macro.h +++ b/libmisc/include/libmisc/macro.h @@ -110,4 +110,21 @@ #define _LM_EVAL__2(...) _LM_EVAL__1(_LM_EVAL__1(__VA_ARGS__)) #define _LM_EVAL__1(...) __VA_ARGS__ +/** The same as LM_FOREACH_TUPLE(), but callable from inside of LM_FOREACH_TUPLE(). */ +#define LM_FOREACH_TUPLE2(tuples, func, ...) \ + LM_IF(LM_TUPLES_NONEMPTY(tuples))( \ + _LM_DEFER2(func)(__VA_ARGS__ __VA_OPT__(,) LM_EXPAND LM_TUPLES_HEAD(tuples)) \ + _LM_DEFER2(_LM_FOREACH_TUPLE_indirect)()(LM_TUPLES_TAIL(tuples), func, __VA_ARGS__) \ + )() +#define LM_FOREACH_TUPLE3(tuples, func, ...) \ + LM_IF(LM_TUPLES_NONEMPTY(tuples))( \ + _LM_DEFER2(func)(__VA_ARGS__ __VA_OPT__(,) LM_EXPAND LM_TUPLES_HEAD(tuples)) \ + _LM_DEFER2(_LM_FOREACH_TUPLE_indirect)()(LM_TUPLES_TAIL(tuples), func, __VA_ARGS__) \ + )() +#define LM_FOREACH_TUPLE4(tuples, func, ...) \ + LM_IF(LM_TUPLES_NONEMPTY(tuples))( \ + _LM_DEFER2(func)(__VA_ARGS__ __VA_OPT__(,) LM_EXPAND LM_TUPLES_HEAD(tuples)) \ + _LM_DEFER2(_LM_FOREACH_TUPLE_indirect)()(LM_TUPLES_TAIL(tuples), func, __VA_ARGS__) \ + )() + #endif /* _LIBMISC_MACRO_H_ */ diff --git a/libobj/CMakeLists.txt b/libobj/CMakeLists.txt index e4d8095..f452e8a 100644 --- a/libobj/CMakeLists.txt +++ b/libobj/CMakeLists.txt @@ -8,7 +8,6 @@ target_include_directories(libobj PUBLIC INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/i target_link_libraries(libobj INTERFACE libmisc ) -target_compile_options(libobj INTERFACE "$<$<COMPILE_LANGUAGE:C>:-fplan9-extensions>") add_lib_test(libobj test_obj) add_lib_test(libobj test_nest) diff --git a/libobj/include/libobj/obj.h b/libobj/include/libobj/obj.h index 1fb8f95..06b7298 100644 --- a/libobj/include/libobj/obj.h +++ b/libobj/include/libobj/obj.h @@ -39,30 +39,42 @@ (lo_nest, _ARG_child_iface_name) #define LO_FUNC(_ARG_ret_type, _ARG_func_name, ...) \ (lo_func, _ARG_ret_type, _ARG_func_name __VA_OPT__(,) __VA_ARGS__) -#define LO_INTERFACE(_ARG_iface_name) \ - typedef struct { \ - LM_FOREACH_TUPLE(_ARG_iface_name##_LO_IFACE, \ - _LO_IFACE_VTABLE) \ - } _lo_##_ARG_iface_name##_vtable; \ - struct _ARG_iface_name { \ - void *self; \ - const _lo_##_ARG_iface_name##_vtable *vtable; \ - }; \ - LM_FOREACH_TUPLE(_ARG_iface_name##_LO_IFACE, \ - _LO_IFACE_PROTO, _ARG_iface_name) \ +#define LO_INTERFACE(_ARG_iface_name) \ + struct _lo_##_ARG_iface_name##_vtable { \ + LM_FOREACH_TUPLE(_ARG_iface_name##_LO_IFACE, \ + _LO_IFACE_VTABLE) \ + }; \ + struct _ARG_iface_name { \ + void *self; \ + const struct _lo_##_ARG_iface_name##_vtable *vtable; \ + }; \ + LM_FOREACH_TUPLE(_ARG_iface_name##_LO_IFACE, \ + _LO_IFACE_PROTO, _ARG_iface_name) \ extern int LM_CAT2_(_HIDDEN_BOGUS_, __COUNTER__) #define _LO_IFACE_VTABLE(_tuple_typ, ...) _LO_IFACE_VTABLE_##_tuple_typ(__VA_ARGS__) -#define _LO_IFACE_VTABLE_lo_nest(_ARG_child_iface_name) _lo_##_ARG_child_iface_name##_vtable; +#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_VTABLE2(_tuple_typ, ...) _LO_IFACE_VTABLE2_##_tuple_typ(__VA_ARGS__) +#define _LO_IFACE_VTABLE2_lo_nest(_ARG_child_iface_name) const struct _lo_##_ARG_child_iface_name##_vtable *_lo_##_ARG_child_iface_name##_vtable; LM_FOREACH_TUPLE3(_ARG_child_iface_name##_LO_IFACE, _LO_IFACE_VTABLE3) +#define _LO_IFACE_VTABLE2_lo_func(_ARG_ret_type, _ARG_func_name, ...) _ARG_ret_type (*_ARG_func_name)(void * __VA_OPT__(,) __VA_ARGS__); + +#define _LO_IFACE_VTABLE3(_tuple_typ, ...) _LO_IFACE_VTABLE3_##_tuple_typ(__VA_ARGS__) +#define _LO_IFACE_VTABLE3_lo_nest(_ARG_child_iface_name) const struct _lo_##_ARG_child_iface_name##_vtable *_lo_##_ARG_child_iface_name##_vtable; LM_FOREACH_TUPLE4(_ARG_child_iface_name##_LO_IFACE, _LO_IFACE_VTABLE4) +#define _LO_IFACE_VTABLE3_lo_func(_ARG_ret_type, _ARG_func_name, ...) _ARG_ret_type (*_ARG_func_name)(void * __VA_OPT__(,) __VA_ARGS__); + +#define _LO_IFACE_VTABLE4(_tuple_typ, ...) _LO_IFACE_VTABLE4_##_tuple_typ(__VA_ARGS__) +#define _LO_IFACE_VTABLE4_lo_nest(_ARG_child_iface_name) static_assert(0, "BUG: libobj cannot nest interfaces more than 4 deep"); +#define _LO_IFACE_VTABLE4_lo_func(_ARG_ret_type, _ARG_func_name, ...) _ARG_ret_type (*_ARG_func_name)(void * __VA_OPT__(,) __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, \ + .vtable = obj.vtable->_lo_##_ARG_child_iface_name##_vtable, \ }; \ } #define _LO_IFACE_PROTO_lo_func(_ARG_iface_name, _ARG_ret_type, _ARG_func_name, ...) \ @@ -103,7 +115,7 @@ */ #define LO_IMPLEMENTATION_H(_ARG_iface_name, _ARG_impl_type, _ARG_impl_name) \ /* Vtable. */ \ - extern const _lo_##_ARG_iface_name##_vtable \ + 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 \ @@ -131,7 +143,7 @@ LM_FOREACH_TUPLE(_ARG_iface_name##_LO_IFACE, \ _LO_IMPL_PROTO, _ARG_impl_type, _ARG_impl_name, __VA_ARGS__) \ /* Vtable. */ \ - const _lo_##_ARG_iface_name##_vtable \ + const struct _lo_##_ARG_iface_name##_vtable \ _lo_##_ARG_impl_name##_##_ARG_iface_name##_vtable = { \ LM_FOREACH_TUPLE(_ARG_iface_name##_LO_IFACE, \ _LO_IMPL_VTABLE, _ARG_impl_name) \ @@ -142,7 +154,20 @@ #define _LO_IMPL_PROTO_lo_func(_ARG_impl_type, _ARG_impl_name, _ARG_quals, _ARG_ret_type, _ARG_func_name, ...) _ARG_quals _ARG_ret_type _ARG_impl_name##_##_ARG_func_name(_ARG_impl_type * __VA_OPT__(,) __VA_ARGS__); #define _LO_IMPL_VTABLE(_ARG_impl_name, _tuple_typ, ...) _LO_IMPL_VTABLE_##_tuple_typ(_ARG_impl_name, __VA_ARGS__) -#define _LO_IMPL_VTABLE_lo_nest(_ARG_impl_name, _ARG_child_iface_name) ._lo_##_ARG_child_iface_name##_vtable = _lo_##_ARG_impl_name##_##_ARG_child_iface_name##_vtable, +#define _LO_IMPL_VTABLE_lo_nest(_ARG_impl_name, _ARG_child_iface_name) ._lo_##_ARG_child_iface_name##_vtable = &_lo_##_ARG_impl_name##_##_ARG_child_iface_name##_vtable, LM_FOREACH_TUPLE2(_ARG_child_iface_name##_LO_IFACE, _LO_IMPL_VTABLE2, _ARG_impl_name) #define _LO_IMPL_VTABLE_lo_func(_ARG_impl_name, _ARG_ret_type, _ARG_func_name, ...) ._ARG_func_name = (void*)_ARG_impl_name##_##_ARG_func_name, +#define _LO_IMPL_VTABLE2(_ARG_impl_name, _tuple_typ, ...) _LO_IMPL_VTABLE2_##_tuple_typ(_ARG_impl_name, __VA_ARGS__) +#define _LO_IMPL_VTABLE2_lo_nest(_ARG_impl_name, _ARG_child_iface_name) ._lo_##_ARG_child_iface_name##_vtable = &_lo_##_ARG_impl_name##_##_ARG_child_iface_name##_vtable, LM_FOREACH_TUPLE3(_ARG_child_iface_name##_LO_IFACE, _LO_IMPL_VTABLE3, _ARG_impl_name) +#define _LO_IMPL_VTABLE2_lo_func(_ARG_impl_name, _ARG_ret_type, _ARG_func_name, ...) ._ARG_func_name = (void*)_ARG_impl_name##_##_ARG_func_name, + +#define _LO_IMPL_VTABLE3(_ARG_impl_name, _tuple_typ, ...) _LO_IMPL_VTABLE3_##_tuple_typ(_ARG_impl_name, __VA_ARGS__) +#define _LO_IMPL_VTABLE3_lo_nest(_ARG_impl_name, _ARG_child_iface_name) ._lo_##_ARG_child_iface_name##_vtable = &_lo_##_ARG_impl_name##_##_ARG_child_iface_name##_vtable, LM_FOREACH_TUPLE4(_ARG_child_iface_name##_LO_IFACE, _LO_IMPL_VTABLE4, _ARG_impl_name) +#define _LO_IMPL_VTABLE3_lo_func(_ARG_impl_name, _ARG_ret_type, _ARG_func_name, ...) ._ARG_func_name = (void*)_ARG_impl_name##_##_ARG_func_name, + +#define _LO_IMPL_VTABLE4(_ARG_impl_name, _tuple_typ, ...) _LO_IMPL_VTABLE4_##_tuple_typ(_ARG_impl_name, __VA_ARGS__) +#define _LO_IMPL_VTABLE4_lo_nest(_ARG_impl_name, _ARG_child_iface_name) static_assert(0, "BUG: libobj cannot nest interfaces more than 4 deep"); +#define _LO_IMPL_VTABLE4_lo_func(_ARG_impl_name, _ARG_ret_type, _ARG_func_name, ...) ._ARG_func_name = (void*)_ARG_impl_name##_##_ARG_func_name, + + #endif /* _LIBOBJ_OBJ_H_ */ |