[Libguestfs] [PATCH libnbd 4/4] lib: Add CALL_CALLBACK macro.
Eric Blake
eblake at redhat.com
Wed Aug 14 13:07:10 UTC 2019
On 8/13/19 5:37 PM, Richard W.M. Jones wrote:
> Another simple internal macro, this time encapsulating calling a
> callback.
> ---
> generator/states-reply-simple.c | 8 ++++----
> generator/states-reply-structured.c | 31 ++++++++++++++---------------
> generator/states-reply.c | 2 +-
> generator/states.c | 2 +-
> lib/debug.c | 2 +-
> lib/internal.h | 4 ++++
> 6 files changed, 26 insertions(+), 23 deletions(-)
>
> diff --git a/generator/states-reply-simple.c b/generator/states-reply-simple.c
> index 8905367..8e3d7f1 100644
> --- a/generator/states-reply-simple.c
> +++ b/generator/states-reply-simple.c
> @@ -64,10 +64,10 @@
> int error = 0;
>
> assert (cmd->error == 0);
> - if (cmd->cb.fn.chunk.callback (cmd->cb.fn.chunk.user_data,
> - cmd->data, cmd->count,
> - cmd->offset, LIBNBD_READ_DATA,
> - &error) == -1)
> + if (CALL_CALLBACK (cmd->cb.fn.chunk,
> + cmd->data, cmd->count,
> + cmd->offset, LIBNBD_READ_DATA,
> + &error) == -1)
Reduces line length, and we have lots of call sites; this one is
actually more useful than 3 if we're going for ease of typing of a
common pattern.
> +++ b/lib/internal.h
> @@ -273,6 +273,10 @@ struct command {
> uint32_t error; /* Local errno value */
> };
>
> +/* Call a callback. */
> +#define CALL_CALLBACK(cb, ...) \
> + (cb).callback ((cb).user_data, ##__VA_ARGS__)
And this one doesn't risk any nasty type-punning issues.
ACK
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190814/fed6ecce/attachment.sig>
More information about the Libguestfs
mailing list