Laszlo Ersek
2023-Feb-26 11:45 UTC
[Libguestfs] [libnbd PATCH v5 3/5] force semicolon after DEFINE_VECTOR_TYPE() macro invocations
Currently, a semicolon after a DEFINE_VECTOR_TYPE(...) macro invocation is not needed, nor does our documentation in "common/utils/vector.h" prescribe one. Furthermore, it breaks ISO C, which gcc reports with "-Wpedantic":> warning: ISO C does not allow extra ?;? outside of a function > [-Wpedantic]Our current usage is inconsistent; a proper subset of all our DEFINE_VECTOR_TYPE() invocations is succeeded by a semicolon. We could remove these semicolons, but that doesn't play nicely with Emacs's C language parser. Thus, force the semicolon instead. Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- Notes: v5: - force semicolon after DEFINE_VECTOR_TYPE() [Eric] - reword commit message accordingly v4: - new patch in v4 common/utils/vector.h | 7 +++++-- lib/uri.c | 2 +- copy/file-ops.c | 2 +- copy/nbd-ops.c | 2 +- dump/dump.c | 2 +- fuse/nbdfuse.h | 2 +- info/list.c | 2 +- info/map.c | 2 +- ublk/nbdublk.h | 2 +- ublk/tgt.c | 2 +- 10 files changed, 14 insertions(+), 11 deletions(-) diff --git a/common/utils/vector.h b/common/utils/vector.h index fb2482c853ff..b9b88ba02e7d 100644 --- a/common/utils/vector.h +++ b/common/utils/vector.h @@ -52,7 +52,7 @@ /* Use of this macro defines a new type called ?name? containing an * extensible vector of ?type? elements. For example: * - * DEFINE_VECTOR_TYPE (string_vector, char *) + * DEFINE_VECTOR_TYPE (string_vector, char *); * * defines a new type called ?string_vector? as a vector of ?char *?. * You can create variables of this type: @@ -176,7 +176,10 @@ { \ return bsearch (key, v->ptr, v->len, sizeof (type), \ (void *) compare); \ - } + } \ + \ + /* End with duplicate declaration, so callers must supply ';'. */ \ + struct name #define empty_vector { .ptr = NULL, .len = 0, .cap = 0 } diff --git a/lib/uri.c b/lib/uri.c index 367621d40208..31ee90f3b94f 100644 --- a/lib/uri.c +++ b/lib/uri.c @@ -58,7 +58,7 @@ struct uri_query { char *value; }; -DEFINE_VECTOR_TYPE (uri_query_list, struct uri_query) +DEFINE_VECTOR_TYPE (uri_query_list, struct uri_query); /* Parse the query_raw substring of a URI into a list of decoded queries. * Return 0 on success or -1 on error. diff --git a/copy/file-ops.c b/copy/file-ops.c index 18cae74a617d..1efece2614e6 100644 --- a/copy/file-ops.c +++ b/copy/file-ops.c @@ -64,7 +64,7 @@ #endif #ifdef PAGE_CACHE_MAPPING -DEFINE_VECTOR_TYPE (byte_vector, uint8_t) +DEFINE_VECTOR_TYPE (byte_vector, uint8_t); #endif static struct rw_ops file_ops; diff --git a/copy/nbd-ops.c b/copy/nbd-ops.c index 34ab4857ee00..0980a5edec46 100644 --- a/copy/nbd-ops.c +++ b/copy/nbd-ops.c @@ -33,7 +33,7 @@ static struct rw_ops nbd_ops; -DEFINE_VECTOR_TYPE (handles, struct nbd_handle *) +DEFINE_VECTOR_TYPE (handles, struct nbd_handle *); struct rw_nbd { struct rw rw; diff --git a/dump/dump.c b/dump/dump.c index d0da28790eb7..922bd4355897 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -38,7 +38,7 @@ #include "version.h" #include "vector.h" -DEFINE_VECTOR_TYPE (uint32_vector, uint32_t) +DEFINE_VECTOR_TYPE (uint32_vector, uint32_t); static const char *progname; static struct nbd_handle *nbd; diff --git a/fuse/nbdfuse.h b/fuse/nbdfuse.h index 371ca8bb53ac..93b66aac52c1 100644 --- a/fuse/nbdfuse.h +++ b/fuse/nbdfuse.h @@ -30,7 +30,7 @@ #include "vector.h" -DEFINE_VECTOR_TYPE (handles, struct nbd_handle *) +DEFINE_VECTOR_TYPE (handles, struct nbd_handle *); extern handles nbd; extern unsigned connections; diff --git a/info/list.c b/info/list.c index c2741ba0fa10..4b4e8f860160 100644 --- a/info/list.c +++ b/info/list.c @@ -35,7 +35,7 @@ struct export { char *name; char *desc; }; -DEFINE_VECTOR_TYPE (exports, struct export) +DEFINE_VECTOR_TYPE (exports, struct export); static exports export_list = empty_vector; static int diff --git a/info/map.c b/info/map.c index a5aad9552208..4924866a3b28 100644 --- a/info/map.c +++ b/info/map.c @@ -36,7 +36,7 @@ #include "nbdinfo.h" -DEFINE_VECTOR_TYPE (uint32_vector, uint32_t) +DEFINE_VECTOR_TYPE (uint32_vector, uint32_t); static void print_extents (uint32_vector *entries); static void print_totals (uint32_vector *entries, int64_t size); diff --git a/ublk/nbdublk.h b/ublk/nbdublk.h index 086352e9d17f..1296b8424a5b 100644 --- a/ublk/nbdublk.h +++ b/ublk/nbdublk.h @@ -25,7 +25,7 @@ #include "vector.h" -DEFINE_VECTOR_TYPE (handles, struct nbd_handle *) +DEFINE_VECTOR_TYPE (handles, struct nbd_handle *); #define UBLKSRV_TGT_TYPE_NBD 0 diff --git a/ublk/tgt.c b/ublk/tgt.c index 5d88e33dcc4b..9b0a64d66b80 100644 --- a/ublk/tgt.c +++ b/ublk/tgt.c @@ -62,7 +62,7 @@ struct thread_info { struct ublksrv_aio_ctx *aio_ctx; struct ublksrv_aio_list compl; }; -DEFINE_VECTOR_TYPE (thread_infos, struct thread_info) +DEFINE_VECTOR_TYPE (thread_infos, struct thread_info); static thread_infos thread_info; static pthread_barrier_t barrier;
Eric Blake
2023-Feb-27 14:04 UTC
[Libguestfs] [libnbd PATCH v5 3/5] force semicolon after DEFINE_VECTOR_TYPE() macro invocations
On Sun, Feb 26, 2023 at 12:45:27PM +0100, Laszlo Ersek wrote:> Currently, a semicolon after a DEFINE_VECTOR_TYPE(...) macro invocation is > not needed, nor does our documentation in "common/utils/vector.h" > prescribe one. Furthermore, it breaks ISO C, which gcc reports with > "-Wpedantic": > > > warning: ISO C does not allow extra ?;? outside of a function > > [-Wpedantic] > > Our current usage is inconsistent; a proper subset of all our > DEFINE_VECTOR_TYPE() invocations is succeeded by a semicolon. We could > remove these semicolons, but that doesn't play nicely with Emacs's CI'm not sure if the possessive is spelled "Emacs'". Either way, Reviewed-by: Eric Blake <eblake at redhat.com>> language parser. Thus, force the semicolon instead. > > Signed-off-by: Laszlo Ersek <lersek at redhat.com> > --- > > Notes: > v5: > - force semicolon after DEFINE_VECTOR_TYPE() [Eric] > - reword commit message accordingly > > v4: > - new patch in v4 > > common/utils/vector.h | 7 +++++-- > lib/uri.c | 2 +- > copy/file-ops.c | 2 +- > copy/nbd-ops.c | 2 +- > dump/dump.c | 2 +- > fuse/nbdfuse.h | 2 +- > info/list.c | 2 +- > info/map.c | 2 +- > ublk/nbdublk.h | 2 +- > ublk/tgt.c | 2 +- > 10 files changed, 14 insertions(+), 11 deletions(-)I grepped to make sure no other files had the pattern, even if they weren't being compiled by your choice of configure options. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org