diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-06-10 17:26:01 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-06-10 17:26:01 -0600 |
commit | 7146166ce00e1f6ad3a35d7e1e4bf778b74272e1 (patch) | |
tree | 61dddfb0735fe841a0e1c56ea331a360a2d2dad0 | |
parent | cd5768ef4bc36b33699539d9656f455bafb0de0c (diff) | |
parent | 6eafa9fd3a49289d34007a018b6d1fba8e4b7e24 (diff) |
Merge branch 'lukeshu/obj-meth'
-rwxr-xr-x | build-aux/lint-src | 14 | ||||
-rw-r--r-- | build-aux/measurestack/app_plugins.py | 5 | ||||
-rw-r--r-- | cmd/sbc_harness/fs_harness_flash_bin.c | 26 | ||||
-rw-r--r-- | cmd/sbc_harness/fs_harness_uptime_txt.c | 25 | ||||
-rw-r--r-- | lib9p/srv.c | 4 | ||||
-rw-r--r-- | lib9p/srv_include/lib9p/srv.h | 16 | ||||
-rw-r--r-- | lib9p/tests/test_server/fs_flush.c | 21 | ||||
-rw-r--r-- | lib9p/tests/test_server/fs_shutdown.c | 21 | ||||
-rw-r--r-- | lib9p/tests/test_server/fs_whoami.c | 21 | ||||
-rw-r--r-- | lib9p/tests/test_server/main.c | 3 | ||||
-rw-r--r-- | lib9p_util/static.c | 73 | ||||
-rw-r--r-- | libdhcp/tests/test_client.c | 9 | ||||
-rw-r--r-- | libhw_cr/host_alarmclock.c | 18 | ||||
-rw-r--r-- | libhw_cr/host_include/libhw/host_net.h | 9 | ||||
-rw-r--r-- | libhw_cr/host_net.c | 36 | ||||
-rw-r--r-- | libhw_cr/rp2040_hwspi.c | 6 | ||||
-rw-r--r-- | libhw_cr/rp2040_hwtimer.c | 3 | ||||
-rw-r--r-- | libhw_cr/rp2040_include/libhw/w5500.h | 13 | ||||
-rw-r--r-- | libhw_cr/w5500.c | 36 | ||||
-rw-r--r-- | libmisc/fmt.c | 6 | ||||
-rw-r--r-- | libmisc/include/libmisc/obj.h | 97 | ||||
-rw-r--r-- | libmisc/log.c | 3 | ||||
-rw-r--r-- | libmisc/tests/test_obj.c | 8 | ||||
-rw-r--r-- | libmisc/tests/test_obj_autobox.c | 14 | ||||
-rw-r--r-- | libmisc/tests/test_obj_nest.c | 14 |
25 files changed, 247 insertions, 254 deletions
diff --git a/build-aux/lint-src b/build-aux/lint-src index 033340d..69b594a 100755 --- a/build-aux/lint-src +++ b/build-aux/lint-src @@ -13,7 +13,7 @@ err() { } get-dscname() { - if [[ $1 == */Documentation/* ]] && [[ "$(sed 1q -- "$1")" == 'NAME' ]]; then + if [[ $1 == */Documentation/* && "$(sed 1q -- "$1")" == 'NAME' ]]; then sed -n ' 2{ s,[/.],_,g; @@ -90,7 +90,7 @@ get-dscname() { # File body ############################################################ - if grep -n --color=auto "$(printf '\\S\t')" "$filename"; then + if grep -n --color=auto $'\\S\t' "$filename"; then err "$filename" 'uses tabs for alignment' fi done @@ -112,6 +112,16 @@ get-dscname() { grep -Fxq "#endif /* ${guard} */" "$filename"; }; then err "$filename" "does not have ${guard} guard" fi + if [[ $filename != libmisc/include/libmisc/obj.h ]] && + grep -Fn --color=auto -e LO_IMPLEMENTATION_C -e LO_IMPLEMENTATION_STATIC "$filename"; then + err "$filename" "contains LO_IMPLEMENTATION_C and/or LO_IMPLEMENTATION_STATIC" + fi + fi + if [[ $filename == *.c ]]; then + if [[ $filename != libmisc/tests/test_obj.c ]] && + grep -Fn --color=auto L_IMPLEMENTATION_H "$filename"; then + err "$filename" "contains LO_IMPLEMENTATION_H" + fi fi done ;; diff --git a/build-aux/measurestack/app_plugins.py b/build-aux/measurestack/app_plugins.py index 6fc81ec..c5407be 100644 --- a/build-aux/measurestack/app_plugins.py +++ b/build-aux/measurestack/app_plugins.py @@ -60,7 +60,10 @@ class LibMiscPlugin: re_lo_iface = re.compile(r"^\s*#\s*define\s+(?P<name>\S+)_LO_IFACE") re_lo_func = re.compile(r"LO_FUNC *\([^,]*, *(?P<name>[^,) ]+) *[,)]") re_lo_implementation = re.compile( - r"^LO_IMPLEMENTATION_[HC]\s*\(\s*(?P<iface>[^, ]+)\s*,\s*(?P<impl_typ>[^,]+)\s*,\s*(?P<impl_name>[^, ]+)\s*[,)].*" + r"^LO_IMPLEMENTATION_(?P<vis>H|C|STATIC)\s*\(" + r"\s*(?P<iface>[^, ]+)\s*," + r"\s*(?P<impl_typ>[^,]+)\s*," + r"\s*(?P<impl_name>[^, ]+)\s\)" ) re_call_objcall = re.compile(r"LO_CALL\((?P<obj>[^,]+), (?P<meth>[^,)]+)[,)].*") diff --git a/cmd/sbc_harness/fs_harness_flash_bin.c b/cmd/sbc_harness/fs_harness_flash_bin.c index ea60447..8eebe9e 100644 --- a/cmd/sbc_harness/fs_harness_flash_bin.c +++ b/cmd/sbc_harness/fs_harness_flash_bin.c @@ -17,10 +17,8 @@ #define IMPLEMENTATION_FOR_FS_HARNESS_FLASH_BIN YES #include "fs_harness_flash_bin.h" -LO_IMPLEMENTATION_C(lib9p_srv_file, struct flash_file, flash_file, static); - -LO_IMPLEMENTATION_H(lib9p_srv_fio, struct flash_file, flash_file); -LO_IMPLEMENTATION_C(lib9p_srv_fio, struct flash_file, flash_file, static); +LO_IMPLEMENTATION_C(lib9p_srv_file, struct flash_file, flash_file); +LO_IMPLEMENTATION_STATIC(lib9p_srv_fio, struct flash_file, flash_file); #define DATA_START ((const char *)(XIP_NOALLOC_BASE)) #define DATA_SIZE PICO_FLASH_SIZE_BYTES @@ -135,10 +133,10 @@ static void ab_flash_write_sector(size_t pos, uint8_t *dat) { /* srv_file *******************************************************************/ -static void flash_file_free(struct flash_file *self) { +void flash_file_free(struct flash_file *self) { assert(self); } -static struct lib9p_qid flash_file_qid(struct flash_file *self) { +struct lib9p_qid flash_file_qid(struct flash_file *self) { assert(self); return (struct lib9p_qid){ @@ -148,7 +146,7 @@ static struct lib9p_qid flash_file_qid(struct flash_file *self) { }; } -static lib9p_srv_stat_or_error flash_file_stat(struct flash_file *self, struct lib9p_srv_ctx *ctx) { +lib9p_srv_stat_or_error flash_file_stat(struct flash_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); @@ -165,24 +163,23 @@ static lib9p_srv_stat_or_error flash_file_stat(struct flash_file *self, struct l .extension = lib9p_str(NULL), })); } -static error flash_file_wstat(struct flash_file *self, struct lib9p_srv_ctx *ctx, - struct lib9p_srv_stat) { +error flash_file_wstat(struct flash_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -static error flash_file_remove(struct flash_file *self, struct lib9p_srv_ctx *ctx) { +error flash_file_remove(struct flash_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -LIB9P_SRV_NOTDIR(struct flash_file, flash_file); +LIB9P_SRV_NOTDIR(, struct flash_file, flash_file); -static lib9p_srv_fio_or_error flash_file_fopen(struct flash_file *self, struct lib9p_srv_ctx *ctx, - bool rd, bool wr, bool trunc) { +lib9p_srv_fio_or_error flash_file_fopen(struct flash_file *self, struct lib9p_srv_ctx *ctx, + bool rd, bool wr, bool trunc) { assert(self); assert(ctx); @@ -206,6 +203,9 @@ static lib9p_srv_fio_or_error flash_file_fopen(struct flash_file *self, struct l /* srv_fio ********************************************************************/ +static struct lib9p_qid flash_file_ioqid(struct flash_file *self) { + return flash_file_qid(self); +} static uint32_t flash_file_iounit(struct flash_file *self) { assert(self); return FLASH_SECTOR_SIZE; diff --git a/cmd/sbc_harness/fs_harness_uptime_txt.c b/cmd/sbc_harness/fs_harness_uptime_txt.c index 021a8bd..4d35385 100644 --- a/cmd/sbc_harness/fs_harness_uptime_txt.c +++ b/cmd/sbc_harness/fs_harness_uptime_txt.c @@ -11,23 +11,21 @@ #include "fs_harness_uptime_txt.h" -LO_IMPLEMENTATION_C(lib9p_srv_file, struct uptime_file, uptime_file, static); +LO_IMPLEMENTATION_C(lib9p_srv_file, struct uptime_file, uptime_file); struct uptime_fio { struct uptime_file *parent; size_t buf_len; char buf[24]; /* len(str(UINT64_MAX)+"ns\n\0") */ }; - -LO_IMPLEMENTATION_H(lib9p_srv_fio, struct uptime_fio, uptime_fio); -LO_IMPLEMENTATION_C(lib9p_srv_fio, struct uptime_fio, uptime_fio, static); +LO_IMPLEMENTATION_STATIC(lib9p_srv_fio, struct uptime_fio, uptime_fio); /* srv_file *******************************************************************/ -static void uptime_file_free(struct uptime_file *self) { +void uptime_file_free(struct uptime_file *self) { assert(self); } -static struct lib9p_qid uptime_file_qid(struct uptime_file *self) { +struct lib9p_qid uptime_file_qid(struct uptime_file *self) { assert(self); return (struct lib9p_qid){ @@ -37,7 +35,7 @@ static struct lib9p_qid uptime_file_qid(struct uptime_file *self) { }; } -static lib9p_srv_stat_or_error uptime_file_stat(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { +lib9p_srv_stat_or_error uptime_file_stat(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); @@ -64,24 +62,23 @@ static lib9p_srv_stat_or_error uptime_file_stat(struct uptime_file *self, struct .extension = lib9p_str(NULL), })); } -static error uptime_file_wstat(struct uptime_file *self, struct lib9p_srv_ctx *ctx, - struct lib9p_srv_stat) { +error uptime_file_wstat(struct uptime_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -static error uptime_file_remove(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { +error uptime_file_remove(struct uptime_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -LIB9P_SRV_NOTDIR(struct uptime_file, uptime_file); +LIB9P_SRV_NOTDIR(, struct uptime_file, uptime_file); -static lib9p_srv_fio_or_error uptime_file_fopen(struct uptime_file *self, struct lib9p_srv_ctx *ctx, - bool LM_UNUSED(rd), bool LM_UNUSED(wr), bool LM_UNUSED(trunc)) { +lib9p_srv_fio_or_error uptime_file_fopen(struct uptime_file *self, struct lib9p_srv_ctx *ctx, + bool LM_UNUSED(rd), bool LM_UNUSED(wr), bool LM_UNUSED(trunc)) { assert(self); assert(ctx); @@ -104,7 +101,7 @@ static void uptime_fio_iofree(struct uptime_fio *self) { free(self); } -static struct lib9p_qid uptime_fio_qid(struct uptime_fio *self) { +static struct lib9p_qid uptime_fio_ioqid(struct uptime_fio *self) { assert(self); assert(self->parent); return uptime_file_qid(self->parent); diff --git a/lib9p/srv.c b/lib9p/srv.c index d1f5814..e938dcb 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -1107,7 +1107,7 @@ static void handle_Topen(struct srv_req *ctx, fidinfo->dir.io = dio_r.lib9p_srv_dio; fidinfo->dir.idx = 0; fidinfo->dir.off = 0; - qid = LO_CALL(fidinfo->dir.io, qid); + qid = LO_CALL(fidinfo->dir.io, ioqid); iounit = 0; break; case SRV_FILETYPE_FILE: @@ -1120,7 +1120,7 @@ static void handle_Topen(struct srv_req *ctx, goto topen_return; } fidinfo->file.io = fio_r.lib9p_srv_fio; - qid = LO_CALL(fidinfo->file.io, qid); + qid = LO_CALL(fidinfo->file.io, ioqid); iounit = LO_CALL(fidinfo->file.io, iounit); break; case SRV_FILETYPE_AUTH: diff --git a/lib9p/srv_include/lib9p/srv.h b/lib9p/srv_include/lib9p/srv.h index ce82e59..1114950 100644 --- a/lib9p/srv_include/lib9p/srv.h +++ b/lib9p/srv_include/lib9p/srv.h @@ -116,7 +116,7 @@ DECLARE_ERROR_OR(lib9p_srv_dirent); * FIXME: It would be nice if pread() could return more than 1 iovec. */ #define lib9p_srv_fio_LO_IFACE /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ \ - LO_FUNC(struct lib9p_qid , qid ) \ + LO_FUNC(struct lib9p_qid , ioqid ) \ LO_FUNC(void , iofree ) \ LO_FUNC(uint32_t , iounit ) \ LO_FUNC(iovec_or_error , pread , struct lib9p_srv_ctx *, \ @@ -135,7 +135,7 @@ typedef lo_interface lib9p_srv_fio lib9p_srv_fio; DECLARE_ERROR_OR(lib9p_srv_fio); #define lib9p_srv_dio_LO_IFACE /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ \ - LO_FUNC(struct lib9p_qid , qid ) \ + LO_FUNC(struct lib9p_qid , ioqid ) \ LO_FUNC(void , iofree ) \ /** \ * Return the idx-th dirent. idx will always be either 0 or \ @@ -203,15 +203,15 @@ DECLARE_ERROR_OR(lib9p_srv_file); LO_FUNC(lib9p_srv_dio_or_error , dopen , struct lib9p_srv_ctx *) LO_INTERFACE(lib9p_srv_file); /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ -#define LIB9P_SRV_NOTDIR(TYP, NAM) \ - static lib9p_srv_file_or_error NAM##_dwalk (TYP *, struct lib9p_srv_ctx *, struct lib9p_s) { assert_notreached("not a directory"); } \ - static lib9p_srv_file_or_error NAM##_dcreate(TYP *, struct lib9p_srv_ctx *, struct lib9p_s, \ +#define LIB9P_SRV_NOTDIR(QUALS, TYP, NAM) \ + QUALS lib9p_srv_file_or_error NAM##_dwalk (TYP *, struct lib9p_srv_ctx *, struct lib9p_s) { assert_notreached("not a directory"); } \ + QUALS lib9p_srv_file_or_error NAM##_dcreate(TYP *, struct lib9p_srv_ctx *, struct lib9p_s, \ struct lib9p_srv_userid *, struct lib9p_srv_userid *, lib9p_dm_t) { assert_notreached("not a directory"); } \ - static lib9p_srv_dio_or_error NAM##_dopen (TYP *, struct lib9p_srv_ctx *) { assert_notreached("not a directory"); } \ + QUALS lib9p_srv_dio_or_error NAM##_dopen (TYP *, struct lib9p_srv_ctx *) { assert_notreached("not a directory"); } \ LM_FORCE_SEMICOLON -#define LIB9P_SRV_NOTFILE(TYP, NAM) \ - static lib9p_srv_fio_or_error NAM##_fopen (TYP *, struct lib9p_srv_ctx *, bool, bool, bool) { assert_notreached("not a file"); } \ +#define LIB9P_SRV_NOTFILE(QUALS, TYP, NAM) \ + QUALS lib9p_srv_fio_or_error NAM##_fopen (TYP *, struct lib9p_srv_ctx *, bool, bool, bool) { assert_notreached("not a file"); } \ LM_FORCE_SEMICOLON /* main server entrypoints ****************************************************/ diff --git a/lib9p/tests/test_server/fs_flush.c b/lib9p/tests/test_server/fs_flush.c index 63a52af..41156ba 100644 --- a/lib9p/tests/test_server/fs_flush.c +++ b/lib9p/tests/test_server/fs_flush.c @@ -9,20 +9,19 @@ #define IMPLEMENTATION_FOR_LIB9P_SRV_H YES /* for ctx->flush_ch */ #include "fs_flush.h" -LO_IMPLEMENTATION_C(lib9p_srv_file, struct flush_file, flush_file, static); +LO_IMPLEMENTATION_C(lib9p_srv_file, struct flush_file, flush_file); struct flush_fio { struct flush_file *parent; }; -LO_IMPLEMENTATION_H(lib9p_srv_fio, struct flush_fio, flush_fio); -LO_IMPLEMENTATION_C(lib9p_srv_fio, struct flush_fio, flush_fio, static); +LO_IMPLEMENTATION_STATIC(lib9p_srv_fio, struct flush_fio, flush_fio); /* srv_file *******************************************************************/ -static void flush_file_free(struct flush_file *self) { +void flush_file_free(struct flush_file *self) { assert(self); } -static struct lib9p_qid flush_file_qid(struct flush_file *self) { +struct lib9p_qid flush_file_qid(struct flush_file *self) { assert(self); return (struct lib9p_qid){ .type = LIB9P_QT_FILE, @@ -31,7 +30,7 @@ static struct lib9p_qid flush_file_qid(struct flush_file *self) { }; } -static lib9p_srv_stat_or_error flush_file_stat(struct flush_file *self, struct lib9p_srv_ctx *ctx) { +lib9p_srv_stat_or_error flush_file_stat(struct flush_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); return ERROR_NEW_VAL(lib9p_srv_stat, ((struct lib9p_srv_stat){ @@ -47,20 +46,20 @@ static lib9p_srv_stat_or_error flush_file_stat(struct flush_file *self, struct l .extension = lib9p_str(NULL), })); } -static error flush_file_wstat(struct flush_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) { +error flush_file_wstat(struct flush_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "cannot wstat API file"); } -static error flush_file_remove(struct flush_file *self, struct lib9p_srv_ctx *ctx) { +error flush_file_remove(struct flush_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "cannot remove API file"); } -LIB9P_SRV_NOTDIR(struct flush_file, flush_file); +LIB9P_SRV_NOTDIR(, struct flush_file, flush_file); -static lib9p_srv_fio_or_error flush_file_fopen(struct flush_file *self, struct lib9p_srv_ctx *ctx, bool, bool, bool) { +lib9p_srv_fio_or_error flush_file_fopen(struct flush_file *self, struct lib9p_srv_ctx *ctx, bool, bool, bool) { assert(self); assert(ctx); @@ -77,7 +76,7 @@ static void flush_fio_iofree(struct flush_fio *self) { free(self); } -static struct lib9p_qid flush_fio_qid(struct flush_fio *self) { +static struct lib9p_qid flush_fio_ioqid(struct flush_fio *self) { assert(self); return flush_file_qid(self->parent); } diff --git a/lib9p/tests/test_server/fs_shutdown.c b/lib9p/tests/test_server/fs_shutdown.c index 079442e..1afbaf3 100644 --- a/lib9p/tests/test_server/fs_shutdown.c +++ b/lib9p/tests/test_server/fs_shutdown.c @@ -8,20 +8,19 @@ #include "fs_shutdown.h" -LO_IMPLEMENTATION_C(lib9p_srv_file, struct shutdown_file, shutdown_file, static); +LO_IMPLEMENTATION_C(lib9p_srv_file, struct shutdown_file, shutdown_file); struct shutdown_fio { struct shutdown_file *parent; }; -LO_IMPLEMENTATION_H(lib9p_srv_fio, struct shutdown_fio, shutdown_fio); -LO_IMPLEMENTATION_C(lib9p_srv_fio, struct shutdown_fio, shutdown_fio, static); +LO_IMPLEMENTATION_STATIC(lib9p_srv_fio, struct shutdown_fio, shutdown_fio); /* srv_file *******************************************************************/ -static void shutdown_file_free(struct shutdown_file *self) { +void shutdown_file_free(struct shutdown_file *self) { assert(self); } -static struct lib9p_qid shutdown_file_qid(struct shutdown_file *self) { +struct lib9p_qid shutdown_file_qid(struct shutdown_file *self) { assert(self); return (struct lib9p_qid){ .type = LIB9P_QT_FILE | LIB9P_QT_APPEND, @@ -30,7 +29,7 @@ static struct lib9p_qid shutdown_file_qid(struct shutdown_file *self) { }; } -static lib9p_srv_stat_or_error shutdown_file_stat(struct shutdown_file *self, struct lib9p_srv_ctx *ctx) { +lib9p_srv_stat_or_error shutdown_file_stat(struct shutdown_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); return ERROR_NEW_VAL(lib9p_srv_stat, ((struct lib9p_srv_stat){ @@ -46,20 +45,20 @@ static lib9p_srv_stat_or_error shutdown_file_stat(struct shutdown_file *self, st .extension = lib9p_str(NULL), })); } -static error shutdown_file_wstat(struct shutdown_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) { +error shutdown_file_wstat(struct shutdown_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "cannot wstat API file"); } -static error shutdown_file_remove(struct shutdown_file *self, struct lib9p_srv_ctx *ctx) { +error shutdown_file_remove(struct shutdown_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "cannot remove API file"); } -LIB9P_SRV_NOTDIR(struct shutdown_file, shutdown_file); +LIB9P_SRV_NOTDIR(, struct shutdown_file, shutdown_file); -static lib9p_srv_fio_or_error shutdown_file_fopen(struct shutdown_file *self, struct lib9p_srv_ctx *ctx, bool, bool, bool) { +lib9p_srv_fio_or_error shutdown_file_fopen(struct shutdown_file *self, struct lib9p_srv_ctx *ctx, bool, bool, bool) { assert(self); assert(ctx); @@ -76,7 +75,7 @@ static void shutdown_fio_iofree(struct shutdown_fio *self) { free(self); } -static struct lib9p_qid shutdown_fio_qid(struct shutdown_fio *self) { +static struct lib9p_qid shutdown_fio_ioqid(struct shutdown_fio *self) { assert(self); return shutdown_file_qid(self->parent); } diff --git a/lib9p/tests/test_server/fs_whoami.c b/lib9p/tests/test_server/fs_whoami.c index 3cc0683..a282cae 100644 --- a/lib9p/tests/test_server/fs_whoami.c +++ b/lib9p/tests/test_server/fs_whoami.c @@ -12,15 +12,14 @@ #include "fs_whoami.h" -LO_IMPLEMENTATION_C(lib9p_srv_file, struct whoami_file, whoami_file, static); +LO_IMPLEMENTATION_C(lib9p_srv_file, struct whoami_file, whoami_file); struct whoami_fio { struct whoami_file *parent; size_t buf_len; char *buf; }; -LO_IMPLEMENTATION_H(lib9p_srv_fio, struct whoami_fio, whoami_fio); -LO_IMPLEMENTATION_C(lib9p_srv_fio, struct whoami_fio, whoami_fio, static); +LO_IMPLEMENTATION_STATIC(lib9p_srv_fio, struct whoami_fio, whoami_fio); size_t whoami_len(struct lib9p_srv_ctx *ctx) { assert(ctx); @@ -41,10 +40,10 @@ size_t whoami_len(struct lib9p_srv_ctx *ctx) { /* srv_file *******************************************************************/ -static void whoami_file_free(struct whoami_file *self) { +void whoami_file_free(struct whoami_file *self) { assert(self); } -static struct lib9p_qid whoami_file_qid(struct whoami_file *self) { +struct lib9p_qid whoami_file_qid(struct whoami_file *self) { assert(self); return (struct lib9p_qid){ .type = LIB9P_QT_FILE, @@ -53,7 +52,7 @@ static struct lib9p_qid whoami_file_qid(struct whoami_file *self) { }; } -static lib9p_srv_stat_or_error whoami_file_stat(struct whoami_file *self, struct lib9p_srv_ctx *ctx) { +lib9p_srv_stat_or_error whoami_file_stat(struct whoami_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); @@ -70,20 +69,20 @@ static lib9p_srv_stat_or_error whoami_file_stat(struct whoami_file *self, struct .extension = lib9p_str(NULL), })); } -static error whoami_file_wstat(struct whoami_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) { +error whoami_file_wstat(struct whoami_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "cannot wstat API file"); } -static error whoami_file_remove(struct whoami_file *self, struct lib9p_srv_ctx *ctx) { +error whoami_file_remove(struct whoami_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "cannot remove API file"); } -LIB9P_SRV_NOTDIR(struct whoami_file, whoami_file); +LIB9P_SRV_NOTDIR(, struct whoami_file, whoami_file); -static lib9p_srv_fio_or_error whoami_file_fopen(struct whoami_file *self, struct lib9p_srv_ctx *ctx, bool, bool, bool) { +lib9p_srv_fio_or_error whoami_file_fopen(struct whoami_file *self, struct lib9p_srv_ctx *ctx, bool, bool, bool) { assert(self); assert(ctx); @@ -104,7 +103,7 @@ static void whoami_fio_iofree(struct whoami_fio *self) { free(self); } -static struct lib9p_qid whoami_fio_qid(struct whoami_fio *self) { +static struct lib9p_qid whoami_fio_ioqid(struct whoami_fio *self) { assert(self); assert(self->parent); return whoami_file_qid(self->parent); diff --git a/lib9p/tests/test_server/main.c b/lib9p/tests/test_server/main.c index e28d19e..2519372 100644 --- a/lib9p/tests/test_server/main.c +++ b/lib9p/tests/test_server/main.c @@ -132,8 +132,7 @@ static COROUTINE init_cr(void *) { } struct tstlog_stdout {}; -LO_IMPLEMENTATION_H(fmt_dest, struct tstlog_stdout, tstlog_stdout); -LO_IMPLEMENTATION_C(fmt_dest, struct tstlog_stdout, tstlog_stdout, static); +LO_IMPLEMENTATION_STATIC(fmt_dest, struct tstlog_stdout, tstlog_stdout); static size_t tstlog_bytes = 0; diff --git a/lib9p_util/static.c b/lib9p_util/static.c index 6861869..d8b8ffc 100644 --- a/lib9p_util/static.c +++ b/lib9p_util/static.c @@ -9,21 +9,18 @@ #include <util9p/static.h> -LO_IMPLEMENTATION_C(lib9p_srv_file, struct util9p_static_dir, util9p_static_dir, static); -LO_IMPLEMENTATION_C(lib9p_srv_file, struct util9p_static_file, util9p_static_file, static); +LO_IMPLEMENTATION_C(lib9p_srv_file, struct util9p_static_dir, util9p_static_dir); +LO_IMPLEMENTATION_C(lib9p_srv_file, struct util9p_static_file, util9p_static_file); -LO_IMPLEMENTATION_H(lib9p_srv_dio, struct util9p_static_dir, util9p_static_dir); -LO_IMPLEMENTATION_C(lib9p_srv_dio, struct util9p_static_dir, util9p_static_dir, static); - -LO_IMPLEMENTATION_H(lib9p_srv_fio, struct util9p_static_file, util9p_static_file); -LO_IMPLEMENTATION_C(lib9p_srv_fio, struct util9p_static_file, util9p_static_file, static); +LO_IMPLEMENTATION_STATIC(lib9p_srv_dio, struct util9p_static_dir, util9p_static_dio); +LO_IMPLEMENTATION_STATIC(lib9p_srv_fio, struct util9p_static_file, util9p_static_fio); /* dir ************************************************************************/ -static void util9p_static_dir_free(struct util9p_static_dir *self) { +void util9p_static_dir_free(struct util9p_static_dir *self) { assert(self); } -static struct lib9p_qid util9p_static_dir_qid(struct util9p_static_dir *self) { +struct lib9p_qid util9p_static_dir_qid(struct util9p_static_dir *self) { assert(self); return (struct lib9p_qid){ @@ -33,7 +30,7 @@ static struct lib9p_qid util9p_static_dir_qid(struct util9p_static_dir *self) { }; } -static lib9p_srv_stat_or_error util9p_static_dir_stat(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { +lib9p_srv_stat_or_error util9p_static_dir_stat(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); @@ -50,22 +47,22 @@ static lib9p_srv_stat_or_error util9p_static_dir_stat(struct util9p_static_dir * .extension = lib9p_str(NULL), })); } -static error util9p_static_dir_wstat(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, +error util9p_static_dir_wstat(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -static error util9p_static_dir_remove(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { +error util9p_static_dir_remove(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -static lib9p_srv_file_or_error util9p_static_dir_dwalk(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, - struct lib9p_s childname) { +lib9p_srv_file_or_error util9p_static_dir_dwalk(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, + struct lib9p_s childname) { assert(self); assert(ctx); @@ -81,7 +78,7 @@ static lib9p_srv_file_or_error util9p_static_dir_dwalk(struct util9p_static_dir return ERROR_NEW_ERR(lib9p_srv_file, error_new(E_POSIX_ENOENT, "no such file or directory")); } -static lib9p_srv_file_or_error util9p_static_dir_dcreate(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, +lib9p_srv_file_or_error util9p_static_dir_dcreate(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, struct lib9p_s LM_UNUSED(childname), struct lib9p_srv_userid *LM_UNUSED(user), struct lib9p_srv_userid *LM_UNUSED(group), @@ -92,17 +89,21 @@ static lib9p_srv_file_or_error util9p_static_dir_dcreate(struct util9p_static_di return ERROR_NEW_ERR(lib9p_srv_file, error_new(E_POSIX_EROFS, "read-only part of filesystem")); } -LIB9P_SRV_NOTFILE(struct util9p_static_dir, util9p_static_dir); +LIB9P_SRV_NOTFILE(, struct util9p_static_dir, util9p_static_dir); -static lib9p_srv_dio_or_error util9p_static_dir_dopen(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { +lib9p_srv_dio_or_error util9p_static_dir_dopen(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); return ERROR_NEW_VAL(lib9p_srv_dio, LO_BOX(lib9p_srv_dio, self)); } -static void util9p_static_dir_iofree(struct util9p_static_dir *self) { + +static struct lib9p_qid util9p_static_dio_ioqid(struct util9p_static_dir *self) { + return util9p_static_dir_qid(self); +} +static void util9p_static_dio_iofree(struct util9p_static_dir *self) { assert(self); } -static lib9p_srv_dirent_or_error util9p_static_dir_dread(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, size_t idx) { +static lib9p_srv_dirent_or_error util9p_static_dio_dread(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, size_t idx) { assert(self); assert(ctx); @@ -123,10 +124,10 @@ static lib9p_srv_dirent_or_error util9p_static_dir_dread(struct util9p_static_di /* file ***********************************************************************/ -static void util9p_static_file_free(struct util9p_static_file *self) { +void util9p_static_file_free(struct util9p_static_file *self) { assert(self); } -static struct lib9p_qid util9p_static_file_qid(struct util9p_static_file *self) { +struct lib9p_qid util9p_static_file_qid(struct util9p_static_file *self) { assert(self); return (struct lib9p_qid){ @@ -148,7 +149,7 @@ static inline size_t util9p_static_file_size(struct util9p_static_file *file) { } -static lib9p_srv_stat_or_error util9p_static_file_stat(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx) { +lib9p_srv_stat_or_error util9p_static_file_stat(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); @@ -165,23 +166,23 @@ static lib9p_srv_stat_or_error util9p_static_file_stat(struct util9p_static_file .extension = lib9p_str(NULL), })); } -static error util9p_static_file_wstat(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, +error util9p_static_file_wstat(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -static error util9p_static_file_remove(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx) { +error util9p_static_file_remove(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx) { assert(self); assert(ctx); return error_new(E_POSIX_EROFS, "read-only part of filesystem"); } -LIB9P_SRV_NOTDIR(struct util9p_static_file, util9p_static_file); +LIB9P_SRV_NOTDIR(, struct util9p_static_file, util9p_static_file); -static lib9p_srv_fio_or_error util9p_static_file_fopen(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, +lib9p_srv_fio_or_error util9p_static_file_fopen(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, bool rd, bool wr, bool trunc) { assert(self); assert(ctx); @@ -190,15 +191,19 @@ static lib9p_srv_fio_or_error util9p_static_file_fopen(struct util9p_static_file assert(!trunc); return ERROR_NEW_VAL(lib9p_srv_fio, LO_BOX(lib9p_srv_fio, self)); } -static void util9p_static_file_iofree(struct util9p_static_file *self) { + +static struct lib9p_qid util9p_static_fio_ioqid(struct util9p_static_file *self) { + return util9p_static_file_qid(self); +} +static void util9p_static_fio_iofree(struct util9p_static_file *self) { assert(self); } -static uint32_t util9p_static_file_iounit(struct util9p_static_file *self) { +static uint32_t util9p_static_fio_iounit(struct util9p_static_file *self) { assert(self); return 0; } -static iovec_or_error util9p_static_file_pread(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, - uint32_t byte_count, uint64_t byte_offset) { +static iovec_or_error util9p_static_fio_pread(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, + uint32_t byte_count, uint64_t byte_offset) { assert(self); assert(ctx); @@ -216,10 +221,10 @@ static iovec_or_error util9p_static_file_pread(struct util9p_static_file *self, .iov_len = end_off-beg_off, })); } -static uint32_t_or_error util9p_static_file_pwrite(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, - void *LM_UNUSED(buf), - uint32_t LM_UNUSED(byte_count), - uint64_t LM_UNUSED(byte_offset)) { +static uint32_t_or_error util9p_static_fio_pwrite(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx, + void *LM_UNUSED(buf), + uint32_t LM_UNUSED(byte_count), + uint64_t LM_UNUSED(byte_offset)) { assert(self); assert(ctx); diff --git a/libdhcp/tests/test_client.c b/libdhcp/tests/test_client.c index cf76653..6446cef 100644 --- a/libdhcp/tests/test_client.c +++ b/libdhcp/tests/test_client.c @@ -18,10 +18,8 @@ struct test_udp { }; -LO_IMPLEMENTATION_H(io_closer, struct test_udp, test_udp); -LO_IMPLEMENTATION_C(io_closer, struct test_udp, test_udp, static); -LO_IMPLEMENTATION_H(net_packet_conn, struct test_udp, test_udp); -LO_IMPLEMENTATION_C(net_packet_conn, struct test_udp, test_udp, static); +LO_IMPLEMENTATION_STATIC(io_closer, struct test_udp, test_udp); +LO_IMPLEMENTATION_STATIC(net_packet_conn, struct test_udp, test_udp); static error test_udp_sendto(struct test_udp *LM_UNUSED(self), void *LM_UNUSED(buf), size_t LM_UNUSED(len), struct net_ip4_addr LM_UNUSED(node), uint16_t LM_UNUSED(port)) { static unsigned cnt = 0; @@ -66,8 +64,7 @@ struct test_iface { struct test_udp conn; }; -LO_IMPLEMENTATION_H(net_iface, struct test_iface, test); -LO_IMPLEMENTATION_C(net_iface, struct test_iface, test, static); +LO_IMPLEMENTATION_STATIC(net_iface, struct test_iface, test); static struct net_eth_addr test_hwaddr(struct test_iface *LM_UNUSED(self)) { struct net_eth_addr ret = {{1, 2, 3, 4, 5, 6}}; diff --git a/libhw_cr/host_alarmclock.c b/libhw_cr/host_alarmclock.c index 325f7e0..c1c5449 100644 --- a/libhw_cr/host_alarmclock.c +++ b/libhw_cr/host_alarmclock.c @@ -22,9 +22,9 @@ #include "host_util.h" /* for host_sigrt_alloc(), ns_to_host_ns_time() */ -LO_IMPLEMENTATION_C(alarmclock, struct hostclock, hostclock, static); +LO_IMPLEMENTATION_C(alarmclock, struct hostclock, hostclock); -static uint64_t hostclock_get_time_ns(struct hostclock *alarmclock) { +uint64_t hostclock_get_time_ns(struct hostclock *alarmclock) { assert(alarmclock); struct timespec ts; @@ -59,11 +59,11 @@ static void hostclock_handle_sig_alarm(int LM_UNUSED(sig), siginfo_t *info, void } } -static bool hostclock_add_trigger(struct hostclock *alarmclock, - struct alarmclock_trigger *trigger, - uint64_t fire_at_ns, - void (*cb)(void *), - void *cb_arg) { +bool hostclock_add_trigger(struct hostclock *alarmclock, + struct alarmclock_trigger *trigger, + uint64_t fire_at_ns, + void (*cb)(void *), + void *cb_arg) { assert(alarmclock); assert(trigger); assert(fire_at_ns); @@ -114,8 +114,8 @@ static bool hostclock_add_trigger(struct hostclock *alarmclock, return false; } -static void hostclock_del_trigger(struct hostclock *alarmclock, - struct alarmclock_trigger *trigger) { + void hostclock_del_trigger(struct hostclock *alarmclock, + struct alarmclock_trigger *trigger) { assert(alarmclock); assert(trigger); diff --git a/libhw_cr/host_include/libhw/host_net.h b/libhw_cr/host_include/libhw/host_net.h index a16ed01..6ff2779 100644 --- a/libhw_cr/host_include/libhw/host_net.h +++ b/libhw_cr/host_include/libhw/host_net.h @@ -13,13 +13,16 @@ #include <libhw/generic/net.h> +/* TCP connection *************************************************************/ + struct _hostnet_tcp_conn { BEGIN_PRIVATE(LIBHW_HOST_NET_H); int fd; uint64_t read_deadline_ns; END_PRIVATE(LIBHW_HOST_NET_H); }; -LO_IMPLEMENTATION_H(net_stream_conn, struct _hostnet_tcp_conn, hostnet_tcp); + +/* TCP listener ***************************************************************/ struct hostnet_tcp_listener { BEGIN_PRIVATE(LIBHW_HOST_NET_H); @@ -27,16 +30,20 @@ struct hostnet_tcp_listener { struct _hostnet_tcp_conn active_conn; END_PRIVATE(LIBHW_HOST_NET_H); }; +LO_IMPLEMENTATION_H(io_closer, struct hostnet_tcp_listener, hostnet_tcplist); LO_IMPLEMENTATION_H(net_stream_listener, struct hostnet_tcp_listener, hostnet_tcplist); void hostnet_tcp_listener_init(struct hostnet_tcp_listener *self, uint16_t port); +/* UDP connection *************************************************************/ + struct hostnet_udp_conn { BEGIN_PRIVATE(LIBHW_HOST_NET_H); int fd; uint64_t read_deadline_ns; END_PRIVATE(LIBHW_HOST_NET_H); }; +LO_IMPLEMENTATION_H(io_closer, struct hostnet_udp_conn, hostnet_udp); LO_IMPLEMENTATION_H(net_packet_conn, struct hostnet_udp_conn, hostnet_udp); void hostnet_udp_conn_init(struct hostnet_udp_conn *self, uint16_t port); diff --git a/libhw_cr/host_net.c b/libhw_cr/host_net.c index 39bfd46..fe420c4 100644 --- a/libhw_cr/host_net.c +++ b/libhw_cr/host_net.c @@ -33,18 +33,18 @@ #include "host_util.h" /* for host_sigrt_alloc(), ns_to_host_us_time() */ -LO_IMPLEMENTATION_C(io_closer, struct hostnet_tcp_listener, hostnet_tcplist, static); -LO_IMPLEMENTATION_C(net_stream_listener, struct hostnet_tcp_listener, hostnet_tcplist, static); +LO_IMPLEMENTATION_C(io_closer, struct hostnet_tcp_listener, hostnet_tcplist); +LO_IMPLEMENTATION_C(net_stream_listener, struct hostnet_tcp_listener, hostnet_tcplist); -LO_IMPLEMENTATION_C(io_reader, struct _hostnet_tcp_conn, hostnet_tcp, static); -LO_IMPLEMENTATION_C(io_writer, struct _hostnet_tcp_conn, hostnet_tcp, static); -LO_IMPLEMENTATION_C(io_readwriter, struct _hostnet_tcp_conn, hostnet_tcp, static); -LO_IMPLEMENTATION_C(io_closer, struct _hostnet_tcp_conn, hostnet_tcp, static); -LO_IMPLEMENTATION_C(io_bidi_closer, struct _hostnet_tcp_conn, hostnet_tcp, static); -LO_IMPLEMENTATION_C(net_stream_conn, struct _hostnet_tcp_conn, hostnet_tcp, static); +LO_IMPLEMENTATION_STATIC(io_reader, struct _hostnet_tcp_conn, hostnet_tcp); +LO_IMPLEMENTATION_STATIC(io_writer, struct _hostnet_tcp_conn, hostnet_tcp); +LO_IMPLEMENTATION_STATIC(io_readwriter, struct _hostnet_tcp_conn, hostnet_tcp); +LO_IMPLEMENTATION_STATIC(io_closer, struct _hostnet_tcp_conn, hostnet_tcp); +LO_IMPLEMENTATION_STATIC(io_bidi_closer, struct _hostnet_tcp_conn, hostnet_tcp); +LO_IMPLEMENTATION_STATIC(net_stream_conn, struct _hostnet_tcp_conn, hostnet_tcp); -LO_IMPLEMENTATION_C(io_closer, struct hostnet_udp_conn, hostnet_udp, static); -LO_IMPLEMENTATION_C(net_packet_conn, struct hostnet_udp_conn, hostnet_udp, static); +LO_IMPLEMENTATION_C(io_closer, struct hostnet_udp_conn, hostnet_udp); +LO_IMPLEMENTATION_C(net_packet_conn, struct hostnet_udp_conn, hostnet_udp); /* common *********************************************************************/ @@ -172,7 +172,7 @@ static void *hostnet_pthread_accept(void *_args) { return NULL; } -static net_stream_conn_or_error hostnet_tcplist_accept(struct hostnet_tcp_listener *listener) { +net_stream_conn_or_error hostnet_tcplist_accept(struct hostnet_tcp_listener *listener) { assert(listener); int ret_connfd; @@ -197,7 +197,7 @@ static net_stream_conn_or_error hostnet_tcplist_accept(struct hostnet_tcp_listen /* TCP listener close() *******************************************************/ -static error hostnet_tcplist_close(struct hostnet_tcp_listener *listener) { +error hostnet_tcplist_close(struct hostnet_tcp_listener *listener) { assert(listener); if (shutdown(listener->fd, SHUT_RDWR)) @@ -460,7 +460,7 @@ static void *hostnet_pthread_sendto(void *_args) { return NULL; } -static error hostnet_udp_sendto(struct hostnet_udp_conn *conn, void *buf, size_t count, +error hostnet_udp_sendto(struct hostnet_udp_conn *conn, void *buf, size_t count, struct net_ip4_addr node, uint16_t port) { assert(conn); @@ -489,8 +489,8 @@ static error hostnet_udp_sendto(struct hostnet_udp_conn *conn, void *buf, size_t /* UDP recvfrom() *************************************************************/ -static void hostnet_udp_set_recv_deadline(struct hostnet_udp_conn *conn, - uint64_t ts_ns) { +void hostnet_udp_set_recv_deadline(struct hostnet_udp_conn *conn, + uint64_t ts_ns) { assert(conn); conn->read_deadline_ns = ts_ns; @@ -555,8 +555,8 @@ static void *hostnet_pthread_recvfrom(void *_args) { return NULL; } -static size_t_or_error hostnet_udp_recvfrom(struct hostnet_udp_conn *conn, void *buf, size_t count, - struct net_ip4_addr *ret_node, uint16_t *ret_port) { +size_t_or_error hostnet_udp_recvfrom(struct hostnet_udp_conn *conn, void *buf, size_t count, + struct net_ip4_addr *ret_node, uint16_t *ret_port) { assert(conn); size_t ret_size; @@ -593,7 +593,7 @@ static size_t_or_error hostnet_udp_recvfrom(struct hostnet_udp_conn *conn, void /* UDP close() ****************************************************************/ -static error hostnet_udp_close(struct hostnet_udp_conn *conn) { +error hostnet_udp_close(struct hostnet_udp_conn *conn) { assert(conn); if (close(conn->fd)) diff --git a/libhw_cr/rp2040_hwspi.c b/libhw_cr/rp2040_hwspi.c index d717a79..f4ad956 100644 --- a/libhw_cr/rp2040_hwspi.c +++ b/libhw_cr/rp2040_hwspi.c @@ -28,8 +28,8 @@ #error config.h must define CONFIG_RP2040_SPI_DEBUG (bool) #endif -LO_IMPLEMENTATION_C(io_duplex_readwriter, struct rp2040_hwspi, rp2040_hwspi, static); -LO_IMPLEMENTATION_C(spi, struct rp2040_hwspi, rp2040_hwspi, static); +LO_IMPLEMENTATION_C(io_duplex_readwriter, struct rp2040_hwspi, rp2040_hwspi); +LO_IMPLEMENTATION_C(spi, struct rp2040_hwspi, rp2040_hwspi); static void rp2040_hwspi_intrhandler(void *_self, enum dmairq LM_UNUSED(irq), uint LM_UNUSED(channel)) { struct rp2040_hwspi *self = _self; @@ -136,7 +136,7 @@ void _rp2040_hwspi_init(struct rp2040_hwspi *self, dmairq_set_and_enable_exclusive_handler(DMAIRQ_0, self->dma_rx_data, rp2040_hwspi_intrhandler, self); } -static size_t_and_error rp2040_hwspi_readwritev(struct rp2040_hwspi *self, const struct duplex_iovec *iov, int iovcnt) { +size_t_and_error rp2040_hwspi_readwritev(struct rp2040_hwspi *self, const struct duplex_iovec *iov, int iovcnt) { assert(self); assert(self->inst); assert(iov); diff --git a/libhw_cr/rp2040_hwtimer.c b/libhw_cr/rp2040_hwtimer.c index d9f0a24..3454383 100644 --- a/libhw_cr/rp2040_hwtimer.c +++ b/libhw_cr/rp2040_hwtimer.c @@ -27,8 +27,7 @@ struct rp2040_hwtimer { bool initialized; struct alarmclock_trigger *queue; }; -LO_IMPLEMENTATION_H(alarmclock, struct rp2040_hwtimer, rp2040_hwtimer); -LO_IMPLEMENTATION_C(alarmclock, struct rp2040_hwtimer, rp2040_hwtimer, static); +LO_IMPLEMENTATION_STATIC(alarmclock, struct rp2040_hwtimer, rp2040_hwtimer); /* Globals ********************************************************************/ diff --git a/libhw_cr/rp2040_include/libhw/w5500.h b/libhw_cr/rp2040_include/libhw/w5500.h index 8dda1a1..43c58a3 100644 --- a/libhw_cr/rp2040_include/libhw/w5500.h +++ b/libhw_cr/rp2040_include/libhw/w5500.h @@ -41,19 +41,6 @@ struct _w5500_socket { END_PRIVATE(LIBHW_W5500_H); }; -LO_IMPLEMENTATION_H(io_closer, struct _w5500_socket, w5500_tcplist); -LO_IMPLEMENTATION_H(net_stream_listener, struct _w5500_socket, w5500_tcplist); - -LO_IMPLEMENTATION_H(io_reader, struct _w5500_socket, w5500_tcp); -LO_IMPLEMENTATION_H(io_writer, struct _w5500_socket, w5500_tcp); -LO_IMPLEMENTATION_H(io_readwriter, struct _w5500_socket, w5500_tcp); -LO_IMPLEMENTATION_H(io_closer, struct _w5500_socket, w5500_tcp); -LO_IMPLEMENTATION_H(io_bidi_closer, struct _w5500_socket, w5500_tcp); -LO_IMPLEMENTATION_H(net_stream_conn, struct _w5500_socket, w5500_tcp); - -LO_IMPLEMENTATION_H(io_closer, struct _w5500_socket, w5500_udp); -LO_IMPLEMENTATION_H(net_packet_conn, struct _w5500_socket, w5500_udp); - struct w5500 { BEGIN_PRIVATE(LIBHW_W5500_H); /* const-after-init */ diff --git a/libhw_cr/w5500.c b/libhw_cr/w5500.c index 594b391..c04cb14 100644 --- a/libhw_cr/w5500.c +++ b/libhw_cr/w5500.c @@ -127,20 +127,20 @@ static const char *w5500_state_str(uint8_t state) { /* libmisc/obj.h **************************************************************/ -LO_IMPLEMENTATION_C(io_closer, struct _w5500_socket, w5500_tcplist, static); -LO_IMPLEMENTATION_C(net_stream_listener, struct _w5500_socket, w5500_tcplist, static); +LO_IMPLEMENTATION_STATIC(io_closer, struct _w5500_socket, w5500_tcplist); +LO_IMPLEMENTATION_STATIC(net_stream_listener, struct _w5500_socket, w5500_tcplist); -LO_IMPLEMENTATION_C(io_reader, struct _w5500_socket, w5500_tcp, static); -LO_IMPLEMENTATION_C(io_writer, struct _w5500_socket, w5500_tcp, static); -LO_IMPLEMENTATION_C(io_readwriter, struct _w5500_socket, w5500_tcp, static); -LO_IMPLEMENTATION_C(io_closer, struct _w5500_socket, w5500_tcp, static); -LO_IMPLEMENTATION_C(io_bidi_closer, struct _w5500_socket, w5500_tcp, static); -LO_IMPLEMENTATION_C(net_stream_conn, struct _w5500_socket, w5500_tcp, static); +LO_IMPLEMENTATION_STATIC(io_reader, struct _w5500_socket, w5500_tcp); +LO_IMPLEMENTATION_STATIC(io_writer, struct _w5500_socket, w5500_tcp); +LO_IMPLEMENTATION_STATIC(io_readwriter, struct _w5500_socket, w5500_tcp); +LO_IMPLEMENTATION_STATIC(io_closer, struct _w5500_socket, w5500_tcp); +LO_IMPLEMENTATION_STATIC(io_bidi_closer, struct _w5500_socket, w5500_tcp); +LO_IMPLEMENTATION_STATIC(net_stream_conn, struct _w5500_socket, w5500_tcp); -LO_IMPLEMENTATION_C(io_closer, struct _w5500_socket, w5500_udp, static); -LO_IMPLEMENTATION_C(net_packet_conn, struct _w5500_socket, w5500_udp, static); +LO_IMPLEMENTATION_STATIC(io_closer, struct _w5500_socket, w5500_udp); +LO_IMPLEMENTATION_STATIC(net_packet_conn, struct _w5500_socket, w5500_udp); -LO_IMPLEMENTATION_C(net_iface, struct w5500, w5500_if, static); +LO_IMPLEMENTATION_C(net_iface, struct w5500, w5500_if); /* mid-level utilities ********************************************************/ @@ -409,7 +409,7 @@ void w5500_soft_reset(struct w5500 *chip) { cr_mutex_unlock(&chip->mu); } -static struct net_eth_addr w5500_if_hwaddr(struct w5500 *chip) { +struct net_eth_addr w5500_if_hwaddr(struct w5500 *chip) { assert(chip); return chip->hwaddr; @@ -427,7 +427,7 @@ static void _w5500_if_up(struct w5500 *chip, struct net_iface_config cfg) { cr_mutex_unlock(&chip->mu); } -static void w5500_if_ifup(struct w5500 *chip, struct net_iface_config cfg) { +void w5500_if_ifup(struct w5500 *chip, struct net_iface_config cfg) { log_debugln("if_up()"); log_debugln(":: addr = ", (net_ip4_addr, cfg.addr)); log_debugln(":: gateway_addr = ", (net_ip4_addr, cfg.gateway_addr)); @@ -435,12 +435,12 @@ static void w5500_if_ifup(struct w5500 *chip, struct net_iface_config cfg) { _w5500_if_up(chip, cfg); } -static void w5500_if_ifdown(struct w5500 *chip) { +void w5500_if_ifdown(struct w5500 *chip) { log_debugln("if_down()"); _w5500_if_up(chip, (struct net_iface_config){}); } -static lo_interface net_stream_listener w5500_if_tcp_listen(struct w5500 *chip, uint16_t local_port) { +lo_interface net_stream_listener w5500_if_tcp_listen(struct w5500 *chip, uint16_t local_port) { assert(chip); struct _w5500_socket *sock = w5500_alloc_socket(chip); @@ -462,7 +462,7 @@ static lo_interface net_stream_listener w5500_if_tcp_listen(struct w5500 *chip, return LO_BOX(net_stream_listener, sock); } -static net_stream_conn_or_error w5500_if_tcp_dial(struct w5500 *chip, +net_stream_conn_or_error w5500_if_tcp_dial(struct w5500 *chip, struct net_ip4_addr node, uint16_t port) { assert(chip); assert(memcmp(node.octets, net_ip4_addr_zero.octets, 4)); @@ -516,7 +516,7 @@ static net_stream_conn_or_error w5500_if_tcp_dial(struct w5500 *chip, } } -static lo_interface net_packet_conn w5500_if_udp_conn(struct w5500 *chip, uint16_t local_port) { +lo_interface net_packet_conn w5500_if_udp_conn(struct w5500 *chip, uint16_t local_port) { assert(chip); struct _w5500_socket *socket = w5500_alloc_socket(chip); @@ -548,7 +548,7 @@ static lo_interface net_packet_conn w5500_if_udp_conn(struct w5500 *chip, uint16 return LO_BOX(net_packet_conn, socket); } -static bool w5500_if_arp_ping(struct w5500 *chip, struct net_ip4_addr addr) { +bool w5500_if_arp_ping(struct w5500 *chip, struct net_ip4_addr addr) { /* FIXME: This arp_ping implementation is really bad (and * assumes that a UDP socket is open, which is "safe" because * I only use it from inside of a DHCP client). */ diff --git a/libmisc/fmt.c b/libmisc/fmt.c index 7c18ef5..175ad60 100644 --- a/libmisc/fmt.c +++ b/libmisc/fmt.c @@ -253,14 +253,14 @@ declare(16, 64); /* fmt_buf ********************************************************************/ -LO_IMPLEMENTATION_C(fmt_dest, struct fmt_buf, fmt_buf, static); +LO_IMPLEMENTATION_C(fmt_dest, struct fmt_buf, fmt_buf); -static void fmt_buf_putb(struct fmt_buf *buf, uint8_t b) { +void fmt_buf_putb(struct fmt_buf *buf, uint8_t b) { if (buf->len < buf->cap) ((uint8_t *)(buf->dat))[buf->len] = b; buf->len++; } -static size_t fmt_buf_tell(struct fmt_buf *buf) { +size_t fmt_buf_tell(struct fmt_buf *buf) { return buf->len; } diff --git a/libmisc/include/libmisc/obj.h b/libmisc/include/libmisc/obj.h index 3467d5b..c00e512 100644 --- a/libmisc/include/libmisc/obj.h +++ b/libmisc/include/libmisc/obj.h @@ -119,57 +119,62 @@ (_ARG_obj).vtable->_ARG_meth((_ARG_obj).self __VA_OPT__(,) __VA_ARGS__) /** - * Use `LO_IMPLEMENTATION_H(iface_name, impl_type, impl_name)` in a .h - * file to declare that `{impl_type}` implements the `{iface_name}` - * interface with functions named `{impl_name}_{method_name}`. + * `LO_IMPLEMENTATION_{H,C,STATIC}` declare that `{impl_type}` + * implements the `{iface_name}` interface with functions named + * `{impl_name}_{method_name}`. * - * This will also define a `lo_box_{impl_name}_as_{iface_name}(obj)` - * const-expr macro. + * Either use _H and _C in the .h file and .c file respectively, or + * use _STATIC in just a .c file. * - * You must also call the LO_IMPLEMENTATION_C in a single .c file. + * These define: + * - The vtable symbol + * - The prototypes for the `{impl_name}_{method_name}` method + * functions. + * - A `lo_box_{impl_name}_as_{iface_name}(obj)` const-expr macro. */ -#define LO_IMPLEMENTATION_H(_ARG_iface_name, _ARG_impl_type, _ARG_impl_name) \ - /* Vtable. */ \ - 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), \ - .vtable = &_lo_##_ARG_impl_name##_##_ARG_iface_name##_vtable, \ - } \ - )); \ +#define LO_IMPLEMENTATION_H( iface_name, impl_type, impl_name) _LO_IMPL_H(extern, iface_name, impl_type, impl_name) +#define LO_IMPLEMENTATION_C( iface_name, impl_type, impl_name) _LO_IMPL_C(extern, iface_name, impl_type, impl_name) +#define LO_IMPLEMENTATION_STATIC(iface_name, impl_type, impl_name) _LO_IMPL_H(static, iface_name, impl_type, impl_name); \ + _LO_IMPL_C(static, iface_name, impl_type, impl_name) + +#define _LO_IMPL_H(_ARG_visibility, _ARG_iface_name, _ARG_impl_type, _ARG_impl_name) \ + /* Vtable. */ \ + _LO_h_vis_vtable_##_ARG_visibility const struct _lo_##_ARG_iface_name##_vtable \ + _lo_##_ARG_impl_name##_##_ARG_iface_name##_vtable; \ + /* Method prototypes. */ \ + LM_FOREACH_TUPLE(_ARG_iface_name##_LO_IFACE, \ + _LO_IMPL_PROTO, _LO_h_vis_fn_##_ARG_visibility, _ARG_impl_type, _ARG_impl_name) \ + /* 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), \ + .vtable = &_lo_##_ARG_impl_name##_##_ARG_iface_name##_vtable, \ + } \ + )); \ LM_FORCE_SEMICOLON +#define _LO_h_vis_vtable_extern extern +#define _LO_h_vis_vtable_static static +#define _LO_h_vis_fn_extern +#define _LO_h_vis_fn_static static + +#define _LO_IMPL_PROTO( _ARG_quals, _ARG_impl_type, _ARG_impl_name, _tuple_typ, ...) _LO_IMPL_PROTO_##_tuple_typ(_ARG_quals, _ARG_impl_type, _ARG_impl_name, __VA_ARGS__) +#define _LO_IMPL_PROTO_lo_nest(_ARG_quals, _ARG_impl_type, _ARG_impl_name, _ARG_child_iface_name) /* empty */ +#define _LO_IMPL_PROTO_lo_func(_ARG_quals, _ARG_impl_type, _ARG_impl_name, _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_C(_ARG_visibility, _ARG_iface_name, _ARG_impl_type, _ARG_impl_name) \ + /* Vtable. */ \ + _LO_c_vis_vtable_##_ARG_visibility 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) \ + }; \ + LM_FORCE_SEMICOLON +#define _LO_c_vis_vtable_extern +#define _LO_c_vis_vtable_static [[maybe_unused]] static -/** - * Use `LO_IMPLEMENTATION_C(iface_name, impl_type, impl_name[, static])` in a .c - * file to declare that `{impl_type}` implements the `{iface_name}` interface - * with functions named `{impl_name}_{method_name}`. - * - * You must also call the LO_IMPLEMENTATION_H in the corresponding .h file. - * - * If `iface_name` contains a nested interface, then the - * implementation of the nested interfaces must be declared with - * `LO_IMPLEMENTATION_C` first. - */ -#define LO_IMPLEMENTATION_C(_ARG_iface_name, _ARG_impl_type, _ARG_impl_name, ...) \ - /* Method prototypes. */ \ - LM_FOREACH_TUPLE(_ARG_iface_name##_LO_IFACE, \ - _LO_IMPL_PROTO, _ARG_impl_type, _ARG_impl_name, __VA_ARGS__) \ - /* 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) \ - } - -#define _LO_IMPL_PROTO( _ARG_impl_type, _ARG_impl_name, _ARG_quals, _tuple_typ, ...) _LO_IMPL_PROTO_##_tuple_typ(_ARG_impl_type, _ARG_impl_name, _ARG_quals, __VA_ARGS__) -#define _LO_IMPL_PROTO_lo_nest(_ARG_impl_type, _ARG_impl_name, _ARG_quals, _ARG_child_iface_name) /* empty */ -#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( _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, 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, diff --git a/libmisc/log.c b/libmisc/log.c index 7e917c6..96e9ca4 100644 --- a/libmisc/log.c +++ b/libmisc/log.c @@ -12,8 +12,7 @@ #include <libmisc/log.h> struct log_stdout {}; -LO_IMPLEMENTATION_H(fmt_dest, struct log_stdout, log_stdout); -LO_IMPLEMENTATION_C(fmt_dest, struct log_stdout, log_stdout, static); +LO_IMPLEMENTATION_STATIC(fmt_dest, struct log_stdout, log_stdout); static size_t log_bytes = 0; diff --git a/libmisc/tests/test_obj.c b/libmisc/tests/test_obj.c index 687ad4e..c3c6786 100644 --- a/libmisc/tests/test_obj.c +++ b/libmisc/tests/test_obj.c @@ -28,19 +28,19 @@ LO_IMPLEMENTATION_H(frobber, struct myclass, myclass); /* `struct myclass` implementation ********************************************/ -LO_IMPLEMENTATION_C(frobber, struct myclass, myclass, static); +LO_IMPLEMENTATION_C(frobber, struct myclass, myclass); -static int myclass_frob(struct myclass *self) { +int myclass_frob(struct myclass *self) { test_assert(self); return self->a; } -static int myclass_frob1(struct myclass *self, int arg) { +int myclass_frob1(struct myclass *self, int arg) { test_assert(self); return arg; } -static void myclass_frob0(struct myclass *self) { +void myclass_frob0(struct myclass *self) { test_assert(self); } diff --git a/libmisc/tests/test_obj_autobox.c b/libmisc/tests/test_obj_autobox.c index 1110639..394f716 100644 --- a/libmisc/tests/test_obj_autobox.c +++ b/libmisc/tests/test_obj_autobox.c @@ -26,21 +26,15 @@ LO_INTERFACE(writer); LO_NEST(writer) LO_INTERFACE(read_writer); -/* implementation header ******************************************************/ +/* implementation *************************************************************/ 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); +LO_IMPLEMENTATION_STATIC(reader, struct myclass, myclass); +LO_IMPLEMENTATION_STATIC(writer, struct myclass, myclass); +LO_IMPLEMENTATION_STATIC(read_writer, struct myclass, myclass); static size_t myclass_read(struct myclass *self, void *buf, size_t count) { test_assert(self); diff --git a/libmisc/tests/test_obj_nest.c b/libmisc/tests/test_obj_nest.c index 20ffe4a..b52cd7b 100644 --- a/libmisc/tests/test_obj_nest.c +++ b/libmisc/tests/test_obj_nest.c @@ -25,21 +25,15 @@ LO_INTERFACE(writer); LO_NEST(writer) LO_INTERFACE(read_writer); -/* implementation header ******************************************************/ +/* implementation *************************************************************/ 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); +LO_IMPLEMENTATION_STATIC(reader, struct myclass, myclass); +LO_IMPLEMENTATION_STATIC(writer, struct myclass, myclass); +LO_IMPLEMENTATION_STATIC(read_writer, struct myclass, myclass); static size_t myclass_read(struct myclass *self, void *buf, size_t count) { test_assert(self); |