summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Morrow <acm@10gen.com>2013-03-07 14:42:30 -0500
committerAndrew Morrow <acm@10gen.com>2013-03-08 11:24:43 -0500
commit13ddc4ee6eb6717808ce3726bd3b59eb55e48b58 (patch)
tree146d1c4e6f8ca4e68e0836bff27807b86c406aaa
parente8f63bc48606952e6352a095db479b178c3672e6 (diff)
downloadmongo-13ddc4ee6eb6717808ce3726bd3b59eb55e48b58.tar.gz
SERVER-8897 Don't use non-portable variadic comma elision
-rw-r--r--src/mongo/base/init.h4
-rw-r--r--src/mongo/base/initializer_dependency_graph_test.cpp61
-rw-r--r--src/mongo/base/initializer_test.cpp19
-rw-r--r--src/mongo/base/make_string_vector.cpp6
-rw-r--r--src/mongo/base/make_string_vector.h9
-rw-r--r--src/mongo/db/server_extra_log_context.cpp3
-rw-r--r--src/mongo/util/fail_point_service.cpp4
7 files changed, 56 insertions, 50 deletions
diff --git a/src/mongo/base/init.h b/src/mongo/base/init.h
index 9fec726ce9b..062112247f3 100644
--- a/src/mongo/base/init.h
+++ b/src/mongo/base/init.h
@@ -62,12 +62,12 @@
/**
* Convenience parameter representing an empty set of prerequisites for an initializer function.
*/
-#define MONGO_NO_PREREQUISITES ()
+#define MONGO_NO_PREREQUISITES (NULL)
/**
* Convenience parameter representing an empty set of dependents of an initializer function.
*/
-#define MONGO_NO_DEPENDENTS ()
+#define MONGO_NO_DEPENDENTS (NULL)
/**
* Convenience parameter representing the default set of dependents for initializer functions.
diff --git a/src/mongo/base/initializer_dependency_graph_test.cpp b/src/mongo/base/initializer_dependency_graph_test.cpp
index 3b35dfff419..7ea03524c37 100644
--- a/src/mongo/base/initializer_dependency_graph_test.cpp
+++ b/src/mongo/base/initializer_dependency_graph_test.cpp
@@ -17,6 +17,7 @@
* Unit tests of the InitializerDependencyGraph type.
*/
+#include "mongo/base/init.h"
#include "mongo/base/initializer_dependency_graph.h"
#include "mongo/base/make_string_vector.h"
#include "mongo/unittest/unittest.h"
@@ -47,13 +48,17 @@ namespace {
TEST(InitializerDependencyGraphTest, InsertNullFunctionFails) {
InitializerDependencyGraph graph;
- ASSERT_EQUALS(ErrorCodes::BadValue, ADD_INITIALIZER(graph, "A", InitializerFunction(), (), ()));
+ ASSERT_EQUALS(ErrorCodes::BadValue, ADD_INITIALIZER(
+ graph, "A", InitializerFunction(),
+ MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS));
}
TEST(InitializerDependencyGraphTest, InsertSameNameTwiceFails) {
InitializerDependencyGraph graph;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, (), ());
- ASSERT_EQUALS(ErrorCodes::DuplicateKey, ADD_INITIALIZER(graph, "A", doNothing, (), ()));
+ ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
+ ASSERT_EQUALS(ErrorCodes::DuplicateKey, ADD_INITIALIZER(
+ graph, "A", doNothing,
+ MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS));
}
TEST(InitializerDependencyGraphTest, TopSortEmptyGraph) {
@@ -66,9 +71,9 @@ namespace {
TEST(InitializerDependencyGraphTest, TopSortGraphNoDeps) {
InitializerDependencyGraph graph;
std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, (), ());
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, (), ());
- ASSERT_ADD_INITIALIZER(graph, "C", doNothing, (), ());
+ ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
+ ASSERT_ADD_INITIALIZER(graph, "B", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
+ ASSERT_ADD_INITIALIZER(graph, "C", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
ASSERT_EQUALS(3U, nodeNames.size());
ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "A");
@@ -90,10 +95,10 @@ namespace {
*/
InitializerDependencyGraph graph;
std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, (), ());
- ASSERT_ADD_INITIALIZER(graph, "D", doNothing, ("B", "C"), ());
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, ("A"), ());
- ASSERT_ADD_INITIALIZER(graph, "C", doNothing, ("A"), ());
+ ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
+ ASSERT_ADD_INITIALIZER(graph, "D", doNothing, ("B", "C"), MONGO_NO_DEPENDENTS);
+ ASSERT_ADD_INITIALIZER(graph, "B", doNothing, ("A"), MONGO_NO_DEPENDENTS);
+ ASSERT_ADD_INITIALIZER(graph, "C", doNothing, ("A"), MONGO_NO_DEPENDENTS);
ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
ASSERT_EQUALS(4U, nodeNames.size());
ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "A");
@@ -118,10 +123,10 @@ namespace {
*/
InitializerDependencyGraph graph;
std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, (), ("B", "C"));
- ASSERT_ADD_INITIALIZER(graph, "D", doNothing, (), ());
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, (), ("D"));
- ASSERT_ADD_INITIALIZER(graph, "C", doNothing, (), ("D"));
+ ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, ("B", "C"));
+ ASSERT_ADD_INITIALIZER(graph, "D", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
+ ASSERT_ADD_INITIALIZER(graph, "B", doNothing, MONGO_NO_PREREQUISITES, ("D"));
+ ASSERT_ADD_INITIALIZER(graph, "C", doNothing, MONGO_NO_PREREQUISITES, ("D"));
ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
ASSERT_EQUALS(4U, nodeNames.size());
ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "A");
@@ -147,8 +152,8 @@ namespace {
*/
InitializerDependencyGraph graph;
std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, (), ());
- ASSERT_ADD_INITIALIZER(graph, "D", doNothing, (), ());
+ ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
+ ASSERT_ADD_INITIALIZER(graph, "D", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
ASSERT_ADD_INITIALIZER(graph, "B", doNothing, ("A"), ("D"));
ASSERT_ADD_INITIALIZER(graph, "C", doNothing, ("A"), ("D"));
ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
@@ -176,10 +181,10 @@ namespace {
*/
InitializerDependencyGraph graph;
std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, (), ("B", "C"));
- ASSERT_ADD_INITIALIZER(graph, "D", doNothing, ("C", "B"), ());
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, (), ());
- ASSERT_ADD_INITIALIZER(graph, "C", doNothing, (), ());
+ ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, ("B", "C"));
+ ASSERT_ADD_INITIALIZER(graph, "D", doNothing, ("C", "B"), MONGO_NO_DEPENDENTS);
+ ASSERT_ADD_INITIALIZER(graph, "B", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
+ ASSERT_ADD_INITIALIZER(graph, "C", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
ASSERT_EQUALS(4U, nodeNames.size());
ASSERT_EXACTLY_ONE_IN_CONTAINER(nodeNames, "A");
@@ -205,8 +210,8 @@ namespace {
*/
InitializerDependencyGraph graph;
std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, (), ("B", "C"));
- ASSERT_ADD_INITIALIZER(graph, "D", doNothing, ("C", "B"), ());
+ ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, ("B", "C"));
+ ASSERT_ADD_INITIALIZER(graph, "D", doNothing, ("C", "B"), MONGO_NO_DEPENDENTS);
ASSERT_ADD_INITIALIZER(graph, "B", doNothing, ("A"), ("D"));
ASSERT_ADD_INITIALIZER(graph, "C", doNothing, ("A"), ("D"));
ASSERT_EQUALS(Status::OK(), graph.topSort(&nodeNames));
@@ -233,10 +238,10 @@ namespace {
*/
InitializerDependencyGraph graph;
std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, (), ("B", "C"));
- ASSERT_ADD_INITIALIZER(graph, "D", doNothing, ("C", "B"), ());
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, (), ());
- ASSERT_ADD_INITIALIZER(graph, "C", doNothing, (), ());
+ ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, ("B", "C"));
+ ASSERT_ADD_INITIALIZER(graph, "D", doNothing, ("C", "B"), MONGO_NO_DEPENDENTS);
+ ASSERT_ADD_INITIALIZER(graph, "B", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
+ ASSERT_ADD_INITIALIZER(graph, "C", doNothing, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS);
ASSERT_ADD_INITIALIZER(graph, "E", doNothing, ("D"), ("B"));
ASSERT_EQUALS(ErrorCodes::GraphContainsCycle, graph.topSort(&nodeNames));
ASSERT_EQUALS(4U, nodeNames.size());
@@ -254,7 +259,7 @@ namespace {
*/
InitializerDependencyGraph graph;
std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "B", doNothing, ("A"), ());
+ ASSERT_ADD_INITIALIZER(graph, "B", doNothing, ("A"), MONGO_NO_DEPENDENTS);
ASSERT_EQUALS(ErrorCodes::BadValue, graph.topSort(&nodeNames));
}
@@ -264,7 +269,7 @@ namespace {
*/
InitializerDependencyGraph graph;
std::vector<std::string> nodeNames;
- ASSERT_ADD_INITIALIZER(graph, "A", doNothing, (), ("B"));
+ ASSERT_ADD_INITIALIZER(graph, "A", doNothing, MONGO_NO_PREREQUISITES, ("B"));
ASSERT_EQUALS(ErrorCodes::BadValue, graph.topSort(&nodeNames));
}
diff --git a/src/mongo/base/initializer_test.cpp b/src/mongo/base/initializer_test.cpp
index ae3fb8d56e6..0635a5c2a2a 100644
--- a/src/mongo/base/initializer_test.cpp
+++ b/src/mongo/base/initializer_test.cpp
@@ -17,6 +17,7 @@
* Unit tests of the Initializer type.
*/
+#include "mongo/base/init.h"
#include "mongo/base/initializer.h"
#include "mongo/base/initializer_dependency_graph.h"
#include "mongo/base/make_string_vector.h"
@@ -50,15 +51,15 @@
#define CONSTRUCT_DEPENDENCY_GRAPH(GRAPH, FN0, FN1, FN2, FN3, FN4, FN5, FN6, FN7, FN8) \
do { \
InitializerDependencyGraph& _graph_ = (GRAPH); \
- ASSERT_ADD_INITIALIZER(_graph_, "n0", FN0, (), ()); \
- ASSERT_ADD_INITIALIZER(_graph_, "n1", FN1, (), ()); \
- ASSERT_ADD_INITIALIZER(_graph_, "n2", FN2, ("n0", "n1"), ()); \
- ASSERT_ADD_INITIALIZER(_graph_, "n3", FN3, ("n0", "n2"), ()); \
- ASSERT_ADD_INITIALIZER(_graph_, "n4", FN4, ("n2", "n1"), ()); \
- ASSERT_ADD_INITIALIZER(_graph_, "n5", FN5, ("n3", "n4"), ()); \
- ASSERT_ADD_INITIALIZER(_graph_, "n6", FN6, ("n4"), ()); \
- ASSERT_ADD_INITIALIZER(_graph_, "n7", FN7, ("n3"), ()); \
- ASSERT_ADD_INITIALIZER(_graph_, "n8", FN8, ("n5", "n6", "n7"), ()); \
+ ASSERT_ADD_INITIALIZER(_graph_, "n0", FN0, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS); \
+ ASSERT_ADD_INITIALIZER(_graph_, "n1", FN1, MONGO_NO_PREREQUISITES, MONGO_NO_DEPENDENTS); \
+ ASSERT_ADD_INITIALIZER(_graph_, "n2", FN2, ("n0", "n1"), MONGO_NO_DEPENDENTS); \
+ ASSERT_ADD_INITIALIZER(_graph_, "n3", FN3, ("n0", "n2"), MONGO_NO_DEPENDENTS); \
+ ASSERT_ADD_INITIALIZER(_graph_, "n4", FN4, ("n2", "n1"), MONGO_NO_DEPENDENTS); \
+ ASSERT_ADD_INITIALIZER(_graph_, "n5", FN5, ("n3", "n4"), MONGO_NO_DEPENDENTS); \
+ ASSERT_ADD_INITIALIZER(_graph_, "n6", FN6, ("n4"), MONGO_NO_DEPENDENTS); \
+ ASSERT_ADD_INITIALIZER(_graph_, "n7", FN7, ("n3"), MONGO_NO_DEPENDENTS); \
+ ASSERT_ADD_INITIALIZER(_graph_, "n8", FN8, ("n5", "n6", "n7"), MONGO_NO_DEPENDENTS); \
} while (false)
namespace mongo {
diff --git a/src/mongo/base/make_string_vector.cpp b/src/mongo/base/make_string_vector.cpp
index 1865f19b859..1818bb9ff53 100644
--- a/src/mongo/base/make_string_vector.cpp
+++ b/src/mongo/base/make_string_vector.cpp
@@ -24,12 +24,8 @@ namespace mongo {
std::vector<std::string> _makeStringVector(int ignored, ...) {
va_list ap;
va_start(ap, ignored);
- const char* arg = va_arg(ap, const char *);
- if (arg) {
- std::cerr << "Internal error!\n";
- std::abort();
- }
std::vector<std::string> result;
+ const char* arg = NULL;
while ((arg = va_arg(ap, const char *)))
result.push_back(arg);
va_end(ap);
diff --git a/src/mongo/base/make_string_vector.h b/src/mongo/base/make_string_vector.h
index 39c5167641e..6dd4dfad391 100644
--- a/src/mongo/base/make_string_vector.h
+++ b/src/mongo/base/make_string_vector.h
@@ -25,7 +25,7 @@
* Usage: MONGO_MAKE_STRING_VECTOR("a", "b", "c") returns a vector containing
* std::strings "a", "b", "c", in that order.
*/
-#define MONGO_MAKE_STRING_VECTOR(...) ::mongo::_makeStringVector(0, NULL, ##__VA_ARGS__, NULL)
+#define MONGO_MAKE_STRING_VECTOR(...) ::mongo::_makeStringVector(0, __VA_ARGS__, NULL)
namespace mongo {
@@ -35,9 +35,10 @@ namespace mongo {
* WARNING: Only intended for use by MONGO_MAKE_STRING_VECTOR macro, defined above. Aborts
* ungracefully if you misuse it, so stick to the macro.
*
- * The first parameter is ignored in all circumstances. The second parameter must be NULL, as
- * must be the last parameter. The third through penultimate parameters should be const char*
- * C-style strings.
+ * The first parameter is ignored in all circumstances. The subsequent parameters must be
+ * const char* C-style strings, or NULL. Of these parameters, at least one must be
+ * NULL. Parameters at and beyond the NULL are not inserted. Typically, the NULL will be
+ * the last parameter. The MONGO_MAKE_STRING_VECTOR macro enforces this.
*
* Returns a vector of std::strings.
*/
diff --git a/src/mongo/db/server_extra_log_context.cpp b/src/mongo/db/server_extra_log_context.cpp
index 866ccc3ac06..dc5b1d94041 100644
--- a/src/mongo/db/server_extra_log_context.cpp
+++ b/src/mongo/db/server_extra_log_context.cpp
@@ -56,7 +56,8 @@ namespace {
builder.appendChar(' ');
}
- MONGO_INITIALIZER_WITH_PREREQUISITES(SetServerLogContextFunction, ())(InitializerContext*) {
+ MONGO_INITIALIZER_WITH_PREREQUISITES(SetServerLogContextFunction,
+ MONGO_NO_PREREQUISITES)(InitializerContext*) {
if (!logUserIds)
return Status::OK();
diff --git a/src/mongo/util/fail_point_service.cpp b/src/mongo/util/fail_point_service.cpp
index b474810ddaf..6840427e80a 100644
--- a/src/mongo/util/fail_point_service.cpp
+++ b/src/mongo/util/fail_point_service.cpp
@@ -26,7 +26,9 @@ namespace mongo {
return Status::OK();
}
- MONGO_INITIALIZER_GENERAL(AllFailPointsRegistered, (), ())(InitializerContext* context) {
+ MONGO_INITIALIZER_GENERAL(AllFailPointsRegistered,
+ MONGO_NO_PREREQUISITES,
+ MONGO_NO_DEPENDENTS)(InitializerContext* context) {
_fpRegistry->freeze();
return Status::OK();
}