@sentryware/s2-node 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (471) hide show
  1. package/.circleci/config.yml +45 -0
  2. package/.dockerignore +1 -0
  3. package/.gitmodules +3 -0
  4. package/CHANGELOG.md +33 -0
  5. package/LICENSE +201 -0
  6. package/README.md +147 -0
  7. package/binding.gyp +170 -0
  8. package/docker/Dockerfile.node20.test +8 -0
  9. package/docker/Dockerfile.node22.test +8 -0
  10. package/docker/Dockerfile.node24.test +8 -0
  11. package/index.d.ts +117 -0
  12. package/index.js +6 -0
  13. package/jest.config.js +184 -0
  14. package/package.json +43 -0
  15. package/publish-linux.sh +18 -0
  16. package/publish-osx.sh +19 -0
  17. package/src/builder.cc +84 -0
  18. package/src/builder.h +29 -0
  19. package/src/cell.cc +71 -0
  20. package/src/cell.h +26 -0
  21. package/src/cell_id.cc +210 -0
  22. package/src/cell_id.h +44 -0
  23. package/src/cell_union.cc +237 -0
  24. package/src/cell_union.h +34 -0
  25. package/src/earth.cc +185 -0
  26. package/src/earth.h +33 -0
  27. package/src/latlng.cc +132 -0
  28. package/src/latlng.h +28 -0
  29. package/src/loop.cc +51 -0
  30. package/src/loop.h +21 -0
  31. package/src/point.cc +69 -0
  32. package/src/point.h +23 -0
  33. package/src/polygon.cc +36 -0
  34. package/src/polygon.h +20 -0
  35. package/src/polyline.cc +186 -0
  36. package/src/polyline.h +34 -0
  37. package/src/region_coverer.cc +450 -0
  38. package/src/region_coverer.h +56 -0
  39. package/src/s2.cc +27 -0
  40. package/test/Cell.test.js +37 -0
  41. package/test/CellId.test.js +135 -0
  42. package/test/CellUnion.test.js +150 -0
  43. package/test/Earth.test.js +62 -0
  44. package/test/LatLng.test.js +45 -0
  45. package/test/Point.test.js +14 -0
  46. package/test/Polyline.test.js +78 -0
  47. package/test/RegionCoverer.test.js +301 -0
  48. package/test.sh +16 -0
  49. package/third_party/s2geometry/.travis.yml +163 -0
  50. package/third_party/s2geometry/AUTHORS +13 -0
  51. package/third_party/s2geometry/CONTRIBUTING.md +65 -0
  52. package/third_party/s2geometry/CONTRIBUTORS +30 -0
  53. package/third_party/s2geometry/LICENSE +202 -0
  54. package/third_party/s2geometry/NOTICE +5 -0
  55. package/third_party/s2geometry/README.md +127 -0
  56. package/third_party/s2geometry/doc/examples/point_index.cc +44 -0
  57. package/third_party/s2geometry/doc/examples/term_index.cc +99 -0
  58. package/third_party/s2geometry/doc/examples/term_index.py +101 -0
  59. package/third_party/s2geometry/src/python/coder.i +125 -0
  60. package/third_party/s2geometry/src/python/pywraps2_test.py +786 -0
  61. package/third_party/s2geometry/src/python/s2.i +37 -0
  62. package/third_party/s2geometry/src/python/s2_common.i +756 -0
  63. package/third_party/s2geometry/src/s2/_fp_contract_off.h +60 -0
  64. package/third_party/s2geometry/src/s2/base/casts.h +318 -0
  65. package/third_party/s2geometry/src/s2/base/commandlineflags.h +67 -0
  66. package/third_party/s2geometry/src/s2/base/integral_types.h +31 -0
  67. package/third_party/s2geometry/src/s2/base/log_severity.h +40 -0
  68. package/third_party/s2geometry/src/s2/base/logging.h +173 -0
  69. package/third_party/s2geometry/src/s2/base/mutex.h +61 -0
  70. package/third_party/s2geometry/src/s2/base/port.h +999 -0
  71. package/third_party/s2geometry/src/s2/base/spinlock.h +60 -0
  72. package/third_party/s2geometry/src/s2/base/stringprintf.cc +107 -0
  73. package/third_party/s2geometry/src/s2/base/stringprintf.h +53 -0
  74. package/third_party/s2geometry/src/s2/base/strtoint.cc +65 -0
  75. package/third_party/s2geometry/src/s2/base/strtoint.h +106 -0
  76. package/third_party/s2geometry/src/s2/base/timer.h +50 -0
  77. package/third_party/s2geometry/src/s2/encoded_s2cell_id_vector.cc +164 -0
  78. package/third_party/s2geometry/src/s2/encoded_s2cell_id_vector.h +110 -0
  79. package/third_party/s2geometry/src/s2/encoded_s2cell_id_vector_test.cc +232 -0
  80. package/third_party/s2geometry/src/s2/encoded_s2point_vector.cc +838 -0
  81. package/third_party/s2geometry/src/s2/encoded_s2point_vector.h +140 -0
  82. package/third_party/s2geometry/src/s2/encoded_s2point_vector_test.cc +344 -0
  83. package/third_party/s2geometry/src/s2/encoded_s2shape_index.cc +181 -0
  84. package/third_party/s2geometry/src/s2/encoded_s2shape_index.h +276 -0
  85. package/third_party/s2geometry/src/s2/encoded_s2shape_index_test.cc +244 -0
  86. package/third_party/s2geometry/src/s2/encoded_string_vector.cc +66 -0
  87. package/third_party/s2geometry/src/s2/encoded_string_vector.h +164 -0
  88. package/third_party/s2geometry/src/s2/encoded_string_vector_test.cc +69 -0
  89. package/third_party/s2geometry/src/s2/encoded_uint_vector.h +299 -0
  90. package/third_party/s2geometry/src/s2/encoded_uint_vector_test.cc +124 -0
  91. package/third_party/s2geometry/src/s2/id_set_lexicon.cc +81 -0
  92. package/third_party/s2geometry/src/s2/id_set_lexicon.h +199 -0
  93. package/third_party/s2geometry/src/s2/id_set_lexicon_test.cc +70 -0
  94. package/third_party/s2geometry/src/s2/mutable_s2shape_index.cc +1585 -0
  95. package/third_party/s2geometry/src/s2/mutable_s2shape_index.h +600 -0
  96. package/third_party/s2geometry/src/s2/mutable_s2shape_index_test.cc +589 -0
  97. package/third_party/s2geometry/src/s2/r1interval.h +220 -0
  98. package/third_party/s2geometry/src/s2/r1interval_test.cc +185 -0
  99. package/third_party/s2geometry/src/s2/r2.h +26 -0
  100. package/third_party/s2geometry/src/s2/r2rect.cc +93 -0
  101. package/third_party/s2geometry/src/s2/r2rect.h +234 -0
  102. package/third_party/s2geometry/src/s2/r2rect_test.cc +228 -0
  103. package/third_party/s2geometry/src/s2/s1angle.cc +54 -0
  104. package/third_party/s2geometry/src/s2/s1angle.h +336 -0
  105. package/third_party/s2geometry/src/s2/s1angle_test.cc +185 -0
  106. package/third_party/s2geometry/src/s2/s1chord_angle.cc +159 -0
  107. package/third_party/s2geometry/src/s2/s1chord_angle.h +369 -0
  108. package/third_party/s2geometry/src/s2/s1chord_angle_test.cc +207 -0
  109. package/third_party/s2geometry/src/s2/s1interval.cc +296 -0
  110. package/third_party/s2geometry/src/s2/s1interval.h +266 -0
  111. package/third_party/s2geometry/src/s2/s1interval_test.cc +469 -0
  112. package/third_party/s2geometry/src/s2/s2boolean_operation.cc +2391 -0
  113. package/third_party/s2geometry/src/s2/s2boolean_operation.h +501 -0
  114. package/third_party/s2geometry/src/s2/s2boolean_operation_test.cc +1400 -0
  115. package/third_party/s2geometry/src/s2/s2builder.cc +1828 -0
  116. package/third_party/s2geometry/src/s2/s2builder.h +1057 -0
  117. package/third_party/s2geometry/src/s2/s2builder_graph.cc +1084 -0
  118. package/third_party/s2geometry/src/s2/s2builder_graph.h +799 -0
  119. package/third_party/s2geometry/src/s2/s2builder_graph_test.cc +462 -0
  120. package/third_party/s2geometry/src/s2/s2builder_layer.h +50 -0
  121. package/third_party/s2geometry/src/s2/s2builder_test.cc +1329 -0
  122. package/third_party/s2geometry/src/s2/s2builderutil_closed_set_normalizer.cc +313 -0
  123. package/third_party/s2geometry/src/s2/s2builderutil_closed_set_normalizer.h +221 -0
  124. package/third_party/s2geometry/src/s2/s2builderutil_closed_set_normalizer_test.cc +261 -0
  125. package/third_party/s2geometry/src/s2/s2builderutil_find_polygon_degeneracies.cc +392 -0
  126. package/third_party/s2geometry/src/s2/s2builderutil_find_polygon_degeneracies.h +86 -0
  127. package/third_party/s2geometry/src/s2/s2builderutil_find_polygon_degeneracies_test.cc +182 -0
  128. package/third_party/s2geometry/src/s2/s2builderutil_graph_shape.h +57 -0
  129. package/third_party/s2geometry/src/s2/s2builderutil_lax_polygon_layer.cc +212 -0
  130. package/third_party/s2geometry/src/s2/s2builderutil_lax_polygon_layer.h +218 -0
  131. package/third_party/s2geometry/src/s2/s2builderutil_lax_polygon_layer_test.cc +367 -0
  132. package/third_party/s2geometry/src/s2/s2builderutil_s2point_vector_layer.cc +74 -0
  133. package/third_party/s2geometry/src/s2/s2builderutil_s2point_vector_layer.h +122 -0
  134. package/third_party/s2geometry/src/s2/s2builderutil_s2point_vector_layer_test.cc +167 -0
  135. package/third_party/s2geometry/src/s2/s2builderutil_s2polygon_layer.cc +191 -0
  136. package/third_party/s2geometry/src/s2/s2builderutil_s2polygon_layer.h +211 -0
  137. package/third_party/s2geometry/src/s2/s2builderutil_s2polygon_layer_test.cc +312 -0
  138. package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_layer.cc +105 -0
  139. package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_layer.h +174 -0
  140. package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_layer_test.cc +220 -0
  141. package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_vector_layer.cc +98 -0
  142. package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_vector_layer.h +292 -0
  143. package/third_party/s2geometry/src/s2/s2builderutil_s2polyline_vector_layer_test.cc +233 -0
  144. package/third_party/s2geometry/src/s2/s2builderutil_snap_functions.cc +354 -0
  145. package/third_party/s2geometry/src/s2/s2builderutil_snap_functions.h +239 -0
  146. package/third_party/s2geometry/src/s2/s2builderutil_snap_functions_test.cc +716 -0
  147. package/third_party/s2geometry/src/s2/s2builderutil_testing.cc +37 -0
  148. package/third_party/s2geometry/src/s2/s2builderutil_testing.h +100 -0
  149. package/third_party/s2geometry/src/s2/s2builderutil_testing_test.cc +85 -0
  150. package/third_party/s2geometry/src/s2/s2cap.cc +347 -0
  151. package/third_party/s2geometry/src/s2/s2cap.h +286 -0
  152. package/third_party/s2geometry/src/s2/s2cap_test.cc +379 -0
  153. package/third_party/s2geometry/src/s2/s2cell.cc +552 -0
  154. package/third_party/s2geometry/src/s2/s2cell.h +249 -0
  155. package/third_party/s2geometry/src/s2/s2cell_id.cc +619 -0
  156. package/third_party/s2geometry/src/s2/s2cell_id.h +705 -0
  157. package/third_party/s2geometry/src/s2/s2cell_id_test.cc +633 -0
  158. package/third_party/s2geometry/src/s2/s2cell_index.cc +149 -0
  159. package/third_party/s2geometry/src/s2/s2cell_index.h +660 -0
  160. package/third_party/s2geometry/src/s2/s2cell_index_test.cc +411 -0
  161. package/third_party/s2geometry/src/s2/s2cell_test.cc +687 -0
  162. package/third_party/s2geometry/src/s2/s2cell_union.cc +515 -0
  163. package/third_party/s2geometry/src/s2/s2cell_union.h +399 -0
  164. package/third_party/s2geometry/src/s2/s2cell_union_test.cc +598 -0
  165. package/third_party/s2geometry/src/s2/s2centroids.cc +84 -0
  166. package/third_party/s2geometry/src/s2/s2centroids.h +87 -0
  167. package/third_party/s2geometry/src/s2/s2centroids_test.cc +82 -0
  168. package/third_party/s2geometry/src/s2/s2closest_cell_query.cc +123 -0
  169. package/third_party/s2geometry/src/s2/s2closest_cell_query.h +385 -0
  170. package/third_party/s2geometry/src/s2/s2closest_cell_query_base.h +841 -0
  171. package/third_party/s2geometry/src/s2/s2closest_cell_query_base_test.cc +63 -0
  172. package/third_party/s2geometry/src/s2/s2closest_cell_query_test.cc +412 -0
  173. package/third_party/s2geometry/src/s2/s2closest_edge_query.cc +106 -0
  174. package/third_party/s2geometry/src/s2/s2closest_edge_query.h +421 -0
  175. package/third_party/s2geometry/src/s2/s2closest_edge_query_base.h +946 -0
  176. package/third_party/s2geometry/src/s2/s2closest_edge_query_base_test.cc +59 -0
  177. package/third_party/s2geometry/src/s2/s2closest_edge_query_test.cc +505 -0
  178. package/third_party/s2geometry/src/s2/s2closest_edge_query_testing.h +91 -0
  179. package/third_party/s2geometry/src/s2/s2closest_point_query.cc +66 -0
  180. package/third_party/s2geometry/src/s2/s2closest_point_query.h +465 -0
  181. package/third_party/s2geometry/src/s2/s2closest_point_query_base.h +767 -0
  182. package/third_party/s2geometry/src/s2/s2closest_point_query_base_test.cc +63 -0
  183. package/third_party/s2geometry/src/s2/s2closest_point_query_test.cc +312 -0
  184. package/third_party/s2geometry/src/s2/s2contains_point_query.h +328 -0
  185. package/third_party/s2geometry/src/s2/s2contains_point_query_test.cc +159 -0
  186. package/third_party/s2geometry/src/s2/s2contains_vertex_query.cc +39 -0
  187. package/third_party/s2geometry/src/s2/s2contains_vertex_query.h +66 -0
  188. package/third_party/s2geometry/src/s2/s2contains_vertex_query_test.cc +67 -0
  189. package/third_party/s2geometry/src/s2/s2convex_hull_query.cc +198 -0
  190. package/third_party/s2geometry/src/s2/s2convex_hull_query.h +110 -0
  191. package/third_party/s2geometry/src/s2/s2convex_hull_query_test.cc +208 -0
  192. package/third_party/s2geometry/src/s2/s2coords.cc +146 -0
  193. package/third_party/s2geometry/src/s2/s2coords.h +459 -0
  194. package/third_party/s2geometry/src/s2/s2coords_internal.h +71 -0
  195. package/third_party/s2geometry/src/s2/s2coords_test.cc +218 -0
  196. package/third_party/s2geometry/src/s2/s2crossing_edge_query.cc +380 -0
  197. package/third_party/s2geometry/src/s2/s2crossing_edge_query.h +220 -0
  198. package/third_party/s2geometry/src/s2/s2crossing_edge_query_test.cc +382 -0
  199. package/third_party/s2geometry/src/s2/s2debug.cc +23 -0
  200. package/third_party/s2geometry/src/s2/s2debug.h +69 -0
  201. package/third_party/s2geometry/src/s2/s2distance_target.h +165 -0
  202. package/third_party/s2geometry/src/s2/s2earth.cc +52 -0
  203. package/third_party/s2geometry/src/s2/s2earth.h +268 -0
  204. package/third_party/s2geometry/src/s2/s2earth_test.cc +146 -0
  205. package/third_party/s2geometry/src/s2/s2edge_clipping.cc +462 -0
  206. package/third_party/s2geometry/src/s2/s2edge_clipping.h +183 -0
  207. package/third_party/s2geometry/src/s2/s2edge_clipping_test.cc +335 -0
  208. package/third_party/s2geometry/src/s2/s2edge_crosser.cc +85 -0
  209. package/third_party/s2geometry/src/s2/s2edge_crosser.h +343 -0
  210. package/third_party/s2geometry/src/s2/s2edge_crosser_test.cc +264 -0
  211. package/third_party/s2geometry/src/s2/s2edge_crossings.cc +515 -0
  212. package/third_party/s2geometry/src/s2/s2edge_crossings.h +138 -0
  213. package/third_party/s2geometry/src/s2/s2edge_crossings_internal.h +59 -0
  214. package/third_party/s2geometry/src/s2/s2edge_crossings_test.cc +246 -0
  215. package/third_party/s2geometry/src/s2/s2edge_distances.cc +419 -0
  216. package/third_party/s2geometry/src/s2/s2edge_distances.h +192 -0
  217. package/third_party/s2geometry/src/s2/s2edge_distances_test.cc +539 -0
  218. package/third_party/s2geometry/src/s2/s2edge_tessellator.cc +276 -0
  219. package/third_party/s2geometry/src/s2/s2edge_tessellator.h +101 -0
  220. package/third_party/s2geometry/src/s2/s2edge_tessellator_test.cc +492 -0
  221. package/third_party/s2geometry/src/s2/s2edge_vector_shape.h +85 -0
  222. package/third_party/s2geometry/src/s2/s2edge_vector_shape_test.cc +66 -0
  223. package/third_party/s2geometry/src/s2/s2error.cc +29 -0
  224. package/third_party/s2geometry/src/s2/s2error.h +147 -0
  225. package/third_party/s2geometry/src/s2/s2error_test.cc +31 -0
  226. package/third_party/s2geometry/src/s2/s2furthest_edge_query.cc +117 -0
  227. package/third_party/s2geometry/src/s2/s2furthest_edge_query.h +439 -0
  228. package/third_party/s2geometry/src/s2/s2furthest_edge_query_test.cc +487 -0
  229. package/third_party/s2geometry/src/s2/s2latlng.cc +90 -0
  230. package/third_party/s2geometry/src/s2/s2latlng.h +234 -0
  231. package/third_party/s2geometry/src/s2/s2latlng_rect.cc +727 -0
  232. package/third_party/s2geometry/src/s2/s2latlng_rect.h +434 -0
  233. package/third_party/s2geometry/src/s2/s2latlng_rect_bounder.cc +344 -0
  234. package/third_party/s2geometry/src/s2/s2latlng_rect_bounder.h +89 -0
  235. package/third_party/s2geometry/src/s2/s2latlng_rect_bounder_test.cc +306 -0
  236. package/third_party/s2geometry/src/s2/s2latlng_rect_test.cc +1030 -0
  237. package/third_party/s2geometry/src/s2/s2latlng_test.cc +165 -0
  238. package/third_party/s2geometry/src/s2/s2lax_loop_shape.cc +104 -0
  239. package/third_party/s2geometry/src/s2/s2lax_loop_shape.h +153 -0
  240. package/third_party/s2geometry/src/s2/s2lax_loop_shape_test.cc +101 -0
  241. package/third_party/s2geometry/src/s2/s2lax_polygon_shape.cc +348 -0
  242. package/third_party/s2geometry/src/s2/s2lax_polygon_shape.h +183 -0
  243. package/third_party/s2geometry/src/s2/s2lax_polygon_shape_test.cc +234 -0
  244. package/third_party/s2geometry/src/s2/s2lax_polyline_shape.cc +118 -0
  245. package/third_party/s2geometry/src/s2/s2lax_polyline_shape.h +124 -0
  246. package/third_party/s2geometry/src/s2/s2lax_polyline_shape_test.cc +62 -0
  247. package/third_party/s2geometry/src/s2/s2loop.cc +1509 -0
  248. package/third_party/s2geometry/src/s2/s2loop.h +711 -0
  249. package/third_party/s2geometry/src/s2/s2loop_measures.cc +313 -0
  250. package/third_party/s2geometry/src/s2/s2loop_measures.h +280 -0
  251. package/third_party/s2geometry/src/s2/s2loop_measures_test.cc +367 -0
  252. package/third_party/s2geometry/src/s2/s2loop_test.cc +1371 -0
  253. package/third_party/s2geometry/src/s2/s2max_distance_targets.cc +265 -0
  254. package/third_party/s2geometry/src/s2/s2max_distance_targets.h +241 -0
  255. package/third_party/s2geometry/src/s2/s2max_distance_targets_test.cc +367 -0
  256. package/third_party/s2geometry/src/s2/s2measures.cc +128 -0
  257. package/third_party/s2geometry/src/s2/s2measures.h +78 -0
  258. package/third_party/s2geometry/src/s2/s2measures_test.cc +135 -0
  259. package/third_party/s2geometry/src/s2/s2metrics.cc +122 -0
  260. package/third_party/s2geometry/src/s2/s2metrics.h +199 -0
  261. package/third_party/s2geometry/src/s2/s2metrics_test.cc +127 -0
  262. package/third_party/s2geometry/src/s2/s2min_distance_targets.cc +295 -0
  263. package/third_party/s2geometry/src/s2/s2min_distance_targets.h +273 -0
  264. package/third_party/s2geometry/src/s2/s2min_distance_targets_test.cc +239 -0
  265. package/third_party/s2geometry/src/s2/s2padded_cell.cc +162 -0
  266. package/third_party/s2geometry/src/s2/s2padded_cell.h +108 -0
  267. package/third_party/s2geometry/src/s2/s2padded_cell_test.cc +138 -0
  268. package/third_party/s2geometry/src/s2/s2point.h +38 -0
  269. package/third_party/s2geometry/src/s2/s2point_compression.cc +388 -0
  270. package/third_party/s2geometry/src/s2/s2point_compression.h +78 -0
  271. package/third_party/s2geometry/src/s2/s2point_compression_test.cc +305 -0
  272. package/third_party/s2geometry/src/s2/s2point_index.h +345 -0
  273. package/third_party/s2geometry/src/s2/s2point_index_test.cc +147 -0
  274. package/third_party/s2geometry/src/s2/s2point_region.cc +72 -0
  275. package/third_party/s2geometry/src/s2/s2point_region.h +76 -0
  276. package/third_party/s2geometry/src/s2/s2point_region_test.cc +100 -0
  277. package/third_party/s2geometry/src/s2/s2point_span.h +57 -0
  278. package/third_party/s2geometry/src/s2/s2point_test.cc +47 -0
  279. package/third_party/s2geometry/src/s2/s2point_vector_shape.h +127 -0
  280. package/third_party/s2geometry/src/s2/s2point_vector_shape_test.cc +59 -0
  281. package/third_party/s2geometry/src/s2/s2pointutil.cc +131 -0
  282. package/third_party/s2geometry/src/s2/s2pointutil.h +138 -0
  283. package/third_party/s2geometry/src/s2/s2pointutil_test.cc +157 -0
  284. package/third_party/s2geometry/src/s2/s2polygon.cc +1569 -0
  285. package/third_party/s2geometry/src/s2/s2polygon.h +934 -0
  286. package/third_party/s2geometry/src/s2/s2polygon_test.cc +3025 -0
  287. package/third_party/s2geometry/src/s2/s2polyline.cc +645 -0
  288. package/third_party/s2geometry/src/s2/s2polyline.h +379 -0
  289. package/third_party/s2geometry/src/s2/s2polyline_alignment.cc +414 -0
  290. package/third_party/s2geometry/src/s2/s2polyline_alignment.h +245 -0
  291. package/third_party/s2geometry/src/s2/s2polyline_alignment_internal.h +158 -0
  292. package/third_party/s2geometry/src/s2/s2polyline_alignment_test.cc +610 -0
  293. package/third_party/s2geometry/src/s2/s2polyline_measures.cc +42 -0
  294. package/third_party/s2geometry/src/s2/s2polyline_measures.h +53 -0
  295. package/third_party/s2geometry/src/s2/s2polyline_measures_test.cc +57 -0
  296. package/third_party/s2geometry/src/s2/s2polyline_simplifier.cc +187 -0
  297. package/third_party/s2geometry/src/s2/s2polyline_simplifier.h +109 -0
  298. package/third_party/s2geometry/src/s2/s2polyline_simplifier_test.cc +165 -0
  299. package/third_party/s2geometry/src/s2/s2polyline_test.cc +554 -0
  300. package/third_party/s2geometry/src/s2/s2predicates.cc +1486 -0
  301. package/third_party/s2geometry/src/s2/s2predicates.h +282 -0
  302. package/third_party/s2geometry/src/s2/s2predicates_internal.h +135 -0
  303. package/third_party/s2geometry/src/s2/s2predicates_test.cc +1427 -0
  304. package/third_party/s2geometry/src/s2/s2projections.cc +109 -0
  305. package/third_party/s2geometry/src/s2/s2projections.h +161 -0
  306. package/third_party/s2geometry/src/s2/s2projections_test.cc +78 -0
  307. package/third_party/s2geometry/src/s2/s2r2rect.cc +88 -0
  308. package/third_party/s2geometry/src/s2/s2r2rect.h +292 -0
  309. package/third_party/s2geometry/src/s2/s2r2rect_test.cc +312 -0
  310. package/third_party/s2geometry/src/s2/s2region.cc +26 -0
  311. package/third_party/s2geometry/src/s2/s2region.h +142 -0
  312. package/third_party/s2geometry/src/s2/s2region_coverer.cc +514 -0
  313. package/third_party/s2geometry/src/s2/s2region_coverer.h +356 -0
  314. package/third_party/s2geometry/src/s2/s2region_coverer_test.cc +509 -0
  315. package/third_party/s2geometry/src/s2/s2region_intersection.cc +84 -0
  316. package/third_party/s2geometry/src/s2/s2region_intersection.h +79 -0
  317. package/third_party/s2geometry/src/s2/s2region_term_indexer.cc +270 -0
  318. package/third_party/s2geometry/src/s2/s2region_term_indexer.h +299 -0
  319. package/third_party/s2geometry/src/s2/s2region_term_indexer_test.cc +209 -0
  320. package/third_party/s2geometry/src/s2/s2region_test.cc +370 -0
  321. package/third_party/s2geometry/src/s2/s2region_union.cc +90 -0
  322. package/third_party/s2geometry/src/s2/s2region_union.h +83 -0
  323. package/third_party/s2geometry/src/s2/s2region_union_test.cc +89 -0
  324. package/third_party/s2geometry/src/s2/s2shape.h +283 -0
  325. package/third_party/s2geometry/src/s2/s2shape_index.cc +321 -0
  326. package/third_party/s2geometry/src/s2/s2shape_index.h +781 -0
  327. package/third_party/s2geometry/src/s2/s2shape_index_buffered_region.cc +113 -0
  328. package/third_party/s2geometry/src/s2/s2shape_index_buffered_region.h +135 -0
  329. package/third_party/s2geometry/src/s2/s2shape_index_buffered_region_test.cc +162 -0
  330. package/third_party/s2geometry/src/s2/s2shape_index_measures.cc +92 -0
  331. package/third_party/s2geometry/src/s2/s2shape_index_measures.h +100 -0
  332. package/third_party/s2geometry/src/s2/s2shape_index_measures_test.cc +136 -0
  333. package/third_party/s2geometry/src/s2/s2shape_index_region.h +350 -0
  334. package/third_party/s2geometry/src/s2/s2shape_index_region_test.cc +161 -0
  335. package/third_party/s2geometry/src/s2/s2shape_index_test.cc +24 -0
  336. package/third_party/s2geometry/src/s2/s2shape_measures.cc +138 -0
  337. package/third_party/s2geometry/src/s2/s2shape_measures.h +95 -0
  338. package/third_party/s2geometry/src/s2/s2shape_measures_test.cc +139 -0
  339. package/third_party/s2geometry/src/s2/s2shapeutil_build_polygon_boundaries.cc +120 -0
  340. package/third_party/s2geometry/src/s2/s2shapeutil_build_polygon_boundaries.h +66 -0
  341. package/third_party/s2geometry/src/s2/s2shapeutil_build_polygon_boundaries_test.cc +170 -0
  342. package/third_party/s2geometry/src/s2/s2shapeutil_coding.cc +253 -0
  343. package/third_party/s2geometry/src/s2/s2shapeutil_coding.h +283 -0
  344. package/third_party/s2geometry/src/s2/s2shapeutil_coding_test.cc +54 -0
  345. package/third_party/s2geometry/src/s2/s2shapeutil_contains_brute_force.cc +40 -0
  346. package/third_party/s2geometry/src/s2/s2shapeutil_contains_brute_force.h +41 -0
  347. package/third_party/s2geometry/src/s2/s2shapeutil_contains_brute_force_test.cc +55 -0
  348. package/third_party/s2geometry/src/s2/s2shapeutil_count_edges.h +57 -0
  349. package/third_party/s2geometry/src/s2/s2shapeutil_count_edges_test.cc +43 -0
  350. package/third_party/s2geometry/src/s2/s2shapeutil_edge_iterator.cc +45 -0
  351. package/third_party/s2geometry/src/s2/s2shapeutil_edge_iterator.h +72 -0
  352. package/third_party/s2geometry/src/s2/s2shapeutil_edge_iterator_test.cc +116 -0
  353. package/third_party/s2geometry/src/s2/s2shapeutil_get_reference_point.cc +107 -0
  354. package/third_party/s2geometry/src/s2/s2shapeutil_get_reference_point.h +48 -0
  355. package/third_party/s2geometry/src/s2/s2shapeutil_get_reference_point_test.cc +104 -0
  356. package/third_party/s2geometry/src/s2/s2shapeutil_range_iterator.cc +58 -0
  357. package/third_party/s2geometry/src/s2/s2shapeutil_range_iterator.h +65 -0
  358. package/third_party/s2geometry/src/s2/s2shapeutil_range_iterator_test.cc +61 -0
  359. package/third_party/s2geometry/src/s2/s2shapeutil_shape_edge.h +58 -0
  360. package/third_party/s2geometry/src/s2/s2shapeutil_shape_edge_id.h +97 -0
  361. package/third_party/s2geometry/src/s2/s2shapeutil_testing.cc +104 -0
  362. package/third_party/s2geometry/src/s2/s2shapeutil_testing.h +36 -0
  363. package/third_party/s2geometry/src/s2/s2shapeutil_visit_crossing_edge_pairs.cc +440 -0
  364. package/third_party/s2geometry/src/s2/s2shapeutil_visit_crossing_edge_pairs.h +72 -0
  365. package/third_party/s2geometry/src/s2/s2shapeutil_visit_crossing_edge_pairs_test.cc +184 -0
  366. package/third_party/s2geometry/src/s2/s2testing.cc +464 -0
  367. package/third_party/s2geometry/src/s2/s2testing.h +385 -0
  368. package/third_party/s2geometry/src/s2/s2testing_test.cc +166 -0
  369. package/third_party/s2geometry/src/s2/s2text_format.cc +506 -0
  370. package/third_party/s2geometry/src/s2/s2text_format.h +289 -0
  371. package/third_party/s2geometry/src/s2/s2text_format_test.cc +417 -0
  372. package/third_party/s2geometry/src/s2/s2wedge_relations.cc +80 -0
  373. package/third_party/s2geometry/src/s2/s2wedge_relations.h +64 -0
  374. package/third_party/s2geometry/src/s2/s2wedge_relations_test.cc +89 -0
  375. package/third_party/s2geometry/src/s2/sequence_lexicon.h +296 -0
  376. package/third_party/s2geometry/src/s2/sequence_lexicon_test.cc +113 -0
  377. package/third_party/s2geometry/src/s2/strings/ostringstream.cc +35 -0
  378. package/third_party/s2geometry/src/s2/strings/ostringstream.h +105 -0
  379. package/third_party/s2geometry/src/s2/strings/serialize.cc +46 -0
  380. package/third_party/s2geometry/src/s2/strings/serialize.h +40 -0
  381. package/third_party/s2geometry/src/s2/third_party/absl/algorithm/algorithm.h +187 -0
  382. package/third_party/s2geometry/src/s2/third_party/absl/base/attributes.h +666 -0
  383. package/third_party/s2geometry/src/s2/third_party/absl/base/casts.h +189 -0
  384. package/third_party/s2geometry/src/s2/third_party/absl/base/config.h +462 -0
  385. package/third_party/s2geometry/src/s2/third_party/absl/base/dynamic_annotations.cc +129 -0
  386. package/third_party/s2geometry/src/s2/third_party/absl/base/dynamic_annotations.h +394 -0
  387. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/atomic_hook.h +168 -0
  388. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/identity.h +33 -0
  389. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/inline_variable.h +117 -0
  390. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/invoke.h +188 -0
  391. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/raw_logging.cc +254 -0
  392. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/raw_logging.h +205 -0
  393. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/throw_delegate.cc +106 -0
  394. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/throw_delegate.h +71 -0
  395. package/third_party/s2geometry/src/s2/third_party/absl/base/internal/unaligned_access.h +322 -0
  396. package/third_party/s2geometry/src/s2/third_party/absl/base/log_severity.h +77 -0
  397. package/third_party/s2geometry/src/s2/third_party/absl/base/macros.h +236 -0
  398. package/third_party/s2geometry/src/s2/third_party/absl/base/optimization.h +177 -0
  399. package/third_party/s2geometry/src/s2/third_party/absl/base/policy_checks.h +124 -0
  400. package/third_party/s2geometry/src/s2/third_party/absl/base/port.h +97 -0
  401. package/third_party/s2geometry/src/s2/third_party/absl/base/thread_annotations.h +277 -0
  402. package/third_party/s2geometry/src/s2/third_party/absl/container/fixed_array.h +523 -0
  403. package/third_party/s2geometry/src/s2/third_party/absl/container/inlined_vector.h +1453 -0
  404. package/third_party/s2geometry/src/s2/third_party/absl/container/internal/compressed_tuple.h +191 -0
  405. package/third_party/s2geometry/src/s2/third_party/absl/container/internal/container_memory.h +424 -0
  406. package/third_party/s2geometry/src/s2/third_party/absl/container/internal/layout.h +739 -0
  407. package/third_party/s2geometry/src/s2/third_party/absl/memory/memory.h +755 -0
  408. package/third_party/s2geometry/src/s2/third_party/absl/meta/type_traits.h +436 -0
  409. package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128.cc +232 -0
  410. package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128.h +656 -0
  411. package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128_have_intrinsic.inc +3 -0
  412. package/third_party/s2geometry/src/s2/third_party/absl/numeric/int128_no_intrinsic.inc +3 -0
  413. package/third_party/s2geometry/src/s2/third_party/absl/strings/ascii.cc +198 -0
  414. package/third_party/s2geometry/src/s2/third_party/absl/strings/ascii.h +239 -0
  415. package/third_party/s2geometry/src/s2/third_party/absl/strings/ascii_ctype.h +66 -0
  416. package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/bits.h +53 -0
  417. package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/memutil.cc +110 -0
  418. package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/memutil.h +146 -0
  419. package/third_party/s2geometry/src/s2/third_party/absl/strings/internal/resize_uninitialized.h +72 -0
  420. package/third_party/s2geometry/src/s2/third_party/absl/strings/match.cc +38 -0
  421. package/third_party/s2geometry/src/s2/third_party/absl/strings/match.h +89 -0
  422. package/third_party/s2geometry/src/s2/third_party/absl/strings/numbers.cc +909 -0
  423. package/third_party/s2geometry/src/s2/third_party/absl/strings/numbers.h +187 -0
  424. package/third_party/s2geometry/src/s2/third_party/absl/strings/str_cat.cc +240 -0
  425. package/third_party/s2geometry/src/s2/third_party/absl/strings/str_cat.h +398 -0
  426. package/third_party/s2geometry/src/s2/third_party/absl/strings/str_join.h +22 -0
  427. package/third_party/s2geometry/src/s2/third_party/absl/strings/str_split.cc +47 -0
  428. package/third_party/s2geometry/src/s2/third_party/absl/strings/str_split.h +43 -0
  429. package/third_party/s2geometry/src/s2/third_party/absl/strings/string_view.cc +245 -0
  430. package/third_party/s2geometry/src/s2/third_party/absl/strings/string_view.h +602 -0
  431. package/third_party/s2geometry/src/s2/third_party/absl/strings/strip.cc +42 -0
  432. package/third_party/s2geometry/src/s2/third_party/absl/strings/strip.h +130 -0
  433. package/third_party/s2geometry/src/s2/third_party/absl/types/span.h +793 -0
  434. package/third_party/s2geometry/src/s2/third_party/absl/utility/utility.h +299 -0
  435. package/third_party/s2geometry/src/s2/util/bits/bit-interleave.cc +274 -0
  436. package/third_party/s2geometry/src/s2/util/bits/bit-interleave.h +53 -0
  437. package/third_party/s2geometry/src/s2/util/bits/bits.cc +155 -0
  438. package/third_party/s2geometry/src/s2/util/bits/bits.h +745 -0
  439. package/third_party/s2geometry/src/s2/util/coding/coder.cc +83 -0
  440. package/third_party/s2geometry/src/s2/util/coding/coder.h +553 -0
  441. package/third_party/s2geometry/src/s2/util/coding/nth-derivative.h +134 -0
  442. package/third_party/s2geometry/src/s2/util/coding/transforms.h +62 -0
  443. package/third_party/s2geometry/src/s2/util/coding/varint.cc +289 -0
  444. package/third_party/s2geometry/src/s2/util/coding/varint.h +476 -0
  445. package/third_party/s2geometry/src/s2/util/endian/endian.h +859 -0
  446. package/third_party/s2geometry/src/s2/util/gtl/btree.h +2471 -0
  447. package/third_party/s2geometry/src/s2/util/gtl/btree_container.h +411 -0
  448. package/third_party/s2geometry/src/s2/util/gtl/btree_map.h +79 -0
  449. package/third_party/s2geometry/src/s2/util/gtl/btree_set.h +73 -0
  450. package/third_party/s2geometry/src/s2/util/gtl/compact_array.h +653 -0
  451. package/third_party/s2geometry/src/s2/util/gtl/container_logging.h +291 -0
  452. package/third_party/s2geometry/src/s2/util/gtl/dense_hash_set.h +358 -0
  453. package/third_party/s2geometry/src/s2/util/gtl/densehashtable.h +1493 -0
  454. package/third_party/s2geometry/src/s2/util/gtl/hashtable_common.h +253 -0
  455. package/third_party/s2geometry/src/s2/util/gtl/layout.h +28 -0
  456. package/third_party/s2geometry/src/s2/util/gtl/legacy_random_shuffle.h +77 -0
  457. package/third_party/s2geometry/src/s2/util/hash/mix.h +76 -0
  458. package/third_party/s2geometry/src/s2/util/math/exactfloat/exactfloat.cc +832 -0
  459. package/third_party/s2geometry/src/s2/util/math/exactfloat/exactfloat.h +646 -0
  460. package/third_party/s2geometry/src/s2/util/math/mathutil.cc +75 -0
  461. package/third_party/s2geometry/src/s2/util/math/mathutil.h +189 -0
  462. package/third_party/s2geometry/src/s2/util/math/matrix3x3.h +574 -0
  463. package/third_party/s2geometry/src/s2/util/math/vector.h +569 -0
  464. package/third_party/s2geometry/src/s2/util/math/vector3_hash.h +54 -0
  465. package/third_party/s2geometry/src/s2/util/units/length-units.cc +21 -0
  466. package/third_party/s2geometry/src/s2/util/units/length-units.h +135 -0
  467. package/third_party/s2geometry/src/s2/util/units/physical-units.h +313 -0
  468. package/third_party/s2geometry/src/s2/value_lexicon.h +234 -0
  469. package/third_party/s2geometry/src/s2/value_lexicon_test.cc +121 -0
  470. package/third_party/s2geometry/third_party/cmake/FindGFlags.cmake +48 -0
  471. package/third_party/s2geometry/third_party/cmake/FindGlog.cmake +48 -0
@@ -0,0 +1,999 @@
1
+ // Copyright Google Inc. All Rights Reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS-IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+
16
+ #ifndef S2_BASE_PORT_H_
17
+ #define S2_BASE_PORT_H_
18
+
19
+ // This file contains things that are not used in third_party/absl but needed by
20
+ // - Platform specific requirement
21
+ // - MSVC
22
+ // - Utility macros
23
+ // - Endianness
24
+ // - Hash
25
+ // - Global variables
26
+ // - Type alias
27
+ // - Predefined system/language macros
28
+ // - Predefined system/language functions
29
+ // - Performance optimization (alignment)
30
+ // - Obsolete
31
+
32
+ #include <cassert>
33
+ #include <climits>
34
+ #include <cstdlib>
35
+ #include <cstring>
36
+
37
+ #include "s2/base/integral_types.h"
38
+ #include "s2/third_party/absl/base/config.h"
39
+ #include "s2/third_party/absl/base/port.h"
40
+
41
+ #ifdef SWIG
42
+ %include "third_party/absl/base/port.h"
43
+ #endif
44
+
45
+ // -----------------------------------------------------------------------------
46
+ // MSVC Specific Requirements
47
+ // -----------------------------------------------------------------------------
48
+
49
+ #ifdef _MSC_VER /* if Visual C++ */
50
+
51
+ #include <winsock2.h> // Must come before <windows.h>
52
+ #include <intrin.h>
53
+ #include <process.h> // _getpid()
54
+ #include <windows.h>
55
+ #undef ERROR
56
+ #undef DELETE
57
+ #undef DIFFERENCE
58
+ #define STDIN_FILENO 0
59
+ #define STDOUT_FILENO 1
60
+ #define STDERR_FILENO 2
61
+ #define S_IRUSR 00400
62
+ #define S_IWUSR 00200
63
+ #define S_IXUSR 00100
64
+ #define S_IRGRP 00040
65
+ #define S_IWGRP 00020
66
+ #define S_IXGRP 00010
67
+ #define S_IROTH 00004
68
+ #define S_IWOTH 00002
69
+ #define S_IXOTH 00001
70
+
71
+ // This compiler flag can be easily overlooked on MSVC.
72
+ // _CHAR_UNSIGNED gets set with the /J flag.
73
+ #ifndef _CHAR_UNSIGNED
74
+ #error chars must be unsigned! Use the /J flag on the compiler command line. // NOLINT
75
+ #endif
76
+
77
+ // Allow comparisons between signed and unsigned values.
78
+ //
79
+ // Lots of Google code uses this pattern:
80
+ // for (int i = 0; i < container.size(); ++i)
81
+ // Since size() returns an unsigned value, this warning would trigger
82
+ // frequently. Very few of these instances are actually bugs since containers
83
+ // rarely exceed MAX_INT items. Unfortunately, there are bugs related to
84
+ // signed-unsigned comparisons that have been missed because we disable this
85
+ // warning. For example:
86
+ // const long stop_time = os::GetMilliseconds() + kWaitTimeoutMillis;
87
+ // while (os::GetMilliseconds() <= stop_time) { ... }
88
+ #pragma warning(disable : 4018) // level 3
89
+ #pragma warning(disable : 4267) // level 3
90
+
91
+ // Don't warn about unused local variables.
92
+ //
93
+ // extension to silence particular instances of this warning. There's no way
94
+ // to define ABSL_ATTRIBUTE_UNUSED to quiet particular instances of this warning
95
+ // in VC++, so we disable it globally. Currently, there aren't many false
96
+ // positives, so perhaps we can address those in the future and re-enable these
97
+ // warnings, which sometimes catch real bugs.
98
+ #pragma warning(disable : 4101) // level 3
99
+
100
+ // Allow initialization and assignment to a smaller type without warnings about
101
+ // possible loss of data.
102
+ //
103
+ // There is a distinct warning, 4267, that warns about size_t conversions to
104
+ // smaller types, but we don't currently disable that warning.
105
+ //
106
+ // Correct code can be written in such a way as to avoid false positives
107
+ // by making the conversion explicit, but Google code isn't usually that
108
+ // verbose. There are too many false positives to address at this time. Note
109
+ // that this warning triggers at levels 2, 3, and 4 depending on the specific
110
+ // type of conversion. By disabling it, we not only silence minor narrowing
111
+ // conversions but also serious ones.
112
+ #pragma warning(disable : 4244) // level 2, 3, and 4
113
+
114
+ // Allow silent truncation of double to float.
115
+ //
116
+ // Silencing this warning has caused us to miss some subtle bugs.
117
+ #pragma warning(disable : 4305) // level 1
118
+
119
+ // Allow a constant to be assigned to a type that is too small.
120
+ //
121
+ // I don't know why we allow this at all. I can't think of a case where this
122
+ // wouldn't be a bug, but enabling the warning breaks many builds today.
123
+ #pragma warning(disable : 4307) // level 2
124
+
125
+ // Allow passing the this pointer to an initializer even though it refers
126
+ // to an uninitialized object.
127
+ //
128
+ // Some observer implementations rely on saving the this pointer. Those are
129
+ // safe because the pointer is not dereferenced until after the object is fully
130
+ // constructed. This could however, obscure other instances. In the future, we
131
+ // should look into disabling this warning locally rather globally.
132
+ #pragma warning(disable : 4355) // level 1 and 4
133
+
134
+ // Allow implicit coercion from an integral type to a bool.
135
+ //
136
+ // These could be avoided by making the code more explicit, but that's never
137
+ // been the style here, so there would be many false positives. It's not
138
+ // obvious if a true positive would ever help to find an actual bug.
139
+ #pragma warning(disable : 4800) // level 3
140
+
141
+ #endif // _MSC_VER
142
+
143
+ // -----------------------------------------------------------------------------
144
+ // Utility Macros
145
+ // -----------------------------------------------------------------------------
146
+
147
+ // OS_IOS
148
+ #if defined(__APPLE__)
149
+ // Currently, blaze supports iOS yet doesn't define a flag. Mac users have
150
+ // traditionally defined OS_IOS themselves via other build systems, since mac
151
+ // hasn't been supported by blaze.
152
+ // TODO(user): Remove this when all toolchains make the proper defines.
153
+ #include <TargetConditionals.h>
154
+ #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
155
+ #ifndef OS_IOS
156
+ #define OS_IOS 1
157
+ #endif
158
+ #endif // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
159
+ #endif // defined(__APPLE__)
160
+
161
+ // __GLIBC_PREREQ
162
+ #if defined __linux__
163
+ // GLIBC-related macros.
164
+ #include <features.h>
165
+
166
+ #ifndef __GLIBC_PREREQ
167
+ #define __GLIBC_PREREQ(a, b) 0 // not a GLIBC system
168
+ #endif
169
+ #endif // __linux__
170
+
171
+ // STATIC_ANALYSIS
172
+ // Klocwork static analysis tool's C/C++ complier kwcc
173
+ #if defined(__KLOCWORK__)
174
+ #define STATIC_ANALYSIS
175
+ #endif // __KLOCWORK__
176
+
177
+ // SIZEOF_MEMBER, OFFSETOF_MEMBER
178
+ #define SIZEOF_MEMBER(t, f) sizeof(reinterpret_cast<t *>(4096)->f)
179
+
180
+ #define OFFSETOF_MEMBER(t, f) \
181
+ (reinterpret_cast<char *>(&(reinterpret_cast<t *>(16)->f)) - \
182
+ reinterpret_cast<char *>(16))
183
+
184
+ // LANG_CXX11
185
+ // GXX_EXPERIMENTAL_CXX0X is defined by gcc and clang up to at least
186
+ // gcc-4.7 and clang-3.1 (2011-12-13). __cplusplus was defined to 1
187
+ // in gcc before 4.7 (Crosstool 16) and clang before 3.1, but is
188
+ // defined according to the language version in effect thereafter.
189
+ // Microsoft Visual Studio 14 (2015) sets __cplusplus==199711 despite
190
+ // reasonably good C++11 support, so we set LANG_CXX for it and
191
+ // newer versions (_MSC_VER >= 1900).
192
+ #if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L || \
193
+ (defined(_MSC_VER) && _MSC_VER >= 1900))
194
+ // DEPRECATED: Do not key off LANG_CXX11. Instead, write more accurate condition
195
+ // that checks whether the C++ feature you need is available or missing, and
196
+ // define a more specific feature macro (GOOGLE_HAVE_FEATURE_FOO). You can check
197
+ // http://en.cppreference.com/w/cpp/compiler_support for compiler support on C++
198
+ // features.
199
+ // Define this to 1 if the code is compiled in C++11 mode; leave it
200
+ // undefined otherwise. Do NOT define it to 0 -- that causes
201
+ // '#ifdef LANG_CXX11' to behave differently from '#if LANG_CXX11'.
202
+ #define LANG_CXX11 1
203
+ #endif
204
+
205
+ // This sanity check can be removed when all references to
206
+ // LANG_CXX11 is removed from the code base.
207
+ #if defined(__cplusplus) && !defined(LANG_CXX11) && !defined(SWIG)
208
+ #error "LANG_CXX11 is required."
209
+ #endif
210
+
211
+ // GOOGLE_OBSCURE_SIGNAL
212
+ #if defined(__APPLE__)
213
+ // No SIGPWR on MacOSX. SIGINFO seems suitably obscure.
214
+ #define GOOGLE_OBSCURE_SIGNAL SIGINFO
215
+ #else
216
+ /* We use SIGPWR since that seems unlikely to be used for other reasons. */
217
+ #define GOOGLE_OBSCURE_SIGNAL SIGPWR
218
+ #endif
219
+
220
+ // ABSL_FUNC_PTR_TO_CHAR_PTR
221
+ // On some platforms, a "function pointer" points to a function descriptor
222
+ // rather than directly to the function itself.
223
+ // Use ABSL_FUNC_PTR_TO_CHAR_PTR(func) to get a char-pointer to the first
224
+ // instruction of the function func.
225
+ // TODO(b/30407660): Move this macro into Abseil when symbolizer is released in
226
+ // Abseil.
227
+ #if defined(__cplusplus)
228
+ #if (defined(__powerpc__) && !(_CALL_ELF > 1)) || defined(__ia64)
229
+ // use opd section for function descriptors on these platforms, the function
230
+ // address is the first word of the descriptor
231
+ namespace absl {
232
+ enum { kPlatformUsesOPDSections = 1 };
233
+ } // namespace absl
234
+ #define ABSL_FUNC_PTR_TO_CHAR_PTR(func) (reinterpret_cast<char **>(func)[0])
235
+ #else // not PPC or IA64
236
+ namespace absl {
237
+ enum { kPlatformUsesOPDSections = 0 };
238
+ } // namespace absl
239
+ #define ABSL_FUNC_PTR_TO_CHAR_PTR(func) (reinterpret_cast<char *>(func))
240
+ #endif // PPC or IA64
241
+ #endif // __cplusplus
242
+
243
+ // -----------------------------------------------------------------------------
244
+ // Utility Functions
245
+ // -----------------------------------------------------------------------------
246
+
247
+ // sized_delete
248
+ #ifdef __cplusplus
249
+ namespace base {
250
+ // We support C++14's sized deallocation for all C++ builds,
251
+ // though for other toolchains, we fall back to using delete.
252
+ inline void sized_delete(void *ptr, size_t size) {
253
+ #ifdef GOOGLE_HAVE_SIZED_DELETE
254
+ ::operator delete(ptr, size);
255
+ #else
256
+ (void)size;
257
+ ::operator delete(ptr);
258
+ #endif // GOOGLE_HAVE_SIZED_DELETE
259
+ }
260
+
261
+ inline void sized_delete_array(void *ptr, size_t size) {
262
+ #ifdef GOOGLE_HAVE_SIZED_DELETEARRAY
263
+ ::operator delete[](ptr, size);
264
+ #else
265
+ (void) size;
266
+ ::operator delete[](ptr);
267
+ #endif
268
+ }
269
+ } // namespace base
270
+ #endif // __cplusplus
271
+
272
+ // -----------------------------------------------------------------------------
273
+ // Endianness
274
+ // -----------------------------------------------------------------------------
275
+
276
+ // IS_LITTLE_ENDIAN, IS_BIG_ENDIAN
277
+ #if defined __linux__ || defined OS_ANDROID || defined(__ANDROID__)
278
+ // TODO(user): http://b/21460321; use one of OS_ANDROID or __ANDROID__.
279
+ // _BIG_ENDIAN
280
+ #include <endian.h>
281
+
282
+ #elif defined(__APPLE__)
283
+
284
+ // BIG_ENDIAN
285
+ #include <machine/endian.h> // NOLINT(build/include)
286
+ /* Let's try and follow the Linux convention */
287
+ #define __BYTE_ORDER BYTE_ORDER
288
+ #define __LITTLE_ENDIAN LITTLE_ENDIAN
289
+ #define __BIG_ENDIAN BIG_ENDIAN
290
+
291
+ #endif
292
+
293
+ // defines __BYTE_ORDER for MSVC
294
+ #ifdef _MSC_VER
295
+ #define __BYTE_ORDER __LITTLE_ENDIAN
296
+ #define IS_LITTLE_ENDIAN
297
+ #else
298
+
299
+ // define the macros IS_LITTLE_ENDIAN or IS_BIG_ENDIAN
300
+ // using the above endian definitions from endian.h if
301
+ // endian.h was included
302
+ #ifdef __BYTE_ORDER
303
+ #if __BYTE_ORDER == __LITTLE_ENDIAN
304
+ #define IS_LITTLE_ENDIAN
305
+ #endif
306
+
307
+ #if __BYTE_ORDER == __BIG_ENDIAN
308
+ #define IS_BIG_ENDIAN
309
+ #endif
310
+
311
+ #else // __BYTE_ORDER
312
+
313
+ #if defined(__LITTLE_ENDIAN__)
314
+ #define IS_LITTLE_ENDIAN
315
+ #elif defined(__BIG_ENDIAN__)
316
+ #define IS_BIG_ENDIAN
317
+ #endif
318
+
319
+ #endif // __BYTE_ORDER
320
+ #endif // _MSC_VER
321
+
322
+ // byte swap functions (bswap_16, bswap_32, bswap_64).
323
+
324
+ // The following guarantees declaration of the byte swap functions
325
+ #ifdef _MSC_VER
326
+ #include <cstdlib> // NOLINT(build/include)
327
+ #define bswap_16(x) _byteswap_ushort(x)
328
+ #define bswap_32(x) _byteswap_ulong(x)
329
+ #define bswap_64(x) _byteswap_uint64(x)
330
+
331
+ #elif defined(__APPLE__)
332
+ // Mac OS X / Darwin features
333
+ #include <libkern/OSByteOrder.h>
334
+ #define bswap_16(x) OSSwapInt16(x)
335
+ #define bswap_32(x) OSSwapInt32(x)
336
+ #define bswap_64(x) OSSwapInt64(x)
337
+
338
+ #elif defined(__GLIBC__) || defined(__BIONIC__) || defined(__ASYLO__)
339
+ #include <byteswap.h> // IWYU pragma: export
340
+
341
+ #else
342
+
343
+ static inline uint16 bswap_16(uint16 x) {
344
+ #ifdef __cplusplus
345
+ return static_cast<uint16>(((x & 0xFF) << 8) | ((x & 0xFF00) >> 8));
346
+ #else
347
+ return (uint16)(((x & 0xFF) << 8) | ((x & 0xFF00) >> 8)); // NOLINT
348
+ #endif // __cplusplus
349
+ }
350
+ #define bswap_16(x) bswap_16(x)
351
+ static inline uint32 bswap_32(uint32 x) {
352
+ return (((x & 0xFF) << 24) |
353
+ ((x & 0xFF00) << 8) |
354
+ ((x & 0xFF0000) >> 8) |
355
+ ((x & 0xFF000000) >> 24));
356
+ }
357
+ #define bswap_32(x) bswap_32(x)
358
+ static inline uint64 bswap_64(uint64 x) {
359
+ return (((x & 0xFFULL) << 56) |
360
+ ((x & 0xFF00ULL) << 40) |
361
+ ((x & 0xFF0000ULL) << 24) |
362
+ ((x & 0xFF000000ULL) << 8) |
363
+ ((x & 0xFF00000000ULL) >> 8) |
364
+ ((x & 0xFF0000000000ULL) >> 24) |
365
+ ((x & 0xFF000000000000ULL) >> 40) |
366
+ ((x & 0xFF00000000000000ULL) >> 56));
367
+ }
368
+ #define bswap_64(x) bswap_64(x)
369
+
370
+ #endif
371
+
372
+ // -----------------------------------------------------------------------------
373
+ // Hash
374
+ // -----------------------------------------------------------------------------
375
+
376
+ #ifdef __cplusplus
377
+ #ifdef STL_MSVC // not always the same as _MSC_VER
378
+ #include "s2/third_party/absl/base/internal/port_hash.inc"
379
+ #else
380
+ struct PortableHashBase {};
381
+ #endif // STL_MSVC
382
+ #endif // __cplusplus
383
+
384
+ // -----------------------------------------------------------------------------
385
+ // Global Variables
386
+ // -----------------------------------------------------------------------------
387
+
388
+ // PATH_SEPARATOR
389
+ // Define the OS's path separator
390
+ //
391
+ // NOTE: Assuming the path separator at compile time is discouraged.
392
+ // Prefer instead to be tolerant of both possible separators whenever possible.
393
+ #ifdef __cplusplus // C won't merge duplicate const variables at link time
394
+ // Some headers provide a macro for this (GCC's system.h), remove it so that we
395
+ // can use our own.
396
+ #undef PATH_SEPARATOR
397
+ #if defined(_WIN32)
398
+ const char PATH_SEPARATOR = '\\';
399
+ #else
400
+ const char PATH_SEPARATOR = '/';
401
+ #endif // _WIN32
402
+ #endif // __cplusplus
403
+
404
+ // -----------------------------------------------------------------------------
405
+ // Type Alias
406
+ // -----------------------------------------------------------------------------
407
+
408
+ // uint, ushort, ulong
409
+ #if defined __linux__
410
+ // The uint mess:
411
+ // mysql.h sets _GNU_SOURCE which sets __USE_MISC in <features.h>
412
+ // sys/types.h typedefs uint if __USE_MISC
413
+ // mysql typedefs uint if HAVE_UINT not set
414
+ // The following typedef is carefully considered, and should not cause
415
+ // any clashes
416
+ #if !defined(__USE_MISC)
417
+ #if !defined(HAVE_UINT)
418
+ #define HAVE_UINT 1
419
+ typedef unsigned int uint;
420
+ #endif // !HAVE_UINT
421
+ #if !defined(HAVE_USHORT)
422
+ #define HAVE_USHORT 1
423
+ typedef unsigned short ushort; // NOLINT
424
+ #endif // !HAVE_USHORT
425
+ #if !defined(HAVE_ULONG)
426
+ #define HAVE_ULONG 1
427
+ typedef unsigned long ulong; // NOLINT
428
+ #endif // !HAVE_ULONG
429
+ #endif // !__USE_MISC
430
+
431
+ #endif // __linux__
432
+
433
+ #ifdef _MSC_VER /* if Visual C++ */
434
+ // VC++ doesn't understand "uint"
435
+ #ifndef HAVE_UINT
436
+ #define HAVE_UINT 1
437
+ typedef unsigned int uint;
438
+ #endif // !HAVE_UINT
439
+ #endif // _MSC_VER
440
+
441
+ #ifdef _MSC_VER
442
+ // uid_t
443
+ // MSVC doesn't have uid_t
444
+ typedef int uid_t;
445
+
446
+ // pid_t
447
+ // Defined all over the place.
448
+ typedef int pid_t;
449
+ #endif // _MSC_VER
450
+
451
+ // mode_t
452
+ #ifdef _MSC_VER
453
+ // From stat.h
454
+ typedef unsigned int mode_t;
455
+ #endif // _MSC_VER
456
+
457
+ // sig_t
458
+ #ifdef _MSC_VER
459
+ typedef void (*sig_t)(int);
460
+ #endif // _MSC_VER
461
+
462
+ // u_int16_t, int16_t
463
+ #ifdef _MSC_VER
464
+ // u_int16_t, int16_t don't exist in MSVC
465
+ typedef unsigned short u_int16_t; // NOLINT
466
+ typedef short int16_t; // NOLINT
467
+ #endif // _MSC_VER
468
+
469
+ // using std::hash
470
+ #ifdef _MSC_VER
471
+ #ifdef __cplusplus
472
+ // Define a minimal set of things typically available in the global
473
+ // namespace in Google code. ::string is handled elsewhere, and uniformly
474
+ // for all targets.
475
+ #include <functional>
476
+ using std::hash;
477
+ #endif // __cplusplus
478
+ #endif // _MSC_VER
479
+
480
+ // printf macros
481
+ // __STDC_FORMAT_MACROS must be defined before inttypes.h inclusion */
482
+ #if defined(__APPLE__)
483
+ /* From MacOSX's inttypes.h:
484
+ * "C++ implementations should define these macros only when
485
+ * __STDC_FORMAT_MACROS is defined before <inttypes.h> is included." */
486
+ #ifndef __STDC_FORMAT_MACROS
487
+ #define __STDC_FORMAT_MACROS
488
+ #endif /* __STDC_FORMAT_MACROS */
489
+ #endif /* __APPLE__ */
490
+
491
+ // printf macros for size_t, in the style of inttypes.h
492
+ #if defined(_LP64) || defined(__APPLE__)
493
+ #define __PRIS_PREFIX "z"
494
+ #else
495
+ #define __PRIS_PREFIX
496
+ #endif
497
+
498
+ // Use these macros after a % in a printf format string
499
+ // to get correct 32/64 bit behavior, like this:
500
+ // size_t size = records.size();
501
+ // printf("%" PRIuS "\n", size);
502
+ #define PRIdS __PRIS_PREFIX "d"
503
+ #define PRIxS __PRIS_PREFIX "x"
504
+ #define PRIuS __PRIS_PREFIX "u"
505
+ #define PRIXS __PRIS_PREFIX "X"
506
+ #define PRIoS __PRIS_PREFIX "o"
507
+
508
+ #define GPRIuPTHREAD "lu"
509
+ #define GPRIxPTHREAD "lx"
510
+ #if defined(__APPLE__)
511
+ #define PRINTABLE_PTHREAD(pthreadt) reinterpret_cast<uintptr_t>(pthreadt)
512
+ #else
513
+ #define PRINTABLE_PTHREAD(pthreadt) pthreadt
514
+ #endif
515
+
516
+ #ifdef PTHREADS_REDHAT_WIN32
517
+ #include <pthread.h> // NOLINT(build/include)
518
+ #include <iosfwd> // NOLINT(build/include)
519
+ // pthread_t is not a simple integer or pointer on Win32
520
+ std::ostream &operator<<(std::ostream &out, const pthread_t &thread_id);
521
+ #endif
522
+
523
+ // -----------------------------------------------------------------------------
524
+ // Predefined System/Language Macros
525
+ // -----------------------------------------------------------------------------
526
+
527
+ // EXFULL
528
+ #if defined(__APPLE__)
529
+ // Linux has this in <linux/errno.h>
530
+ #define EXFULL ENOMEM // not really that great a translation...
531
+ #endif // __APPLE__
532
+ #ifdef _MSC_VER
533
+ // This actually belongs in errno.h but there's a name conflict in errno
534
+ // on WinNT. They (and a ton more) are also found in Winsock2.h, but
535
+ // if'd out under NT. We need this subset at minimum.
536
+ #define EXFULL ENOMEM // not really that great a translation...
537
+ #endif // _MSC_VER
538
+
539
+ // MSG_NOSIGNAL
540
+ #if defined(__APPLE__)
541
+ // Doesn't exist on OSX.
542
+ #define MSG_NOSIGNAL 0
543
+ #endif // __APPLE__
544
+
545
+ // __ptr_t
546
+ #if defined(__APPLE__)
547
+ // Linux has this in <sys/cdefs.h>
548
+ #define __ptr_t void *
549
+ #endif // __APPLE__
550
+ #ifdef _MSC_VER
551
+ // From glob.h
552
+ #define __ptr_t void *
553
+ #endif
554
+
555
+ // HUGE_VALF
556
+ #ifdef _MSC_VER
557
+ #include <cmath> // for HUGE_VAL
558
+
559
+ #ifndef HUGE_VALF
560
+ #define HUGE_VALF (static_cast<float>(HUGE_VAL))
561
+ #endif
562
+ #endif // _MSC_VER
563
+
564
+ // MAP_ANONYMOUS
565
+ #if defined(__APPLE__)
566
+ // For mmap, Linux defines both MAP_ANONYMOUS and MAP_ANON and says MAP_ANON is
567
+ // deprecated. In Darwin, MAP_ANON is all there is.
568
+ #if !defined MAP_ANONYMOUS
569
+ #define MAP_ANONYMOUS MAP_ANON
570
+ #endif // !MAP_ANONYMOUS
571
+ #endif // __APPLE__
572
+
573
+ // PATH_MAX
574
+ // You say tomato, I say atotom
575
+ #ifdef _MSC_VER
576
+ #define PATH_MAX MAX_PATH
577
+ #endif
578
+
579
+ // -----------------------------------------------------------------------------
580
+ // Predefined System/Language Functions
581
+ // -----------------------------------------------------------------------------
582
+
583
+ // strtoq, strtouq, atoll
584
+ #ifdef _MSC_VER
585
+ #define strtoq _strtoi64
586
+ #define strtouq _strtoui64
587
+ #define atoll _atoi64
588
+ #endif // _MSC_VER
589
+
590
+ #ifdef _MSC_VER
591
+ // You say tomato, I say _tomato
592
+ #define strcasecmp _stricmp
593
+ #define strncasecmp _strnicmp
594
+ #define strdup _strdup
595
+ #define tempnam _tempnam
596
+ #define chdir _chdir
597
+ #define getpid _getpid
598
+ #define getcwd _getcwd
599
+ #define putenv _putenv
600
+ #define timezone _timezone
601
+ #define tzname _tzname
602
+ #endif // _MSC_VER
603
+
604
+ // random, srandom
605
+ #ifdef _MSC_VER
606
+ // You say tomato, I say toma
607
+ inline int random() { return rand(); }
608
+ inline void srandom(unsigned int seed) { srand(seed); }
609
+ #endif // _MSC_VER
610
+
611
+ // bcopy, bzero
612
+ #ifdef _MSC_VER
613
+ // You say juxtapose, I say transpose
614
+ #define bcopy(s, d, n) memcpy(d, s, n)
615
+ // Really from <string.h>
616
+ inline void bzero(void *s, int n) { memset(s, 0, n); }
617
+ #endif // _MSC_VER
618
+
619
+ // gethostbyname
620
+ #if defined(_WIN32) || defined(__APPLE__)
621
+ // gethostbyname() *is* thread-safe for Windows native threads. It is also
622
+ // safe on Mac OS X and iOS, where it uses thread-local storage, even though the
623
+ // manpages claim otherwise. For details, see
624
+ // http://lists.apple.com/archives/Darwin-dev/2006/May/msg00008.html
625
+ #else
626
+ // gethostbyname() is not thread-safe. So disallow its use. People
627
+ // should either use the HostLookup::Lookup*() methods, or gethostbyname_r()
628
+ #define gethostbyname gethostbyname_is_not_thread_safe_DO_NOT_USE
629
+ #endif
630
+
631
+ // -----------------------------------------------------------------------------
632
+ // Performance Optimization
633
+ // -----------------------------------------------------------------------------
634
+
635
+ // Alignment
636
+
637
+ // Unaligned APIs
638
+
639
+ // Portable handling of unaligned loads, stores, and copies.
640
+ // On some platforms, like ARM, the copy functions can be more efficient
641
+ // then a load and a store.
642
+ //
643
+ // It is possible to implement all of these these using constant-length memcpy
644
+ // calls, which is portable and will usually be inlined into simple loads and
645
+ // stores if the architecture supports it. However, such inlining usually
646
+ // happens in a pass that's quite late in compilation, which means the resulting
647
+ // loads and stores cannot participate in many other optimizations, leading to
648
+ // overall worse code.
649
+ // TODO(user): These APIs are forked in Abseil, see
650
+ // LLVM, we should reimplement these APIs with functions calling memcpy(), and
651
+ // maybe publish them in Abseil.
652
+
653
+ // The unaligned API is C++ only. The declarations use C++ features
654
+ // (namespaces, inline) which are absent or incompatible in C.
655
+ #if defined(__cplusplus)
656
+
657
+ #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \
658
+ defined(MEMORY_SANITIZER)
659
+ // Consider we have an unaligned load/store of 4 bytes from address 0x...05.
660
+ // AddressSanitizer will treat it as a 3-byte access to the range 05:07 and
661
+ // will miss a bug if 08 is the first unaddressable byte.
662
+ // ThreadSanitizer will also treat this as a 3-byte access to 05:07 and will
663
+ // miss a race between this access and some other accesses to 08.
664
+ // MemorySanitizer will correctly propagate the shadow on unaligned stores
665
+ // and correctly report bugs on unaligned loads, but it may not properly
666
+ // update and report the origin of the uninitialized memory.
667
+ // For all three tools, replacing an unaligned access with a tool-specific
668
+ // callback solves the problem.
669
+
670
+ // Make sure uint16_t/uint32_t/uint64_t are defined.
671
+ #include <cstdint>
672
+
673
+ extern "C" {
674
+ uint16_t __sanitizer_unaligned_load16(const void *p);
675
+ uint32_t __sanitizer_unaligned_load32(const void *p);
676
+ uint64_t __sanitizer_unaligned_load64(const void *p);
677
+ void __sanitizer_unaligned_store16(void *p, uint16_t v);
678
+ void __sanitizer_unaligned_store32(void *p, uint32_t v);
679
+ void __sanitizer_unaligned_store64(void *p, uint64_t v);
680
+ } // extern "C"
681
+
682
+ inline uint16 UNALIGNED_LOAD16(const void *p) {
683
+ return __sanitizer_unaligned_load16(p);
684
+ }
685
+
686
+ inline uint32 UNALIGNED_LOAD32(const void *p) {
687
+ return __sanitizer_unaligned_load32(p);
688
+ }
689
+
690
+ inline uint64 UNALIGNED_LOAD64(const void *p) {
691
+ return __sanitizer_unaligned_load64(p);
692
+ }
693
+
694
+ inline void UNALIGNED_STORE16(void *p, uint16 v) {
695
+ __sanitizer_unaligned_store16(p, v);
696
+ }
697
+
698
+ inline void UNALIGNED_STORE32(void *p, uint32 v) {
699
+ __sanitizer_unaligned_store32(p, v);
700
+ }
701
+
702
+ inline void UNALIGNED_STORE64(void *p, uint64 v) {
703
+ __sanitizer_unaligned_store64(p, v);
704
+ }
705
+
706
+ #elif defined(UNDEFINED_BEHAVIOR_SANITIZER)
707
+
708
+ inline uint16 UNALIGNED_LOAD16(const void *p) {
709
+ uint16 t;
710
+ memcpy(&t, p, sizeof t);
711
+ return t;
712
+ }
713
+
714
+ inline uint32 UNALIGNED_LOAD32(const void *p) {
715
+ uint32 t;
716
+ memcpy(&t, p, sizeof t);
717
+ return t;
718
+ }
719
+
720
+ inline uint64 UNALIGNED_LOAD64(const void *p) {
721
+ uint64 t;
722
+ memcpy(&t, p, sizeof t);
723
+ return t;
724
+ }
725
+
726
+ inline void UNALIGNED_STORE16(void *p, uint16 v) { memcpy(p, &v, sizeof v); }
727
+
728
+ inline void UNALIGNED_STORE32(void *p, uint32 v) { memcpy(p, &v, sizeof v); }
729
+
730
+ inline void UNALIGNED_STORE64(void *p, uint64 v) { memcpy(p, &v, sizeof v); }
731
+
732
+ #elif defined(__x86_64__) || defined(_M_X64) || defined(__i386) || \
733
+ defined(_M_IX86) || defined(__ppc__) || defined(__PPC__) || \
734
+ defined(__ppc64__) || defined(__PPC64__)
735
+
736
+ // x86 and x86-64 can perform unaligned loads/stores directly;
737
+ // modern PowerPC hardware can also do unaligned integer loads and stores;
738
+ // but note: the FPU still sends unaligned loads and stores to a trap handler!
739
+
740
+ #define UNALIGNED_LOAD16(_p) (*reinterpret_cast<const uint16 *>(_p))
741
+ #define UNALIGNED_LOAD32(_p) (*reinterpret_cast<const uint32 *>(_p))
742
+ #define UNALIGNED_LOAD64(_p) (*reinterpret_cast<const uint64 *>(_p))
743
+
744
+ #define UNALIGNED_STORE16(_p, _val) (*reinterpret_cast<uint16 *>(_p) = (_val))
745
+ #define UNALIGNED_STORE32(_p, _val) (*reinterpret_cast<uint32 *>(_p) = (_val))
746
+ #define UNALIGNED_STORE64(_p, _val) (*reinterpret_cast<uint64 *>(_p) = (_val))
747
+
748
+ #elif defined(__arm__) && !defined(__ARM_ARCH_5__) && \
749
+ !defined(__ARM_ARCH_5T__) && !defined(__ARM_ARCH_5TE__) && \
750
+ !defined(__ARM_ARCH_5TEJ__) && !defined(__ARM_ARCH_6__) && \
751
+ !defined(__ARM_ARCH_6J__) && !defined(__ARM_ARCH_6K__) && \
752
+ !defined(__ARM_ARCH_6Z__) && !defined(__ARM_ARCH_6ZK__) && \
753
+ !defined(__ARM_ARCH_6T2__)
754
+
755
+ // ARMv7 and newer support native unaligned accesses, but only of 16-bit
756
+ // and 32-bit values (not 64-bit); older versions either raise a fatal signal,
757
+ // do an unaligned read and rotate the words around a bit, or do the reads very
758
+ // slowly (trip through kernel mode). There's no simple #define that says just
759
+ // “ARMv7 or higher”, so we have to filter away all ARMv5 and ARMv6
760
+ // sub-architectures. Newer gcc (>= 4.6) set an __ARM_FEATURE_ALIGNED #define,
761
+ // so in time, maybe we can move on to that.
762
+ //
763
+ // This is a mess, but there's not much we can do about it.
764
+ //
765
+ // To further complicate matters, only LDR instructions (single reads) are
766
+ // allowed to be unaligned, not LDRD (two reads) or LDM (many reads). Unless we
767
+ // explicitly tell the compiler that these accesses can be unaligned, it can and
768
+ // will combine accesses. On armcc, the way to signal this is done by accessing
769
+ // through the type (uint32 __packed *), but GCC has no such attribute
770
+ // (it ignores __attribute__((packed)) on individual variables). However,
771
+ // we can tell it that a _struct_ is unaligned, which has the same effect,
772
+ // so we do that.
773
+
774
+ namespace base {
775
+ namespace internal {
776
+
777
+ struct Unaligned16Struct {
778
+ uint16 value;
779
+ uint8 dummy; // To make the size non-power-of-two.
780
+ } ABSL_ATTRIBUTE_PACKED;
781
+
782
+ struct Unaligned32Struct {
783
+ uint32 value;
784
+ uint8 dummy; // To make the size non-power-of-two.
785
+ } ABSL_ATTRIBUTE_PACKED;
786
+
787
+ } // namespace internal
788
+ } // namespace base
789
+
790
+ #define UNALIGNED_LOAD16(_p) \
791
+ ((reinterpret_cast<const ::base::internal::Unaligned16Struct *>(_p))->value)
792
+ #define UNALIGNED_LOAD32(_p) \
793
+ ((reinterpret_cast<const ::base::internal::Unaligned32Struct *>(_p))->value)
794
+
795
+ #define UNALIGNED_STORE16(_p, _val) \
796
+ ((reinterpret_cast< ::base::internal::Unaligned16Struct *>(_p))->value = \
797
+ (_val))
798
+ #define UNALIGNED_STORE32(_p, _val) \
799
+ ((reinterpret_cast< ::base::internal::Unaligned32Struct *>(_p))->value = \
800
+ (_val))
801
+
802
+ // TODO(user): NEON supports unaligned 64-bit loads and stores.
803
+ // See if that would be more efficient on platforms supporting it,
804
+ // at least for copies.
805
+
806
+ inline uint64 UNALIGNED_LOAD64(const void *p) {
807
+ uint64 t;
808
+ memcpy(&t, p, sizeof t);
809
+ return t;
810
+ }
811
+
812
+ inline void UNALIGNED_STORE64(void *p, uint64 v) { memcpy(p, &v, sizeof v); }
813
+
814
+ #else
815
+
816
+ #define NEED_ALIGNED_LOADS
817
+
818
+ // These functions are provided for architectures that don't support
819
+ // unaligned loads and stores.
820
+
821
+ inline uint16 UNALIGNED_LOAD16(const void *p) {
822
+ uint16 t;
823
+ memcpy(&t, p, sizeof t);
824
+ return t;
825
+ }
826
+
827
+ inline uint32 UNALIGNED_LOAD32(const void *p) {
828
+ uint32 t;
829
+ memcpy(&t, p, sizeof t);
830
+ return t;
831
+ }
832
+
833
+ inline uint64 UNALIGNED_LOAD64(const void *p) {
834
+ uint64 t;
835
+ memcpy(&t, p, sizeof t);
836
+ return t;
837
+ }
838
+
839
+ inline void UNALIGNED_STORE16(void *p, uint16 v) { memcpy(p, &v, sizeof v); }
840
+
841
+ inline void UNALIGNED_STORE32(void *p, uint32 v) { memcpy(p, &v, sizeof v); }
842
+
843
+ inline void UNALIGNED_STORE64(void *p, uint64 v) { memcpy(p, &v, sizeof v); }
844
+
845
+ #endif
846
+
847
+ // The UNALIGNED_LOADW and UNALIGNED_STOREW macros load and store values
848
+ // of type uword_t.
849
+ #ifdef _LP64
850
+ #define UNALIGNED_LOADW(_p) UNALIGNED_LOAD64(_p)
851
+ #define UNALIGNED_STOREW(_p, _val) UNALIGNED_STORE64(_p, _val)
852
+ #else
853
+ #define UNALIGNED_LOADW(_p) UNALIGNED_LOAD32(_p)
854
+ #define UNALIGNED_STOREW(_p, _val) UNALIGNED_STORE32(_p, _val)
855
+ #endif
856
+
857
+ inline void UnalignedCopy16(const void *src, void *dst) {
858
+ UNALIGNED_STORE16(dst, UNALIGNED_LOAD16(src));
859
+ }
860
+
861
+ inline void UnalignedCopy32(const void *src, void *dst) {
862
+ UNALIGNED_STORE32(dst, UNALIGNED_LOAD32(src));
863
+ }
864
+
865
+ inline void UnalignedCopy64(const void *src, void *dst) {
866
+ if (sizeof(void *) == 8) {
867
+ UNALIGNED_STORE64(dst, UNALIGNED_LOAD64(src));
868
+ } else {
869
+ const char *src_char = reinterpret_cast<const char *>(src);
870
+ char *dst_char = reinterpret_cast<char *>(dst);
871
+
872
+ UNALIGNED_STORE32(dst_char, UNALIGNED_LOAD32(src_char));
873
+ UNALIGNED_STORE32(dst_char + 4, UNALIGNED_LOAD32(src_char + 4));
874
+ }
875
+ }
876
+
877
+ #endif // defined(__cplusplus), end of unaligned API
878
+
879
+ // aligned_malloc, aligned_free
880
+ #if defined(__ANDROID__) || defined(__ASYLO__)
881
+ #include <malloc.h> // for memalign()
882
+ #endif
883
+
884
+ // __ASYLO__ platform uses newlib without an underlying OS, which provides
885
+ // memalign, but not posix_memalign.
886
+ #if defined(__cplusplus) && \
887
+ (((defined(__GNUC__) || defined(__APPLE__) || \
888
+ defined(__NVCC__)) && \
889
+ !defined(SWIG)) || \
890
+ ((__GNUC__ >= 3 || defined(__clang__)) && defined(__ANDROID__)) || \
891
+ defined(__ASYLO__))
892
+ inline void *aligned_malloc(size_t size, size_t minimum_alignment) {
893
+ #if defined(__ANDROID__) || defined(OS_ANDROID) || defined(__ASYLO__)
894
+ return memalign(minimum_alignment, size);
895
+ #else // !__ANDROID__ && !OS_ANDROID && !__ASYLO__
896
+ // posix_memalign requires that the requested alignment be at least
897
+ // sizeof(void*). In this case, fall back on malloc which should return memory
898
+ // aligned to at least the size of a pointer.
899
+ const size_t required_alignment = sizeof(void*);
900
+ if (minimum_alignment < required_alignment)
901
+ return malloc(size);
902
+ void *ptr = nullptr;
903
+ if (posix_memalign(&ptr, minimum_alignment, size) == 0)
904
+ return ptr;
905
+ return nullptr;
906
+ #endif
907
+ }
908
+
909
+ inline void aligned_free(void *aligned_memory) {
910
+ free(aligned_memory);
911
+ }
912
+
913
+ #elif defined(_MSC_VER) // MSVC
914
+
915
+ inline void *aligned_malloc(size_t size, size_t minimum_alignment) {
916
+ return _aligned_malloc(size, minimum_alignment);
917
+ }
918
+
919
+ inline void aligned_free(void *aligned_memory) {
920
+ _aligned_free(aligned_memory);
921
+ }
922
+
923
+ #endif // aligned_malloc, aligned_free
924
+
925
+ // ALIGNED_CHAR_ARRAY
926
+ //
927
+ // Provides a char array with the exact same alignment as another type. The
928
+ // first parameter must be a complete type, the second parameter is how many
929
+ // of that type to provide space for.
930
+ //
931
+ // ALIGNED_CHAR_ARRAY(struct stat, 16) storage_;
932
+ //
933
+ #if defined(__cplusplus)
934
+ #undef ALIGNED_CHAR_ARRAY
935
+ // Because MSVC and older GCCs require that the argument to their alignment
936
+ // construct to be a literal constant integer, we use a template instantiated
937
+ // at all the possible powers of two.
938
+ #ifndef SWIG
939
+ template<int alignment, int size> struct AlignType { };
940
+ template<int size> struct AlignType<0, size> { typedef char result[size]; };
941
+ #if defined(_MSC_VER)
942
+ #define BASE_PORT_H_ALIGN_ATTRIBUTE(X) __declspec(align(X))
943
+ #define BASE_PORT_H_ALIGN_OF(T) __alignof(T)
944
+ #elif defined(__GNUC__) || defined(__INTEL_COMPILER)
945
+ #define BASE_PORT_H_ALIGN_ATTRIBUTE(X) __attribute__((aligned(X)))
946
+ #define BASE_PORT_H_ALIGN_OF(T) __alignof__(T)
947
+ #endif
948
+
949
+ #if defined(BASE_PORT_H_ALIGN_ATTRIBUTE)
950
+
951
+ #define BASE_PORT_H_ALIGNTYPE_TEMPLATE(X) \
952
+ template<int size> struct AlignType<X, size> { \
953
+ typedef BASE_PORT_H_ALIGN_ATTRIBUTE(X) char result[size]; \
954
+ }
955
+
956
+ BASE_PORT_H_ALIGNTYPE_TEMPLATE(1);
957
+ BASE_PORT_H_ALIGNTYPE_TEMPLATE(2);
958
+ BASE_PORT_H_ALIGNTYPE_TEMPLATE(4);
959
+ BASE_PORT_H_ALIGNTYPE_TEMPLATE(8);
960
+ BASE_PORT_H_ALIGNTYPE_TEMPLATE(16);
961
+ BASE_PORT_H_ALIGNTYPE_TEMPLATE(32);
962
+ BASE_PORT_H_ALIGNTYPE_TEMPLATE(64);
963
+ BASE_PORT_H_ALIGNTYPE_TEMPLATE(128);
964
+ BASE_PORT_H_ALIGNTYPE_TEMPLATE(256);
965
+ BASE_PORT_H_ALIGNTYPE_TEMPLATE(512);
966
+ BASE_PORT_H_ALIGNTYPE_TEMPLATE(1024);
967
+ BASE_PORT_H_ALIGNTYPE_TEMPLATE(2048);
968
+ BASE_PORT_H_ALIGNTYPE_TEMPLATE(4096);
969
+ BASE_PORT_H_ALIGNTYPE_TEMPLATE(8192);
970
+ // Any larger and MSVC++ will complain.
971
+
972
+ #define ALIGNED_CHAR_ARRAY(T, Size) \
973
+ typename AlignType<BASE_PORT_H_ALIGN_OF(T), sizeof(T) * Size>::result
974
+
975
+ #undef BASE_PORT_H_ALIGNTYPE_TEMPLATE
976
+ #undef BASE_PORT_H_ALIGN_ATTRIBUTE
977
+
978
+ #else // defined(BASE_PORT_H_ALIGN_ATTRIBUTE)
979
+ #define ALIGNED_CHAR_ARRAY \
980
+ you_must_define_ALIGNED_CHAR_ARRAY_for_your_compiler_in_base_port_h
981
+ #endif // defined(BASE_PORT_H_ALIGN_ATTRIBUTE)
982
+
983
+ #else // !SWIG
984
+
985
+ // SWIG can't represent alignment and doesn't care about alignment on data
986
+ // members (it works fine without it).
987
+ template<typename Size>
988
+ struct AlignType { typedef char result[Size]; };
989
+ #define ALIGNED_CHAR_ARRAY(T, Size) AlignType<Size * sizeof(T)>::result
990
+
991
+ // Enough to parse with SWIG, will never be used by running code.
992
+ #define BASE_PORT_H_ALIGN_OF(Type) 16
993
+
994
+ #endif // !SWIG
995
+ #else // __cplusplus
996
+ #define ALIGNED_CHAR_ARRAY ALIGNED_CHAR_ARRAY_is_not_available_without_Cplusplus
997
+ #endif // __cplusplus
998
+
999
+ #endif // S2_BASE_PORT_H_