]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Turn global_opts into a static initializer function.
authorMark Wielaard <mjw@redhat.com>
Fri, 1 Apr 2011 13:59:27 +0000 (15:59 +0200)
committerMark Wielaard <mjw@redhat.com>
Fri, 1 Apr 2011 13:59:27 +0000 (15:59 +0200)
Trick to make sure the static options are always initialized
before access (it is used from various global initializers).

dwarflint/option.cc
dwarflint/option.hh

index 420493eeea085b5cee10995ab83895fbaa13926a..d87d22fde66a47c6acf68a736b6f50cdc02cabd0 100644 (file)
@@ -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;
+}
index 8016811fc626b70479d9cafb555988f9b16b2812..7afe10ca7c3371963343beba3bd2a62ec92e1935 100644 (file)
@@ -218,7 +218,7 @@ typedef xoption<void> void_option;
 typedef xoption<std::string> string_option;
 typedef xoption<unsigned> unsigned_option;
 
-extern options global_opts;
+options & global_opts ();
 
 template<class OPT>
 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);
   }
 };