From 51a2c9eabc44ff9669d11802b9453c1a40e9a32c Mon Sep 17 00:00:00 2001 From: Max Hirschhorn Date: Sat, 20 Feb 2016 11:06:47 -0500 Subject: SERVER-22569 Change findParentEqualityElement() to return by value. MSVC 2013 doesn't support thread-safe initialization of function-local static-duration objects, so it's possible to return a reference to 'eooElement' prior to the value being fully initialized. (cherry picked from commit 4f1cc51f3e21e4ff76c68e86ecae4e5d138de0aa) --- src/mongo/db/ops/path_support.cpp | 11 +++++------ src/mongo/db/ops/path_support.h | 6 +++--- src/mongo/s/shard_key_pattern.cpp | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/mongo/db/ops/path_support.cpp b/src/mongo/db/ops/path_support.cpp index d1e8fa7fcde..0b79a872053 100644 --- a/src/mongo/db/ops/path_support.cpp +++ b/src/mongo/db/ops/path_support.cpp @@ -287,9 +287,9 @@ Status setElementAtPath(const FieldRef& path, } } -const BSONElement& findParentEqualityElement(const EqualityMatches& equalities, - const FieldRef& path, - int* parentPathParts) { +BSONElement findParentEqualityElement(const EqualityMatches& equalities, + const FieldRef& path, + int* parentPathParts) { // We may have an equality match to an object at a higher point in the pattern path, check // all path prefixes for equality matches // ex: path: 'a.b', query : { 'a' : { b : } } @@ -309,8 +309,7 @@ const BSONElement& findParentEqualityElement(const EqualityMatches& equalities, } *parentPathParts = -1; - static const BSONElement eooElement; - return eooElement; + return BSONElement(); } /** @@ -318,7 +317,7 @@ const BSONElement& findParentEqualityElement(const EqualityMatches& equalities, */ static Status checkEqualityConflicts(const EqualityMatches& equalities, const FieldRef& path) { int parentPathPart = -1; - const BSONElement& parentEl = findParentEqualityElement(equalities, path, &parentPathPart); + const BSONElement parentEl = findParentEqualityElement(equalities, path, &parentPathPart); if (parentEl.eoo()) return Status::OK(); diff --git a/src/mongo/db/ops/path_support.h b/src/mongo/db/ops/path_support.h index 95d0a3da44c..cebda16aa76 100644 --- a/src/mongo/db/ops/path_support.h +++ b/src/mongo/db/ops/path_support.h @@ -170,9 +170,9 @@ Status extractFullEqualityMatches(const MatchExpression& root, * Path 'a.b.c' has an eqmatch parent of 'a.b' : 1 * */ -const BSONElement& findParentEqualityElement(const EqualityMatches& equalities, - const FieldRef& path, - int* parentPathParts); +BSONElement findParentEqualityElement(const EqualityMatches& equalities, + const FieldRef& path, + int* parentPathParts); /** * Adds the BSON values from equality matches into the given document at the equality match diff --git a/src/mongo/s/shard_key_pattern.cpp b/src/mongo/s/shard_key_pattern.cpp index 8fca176754c..2071bde5d70 100644 --- a/src/mongo/s/shard_key_pattern.cpp +++ b/src/mongo/s/shard_key_pattern.cpp @@ -249,7 +249,7 @@ BSONObj ShardKeyPattern::extractShardKeyFromDoc(const BSONObj& doc) const { static BSONElement findEqualityElement(const EqualityMatches& equalities, const FieldRef& path) { int parentPathPart; - const BSONElement& parentEl = + const BSONElement parentEl = pathsupport::findParentEqualityElement(equalities, path, &parentPathPart); if (parentPathPart == static_cast(path.numParts())) -- cgit v1.2.1