diff options
author | Alan Conway <aconway@apache.org> | 2012-04-05 15:54:00 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2012-04-05 15:54:00 +0000 |
commit | 347ee6bc0e71ca79d729ccf53c134fbe01289621 (patch) | |
tree | ce2538544db6c7349497565370f41627f6448438 | |
parent | 4a0673e3dd90c98eb777558044062fd22d2e94dc (diff) | |
download | qpid-python-347ee6bc0e71ca79d729ccf53c134fbe01289621.tar.gz |
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
-rw-r--r-- | qpid/cpp/src/qpid/ha/ReplicateLevel.cpp | 25 |
1 files 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 <iostream> +#include <assert.h> 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; |