Use init_ExeContext_storage instead of relying (unintentionally) on
properties of 'static'.  Also, de-globalise this function.  Some days
I really yearn for a proper module system in C.  Come back Haskell,
all is forgiven :-)


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1781 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/vg_execontext.c b/coregrind/vg_execontext.c
index c588a1b..4fa6b9f 100644
--- a/coregrind/vg_execontext.c
+++ b/coregrind/vg_execontext.c
@@ -63,9 +63,12 @@
 
 
 /* Initialise this subsystem. */
-void VG_(init_ExeContext_storage) ( void )
+static void init_ExeContext_storage ( void )
 {
    Int i;
+   static Bool init_done = False;
+   if (init_done)
+      return;
    vg_ec_searchreqs = 0;
    vg_ec_searchcmps = 0;
    vg_ec_totstored = 0;
@@ -74,12 +77,14 @@
    vg_ec_cmpAlls = 0;
    for (i = 0; i < VG_N_EC_LISTS; i++)
       vg_ec_list[i] = NULL;
+   init_done = True;
 }
 
 
 /* Show stats. */
 void VG_(show_ExeContext_stats) ( void )
 {
+   init_ExeContext_storage();
    VG_(message)(Vg_DebugMsg, 
       "exectx: %d lists, %d contexts (avg %d per list)",
       VG_N_EC_LISTS, vg_ec_totstored, 
@@ -103,6 +108,7 @@
 /* Print an ExeContext. */
 void VG_(pp_ExeContext) ( ExeContext* e )
 {
+   init_ExeContext_storage();
    VG_(mini_stack_dump) ( e );
 }
 
@@ -169,6 +175,7 @@
 
    VGP_PUSHCC(VgpExeContext);
 
+   init_ExeContext_storage();
    vg_assert(VG_(clo_backtrace_size) >= 2 
              && VG_(clo_backtrace_size) <= VG_DEEPEST_BACKTRACE);
 
diff --git a/coregrind/vg_include.h b/coregrind/vg_include.h
index aeb5c23..bc8ce86 100644
--- a/coregrind/vg_include.h
+++ b/coregrind/vg_include.h
@@ -1154,9 +1154,6 @@
 };
 
 
-/* Initialise the ExeContext storage mechanism. */
-extern void VG_(init_ExeContext_storage) ( void );
-
 /* Print stats (informational only). */
 extern void VG_(show_ExeContext_stats) ( void );