From 347ee6bc0e71ca79d729ccf53c134fbe01289621 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 5 Apr 2012 15:54:00 +0000 Subject: NO-JIRA: Fix a static-initialization bug in the HaPlugin. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1309913 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/qpid/ha/ReplicateLevel.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/qpid/cpp/src/qpid/ha/ReplicateLevel.cpp b/qpid/cpp/src/qpid/ha/ReplicateLevel.cpp index 48f21a1f66..2c3614bb63 100644 --- a/qpid/cpp/src/qpid/ha/ReplicateLevel.cpp +++ b/qpid/cpp/src/qpid/ha/ReplicateLevel.cpp @@ -21,18 +21,21 @@ #include "ReplicateLevel.h" #include "qpid/Exception.h" #include +#include namespace qpid { namespace ha { using namespace std; +// Note replicateLevel is called during plugin-initialization which +// happens in the static construction phase so these constants need +// to be POD, they can't be class objects +// namespace { -const string S_NONE="none"; -const string S_CONFIGURATION="configuration"; -const string S_ALL="all"; - -string names[] = { S_NONE, S_CONFIGURATION, S_ALL }; +const char* S_NONE="none"; +const char* S_CONFIGURATION="configuration"; +const char* S_ALL="all"; } bool replicateLevel(const string& level, ReplicateLevel& out) { @@ -44,14 +47,22 @@ bool replicateLevel(const string& level, ReplicateLevel& out) { ReplicateLevel replicateLevel(const string& level) { ReplicateLevel rl; - if (!replicateLevel(level, rl)) + if (!replicateLevel(level, rl)) { + assert(0); throw Exception("Invalid value for replication level: "+level); + } return rl; } -string str(ReplicateLevel l) { return names[l]; } +string str(ReplicateLevel l) { + const char* names[] = { S_NONE, S_CONFIGURATION, S_ALL }; + assert(l >= RL_NONE); + assert(l <= RL_ALL); + return names[l]; +} ostream& operator<<(ostream& o, ReplicateLevel rl) { return o << str(rl); } + istream& operator>>(istream& i, ReplicateLevel& rl) { string str; i >> str; -- cgit v1.2.1