Laszlo Ersek
2023-Feb-15 14:11 UTC
[Libguestfs] [libnbd PATCH v3 01/29] use space consistently in function and function-like macro invocations
We intend to place a space character between the function designator and the opening parenthesis in a function call. We've been executing on that mostly consistently; fix the few exceptions now. The same convention should be applied to the invocations of function-like macros, and to instances of "__attribute__ ((attr))". (The latter is exemplified, although not consistently, by the GCC manual.) Implement this, by inserting the necessary spaces. Furthermore, some compiler attributes take multiple parameters, such as "nonnull". The GCC manual clearly shows that arguments passed to such attributes may be separated with ", " as well, not just ",". Use the former, as it's more readable. Finally, the C standard calls "defined" -- as in "#if defined identifier" and (equivalently) "#if defined (identifier)" -- a unary preprocessing operator. We can spell the parenthesized form as "defined (identifier)" rather than "defined(identifier)", so choose the former. I collected the locations possibly missing spaces with: git grep -EHn '\<[a-zA-Z0-9_]+\(' -- '*.c' '*.h' and then manually updated each as necessary. I didn't change occurrences in comments, except where the comment clearly indicated copying and pasting an expression into new code. "git show -w" outputs nothing for this patch. The test suite passes. Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- lib/internal.h | 72 ++++++++++---------- lib/nbd-protocol.h | 12 ++-- common/include/array-size.h | 2 +- common/include/byte-swapping.h | 24 +++---- common/include/checked-overflow.h | 42 ++++++------ common/include/compiler-macros.h | 2 +- common/include/iszero.h | 2 +- common/include/minmax.h | 4 +- common/utils/const-string-vector.h | 2 +- common/utils/nbdkit-string.h | 2 +- common/utils/string-vector.h | 2 +- common/utils/vector.h | 20 +++--- lib/errors.c | 6 +- lib/opt.c | 4 +- lib/uri.c | 2 +- lib/utils.c | 12 ++-- common/include/test-array-size.c | 26 +++---- common/utils/test-human-size.c | 10 +-- common/utils/test-vector.c | 4 +- ocaml/nbd-c.h | 6 +- tests/eflags.c | 6 +- tests/get-size.c | 4 +- tests/newstyle-limited.c | 6 +- tests/oldstyle.c | 4 +- examples/copy-libev.c | 30 ++++---- examples/list-exports.c | 2 +- examples/strict-structured-reads.c | 2 +- examples/threaded-reads-and-writes.c | 2 +- interop/interop.c | 2 +- copy/file-ops.c | 2 +- copy/main.c | 2 +- copy/nbdcopy.h | 2 +- dump/dump.c | 2 +- fuse/nbdfuse.c | 2 +- info/main.c | 2 +- ublk/nbdublk.c | 4 +- ublk/tgt.c | 20 +++--- 37 files changed, 175 insertions(+), 175 deletions(-) diff --git a/lib/internal.h b/lib/internal.h index bbbd26393f5a..c5827f4f0037 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -46,7 +46,7 @@ * debug and error handling code out of hot paths, making the hot path * into common functions use less instruction cache. */ -#if defined(__GNUC__) +#if defined (__GNUC__) #define unlikely(x) __builtin_expect (!!(x), 0) #define if_debug(h) if (unlikely ((h)->debug)) #else @@ -71,7 +71,7 @@ struct meta_context { char *name; /* Name of meta context. */ uint32_t context_id; /* Context ID negotiated with the server. */ }; -DEFINE_VECTOR_TYPE(meta_vector, struct meta_context); +DEFINE_VECTOR_TYPE (meta_vector, struct meta_context); struct export { char *name; @@ -220,20 +220,20 @@ struct nbd_handle { struct { struct nbd_fixed_new_option_reply_server server; char str[NBD_MAX_STRING * 2 + 1]; /* name, description, NUL */ - } __attribute__((packed)) server; + } __attribute__ ((packed)) server; struct nbd_fixed_new_option_reply_info_export export; struct nbd_fixed_new_option_reply_info_block_size block_size; struct { struct nbd_fixed_new_option_reply_info_name_or_desc info; char str[NBD_MAX_STRING]; - } __attribute__((packed)) name_desc; + } __attribute__ ((packed)) name_desc; struct { struct nbd_fixed_new_option_reply_meta_context context; char str[NBD_MAX_STRING]; - } __attribute__((packed)) context; + } __attribute__ ((packed)) context; char err_msg[NBD_MAX_STRING]; } payload; - } __attribute__((packed)) or; + } __attribute__ ((packed)) or; struct nbd_export_name_option_reply export_name_reply; struct nbd_simple_reply simple_reply; struct { @@ -245,9 +245,9 @@ struct nbd_handle { struct nbd_structured_reply_error error; char msg[NBD_MAX_STRING]; /* Common to all error types */ uint64_t offset; /* Only used for NBD_REPLY_TYPE_ERROR_OFFSET */ - } __attribute__((packed)) error; + } __attribute__ ((packed)) error; } payload; - } __attribute__((packed)) sr; + } __attribute__ ((packed)) sr; uint16_t gflags; uint32_t cflags; uint32_t len; @@ -387,26 +387,26 @@ struct command { /* aio.c */ extern void nbd_internal_retire_and_free_command (struct command *) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); /* connect.c */ extern int nbd_internal_wait_until_connected (struct nbd_handle *h) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); /* crypto.c */ extern struct socket *nbd_internal_crypto_create_session (struct nbd_handle *, struct socket *oldsock) - LIBNBD_ATTRIBUTE_NONNULL(1, 2); + LIBNBD_ATTRIBUTE_NONNULL (1, 2); extern bool nbd_internal_crypto_is_reading (struct nbd_handle *) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); extern int nbd_internal_crypto_handshake (struct nbd_handle *) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); extern void nbd_internal_crypto_debug_tls_enabled (struct nbd_handle *) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); /* debug.c */ extern void nbd_internal_debug (struct nbd_handle *h, const char *context, const char *fs, ...) - LIBNBD_ATTRIBUTE_NONNULL(1, 3); + LIBNBD_ATTRIBUTE_NONNULL (1, 3); #define debug(h, fs, ...) \ do { \ if_debug ((h)) \ @@ -420,10 +420,10 @@ extern void nbd_internal_debug (struct nbd_handle *h, const char *context, /* errors.c */ extern void nbd_internal_set_error_context (const char *context) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); extern const char *nbd_internal_get_error_context (void); extern void nbd_internal_set_last_error (int errnum, char *error) - LIBNBD_ATTRIBUTE_NONNULL(2); + LIBNBD_ATTRIBUTE_NONNULL (2); #define set_error(errnum, fs, ...) \ do { \ int _e = (errnum); \ @@ -442,16 +442,16 @@ extern void nbd_internal_set_last_error (int errnum, char *error) /* flags.c */ extern void nbd_internal_reset_size_and_flags (struct nbd_handle *h) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); extern int nbd_internal_set_size_and_flags (struct nbd_handle *h, uint64_t exportsize, uint16_t eflags) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); extern int nbd_internal_set_block_size (struct nbd_handle *h, uint32_t min, uint32_t pref, uint32_t max) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); extern void nbd_internal_set_payload (struct nbd_handle *h) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); /* is-state.c */ extern bool nbd_internal_is_state_created (enum state state); @@ -464,7 +464,7 @@ extern bool nbd_internal_is_state_closed (enum state state); /* opt.c */ extern void nbd_internal_free_option (struct nbd_handle *h) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); /* protocol.c */ extern int nbd_internal_errno_of_nbd_error (uint32_t error); @@ -476,7 +476,7 @@ extern int64_t nbd_internal_command_common (struct nbd_handle *h, uint64_t offset, uint64_t count, int count_err, void *data, struct command_cb *cb) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); /* socket.c */ struct socket *nbd_internal_socket_create (int fd); @@ -484,9 +484,9 @@ struct socket *nbd_internal_socket_create (int fd); /* states.c */ extern void nbd_internal_abort_commands (struct nbd_handle *h, struct command **list) - LIBNBD_ATTRIBUTE_NONNULL(1,2); + LIBNBD_ATTRIBUTE_NONNULL (1, 2); extern int nbd_internal_run (struct nbd_handle *h, enum external_event ev) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); extern const char *nbd_internal_state_short_string (enum state state); extern enum state_group nbd_internal_state_group (enum state state); extern enum state_group nbd_internal_state_group_parent (enum state_group group); @@ -498,24 +498,24 @@ extern int nbd_internal_aio_get_direction (enum state state); /* utils.c */ extern void nbd_internal_hexdump (const void *data, size_t len, FILE *fp) - LIBNBD_ATTRIBUTE_NONNULL(1,3); + LIBNBD_ATTRIBUTE_NONNULL (1, 3); extern int nbd_internal_copy_string_list (string_vector *v, char **in) - LIBNBD_ATTRIBUTE_NONNULL(1,2); + LIBNBD_ATTRIBUTE_NONNULL (1, 2); extern int nbd_internal_set_argv (struct nbd_handle *h, char **argv) - LIBNBD_ATTRIBUTE_NONNULL(1,2); + LIBNBD_ATTRIBUTE_NONNULL (1, 2); extern int nbd_internal_set_querylist (struct nbd_handle *h, char **queries) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); extern const char *nbd_internal_fork_safe_itoa (long v, char *buf, size_t len) - LIBNBD_ATTRIBUTE_NONNULL(2); + LIBNBD_ATTRIBUTE_NONNULL (2); extern void nbd_internal_fork_safe_perror (const char *s) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); extern char *nbd_internal_printable_buffer (const void *buf, size_t count) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_NONNULL (1); extern char *nbd_internal_printable_string (const char *str) - LIBNBD_ATTRIBUTE_ALLOC_DEALLOC(free) - LIBNBD_ATTRIBUTE_NONNULL(1); + LIBNBD_ATTRIBUTE_ALLOC_DEALLOC (free) + LIBNBD_ATTRIBUTE_NONNULL (1); extern char *nbd_internal_printable_string_list (char **list) - LIBNBD_ATTRIBUTE_ALLOC_DEALLOC(free); + LIBNBD_ATTRIBUTE_ALLOC_DEALLOC (free); /* These are wrappers around socket(2) and socketpair(2). They * always set SOCK_CLOEXEC. nbd_internal_socket can set SOCK_NONBLOCK @@ -525,6 +525,6 @@ extern int nbd_internal_socket (int domain, int type, int protocol, bool nonblock); extern int nbd_internal_socketpair (int domain, int type, int protocol, int *fds) - LIBNBD_ATTRIBUTE_NONNULL(4); + LIBNBD_ATTRIBUTE_NONNULL (4); #endif /* LIBNBD_INTERNAL_H */ diff --git a/lib/nbd-protocol.h b/lib/nbd-protocol.h index e5d6404b8eaa..9353668605ff 100644 --- a/lib/nbd-protocol.h +++ b/lib/nbd-protocol.h @@ -40,8 +40,8 @@ * these structures. */ -#if defined(__GNUC__) || defined(__clang__) -#define NBD_ATTRIBUTE_PACKED __attribute__((__packed__)) +#if defined (__GNUC__) || defined (__clang__) +#define NBD_ATTRIBUTE_PACKED __attribute__ ((__packed__)) #else #error "Please port to your compiler's notion of a packed struct" #endif @@ -58,8 +58,8 @@ struct nbd_old_handshake { char zeroes[124]; /* must be sent as zero bytes */ } NBD_ATTRIBUTE_PACKED; -#define NBD_MAGIC UINT64_C(0x4e42444d41474943) /* ASCII "NBDMAGIC" */ -#define NBD_OLD_VERSION UINT64_C(0x0000420281861253) +#define NBD_MAGIC UINT64_C (0x4e42444d41474943) /* ASCII "NBDMAGIC" */ +#define NBD_OLD_VERSION UINT64_C (0x0000420281861253) /* New-style handshake. */ struct nbd_new_handshake { @@ -68,7 +68,7 @@ struct nbd_new_handshake { uint16_t gflags; /* global flags */ } NBD_ATTRIBUTE_PACKED; -#define NBD_NEW_VERSION UINT64_C(0x49484156454F5054) /* ASCII "IHAVEOPT" */ +#define NBD_NEW_VERSION UINT64_C (0x49484156454F5054) /* ASCII "IHAVEOPT" */ /* New-style handshake option (sent by the client to us). */ struct nbd_new_option { @@ -95,7 +95,7 @@ struct nbd_fixed_new_option_reply { uint32_t replylen; } NBD_ATTRIBUTE_PACKED; -#define NBD_REP_MAGIC UINT64_C(0x3e889045565a9) +#define NBD_REP_MAGIC UINT64_C (0x3e889045565a9) /* Global flags. */ #define NBD_FLAG_FIXED_NEWSTYLE (1 << 0) diff --git a/common/include/array-size.h b/common/include/array-size.h index 3212d9dc6cdb..6f0a1ae87233 100644 --- a/common/include/array-size.h +++ b/common/include/array-size.h @@ -36,6 +36,6 @@ #include "compiler-macros.h" #define ARRAY_SIZE(a) \ - ((sizeof (a) / sizeof ((a)[0])) + BUILD_BUG_UNLESS_TRUE (TYPE_IS_ARRAY(a))) + ((sizeof (a) / sizeof ((a)[0])) + BUILD_BUG_UNLESS_TRUE (TYPE_IS_ARRAY (a))) #endif /* NBDKIT_ARRAY_SIZE_H */ diff --git a/common/include/byte-swapping.h b/common/include/byte-swapping.h index c53fba2e8f24..fce56df585ca 100644 --- a/common/include/byte-swapping.h +++ b/common/include/byte-swapping.h @@ -58,20 +58,20 @@ #ifdef __HAIKU__ #include <ByteOrder.h> -#define htobe16(x) B_HOST_TO_BENDIAN_INT16(x) -#define htole16(x) B_HOST_TO_LENDIAN_INT16(x) -#define be16toh(x) B_BENDIAN_TO_HOST_INT16(x) -#define le16toh(x) B_LENDIAN_TO_HOST_INT16(x) +#define htobe16(x) B_HOST_TO_BENDIAN_INT16 (x) +#define htole16(x) B_HOST_TO_LENDIAN_INT16 (x) +#define be16toh(x) B_BENDIAN_TO_HOST_INT16 (x) +#define le16toh(x) B_LENDIAN_TO_HOST_INT16 (x) -#define htobe32(x) B_HOST_TO_BENDIAN_INT32(x) -#define htole32(x) B_HOST_TO_LENDIAN_INT32(x) -#define be32toh(x) B_BENDIAN_TO_HOST_INT32(x) -#define le32toh(x) B_LENDIAN_TO_HOST_INT32(x) +#define htobe32(x) B_HOST_TO_BENDIAN_INT32 (x) +#define htole32(x) B_HOST_TO_LENDIAN_INT32 (x) +#define be32toh(x) B_BENDIAN_TO_HOST_INT32 (x) +#define le32toh(x) B_LENDIAN_TO_HOST_INT32 (x) -#define htobe64(x) B_HOST_TO_BENDIAN_INT64(x) -#define htole64(x) B_HOST_TO_LENDIAN_INT64(x) -#define be64toh(x) B_BENDIAN_TO_HOST_INT64(x) -#define le64toh(x) B_LENDIAN_TO_HOST_INT64(x) +#define htobe64(x) B_HOST_TO_BENDIAN_INT64 (x) +#define htole64(x) B_HOST_TO_LENDIAN_INT64 (x) +#define be64toh(x) B_BENDIAN_TO_HOST_INT64 (x) +#define le64toh(x) B_LENDIAN_TO_HOST_INT64 (x) #endif /* If we didn't define bswap_16, bswap_32 and bswap_64 already above, diff --git a/common/include/checked-overflow.h b/common/include/checked-overflow.h index 546c930b33d2..a1852adcdc7a 100644 --- a/common/include/checked-overflow.h +++ b/common/include/checked-overflow.h @@ -46,7 +46,7 @@ #ifndef NBDKIT_CHECKED_OVERFLOW_H #define NBDKIT_CHECKED_OVERFLOW_H -#if !defined(__GNUC__) && !defined(__clang__) +#if !defined (__GNUC__) && !defined (__clang__) #error "this file may need to be ported to your compiler" #endif @@ -66,9 +66,9 @@ * mathematical sum are stored to "*r". */ #if HAVE_DECL___BUILTIN_ADD_OVERFLOW -#define ADD_OVERFLOW(a, b, r) ADD_OVERFLOW_BUILTIN((a), (b), (r)) +#define ADD_OVERFLOW(a, b, r) ADD_OVERFLOW_BUILTIN ((a), (b), (r)) #else -#define ADD_OVERFLOW(a, b, r) ADD_OVERFLOW_FALLBACK((a), (b), (r)) +#define ADD_OVERFLOW(a, b, r) ADD_OVERFLOW_FALLBACK ((a), (b), (r)) #endif /* Multiply "a" and "b", both of (possibly different) unsigned integer types, @@ -83,9 +83,9 @@ * the mathematical product are stored to "*r". */ #if HAVE_DECL___BUILTIN_MUL_OVERFLOW -#define MUL_OVERFLOW(a, b, r) MUL_OVERFLOW_BUILTIN((a), (b), (r)) +#define MUL_OVERFLOW(a, b, r) MUL_OVERFLOW_BUILTIN ((a), (b), (r)) #else -#define MUL_OVERFLOW(a, b, r) MUL_OVERFLOW_FALLBACK((a), (b), (r)) +#define MUL_OVERFLOW(a, b, r) MUL_OVERFLOW_FALLBACK ((a), (b), (r)) #endif /* The ADD_OVERFLOW_BUILTIN and MUL_OVERFLOW_BUILTIN function-like macros @@ -99,22 +99,22 @@ * variably modified type. */ #if HAVE_DECL___BUILTIN_ADD_OVERFLOW -#define ADD_OVERFLOW_BUILTIN(a, b, r) \ - ({ \ - STATIC_ASSERT_UNSIGNED_INT (a); \ - STATIC_ASSERT_UNSIGNED_INT (b); \ - STATIC_ASSERT_UNSIGNED_INT (*(r)); \ - __builtin_add_overflow((a), (b), (r)); \ +#define ADD_OVERFLOW_BUILTIN(a, b, r) \ + ({ \ + STATIC_ASSERT_UNSIGNED_INT (a); \ + STATIC_ASSERT_UNSIGNED_INT (b); \ + STATIC_ASSERT_UNSIGNED_INT (*(r)); \ + __builtin_add_overflow ((a), (b), (r)); \ }) #endif #if HAVE_DECL___BUILTIN_MUL_OVERFLOW -#define MUL_OVERFLOW_BUILTIN(a, b, r) \ - ({ \ - STATIC_ASSERT_UNSIGNED_INT (a); \ - STATIC_ASSERT_UNSIGNED_INT (b); \ - STATIC_ASSERT_UNSIGNED_INT (*(r)); \ - __builtin_mul_overflow((a), (b), (r)); \ +#define MUL_OVERFLOW_BUILTIN(a, b, r) \ + ({ \ + STATIC_ASSERT_UNSIGNED_INT (a); \ + STATIC_ASSERT_UNSIGNED_INT (b); \ + STATIC_ASSERT_UNSIGNED_INT (*(r)); \ + __builtin_mul_overflow ((a), (b), (r)); \ }) #endif @@ -173,10 +173,10 @@ * * The expression "x" is not evaluated, unless it has variably modified type. */ -#define STATIC_ASSERT_UNSIGNED_INT(x) \ - do { \ - typedef char NBDKIT_UNIQUE_NAME(_x_has_uint_type)[(typeof (x))-1 > 0 ? 1 : -1] \ - __attribute__((__unused__)); \ +#define STATIC_ASSERT_UNSIGNED_INT(x) \ + do { \ + typedef char NBDKIT_UNIQUE_NAME (_x_has_uint_type)[(typeof (x))-1 > 0 ? 1 : -1] \ + __attribute__ ((__unused__)); \ } while (0) /* Assign the sum "a + b" to "*r", using uintmax_t modular arithmetic. diff --git a/common/include/compiler-macros.h b/common/include/compiler-macros.h index d41166614f95..7933bb87a5bf 100644 --- a/common/include/compiler-macros.h +++ b/common/include/compiler-macros.h @@ -48,7 +48,7 @@ #define BUILD_BUG_STRUCT_SIZE(cond) \ (sizeof (struct { int: (cond) ? 1 : -1; })) #define BUILD_BUG_UNLESS_TRUE(cond) \ - (BUILD_BUG_STRUCT_SIZE(cond) - BUILD_BUG_STRUCT_SIZE(cond)) + (BUILD_BUG_STRUCT_SIZE (cond) - BUILD_BUG_STRUCT_SIZE (cond)) #define TYPE_IS_ARRAY(a) \ (!__builtin_types_compatible_p (typeof (a), typeof (&(a)[0]))) diff --git a/common/include/iszero.h b/common/include/iszero.h index 7fdbb52c2a03..657ed5bac4ef 100644 --- a/common/include/iszero.h +++ b/common/include/iszero.h @@ -45,7 +45,7 @@ * See also: * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69908 */ -static inline bool __attribute__((__nonnull__ (1))) +static inline bool __attribute__ ((__nonnull__ (1))) is_zero (const char *buffer, size_t size) { size_t i; diff --git a/common/include/minmax.h b/common/include/minmax.h index 8d1fbf19bc23..8b0e6b7a4dbb 100644 --- a/common/include/minmax.h +++ b/common/include/minmax.h @@ -48,10 +48,10 @@ #undef MIN #define MIN(x, y) \ - MIN_1((x), (y), NBDKIT_UNIQUE_NAME(_x), NBDKIT_UNIQUE_NAME(_y)) + MIN_1 ((x), (y), NBDKIT_UNIQUE_NAME (_x), NBDKIT_UNIQUE_NAME (_y)) #undef MAX #define MAX(x, y) \ - MAX_1((x), (y), NBDKIT_UNIQUE_NAME(_x), NBDKIT_UNIQUE_NAME(_y)) + MAX_1 ((x), (y), NBDKIT_UNIQUE_NAME (_x), NBDKIT_UNIQUE_NAME (_y)) #ifdef HAVE_AUTO_TYPE diff --git a/common/utils/const-string-vector.h b/common/utils/const-string-vector.h index 91307ca1cf91..c15f8952b3b3 100644 --- a/common/utils/const-string-vector.h +++ b/common/utils/const-string-vector.h @@ -37,6 +37,6 @@ #include "vector.h" -DEFINE_VECTOR_TYPE(const_string_vector, const char *); +DEFINE_VECTOR_TYPE (const_string_vector, const char *); #endif /* CONST_STRING_VECTOR_H */ diff --git a/common/utils/nbdkit-string.h b/common/utils/nbdkit-string.h index 14998703b80a..b85f05991a82 100644 --- a/common/utils/nbdkit-string.h +++ b/common/utils/nbdkit-string.h @@ -37,6 +37,6 @@ #include "vector.h" -DEFINE_VECTOR_TYPE(string, char); +DEFINE_VECTOR_TYPE (string, char); #endif /* NBDKIT_STRING_H */ diff --git a/common/utils/string-vector.h b/common/utils/string-vector.h index 80d7311debfb..aa33fd48ceb5 100644 --- a/common/utils/string-vector.h +++ b/common/utils/string-vector.h @@ -37,6 +37,6 @@ #include "vector.h" -DEFINE_VECTOR_TYPE(string_vector, char *); +DEFINE_VECTOR_TYPE (string_vector, char *); #endif /* STRING_VECTOR_H */ diff --git a/common/utils/vector.h b/common/utils/vector.h index 60577eaefd74..fb2482c853ff 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: @@ -94,7 +94,7 @@ * allocated and capacity is increased, but the vector length is \ * not increased and the new elements are not initialized. \ */ \ - static inline int __attribute__((__unused__)) \ + static inline int __attribute__ ((__unused__)) \ name##_reserve (name *v, size_t n) \ { \ return generic_vector_reserve ((struct generic_vector *)v, n, \ @@ -104,7 +104,7 @@ /* Same as _reserve, but the allocation will be page aligned. Note \ * that the machine page size must be divisible by sizeof (type). \ */ \ - static inline int __attribute__((__unused__)) \ + static inline int __attribute__ ((__unused__)) \ name##_reserve_page_aligned (name *v, size_t n) \ { \ return generic_vector_reserve_page_aligned ((struct generic_vector *)v, \ @@ -112,7 +112,7 @@ } \ \ /* Insert at i'th element. i=0 => beginning i=len => append */ \ - static inline int __attribute__((__unused__)) \ + static inline int __attribute__ ((__unused__)) \ name##_insert (name *v, type elem, size_t i) \ { \ assert (i <= v->len); \ @@ -126,14 +126,14 @@ } \ \ /* Append a new element to the end of the vector. */ \ - static inline int __attribute__((__unused__)) \ + static inline int __attribute__ ((__unused__)) \ name##_append (name *v, type elem) \ { \ return name##_insert (v, elem, v->len); \ } \ \ /* Remove i'th element. i=0 => beginning i=len-1 => end */ \ - static inline void __attribute__((__unused__)) \ + static inline void __attribute__ ((__unused__)) \ name##_remove (name *v, size_t i) \ { \ assert (i < v->len); \ @@ -142,7 +142,7 @@ } \ \ /* Remove all elements and deallocate the vector. */ \ - static inline void __attribute__((__unused__)) \ + static inline void __attribute__ ((__unused__)) \ name##_reset (name *v) \ { \ free (v->ptr); \ @@ -151,7 +151,7 @@ } \ \ /* Iterate over the vector, calling f() on each element. */ \ - static inline void __attribute__((__unused__)) \ + static inline void __attribute__ ((__unused__)) \ name##_iter (name *v, void (*f) (type elem)) \ { \ size_t i; \ @@ -160,7 +160,7 @@ } \ \ /* Sort the elements of the vector. */ \ - static inline void __attribute__((__unused__)) \ + static inline void __attribute__ ((__unused__)) \ name##_sort (name *v, \ int (*compare) (const type *p1, const type *p2)) \ { \ @@ -170,7 +170,7 @@ /* Search for an exactly matching element in the vector using a \ * binary search. Returns a pointer to the element or NULL. \ */ \ - static inline type * __attribute__((__unused__)) \ + static inline type * __attribute__ ((__unused__)) \ name##_search (const name *v, const void *key, \ int (*compare) (const void *key, const type *v)) \ { \ diff --git a/lib/errors.c b/lib/errors.c index 8859ae739528..c601a204d2b9 100644 --- a/lib/errors.c +++ b/lib/errors.c @@ -35,13 +35,13 @@ struct last_error { /* Thread-local storage of the last error. */ static pthread_key_t errors_key; -static void free_errors_key (void *vp) LIBNBD_ATTRIBUTE_NONNULL(1); +static void free_errors_key (void *vp) LIBNBD_ATTRIBUTE_NONNULL (1); /* Constructor/destructor to create the thread-local key when the * library is loaded and unloaded. */ -static void errors_init (void) __attribute__((constructor)); -static void errors_free (void) __attribute__((destructor)); +static void errors_init (void) __attribute__ ((constructor)); +static void errors_free (void) __attribute__ ((destructor)); static void errors_init (void) diff --git a/lib/opt.c b/lib/opt.c index 776a3612056a..9346d6b5f792 100644 --- a/lib/opt.c +++ b/lib/opt.c @@ -30,13 +30,13 @@ static int opt_meta_context_queries (struct nbd_handle *h, uint32_t opt, char **queries, nbd_context_callback *context) - LIBNBD_ATTRIBUTE_NONNULL(1,4); + LIBNBD_ATTRIBUTE_NONNULL (1, 4); static int aio_opt_meta_context_queries (struct nbd_handle *h, uint32_t opt, char **queries, nbd_context_callback *context, nbd_completion_callback *complete) - LIBNBD_ATTRIBUTE_NONNULL(1,4,5); + LIBNBD_ATTRIBUTE_NONNULL (1, 4, 5); /* Internal function which frees an option with callback. */ void diff --git a/lib/uri.c b/lib/uri.c index ae5b9adbc3cc..367621d40208 100644 --- a/lib/uri.c +++ b/lib/uri.c @@ -403,7 +403,7 @@ nbd_unlocked_aio_connect_uri (struct nbd_handle *h, const char *raw_uri) static int append_query_params (char **query_params, const char *key, const char *value) - LIBNBD_ATTRIBUTE_NONNULL(1,2,3); + LIBNBD_ATTRIBUTE_NONNULL (1, 2, 3); char * nbd_unlocked_get_uri (struct nbd_handle *h) diff --git a/lib/utils.c b/lib/utils.c index 9c5c38060a29..c229ebfc6106 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -178,7 +178,7 @@ nbd_internal_fork_safe_itoa (long v, char *buf, size_t bufsize) return &buf[i]; } -#if defined(__GNUC__) +#if defined (__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-result" #endif @@ -213,7 +213,7 @@ nbd_internal_fork_safe_perror (const char *s) errno = err; } -#if defined(__GNUC__) +#if defined (__GNUC__) #pragma GCC diagnostic pop #endif @@ -334,10 +334,10 @@ nbd_internal_printable_string_list (char **list) } -int nbd_internal_socket(int domain, - int type, - int protocol, - bool nonblock) +int nbd_internal_socket (int domain, + int type, + int protocol, + bool nonblock) { int fd; diff --git a/common/include/test-array-size.c b/common/include/test-array-size.c index 1ce2142cd39c..8b0972aaabe1 100644 --- a/common/include/test-array-size.c +++ b/common/include/test-array-size.c @@ -41,21 +41,21 @@ struct st { const char *s; int i; }; -static const char *s0[] __attribute__((__unused__)) = { }; -static const char *s1[] __attribute__((__unused__)) = { "a" }; -static const char *s3[] __attribute__((__unused__)) = { "a", "b", "c" }; -static const char *s4[4] __attribute__((__unused__)) = { "a", "b", "c", "d" }; -static int i0[] __attribute__((__unused__)) = { }; -static int i1[] __attribute__((__unused__)) = { 1 }; -static int i3[] __attribute__((__unused__)) = { 1, 2, 3 }; -static int i4[4] __attribute__((__unused__)) = { 1, 2, 3, 4 }; -static struct st st0[] __attribute__((__unused__)) = { }; -static struct st st1[] __attribute__((__unused__)) = { { "a", 1 } }; -static struct st st3[] __attribute__((__unused__)) +static const char *s0[] __attribute__ ((__unused__)) = { }; +static const char *s1[] __attribute__ ((__unused__)) = { "a" }; +static const char *s3[] __attribute__ ((__unused__)) = { "a", "b", "c" }; +static const char *s4[4] __attribute__ ((__unused__)) = { "a", "b", "c", "d" }; +static int i0[] __attribute__ ((__unused__)) = { }; +static int i1[] __attribute__ ((__unused__)) = { 1 }; +static int i3[] __attribute__ ((__unused__)) = { 1, 2, 3 }; +static int i4[4] __attribute__ ((__unused__)) = { 1, 2, 3, 4 }; +static struct st st0[] __attribute__ ((__unused__)) = { }; +static struct st st1[] __attribute__ ((__unused__)) = { { "a", 1 } }; +static struct st st3[] __attribute__ ((__unused__)) { { "a", 1 }, { "b", 2 }, { "c", 3 } }; -static struct st st4[4] __attribute__((__unused__)) +static struct st st4[4] __attribute__ ((__unused__)) { { "a", 1 }, { "b", 2 }, { "c", 3 }, { "d", 4 } }; -static struct st st4_0[4] __attribute__((__unused__)); +static struct st st4_0[4] __attribute__ ((__unused__)); int main (void) diff --git a/common/utils/test-human-size.c b/common/utils/test-human-size.c index 193f535f5ac6..2747ee67ffe6 100644 --- a/common/utils/test-human-size.c +++ b/common/utils/test-human-size.c @@ -73,13 +73,13 @@ main (int argc, char *argv[]) test (1048576, "1M", true); test (1048577, "1048577", false); - test (UINT64_C(1073741824), "1G", true); + test (UINT64_C (1073741824), "1G", true); - test (UINT64_C(1099511627776), "1T", true); - test (UINT64_C(1099511627777), "1099511627777", false); - test (UINT64_C(1099511627776) + 1024, "1073741825K", true); + test (UINT64_C (1099511627776), "1T", true); + test (UINT64_C (1099511627777), "1099511627777", false); + test (UINT64_C (1099511627776) + 1024, "1073741825K", true); - test (UINT64_C(1125899906842624), "1P", true); + test (UINT64_C (1125899906842624), "1P", true); test ((uint64_t)INT64_MAX+1, "8E", true); test (UINT64_MAX-1023, "18014398509481983K", true); diff --git a/common/utils/test-vector.c b/common/utils/test-vector.c index ecd5c1610e3c..55c8ebeb8a1e 100644 --- a/common/utils/test-vector.c +++ b/common/utils/test-vector.c @@ -50,8 +50,8 @@ #define APPENDS 1000000 -DEFINE_VECTOR_TYPE(int64_vector, int64_t); -DEFINE_VECTOR_TYPE(uint32_vector, uint32_t); +DEFINE_VECTOR_TYPE (int64_vector, int64_t); +DEFINE_VECTOR_TYPE (uint32_vector, uint32_t); static int compare (const int64_t *a, const int64_t *b) diff --git a/ocaml/nbd-c.h b/ocaml/nbd-c.h index 8b0c088da7ec..24505a0e0478 100644 --- a/ocaml/nbd-c.h +++ b/ocaml/nbd-c.h @@ -32,7 +32,7 @@ /* Workaround for OCaml < 4.06.0 */ #ifndef Bytes_val -#define Bytes_val(x) String_val(x) +#define Bytes_val(x) String_val (x) #endif /* Wrapper around caml_alloc_custom_mem for pre-2019 versions of OCaml. */ @@ -68,7 +68,7 @@ extern void nbd_internal_unix_sockaddr_to_sa (value, struct sockaddr_storage *, extern void nbd_internal_ocaml_exception_in_wrapper (const char *, value); /* Extract an NBD handle from an OCaml heap value. */ -#define NBD_val(v) (*((struct nbd_handle **)Data_custom_val(v))) +#define NBD_val(v) (*((struct nbd_handle **)Data_custom_val (v))) static struct custom_operations libnbd_custom_operations = { (char *) "libnbd_custom_operations", @@ -108,7 +108,7 @@ struct nbd_buffer { * whole struct is stored in the custom, not a pointer. This macro * returns a pointer to the struct. */ -#define NBD_buffer_val(v) ((struct nbd_buffer *)Data_custom_val(v)) +#define NBD_buffer_val(v) ((struct nbd_buffer *)Data_custom_val (v)) static struct custom_operations nbd_buffer_custom_operations = { (char *) "nbd_buffer_custom_operations", diff --git a/tests/eflags.c b/tests/eflags.c index 78fb6d3ec15a..023b7845c483 100644 --- a/tests/eflags.c +++ b/tests/eflags.c @@ -37,10 +37,10 @@ /* https://stackoverflow.com/a/1489985 */ #define XNBD_FLAG_FUNCTION(f) nbd_ ## f -#define NBD_FLAG_FUNCTION(f) XNBD_FLAG_FUNCTION(f) +#define NBD_FLAG_FUNCTION(f) XNBD_FLAG_FUNCTION (f) #define XSTR(x) #x -#define STR(x) XSTR(x) +#define STR(x) XSTR (x) int main (int argc, char *argv[]) @@ -108,7 +108,7 @@ main (int argc, char *argv[]) #error "unknown value" #endif - if ((r = NBD_FLAG_FUNCTION(flag) (nbd)) == -1) { + if ((r = NBD_FLAG_FUNCTION (flag) (nbd)) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/get-size.c b/tests/get-size.c index e6f44f776f13..d09e0d046d4c 100644 --- a/tests/get-size.c +++ b/tests/get-size.c @@ -32,7 +32,7 @@ #define SIZE 123456789 #define XSTR(s) #s -#define STR(s) XSTR(s) +#define STR(s) XSTR (s) int main (int argc, char *argv[]) @@ -41,7 +41,7 @@ main (int argc, char *argv[]) int64_t r; /* -n forces newstyle even if someone is still using nbdkit < 1.3 */ char *args[] = { "nbdkit", "-s", "--exit-with-parent", "-n", "-v", - "null", "size=" STR(SIZE), NULL }; + "null", "size=" STR (SIZE), NULL }; const char *s; nbd = nbd_create (); diff --git a/tests/newstyle-limited.c b/tests/newstyle-limited.c index a8f16bc88707..54cba442b28a 100644 --- a/tests/newstyle-limited.c +++ b/tests/newstyle-limited.c @@ -33,7 +33,7 @@ #define SIZE 65536 #define XSTR(s) #s -#define STR(s) XSTR(s) +#define STR(s) XSTR (s) static char wbuf[512] = { 1, 2, 3, 4 }, rbuf[512]; static const char *progname; @@ -105,9 +105,9 @@ main (int argc, char *argv[]) char *args[] = { "nbdkit", "-s", "--mask-handshake", "0", "--exit-with-parent", "-v", "eval", "list_exports=printf a\\nb\\n", - "get_size=echo " STR(SIZE), + "get_size=echo " STR (SIZE), "open=if [ \"$3\" != a ]; then exit 1; fi\n" - " truncate --size=" STR(SIZE) " $tmpdir/a", + " truncate --size=" STR (SIZE) " $tmpdir/a", "pread=dd bs=1 skip=$4 count=$3 if=$tmpdir/a || exit 1", "pwrite=dd bs=1 conv=notrunc seek=$4 of=$tmpdir/a || exit 1", "can_write=exit 0", diff --git a/tests/oldstyle.c b/tests/oldstyle.c index fd8bdc5fdd7c..5667e388d3d2 100644 --- a/tests/oldstyle.c +++ b/tests/oldstyle.c @@ -31,7 +31,7 @@ #define SIZE 65536 #define XSTR(s) #s -#define STR(s) XSTR(s) +#define STR(s) XSTR (s) static char wbuf[512] = { 1, 2, 3, 4 }, rbuf[512]; static const char *progname; @@ -82,7 +82,7 @@ main (int argc, char *argv[]) struct nbd_handle *nbd; int64_t r; char *args[] = { "nbdkit", "-s", "-o", "--exit-with-parent", "-v", - "memory", "size=" STR(SIZE), NULL }; + "memory", "size=" STR (SIZE), NULL }; int calls = 0; const char *s; diff --git a/examples/copy-libev.c b/examples/copy-libev.c index 418d99f1419d..02f9cad492b9 100644 --- a/examples/copy-libev.c +++ b/examples/copy-libev.c @@ -121,12 +121,12 @@ static ev_timer progress; static inline void start_request_soon (struct request *r); static void start_request_cb (struct ev_loop *loop, ev_timer *w, int revents); -static void start_request(struct request *r); -static void start_read(struct request *r); -static void start_write(struct request *r); -static void start_zero(struct request *r); -static int read_completed(void *user_data, int *error); -static int request_completed(void *user_data, int *error); +static void start_request (struct request *r); +static void start_read (struct request *r); +static void start_write (struct request *r); +static void start_zero (struct request *r); +static int read_completed (void *user_data, int *error); +static int request_completed (void *user_data, int *error); /* Return true iff data is all zero bytes. * @@ -158,13 +158,13 @@ request_state (struct request *r) } static inline int -get_fd(struct connection *c) +get_fd (struct connection *c) { return nbd_aio_get_fd (c->nbd); } static inline int -get_events(struct connection *c) +get_events (struct connection *c) { unsigned dir = nbd_aio_get_direction (c->nbd); @@ -388,7 +388,7 @@ start_request_cb (struct ev_loop *loop, ev_timer *w, int revents) /* Start async copy or zero request. */ static void -start_request(struct request *r) +start_request (struct request *r) { /* Cancel the request if we are done. */ if (offset == size) @@ -430,7 +430,7 @@ start_request(struct request *r) } static void -start_read(struct request *r) +start_read (struct request *r) { int64_t cookie; @@ -468,7 +468,7 @@ read_completed (void *user_data, int *error) } static void -start_write(struct request *r) +start_write (struct request *r) { int64_t cookie; @@ -487,7 +487,7 @@ start_write(struct request *r) } static void -start_zero(struct request *r) +start_zero (struct request *r) { int64_t cookie; @@ -535,7 +535,7 @@ request_completed (void *user_data, int *error) * iteration, to avoid deadlock if we need to start a zero or write. */ if (offset < size) - start_request_soon(r); + start_request_soon (r); return 1; } @@ -590,7 +590,7 @@ finish_progress () static inline void update_watcher (struct connection *c) { - int events = get_events(c); + int events = get_events (c); if (events != c->watcher.events) { ev_io_stop (loop, &c->watcher); @@ -671,7 +671,7 @@ main (int argc, char *argv[]) if (r->data == NULL) FAIL ("Cannot allocate buffer: %s", strerror (errno)); - start_request(r); + start_request (r); } /* Start watching events on src and dst handles. */ diff --git a/examples/list-exports.c b/examples/list-exports.c index f6200f480a63..c7780ffd5bb7 100644 --- a/examples/list-exports.c +++ b/examples/list-exports.c @@ -50,7 +50,7 @@ list_one (void *opaque, const char *name, printf ("[%d] %s\n", l->i, name); if (*description) - printf(" (%s)\n", description); + printf (" (%s)\n", description); names = realloc (l->names, (l->i + 1) * sizeof *names); if (!names) { diff --git a/examples/strict-structured-reads.c b/examples/strict-structured-reads.c index 5a61caa8681d..1c9664260654 100644 --- a/examples/strict-structured-reads.c +++ b/examples/strict-structured-reads.c @@ -225,7 +225,7 @@ main (int argc, char *argv[]) assert (d && r); offset = rand () % (exportsize - maxsize); - if (rand() & 1) + if (rand () & 1) flags = LIBNBD_CMD_FLAG_DF; *r = (struct range) { .first = offset, .last = offset + maxsize, }; *d = (struct data) { .offset = offset, .count = maxsize, .flags = flags, diff --git a/examples/threaded-reads-and-writes.c b/examples/threaded-reads-and-writes.c index fd3e677d7d9c..e01727c8d072 100644 --- a/examples/threaded-reads-and-writes.c +++ b/examples/threaded-reads-and-writes.c @@ -248,7 +248,7 @@ start_thread (void *arg) * Simulate a mix of large and small requests. */ while (i > 0 && in_flight < MAX_IN_FLIGHT) { - size = (rand() & 1) ? BUFFER_SIZE : 512; + size = (rand () & 1) ? BUFFER_SIZE : 512; offset = rand () % (exportsize - size); cmd = rand () & 1; if (cmd == 0) diff --git a/interop/interop.c b/interop/interop.c index bd5dc2e19656..371bfc47c672 100644 --- a/interop/interop.c +++ b/interop/interop.c @@ -88,7 +88,7 @@ main (int argc, char *argv[]) * GNUTLS_NO_SIGNAL flag, either because it predates GnuTLS 3.4.2 or * because the OS lacks MSG_NOSIGNAL support. */ -#if TLS && !defined(HAVE_GNUTLS_NO_SIGNAL) +#if TLS && !defined (HAVE_GNUTLS_NO_SIGNAL) signal (SIGPIPE, SIG_IGN); #endif diff --git a/copy/file-ops.c b/copy/file-ops.c index cc225de99d9b..18cae74a617d 100644 --- a/copy/file-ops.c +++ b/copy/file-ops.c @@ -90,7 +90,7 @@ struct rw_file { #ifdef PAGE_CACHE_MAPPING static long page_size; -static void page_size_init (void) __attribute__((constructor)); +static void page_size_init (void) __attribute__ ((constructor)); static void page_size_init (void) { diff --git a/copy/main.c b/copy/main.c index eb10c84dcc5d..ae46b76ef053 100644 --- a/copy/main.c +++ b/copy/main.c @@ -66,7 +66,7 @@ static bool is_nbd_uri (const char *s); static struct rw *open_local (const char *filename, direction d); static void print_rw (struct rw *rw, const char *prefix, FILE *fp); -static void __attribute__((noreturn)) +static void __attribute__ ((noreturn)) usage (FILE *fp, int exitcode) { fprintf (fp, diff --git a/copy/nbdcopy.h b/copy/nbdcopy.h index 9438cce4179b..b6257cc13951 100644 --- a/copy/nbdcopy.h +++ b/copy/nbdcopy.h @@ -116,7 +116,7 @@ struct extent { uint64_t length; bool zero; }; -DEFINE_VECTOR_TYPE(extent_list, struct extent); +DEFINE_VECTOR_TYPE (extent_list, struct extent); /* The operations struct hides some of the differences between local * file, NBD and pipes from the copying code. diff --git a/dump/dump.c b/dump/dump.c index bdbc90401fe2..d0da28790eb7 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -58,7 +58,7 @@ static void do_connect (void); static void do_dump (void); static void catch_signal (int); -static void __attribute__((noreturn)) +static void __attribute__ ((noreturn)) usage (FILE *fp, int exitcode) { fprintf (fp, diff --git a/fuse/nbdfuse.c b/fuse/nbdfuse.c index b9d54abd988a..b18cce83652b 100644 --- a/fuse/nbdfuse.c +++ b/fuse/nbdfuse.c @@ -66,7 +66,7 @@ enum mode { MODE_VSOCK, /* --vsock */ }; -static void __attribute__((noreturn)) +static void __attribute__ ((noreturn)) usage (FILE *fp, int exitcode) { fprintf (fp, diff --git a/info/main.c b/info/main.c index 5cd91fe1a3cf..0b5a5190ba26 100644 --- a/info/main.c +++ b/info/main.c @@ -51,7 +51,7 @@ bool totals = false; /* --totals option */ static enum { MODE_URI = 1, MODE_SQUARE_BRACKET } mode; static char **args; -static void __attribute__((noreturn)) +static void __attribute__ ((noreturn)) usage (FILE *fp, int exitcode) { fprintf (fp, diff --git a/ublk/nbdublk.c b/ublk/nbdublk.c index 00aa23ec03b5..89976fabcb17 100644 --- a/ublk/nbdublk.c +++ b/ublk/nbdublk.c @@ -66,7 +66,7 @@ enum mode { MODE_VSOCK, /* --vsock */ }; -static void __attribute__((noreturn)) +static void __attribute__ ((noreturn)) usage (FILE *fp, int exitcode) { fprintf (fp, @@ -421,7 +421,7 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } - dinfo = ublksrv_ctrl_get_dev_info(dev); + dinfo = ublksrv_ctrl_get_dev_info (dev); /* Register signal handlers to try to stop the device. */ sa.sa_handler = signal_handler; diff --git a/ublk/tgt.c b/ublk/tgt.c index 3fb222333143..5d88e33dcc4b 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; @@ -209,7 +209,7 @@ nbd_work_thread (void *vpinfo) ublksrv_aio_complete_worker (aio_ctx, &compl); - if (nbd_poll2 (h, ublksrv_aio_get_efd(aio_ctx), -1) == -1) { + if (nbd_poll2 (h, ublksrv_aio_get_efd (aio_ctx), -1) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } @@ -223,13 +223,13 @@ io_uring_thread (void *vpinfo) { struct thread_info *thread_info = vpinfo; const struct ublksrv_dev *dev = thread_info->dev; - const struct ublksrv_ctrl_dev *cdev = ublksrv_get_ctrl_dev(dev); - const struct ublksrv_ctrl_dev_info *dinfo = ublksrv_ctrl_get_dev_info(cdev); + const struct ublksrv_ctrl_dev *cdev = ublksrv_get_ctrl_dev (dev); + const struct ublksrv_ctrl_dev_info *dinfo = ublksrv_ctrl_get_dev_info (cdev); const unsigned dev_id = dinfo->dev_id; const size_t q_id = thread_info->i; const struct ublksrv_queue *q; int r; - int tid = gettid(); + int tid = gettid (); pthread_mutex_lock (&jbuf_lock); ublksrv_json_write_queue_info (cdev, jbuf, sizeof jbuf, q_id, tid); @@ -268,7 +268,7 @@ static int set_parameters (struct ublksrv_ctrl_dev *ctrl_dev, const struct ublksrv_dev *dev) { - const struct ublksrv_ctrl_dev_info *dinfo = ublksrv_ctrl_get_dev_info(ctrl_dev); + const struct ublksrv_ctrl_dev_info *dinfo = ublksrv_ctrl_get_dev_info (ctrl_dev); const unsigned attrs (readonly ? UBLK_ATTR_READ_ONLY : 0) | (rotational ? UBLK_ATTR_ROTATIONAL : 0) | @@ -308,7 +308,7 @@ set_parameters (struct ublksrv_ctrl_dev *ctrl_dev, int start_daemon (struct ublksrv_ctrl_dev *ctrl_dev) { - const struct ublksrv_ctrl_dev_info *dinfo = ublksrv_ctrl_get_dev_info(ctrl_dev); + const struct ublksrv_ctrl_dev_info *dinfo = ublksrv_ctrl_get_dev_info (ctrl_dev); const struct ublksrv_dev *dev; size_t i; int r; @@ -421,8 +421,8 @@ start_daemon (struct ublksrv_ctrl_dev *ctrl_dev) static int init_tgt (struct ublksrv_dev *dev, int type, int argc, char *argv[]) { - const struct ublksrv_ctrl_dev *cdev = ublksrv_get_ctrl_dev(dev); - const struct ublksrv_ctrl_dev_info *info = ublksrv_ctrl_get_dev_info(cdev); + const struct ublksrv_ctrl_dev *cdev = ublksrv_get_ctrl_dev (dev); + const struct ublksrv_ctrl_dev_info *info = ublksrv_ctrl_get_dev_info (cdev); struct ublksrv_tgt_info *tgt = &dev->tgt; struct ublksrv_tgt_base_json tgt_json = { .type = type, @@ -439,7 +439,7 @@ init_tgt (struct ublksrv_dev *dev, int type, int argc, char *argv[]) tgt->tgt_ring_depth = info->queue_depth; tgt->nr_fds = 0; - ublksrv_json_write_dev_info (ublksrv_get_ctrl_dev(dev), jbuf, sizeof jbuf); + ublksrv_json_write_dev_info (ublksrv_get_ctrl_dev (dev), jbuf, sizeof jbuf); ublksrv_json_write_target_base_info (jbuf, sizeof jbuf, &tgt_json); return 0;
Eric Blake
2023-Feb-15 19:48 UTC
[Libguestfs] [libnbd PATCH v3 01/29] use space consistently in function and function-like macro invocations
On Wed, Feb 15, 2023 at 03:11:30PM +0100, Laszlo Ersek wrote:> We intend to place a space character between the function designator and > the opening parenthesis in a function call. We've been executing on that > mostly consistently; fix the few exceptions now. > > The same convention should be applied to the invocations of function-like > macros, and to instances of "__attribute__ ((attr))". (The latter is > exemplified, although not consistently, by the GCC manual.) Implement > this, by inserting the necessary spaces. > > Furthermore, some compiler attributes take multiple parameters, such as > "nonnull". The GCC manual clearly shows that arguments passed to such > attributes may be separated with ", " as well, not just ",". Use the > former, as it's more readable. > > Finally, the C standard calls "defined" -- as in "#if defined identifier" > and (equivalently) "#if defined (identifier)" -- a unary preprocessing > operator. We can spell the parenthesized form as "defined (identifier)" > rather than "defined(identifier)", so choose the former. > > I collected the locations possibly missing spaces with: > > git grep -EHn '\<[a-zA-Z0-9_]+\(' -- '*.c' '*.h' > > and then manually updated each as necessary. > > I didn't change occurrences in comments, except where the comment clearly > indicated copying and pasting an expression into new code. > > "git show -w" outputs nothing for this patch.Which would not remain the case if we reflow a long line made longer (see [1] below).> > The test suite passes. > > Signed-off-by: Laszlo Ersek <lersek at redhat.com> > ---> +++ b/lib/internal.h > @@ -46,7 +46,7 @@ > * debug and error handling code out of hot paths, making the hot path > * into common functions use less instruction cache. > */ > -#if defined(__GNUC__) > +#if defined (__GNUC__)In my experience with GNU code (which this is not), the style I've seen there is to omit () whenever possible, as in: #if defined __GNUC__ or even #ifdef __GNUC__ ...> +++ b/common/include/checked-overflow.h > @@ -46,7 +46,7 @@ > #ifndef NBDKIT_CHECKED_OVERFLOW_H > #define NBDKIT_CHECKED_OVERFLOW_H > > -#if !defined(__GNUC__) && !defined(__clang__) > +#if !defined (__GNUC__) && !defined (__clang__)...obviously, the shorter #ifdef version can't be used here, but it could still be shortened to: #if !defined __GNUC__ && !defined __clang__> @@ -173,10 +173,10 @@ > * > * The expression "x" is not evaluated, unless it has variably modified type. > */ > -#define STATIC_ASSERT_UNSIGNED_INT(x) \ > - do { \ > - typedef char NBDKIT_UNIQUE_NAME(_x_has_uint_type)[(typeof (x))-1 > 0 ? 1 : -1] \ > - __attribute__((__unused__)); \ > +#define STATIC_ASSERT_UNSIGNED_INT(x) \ > + do { \ > + typedef char NBDKIT_UNIQUE_NAME (_x_has_uint_type)[(typeof (x))-1 > 0 ? 1 : -1] \ > + __attribute__ ((__unused__)); \[1] This change widened out beyond 80 columns. Is it worth splitting that typedef line in two, perhaps as: typedef char NBDKIT_UNIQUE_NAME (_x_has_uint_type) \ [(typeof (x))-1 > 0 ? 1 : -1] __attribute__ ((__unused__)); \ or does that make it look worse? At any rate, even if we do want to reflow the line to be shorter, you have to consider the commit message blurb about 'git show -w'.> +++ b/common/utils/string-vector.h > @@ -37,6 +37,6 @@ > > #include "vector.h" > > -DEFINE_VECTOR_TYPE(string_vector, char *); > +DEFINE_VECTOR_TYPE (string_vector, char *);We'll want to reflect changes to common files back to nbdkit; but it doesn't hold up the libnbd review.> +++ b/common/include/test-array-size.c > @@ -41,21 +41,21 @@ > > struct st { const char *s; int i; }; > > -static const char *s0[] __attribute__((__unused__)) = { }; > -static const char *s1[] __attribute__((__unused__)) = { "a" }; > -static const char *s3[] __attribute__((__unused__)) = { "a", "b", "c" }; > -static const char *s4[4] __attribute__((__unused__)) = { "a", "b", "c", "d" }; > -static int i0[] __attribute__((__unused__)) = { }; > -static int i1[] __attribute__((__unused__)) = { 1 }; > -static int i3[] __attribute__((__unused__)) = { 1, 2, 3 }; > -static int i4[4] __attribute__((__unused__)) = { 1, 2, 3, 4 }; > -static struct st st0[] __attribute__((__unused__)) = { }; > -static struct st st1[] __attribute__((__unused__)) = { { "a", 1 } }; > -static struct st st3[] __attribute__((__unused__)) > +static const char *s0[] __attribute__ ((__unused__)) = { }; > +static const char *s1[] __attribute__ ((__unused__)) = { "a" }; > +static const char *s3[] __attribute__ ((__unused__)) = { "a", "b", "c" }; > +static const char *s4[4] __attribute__ ((__unused__)) = { "a", "b", "c", "d" };This one is still barely inside 80 columns, but did grab my eye as getting longer.> +++ b/ocaml/nbd-c.h > @@ -32,7 +32,7 @@ > > /* Workaround for OCaml < 4.06.0 */ > #ifndef Bytes_val > -#define Bytes_val(x) String_val(x) > +#define Bytes_val(x) String_val (x) > #endif > > /* Wrapper around caml_alloc_custom_mem for pre-2019 versions of OCaml. */ > @@ -68,7 +68,7 @@ extern void nbd_internal_unix_sockaddr_to_sa (value, struct sockaddr_storage *, > extern void nbd_internal_ocaml_exception_in_wrapper (const char *, value); > > /* Extract an NBD handle from an OCaml heap value. */ > -#define NBD_val(v) (*((struct nbd_handle **)Data_custom_val(v))) > +#define NBD_val(v) (*((struct nbd_handle **)Data_custom_val (v)))Hmm. Another potential cleanup patch (NOT for this one) would be settling on a preferred style for whether the cast prefix operator has a following space. For example, in copy/file-ops.c, we use both styles (git grep ' \*) \?[a-zA-Z]') when casting to a single pointer type (I didn't check double pointers or casts to a type name): copy/file-ops.c: struct rw_file *rwf = (struct rw_file *)rw; copy/file-ops.c: struct rw_file *rwf = (struct rw_file *) rw; copy/file-ops.c: struct rw_file *rwf = (struct rw_file *)rw; copy/file-ops.c: struct rw_file *rwf = (struct rw_file *)rw; copy/file-ops.c: data = (char *) data + r; copy/file-ops.c: struct rw_file *rwf = (struct rw_file *)rw; copy/file-ops.c: data = (char *) data + r; I think I'm a fan of having the space after the cast operator, and as long as we're doing tree-wide cleanups, this would be a good time to inject such a patch if we wanted. Also, it might be cool to have a code formatting tool automatically check that patches conform to a given style (but that presupposes that there is a tool out there that gives us a style we like, or where the differences to our current style are minimal to instead go with one of its builtin styles - AND that such a tool can be present on at least one of the CI machines to avoid regressions). But that's a much bigger task, and I'm not up to doing it myself at the moment. Overall, I don't have any strong reasons to insist on shorter #ifdef spellings, and the rest of your changes, while mechanical, do make the codebase seem more consistent. Tweaking the long line is minor enough that it could be done later if at all. Reviewed-by: Eric Blake <eblake at redhat.com> -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Laszlo Ersek
2023-Feb-22 12:09 UTC
[Libguestfs] [libnbd PATCH v3 01/29] use space consistently in function and function-like macro invocations
On 2/15/23 15:11, Laszlo Ersek wrote:> We intend to place a space character between the function designator and > the opening parenthesis in a function call. We've been executing on that > mostly consistently; fix the few exceptions now. > > The same convention should be applied to the invocations of function-like > macros, and to instances of "__attribute__ ((attr))". (The latter is > exemplified, although not consistently, by the GCC manual.) Implement > this, by inserting the necessary spaces. > > Furthermore, some compiler attributes take multiple parameters, such as > "nonnull". The GCC manual clearly shows that arguments passed to such > attributes may be separated with ", " as well, not just ",". Use the > former, as it's more readable. > > Finally, the C standard calls "defined" -- as in "#if defined identifier" > and (equivalently) "#if defined (identifier)" -- a unary preprocessing > operator. We can spell the parenthesized form as "defined (identifier)" > rather than "defined(identifier)", so choose the former. > > I collected the locations possibly missing spaces with: > > git grep -EHn '\<[a-zA-Z0-9_]+\(' -- '*.c' '*.h' > > and then manually updated each as necessary. > > I didn't change occurrences in comments, except where the comment clearly > indicated copying and pasting an expression into new code. > > "git show -w" outputs nothing for this patch. > > The test suite passes. > > Signed-off-by: Laszlo Ersek <lersek at redhat.com> > --- > lib/internal.h | 72 ++++++++++---------- > lib/nbd-protocol.h | 12 ++-- > common/include/array-size.h | 2 +- > common/include/byte-swapping.h | 24 +++---- > common/include/checked-overflow.h | 42 ++++++------ > common/include/compiler-macros.h | 2 +- > common/include/iszero.h | 2 +- > common/include/minmax.h | 4 +- > common/utils/const-string-vector.h | 2 +- > common/utils/nbdkit-string.h | 2 +- > common/utils/string-vector.h | 2 +- > common/utils/vector.h | 20 +++--- > lib/errors.c | 6 +- > lib/opt.c | 4 +- > lib/uri.c | 2 +- > lib/utils.c | 12 ++-- > common/include/test-array-size.c | 26 +++---- > common/utils/test-human-size.c | 10 +-- > common/utils/test-vector.c | 4 +- > ocaml/nbd-c.h | 6 +- > tests/eflags.c | 6 +- > tests/get-size.c | 4 +- > tests/newstyle-limited.c | 6 +- > tests/oldstyle.c | 4 +- > examples/copy-libev.c | 30 ++++---- > examples/list-exports.c | 2 +- > examples/strict-structured-reads.c | 2 +- > examples/threaded-reads-and-writes.c | 2 +- > interop/interop.c | 2 +- > copy/file-ops.c | 2 +- > copy/main.c | 2 +- > copy/nbdcopy.h | 2 +- > dump/dump.c | 2 +- > fuse/nbdfuse.c | 2 +- > info/main.c | 2 +- > ublk/nbdublk.c | 4 +- > ublk/tgt.c | 20 +++--- > 37 files changed, 175 insertions(+), 175 deletions(-)Merged this patch as commit b5101fbc59cb ("use space consistently in function and function-like macro invocations", 2023-02-22), with Eric's R-b from this thread, and with Rich's R-b from under patch#04. A longer-term subset of the new or newly highlighted tasks I've recorded in another commit: 46d60f807eca ("TODO: coding style and nbdkit code sharing ideas", 2023-02-22). The more direct tasks I've captured in <https://bugzilla.redhat.com/show_bug.cgi?id=2172516>. Laszlo