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