]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix clang errors with global InstanceId initialization
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 6 Aug 2016 04:49:55 +0000 (16:49 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 6 Aug 2016 04:49:55 +0000 (16:49 +1200)
Move static member Last into change() method to avoid initialization order
errors when a caller uses a global InstanceId object before the library
instantiating its template is initialized.

Also, convert the Prefix static member to a constant string in a prefix()
method to avoid the same issue there.

src/adaptation/icap/Xaction.cc
src/base/AsyncJob.cc
src/base/InstanceId.h
src/security/PeerConnector.cc

index fca9f8507bbad5098b06b431ed7d45d4eb5ad357..180bf0457431d78c5928631ba0c31a15b207464b 100644 (file)
@@ -669,7 +669,7 @@ const char *Adaptation::Icap::Xaction::status() const
     fillPendingStatus(buf);
     buf.append("/", 1);
     fillDoneStatus(buf);
-    buf.appendf(" %s%u]", id.Prefix, id.value);
+    buf.appendf(" %s%u]", id.prefix(), id.value);
     buf.terminate();
 
     return buf.content();
index 96f110183a432d21aabbcf3f46675f8395d6fb70..b7c0e18f2755430fa2349e3448392ac522e90fe4 100644 (file)
@@ -165,7 +165,7 @@ const char *AsyncJob::status() const
     if (stopReason != NULL) {
         buf.appendf("Stopped, reason:%s", stopReason);
     }
-    buf.appendf(" %s%u]", id.Prefix, id.value);
+    buf.appendf(" %s%u]", id.prefix(), id.value);
     buf.terminate();
 
     return buf.content();
index c64f9df13d00c7c56428417a97c4d118b096ada1..2e2c457d92946191ba5024d6ca5cb6448491ad39 100644 (file)
@@ -25,35 +25,41 @@ class InstanceId
 public:
     typedef unsigned int Value; ///< id storage type; \todo: parameterize?
 
-    InstanceId(): value(++Last ? Last : ++Last) {}
+    InstanceId(): value(0) {change();}
 
     operator Value() const { return value; }
     bool operator ==(const InstanceId &o) const { return value == o.value; }
     bool operator !=(const InstanceId &o) const { return !(*this == o); }
-    void change() {value = ++Last ? Last : ++Last;}
+    void change();
 
-    /// prints Prefix followed by ID value; \todo: use HEX for value printing?
+    /// prints class-pecific prefix followed by ID value; \todo: use HEX for value printing?
     std::ostream &print(std::ostream &os) const;
 
+    /// returns the class-pecific prefix
+    const char * const prefix() const;
+
 public:
-    static const char *Prefix; ///< Class shorthand string for debugging
     Value value; ///< instance identifier
 
 private:
     InstanceId(const InstanceId& right); ///< not implemented; IDs are unique
     InstanceId& operator=(const InstanceId &right); ///< not implemented
-
-private:
-    static Value Last; ///< the last used ID value
 };
 
 /// convenience macro to instantiate Class-specific stuff in .cc files
-#define InstanceIdDefinitions(Class, prefix) \
-    template<> const char *InstanceId<Class>::Prefix = prefix; \
-    template<> InstanceId<Class>::Value InstanceId<Class>::Last = 0; \
+#define InstanceIdDefinitions(Class, pfx) \
+    template<> const char * const \
+    InstanceId<Class>::prefix() const { \
+        return pfx; \
+    } \
     template<> std::ostream & \
     InstanceId<Class>::print(std::ostream &os) const { \
-        return os << Prefix << value; \
+        return os << pfx << value; \
+    } \
+    template<> void \
+    InstanceId<Class>::change() { \
+        static InstanceId<Class>::Value Last = 0; \
+        value = ++Last ? Last : ++Last; \
     }
 
 /// print the id
index 5d3022636d70356ced11f1f2ac5749517edb1bbd..cc4c608d8c7482da6551ca07bf856bb957b4bab6 100644 (file)
@@ -534,7 +534,7 @@ Security::PeerConnector::status() const
     }
     if (serverConn != NULL)
         buf.appendf(" FD %d", serverConn->fd);
-    buf.appendf(" %s%u]", id.Prefix, id.value);
+    buf.appendf(" %s%u]", id.prefix(), id.value);
     buf.terminate();
 
     return buf.content();