Skip to content

Commit 8c6dba9

Browse files
committed
CXX-480 Backport server r2.8.0-rc5..r3.0.0-rc6 changes
1 parent d59f92b commit 8c6dba9

19 files changed

+433
-122
lines changed

SConstruct

Lines changed: 105 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import imp
66
import os
77
import platform as py_platform
88
import re
9+
import shlex
910
import shutil
1011
import stat
1112
import sys
@@ -217,6 +218,10 @@ add_option("use-sasl-client", "Support SASL authentication in the client library
217218

218219
add_option('build-fast-and-loose', "NEVER for production builds", 0, False)
219220

221+
add_option( "boost-lib-search-suffixes",
222+
"Comma delimited sequence of boost library suffixes to search",
223+
1, False )
224+
220225
add_option('disable-warnings-as-errors', "Don't add -Werror to compiler command line", 0, False)
221226

222227
add_option('propagate-shell-environment',
@@ -236,6 +241,10 @@ add_option('mongo-orchestration-host',
236241
add_option('mongo-orchestration-port',
237242
"Host mongo-orchestration is running on",
238243
1, False, default='8889' )
244+
245+
add_option('variables-help',
246+
"Print the help text for SCons variables", 0, False)
247+
239248
if darwin:
240249
osx_version_choices = ['10.6', '10.7', '10.8', '10.9', '10.10']
241250

@@ -281,6 +290,64 @@ add_option('cache-dir',
281290
"Specify the directory to use for caching objects if --cache is in use",
282291
1, False, default="$BUILD_DIR/scons/cache")
283292

293+
# Setup the command-line variables
294+
def variable_shlex_converter(val):
295+
return shlex.split(val)
296+
297+
env_vars = Variables()
298+
299+
env_vars.Add('ARFLAGS',
300+
help='Sets flags for the archiver',
301+
converter=variable_shlex_converter)
302+
303+
env_vars.Add('CCFLAGS',
304+
help='Sets flags for the C and C++ compiler',
305+
converter=variable_shlex_converter)
306+
307+
env_vars.Add('CFLAGS',
308+
help='Sets flags for the C compiler',
309+
converter=variable_shlex_converter)
310+
311+
env_vars.Add('CPPDEFINES',
312+
help='Sets pre-processor definitions for C and C++',
313+
converter=variable_shlex_converter)
314+
315+
env_vars.Add('CPPPATH',
316+
help='Adds paths to the preprocessor search path',
317+
converter=variable_shlex_converter)
318+
319+
env_vars.Add('CXXFLAGS',
320+
help='Sets flags for the C++ compiler',
321+
converter=variable_shlex_converter)
322+
323+
env_vars.Add('LIBPATH',
324+
help='Adds paths to the linker search path',
325+
converter=variable_shlex_converter)
326+
327+
env_vars.Add('LIBS',
328+
help='Adds extra libraries to link against',
329+
converter=variable_shlex_converter)
330+
331+
env_vars.Add('LINKFLAGS',
332+
help='Sets flags for the linker',
333+
converter=variable_shlex_converter)
334+
335+
env_vars.Add('SHCCFLAGS',
336+
help='Sets flags for the C and C++ compiler when building shared libraries',
337+
converter=variable_shlex_converter)
338+
339+
env_vars.Add('SHCFLAGS',
340+
help='Sets flags for the C compiler when building shared libraries',
341+
converter=variable_shlex_converter)
342+
343+
env_vars.Add('SHCXXFLAGS',
344+
help='Sets flags for the C++ compiler when building shared libraries',
345+
converter=variable_shlex_converter)
346+
347+
env_vars.Add('SHLINKFLAGS',
348+
help='Sets flags for the linker when building shared libraries',
349+
converter=variable_shlex_converter)
350+
284351
# don't run configure if user calls --help
285352
if GetOption('help'):
286353
Return()
@@ -433,9 +500,36 @@ if windows:
433500
msvc_script = None
434501
envDict['MSVC_USE_SCRIPT'] = msvc_script
435502

436-
env = Environment(**envDict)
503+
env = Environment(variables=env_vars, **envDict)
437504
del envDict
438505

506+
if has_option('variables-help'):
507+
print env_vars.GenerateHelpText(env)
508+
Exit(0)
509+
510+
unknown_vars = env_vars.UnknownVariables()
511+
if unknown_vars:
512+
print "Unknown variables specified: {0}".format(", ".join(unknown_vars.keys()))
513+
Exit(1)
514+
515+
516+
# Add any scons options that conflict with scons variables here.
517+
# The first item in each tuple is the option name and the second
518+
# is the variable name
519+
variable_conflicts = [
520+
('libpath', 'LIBPATH'),
521+
('cpppath', 'CPPPATH'),
522+
('extrapath', 'CPPPATH'),
523+
('extrapath', 'LIBPATH'),
524+
('extralib', 'LIBS')
525+
]
526+
527+
for (opt_name, var_name) in variable_conflicts:
528+
if has_option(opt_name) and var_name in env:
529+
print("Both option \"--{0}\" and variable {1} were specified".
530+
format(opt_name, var_name))
531+
Exit(1)
532+
439533
if has_option("cache"):
440534
EnsureSConsVersion( 2, 3, 0 )
441535
if has_option("release"):
@@ -524,8 +618,6 @@ if has_option( "cc" ):
524618
exit(1)
525619
env["CC"] = get_option( "cc" )
526620

527-
env["LIBPATH"] = []
528-
529621
if has_option( "libpath" ):
530622
env["LIBPATH"] = [get_option( "libpath" )]
531623

@@ -843,6 +935,14 @@ except OSError:
843935

844936
env.Prepend(CPPPATH=['$VARIANT_DIR/third_party/gtest-1.7.0/include'])
845937

938+
boostSuffixList = ["-mt", ""]
939+
if get_option("boost-lib-search-suffixes") is not None:
940+
boostSuffixList = get_option("boost-lib-search-suffixes")
941+
if boostSuffixList == "":
942+
boostSuffixList = []
943+
else:
944+
boostSuffixList = boostSuffixList.split(',')
945+
846946
env.Append( CPPPATH=['$EXTRACPPPATH'],
847947
LIBPATH=['$EXTRALIBPATH'] )
848948

@@ -1643,10 +1743,10 @@ def doConfigure(myenv):
16431743
print( "Could not find boost headers in include search path" )
16441744
Exit(1)
16451745

1646-
if not windows:
1746+
if (not windows) and boostSuffixList:
16471747
# We don't do this for windows because we rely on autolib.
16481748
for b in boostLibs:
1649-
boostCandidates = ["boost_" + b + "-mt", "boost_" + b]
1749+
boostCandidates = ["boost_" + b + suffix for suffix in boostSuffixList]
16501750
if not conf.CheckLib(boostCandidates, language="C++"):
16511751
print( "can't find boost")
16521752
Exit(1)

src/mongo/base/compare_numbers.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/* Copyright 2015 MongoDB Inc.
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Affero General Public License, version 3,
5+
* as published by the Free Software Foundation.
6+
*
7+
* This program is distributed in the hope that it will be useful,
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
* GNU Affero General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU Affero General Public License
13+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
14+
*
15+
* As a special exception, the copyright holders give permission to link the
16+
* code of portions of this program with the OpenSSL library under certain
17+
* conditions as described in each individual source file and distribute
18+
* linked combinations including the program with the OpenSSL library. You
19+
* must comply with the GNU Affero General Public License in all respects
20+
* for all of the code used other than as permitted herein. If you modify
21+
* file(s) with this exception, you may extend this exception to your
22+
* version of the file(s), but you are not obligated to do so. If you do not
23+
* wish to do so, delete this exception statement from your version. If you
24+
* delete this exception statement from all source files in the program,
25+
* then also delete it in the license file.
26+
*/
27+
28+
#pragma once
29+
30+
#include "mongo/platform/float_utils.h"
31+
32+
namespace mongo {
33+
34+
/**
35+
* These functions compare numbers using the same rules as BSON. Care is taken to always give
36+
* numerically correct results when comparing different types. Returns are always -1, 0, or 1 to
37+
* ensure it is safe to negate the result to invert the direction of the comparison.
38+
*/
39+
40+
inline int compareInts(int lhs, int rhs) {
41+
return lhs == rhs ? 0 : lhs < rhs ? -1 : 1;
42+
}
43+
44+
inline int compareLongs(long long lhs, long long rhs) {
45+
return lhs == rhs ? 0 : lhs < rhs ? -1 : 1;
46+
}
47+
48+
inline int compareDoubles(double lhs, double rhs) {
49+
if (lhs == rhs) return 0;
50+
if (lhs < rhs) return -1;
51+
if (lhs > rhs) return 1;
52+
53+
// If none of the above cases returned, lhs or rhs must be NaN.
54+
if (isNaN(lhs)) return isNaN(rhs) ? 0 : -1;
55+
return 1;
56+
}
57+
58+
// This is the tricky one. Needs to support the following cases:
59+
// * Doubles with a fractional component.
60+
// * Longs that can't be precisely represented as a double.
61+
// * Doubles outside of the range of Longs (including +/- Inf).
62+
// * NaN (defined by us as less than all Longs)
63+
// * Return value is always -1, 0, or 1 to ensure it is safe to negate.
64+
inline int compareLongToDouble(long long lhs, double rhs) {
65+
// All Longs are > NaN
66+
if (isNaN(rhs)) return 1;
67+
68+
// Ints with magnitude <= 2**53 can be precisely represented as doubles.
69+
// Additionally, doubles outside of this range can't have a fractional component.
70+
static const long long kEndOfPreciseDoubles = 1ll << 53;
71+
if (lhs <= kEndOfPreciseDoubles && lhs >= -kEndOfPreciseDoubles) {
72+
return compareDoubles(lhs, rhs);
73+
}
74+
75+
// Large magnitude doubles (including +/- Inf) are strictly > or < all Longs.
76+
static const double kBoundOfLongRange = -static_cast<double>(LLONG_MIN); // positive 2**63
77+
if (rhs >= kBoundOfLongRange) return -1; // Can't be represented in a Long.
78+
if (rhs < -kBoundOfLongRange) return 1; // Can be represented in a Long.
79+
80+
// Remaining Doubles can have their integer component precisely represented as long longs.
81+
// If they have a fractional component, they must be strictly > or < lhs even after
82+
// truncation of the fractional component since low-magnitude lhs were handled above.
83+
return compareLongs(lhs, rhs);
84+
}
85+
86+
inline int compareDoubleToLong(double lhs, long long rhs) {
87+
// Only implement the real logic once.
88+
return -compareLongToDouble(rhs, lhs);
89+
}
90+
91+
} // namespace mongo

0 commit comments

Comments
 (0)