From: Mark Wielaard Date: Fri, 1 Apr 2011 13:59:27 +0000 (+0200) Subject: dwarflint: Turn global_opts into a static initializer function. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4b63527e857a148e21e3ed5073a491a103970fee;p=thirdparty%2Felfutils.git dwarflint: Turn global_opts into a static initializer function. Trick to make sure the static options are always initialized before access (it is used from various global initializers). --- diff --git a/dwarflint/option.cc b/dwarflint/option.cc index 420493eee..d87d22fde 100644 --- a/dwarflint/option.cc +++ b/dwarflint/option.cc @@ -92,7 +92,7 @@ argppp & argppp::inst () { static argppp my - (global_opts, dwarflint::main_registrar ()->get_descriptors ()); + (global_opts (), dwarflint::main_registrar ()->get_descriptors ()); return my; } @@ -165,7 +165,7 @@ void argppp::parse (int argc, char **argv, unsigned flags, int *remaining) { assert (!_m_inited); - argp_parse (&_m_argp, argc, argv, flags, remaining, &global_opts); + argp_parse (&_m_argp, argc, argv, flags, remaining, &global_opts ()); } void @@ -209,4 +209,12 @@ option_common::option_common (char const *description, , _m_seen (false) {} -options global_opts; +// Trick to make sure the static options are always initialized +// before access (it is used from various global initializers. + +options & +global_opts () +{ + static options inst; + return inst; +} diff --git a/dwarflint/option.hh b/dwarflint/option.hh index 8016811fc..7afe10ca7 100644 --- a/dwarflint/option.hh +++ b/dwarflint/option.hh @@ -218,7 +218,7 @@ typedef xoption void_option; typedef xoption string_option; typedef xoption unsigned_option; -extern options global_opts; +options & global_opts (); template struct global_opt @@ -228,7 +228,7 @@ struct global_opt global_opt (Args const&... args) : OPT (args...) { - global_opts.add (this); + global_opts ().add (this); } };