Subject: [dtn-users] gcc bug and dtn

From: Lana Black <[email-masked]>
Date: Thu, 7 Mar 2013 09:14:12 +0000

Hi,

DTN code currently relies on a gcc bug in order to be built (please see
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21534). The patch attached 
allows DTN to be built using other than gcc compilers.

With best regards.
diff --git a/apps/dtntunnel/DTNTunnel.cc b/apps/dtntunnel/DTNTunnel.cc
index e631a18..436861e 100644
--- a/apps/dtntunnel/DTNTunnel.cc
+++ b/apps/dtntunnel/DTNTunnel.cc
@@ -39,10 +39,10 @@
 #include "TCPTunnel.h"
 #include "UDPTunnel.h"
 
-namespace dtntunnel {
-
 template <>
-DTNTunnel* oasys::Singleton<DTNTunnel>::instance_ = 0;
+dtntunnel::DTNTunnel* oasys::Singleton<dtntunnel::DTNTunnel>::instance_ = 0;
+
+namespace dtntunnel {
 
 //----------------------------------------------------------------------
 DTNTunnel::DTNTunnel()
diff --git a/servlib/bundling/APIBlockProcessor.cc b/servlib/bundling/APIBlockProcessor.cc
index 56014f8..0338d6c 100644
--- a/servlib/bundling/APIBlockProcessor.cc
+++ b/servlib/bundling/APIBlockProcessor.cc
@@ -23,11 +23,11 @@
 #include "BlockInfo.h"
 #include "BundleProtocol.h"
 
+template <> dtn::APIBlockProcessor*
+oasys::Singleton<dtn::APIBlockProcessor>::instance_ = NULL;
+
 namespace dtn {
 
-template <> APIBlockProcessor*
-oasys::Singleton<APIBlockProcessor>::instance_ = NULL;
-        
 //----------------------------------------------------------------------
 APIBlockProcessor::APIBlockProcessor() :
         BlockProcessor(BundleProtocol::API_EXTENSION_BLOCK)
diff --git a/servlib/bundling/BundleDaemon.cc b/servlib/bundling/BundleDaemon.cc
index d507528..da7b224 100644
--- a/servlib/bundling/BundleDaemon.cc
+++ b/servlib/bundling/BundleDaemon.cc
@@ -54,10 +54,10 @@
 #  include "security/KeyDB.h"
 #endif
 
-namespace dtn {
-
 template <>
-BundleDaemon* oasys::Singleton<BundleDaemon, false>::instance_ = NULL;
+dtn::BundleDaemon* oasys::Singleton<dtn::BundleDaemon, false>::instance_ = NULL;
+
+namespace dtn {
 
 BundleDaemon::Params::Params()
     :  early_deletion_(true),
@@ -146,6 +146,19 @@ BundleDaemon::do_init()
 
 //----------------------------------------------------------------------
 void
+BundleDaemon::init()
+{       
+    if (instance_ != NULL) 
+    {
+        PANIC("BundleDaemon already initialized");
+    }
+
+    instance_ = new BundleDaemon();     
+    instance_->do_init();
+}
+
+//----------------------------------------------------------------------
+void
 BundleDaemon::post(BundleEvent* event)
 {
     instance_->post_event(event);
diff --git a/servlib/bundling/BundleDaemon.h b/servlib/bundling/BundleDaemon.h
index 6f0976a..787001b 100644
--- a/servlib/bundling/BundleDaemon.h
+++ b/servlib/bundling/BundleDaemon.h
@@ -88,16 +88,7 @@ public:
     /**
      * Boot time initializer.
      */
-    static void init()
-    {       
-        if (instance_ != NULL) 
-        {
-            PANIC("BundleDaemon already initialized");
-        }
-
-        instance_ = new BundleDaemon();     
-        instance_->do_init();
-    }
+    static void init();
     
     /**
      * Return the number of events currently waiting for processing.
diff --git a/servlib/bundling/UnknownBlockProcessor.cc b/servlib/bundling/UnknownBlockProcessor.cc
index 39e39bf..f210ffe 100644
--- a/servlib/bundling/UnknownBlockProcessor.cc
+++ b/servlib/bundling/UnknownBlockProcessor.cc
@@ -24,10 +24,10 @@
 #include "BundleProtocol.h"
 #include "Bundle.h"
 
-namespace dtn {
+template <> dtn::UnknownBlockProcessor*
+oasys::Singleton<dtn::UnknownBlockProcessor>::instance_ = NULL;
 
-template <> UnknownBlockProcessor*
-oasys::Singleton<UnknownBlockProcessor>::instance_ = NULL;
+namespace dtn {
 
 //----------------------------------------------------------------------
 UnknownBlockProcessor::UnknownBlockProcessor()
diff --git a/servlib/cmd/CompletionNotifier.cc b/servlib/cmd/CompletionNotifier.cc
index b398ebf..478110f 100644
--- a/servlib/cmd/CompletionNotifier.cc
+++ b/servlib/cmd/CompletionNotifier.cc
@@ -20,9 +20,6 @@
 
 #include "CompletionNotifier.h"
 
-namespace dtn {
-
 template <>
-CompletionNotifier* oasys::Singleton<CompletionNotifier>::instance_ = 0;
+dtn::CompletionNotifier* oasys::Singleton<dtn::CompletionNotifier>::instance_ = 0;
 
-} // namespace dtn
diff --git a/servlib/conv_layers/ConvergenceLayer.cc b/servlib/conv_layers/ConvergenceLayer.cc
index 352530e..0736ec2 100644
--- a/servlib/conv_layers/ConvergenceLayer.cc
+++ b/servlib/conv_layers/ConvergenceLayer.cc
@@ -32,10 +32,10 @@
 
 #include "bundling/BundleDaemon.h"
 
-namespace dtn {
-
 template<>
-CLVector* oasys::Singleton<CLVector>::instance_ = NULL;
+dtn::CLVector* oasys::Singleton<dtn::CLVector>::instance_ = NULL;
+
+namespace dtn {
 
 //----------------------------------------------------------------------
 ConvergenceLayer::~ConvergenceLayer()
diff --git a/servlib/discovery/DiscoveryTable.cc b/servlib/discovery/DiscoveryTable.cc
index 57b0176..818659d 100644
--- a/servlib/discovery/DiscoveryTable.cc
+++ b/servlib/discovery/DiscoveryTable.cc
@@ -22,10 +22,10 @@
 #include "DiscoveryTable.h"
 #include "conv_layers/ConvergenceLayer.h"
 
-namespace dtn {
-
 template<>
-DiscoveryTable* oasys::Singleton<DiscoveryTable,false>::instance_ = NULL;
+dtn::DiscoveryTable* oasys::Singleton<dtn::DiscoveryTable,false>::instance_ = NULL;
+
+namespace dtn {
 
 DiscoveryTable::DiscoveryTable()
     : Logger("DiscoveryTable","/dtn/discovery/table")
@@ -37,6 +37,17 @@ DiscoveryTable::~DiscoveryTable()
 }
 
 void
+DiscoveryTable::init()
+{
+    if (instance_ != NULL)
+    {
+        PANIC("DiscoveryTable already initialized");
+    }
+    instance_ = new DiscoveryTable();
+}
+
+
+void
 DiscoveryTable::shutdown()
 {
     for(DiscoveryList::iterator i = dlist_.begin();
diff --git a/servlib/discovery/DiscoveryTable.h b/servlib/discovery/DiscoveryTable.h
index c7a1bb9..2986ac2 100644
--- a/servlib/discovery/DiscoveryTable.h
+++ b/servlib/discovery/DiscoveryTable.h
@@ -34,14 +34,7 @@ class DiscoveryTable : public oasys::Singleton<DiscoveryTable,false>,
 public:
     virtual ~DiscoveryTable();
 
-    static void init()
-    {
-        if (instance_ != NULL)
-        {
-            PANIC("DiscoveryTable already initialized");
-        }
-        instance_ = new DiscoveryTable();
-    }
+    static void init();
 
     bool add(const std::string& name, const char* addr_family,
              int argc, const char* argv[], const char** error);
diff --git a/servlib/naming/DTNScheme.cc b/servlib/naming/DTNScheme.cc
index 88c276b..e277585 100644
--- a/servlib/naming/DTNScheme.cc
+++ b/servlib/naming/DTNScheme.cc
@@ -25,10 +25,10 @@
 #include "DTNScheme.h"
 #include "EndpointID.h"
 
-namespace dtn {
-
 template <>
-DTNScheme* oasys::Singleton<DTNScheme>::instance_ = 0;
+dtn::DTNScheme* oasys::Singleton<dtn::DTNScheme>::instance_ = 0;
+
+namespace dtn {
 
 //----------------------------------------------------------------------
 bool
diff --git a/servlib/naming/EthernetScheme.cc b/servlib/naming/EthernetScheme.cc
index 064e369..40eddc4 100644
--- a/servlib/naming/EthernetScheme.cc
+++ b/servlib/naming/EthernetScheme.cc
@@ -26,10 +26,10 @@
 #include "EthernetScheme.h"
 #include "EndpointID.h"
 
-namespace dtn {
-
 template <>
-EthernetScheme* oasys::Singleton<EthernetScheme>::instance_ = 0;
+dtn::EthernetScheme* oasys::Singleton<dtn::EthernetScheme>::instance_ = 0;
+
+namespace dtn {
 
 /*
  * Parse out an ethernet address from the ssp.
diff --git a/servlib/naming/IPNScheme.cc b/servlib/naming/IPNScheme.cc
index 6436d1a..66cbda4 100644
--- a/servlib/naming/IPNScheme.cc
+++ b/servlib/naming/IPNScheme.cc
@@ -8,10 +8,10 @@
 #include "IPNScheme.h"
 #include "EndpointID.h"
 
-namespace dtn {
+template <>
+dtn::IPNScheme* oasys::Singleton<dtn::IPNScheme>::instance_ = 0;
 
-        template <>
-        IPNScheme* oasys::Singleton<IPNScheme>::instance_ = 0;
+namespace dtn {
 
         bool
         IPNScheme::validate(const URI& uri, bool is_pattern)
diff --git a/servlib/naming/SchemeTable.cc b/servlib/naming/SchemeTable.cc
index 49d6166..2f88d57 100644
--- a/servlib/naming/SchemeTable.cc
+++ b/servlib/naming/SchemeTable.cc
@@ -27,10 +27,10 @@
 #include "WildcardScheme.h"
 #include "TCAScheme.h"
 
-namespace dtn {
-
 template <>
-SchemeTable* oasys::Singleton<SchemeTable>::instance_ = 0;
+dtn::SchemeTable* oasys::Singleton<dtn::SchemeTable>::instance_ = 0;
+
+namespace dtn {
 
 //----------------------------------------------------------------------
 SchemeTable::SchemeTable()
diff --git a/servlib/naming/SessionScheme.cc b/servlib/naming/SessionScheme.cc
index 235ff83..b4ff5c4 100644
--- a/servlib/naming/SessionScheme.cc
+++ b/servlib/naming/SessionScheme.cc
@@ -25,10 +25,10 @@
 #include "SessionScheme.h"
 #include "EndpointID.h"
 
-namespace dtn {
-
 template <>
-SessionScheme* oasys::Singleton<SessionScheme>::instance_ = 0;
+dtn::SessionScheme* oasys::Singleton<dtn::SessionScheme>::instance_ = 0;
+
+namespace dtn {
 
 //----------------------------------------------------------------------
 bool
diff --git a/servlib/naming/StringScheme.cc b/servlib/naming/StringScheme.cc
index d85bd52..f6cae00 100755
--- a/servlib/naming/StringScheme.cc
+++ b/servlib/naming/StringScheme.cc
@@ -21,10 +21,10 @@
 #include "StringScheme.h"
 #include "EndpointID.h"
 
-namespace dtn {
-
 template <>
-StringScheme* oasys::Singleton<StringScheme>::instance_ = 0;
+dtn::StringScheme* oasys::Singleton<dtn::StringScheme>::instance_ = 0;
+
+namespace dtn {
 
 //----------------------------------------------------------------------
 bool
diff --git a/servlib/naming/TCAScheme.cc b/servlib/naming/TCAScheme.cc
index 07437b2..30f5c27 100644
--- a/servlib/naming/TCAScheme.cc
+++ b/servlib/naming/TCAScheme.cc
@@ -24,10 +24,10 @@
 #include "TCAScheme.h"
 #include "EndpointID.h"
 
-namespace dtn {
-
 template <>
-TCAScheme* oasys::Singleton<TCAScheme>::instance_ = 0;
+dtn::TCAScheme* oasys::Singleton<dtn::TCAScheme>::instance_ = 0;
+
+namespace dtn {
 
 /**
  * Validate that the SSP in the given URI is legitimate for
diff --git a/servlib/naming/WildcardScheme.cc b/servlib/naming/WildcardScheme.cc
index c73a2e9..abc06e3 100644
--- a/servlib/naming/WildcardScheme.cc
+++ b/servlib/naming/WildcardScheme.cc
@@ -21,11 +21,10 @@
 #include "WildcardScheme.h"
 #include "EndpointID.h"
 
-namespace dtn {
-
-//----------------------------------------------------------------------
 template <>
-WildcardScheme* oasys::Singleton<WildcardScheme>::instance_ = 0;
+dtn::WildcardScheme* oasys::Singleton<dtn::WildcardScheme>::instance_ = 0;
+
+namespace dtn {
 
 //----------------------------------------------------------------------
 bool
diff --git a/servlib/routing/DTLSRConfig.cc b/servlib/routing/DTLSRConfig.cc
index ac41e6f..bad15b2 100644
--- a/servlib/routing/DTLSRConfig.cc
+++ b/servlib/routing/DTLSRConfig.cc
@@ -20,11 +20,10 @@
 
 #include "DTLSRConfig.h"
 
-namespace dtn {
-
-//----------------------------------------------------------------------
 template <>
-DTLSRConfig* oasys::Singleton<DTLSRConfig>::instance_ = NULL;
+dtn::DTLSRConfig* oasys::Singleton<dtn::DTLSRConfig>::instance_ = NULL;
+
+namespace dtn {
 
 //----------------------------------------------------------------------
 DTLSRConfig::DTLSRConfig()
diff --git a/servlib/storage/BundleStore.cc b/servlib/storage/BundleStore.cc
index c1a3638..474de26 100644
--- a/servlib/storage/BundleStore.cc
+++ b/servlib/storage/BundleStore.cc
@@ -23,10 +23,10 @@
 
 #include <oasys/storage/DurableStore.h>
 
-namespace dtn {
-
 template <>
-BundleStore* oasys::Singleton<BundleStore, false>::instance_ = 0;
+dtn::BundleStore* oasys::Singleton<dtn::BundleStore, false>::instance_ = 0;
+
+namespace dtn {
 
 bool BundleStore::using_aux_table_ = false;
 
diff --git a/servlib/storage/LinkStore.cc b/servlib/storage/LinkStore.cc
index bc63ff9..b19ae68 100644
--- a/servlib/storage/LinkStore.cc
+++ b/servlib/storage/LinkStore.cc
@@ -21,16 +21,31 @@
 #include "LinkStore.h"
 #include "contacts/Link.h"
 
-namespace dtn {
-
 template<>
-LinkStore* oasys::Singleton<LinkStore, false>::instance_ = NULL;
+dtn::LinkStore* oasys::Singleton<dtn::LinkStore, false>::instance_ = NULL;
+
+namespace dtn {
 
 LinkStore::LinkStore()
     : LinkStoreImpl("LinkStore", "/dtn/storage/links", "link", "links")
 {
 }
 
+/**
+ * Boot time initializer that takes as a parameter the storage
+ * configuration to use.
+ */
+int
+LinkStore::init(const oasys::StorageConfig& cfg,
+                oasys::DurableStore*        store) 
+{
+    if (instance_ != NULL) {
+        PANIC("LinkStore::init called multiple times");
+    }
+    instance_ = new LinkStore();
+    return instance_->do_init(cfg, store);
+}
+
 
 } // namespace dtn
 
diff --git a/servlib/storage/LinkStore.h b/servlib/storage/LinkStore.h
index 2379264..e4d1744 100644
--- a/servlib/storage/LinkStore.h
+++ b/servlib/storage/LinkStore.h
@@ -44,14 +44,7 @@ public:
      * configuration to use.
      */
     static int init(const oasys::StorageConfig& cfg,
-                    oasys::DurableStore*        store) 
-    {
-        if (instance_ != NULL) {
-            PANIC("LinkStore::init called multiple times");
-        }
-        instance_ = new LinkStore();
-        return instance_->do_init(cfg, store);
-    }
+                    oasys::DurableStore*        store); 
     
     /**
      * Constructor.
diff --git a/servlib/storage/ProphetStore.cc b/servlib/storage/ProphetStore.cc
index ce6ec75..1b29963 100644
--- a/servlib/storage/ProphetStore.cc
+++ b/servlib/storage/ProphetStore.cc
@@ -21,10 +21,10 @@
 #include <oasys/debug/Log.h>
 #include "ProphetStore.h"
 
-namespace dtn {
-
 template <>
-ProphetStore* oasys::Singleton<ProphetStore,false>::instance_ = 0;
+dtn::ProphetStore* oasys::Singleton<dtn::ProphetStore,false>::instance_ = 0;
+
+namespace dtn {
 
 //----------------------------------------------------------------------
 ProphetStore::ProphetStore(const oasys::StorageConfig& cfg)
diff --git a/servlib/storage/RegistrationStore.cc b/servlib/storage/RegistrationStore.cc
index c279182..bc66176 100644
--- a/servlib/storage/RegistrationStore.cc
+++ b/servlib/storage/RegistrationStore.cc
@@ -21,10 +21,10 @@
 #include "RegistrationStore.h"
 #include "reg/Registration.h"
 
-namespace dtn {
-
 template<>
-RegistrationStore* oasys::Singleton<RegistrationStore, false>::instance_ = NULL;
+dtn::RegistrationStore* oasys::Singleton<dtn::RegistrationStore, false>::instance_ = NULL;
+
+namespace dtn {
 
 RegistrationStore::RegistrationStore()
     : RegistrationStoreImpl("RegistrationStore", "/dtn/storage/registrations",
@@ -32,6 +32,21 @@ RegistrationStore::RegistrationStore()
 {
 }
 
+/**
+ * Boot time initializer that takes as a parameter the storage
+ * configuration to use.
+ */
+int
+RegistrationStore::init(const oasys::StorageConfig& cfg,
+                        oasys::DurableStore*        store) 
+{
+    if (instance_ != NULL) {
+        PANIC("RegistrationStore::init called multiple times");
+    }
+    instance_ = new RegistrationStore();
+    return instance_->do_init(cfg, store);
+}
+
 
 } // namespace dtn
 
diff --git a/servlib/storage/RegistrationStore.h b/servlib/storage/RegistrationStore.h
index 7ea2ba6..46f7d7f 100644
--- a/servlib/storage/RegistrationStore.h
+++ b/servlib/storage/RegistrationStore.h
@@ -44,15 +44,8 @@ public:
      * configuration to use.
      */
     static int init(const oasys::StorageConfig& cfg,
-                    oasys::DurableStore*        store) 
-    {
-        if (instance_ != NULL) {
-            PANIC("RegistrationStore::init called multiple times");
-        }
-        instance_ = new RegistrationStore();
-        return instance_->do_init(cfg, store);
-    }
-    
+                    oasys::DurableStore*        store);
+        
     /**
      * Constructor.
      */
diff --git a/sim/SimLog.cc b/sim/SimLog.cc
index 4cf1820..c563b39 100644
--- a/sim/SimLog.cc
+++ b/sim/SimLog.cc
@@ -24,11 +24,10 @@
 #include "SimLog.h"
 #include "Simulator.h"
 
-namespace dtnsim {
-
 template <>
-SimLog* oasys::Singleton<SimLog>::instance_ = NULL;
+dtnsim::SimLog* oasys::Singleton<dtnsim::SimLog>::instance_ = NULL;
 
+namespace dtnsim {
 
 //----------------------------------------------------------------------
 SimLog::SimLog()
diff --git a/sim/Simulator.cc b/sim/Simulator.cc
index f484cdd..b1dc6e3 100644
--- a/sim/Simulator.cc
+++ b/sim/Simulator.cc
@@ -28,10 +28,10 @@
 
 using namespace dtn;
 
-namespace dtnsim {
-
 template<>
-Simulator* oasys::Singleton<Simulator, false>::instance_ = NULL;
+dtnsim::Simulator* oasys::Singleton<dtnsim::Simulator, false>::instance_ = NULL;
+
+namespace dtnsim {
 
 //----------------------------------------------------------------------