changeset 1099:2c0eea3af7df

misc: be more pedantic
author David Demelier <markand@malikania.fr>
date Sun, 03 Oct 2021 11:20:47 +0200
parents 6c15d37b7518
children 792730ae5c77
files irccd/dl-plugin.c irccdctl/irccdctl.c tests/test-rule.c
diffstat 3 files changed, 46 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/irccd/dl-plugin.c	Wed Sep 22 15:44:36 2021 +0200
+++ b/irccd/dl-plugin.c	Sun Oct 03 11:20:47 2021 +0200
@@ -32,15 +32,46 @@
 
 #include "dl-plugin.h"
 
+/* Invoke with arguments and return value. */
 #define INVOKE(pg, name, sig, ...)                                              \
 do {                                                                            \
         struct self *self = pg->data;                                           \
         sig fn;                                                                 \
                                                                                 \
-        if (self->handle && (fn = dlsym(self->handle, symbol(self, name))))     \
+        if (self->handle && (fn = (sig)dlsym(self->handle, symbol(self, name))))\
                 return fn(__VA_ARGS__);                                         \
 } while (0)
 
+/* Invoke with argument and without return value. */
+#define INVOKE_NR(pg, name, sig, ...)                                           \
+do {                                                                            \
+        struct self *self = pg->data;                                           \
+        sig fn;                                                                 \
+                                                                                \
+        if (self->handle && (fn = (sig)dlsym(self->handle, symbol(self, name))))\
+                fn(__VA_ARGS__);                                                \
+} while (0)
+
+/* Invoke without arguments and with return value. */
+#define INVOKE_NA(pg, name, sig)                                                \
+do {                                                                            \
+        struct self *self = pg->data;                                           \
+        sig fn;                                                                 \
+                                                                                \
+        if (self->handle && (fn = (sig)dlsym(self->handle, symbol(self, name))))\
+                return fn();                                                    \
+} while (0)
+
+/* Invoke without arguments and without return value. */
+#define INVOKE_NA_NR(pg, name, sig)                                             \
+do {                                                                            \
+        struct self *self = pg->data;                                           \
+        sig fn;                                                                 \
+                                                                                \
+        if (self->handle && (fn = (sig)dlsym(self->handle, symbol(self, name))))\
+                fn();                                                           \
+} while (0)
+
 struct self {
 	struct irc_plugin plugin;
 	char prefix[32];
@@ -85,7 +116,7 @@
 static void
 set_template(struct irc_plugin *plg, const char *key, const char *value)
 {
-	INVOKE(plg, "set_template", set_template_fn, key, value);
+	INVOKE_NR(plg, "set_template", set_template_fn, key, value);
 }
 
 static const char *
@@ -99,7 +130,7 @@
 static const char **
 get_templates(struct irc_plugin *plg)
 {
-	INVOKE(plg, "get_templates", get_templates_fn);
+	INVOKE_NA(plg, "get_templates", get_templates_fn);
 
 	return NULL;
 }
@@ -107,7 +138,7 @@
 static void
 set_path(struct irc_plugin *plg, const char *key, const char *value)
 {
-	INVOKE(plg, "set_path", set_path_fn, key, value);
+	INVOKE_NR(plg, "set_path", set_path_fn, key, value);
 }
 
 static const char *
@@ -121,7 +152,7 @@
 static const char **
 get_paths(struct irc_plugin *plg)
 {
-	INVOKE(plg, "get_paths", get_paths_fn);
+	INVOKE_NA(plg, "get_paths", get_paths_fn);
 
 	return NULL;
 }
@@ -129,7 +160,7 @@
 static void
 set_option(struct irc_plugin *plg, const char *key, const char *value)
 {
-	INVOKE(plg, "set_option", set_option_fn, key, value);
+	INVOKE_NR(plg, "set_option", set_option_fn, key, value);
 }
 
 static const char *
@@ -143,7 +174,7 @@
 static const char **
 get_options(struct irc_plugin *plg)
 {
-	INVOKE(plg, "get_options", get_options_fn);
+	INVOKE_NA(plg, "get_options", get_options_fn);
 
 	return NULL;
 }
@@ -151,7 +182,7 @@
 static int
 load(struct irc_plugin *plg)
 {
-	INVOKE(plg, "load", load_fn);
+	INVOKE_NA(plg, "load", load_fn);
 
 	return 0;
 }
@@ -159,19 +190,19 @@
 static void
 reload(struct irc_plugin *plg)
 {
-	INVOKE(plg, "reload", reload_fn);
+	INVOKE_NA_NR(plg, "reload", reload_fn);
 }
 
 static void
 unload(struct irc_plugin *plg)
 {
-	INVOKE(plg, "unload", unload_fn);
+	INVOKE_NA_NR(plg, "unload", unload_fn);
 }
 
 static void
 handle(struct irc_plugin *plg, const struct irc_event *ev)
 {
-	INVOKE(plg, "event", event_fn, ev);
+	INVOKE_NR(plg, "event", event_fn, ev);
 }
 
 static void
--- a/irccdctl/irccdctl.c	Wed Sep 22 15:44:36 2021 +0200
+++ b/irccdctl/irccdctl.c	Sun Oct 03 11:20:47 2021 +0200
@@ -436,7 +436,7 @@
 static void
 cmd_plugin_config(int argc, char **argv)
 {
-	return plugin_list_set(argc, argv, "PLUGIN-CONFIG");
+	plugin_list_set(argc, argv, "PLUGIN-CONFIG");
 }
 
 /*
@@ -488,7 +488,7 @@
 static void
 cmd_plugin_path(int argc, char **argv)
 {
-	return plugin_list_set(argc, argv, "PLUGIN-PATH");
+	plugin_list_set(argc, argv, "PLUGIN-PATH");
 }
 
 static void
@@ -505,7 +505,7 @@
 static void
 cmd_plugin_template(int argc, char **argv)
 {
-	return plugin_list_set(argc, argv, "PLUGIN-TEMPLATE");
+	plugin_list_set(argc, argv, "PLUGIN-TEMPLATE");
 }
 
 static void
--- a/tests/test-rule.c	Wed Sep 22 15:44:36 2021 +0200
+++ b/tests/test-rule.c	Sun Oct 03 11:20:47 2021 +0200
@@ -163,7 +163,7 @@
 	irc_rule_add(r32->events, "onCommand");
 	irc_rule_add(r32->events, "onMessage");
 	irc_bot_rule_insert(r32, -1);
-};
+}
 
 GREATEST_TEST
 solve_match1(void)