From eba7755248f3c042238cf319676dead0dcc785c6 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 3 Feb 2016 15:18:33 -0800 Subject: [PATCH] vlog: Simplify module definition. Until now, vlog had a macro VLOG_DEFINE_THIS_MODULE, which expanded using VLOG_DEFINE_MODULE, which expanded using VLOG_DEFINE_MODULE__, and the latter macros didn't have any other users. This commit combines them for clarity. Signed-off-by: Ben Pfaff Acked-by: Russell Bryant --- include/openvswitch/vlog.h | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/include/openvswitch/vlog.h b/include/openvswitch/vlog.h index 739c049a8..899ad4664 100644 --- a/include/openvswitch/vlog.h +++ b/include/openvswitch/vlog.h @@ -88,13 +88,6 @@ struct vlog_module { void vlog_insert_module(struct ovs_list *); -/* Creates and initializes a global instance of a module named MODULE. */ -#define VLOG_DEFINE_MODULE(MODULE) \ - VLOG_DEFINE_MODULE__(MODULE) \ - OVS_CONSTRUCTOR(init_##MODULE) { \ - vlog_insert_module(&VLM_##MODULE.list); \ - } \ - const char *vlog_get_module_name(const struct vlog_module *); struct vlog_module *vlog_module_from_name(const char *name); @@ -181,12 +174,24 @@ void vlog_rate_limit(const struct vlog_module *, enum vlog_level, * defines a static variable named THIS_MODULE that points to it, for use with * the convenience macros below. */ #define VLOG_DEFINE_THIS_MODULE(MODULE) \ - VLOG_DEFINE_MODULE(MODULE); \ + /* This extra "extern" declaration makes sparse happy. */ \ + extern struct vlog_module VLM_##MODULE; \ + struct vlog_module VLM_##MODULE = \ + { \ + OVS_LIST_INITIALIZER(&VLM_##MODULE.list), \ + #MODULE, /* name */ \ + { VLL_INFO, VLL_INFO, VLL_INFO }, /* levels */ \ + VLL_INFO, /* min_level */ \ + true /* honor_rate_limits */ \ + }; \ + OVS_CONSTRUCTOR(init_##MODULE) { \ + vlog_insert_module(&VLM_##MODULE.list); \ + } \ static struct vlog_module *const THIS_MODULE = &VLM_##MODULE /* Convenience macros. These assume that THIS_MODULE points to a "struct * vlog_module" for the current module, as set up by e.g. the - * VLOG_DEFINE_MODULE macro above. + * VLOG_DEFINE_THIS_MODULE macro above. * * Guaranteed to preserve errno. */ @@ -289,17 +294,6 @@ void vlog_usage(void); } \ } while (0) -#define VLOG_DEFINE_MODULE__(MODULE) \ - extern struct vlog_module VLM_##MODULE; \ - struct vlog_module VLM_##MODULE = \ - { \ - OVS_LIST_INITIALIZER(&VLM_##MODULE.list), \ - #MODULE, /* name */ \ - { VLL_INFO, VLL_INFO, VLL_INFO }, /* levels */ \ - VLL_INFO, /* min_level */ \ - true /* honor_rate_limits */ \ - }; - #ifdef __cplusplus } #endif -- 2.20.1