From cba95b2b30bcf1565969de702a1b1161bff25011 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 30 Jan 2022 19:19:20 +0100 Subject: [PATCH] [event] union for const/non-const void * --- src/bookmarks/bookmarks.c | 8 ++++---- src/config/urlhist.c | 2 +- src/globhist/globhist.c | 2 +- src/main/event.c | 2 +- src/main/event.h | 7 +++++-- src/protocol/rewrite/rewrite.c | 2 +- src/scripting/guile/hooks.c | 10 +++++----- src/scripting/lua/hooks.c | 14 +++++++------- src/scripting/perl/hooks.c | 10 +++++----- src/scripting/python/hooks.c | 16 ++++++++-------- src/scripting/ruby/hooks.c | 10 +++++----- src/scripting/smjs/hooks.c | 6 +++--- src/viewer/text/search.c | 2 +- 13 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/bookmarks/bookmarks.c b/src/bookmarks/bookmarks.c index 12a37a89..4032cb63 100644 --- a/src/bookmarks/bookmarks.c +++ b/src/bookmarks/bookmarks.c @@ -87,10 +87,10 @@ static enum evhook_status bookmark_change_hook(va_list ap, void *data); static enum evhook_status bookmark_write_hook(va_list ap, void *data); struct event_hook_info bookmark_hooks[] = { - { C_("bookmark-delete"), 0, bookmark_change_hook, NULL }, - { C_("bookmark-move"), 0, bookmark_change_hook, NULL }, - { C_("bookmark-update"), 0, bookmark_change_hook, NULL }, - { C_("periodic-saving"), 0, bookmark_write_hook, NULL }, + { C_("bookmark-delete"), 0, bookmark_change_hook, {NULL} }, + { C_("bookmark-move"), 0, bookmark_change_hook, {NULL} }, + { C_("bookmark-update"), 0, bookmark_change_hook, {NULL} }, + { C_("periodic-saving"), 0, bookmark_write_hook, {NULL} }, NULL_EVENT_HOOK_INFO, }; diff --git a/src/config/urlhist.c b/src/config/urlhist.c index 22259db9..9b892f19 100644 --- a/src/config/urlhist.c +++ b/src/config/urlhist.c @@ -39,7 +39,7 @@ goto_url_history_write_hook(va_list ap, void *data) } static struct event_hook_info goto_url_history_hooks[] = { - { "periodic-saving", 0, goto_url_history_write_hook, NULL }, + { "periodic-saving", 0, goto_url_history_write_hook, {NULL} }, NULL_EVENT_HOOK_INFO, }; diff --git a/src/globhist/globhist.c b/src/globhist/globhist.c index 157ae6b1..68c45b8c 100644 --- a/src/globhist/globhist.c +++ b/src/globhist/globhist.c @@ -425,7 +425,7 @@ global_history_write_hook(va_list ap, void *data) } struct event_hook_info global_history_hooks[] = { - { "periodic-saving", 0, global_history_write_hook, NULL }, + { "periodic-saving", 0, global_history_write_hook, {NULL} }, NULL_EVENT_HOOK_INFO, }; diff --git a/src/main/event.c b/src/main/event.c index 60a19df3..f2df4a31 100644 --- a/src/main/event.c +++ b/src/main/event.c @@ -289,7 +289,7 @@ register_event_hooks(struct event_hook_info *hooks) if (id == EVENT_NONE) continue; register_event_hook(id, hooks[i].callback, hooks[i].priority, - hooks[i].data); + hooks[i].adata); } } diff --git a/src/main/event.h b/src/main/event.h index 840f8738..87d4e567 100644 --- a/src/main/event.h +++ b/src/main/event.h @@ -79,10 +79,13 @@ struct event_hook_info { const char *name; int priority; event_hook_T callback; - void *data; + union { + const void *data; + void *adata; + }; }; -#define NULL_EVENT_HOOK_INFO { NULL, 0, NULL, NULL } +#define NULL_EVENT_HOOK_INFO { NULL, 0, NULL, {NULL} } void register_event_hooks(struct event_hook_info *hooks); void unregister_event_hooks(struct event_hook_info *hooks); diff --git a/src/protocol/rewrite/rewrite.c b/src/protocol/rewrite/rewrite.c index 7675d98c..f339eea9 100644 --- a/src/protocol/rewrite/rewrite.c +++ b/src/protocol/rewrite/rewrite.c @@ -339,7 +339,7 @@ goto_url_hook(va_list ap, void *data) } struct event_hook_info uri_rewrite_hooks[] = { - { "goto-url", -1, goto_url_hook }, + { "goto-url", -1, goto_url_hook, {NULL} }, NULL_EVENT_HOOK_INFO }; diff --git a/src/scripting/guile/hooks.c b/src/scripting/guile/hooks.c index f481a880..097e1d7d 100644 --- a/src/scripting/guile/hooks.c +++ b/src/scripting/guile/hooks.c @@ -184,10 +184,10 @@ script_hook_quit(va_list ap, void *data) } struct event_hook_info guile_scripting_hooks[] = { - { "goto-url", 0, script_hook_goto_url, NULL }, - { "follow-url", 0, script_hook_follow_url, NULL }, - { "pre-format-html", 0, script_hook_pre_format_html, NULL }, - { "get-proxy", 0, script_hook_get_proxy, NULL }, - { "quit", 0, script_hook_quit, NULL }, + { "goto-url", 0, script_hook_goto_url, {NULL} }, + { "follow-url", 0, script_hook_follow_url, {NULL} }, + { "pre-format-html", 0, script_hook_pre_format_html, {NULL} }, + { "get-proxy", 0, script_hook_get_proxy, {NULL} }, + { "quit", 0, script_hook_quit, {NULL} }, NULL_EVENT_HOOK_INFO, }; diff --git a/src/scripting/lua/hooks.c b/src/scripting/lua/hooks.c index 0d2a9a4f..338a028b 100644 --- a/src/scripting/lua/hooks.c +++ b/src/scripting/lua/hooks.c @@ -235,12 +235,12 @@ script_hook_quit(va_list ap, void *data) } struct event_hook_info lua_scripting_hooks[] = { - { "goto-url", 0, script_hook_goto_url, NULL }, - { "follow-url", 0, script_hook_follow_url, NULL }, - { "pre-format-html", 0, script_hook_pre_format_html, NULL }, - { "get-proxy", 0, script_hook_get_proxy, NULL }, - { "quit", 0, script_hook_quit, NULL }, - { "dialog-lua-console", 0, dialog_lua_console, NULL }, - { "free-history", 0, free_lua_console_history, NULL }, + { "goto-url", 0, script_hook_goto_url, {NULL} }, + { "follow-url", 0, script_hook_follow_url, {NULL} }, + { "pre-format-html", 0, script_hook_pre_format_html, {NULL} }, + { "get-proxy", 0, script_hook_get_proxy, {NULL} }, + { "quit", 0, script_hook_quit, {NULL} }, + { "dialog-lua-console", 0, dialog_lua_console, {NULL} }, + { "free-history", 0, free_lua_console_history, {NULL} }, NULL_EVENT_HOOK_INFO, }; diff --git a/src/scripting/perl/hooks.c b/src/scripting/perl/hooks.c index 5b52d085..8abd415a 100644 --- a/src/scripting/perl/hooks.c +++ b/src/scripting/perl/hooks.c @@ -237,10 +237,10 @@ script_hook_quit(va_list ap, void *data) } struct event_hook_info perl_scripting_hooks[] = { - { "goto-url", 0, script_hook_goto_url, NULL }, - { "follow-url", 0, script_hook_follow_url, NULL }, - { "pre-format-html", 0, script_hook_pre_format_html, NULL }, - { "get-proxy", 0, script_hook_get_proxy, NULL }, - { "quit", 0, script_hook_quit, NULL }, + { "goto-url", 0, script_hook_goto_url, {NULL} }, + { "follow-url", 0, script_hook_follow_url, {NULL} }, + { "pre-format-html", 0, script_hook_pre_format_html, {NULL} }, + { "get-proxy", 0, script_hook_get_proxy, {NULL} }, + { "quit", 0, script_hook_quit, {NULL} }, NULL_EVENT_HOOK_INFO, }; diff --git a/src/scripting/python/hooks.c b/src/scripting/python/hooks.c index ceb85a4b..06b38589 100644 --- a/src/scripting/python/hooks.c +++ b/src/scripting/python/hooks.c @@ -144,7 +144,7 @@ script_hook_pre_format_html(va_list ap, void *data) struct fragment *fragment = get_cache_fragment(cached); char *url = struri(cached->uri); int codepage = get_codepage(cached->head); - char *method = "pre_format_html_hook"; + const char *method = "pre_format_html_hook"; struct session *saved_python_ses = python_ses; PyObject *result = NULL; int success = 0; @@ -264,7 +264,7 @@ script_hook_get_proxy(va_list ap, void *data) { char **proxy = va_arg(ap, char **); char *url = va_arg(ap, char *); - char *method = "proxy_for_hook"; + const char *method = "proxy_for_hook"; PyObject *result; evhook_use_params(proxy && url); @@ -288,7 +288,7 @@ script_hook_get_proxy(va_list ap, void *data) static enum evhook_status script_hook_quit(va_list ap, void *data) { - char *method = "quit_hook"; + const char *method = "quit_hook"; PyObject *result; if (!python_hooks || !PyObject_HasAttrString(python_hooks, method)) @@ -303,10 +303,10 @@ script_hook_quit(va_list ap, void *data) } struct event_hook_info python_scripting_hooks[] = { - { "goto-url", 0, script_hook_url, "goto_url_hook" }, - { "follow-url", 0, script_hook_url, "follow_url_hook" }, - { "pre-format-html", 0, script_hook_pre_format_html, NULL }, - { "get-proxy", 0, script_hook_get_proxy, NULL }, - { "quit", 0, script_hook_quit, NULL }, + { "goto-url", 0, script_hook_url, {"goto_url_hook"} }, + { "follow-url", 0, script_hook_url, {"follow_url_hook"} }, + { "pre-format-html", 0, script_hook_pre_format_html, {NULL} }, + { "get-proxy", 0, script_hook_get_proxy, {NULL} }, + { "quit", 0, script_hook_quit, {NULL} }, NULL_EVENT_HOOK_INFO, }; diff --git a/src/scripting/ruby/hooks.c b/src/scripting/ruby/hooks.c index 8f879ef0..cc49ba7e 100644 --- a/src/scripting/ruby/hooks.c +++ b/src/scripting/ruby/hooks.c @@ -247,11 +247,11 @@ script_hook_quit(va_list ap, void *data) } struct event_hook_info ruby_scripting_hooks[] = { - { "goto-url", 0, script_hook_goto_url, NULL }, - { "follow-url", 0, script_hook_follow_url, NULL }, - { "pre-format-html", 0, script_hook_pre_format_html, NULL }, - { "get-proxy", 0, script_hook_get_proxy, NULL }, - { "quit", 0, script_hook_quit, NULL }, + { "goto-url", 0, script_hook_goto_url, {NULL} }, + { "follow-url", 0, script_hook_follow_url, {NULL} }, + { "pre-format-html", 0, script_hook_pre_format_html, {NULL} }, + { "get-proxy", 0, script_hook_get_proxy, {NULL} }, + { "quit", 0, script_hook_quit, {NULL} }, NULL_EVENT_HOOK_INFO, }; diff --git a/src/scripting/smjs/hooks.c b/src/scripting/smjs/hooks.c index 90079108..b086dbc7 100644 --- a/src/scripting/smjs/hooks.c +++ b/src/scripting/smjs/hooks.c @@ -102,9 +102,9 @@ end: } struct event_hook_info smjs_scripting_hooks[] = { - { "goto-url", 0, script_hook_url, "goto_url_hook" }, - { "follow-url", 0, script_hook_url, "follow_url_hook" }, - { "pre-format-html", 0, script_hook_pre_format_html, NULL }, + { "goto-url", 0, script_hook_url, {"goto_url_hook"} }, + { "follow-url", 0, script_hook_url, {"follow_url_hook"} }, + { "pre-format-html", 0, script_hook_pre_format_html, {NULL} }, NULL_EVENT_HOOK_INFO, }; diff --git a/src/viewer/text/search.c b/src/viewer/text/search.c index 9336d40a..c97bcbc2 100644 --- a/src/viewer/text/search.c +++ b/src/viewer/text/search.c @@ -2010,7 +2010,7 @@ search_history_write_hook(va_list ap, void *data) } static struct event_hook_info search_history_hooks[] = { - { "periodic-saving", 0, search_history_write_hook, NULL }, + { "periodic-saving", 0, search_history_write_hook, {NULL} }, NULL_EVENT_HOOK_INFO, };