Skip to content

Commit a538e02

Browse files
authored
Update to 2025-10-24 google3 version (#465)
* Remove `S2_DEFINE_*` flags macros and use `ABSL_FLAG` directly * Modernize `ExactFloat` interface * Replace `exactfloat::is_nan()` with `isnan(const ExactFloat&)` * Replace `ToDouble()` with `explicit operator double()` * Add `fpclassify(const ExactFloat&)` * Add exactfloat_underflow_test * New `S2Cell::IsDistanceLess` and related predicates * Do not use `#pragma STDC FP_CONTRACT off` for gcc to try to prevent warnings. gcc has its own pragma (which was always used) * Switch some `ABSL_LOG(ERROR)`s to `DFATAL`
2 parents ead4b7a + 936e214 commit a538e02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+811
-553
lines changed

CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ else()
9191
# match [-Wattributes]
9292
add_definitions(-Wno-attributes)
9393
add_definitions(-Wno-deprecated-declarations)
94-
# `base/port.h` uses sized deallocation, which should be enabled by
94+
# Some files use sized deallocation, which should be enabled by
9595
# default for C++14 and later. There appears to be a bug with clang
9696
# < 19 causing this not to be enabled.
9797
# https://github.com/google/s2geometry/issues/411#issuecomment-2726949607
@@ -432,11 +432,8 @@ if(S2_ENABLE_INSTALL)
432432
src/s2/internal/s2meta.h
433433
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/internal")
434434
install(FILES src/s2/base/casts.h
435-
src/s2/base/commandlineflags.h
436-
src/s2/base/commandlineflags_declare.h
437435
src/s2/base/log_severity.h
438436
src/s2/base/malloc_extension.h
439-
src/s2/base/port.h
440437
src/s2/base/spinlock.h
441438
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/s2/base")
442439
install(FILES src/s2/testing/gtest_prod.h
@@ -622,7 +619,8 @@ if (BUILD_TESTS)
622619
src/s2/s2wrapped_shape_test.cc
623620
src/s2/sequence_lexicon_test.cc
624621
src/s2/value_lexicon_test.cc
625-
src/s2/util/math/exactfloat/exactfloat_test.cc)
622+
src/s2/util/math/exactfloat/exactfloat_test.cc
623+
src/s2/util/math/exactfloat/exactfloat_underflow_test.cc)
626624

627625
enable_testing()
628626

doc/examples/point_index.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
#include <random>
1010
#include <vector>
1111

12-
#include "s2/base/commandlineflags.h"
13-
#include "s2/s2earth.h"
1412
#include "absl/flags/flag.h"
1513
#include "absl/strings/str_format.h"
14+
1615
#include "s2/s1angle.h"
1716
#include "s2/s2closest_point_query.h"
17+
#include "s2/s2earth.h"
1818
#include "s2/s2point_index.h"
1919
#include "s2/s2random.h"
2020

21-
S2_DEFINE_int32(num_index_points, 10000, "Number of points to index");
22-
S2_DEFINE_int32(num_queries, 10000, "Number of queries");
23-
S2_DEFINE_double(query_radius_km, 100, "Query radius in kilometers");
21+
ABSL_FLAG(int32_t, num_index_points, 10000, "Number of points to index");
22+
ABSL_FLAG(int32_t, num_queries, 10000, "Number of queries");
23+
ABSL_FLAG(double, query_radius_km, 100, "Query radius in kilometers");
2424

2525
int main(int argc, char **argv) {
2626
std::mt19937_64 bitgen;

doc/examples/term_index.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,20 @@
1616
#include <string>
1717
#include <vector>
1818

19-
#include "s2/base/commandlineflags.h"
20-
#include "s2/s2earth.h"
2119
#include "absl/container/btree_set.h"
2220
#include "absl/container/flat_hash_map.h"
2321
#include "absl/flags/flag.h"
2422
#include "absl/strings/str_format.h"
2523
#include "s2/s1angle.h"
2624
#include "s2/s2cap.h"
25+
#include "s2/s2earth.h"
2726
#include "s2/s2point.h"
2827
#include "s2/s2random.h"
2928
#include "s2/s2region_term_indexer.h"
3029

31-
using std::string;
32-
33-
S2_DEFINE_int32(num_documents, 10000, "Number of documents");
34-
S2_DEFINE_int32(num_queries, 10000, "Number of queries");
35-
S2_DEFINE_double(query_radius_km, 100, "Query radius in kilometers");
30+
ABSL_FLAG(int32_t, num_documents, 10000, "Number of documents");
31+
ABSL_FLAG(int32_t, num_queries, 10000, "Number of queries");
32+
ABSL_FLAG(double, query_radius_km, 100, "Query radius in kilometers");
3633

3734
// A prefix added to spatial terms to distinguish them from other index terms
3835
// (e.g. representing words or phrases).

src/BUILD.bazel

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ cc_library(
236236
"//s2:value_lexicon.h",
237237
],
238238
deps = [
239-
"//s2/base:commandlineflags",
240239
"//s2/base:logging",
241-
"//s2/base:port",
242240
"//s2/base:spinlock",
243241
"//s2/testing",
244242
"//s2/util/bitmap",
@@ -387,7 +385,6 @@ cc_library(
387385
includes = ["src"],
388386
deps = [
389387
":s2",
390-
"//s2/base:commandlineflags",
391388
"//s2/base:timer",
392389
"@abseil-cpp//absl/base",
393390
"@abseil-cpp//absl/flags:flag",

src/s2/_fp_contract_off.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@
4141
// appears before the first non-inline function definition. It is
4242
// named with an underscore so that it is included first among the S2 headers.
4343

44-
// Assume all compilers support or ignore the standard pragma.
45-
#pragma STDC FP_CONTRACT OFF
46-
4744
#if defined(__GNUC__) && !defined(__clang__)
4845
// GCC defines its own pragma that operates at the function level rather than
4946
// the statement level.
5047
#pragma GCC optimize("fp-contract=off")
48+
#else
49+
// Assume all other compilers support or ignore the standard pragma.
50+
// Avoid gcc `-Wunknown-pragmas` warnings by not using this for gcc.
51+
#pragma STDC FP_CONTRACT OFF
5152
#endif
5253

5354
#endif // S2__FP_CONTRACT_OFF_H_

src/s2/base/BUILD

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,6 @@ cc_library(
2929
],
3030
)
3131

32-
cc_library(
33-
name = "port",
34-
hdrs = ["port.h"],
35-
)
36-
37-
cc_library(
38-
name = "commandlineflags",
39-
hdrs = [
40-
"commandlineflags.h",
41-
"commandlineflags_declare.h",
42-
],
43-
deps = [
44-
"@abseil-cpp//absl/flags:flag",
45-
],
46-
)
47-
4832
cc_library(
4933
name = "timer",
5034
hdrs = [

src/s2/base/commandlineflags.h

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/s2/base/port.h

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/s2/encoded_s2point_vector.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void EncodeS2PointVector(Span<const S2Point> points, CodingHint hint,
114114
return EncodeS2PointVectorCompact(points, encoder);
115115

116116
default:
117-
ABSL_LOG(ERROR) << "Unknown CodingHint: " << static_cast<int>(hint);
117+
ABSL_LOG(DFATAL) << "Unknown CodingHint: " << static_cast<int>(hint);
118118
}
119119
}
120120

@@ -236,7 +236,7 @@ bool EncodedS2PointVector::InitUncompressedFormat(Decoder* decoder) {
236236
// Maybe the compiler is smart enough that we can do this all the time,
237237
// but more likely we will need two cases using the #ifdef above.
238238
// (Note that even ARMv7 does not support unaligned 64-bit loads.)
239-
ABSL_LOG(ERROR)
239+
ABSL_LOG(DFATAL)
240240
<< "Needs architecture with 64-bit little-endian unaligned loads";
241241
return false;
242242
}

src/s2/encoded_s2point_vector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class EncodedS2PointVector {
6363
//
6464
// Encoded types do not necessarily read all of their data when calling
6565
// Init(), instead only data necessary to decode further is read, which means
66-
// that encoded types may in general log ERROR errors when reading from an
66+
// that encoded types may in general log DFATAL errors when reading from an
6767
// untrusted byte stream using unchecked accessors (e.g. operator[]).
6868
//
6969
// Checked accessors such as Decode(S2Error&) will instead set an error
@@ -182,7 +182,7 @@ inline S2Point EncodedS2PointVector::operator[](int i) const {
182182
S2Error error;
183183
S2Point point = At(i, error);
184184
if (!error.ok()) {
185-
ABSL_LOG(ERROR) << error.message();
185+
ABSL_LOG(DFATAL) << error.message();
186186
}
187187
return point;
188188
#else

0 commit comments

Comments
 (0)