wuxing0105 commited on
Commit
5f4cece
·
verified ·
1 Parent(s): f499a53

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. weight/_dep/abseil-cpp/absl/log/internal/BUILD.bazel +471 -0
  2. weight/_dep/abseil-cpp/absl/log/internal/check_impl.h +150 -0
  3. weight/_dep/abseil-cpp/absl/log/internal/check_op.cc +118 -0
  4. weight/_dep/abseil-cpp/absl/log/internal/conditions.cc +83 -0
  5. weight/_dep/abseil-cpp/absl/log/internal/conditions.h +239 -0
  6. weight/_dep/abseil-cpp/absl/log/internal/config.h +45 -0
  7. weight/_dep/abseil-cpp/absl/log/internal/flags.h +59 -0
  8. weight/_dep/abseil-cpp/absl/log/internal/fnmatch.cc +73 -0
  9. weight/_dep/abseil-cpp/absl/log/internal/fnmatch.h +35 -0
  10. weight/_dep/abseil-cpp/absl/log/internal/fnmatch_benchmark.cc +29 -0
  11. weight/_dep/abseil-cpp/absl/log/internal/fnmatch_test.cc +59 -0
  12. weight/_dep/abseil-cpp/absl/log/internal/globals.cc +145 -0
  13. weight/_dep/abseil-cpp/absl/log/internal/globals.h +101 -0
  14. weight/_dep/abseil-cpp/absl/log/internal/log_format.cc +205 -0
  15. weight/_dep/abseil-cpp/absl/log/internal/log_format.h +78 -0
  16. weight/_dep/abseil-cpp/absl/log/internal/log_impl.h +282 -0
  17. weight/_dep/abseil-cpp/absl/log/internal/log_message.cc +633 -0
  18. weight/_dep/abseil-cpp/absl/log/internal/log_message.h +375 -0
  19. weight/_dep/abseil-cpp/absl/log/internal/log_sink_set.cc +296 -0
  20. weight/_dep/abseil-cpp/absl/log/internal/log_sink_set.h +54 -0
  21. weight/_dep/abseil-cpp/absl/log/internal/nullguard.cc +35 -0
  22. weight/_dep/abseil-cpp/absl/log/internal/nullguard.h +88 -0
  23. weight/_dep/abseil-cpp/absl/log/internal/nullstream.h +136 -0
  24. weight/_dep/abseil-cpp/absl/log/internal/proto.cc +220 -0
  25. weight/_dep/abseil-cpp/absl/log/internal/proto.h +288 -0
  26. weight/_dep/abseil-cpp/absl/log/internal/stderr_log_sink_test.cc +105 -0
  27. weight/_dep/abseil-cpp/absl/log/internal/strip.h +72 -0
  28. weight/_dep/abseil-cpp/absl/log/internal/structured.h +58 -0
  29. weight/_dep/abseil-cpp/absl/log/internal/test_actions.cc +75 -0
  30. weight/_dep/abseil-cpp/absl/log/internal/test_actions.h +90 -0
  31. weight/_dep/abseil-cpp/absl/log/internal/test_helpers.cc +82 -0
  32. weight/_dep/abseil-cpp/absl/log/internal/test_helpers.h +71 -0
  33. weight/_dep/abseil-cpp/absl/log/internal/test_matchers.cc +217 -0
  34. weight/_dep/abseil-cpp/absl/log/internal/test_matchers.h +94 -0
  35. weight/_dep/abseil-cpp/absl/log/internal/vlog_config.cc +340 -0
  36. weight/_dep/abseil-cpp/absl/log/internal/vlog_config.h +163 -0
  37. weight/_dep/abseil-cpp/absl/log/internal/vlog_config_benchmark.cc +187 -0
  38. weight/_dep/abseil-cpp/absl/log/internal/voidify.h +44 -0
  39. weight/_dep/abseil-cpp/absl/log/scoped_mock_log_test.cc +295 -0
  40. weight/_dep/abseil-cpp/absl/log/stripping_test.cc +502 -0
  41. weight/_dep/abseil-cpp/absl/log/vlog_is_on.h +72 -0
  42. weight/_dep/abseil-cpp/absl/memory/BUILD.bazel +60 -0
  43. weight/_dep/abseil-cpp/absl/memory/CMakeLists.txt +41 -0
  44. weight/_dep/abseil-cpp/absl/memory/memory.h +278 -0
  45. weight/_dep/abseil-cpp/absl/memory/memory_test.cc +222 -0
  46. weight/_dep/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/America/Cambridge_Bay +0 -0
  47. weight/_dep/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/America/Campo_Grande +0 -0
  48. weight/_dep/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/America/Cayman +0 -0
  49. weight/_dep/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/America/Chihuahua +0 -0
  50. weight/_dep/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/America/Cordoba +0 -0
weight/_dep/abseil-cpp/absl/log/internal/BUILD.bazel ADDED
@@ -0,0 +1,471 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # Copyright 2022 The Abseil Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # https://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ load(
18
+ "//absl:copts/configure_copts.bzl",
19
+ "ABSL_DEFAULT_COPTS",
20
+ "ABSL_DEFAULT_LINKOPTS",
21
+ "ABSL_TEST_COPTS",
22
+ )
23
+
24
+ package(
25
+ default_visibility = [
26
+ "//absl/log:__pkg__",
27
+ ],
28
+ features = [
29
+ "header_modules",
30
+ "layering_check",
31
+ "parse_headers",
32
+ ],
33
+ )
34
+
35
+ licenses(["notice"])
36
+
37
+ cc_library(
38
+ name = "check_impl",
39
+ hdrs = ["check_impl.h"],
40
+ copts = ABSL_DEFAULT_COPTS,
41
+ linkopts = ABSL_DEFAULT_LINKOPTS,
42
+ deps = [
43
+ ":check_op",
44
+ ":conditions",
45
+ ":log_message",
46
+ ":strip",
47
+ "//absl/base:core_headers",
48
+ ],
49
+ )
50
+
51
+ cc_library(
52
+ name = "check_op",
53
+ srcs = ["check_op.cc"],
54
+ hdrs = ["check_op.h"],
55
+ copts = ABSL_DEFAULT_COPTS,
56
+ linkopts = ABSL_DEFAULT_LINKOPTS,
57
+ visibility = [
58
+ "//absl/log:__pkg__",
59
+ ],
60
+ deps = [
61
+ ":nullguard",
62
+ ":nullstream",
63
+ ":strip",
64
+ "//absl/base:config",
65
+ "//absl/base:core_headers",
66
+ "//absl/strings",
67
+ ],
68
+ )
69
+
70
+ cc_library(
71
+ name = "conditions",
72
+ srcs = ["conditions.cc"],
73
+ hdrs = ["conditions.h"],
74
+ copts = ABSL_DEFAULT_COPTS,
75
+ linkopts = ABSL_DEFAULT_LINKOPTS,
76
+ deps = [
77
+ ":voidify",
78
+ "//absl/base",
79
+ "//absl/base:config",
80
+ "//absl/base:core_headers",
81
+ ],
82
+ )
83
+
84
+ cc_library(
85
+ name = "config",
86
+ hdrs = ["config.h"],
87
+ copts = ABSL_DEFAULT_COPTS,
88
+ linkopts = ABSL_DEFAULT_LINKOPTS,
89
+ visibility = [
90
+ "//absl/log:__pkg__",
91
+ ],
92
+ deps = [
93
+ "//absl/base:config",
94
+ "//absl/base:core_headers",
95
+ ],
96
+ )
97
+
98
+ cc_library(
99
+ name = "flags",
100
+ hdrs = ["flags.h"],
101
+ copts = ABSL_DEFAULT_COPTS,
102
+ linkopts = ABSL_DEFAULT_LINKOPTS,
103
+ deps = [
104
+ "//absl/flags:flag",
105
+ ],
106
+ )
107
+
108
+ cc_library(
109
+ name = "format",
110
+ srcs = ["log_format.cc"],
111
+ hdrs = ["log_format.h"],
112
+ copts = ABSL_DEFAULT_COPTS,
113
+ linkopts = ABSL_DEFAULT_LINKOPTS,
114
+ deps = [
115
+ ":append_truncated",
116
+ ":config",
117
+ ":globals",
118
+ "//absl/base:config",
119
+ "//absl/base:core_headers",
120
+ "//absl/base:log_severity",
121
+ "//absl/strings",
122
+ "//absl/strings:str_format",
123
+ "//absl/time",
124
+ "//absl/types:span",
125
+ ],
126
+ )
127
+
128
+ cc_library(
129
+ name = "globals",
130
+ srcs = ["globals.cc"],
131
+ hdrs = ["globals.h"],
132
+ copts = ABSL_DEFAULT_COPTS,
133
+ linkopts = ABSL_DEFAULT_LINKOPTS,
134
+ visibility = [
135
+ "//absl/log:__pkg__",
136
+ ],
137
+ deps = [
138
+ "//absl/base:config",
139
+ "//absl/base:core_headers",
140
+ "//absl/base:log_severity",
141
+ "//absl/base:raw_logging_internal",
142
+ "//absl/strings",
143
+ "//absl/time",
144
+ ],
145
+ )
146
+
147
+ cc_library(
148
+ name = "log_impl",
149
+ hdrs = ["log_impl.h"],
150
+ copts = ABSL_DEFAULT_COPTS,
151
+ linkopts = ABSL_DEFAULT_LINKOPTS,
152
+ deps = [
153
+ ":conditions",
154
+ ":log_message",
155
+ ":strip",
156
+ "//absl/log:absl_vlog_is_on",
157
+ ],
158
+ )
159
+
160
+ cc_library(
161
+ name = "log_message",
162
+ srcs = ["log_message.cc"],
163
+ hdrs = ["log_message.h"],
164
+ copts = ABSL_DEFAULT_COPTS,
165
+ linkopts = ABSL_DEFAULT_LINKOPTS,
166
+ visibility = [
167
+ "//absl/log:__pkg__",
168
+ ],
169
+ deps = [
170
+ ":append_truncated",
171
+ ":format",
172
+ ":globals",
173
+ ":log_sink_set",
174
+ ":nullguard",
175
+ ":proto",
176
+ "//absl/base",
177
+ "//absl/base:config",
178
+ "//absl/base:core_headers",
179
+ "//absl/base:errno_saver",
180
+ "//absl/base:log_severity",
181
+ "//absl/base:raw_logging_internal",
182
+ "//absl/base:strerror",
183
+ "//absl/container:inlined_vector",
184
+ "//absl/debugging:examine_stack",
185
+ "//absl/log:globals",
186
+ "//absl/log:log_entry",
187
+ "//absl/log:log_sink",
188
+ "//absl/log:log_sink_registry",
189
+ "//absl/memory",
190
+ "//absl/strings",
191
+ "//absl/time",
192
+ "//absl/types:span",
193
+ ],
194
+ )
195
+
196
+ cc_library(
197
+ name = "append_truncated",
198
+ hdrs = ["append_truncated.h"],
199
+ copts = ABSL_DEFAULT_COPTS,
200
+ linkopts = ABSL_DEFAULT_LINKOPTS,
201
+ deps = [
202
+ "//absl/base:config",
203
+ "//absl/strings",
204
+ "//absl/types:span",
205
+ ],
206
+ )
207
+
208
+ cc_library(
209
+ name = "log_sink_set",
210
+ srcs = ["log_sink_set.cc"],
211
+ hdrs = ["log_sink_set.h"],
212
+ copts = ABSL_DEFAULT_COPTS,
213
+ linkopts = ABSL_DEFAULT_LINKOPTS + select({
214
+ "//conditions:default": [],
215
+ "@platforms//os:android": ["-llog"],
216
+ }),
217
+ deps = [
218
+ ":config",
219
+ ":globals",
220
+ "//absl/base",
221
+ "//absl/base:config",
222
+ "//absl/base:core_headers",
223
+ "//absl/base:log_severity",
224
+ "//absl/base:no_destructor",
225
+ "//absl/base:raw_logging_internal",
226
+ "//absl/cleanup",
227
+ "//absl/log:globals",
228
+ "//absl/log:log_entry",
229
+ "//absl/log:log_sink",
230
+ "//absl/strings",
231
+ "//absl/synchronization",
232
+ "//absl/types:span",
233
+ ],
234
+ )
235
+
236
+ cc_library(
237
+ name = "nullguard",
238
+ srcs = ["nullguard.cc"],
239
+ hdrs = ["nullguard.h"],
240
+ copts = ABSL_DEFAULT_COPTS,
241
+ linkopts = ABSL_DEFAULT_LINKOPTS,
242
+ deps = [
243
+ "//absl/base:config",
244
+ "//absl/base:core_headers",
245
+ ],
246
+ )
247
+
248
+ cc_library(
249
+ name = "nullstream",
250
+ hdrs = ["nullstream.h"],
251
+ copts = ABSL_DEFAULT_COPTS,
252
+ linkopts = ABSL_DEFAULT_LINKOPTS,
253
+ deps = [
254
+ "//absl/base:config",
255
+ "//absl/base:core_headers",
256
+ "//absl/base:log_severity",
257
+ "//absl/strings",
258
+ ],
259
+ )
260
+
261
+ cc_library(
262
+ name = "strip",
263
+ hdrs = ["strip.h"],
264
+ copts = ABSL_DEFAULT_COPTS,
265
+ linkopts = ABSL_DEFAULT_LINKOPTS,
266
+ deps = [
267
+ ":log_message",
268
+ ":nullstream",
269
+ "//absl/base:log_severity",
270
+ ],
271
+ )
272
+
273
+ cc_library(
274
+ name = "structured",
275
+ hdrs = ["structured.h"],
276
+ copts = ABSL_DEFAULT_COPTS,
277
+ linkopts = ABSL_DEFAULT_LINKOPTS,
278
+ deps = [
279
+ ":log_message",
280
+ "//absl/base:config",
281
+ "//absl/strings",
282
+ ],
283
+ )
284
+
285
+ cc_library(
286
+ name = "test_actions",
287
+ testonly = True,
288
+ srcs = ["test_actions.cc"],
289
+ hdrs = ["test_actions.h"],
290
+ copts = ABSL_DEFAULT_COPTS,
291
+ linkopts = ABSL_DEFAULT_LINKOPTS,
292
+ deps = [
293
+ "//absl/base:config",
294
+ "//absl/base:core_headers",
295
+ "//absl/base:log_severity",
296
+ "//absl/log:log_entry",
297
+ "//absl/strings",
298
+ "//absl/time",
299
+ ] + select({
300
+ "//absl:msvc_compiler": [],
301
+ "//conditions:default": [
302
+ ],
303
+ }),
304
+ )
305
+
306
+ cc_library(
307
+ name = "test_helpers",
308
+ testonly = True,
309
+ srcs = ["test_helpers.cc"],
310
+ hdrs = ["test_helpers.h"],
311
+ copts = ABSL_DEFAULT_COPTS,
312
+ linkopts = ABSL_DEFAULT_LINKOPTS,
313
+ deps = [
314
+ ":globals",
315
+ "//absl/base:config",
316
+ "//absl/base:log_severity",
317
+ "//absl/log:globals",
318
+ "//absl/log:initialize",
319
+ "@com_google_googletest//:gtest",
320
+ ],
321
+ )
322
+
323
+ cc_library(
324
+ name = "test_matchers",
325
+ testonly = True,
326
+ srcs = ["test_matchers.cc"],
327
+ hdrs = ["test_matchers.h"],
328
+ copts = ABSL_DEFAULT_COPTS,
329
+ linkopts = ABSL_DEFAULT_LINKOPTS,
330
+ deps = [
331
+ ":test_helpers",
332
+ "//absl/base:config",
333
+ "//absl/base:core_headers",
334
+ "//absl/base:log_severity",
335
+ "//absl/log:log_entry",
336
+ "//absl/strings",
337
+ "//absl/time",
338
+ "@com_google_googletest//:gtest",
339
+ ] + select({
340
+ "//absl:msvc_compiler": [],
341
+ "//conditions:default": [
342
+ ],
343
+ }),
344
+ )
345
+
346
+ cc_library(
347
+ name = "voidify",
348
+ hdrs = ["voidify.h"],
349
+ copts = ABSL_DEFAULT_COPTS,
350
+ linkopts = ABSL_DEFAULT_LINKOPTS,
351
+ deps = ["//absl/base:config"],
352
+ )
353
+
354
+ cc_library(
355
+ name = "proto",
356
+ srcs = ["proto.cc"],
357
+ hdrs = ["proto.h"],
358
+ copts = ABSL_DEFAULT_COPTS,
359
+ linkopts = ABSL_DEFAULT_LINKOPTS,
360
+ deps = [
361
+ "//absl/base",
362
+ "//absl/base:config",
363
+ "//absl/base:core_headers",
364
+ "//absl/strings",
365
+ "//absl/types:span",
366
+ ],
367
+ )
368
+
369
+ cc_library(
370
+ name = "fnmatch",
371
+ srcs = ["fnmatch.cc"],
372
+ hdrs = ["fnmatch.h"],
373
+ copts = ABSL_DEFAULT_COPTS,
374
+ linkopts = ABSL_DEFAULT_LINKOPTS,
375
+ deps = [
376
+ "//absl/base:config",
377
+ "//absl/strings",
378
+ ],
379
+ )
380
+
381
+ cc_library(
382
+ name = "vlog_config",
383
+ srcs = ["vlog_config.cc"],
384
+ hdrs = ["vlog_config.h"],
385
+ copts = ABSL_DEFAULT_COPTS,
386
+ linkopts = ABSL_DEFAULT_LINKOPTS,
387
+ visibility = ["//absl/log:__subpackages__"],
388
+ deps = [
389
+ "//absl/base",
390
+ "//absl/base:config",
391
+ "//absl/base:core_headers",
392
+ "//absl/base:no_destructor",
393
+ "//absl/log/internal:fnmatch",
394
+ "//absl/memory",
395
+ "//absl/strings",
396
+ "//absl/synchronization",
397
+ "//absl/types:optional",
398
+ ],
399
+ )
400
+
401
+ cc_binary(
402
+ name = "vlog_config_benchmark",
403
+ testonly = 1,
404
+ srcs = ["vlog_config_benchmark.cc"],
405
+ copts = ABSL_TEST_COPTS,
406
+ linkopts = ABSL_DEFAULT_LINKOPTS,
407
+ tags = [
408
+ "benchmark",
409
+ ],
410
+ visibility = ["//visibility:private"],
411
+ deps = [
412
+ ":vlog_config",
413
+ "//absl/base:config",
414
+ "//absl/base:core_headers",
415
+ "//absl/container:layout",
416
+ "//absl/memory",
417
+ "//absl/random:distributions",
418
+ "//absl/strings",
419
+ "@com_github_google_benchmark//:benchmark_main",
420
+ ],
421
+ )
422
+
423
+ # Test targets
424
+ cc_test(
425
+ name = "stderr_log_sink_test",
426
+ size = "small",
427
+ srcs = ["stderr_log_sink_test.cc"],
428
+ copts = ABSL_TEST_COPTS,
429
+ linkopts = ABSL_DEFAULT_LINKOPTS,
430
+ tags = [
431
+ "no_test:os:android",
432
+ "no_test:os:ios",
433
+ "no_test_android",
434
+ "no_test_darwin_x86_64",
435
+ "no_test_ios",
436
+ "no_test_wasm",
437
+ ],
438
+ deps = [
439
+ ":test_helpers",
440
+ "//absl/base:core_headers",
441
+ "//absl/base:log_severity",
442
+ "//absl/log",
443
+ "//absl/log:globals",
444
+ "@com_google_googletest//:gtest",
445
+ "@com_google_googletest//:gtest_main",
446
+ ],
447
+ )
448
+
449
+ cc_test(
450
+ name = "fnmatch_test",
451
+ srcs = ["fnmatch_test.cc"],
452
+ copts = ABSL_TEST_COPTS,
453
+ linkopts = ABSL_DEFAULT_LINKOPTS,
454
+ deps = [
455
+ ":fnmatch",
456
+ "@com_google_googletest//:gtest",
457
+ "@com_google_googletest//:gtest_main",
458
+ ],
459
+ )
460
+
461
+ cc_test(
462
+ name = "fnmatch_benchmark",
463
+ srcs = ["fnmatch_benchmark.cc"],
464
+ copts = ABSL_TEST_COPTS,
465
+ linkopts = ABSL_DEFAULT_LINKOPTS,
466
+ tags = ["benchmark"],
467
+ deps = [
468
+ ":fnmatch",
469
+ "@com_github_google_benchmark//:benchmark_main",
470
+ ],
471
+ )
weight/_dep/abseil-cpp/absl/log/internal/check_impl.h ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ #ifndef ABSL_LOG_INTERNAL_CHECK_IMPL_H_
16
+ #define ABSL_LOG_INTERNAL_CHECK_IMPL_H_
17
+
18
+ #include "absl/base/optimization.h"
19
+ #include "absl/log/internal/check_op.h"
20
+ #include "absl/log/internal/conditions.h"
21
+ #include "absl/log/internal/log_message.h"
22
+ #include "absl/log/internal/strip.h"
23
+
24
+ // CHECK
25
+ #define ABSL_LOG_INTERNAL_CHECK_IMPL(condition, condition_text) \
26
+ ABSL_LOG_INTERNAL_CONDITION_FATAL(STATELESS, \
27
+ ABSL_PREDICT_FALSE(!(condition))) \
28
+ ABSL_LOG_INTERNAL_CHECK(condition_text).InternalStream()
29
+
30
+ #define ABSL_LOG_INTERNAL_QCHECK_IMPL(condition, condition_text) \
31
+ ABSL_LOG_INTERNAL_CONDITION_QFATAL(STATELESS, \
32
+ ABSL_PREDICT_FALSE(!(condition))) \
33
+ ABSL_LOG_INTERNAL_QCHECK(condition_text).InternalStream()
34
+
35
+ #define ABSL_LOG_INTERNAL_PCHECK_IMPL(condition, condition_text) \
36
+ ABSL_LOG_INTERNAL_CHECK_IMPL(condition, condition_text).WithPerror()
37
+
38
+ #ifndef NDEBUG
39
+ #define ABSL_LOG_INTERNAL_DCHECK_IMPL(condition, condition_text) \
40
+ ABSL_LOG_INTERNAL_CHECK_IMPL(condition, condition_text)
41
+ #else
42
+ #define ABSL_LOG_INTERNAL_DCHECK_IMPL(condition, condition_text) \
43
+ ABSL_LOG_INTERNAL_CHECK_IMPL(true || (condition), "true")
44
+ #endif
45
+
46
+ // CHECK_EQ
47
+ #define ABSL_LOG_INTERNAL_CHECK_EQ_IMPL(val1, val1_text, val2, val2_text) \
48
+ ABSL_LOG_INTERNAL_CHECK_OP(Check_EQ, ==, val1, val1_text, val2, val2_text)
49
+ #define ABSL_LOG_INTERNAL_CHECK_NE_IMPL(val1, val1_text, val2, val2_text) \
50
+ ABSL_LOG_INTERNAL_CHECK_OP(Check_NE, !=, val1, val1_text, val2, val2_text)
51
+ #define ABSL_LOG_INTERNAL_CHECK_LE_IMPL(val1, val1_text, val2, val2_text) \
52
+ ABSL_LOG_INTERNAL_CHECK_OP(Check_LE, <=, val1, val1_text, val2, val2_text)
53
+ #define ABSL_LOG_INTERNAL_CHECK_LT_IMPL(val1, val1_text, val2, val2_text) \
54
+ ABSL_LOG_INTERNAL_CHECK_OP(Check_LT, <, val1, val1_text, val2, val2_text)
55
+ #define ABSL_LOG_INTERNAL_CHECK_GE_IMPL(val1, val1_text, val2, val2_text) \
56
+ ABSL_LOG_INTERNAL_CHECK_OP(Check_GE, >=, val1, val1_text, val2, val2_text)
57
+ #define ABSL_LOG_INTERNAL_CHECK_GT_IMPL(val1, val1_text, val2, val2_text) \
58
+ ABSL_LOG_INTERNAL_CHECK_OP(Check_GT, >, val1, val1_text, val2, val2_text)
59
+ #define ABSL_LOG_INTERNAL_QCHECK_EQ_IMPL(val1, val1_text, val2, val2_text) \
60
+ ABSL_LOG_INTERNAL_QCHECK_OP(Check_EQ, ==, val1, val1_text, val2, val2_text)
61
+ #define ABSL_LOG_INTERNAL_QCHECK_NE_IMPL(val1, val1_text, val2, val2_text) \
62
+ ABSL_LOG_INTERNAL_QCHECK_OP(Check_NE, !=, val1, val1_text, val2, val2_text)
63
+ #define ABSL_LOG_INTERNAL_QCHECK_LE_IMPL(val1, val1_text, val2, val2_text) \
64
+ ABSL_LOG_INTERNAL_QCHECK_OP(Check_LE, <=, val1, val1_text, val2, val2_text)
65
+ #define ABSL_LOG_INTERNAL_QCHECK_LT_IMPL(val1, val1_text, val2, val2_text) \
66
+ ABSL_LOG_INTERNAL_QCHECK_OP(Check_LT, <, val1, val1_text, val2, val2_text)
67
+ #define ABSL_LOG_INTERNAL_QCHECK_GE_IMPL(val1, val1_text, val2, val2_text) \
68
+ ABSL_LOG_INTERNAL_QCHECK_OP(Check_GE, >=, val1, val1_text, val2, val2_text)
69
+ #define ABSL_LOG_INTERNAL_QCHECK_GT_IMPL(val1, val1_text, val2, val2_text) \
70
+ ABSL_LOG_INTERNAL_QCHECK_OP(Check_GT, >, val1, val1_text, val2, val2_text)
71
+ #ifndef NDEBUG
72
+ #define ABSL_LOG_INTERNAL_DCHECK_EQ_IMPL(val1, val1_text, val2, val2_text) \
73
+ ABSL_LOG_INTERNAL_CHECK_EQ_IMPL(val1, val1_text, val2, val2_text)
74
+ #define ABSL_LOG_INTERNAL_DCHECK_NE_IMPL(val1, val1_text, val2, val2_text) \
75
+ ABSL_LOG_INTERNAL_CHECK_NE_IMPL(val1, val1_text, val2, val2_text)
76
+ #define ABSL_LOG_INTERNAL_DCHECK_LE_IMPL(val1, val1_text, val2, val2_text) \
77
+ ABSL_LOG_INTERNAL_CHECK_LE_IMPL(val1, val1_text, val2, val2_text)
78
+ #define ABSL_LOG_INTERNAL_DCHECK_LT_IMPL(val1, val1_text, val2, val2_text) \
79
+ ABSL_LOG_INTERNAL_CHECK_LT_IMPL(val1, val1_text, val2, val2_text)
80
+ #define ABSL_LOG_INTERNAL_DCHECK_GE_IMPL(val1, val1_text, val2, val2_text) \
81
+ ABSL_LOG_INTERNAL_CHECK_GE_IMPL(val1, val1_text, val2, val2_text)
82
+ #define ABSL_LOG_INTERNAL_DCHECK_GT_IMPL(val1, val1_text, val2, val2_text) \
83
+ ABSL_LOG_INTERNAL_CHECK_GT_IMPL(val1, val1_text, val2, val2_text)
84
+ #else // ndef NDEBUG
85
+ #define ABSL_LOG_INTERNAL_DCHECK_EQ_IMPL(val1, val1_text, val2, val2_text) \
86
+ ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
87
+ #define ABSL_LOG_INTERNAL_DCHECK_NE_IMPL(val1, val1_text, val2, val2_text) \
88
+ ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
89
+ #define ABSL_LOG_INTERNAL_DCHECK_LE_IMPL(val1, val1_text, val2, val2_text) \
90
+ ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
91
+ #define ABSL_LOG_INTERNAL_DCHECK_LT_IMPL(val1, val1_text, val2, val2_text) \
92
+ ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
93
+ #define ABSL_LOG_INTERNAL_DCHECK_GE_IMPL(val1, val1_text, val2, val2_text) \
94
+ ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
95
+ #define ABSL_LOG_INTERNAL_DCHECK_GT_IMPL(val1, val1_text, val2, val2_text) \
96
+ ABSL_LOG_INTERNAL_DCHECK_NOP(val1, val2)
97
+ #endif // def NDEBUG
98
+
99
+ // CHECK_OK
100
+ #define ABSL_LOG_INTERNAL_CHECK_OK_IMPL(status, status_text) \
101
+ ABSL_LOG_INTERNAL_CHECK_OK(status, status_text)
102
+ #define ABSL_LOG_INTERNAL_QCHECK_OK_IMPL(status, status_text) \
103
+ ABSL_LOG_INTERNAL_QCHECK_OK(status, status_text)
104
+ #ifndef NDEBUG
105
+ #define ABSL_LOG_INTERNAL_DCHECK_OK_IMPL(status, status_text) \
106
+ ABSL_LOG_INTERNAL_CHECK_OK(status, status_text)
107
+ #else
108
+ #define ABSL_LOG_INTERNAL_DCHECK_OK_IMPL(status, status_text) \
109
+ ABSL_LOG_INTERNAL_DCHECK_NOP(status, nullptr)
110
+ #endif
111
+
112
+ // CHECK_STREQ
113
+ #define ABSL_LOG_INTERNAL_CHECK_STREQ_IMPL(s1, s1_text, s2, s2_text) \
114
+ ABSL_LOG_INTERNAL_CHECK_STROP(strcmp, ==, true, s1, s1_text, s2, s2_text)
115
+ #define ABSL_LOG_INTERNAL_CHECK_STRNE_IMPL(s1, s1_text, s2, s2_text) \
116
+ ABSL_LOG_INTERNAL_CHECK_STROP(strcmp, !=, false, s1, s1_text, s2, s2_text)
117
+ #define ABSL_LOG_INTERNAL_CHECK_STRCASEEQ_IMPL(s1, s1_text, s2, s2_text) \
118
+ ABSL_LOG_INTERNAL_CHECK_STROP(strcasecmp, ==, true, s1, s1_text, s2, s2_text)
119
+ #define ABSL_LOG_INTERNAL_CHECK_STRCASENE_IMPL(s1, s1_text, s2, s2_text) \
120
+ ABSL_LOG_INTERNAL_CHECK_STROP(strcasecmp, !=, false, s1, s1_text, s2, s2_text)
121
+ #define ABSL_LOG_INTERNAL_QCHECK_STREQ_IMPL(s1, s1_text, s2, s2_text) \
122
+ ABSL_LOG_INTERNAL_QCHECK_STROP(strcmp, ==, true, s1, s1_text, s2, s2_text)
123
+ #define ABSL_LOG_INTERNAL_QCHECK_STRNE_IMPL(s1, s1_text, s2, s2_text) \
124
+ ABSL_LOG_INTERNAL_QCHECK_STROP(strcmp, !=, false, s1, s1_text, s2, s2_text)
125
+ #define ABSL_LOG_INTERNAL_QCHECK_STRCASEEQ_IMPL(s1, s1_text, s2, s2_text) \
126
+ ABSL_LOG_INTERNAL_QCHECK_STROP(strcasecmp, ==, true, s1, s1_text, s2, s2_text)
127
+ #define ABSL_LOG_INTERNAL_QCHECK_STRCASENE_IMPL(s1, s1_text, s2, s2_text) \
128
+ ABSL_LOG_INTERNAL_QCHECK_STROP(strcasecmp, !=, false, s1, s1_text, s2, \
129
+ s2_text)
130
+ #ifndef NDEBUG
131
+ #define ABSL_LOG_INTERNAL_DCHECK_STREQ_IMPL(s1, s1_text, s2, s2_text) \
132
+ ABSL_LOG_INTERNAL_CHECK_STREQ_IMPL(s1, s1_text, s2, s2_text)
133
+ #define ABSL_LOG_INTERNAL_DCHECK_STRCASEEQ_IMPL(s1, s1_text, s2, s2_text) \
134
+ ABSL_LOG_INTERNAL_CHECK_STRCASEEQ_IMPL(s1, s1_text, s2, s2_text)
135
+ #define ABSL_LOG_INTERNAL_DCHECK_STRNE_IMPL(s1, s1_text, s2, s2_text) \
136
+ ABSL_LOG_INTERNAL_CHECK_STRNE_IMPL(s1, s1_text, s2, s2_text)
137
+ #define ABSL_LOG_INTERNAL_DCHECK_STRCASENE_IMPL(s1, s1_text, s2, s2_text) \
138
+ ABSL_LOG_INTERNAL_CHECK_STRCASENE_IMPL(s1, s1_text, s2, s2_text)
139
+ #else // ndef NDEBUG
140
+ #define ABSL_LOG_INTERNAL_DCHECK_STREQ_IMPL(s1, s1_text, s2, s2_text) \
141
+ ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
142
+ #define ABSL_LOG_INTERNAL_DCHECK_STRCASEEQ_IMPL(s1, s1_text, s2, s2_text) \
143
+ ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
144
+ #define ABSL_LOG_INTERNAL_DCHECK_STRNE_IMPL(s1, s1_text, s2, s2_text) \
145
+ ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
146
+ #define ABSL_LOG_INTERNAL_DCHECK_STRCASENE_IMPL(s1, s1_text, s2, s2_text) \
147
+ ABSL_LOG_INTERNAL_DCHECK_NOP(s1, s2)
148
+ #endif // def NDEBUG
149
+
150
+ #endif // ABSL_LOG_INTERNAL_CHECK_IMPL_H_
weight/_dep/abseil-cpp/absl/log/internal/check_op.cc ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ #include "absl/log/internal/check_op.h"
16
+
17
+ #include <string.h>
18
+
19
+ #ifdef _MSC_VER
20
+ #define strcasecmp _stricmp
21
+ #else
22
+ #include <strings.h> // for strcasecmp, but msvc does not have this header
23
+ #endif
24
+
25
+ #include <sstream>
26
+ #include <string>
27
+
28
+ #include "absl/base/config.h"
29
+ #include "absl/strings/str_cat.h"
30
+
31
+ namespace absl {
32
+ ABSL_NAMESPACE_BEGIN
33
+ namespace log_internal {
34
+
35
+ #define ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING(x) \
36
+ template std::string* MakeCheckOpString(x, x, const char*)
37
+ ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING(bool);
38
+ ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING(int64_t);
39
+ ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING(uint64_t);
40
+ ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING(float);
41
+ ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING(double);
42
+ ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING(char);
43
+ ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING(unsigned char);
44
+ ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING(const std::string&);
45
+ ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING(const absl::string_view&);
46
+ ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING(const char*);
47
+ ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING(const signed char*);
48
+ ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING(const unsigned char*);
49
+ ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING(const void*);
50
+ #undef ABSL_LOGGING_INTERNAL_DEFINE_MAKE_CHECK_OP_STRING
51
+
52
+ CheckOpMessageBuilder::CheckOpMessageBuilder(const char* exprtext) {
53
+ stream_ << exprtext << " (";
54
+ }
55
+
56
+ std::ostream& CheckOpMessageBuilder::ForVar2() {
57
+ stream_ << " vs. ";
58
+ return stream_;
59
+ }
60
+
61
+ std::string* CheckOpMessageBuilder::NewString() {
62
+ stream_ << ")";
63
+ return new std::string(stream_.str());
64
+ }
65
+
66
+ void MakeCheckOpValueString(std::ostream& os, const char v) {
67
+ if (v >= 32 && v <= 126) {
68
+ os << "'" << v << "'";
69
+ } else {
70
+ os << "char value " << int{v};
71
+ }
72
+ }
73
+
74
+ void MakeCheckOpValueString(std::ostream& os, const signed char v) {
75
+ if (v >= 32 && v <= 126) {
76
+ os << "'" << v << "'";
77
+ } else {
78
+ os << "signed char value " << int{v};
79
+ }
80
+ }
81
+
82
+ void MakeCheckOpValueString(std::ostream& os, const unsigned char v) {
83
+ if (v >= 32 && v <= 126) {
84
+ os << "'" << v << "'";
85
+ } else {
86
+ os << "unsigned char value " << int{v};
87
+ }
88
+ }
89
+
90
+ void MakeCheckOpValueString(std::ostream& os, const void* p) {
91
+ if (p == nullptr) {
92
+ os << "(null)";
93
+ } else {
94
+ os << p;
95
+ }
96
+ }
97
+
98
+ // Helper functions for string comparisons.
99
+ #define DEFINE_CHECK_STROP_IMPL(name, func, expected) \
100
+ std::string* Check##func##expected##Impl(const char* s1, const char* s2, \
101
+ const char* exprtext) { \
102
+ bool equal = s1 == s2 || (s1 && s2 && !func(s1, s2)); \
103
+ if (equal == expected) { \
104
+ return nullptr; \
105
+ } else { \
106
+ return new std::string( \
107
+ absl::StrCat(exprtext, " (", s1, " vs. ", s2, ")")); \
108
+ } \
109
+ }
110
+ DEFINE_CHECK_STROP_IMPL(CHECK_STREQ, strcmp, true)
111
+ DEFINE_CHECK_STROP_IMPL(CHECK_STRNE, strcmp, false)
112
+ DEFINE_CHECK_STROP_IMPL(CHECK_STRCASEEQ, strcasecmp, true)
113
+ DEFINE_CHECK_STROP_IMPL(CHECK_STRCASENE, strcasecmp, false)
114
+ #undef DEFINE_CHECK_STROP_IMPL
115
+
116
+ } // namespace log_internal
117
+ ABSL_NAMESPACE_END
118
+ } // namespace absl
weight/_dep/abseil-cpp/absl/log/internal/conditions.cc ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ #include "absl/log/internal/conditions.h"
16
+
17
+ #include <atomic>
18
+ #include <cstdint>
19
+
20
+ #include "absl/base/config.h"
21
+ #include "absl/base/internal/cycleclock.h"
22
+
23
+ namespace absl {
24
+ ABSL_NAMESPACE_BEGIN
25
+ namespace log_internal {
26
+ namespace {
27
+
28
+ // The following code behaves like AtomicStatsCounter::LossyAdd() for
29
+ // speed since it is fine to lose occasional updates.
30
+ // Returns old value of *counter.
31
+ uint32_t LossyIncrement(std::atomic<uint32_t>* counter) {
32
+ const uint32_t value = counter->load(std::memory_order_relaxed);
33
+ counter->store(value + 1, std::memory_order_relaxed);
34
+ return value;
35
+ }
36
+
37
+ } // namespace
38
+
39
+ bool LogEveryNState::ShouldLog(int n) {
40
+ return n > 0 && (LossyIncrement(&counter_) % static_cast<uint32_t>(n)) == 0;
41
+ }
42
+
43
+ bool LogFirstNState::ShouldLog(int n) {
44
+ const uint32_t counter_value = counter_.load(std::memory_order_relaxed);
45
+ if (static_cast<int64_t>(counter_value) < n) {
46
+ counter_.store(counter_value + 1, std::memory_order_relaxed);
47
+ return true;
48
+ }
49
+ return false;
50
+ }
51
+
52
+ bool LogEveryPow2State::ShouldLog() {
53
+ const uint32_t new_value = LossyIncrement(&counter_) + 1;
54
+ return (new_value & (new_value - 1)) == 0;
55
+ }
56
+
57
+ bool LogEveryNSecState::ShouldLog(double seconds) {
58
+ using absl::base_internal::CycleClock;
59
+ LossyIncrement(&counter_);
60
+ const int64_t now_cycles = CycleClock::Now();
61
+ int64_t next_cycles = next_log_time_cycles_.load(std::memory_order_relaxed);
62
+ #if defined(__myriad2__)
63
+ // myriad2 does not have 8-byte compare and exchange. Use a racy version that
64
+ // is "good enough" but will over-log in the face of concurrent logging.
65
+ if (now_cycles > next_cycles) {
66
+ next_log_time_cycles_.store(now_cycles + seconds * CycleClock::Frequency(),
67
+ std::memory_order_relaxed);
68
+ return true;
69
+ }
70
+ return false;
71
+ #else
72
+ do {
73
+ if (now_cycles <= next_cycles) return false;
74
+ } while (!next_log_time_cycles_.compare_exchange_weak(
75
+ next_cycles, now_cycles + seconds * CycleClock::Frequency(),
76
+ std::memory_order_relaxed, std::memory_order_relaxed));
77
+ return true;
78
+ #endif
79
+ }
80
+
81
+ } // namespace log_internal
82
+ ABSL_NAMESPACE_END
83
+ } // namespace absl
weight/_dep/abseil-cpp/absl/log/internal/conditions.h ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/internal/conditions.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This file contains implementation of conditional log statements, like LOG_IF
20
+ // including all the ABSL_LOG_INTERNAL_..._CONDITION_... macros and
21
+ // various condition classes like LogEveryNState.
22
+
23
+ #ifndef ABSL_LOG_INTERNAL_CONDITIONS_H_
24
+ #define ABSL_LOG_INTERNAL_CONDITIONS_H_
25
+
26
+ #if defined(_WIN32) || defined(__hexagon__)
27
+ #include <cstdlib>
28
+ #else
29
+ #include <unistd.h>
30
+ #endif
31
+ #include <stdlib.h>
32
+
33
+ #include <atomic>
34
+ #include <cstdint>
35
+
36
+ #include "absl/base/attributes.h"
37
+ #include "absl/base/config.h"
38
+ #include "absl/log/internal/voidify.h"
39
+
40
+ // `ABSL_LOG_INTERNAL_CONDITION` prefixes another macro that expands to a
41
+ // temporary `LogMessage` instantiation followed by zero or more streamed
42
+ // expressions. This definition is tricky to read correctly. It evaluates to
43
+ // either
44
+ //
45
+ // (void)0;
46
+ //
47
+ // or
48
+ //
49
+ // ::absl::log_internal::Voidify() &&
50
+ // ::absl::log_internal::LogMessage(...) << "the user's message";
51
+ //
52
+ // If the condition is evaluable at compile time, as is often the case, it
53
+ // compiles away to just one side or the other.
54
+ //
55
+ // Although this is not used anywhere a statement (e.g. `if`) could not go,
56
+ // the ternary expression does a better job avoiding spurious diagnostics
57
+ // (dangling else, missing switch case) and preserving noreturn semantics (e.g.
58
+ // on `LOG(FATAL)`) without requiring braces.
59
+ //
60
+ // The `switch` ensures that this expansion is the beginning of a statement (as
61
+ // opposed to an expression) and prevents shenanigans like
62
+ // `AFunction(LOG(INFO))` and `decltype(LOG(INFO))`. The apparently-redundant
63
+ // `default` case makes the condition more amenable to Clang dataflow analysis.
64
+ #define ABSL_LOG_INTERNAL_STATELESS_CONDITION(condition) \
65
+ switch (0) \
66
+ case 0: \
67
+ default: \
68
+ !(condition) ? (void)0 : ::absl::log_internal::Voidify()&&
69
+
70
+ // `ABSL_LOG_INTERNAL_STATEFUL_CONDITION` applies a condition like
71
+ // `ABSL_LOG_INTERNAL_STATELESS_CONDITION` but adds to that a series of variable
72
+ // declarations, including a local static object which stores the state needed
73
+ // to implement the stateful macros like `LOG_EVERY_N`.
74
+ //
75
+ // `for`-loops are used to declare scoped variables without braces (to permit
76
+ // streaming into the macro's expansion) and without the dangling-`else`
77
+ // problems/diagnostics that come with `if`.
78
+ //
79
+ // Two more variables are declared in separate `for`-loops:
80
+ //
81
+ // * `COUNTER` implements a streamable token whose value when streamed is the
82
+ // number of times execution has passed through the macro.
83
+ // * A boolean flag is used to prevent any of the `for`-loops from ever actually
84
+ // looping.
85
+ #define ABSL_LOG_INTERNAL_STATEFUL_CONDITION(condition) \
86
+ for (bool absl_log_internal_stateful_condition_do_log(condition); \
87
+ absl_log_internal_stateful_condition_do_log; \
88
+ absl_log_internal_stateful_condition_do_log = false) \
89
+ ABSL_LOG_INTERNAL_STATEFUL_CONDITION_IMPL
90
+ #define ABSL_LOG_INTERNAL_STATEFUL_CONDITION_IMPL(kind, ...) \
91
+ for (static ::absl::log_internal::Log##kind##State \
92
+ absl_log_internal_stateful_condition_state; \
93
+ absl_log_internal_stateful_condition_do_log && \
94
+ absl_log_internal_stateful_condition_state.ShouldLog(__VA_ARGS__); \
95
+ absl_log_internal_stateful_condition_do_log = false) \
96
+ for (const uint32_t COUNTER ABSL_ATTRIBUTE_UNUSED = \
97
+ absl_log_internal_stateful_condition_state.counter(); \
98
+ absl_log_internal_stateful_condition_do_log; \
99
+ absl_log_internal_stateful_condition_do_log = false)
100
+
101
+ // `ABSL_LOG_INTERNAL_CONDITION_*` serve to combine any conditions from the
102
+ // macro (e.g. `LOG_IF` or `VLOG`) with inherent conditions (e.g.
103
+ // `ABSL_MIN_LOG_LEVEL`) into a single boolean expression. We could chain
104
+ // ternary operators instead, however some versions of Clang sometimes issue
105
+ // spurious diagnostics after such expressions due to a control flow analysis
106
+ // bug.
107
+ #ifdef ABSL_MIN_LOG_LEVEL
108
+ #define ABSL_LOG_INTERNAL_CONDITION_INFO(type, condition) \
109
+ ABSL_LOG_INTERNAL_##type##_CONDITION( \
110
+ (condition) && ::absl::LogSeverity::kInfo >= \
111
+ static_cast<::absl::LogSeverity>(ABSL_MIN_LOG_LEVEL))
112
+ #define ABSL_LOG_INTERNAL_CONDITION_WARNING(type, condition) \
113
+ ABSL_LOG_INTERNAL_##type##_CONDITION( \
114
+ (condition) && ::absl::LogSeverity::kWarning >= \
115
+ static_cast<::absl::LogSeverity>(ABSL_MIN_LOG_LEVEL))
116
+ #define ABSL_LOG_INTERNAL_CONDITION_ERROR(type, condition) \
117
+ ABSL_LOG_INTERNAL_##type##_CONDITION( \
118
+ (condition) && ::absl::LogSeverity::kError >= \
119
+ static_cast<::absl::LogSeverity>(ABSL_MIN_LOG_LEVEL))
120
+ // NOTE: Use ternary operators instead of short-circuiting to mitigate
121
+ // https://bugs.llvm.org/show_bug.cgi?id=51928.
122
+ #define ABSL_LOG_INTERNAL_CONDITION_FATAL(type, condition) \
123
+ ABSL_LOG_INTERNAL_##type##_CONDITION( \
124
+ ((condition) \
125
+ ? (::absl::LogSeverity::kFatal >= \
126
+ static_cast<::absl::LogSeverity>(ABSL_MIN_LOG_LEVEL) \
127
+ ? true \
128
+ : (::absl::log_internal::AbortQuietly(), false)) \
129
+ : false))
130
+ // NOTE: Use ternary operators instead of short-circuiting to mitigate
131
+ // https://bugs.llvm.org/show_bug.cgi?id=51928.
132
+ #define ABSL_LOG_INTERNAL_CONDITION_QFATAL(type, condition) \
133
+ ABSL_LOG_INTERNAL_##type##_CONDITION( \
134
+ ((condition) \
135
+ ? (::absl::LogSeverity::kFatal >= \
136
+ static_cast<::absl::LogSeverity>(ABSL_MIN_LOG_LEVEL) \
137
+ ? true \
138
+ : (::absl::log_internal::ExitQuietly(), false)) \
139
+ : false))
140
+ #define ABSL_LOG_INTERNAL_CONDITION_DFATAL(type, condition) \
141
+ ABSL_LOG_INTERNAL_##type##_CONDITION( \
142
+ (ABSL_ASSUME(absl::kLogDebugFatal == absl::LogSeverity::kError || \
143
+ absl::kLogDebugFatal == absl::LogSeverity::kFatal), \
144
+ (condition) && \
145
+ (::absl::kLogDebugFatal >= \
146
+ static_cast<::absl::LogSeverity>(ABSL_MIN_LOG_LEVEL) || \
147
+ (::absl::kLogDebugFatal == ::absl::LogSeverity::kFatal && \
148
+ (::absl::log_internal::AbortQuietly(), false)))))
149
+
150
+ #define ABSL_LOG_INTERNAL_CONDITION_LEVEL(severity) \
151
+ for (int absl_log_internal_severity_loop = 1; \
152
+ absl_log_internal_severity_loop; absl_log_internal_severity_loop = 0) \
153
+ for (const absl::LogSeverity absl_log_internal_severity = \
154
+ ::absl::NormalizeLogSeverity(severity); \
155
+ absl_log_internal_severity_loop; absl_log_internal_severity_loop = 0) \
156
+ ABSL_LOG_INTERNAL_CONDITION_LEVEL_IMPL
157
+ #define ABSL_LOG_INTERNAL_CONDITION_LEVEL_IMPL(type, condition) \
158
+ ABSL_LOG_INTERNAL_##type##_CONDITION(( \
159
+ (condition) && \
160
+ (absl_log_internal_severity >= \
161
+ static_cast<::absl::LogSeverity>(ABSL_MIN_LOG_LEVEL) || \
162
+ (absl_log_internal_severity == ::absl::LogSeverity::kFatal && \
163
+ (::absl::log_internal::AbortQuietly(), false)))))
164
+ #else // ndef ABSL_MIN_LOG_LEVEL
165
+ #define ABSL_LOG_INTERNAL_CONDITION_INFO(type, condition) \
166
+ ABSL_LOG_INTERNAL_##type##_CONDITION(condition)
167
+ #define ABSL_LOG_INTERNAL_CONDITION_WARNING(type, condition) \
168
+ ABSL_LOG_INTERNAL_##type##_CONDITION(condition)
169
+ #define ABSL_LOG_INTERNAL_CONDITION_ERROR(type, condition) \
170
+ ABSL_LOG_INTERNAL_##type##_CONDITION(condition)
171
+ #define ABSL_LOG_INTERNAL_CONDITION_FATAL(type, condition) \
172
+ ABSL_LOG_INTERNAL_##type##_CONDITION(condition)
173
+ #define ABSL_LOG_INTERNAL_CONDITION_QFATAL(type, condition) \
174
+ ABSL_LOG_INTERNAL_##type##_CONDITION(condition)
175
+ #define ABSL_LOG_INTERNAL_CONDITION_DFATAL(type, condition) \
176
+ ABSL_LOG_INTERNAL_##type##_CONDITION(condition)
177
+ #define ABSL_LOG_INTERNAL_CONDITION_LEVEL(severity) \
178
+ for (int absl_log_internal_severity_loop = 1; \
179
+ absl_log_internal_severity_loop; absl_log_internal_severity_loop = 0) \
180
+ for (const absl::LogSeverity absl_log_internal_severity = \
181
+ ::absl::NormalizeLogSeverity(severity); \
182
+ absl_log_internal_severity_loop; absl_log_internal_severity_loop = 0) \
183
+ ABSL_LOG_INTERNAL_CONDITION_LEVEL_IMPL
184
+ #define ABSL_LOG_INTERNAL_CONDITION_LEVEL_IMPL(type, condition) \
185
+ ABSL_LOG_INTERNAL_##type##_CONDITION(condition)
186
+ #endif // ndef ABSL_MIN_LOG_LEVEL
187
+
188
+ namespace absl {
189
+ ABSL_NAMESPACE_BEGIN
190
+ namespace log_internal {
191
+
192
+ // Stateful condition class name should be "Log" + name + "State".
193
+ class LogEveryNState final {
194
+ public:
195
+ bool ShouldLog(int n);
196
+ uint32_t counter() { return counter_.load(std::memory_order_relaxed); }
197
+
198
+ private:
199
+ std::atomic<uint32_t> counter_{0};
200
+ };
201
+
202
+ class LogFirstNState final {
203
+ public:
204
+ bool ShouldLog(int n);
205
+ uint32_t counter() { return counter_.load(std::memory_order_relaxed); }
206
+
207
+ private:
208
+ std::atomic<uint32_t> counter_{0};
209
+ };
210
+
211
+ class LogEveryPow2State final {
212
+ public:
213
+ bool ShouldLog();
214
+ uint32_t counter() { return counter_.load(std::memory_order_relaxed); }
215
+
216
+ private:
217
+ std::atomic<uint32_t> counter_{0};
218
+ };
219
+
220
+ class LogEveryNSecState final {
221
+ public:
222
+ bool ShouldLog(double seconds);
223
+ uint32_t counter() { return counter_.load(std::memory_order_relaxed); }
224
+
225
+ private:
226
+ std::atomic<uint32_t> counter_{0};
227
+ // Cycle count according to CycleClock that we should next log at.
228
+ std::atomic<int64_t> next_log_time_cycles_{0};
229
+ };
230
+
231
+ // Helper routines to abort the application quietly
232
+
233
+ ABSL_ATTRIBUTE_NORETURN inline void AbortQuietly() { abort(); }
234
+ ABSL_ATTRIBUTE_NORETURN inline void ExitQuietly() { _exit(1); }
235
+ } // namespace log_internal
236
+ ABSL_NAMESPACE_END
237
+ } // namespace absl
238
+
239
+ #endif // ABSL_LOG_INTERNAL_CONDITIONS_H_
weight/_dep/abseil-cpp/absl/log/internal/config.h ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/internal/config.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+
20
+ #ifndef ABSL_LOG_INTERNAL_CONFIG_H_
21
+ #define ABSL_LOG_INTERNAL_CONFIG_H_
22
+
23
+ #include "absl/base/config.h"
24
+
25
+ #ifdef _WIN32
26
+ #include <cstdint>
27
+ #else
28
+ #include <sys/types.h>
29
+ #endif
30
+
31
+ namespace absl {
32
+ ABSL_NAMESPACE_BEGIN
33
+ namespace log_internal {
34
+
35
+ #ifdef _WIN32
36
+ using Tid = uint32_t;
37
+ #else
38
+ using Tid = pid_t;
39
+ #endif
40
+
41
+ } // namespace log_internal
42
+ ABSL_NAMESPACE_END
43
+ } // namespace absl
44
+
45
+ #endif // ABSL_LOG_INTERNAL_CONFIG_H_
weight/_dep/abseil-cpp/absl/log/internal/flags.h ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/log_flags.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This header declares set of flags which can be used to configure Abseil
20
+ // Logging library behaviour at runtime.
21
+
22
+ #ifndef ABSL_LOG_INTERNAL_FLAGS_H_
23
+ #define ABSL_LOG_INTERNAL_FLAGS_H_
24
+
25
+ #include <string>
26
+
27
+ #include "absl/flags/declare.h"
28
+
29
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
30
+ // These flags should not be used in C++ code to access logging library
31
+ // configuration knobs. Use interfaces defined in absl/log/globals.h
32
+ // instead. It is still ok to use these flags on a command line.
33
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34
+
35
+ // Log messages at this severity or above are sent to stderr in *addition* to
36
+ // `LogSink`s. Defaults to `ERROR`. See log_severity.h for numeric values of
37
+ // severity levels.
38
+ ABSL_DECLARE_FLAG(int, stderrthreshold);
39
+
40
+ // Log messages at this severity or above are logged; others are discarded.
41
+ // Defaults to `INFO`, i.e. log all severities. See log_severity.h for numeric
42
+ // values of severity levels.
43
+ ABSL_DECLARE_FLAG(int, minloglevel);
44
+
45
+ // If specified in the form file:linenum, any messages logged from a matching
46
+ // location will also include a backtrace.
47
+ ABSL_DECLARE_FLAG(std::string, log_backtrace_at);
48
+
49
+ // If true, the log prefix (severity, date, time, PID, etc.) is prepended to
50
+ // each message logged. Defaults to true.
51
+ ABSL_DECLARE_FLAG(bool, log_prefix);
52
+
53
+ // Global log verbosity level. Default is 0.
54
+ ABSL_DECLARE_FLAG(int, v);
55
+
56
+ // Per-module log verbosity level. By default is empty and is unused.
57
+ ABSL_DECLARE_FLAG(std::string, vmodule);
58
+
59
+ #endif // ABSL_LOG_INTERNAL_FLAGS_H_
weight/_dep/abseil-cpp/absl/log/internal/fnmatch.cc ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 The Abseil Authors
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
+ // https://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
+ #include "absl/log/internal/fnmatch.h"
16
+
17
+ #include <cstddef>
18
+
19
+ #include "absl/base/config.h"
20
+ #include "absl/strings/string_view.h"
21
+
22
+ namespace absl {
23
+ ABSL_NAMESPACE_BEGIN
24
+ namespace log_internal {
25
+ bool FNMatch(absl::string_view pattern, absl::string_view str) {
26
+ bool in_wildcard_match = false;
27
+ while (true) {
28
+ if (pattern.empty()) {
29
+ // `pattern` is exhausted; succeed if all of `str` was consumed matching
30
+ // it.
31
+ return in_wildcard_match || str.empty();
32
+ }
33
+ if (str.empty()) {
34
+ // `str` is exhausted; succeed if `pattern` is empty or all '*'s.
35
+ return pattern.find_first_not_of('*') == pattern.npos;
36
+ }
37
+ switch (pattern.front()) {
38
+ case '*':
39
+ pattern.remove_prefix(1);
40
+ in_wildcard_match = true;
41
+ break;
42
+ case '?':
43
+ pattern.remove_prefix(1);
44
+ str.remove_prefix(1);
45
+ break;
46
+ default:
47
+ if (in_wildcard_match) {
48
+ absl::string_view fixed_portion = pattern;
49
+ const size_t end = fixed_portion.find_first_of("*?");
50
+ if (end != fixed_portion.npos) {
51
+ fixed_portion = fixed_portion.substr(0, end);
52
+ }
53
+ const size_t match = str.find(fixed_portion);
54
+ if (match == str.npos) {
55
+ return false;
56
+ }
57
+ pattern.remove_prefix(fixed_portion.size());
58
+ str.remove_prefix(match + fixed_portion.size());
59
+ in_wildcard_match = false;
60
+ } else {
61
+ if (pattern.front() != str.front()) {
62
+ return false;
63
+ }
64
+ pattern.remove_prefix(1);
65
+ str.remove_prefix(1);
66
+ }
67
+ break;
68
+ }
69
+ }
70
+ }
71
+ } // namespace log_internal
72
+ ABSL_NAMESPACE_END
73
+ } // namespace absl
weight/_dep/abseil-cpp/absl/log/internal/fnmatch.h ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 The Abseil Authors
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
+ // https://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
+ #ifndef ABSL_LOG_INTERNAL_FNMATCH_H_
16
+ #define ABSL_LOG_INTERNAL_FNMATCH_H_
17
+
18
+ #include "absl/base/config.h"
19
+ #include "absl/strings/string_view.h"
20
+
21
+ namespace absl {
22
+ ABSL_NAMESPACE_BEGIN
23
+ namespace log_internal {
24
+ // Like POSIX `fnmatch`, but:
25
+ // * accepts `string_view`
26
+ // * does not allocate any dynamic memory
27
+ // * only supports * and ? wildcards and not bracket expressions [...]
28
+ // * wildcards may match /
29
+ // * no backslash-escaping
30
+ bool FNMatch(absl::string_view pattern, absl::string_view str);
31
+ } // namespace log_internal
32
+ ABSL_NAMESPACE_END
33
+ } // namespace absl
34
+
35
+ #endif // ABSL_LOG_INTERNAL_FNMATCH_H_
weight/_dep/abseil-cpp/absl/log/internal/fnmatch_benchmark.cc ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 The Abseil Authors
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
+ // https://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
+ #include "absl/log/internal/fnmatch.h"
16
+ #include "benchmark/benchmark.h"
17
+
18
+ namespace {
19
+ void BM_FNMatch(benchmark::State& state) {
20
+ while (state.KeepRunning()) {
21
+ bool ret =
22
+ absl::log_internal::FNMatch("*?*asdf*?*we???asdf**asdf*we",
23
+ "QWERFASVWERASDFWEDFASDasdfQWERGFWASDERREWF"
24
+ "weHOOasdf@#$%TW#ZSERasdfQW#REGTZSERERwe");
25
+ benchmark::DoNotOptimize(ret);
26
+ }
27
+ }
28
+ BENCHMARK(BM_FNMatch);
29
+ } // namespace
weight/_dep/abseil-cpp/absl/log/internal/fnmatch_test.cc ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 The Abseil Authors
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
+ // https://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
+ #include "absl/log/internal/fnmatch.h"
16
+
17
+ #include "gmock/gmock.h"
18
+ #include "gtest/gtest.h"
19
+
20
+ namespace {
21
+ using ::testing::IsFalse;
22
+ using ::testing::IsTrue;
23
+
24
+ TEST(FNMatchTest, Works) {
25
+ using absl::log_internal::FNMatch;
26
+ EXPECT_THAT(FNMatch("foo", "foo"), IsTrue());
27
+ EXPECT_THAT(FNMatch("foo", "bar"), IsFalse());
28
+ EXPECT_THAT(FNMatch("foo", "fo"), IsFalse());
29
+ EXPECT_THAT(FNMatch("foo", "foo2"), IsFalse());
30
+ EXPECT_THAT(FNMatch("bar/foo.ext", "bar/foo.ext"), IsTrue());
31
+ EXPECT_THAT(FNMatch("*ba*r/fo*o.ext*", "bar/foo.ext"), IsTrue());
32
+ EXPECT_THAT(FNMatch("bar/foo.ext", "bar/baz.ext"), IsFalse());
33
+ EXPECT_THAT(FNMatch("bar/foo.ext", "bar/foo"), IsFalse());
34
+ EXPECT_THAT(FNMatch("bar/foo.ext", "bar/foo.ext.zip"), IsFalse());
35
+ EXPECT_THAT(FNMatch("ba?/*.ext", "bar/foo.ext"), IsTrue());
36
+ EXPECT_THAT(FNMatch("ba?/*.ext", "baZ/FOO.ext"), IsTrue());
37
+ EXPECT_THAT(FNMatch("ba?/*.ext", "barr/foo.ext"), IsFalse());
38
+ EXPECT_THAT(FNMatch("ba?/*.ext", "bar/foo.ext2"), IsFalse());
39
+ EXPECT_THAT(FNMatch("ba?/*", "bar/foo.ext2"), IsTrue());
40
+ EXPECT_THAT(FNMatch("ba?/*", "bar/"), IsTrue());
41
+ EXPECT_THAT(FNMatch("ba?/?", "bar/"), IsFalse());
42
+ EXPECT_THAT(FNMatch("ba?/*", "bar"), IsFalse());
43
+ EXPECT_THAT(FNMatch("?x", "zx"), IsTrue());
44
+ EXPECT_THAT(FNMatch("*b", "aab"), IsTrue());
45
+ EXPECT_THAT(FNMatch("a*b", "aXb"), IsTrue());
46
+ EXPECT_THAT(FNMatch("", ""), IsTrue());
47
+ EXPECT_THAT(FNMatch("", "a"), IsFalse());
48
+ EXPECT_THAT(FNMatch("ab*", "ab"), IsTrue());
49
+ EXPECT_THAT(FNMatch("ab**", "ab"), IsTrue());
50
+ EXPECT_THAT(FNMatch("ab*?", "ab"), IsFalse());
51
+ EXPECT_THAT(FNMatch("*", "bbb"), IsTrue());
52
+ EXPECT_THAT(FNMatch("*", ""), IsTrue());
53
+ EXPECT_THAT(FNMatch("?", ""), IsFalse());
54
+ EXPECT_THAT(FNMatch("***", "**p"), IsTrue());
55
+ EXPECT_THAT(FNMatch("**", "*"), IsTrue());
56
+ EXPECT_THAT(FNMatch("*?", "*"), IsTrue());
57
+ }
58
+
59
+ } // namespace
weight/_dep/abseil-cpp/absl/log/internal/globals.cc ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ #include "absl/log/internal/globals.h"
16
+
17
+ #include <atomic>
18
+ #include <cstdio>
19
+
20
+ #if defined(__EMSCRIPTEN__)
21
+ #include <emscripten/console.h>
22
+ #endif
23
+
24
+ #include "absl/base/attributes.h"
25
+ #include "absl/base/config.h"
26
+ #include "absl/base/internal/raw_logging.h"
27
+ #include "absl/base/log_severity.h"
28
+ #include "absl/strings/string_view.h"
29
+ #include "absl/strings/strip.h"
30
+ #include "absl/time/time.h"
31
+
32
+ namespace absl {
33
+ ABSL_NAMESPACE_BEGIN
34
+ namespace log_internal {
35
+
36
+ namespace {
37
+ // Keeps track of whether Logging initialization is finalized.
38
+ // Log messages generated before that will go to stderr.
39
+ ABSL_CONST_INIT std::atomic<bool> logging_initialized(false);
40
+
41
+ // The TimeZone used for logging. This may only be set once.
42
+ ABSL_CONST_INIT std::atomic<absl::TimeZone*> timezone_ptr{nullptr};
43
+
44
+ // If true, the logging library will symbolize stack in fatal messages
45
+ ABSL_CONST_INIT std::atomic<bool> symbolize_stack_trace(true);
46
+
47
+ // Specifies maximum number of stack frames to report in fatal messages.
48
+ ABSL_CONST_INIT std::atomic<int> max_frames_in_stack_trace(64);
49
+
50
+ ABSL_CONST_INIT std::atomic<bool> exit_on_dfatal(true);
51
+ ABSL_CONST_INIT std::atomic<bool> suppress_sigabort_trace(false);
52
+ } // namespace
53
+
54
+ bool IsInitialized() {
55
+ return logging_initialized.load(std::memory_order_acquire);
56
+ }
57
+
58
+ void SetInitialized() {
59
+ logging_initialized.store(true, std::memory_order_release);
60
+ }
61
+
62
+ void WriteToStderr(absl::string_view message, absl::LogSeverity severity) {
63
+ if (message.empty()) return;
64
+ #if defined(__EMSCRIPTEN__)
65
+ // In WebAssembly, bypass filesystem emulation via fwrite.
66
+ // Skip a trailing newline character as emscripten_errn adds one itself.
67
+ const auto message_minus_newline = absl::StripSuffix(message, "\n");
68
+ // emscripten_errn was introduced in 3.1.41 but broken in standalone mode
69
+ // until 3.1.43.
70
+ #if ABSL_INTERNAL_EMSCRIPTEN_VERSION >= 3001043
71
+ emscripten_errn(message_minus_newline.data(), message_minus_newline.size());
72
+ #else
73
+ std::string null_terminated_message(message_minus_newline);
74
+ _emscripten_err(null_terminated_message.c_str());
75
+ #endif
76
+ #else
77
+ // Avoid using std::cerr from this module since we may get called during
78
+ // exit code, and cerr may be partially or fully destroyed by then.
79
+ std::fwrite(message.data(), message.size(), 1, stderr);
80
+ #endif
81
+
82
+ #if defined(_WIN64) || defined(_WIN32) || defined(_WIN16)
83
+ // C99 requires stderr to not be fully-buffered by default (7.19.3.7), but
84
+ // MS CRT buffers it anyway, so we must `fflush` to ensure the string hits
85
+ // the console/file before the program dies (and takes the libc buffers
86
+ // with it).
87
+ // https://docs.microsoft.com/en-us/cpp/c-runtime-library/stream-i-o
88
+ if (severity >= absl::LogSeverity::kWarning) {
89
+ std::fflush(stderr);
90
+ }
91
+ #else
92
+ // Avoid unused parameter warning in this branch.
93
+ (void)severity;
94
+ #endif
95
+ }
96
+
97
+ void SetTimeZone(absl::TimeZone tz) {
98
+ absl::TimeZone* expected = nullptr;
99
+ absl::TimeZone* new_tz = new absl::TimeZone(tz);
100
+ // timezone_ptr can only be set once, otherwise new_tz is leaked.
101
+ if (!timezone_ptr.compare_exchange_strong(expected, new_tz,
102
+ std::memory_order_release,
103
+ std::memory_order_relaxed)) {
104
+ ABSL_RAW_LOG(FATAL,
105
+ "absl::log_internal::SetTimeZone() has already been called");
106
+ }
107
+ }
108
+
109
+ const absl::TimeZone* TimeZone() {
110
+ return timezone_ptr.load(std::memory_order_acquire);
111
+ }
112
+
113
+ bool ShouldSymbolizeLogStackTrace() {
114
+ return symbolize_stack_trace.load(std::memory_order_acquire);
115
+ }
116
+
117
+ void EnableSymbolizeLogStackTrace(bool on_off) {
118
+ symbolize_stack_trace.store(on_off, std::memory_order_release);
119
+ }
120
+
121
+ int MaxFramesInLogStackTrace() {
122
+ return max_frames_in_stack_trace.load(std::memory_order_acquire);
123
+ }
124
+
125
+ void SetMaxFramesInLogStackTrace(int max_num_frames) {
126
+ max_frames_in_stack_trace.store(max_num_frames, std::memory_order_release);
127
+ }
128
+
129
+ bool ExitOnDFatal() { return exit_on_dfatal.load(std::memory_order_acquire); }
130
+
131
+ void SetExitOnDFatal(bool on_off) {
132
+ exit_on_dfatal.store(on_off, std::memory_order_release);
133
+ }
134
+
135
+ bool SuppressSigabortTrace() {
136
+ return suppress_sigabort_trace.load(std::memory_order_acquire);
137
+ }
138
+
139
+ bool SetSuppressSigabortTrace(bool on_off) {
140
+ return suppress_sigabort_trace.exchange(on_off);
141
+ }
142
+
143
+ } // namespace log_internal
144
+ ABSL_NAMESPACE_END
145
+ } // namespace absl
weight/_dep/abseil-cpp/absl/log/internal/globals.h ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/internal/globals.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This header file contains various global objects and static helper routines
20
+ // use in logging implementation.
21
+
22
+ #ifndef ABSL_LOG_INTERNAL_GLOBALS_H_
23
+ #define ABSL_LOG_INTERNAL_GLOBALS_H_
24
+
25
+ #include "absl/base/config.h"
26
+ #include "absl/base/log_severity.h"
27
+ #include "absl/strings/string_view.h"
28
+ #include "absl/time/time.h"
29
+
30
+ namespace absl {
31
+ ABSL_NAMESPACE_BEGIN
32
+ namespace log_internal {
33
+
34
+ // IsInitialized returns true if the logging library is initialized.
35
+ // This function is async-signal-safe
36
+ bool IsInitialized();
37
+
38
+ // SetLoggingInitialized is called once after logging initialization is done.
39
+ void SetInitialized();
40
+
41
+ // Unconditionally write a `message` to stderr. If `severity` exceeds kInfo
42
+ // we also flush the stderr stream.
43
+ void WriteToStderr(absl::string_view message, absl::LogSeverity severity);
44
+
45
+ // Set the TimeZone used for human-friendly times (for example, the log message
46
+ // prefix) printed by the logging library. This may only be called once.
47
+ void SetTimeZone(absl::TimeZone tz);
48
+
49
+ // Returns the TimeZone used for human-friendly times (for example, the log
50
+ // message prefix) printed by the logging library Returns nullptr prior to
51
+ // initialization.
52
+ const absl::TimeZone* TimeZone();
53
+
54
+ // Returns true if stack traces emitted by the logging library should be
55
+ // symbolized. This function is async-signal-safe.
56
+ bool ShouldSymbolizeLogStackTrace();
57
+
58
+ // Enables or disables symbolization of stack traces emitted by the
59
+ // logging library. This function is async-signal-safe.
60
+ void EnableSymbolizeLogStackTrace(bool on_off);
61
+
62
+ // Returns the maximum number of frames that appear in stack traces
63
+ // emitted by the logging library. This function is async-signal-safe.
64
+ int MaxFramesInLogStackTrace();
65
+
66
+ // Sets the maximum number of frames that appear in stack traces emitted by
67
+ // the logging library. This function is async-signal-safe.
68
+ void SetMaxFramesInLogStackTrace(int max_num_frames);
69
+
70
+ // Determines whether we exit the program for a LOG(DFATAL) message in
71
+ // debug mode. It does this by skipping the call to Fail/FailQuietly.
72
+ // This is intended for testing only.
73
+ //
74
+ // This can have some effects on LOG(FATAL) as well. Failure messages
75
+ // are always allocated (rather than sharing a buffer), the crash
76
+ // reason is not recorded, the "gwq" status message is not updated,
77
+ // and the stack trace is not recorded. The LOG(FATAL) *will* still
78
+ // exit the program. Since this function is used only in testing,
79
+ // these differences are acceptable.
80
+ //
81
+ // Additionally, LOG(LEVEL(FATAL)) is indistinguishable from LOG(DFATAL) and
82
+ // will not terminate the program if SetExitOnDFatal(false) has been called.
83
+ bool ExitOnDFatal();
84
+
85
+ // SetExitOnDFatal() sets the ExitOnDFatal() status
86
+ void SetExitOnDFatal(bool on_off);
87
+
88
+ // Determines if the logging library should suppress logging of stacktraces in
89
+ // the `SIGABRT` handler, typically because we just logged a stacktrace as part
90
+ // of `LOG(FATAL)` and are about to send ourselves a `SIGABRT` to end the
91
+ // program.
92
+ bool SuppressSigabortTrace();
93
+
94
+ // Sets the SuppressSigabortTrace() status and returns the previous state.
95
+ bool SetSuppressSigabortTrace(bool on_off);
96
+
97
+ } // namespace log_internal
98
+ ABSL_NAMESPACE_END
99
+ } // namespace absl
100
+
101
+ #endif // ABSL_LOG_INTERNAL_GLOBALS_H_
weight/_dep/abseil-cpp/absl/log/internal/log_format.cc ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //
2
+ // Copyright 2022 The Abseil Authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // https://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+
16
+ #include "absl/log/internal/log_format.h"
17
+
18
+ #include <string.h>
19
+
20
+ #ifdef _MSC_VER
21
+ #include <winsock2.h> // For timeval
22
+ #else
23
+ #include <sys/time.h>
24
+ #endif
25
+
26
+ #include <cstddef>
27
+ #include <cstdint>
28
+ #include <limits>
29
+ #include <string>
30
+ #include <type_traits>
31
+
32
+ #include "absl/base/config.h"
33
+ #include "absl/base/log_severity.h"
34
+ #include "absl/base/optimization.h"
35
+ #include "absl/log/internal/append_truncated.h"
36
+ #include "absl/log/internal/config.h"
37
+ #include "absl/log/internal/globals.h"
38
+ #include "absl/strings/numbers.h"
39
+ #include "absl/strings/str_format.h"
40
+ #include "absl/strings/string_view.h"
41
+ #include "absl/time/civil_time.h"
42
+ #include "absl/time/time.h"
43
+ #include "absl/types/span.h"
44
+
45
+ namespace absl {
46
+ ABSL_NAMESPACE_BEGIN
47
+ namespace log_internal {
48
+ namespace {
49
+
50
+ // This templated function avoids compiler warnings about tautological
51
+ // comparisons when log_internal::Tid is unsigned. It can be replaced with a
52
+ // constexpr if once the minimum C++ version Abseil supports is C++17.
53
+ template <typename T>
54
+ inline std::enable_if_t<!std::is_signed<T>::value>
55
+ PutLeadingWhitespace(T tid, char*& p) {
56
+ if (tid < 10) *p++ = ' ';
57
+ if (tid < 100) *p++ = ' ';
58
+ if (tid < 1000) *p++ = ' ';
59
+ if (tid < 10000) *p++ = ' ';
60
+ if (tid < 100000) *p++ = ' ';
61
+ if (tid < 1000000) *p++ = ' ';
62
+ }
63
+
64
+ template <typename T>
65
+ inline std::enable_if_t<std::is_signed<T>::value>
66
+ PutLeadingWhitespace(T tid, char*& p) {
67
+ if (tid >= 0 && tid < 10) *p++ = ' ';
68
+ if (tid > -10 && tid < 100) *p++ = ' ';
69
+ if (tid > -100 && tid < 1000) *p++ = ' ';
70
+ if (tid > -1000 && tid < 10000) *p++ = ' ';
71
+ if (tid > -10000 && tid < 100000) *p++ = ' ';
72
+ if (tid > -100000 && tid < 1000000) *p++ = ' ';
73
+ }
74
+
75
+ // The fields before the filename are all fixed-width except for the thread ID,
76
+ // which is of bounded width.
77
+ size_t FormatBoundedFields(absl::LogSeverity severity, absl::Time timestamp,
78
+ log_internal::Tid tid, absl::Span<char>& buf) {
79
+ constexpr size_t kBoundedFieldsMaxLen =
80
+ sizeof("SMMDD HH:MM:SS.NNNNNN ") +
81
+ (1 + std::numeric_limits<log_internal::Tid>::digits10 + 1) - sizeof("");
82
+ if (ABSL_PREDICT_FALSE(buf.size() < kBoundedFieldsMaxLen)) {
83
+ // We don't bother trying to truncate these fields if the buffer is too
84
+ // short (or almost too short) because it would require doing a lot more
85
+ // length checking (slow) and it should never happen. A 15kB buffer should
86
+ // be enough for anyone. Instead we mark `buf` full without writing
87
+ // anything.
88
+ buf.remove_suffix(buf.size());
89
+ return 0;
90
+ }
91
+
92
+ // We can't call absl::LocalTime(), localtime_r(), or anything else here that
93
+ // isn't async-signal-safe. We can only use the time zone if it has already
94
+ // been loaded.
95
+ const absl::TimeZone* tz = absl::log_internal::TimeZone();
96
+ if (ABSL_PREDICT_FALSE(tz == nullptr)) {
97
+ // If a time zone hasn't been set yet because we are logging before the
98
+ // logging library has been initialized, we fallback to a simpler, slower
99
+ // method. Just report the raw Unix time in seconds. We cram this into the
100
+ // normal time format for the benefit of parsers.
101
+ auto tv = absl::ToTimeval(timestamp);
102
+ int snprintf_result = absl::SNPrintF(
103
+ buf.data(), buf.size(), "%c0000 00:00:%02d.%06d %7d ",
104
+ absl::LogSeverityName(severity)[0], static_cast<int>(tv.tv_sec),
105
+ static_cast<int>(tv.tv_usec), static_cast<int>(tid));
106
+ if (snprintf_result >= 0) {
107
+ buf.remove_prefix(static_cast<size_t>(snprintf_result));
108
+ return static_cast<size_t>(snprintf_result);
109
+ }
110
+ return 0;
111
+ }
112
+
113
+ char* p = buf.data();
114
+ *p++ = absl::LogSeverityName(severity)[0];
115
+ const absl::TimeZone::CivilInfo ci = tz->At(timestamp);
116
+ absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(ci.cs.month()), p);
117
+ p += 2;
118
+ absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(ci.cs.day()), p);
119
+ p += 2;
120
+ *p++ = ' ';
121
+ absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(ci.cs.hour()), p);
122
+ p += 2;
123
+ *p++ = ':';
124
+ absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(ci.cs.minute()),
125
+ p);
126
+ p += 2;
127
+ *p++ = ':';
128
+ absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(ci.cs.second()),
129
+ p);
130
+ p += 2;
131
+ *p++ = '.';
132
+ const int64_t usecs = absl::ToInt64Microseconds(ci.subsecond);
133
+ absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(usecs / 10000), p);
134
+ p += 2;
135
+ absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(usecs / 100 % 100),
136
+ p);
137
+ p += 2;
138
+ absl::numbers_internal::PutTwoDigits(static_cast<uint32_t>(usecs % 100), p);
139
+ p += 2;
140
+ *p++ = ' ';
141
+ PutLeadingWhitespace(tid, p);
142
+ p = absl::numbers_internal::FastIntToBuffer(tid, p);
143
+ *p++ = ' ';
144
+ const size_t bytes_formatted = static_cast<size_t>(p - buf.data());
145
+ buf.remove_prefix(bytes_formatted);
146
+ return bytes_formatted;
147
+ }
148
+
149
+ size_t FormatLineNumber(int line, absl::Span<char>& buf) {
150
+ constexpr size_t kLineFieldMaxLen =
151
+ sizeof(":] ") + (1 + std::numeric_limits<int>::digits10 + 1) - sizeof("");
152
+ if (ABSL_PREDICT_FALSE(buf.size() < kLineFieldMaxLen)) {
153
+ // As above, we don't bother trying to truncate this if the buffer is too
154
+ // short and it should never happen.
155
+ buf.remove_suffix(buf.size());
156
+ return 0;
157
+ }
158
+ char* p = buf.data();
159
+ *p++ = ':';
160
+ p = absl::numbers_internal::FastIntToBuffer(line, p);
161
+ *p++ = ']';
162
+ *p++ = ' ';
163
+ const size_t bytes_formatted = static_cast<size_t>(p - buf.data());
164
+ buf.remove_prefix(bytes_formatted);
165
+ return bytes_formatted;
166
+ }
167
+
168
+ } // namespace
169
+
170
+ std::string FormatLogMessage(absl::LogSeverity severity,
171
+ absl::CivilSecond civil_second,
172
+ absl::Duration subsecond, log_internal::Tid tid,
173
+ absl::string_view basename, int line,
174
+ PrefixFormat format, absl::string_view message) {
175
+ return absl::StrFormat(
176
+ "%c%02d%02d %02d:%02d:%02d.%06d %7d %s:%d] %s%s",
177
+ absl::LogSeverityName(severity)[0], civil_second.month(),
178
+ civil_second.day(), civil_second.hour(), civil_second.minute(),
179
+ civil_second.second(), absl::ToInt64Microseconds(subsecond), tid,
180
+ basename, line, format == PrefixFormat::kRaw ? "RAW: " : "", message);
181
+ }
182
+
183
+ // This method is fairly hot, and the library always passes a huge `buf`, so we
184
+ // save some bounds-checking cycles by not trying to do precise truncation.
185
+ // Truncating at a field boundary is probably a better UX anyway.
186
+ //
187
+ // The prefix is written in three parts, each of which does a single
188
+ // bounds-check and truncation:
189
+ // 1. severity, timestamp, and thread ID
190
+ // 2. filename
191
+ // 3. line number and bracket
192
+ size_t FormatLogPrefix(absl::LogSeverity severity, absl::Time timestamp,
193
+ log_internal::Tid tid, absl::string_view basename,
194
+ int line, PrefixFormat format, absl::Span<char>& buf) {
195
+ auto prefix_size = FormatBoundedFields(severity, timestamp, tid, buf);
196
+ prefix_size += log_internal::AppendTruncated(basename, buf);
197
+ prefix_size += FormatLineNumber(line, buf);
198
+ if (format == PrefixFormat::kRaw)
199
+ prefix_size += log_internal::AppendTruncated("RAW: ", buf);
200
+ return prefix_size;
201
+ }
202
+
203
+ } // namespace log_internal
204
+ ABSL_NAMESPACE_END
205
+ } // namespace absl
weight/_dep/abseil-cpp/absl/log/internal/log_format.h ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/internal/log_format.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This file declares routines implementing formatting of log message and log
20
+ // prefix.
21
+
22
+ #ifndef ABSL_LOG_INTERNAL_LOG_FORMAT_H_
23
+ #define ABSL_LOG_INTERNAL_LOG_FORMAT_H_
24
+
25
+ #include <stddef.h>
26
+
27
+ #include <string>
28
+
29
+ #include "absl/base/config.h"
30
+ #include "absl/base/log_severity.h"
31
+ #include "absl/log/internal/config.h"
32
+ #include "absl/strings/string_view.h"
33
+ #include "absl/time/civil_time.h"
34
+ #include "absl/time/time.h"
35
+ #include "absl/types/span.h"
36
+
37
+ namespace absl {
38
+ ABSL_NAMESPACE_BEGIN
39
+ namespace log_internal {
40
+
41
+ enum class PrefixFormat {
42
+ kNotRaw,
43
+ kRaw,
44
+ };
45
+
46
+ // Formats log message based on provided data.
47
+ std::string FormatLogMessage(absl::LogSeverity severity,
48
+ absl::CivilSecond civil_second,
49
+ absl::Duration subsecond, log_internal::Tid tid,
50
+ absl::string_view basename, int line,
51
+ PrefixFormat format, absl::string_view message);
52
+
53
+ // Formats various entry metadata into a text string meant for use as a
54
+ // prefix on a log message string. Writes into `buf`, advances `buf` to point
55
+ // at the remainder of the buffer (i.e. past any written bytes), and returns the
56
+ // number of bytes written.
57
+ //
58
+ // In addition to calling `buf->remove_prefix()` (or the equivalent), this
59
+ // function may also do `buf->remove_suffix(buf->size())` in cases where no more
60
+ // bytes (i.e. no message data) should be written into the buffer. For example,
61
+ // if the prefix ought to be:
62
+ // I0926 09:00:00.000000 1234567 foo.cc:123]
63
+ // `buf` is too small, the function might fill the whole buffer:
64
+ // I0926 09:00:00.000000 1234
65
+ // (note the apparrently incorrect thread ID), or it might write less:
66
+ // I0926 09:00:00.000000
67
+ // In this case, it might also empty `buf` prior to returning to prevent
68
+ // message data from being written into the space where a reader would expect to
69
+ // see a thread ID.
70
+ size_t FormatLogPrefix(absl::LogSeverity severity, absl::Time timestamp,
71
+ log_internal::Tid tid, absl::string_view basename,
72
+ int line, PrefixFormat format, absl::Span<char>& buf);
73
+
74
+ } // namespace log_internal
75
+ ABSL_NAMESPACE_END
76
+ } // namespace absl
77
+
78
+ #endif // ABSL_LOG_INTERNAL_LOG_FORMAT_H_
weight/_dep/abseil-cpp/absl/log/internal/log_impl.h ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors
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
+ // https://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
+ #ifndef ABSL_LOG_INTERNAL_LOG_IMPL_H_
16
+ #define ABSL_LOG_INTERNAL_LOG_IMPL_H_
17
+
18
+ #include "absl/log/absl_vlog_is_on.h"
19
+ #include "absl/log/internal/conditions.h"
20
+ #include "absl/log/internal/log_message.h"
21
+ #include "absl/log/internal/strip.h"
22
+
23
+ // ABSL_LOG()
24
+ #define ABSL_LOG_INTERNAL_LOG_IMPL(severity) \
25
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
26
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
27
+
28
+ // ABSL_PLOG()
29
+ #define ABSL_LOG_INTERNAL_PLOG_IMPL(severity) \
30
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
31
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
32
+ .WithPerror()
33
+
34
+ // ABSL_DLOG()
35
+ #ifndef NDEBUG
36
+ #define ABSL_LOG_INTERNAL_DLOG_IMPL(severity) \
37
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, true) \
38
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
39
+ #else
40
+ #define ABSL_LOG_INTERNAL_DLOG_IMPL(severity) \
41
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, false) \
42
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
43
+ #endif
44
+
45
+ // The `switch` ensures that this expansion is the begnning of a statement (as
46
+ // opposed to an expression). The use of both `case 0` and `default` is to
47
+ // suppress a compiler warning.
48
+ #define ABSL_LOG_INTERNAL_VLOG_IMPL(verbose_level) \
49
+ switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
50
+ case 0: \
51
+ default: \
52
+ ABSL_LOG_INTERNAL_LOG_IF_IMPL( \
53
+ _INFO, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
54
+ .WithVerbosity(absl_logging_internal_verbose_level)
55
+
56
+ #ifndef NDEBUG
57
+ #define ABSL_LOG_INTERNAL_DVLOG_IMPL(verbose_level) \
58
+ switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
59
+ case 0: \
60
+ default: \
61
+ ABSL_LOG_INTERNAL_LOG_IF_IMPL( \
62
+ _INFO, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
63
+ .WithVerbosity(absl_logging_internal_verbose_level)
64
+ #else
65
+ #define ABSL_LOG_INTERNAL_DVLOG_IMPL(verbose_level) \
66
+ switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
67
+ case 0: \
68
+ default: \
69
+ ABSL_LOG_INTERNAL_LOG_IF_IMPL( \
70
+ _INFO, false && ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
71
+ .WithVerbosity(absl_logging_internal_verbose_level)
72
+ #endif
73
+
74
+ #define ABSL_LOG_INTERNAL_LOG_IF_IMPL(severity, condition) \
75
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
76
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
77
+ #define ABSL_LOG_INTERNAL_PLOG_IF_IMPL(severity, condition) \
78
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
79
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
80
+ .WithPerror()
81
+
82
+ #ifndef NDEBUG
83
+ #define ABSL_LOG_INTERNAL_DLOG_IF_IMPL(severity, condition) \
84
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, condition) \
85
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
86
+ #else
87
+ #define ABSL_LOG_INTERNAL_DLOG_IF_IMPL(severity, condition) \
88
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATELESS, false && (condition)) \
89
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
90
+ #endif
91
+
92
+ // ABSL_LOG_EVERY_N
93
+ #define ABSL_LOG_INTERNAL_LOG_EVERY_N_IMPL(severity, n) \
94
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryN, n) \
95
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
96
+
97
+ // ABSL_LOG_FIRST_N
98
+ #define ABSL_LOG_INTERNAL_LOG_FIRST_N_IMPL(severity, n) \
99
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(FirstN, n) \
100
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
101
+
102
+ // ABSL_LOG_EVERY_POW_2
103
+ #define ABSL_LOG_INTERNAL_LOG_EVERY_POW_2_IMPL(severity) \
104
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryPow2) \
105
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
106
+
107
+ // ABSL_LOG_EVERY_N_SEC
108
+ #define ABSL_LOG_INTERNAL_LOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
109
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryNSec, n_seconds) \
110
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
111
+
112
+ #define ABSL_LOG_INTERNAL_PLOG_EVERY_N_IMPL(severity, n) \
113
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryN, n) \
114
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
115
+ .WithPerror()
116
+
117
+ #define ABSL_LOG_INTERNAL_PLOG_FIRST_N_IMPL(severity, n) \
118
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(FirstN, n) \
119
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
120
+ .WithPerror()
121
+
122
+ #define ABSL_LOG_INTERNAL_PLOG_EVERY_POW_2_IMPL(severity) \
123
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryPow2) \
124
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
125
+ .WithPerror()
126
+
127
+ #define ABSL_LOG_INTERNAL_PLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
128
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, true)(EveryNSec, n_seconds) \
129
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
130
+ .WithPerror()
131
+
132
+ #ifndef NDEBUG
133
+ #define ABSL_LOG_INTERNAL_DLOG_EVERY_N_IMPL(severity, n) \
134
+ ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
135
+ (EveryN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
136
+
137
+ #define ABSL_LOG_INTERNAL_DLOG_FIRST_N_IMPL(severity, n) \
138
+ ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
139
+ (FirstN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
140
+
141
+ #define ABSL_LOG_INTERNAL_DLOG_EVERY_POW_2_IMPL(severity) \
142
+ ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
143
+ (EveryPow2) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
144
+
145
+ #define ABSL_LOG_INTERNAL_DLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
146
+ ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, true) \
147
+ (EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
148
+
149
+ #else // def NDEBUG
150
+ #define ABSL_LOG_INTERNAL_DLOG_EVERY_N_IMPL(severity, n) \
151
+ ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
152
+ (EveryN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
153
+
154
+ #define ABSL_LOG_INTERNAL_DLOG_FIRST_N_IMPL(severity, n) \
155
+ ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
156
+ (FirstN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
157
+
158
+ #define ABSL_LOG_INTERNAL_DLOG_EVERY_POW_2_IMPL(severity) \
159
+ ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
160
+ (EveryPow2) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
161
+
162
+ #define ABSL_LOG_INTERNAL_DLOG_EVERY_N_SEC_IMPL(severity, n_seconds) \
163
+ ABSL_LOG_INTERNAL_CONDITION_INFO(STATEFUL, false) \
164
+ (EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
165
+ #endif // def NDEBUG
166
+
167
+ #define ABSL_LOG_INTERNAL_VLOG_EVERY_N_IMPL(verbose_level, n) \
168
+ switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
169
+ case 0: \
170
+ default: \
171
+ ABSL_LOG_INTERNAL_CONDITION_INFO( \
172
+ STATEFUL, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
173
+ (EveryN, n) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
174
+ absl_logging_internal_verbose_level)
175
+
176
+ #define ABSL_LOG_INTERNAL_VLOG_FIRST_N_IMPL(verbose_level, n) \
177
+ switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
178
+ case 0: \
179
+ default: \
180
+ ABSL_LOG_INTERNAL_CONDITION_INFO( \
181
+ STATEFUL, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
182
+ (FirstN, n) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
183
+ absl_logging_internal_verbose_level)
184
+
185
+ #define ABSL_LOG_INTERNAL_VLOG_EVERY_POW_2_IMPL(verbose_level) \
186
+ switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
187
+ case 0: \
188
+ default: \
189
+ ABSL_LOG_INTERNAL_CONDITION_INFO( \
190
+ STATEFUL, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
191
+ (EveryPow2) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream().WithVerbosity( \
192
+ absl_logging_internal_verbose_level)
193
+
194
+ #define ABSL_LOG_INTERNAL_VLOG_EVERY_N_SEC_IMPL(verbose_level, n_seconds) \
195
+ switch (const int absl_logging_internal_verbose_level = (verbose_level)) \
196
+ case 0: \
197
+ default: \
198
+ ABSL_LOG_INTERNAL_CONDITION_INFO( \
199
+ STATEFUL, ABSL_VLOG_IS_ON(absl_logging_internal_verbose_level)) \
200
+ (EveryNSec, n_seconds) ABSL_LOGGING_INTERNAL_LOG_INFO.InternalStream() \
201
+ .WithVerbosity(absl_logging_internal_verbose_level)
202
+
203
+ #define ABSL_LOG_INTERNAL_LOG_IF_EVERY_N_IMPL(severity, condition, n) \
204
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
205
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
206
+
207
+ #define ABSL_LOG_INTERNAL_LOG_IF_FIRST_N_IMPL(severity, condition, n) \
208
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
209
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
210
+
211
+ #define ABSL_LOG_INTERNAL_LOG_IF_EVERY_POW_2_IMPL(severity, condition) \
212
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
213
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
214
+
215
+ #define ABSL_LOG_INTERNAL_LOG_IF_EVERY_N_SEC_IMPL(severity, condition, \
216
+ n_seconds) \
217
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
218
+ n_seconds) \
219
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
220
+
221
+ #define ABSL_LOG_INTERNAL_PLOG_IF_EVERY_N_IMPL(severity, condition, n) \
222
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
223
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
224
+ .WithPerror()
225
+
226
+ #define ABSL_LOG_INTERNAL_PLOG_IF_FIRST_N_IMPL(severity, condition, n) \
227
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
228
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
229
+ .WithPerror()
230
+
231
+ #define ABSL_LOG_INTERNAL_PLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
232
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
233
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
234
+ .WithPerror()
235
+
236
+ #define ABSL_LOG_INTERNAL_PLOG_IF_EVERY_N_SEC_IMPL(severity, condition, \
237
+ n_seconds) \
238
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
239
+ n_seconds) \
240
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream() \
241
+ .WithPerror()
242
+
243
+ #ifndef NDEBUG
244
+ #define ABSL_LOG_INTERNAL_DLOG_IF_EVERY_N_IMPL(severity, condition, n) \
245
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryN, n) \
246
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
247
+
248
+ #define ABSL_LOG_INTERNAL_DLOG_IF_FIRST_N_IMPL(severity, condition, n) \
249
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(FirstN, n) \
250
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
251
+
252
+ #define ABSL_LOG_INTERNAL_DLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
253
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryPow2) \
254
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
255
+
256
+ #define ABSL_LOG_INTERNAL_DLOG_IF_EVERY_N_SEC_IMPL(severity, condition, \
257
+ n_seconds) \
258
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, condition)(EveryNSec, \
259
+ n_seconds) \
260
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
261
+
262
+ #else // def NDEBUG
263
+ #define ABSL_LOG_INTERNAL_DLOG_IF_EVERY_N_IMPL(severity, condition, n) \
264
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
265
+ EveryN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
266
+
267
+ #define ABSL_LOG_INTERNAL_DLOG_IF_FIRST_N_IMPL(severity, condition, n) \
268
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
269
+ FirstN, n) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
270
+
271
+ #define ABSL_LOG_INTERNAL_DLOG_IF_EVERY_POW_2_IMPL(severity, condition) \
272
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
273
+ EveryPow2) ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
274
+
275
+ #define ABSL_LOG_INTERNAL_DLOG_IF_EVERY_N_SEC_IMPL(severity, condition, \
276
+ n_seconds) \
277
+ ABSL_LOG_INTERNAL_CONDITION##severity(STATEFUL, false && (condition))( \
278
+ EveryNSec, n_seconds) \
279
+ ABSL_LOGGING_INTERNAL_LOG##severity.InternalStream()
280
+ #endif // def NDEBUG
281
+
282
+ #endif // ABSL_LOG_INTERNAL_LOG_IMPL_H_
weight/_dep/abseil-cpp/absl/log/internal/log_message.cc ADDED
@@ -0,0 +1,633 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //
2
+ // Copyright 2022 The Abseil Authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // https://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+
16
+ #include "absl/log/internal/log_message.h"
17
+
18
+ #include <stddef.h>
19
+ #include <stdint.h>
20
+ #include <stdlib.h>
21
+ #include <string.h>
22
+
23
+ #ifndef _WIN32
24
+ #include <unistd.h>
25
+ #endif
26
+
27
+ #include <algorithm>
28
+ #include <array>
29
+ #include <atomic>
30
+ #include <memory>
31
+ #include <ostream>
32
+ #include <string>
33
+ #include <tuple>
34
+
35
+ #include "absl/base/attributes.h"
36
+ #include "absl/base/config.h"
37
+ #include "absl/base/internal/raw_logging.h"
38
+ #include "absl/base/internal/strerror.h"
39
+ #include "absl/base/internal/sysinfo.h"
40
+ #include "absl/base/log_severity.h"
41
+ #include "absl/container/inlined_vector.h"
42
+ #include "absl/debugging/internal/examine_stack.h"
43
+ #include "absl/log/globals.h"
44
+ #include "absl/log/internal/append_truncated.h"
45
+ #include "absl/log/internal/globals.h"
46
+ #include "absl/log/internal/log_format.h"
47
+ #include "absl/log/internal/log_sink_set.h"
48
+ #include "absl/log/internal/proto.h"
49
+ #include "absl/log/log_entry.h"
50
+ #include "absl/log/log_sink.h"
51
+ #include "absl/log/log_sink_registry.h"
52
+ #include "absl/memory/memory.h"
53
+ #include "absl/strings/string_view.h"
54
+ #include "absl/time/clock.h"
55
+ #include "absl/time/time.h"
56
+ #include "absl/types/span.h"
57
+
58
+ extern "C" ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(
59
+ AbslInternalOnFatalLogMessage)(const absl::LogEntry&) {
60
+ // Default - Do nothing
61
+ }
62
+
63
+ namespace absl {
64
+ ABSL_NAMESPACE_BEGIN
65
+ namespace log_internal {
66
+
67
+ namespace {
68
+ // message `logging.proto.Event`
69
+ enum EventTag : uint8_t {
70
+ kValue = 7,
71
+ };
72
+
73
+ // message `logging.proto.Value`
74
+ enum ValueTag : uint8_t {
75
+ kString = 1,
76
+ kStringLiteral = 6,
77
+ };
78
+
79
+ // Decodes a `logging.proto.Value` from `buf` and writes a string representation
80
+ // into `dst`. The string representation will be truncated if `dst` is not
81
+ // large enough to hold it. Returns false if `dst` has size zero or one (i.e.
82
+ // sufficient only for a nul-terminator) and no decoded data could be written.
83
+ // This function may or may not write a nul-terminator into `dst`, and it may or
84
+ // may not truncate the data it writes in order to do make space for that nul
85
+ // terminator. In any case, `dst` will be advanced to point at the byte where
86
+ // subsequent writes should begin.
87
+ bool PrintValue(absl::Span<char>& dst, absl::Span<const char> buf) {
88
+ if (dst.size() <= 1) return false;
89
+ ProtoField field;
90
+ while (field.DecodeFrom(&buf)) {
91
+ switch (field.tag()) {
92
+ case ValueTag::kString:
93
+ case ValueTag::kStringLiteral:
94
+ if (field.type() == WireType::kLengthDelimited)
95
+ if (log_internal::AppendTruncated(field.string_value(), dst) <
96
+ field.string_value().size())
97
+ return false;
98
+ }
99
+ }
100
+ return true;
101
+ }
102
+
103
+ absl::string_view Basename(absl::string_view filepath) {
104
+ #ifdef _WIN32
105
+ size_t path = filepath.find_last_of("/\\");
106
+ #else
107
+ size_t path = filepath.find_last_of('/');
108
+ #endif
109
+ if (path != filepath.npos) filepath.remove_prefix(path + 1);
110
+ return filepath;
111
+ }
112
+
113
+ void WriteToString(const char* data, void* str) {
114
+ reinterpret_cast<std::string*>(str)->append(data);
115
+ }
116
+ void WriteToStream(const char* data, void* os) {
117
+ auto* cast_os = static_cast<std::ostream*>(os);
118
+ *cast_os << data;
119
+ }
120
+ } // namespace
121
+
122
+ struct LogMessage::LogMessageData final {
123
+ LogMessageData(const char* file, int line, absl::LogSeverity severity,
124
+ absl::Time timestamp);
125
+ LogMessageData(const LogMessageData&) = delete;
126
+ LogMessageData& operator=(const LogMessageData&) = delete;
127
+
128
+ // `LogEntry` sent to `LogSink`s; contains metadata.
129
+ absl::LogEntry entry;
130
+
131
+ // true => this was first fatal msg
132
+ bool first_fatal;
133
+ // true => all failures should be quiet
134
+ bool fail_quietly;
135
+ // true => PLOG was requested
136
+ bool is_perror;
137
+
138
+ // Extra `LogSink`s to log to, in addition to `global_sinks`.
139
+ absl::InlinedVector<absl::LogSink*, 16> extra_sinks;
140
+ // If true, log to `extra_sinks` but not to `global_sinks` or hardcoded
141
+ // non-sink targets (e.g. stderr, log files).
142
+ bool extra_sinks_only;
143
+
144
+ std::ostream manipulated; // ostream with IO manipulators applied
145
+
146
+ // A `logging.proto.Event` proto message is built into `encoded_buf`.
147
+ std::array<char, kLogMessageBufferSize> encoded_buf;
148
+ // `encoded_remaining` is the suffix of `encoded_buf` that has not been filled
149
+ // yet. If a datum to be encoded does not fit into `encoded_remaining` and
150
+ // cannot be truncated to fit, the size of `encoded_remaining` will be zeroed
151
+ // to prevent encoding of any further data. Note that in this case its data()
152
+ // pointer will not point past the end of `encoded_buf`.
153
+ absl::Span<char> encoded_remaining;
154
+
155
+ // A formatted string message is built in `string_buf`.
156
+ std::array<char, kLogMessageBufferSize> string_buf;
157
+
158
+ void FinalizeEncodingAndFormat();
159
+ };
160
+
161
+ LogMessage::LogMessageData::LogMessageData(const char* file, int line,
162
+ absl::LogSeverity severity,
163
+ absl::Time timestamp)
164
+ : extra_sinks_only(false),
165
+ manipulated(nullptr),
166
+ // This `absl::MakeSpan` silences spurious -Wuninitialized from GCC:
167
+ encoded_remaining(absl::MakeSpan(encoded_buf)) {
168
+ // Legacy defaults for LOG's ostream:
169
+ manipulated.setf(std::ios_base::showbase | std::ios_base::boolalpha);
170
+ entry.full_filename_ = file;
171
+ entry.base_filename_ = Basename(file);
172
+ entry.line_ = line;
173
+ entry.prefix_ = absl::ShouldPrependLogPrefix();
174
+ entry.severity_ = absl::NormalizeLogSeverity(severity);
175
+ entry.verbose_level_ = absl::LogEntry::kNoVerbosityLevel;
176
+ entry.timestamp_ = timestamp;
177
+ entry.tid_ = absl::base_internal::GetCachedTID();
178
+ }
179
+
180
+ void LogMessage::LogMessageData::FinalizeEncodingAndFormat() {
181
+ // Note that `encoded_remaining` may have zero size without pointing past the
182
+ // end of `encoded_buf`, so the difference between `data()` pointers is used
183
+ // to compute the size of `encoded_data`.
184
+ absl::Span<const char> encoded_data(
185
+ encoded_buf.data(),
186
+ static_cast<size_t>(encoded_remaining.data() - encoded_buf.data()));
187
+ // `string_remaining` is the suffix of `string_buf` that has not been filled
188
+ // yet.
189
+ absl::Span<char> string_remaining(string_buf);
190
+ // We may need to write a newline and nul-terminator at the end of the decoded
191
+ // string data. Rather than worry about whether those should overwrite the
192
+ // end of the string (if the buffer is full) or be appended, we avoid writing
193
+ // into the last two bytes so we always have space to append.
194
+ string_remaining.remove_suffix(2);
195
+ entry.prefix_len_ =
196
+ entry.prefix() ? log_internal::FormatLogPrefix(
197
+ entry.log_severity(), entry.timestamp(), entry.tid(),
198
+ entry.source_basename(), entry.source_line(),
199
+ log_internal::ThreadIsLoggingToLogSink()
200
+ ? PrefixFormat::kRaw
201
+ : PrefixFormat::kNotRaw,
202
+ string_remaining)
203
+ : 0;
204
+ // Decode data from `encoded_buf` until we run out of data or we run out of
205
+ // `string_remaining`.
206
+ ProtoField field;
207
+ while (field.DecodeFrom(&encoded_data)) {
208
+ switch (field.tag()) {
209
+ case EventTag::kValue:
210
+ if (field.type() != WireType::kLengthDelimited) continue;
211
+ if (PrintValue(string_remaining, field.bytes_value())) continue;
212
+ break;
213
+ }
214
+ break;
215
+ }
216
+ auto chars_written =
217
+ static_cast<size_t>(string_remaining.data() - string_buf.data());
218
+ string_buf[chars_written++] = '\n';
219
+ string_buf[chars_written++] = '\0';
220
+ entry.text_message_with_prefix_and_newline_and_nul_ =
221
+ absl::MakeSpan(string_buf).subspan(0, chars_written);
222
+ }
223
+
224
+ LogMessage::LogMessage(const char* file, int line, absl::LogSeverity severity)
225
+ : data_(absl::make_unique<LogMessageData>(file, line, severity,
226
+ absl::Now())) {
227
+ data_->first_fatal = false;
228
+ data_->is_perror = false;
229
+ data_->fail_quietly = false;
230
+
231
+ // This logs a backtrace even if the location is subsequently changed using
232
+ // AtLocation. This quirk, and the behavior when AtLocation is called twice,
233
+ // are fixable but probably not worth fixing.
234
+ LogBacktraceIfNeeded();
235
+ }
236
+
237
+ LogMessage::LogMessage(const char* file, int line, InfoTag)
238
+ : LogMessage(file, line, absl::LogSeverity::kInfo) {}
239
+ LogMessage::LogMessage(const char* file, int line, WarningTag)
240
+ : LogMessage(file, line, absl::LogSeverity::kWarning) {}
241
+ LogMessage::LogMessage(const char* file, int line, ErrorTag)
242
+ : LogMessage(file, line, absl::LogSeverity::kError) {}
243
+
244
+ LogMessage::~LogMessage() {
245
+ #ifdef ABSL_MIN_LOG_LEVEL
246
+ if (data_->entry.log_severity() <
247
+ static_cast<absl::LogSeverity>(ABSL_MIN_LOG_LEVEL) &&
248
+ data_->entry.log_severity() < absl::LogSeverity::kFatal) {
249
+ return;
250
+ }
251
+ #endif
252
+ Flush();
253
+ }
254
+
255
+ LogMessage& LogMessage::AtLocation(absl::string_view file, int line) {
256
+ data_->entry.full_filename_ = file;
257
+ data_->entry.base_filename_ = Basename(file);
258
+ data_->entry.line_ = line;
259
+ LogBacktraceIfNeeded();
260
+ return *this;
261
+ }
262
+
263
+ LogMessage& LogMessage::NoPrefix() {
264
+ data_->entry.prefix_ = false;
265
+ return *this;
266
+ }
267
+
268
+ LogMessage& LogMessage::WithVerbosity(int verbose_level) {
269
+ if (verbose_level == absl::LogEntry::kNoVerbosityLevel) {
270
+ data_->entry.verbose_level_ = absl::LogEntry::kNoVerbosityLevel;
271
+ } else {
272
+ data_->entry.verbose_level_ = std::max(0, verbose_level);
273
+ }
274
+ return *this;
275
+ }
276
+
277
+ LogMessage& LogMessage::WithTimestamp(absl::Time timestamp) {
278
+ data_->entry.timestamp_ = timestamp;
279
+ return *this;
280
+ }
281
+
282
+ LogMessage& LogMessage::WithThreadID(absl::LogEntry::tid_t tid) {
283
+ data_->entry.tid_ = tid;
284
+ return *this;
285
+ }
286
+
287
+ LogMessage& LogMessage::WithMetadataFrom(const absl::LogEntry& entry) {
288
+ data_->entry.full_filename_ = entry.full_filename_;
289
+ data_->entry.base_filename_ = entry.base_filename_;
290
+ data_->entry.line_ = entry.line_;
291
+ data_->entry.prefix_ = entry.prefix_;
292
+ data_->entry.severity_ = entry.severity_;
293
+ data_->entry.verbose_level_ = entry.verbose_level_;
294
+ data_->entry.timestamp_ = entry.timestamp_;
295
+ data_->entry.tid_ = entry.tid_;
296
+ return *this;
297
+ }
298
+
299
+ LogMessage& LogMessage::WithPerror() {
300
+ data_->is_perror = true;
301
+ return *this;
302
+ }
303
+
304
+ LogMessage& LogMessage::ToSinkAlso(absl::LogSink* sink) {
305
+ ABSL_INTERNAL_CHECK(sink, "null LogSink*");
306
+ data_->extra_sinks.push_back(sink);
307
+ return *this;
308
+ }
309
+
310
+ LogMessage& LogMessage::ToSinkOnly(absl::LogSink* sink) {
311
+ ABSL_INTERNAL_CHECK(sink, "null LogSink*");
312
+ data_->extra_sinks.clear();
313
+ data_->extra_sinks.push_back(sink);
314
+ data_->extra_sinks_only = true;
315
+ return *this;
316
+ }
317
+
318
+ #ifdef __ELF__
319
+ extern "C" void __gcov_dump() ABSL_ATTRIBUTE_WEAK;
320
+ extern "C" void __gcov_flush() ABSL_ATTRIBUTE_WEAK;
321
+ #endif
322
+
323
+ void LogMessage::FailWithoutStackTrace() {
324
+ // Now suppress repeated trace logging:
325
+ log_internal::SetSuppressSigabortTrace(true);
326
+ #if defined _DEBUG && defined COMPILER_MSVC
327
+ // When debugging on windows, avoid the obnoxious dialog.
328
+ __debugbreak();
329
+ #endif
330
+
331
+ #ifdef __ELF__
332
+ // For b/8737634, flush coverage if we are in coverage mode.
333
+ if (&__gcov_dump != nullptr) {
334
+ __gcov_dump();
335
+ } else if (&__gcov_flush != nullptr) {
336
+ __gcov_flush();
337
+ }
338
+ #endif
339
+
340
+ abort();
341
+ }
342
+
343
+ void LogMessage::FailQuietly() {
344
+ // _exit. Calling abort() would trigger all sorts of death signal handlers
345
+ // and a detailed stack trace. Calling exit() would trigger the onexit
346
+ // handlers, including the heap-leak checker, which is guaranteed to fail in
347
+ // this case: we probably just new'ed the std::string that we logged.
348
+ // Anyway, if you're calling Fail or FailQuietly, you're trying to bail out
349
+ // of the program quickly, and it doesn't make much sense for FailQuietly to
350
+ // offer different guarantees about exit behavior than Fail does. (And as a
351
+ // consequence for QCHECK and CHECK to offer different exit behaviors)
352
+ _exit(1);
353
+ }
354
+
355
+ LogMessage& LogMessage::operator<<(const std::string& v) {
356
+ CopyToEncodedBuffer<StringType::kNotLiteral>(v);
357
+ return *this;
358
+ }
359
+
360
+ LogMessage& LogMessage::operator<<(absl::string_view v) {
361
+ CopyToEncodedBuffer<StringType::kNotLiteral>(v);
362
+ return *this;
363
+ }
364
+ LogMessage& LogMessage::operator<<(std::ostream& (*m)(std::ostream& os)) {
365
+ OstreamView view(*data_);
366
+ data_->manipulated << m;
367
+ return *this;
368
+ }
369
+ LogMessage& LogMessage::operator<<(std::ios_base& (*m)(std::ios_base& os)) {
370
+ OstreamView view(*data_);
371
+ data_->manipulated << m;
372
+ return *this;
373
+ }
374
+ template LogMessage& LogMessage::operator<<(const char& v);
375
+ template LogMessage& LogMessage::operator<<(const signed char& v);
376
+ template LogMessage& LogMessage::operator<<(const unsigned char& v);
377
+ template LogMessage& LogMessage::operator<<(const short& v); // NOLINT
378
+ template LogMessage& LogMessage::operator<<(const unsigned short& v); // NOLINT
379
+ template LogMessage& LogMessage::operator<<(const int& v);
380
+ template LogMessage& LogMessage::operator<<(const unsigned int& v);
381
+ template LogMessage& LogMessage::operator<<(const long& v); // NOLINT
382
+ template LogMessage& LogMessage::operator<<(const unsigned long& v); // NOLINT
383
+ template LogMessage& LogMessage::operator<<(const long long& v); // NOLINT
384
+ template LogMessage& LogMessage::operator<<(
385
+ const unsigned long long& v); // NOLINT
386
+ template LogMessage& LogMessage::operator<<(void* const& v);
387
+ template LogMessage& LogMessage::operator<<(const void* const& v);
388
+ template LogMessage& LogMessage::operator<<(const float& v);
389
+ template LogMessage& LogMessage::operator<<(const double& v);
390
+ template LogMessage& LogMessage::operator<<(const bool& v);
391
+
392
+ void LogMessage::Flush() {
393
+ if (data_->entry.log_severity() < absl::MinLogLevel()) return;
394
+
395
+ if (data_->is_perror) {
396
+ InternalStream() << ": " << absl::base_internal::StrError(errno_saver_())
397
+ << " [" << errno_saver_() << "]";
398
+ }
399
+
400
+ // Have we already seen a fatal message?
401
+ ABSL_CONST_INIT static std::atomic<bool> seen_fatal(false);
402
+ if (data_->entry.log_severity() == absl::LogSeverity::kFatal &&
403
+ absl::log_internal::ExitOnDFatal()) {
404
+ // Exactly one LOG(FATAL) message is responsible for aborting the process,
405
+ // even if multiple threads LOG(FATAL) concurrently.
406
+ bool expected_seen_fatal = false;
407
+ if (seen_fatal.compare_exchange_strong(expected_seen_fatal, true,
408
+ std::memory_order_relaxed)) {
409
+ data_->first_fatal = true;
410
+ }
411
+ }
412
+
413
+ data_->FinalizeEncodingAndFormat();
414
+ data_->entry.encoding_ =
415
+ absl::string_view(data_->encoded_buf.data(),
416
+ static_cast<size_t>(data_->encoded_remaining.data() -
417
+ data_->encoded_buf.data()));
418
+ SendToLog();
419
+ }
420
+
421
+ void LogMessage::SetFailQuietly() { data_->fail_quietly = true; }
422
+
423
+ LogMessage::OstreamView::OstreamView(LogMessageData& message_data)
424
+ : data_(message_data), encoded_remaining_copy_(data_.encoded_remaining) {
425
+ // This constructor sets the `streambuf` up so that streaming into an attached
426
+ // ostream encodes string data in-place. To do that, we write appropriate
427
+ // headers into the buffer using a copy of the buffer view so that we can
428
+ // decide not to keep them later if nothing is ever streamed in. We don't
429
+ // know how much data we'll get, but we can use the size of the remaining
430
+ // buffer as an upper bound and fill in the right size once we know it.
431
+ message_start_ =
432
+ EncodeMessageStart(EventTag::kValue, encoded_remaining_copy_.size(),
433
+ &encoded_remaining_copy_);
434
+ string_start_ =
435
+ EncodeMessageStart(ValueTag::kString, encoded_remaining_copy_.size(),
436
+ &encoded_remaining_copy_);
437
+ setp(encoded_remaining_copy_.data(),
438
+ encoded_remaining_copy_.data() + encoded_remaining_copy_.size());
439
+ data_.manipulated.rdbuf(this);
440
+ }
441
+
442
+ LogMessage::OstreamView::~OstreamView() {
443
+ data_.manipulated.rdbuf(nullptr);
444
+ if (!string_start_.data()) {
445
+ // The second field header didn't fit. Whether the first one did or not, we
446
+ // shouldn't commit `encoded_remaining_copy_`, and we also need to zero the
447
+ // size of `data_->encoded_remaining` so that no more data are encoded.
448
+ data_.encoded_remaining.remove_suffix(data_.encoded_remaining.size());
449
+ return;
450
+ }
451
+ const absl::Span<const char> contents(pbase(),
452
+ static_cast<size_t>(pptr() - pbase()));
453
+ if (contents.empty()) return;
454
+ encoded_remaining_copy_.remove_prefix(contents.size());
455
+ EncodeMessageLength(string_start_, &encoded_remaining_copy_);
456
+ EncodeMessageLength(message_start_, &encoded_remaining_copy_);
457
+ data_.encoded_remaining = encoded_remaining_copy_;
458
+ }
459
+
460
+ std::ostream& LogMessage::OstreamView::stream() { return data_.manipulated; }
461
+
462
+ bool LogMessage::IsFatal() const {
463
+ return data_->entry.log_severity() == absl::LogSeverity::kFatal &&
464
+ absl::log_internal::ExitOnDFatal();
465
+ }
466
+
467
+ void LogMessage::PrepareToDie() {
468
+ // If we log a FATAL message, flush all the log destinations, then toss
469
+ // a signal for others to catch. We leave the logs in a state that
470
+ // someone else can use them (as long as they flush afterwards)
471
+ if (data_->first_fatal) {
472
+ // Notify observers about the upcoming fatal error.
473
+ ABSL_INTERNAL_C_SYMBOL(AbslInternalOnFatalLogMessage)(data_->entry);
474
+ }
475
+
476
+ if (!data_->fail_quietly) {
477
+ // Log the message first before we start collecting stack trace.
478
+ log_internal::LogToSinks(data_->entry, absl::MakeSpan(data_->extra_sinks),
479
+ data_->extra_sinks_only);
480
+
481
+ // `DumpStackTrace` generates an empty string under MSVC.
482
+ // Adding the constant prefix here simplifies testing.
483
+ data_->entry.stacktrace_ = "*** Check failure stack trace: ***\n";
484
+ debugging_internal::DumpStackTrace(
485
+ 0, log_internal::MaxFramesInLogStackTrace(),
486
+ log_internal::ShouldSymbolizeLogStackTrace(), WriteToString,
487
+ &data_->entry.stacktrace_);
488
+ }
489
+ }
490
+
491
+ void LogMessage::Die() {
492
+ absl::FlushLogSinks();
493
+
494
+ if (data_->fail_quietly) {
495
+ FailQuietly();
496
+ } else {
497
+ FailWithoutStackTrace();
498
+ }
499
+ }
500
+
501
+ void LogMessage::SendToLog() {
502
+ if (IsFatal()) PrepareToDie();
503
+ // Also log to all registered sinks, even if OnlyLogToStderr() is set.
504
+ log_internal::LogToSinks(data_->entry, absl::MakeSpan(data_->extra_sinks),
505
+ data_->extra_sinks_only);
506
+ if (IsFatal()) Die();
507
+ }
508
+
509
+ void LogMessage::LogBacktraceIfNeeded() {
510
+ if (!absl::log_internal::IsInitialized()) return;
511
+
512
+ if (!absl::log_internal::ShouldLogBacktraceAt(data_->entry.source_basename(),
513
+ data_->entry.source_line()))
514
+ return;
515
+ OstreamView view(*data_);
516
+ view.stream() << " (stacktrace:\n";
517
+ debugging_internal::DumpStackTrace(
518
+ 1, log_internal::MaxFramesInLogStackTrace(),
519
+ log_internal::ShouldSymbolizeLogStackTrace(), WriteToStream,
520
+ &view.stream());
521
+ view.stream() << ") ";
522
+ }
523
+
524
+ // Encodes into `data_->encoded_remaining` a partial `logging.proto.Event`
525
+ // containing the specified string data using a `Value` field appropriate to
526
+ // `str_type`. Truncates `str` if necessary, but emits nothing and marks the
527
+ // buffer full if even the field headers do not fit.
528
+ template <LogMessage::StringType str_type>
529
+ void LogMessage::CopyToEncodedBuffer(absl::string_view str) {
530
+ auto encoded_remaining_copy = data_->encoded_remaining;
531
+ auto start = EncodeMessageStart(
532
+ EventTag::kValue, BufferSizeFor(WireType::kLengthDelimited) + str.size(),
533
+ &encoded_remaining_copy);
534
+ // If the `logging.proto.Event.value` field header did not fit,
535
+ // `EncodeMessageStart` will have zeroed `encoded_remaining_copy`'s size and
536
+ // `EncodeStringTruncate` will fail too.
537
+ if (EncodeStringTruncate(str_type == StringType::kLiteral
538
+ ? ValueTag::kStringLiteral
539
+ : ValueTag::kString,
540
+ str, &encoded_remaining_copy)) {
541
+ // The string may have been truncated, but the field header fit.
542
+ EncodeMessageLength(start, &encoded_remaining_copy);
543
+ data_->encoded_remaining = encoded_remaining_copy;
544
+ } else {
545
+ // The field header(s) did not fit; zero `encoded_remaining` so we don't
546
+ // write anything else later.
547
+ data_->encoded_remaining.remove_suffix(data_->encoded_remaining.size());
548
+ }
549
+ }
550
+ template void LogMessage::CopyToEncodedBuffer<LogMessage::StringType::kLiteral>(
551
+ absl::string_view str);
552
+ template void LogMessage::CopyToEncodedBuffer<
553
+ LogMessage::StringType::kNotLiteral>(absl::string_view str);
554
+ template <LogMessage::StringType str_type>
555
+ void LogMessage::CopyToEncodedBuffer(char ch, size_t num) {
556
+ auto encoded_remaining_copy = data_->encoded_remaining;
557
+ auto value_start = EncodeMessageStart(
558
+ EventTag::kValue, BufferSizeFor(WireType::kLengthDelimited) + num,
559
+ &encoded_remaining_copy);
560
+ auto str_start = EncodeMessageStart(str_type == StringType::kLiteral
561
+ ? ValueTag::kStringLiteral
562
+ : ValueTag::kString,
563
+ num, &encoded_remaining_copy);
564
+ if (str_start.data()) {
565
+ // The field headers fit.
566
+ log_internal::AppendTruncated(ch, num, encoded_remaining_copy);
567
+ EncodeMessageLength(str_start, &encoded_remaining_copy);
568
+ EncodeMessageLength(value_start, &encoded_remaining_copy);
569
+ data_->encoded_remaining = encoded_remaining_copy;
570
+ } else {
571
+ // The field header(s) did not fit; zero `encoded_remaining` so we don't
572
+ // write anything else later.
573
+ data_->encoded_remaining.remove_suffix(data_->encoded_remaining.size());
574
+ }
575
+ }
576
+ template void LogMessage::CopyToEncodedBuffer<LogMessage::StringType::kLiteral>(
577
+ char ch, size_t num);
578
+ template void LogMessage::CopyToEncodedBuffer<
579
+ LogMessage::StringType::kNotLiteral>(char ch, size_t num);
580
+
581
+ LogMessageFatal::LogMessageFatal(const char* file, int line)
582
+ : LogMessage(file, line, absl::LogSeverity::kFatal) {}
583
+
584
+ LogMessageFatal::LogMessageFatal(const char* file, int line,
585
+ absl::string_view failure_msg)
586
+ : LogMessage(file, line, absl::LogSeverity::kFatal) {
587
+ *this << "Check failed: " << failure_msg << " ";
588
+ }
589
+
590
+ // ABSL_ATTRIBUTE_NORETURN doesn't seem to work on destructors with msvc, so
591
+ // disable msvc's warning about the d'tor never returning.
592
+ #if defined(_MSC_VER) && !defined(__clang__)
593
+ #pragma warning(push)
594
+ #pragma warning(disable : 4722)
595
+ #endif
596
+ LogMessageFatal::~LogMessageFatal() {
597
+ Flush();
598
+ FailWithoutStackTrace();
599
+ }
600
+ #if defined(_MSC_VER) && !defined(__clang__)
601
+ #pragma warning(pop)
602
+ #endif
603
+
604
+ LogMessageQuietlyFatal::LogMessageQuietlyFatal(const char* file, int line)
605
+ : LogMessage(file, line, absl::LogSeverity::kFatal) {
606
+ SetFailQuietly();
607
+ }
608
+
609
+ LogMessageQuietlyFatal::LogMessageQuietlyFatal(const char* file, int line,
610
+ absl::string_view failure_msg)
611
+ : LogMessage(file, line, absl::LogSeverity::kFatal) {
612
+ SetFailQuietly();
613
+ *this << "Check failed: " << failure_msg << " ";
614
+ }
615
+
616
+ // ABSL_ATTRIBUTE_NORETURN doesn't seem to work on destructors with msvc, so
617
+ // disable msvc's warning about the d'tor never returning.
618
+ #if defined(_MSC_VER) && !defined(__clang__)
619
+ #pragma warning(push)
620
+ #pragma warning(disable : 4722)
621
+ #endif
622
+ LogMessageQuietlyFatal::~LogMessageQuietlyFatal() {
623
+ Flush();
624
+ FailQuietly();
625
+ }
626
+ #if defined(_MSC_VER) && !defined(__clang__)
627
+ #pragma warning(pop)
628
+ #endif
629
+
630
+ } // namespace log_internal
631
+
632
+ ABSL_NAMESPACE_END
633
+ } // namespace absl
weight/_dep/abseil-cpp/absl/log/internal/log_message.h ADDED
@@ -0,0 +1,375 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/internal/log_message.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This file declares `class absl::log_internal::LogMessage`. This class more or
20
+ // less represents a particular log message. LOG/CHECK macros create a
21
+ // temporary instance of `LogMessage` and then stream values to it. At the end
22
+ // of the LOG/CHECK statement, LogMessage instance goes out of scope and
23
+ // `~LogMessage` directs the message to the registered log sinks.
24
+ // Heap-allocation of `LogMessage` is unsupported. Construction outside of a
25
+ // `LOG` macro is unsupported.
26
+
27
+ #ifndef ABSL_LOG_INTERNAL_LOG_MESSAGE_H_
28
+ #define ABSL_LOG_INTERNAL_LOG_MESSAGE_H_
29
+
30
+ #include <ios>
31
+ #include <memory>
32
+ #include <ostream>
33
+ #include <streambuf>
34
+ #include <string>
35
+
36
+ #include "absl/base/attributes.h"
37
+ #include "absl/base/config.h"
38
+ #include "absl/base/internal/errno_saver.h"
39
+ #include "absl/base/log_severity.h"
40
+ #include "absl/log/internal/nullguard.h"
41
+ #include "absl/log/log_entry.h"
42
+ #include "absl/log/log_sink.h"
43
+ #include "absl/strings/has_absl_stringify.h"
44
+ #include "absl/strings/string_view.h"
45
+ #include "absl/time/time.h"
46
+
47
+ namespace absl {
48
+ ABSL_NAMESPACE_BEGIN
49
+ namespace log_internal {
50
+ constexpr int kLogMessageBufferSize = 15000;
51
+
52
+ class LogMessage {
53
+ public:
54
+ struct InfoTag {};
55
+ struct WarningTag {};
56
+ struct ErrorTag {};
57
+
58
+ // Used for `LOG`.
59
+ LogMessage(const char* file, int line,
60
+ absl::LogSeverity severity) ABSL_ATTRIBUTE_COLD;
61
+ // These constructors are slightly smaller/faster to call; the severity is
62
+ // curried into the function pointer.
63
+ LogMessage(const char* file, int line,
64
+ InfoTag) ABSL_ATTRIBUTE_COLD ABSL_ATTRIBUTE_NOINLINE;
65
+ LogMessage(const char* file, int line,
66
+ WarningTag) ABSL_ATTRIBUTE_COLD ABSL_ATTRIBUTE_NOINLINE;
67
+ LogMessage(const char* file, int line,
68
+ ErrorTag) ABSL_ATTRIBUTE_COLD ABSL_ATTRIBUTE_NOINLINE;
69
+ LogMessage(const LogMessage&) = delete;
70
+ LogMessage& operator=(const LogMessage&) = delete;
71
+ ~LogMessage() ABSL_ATTRIBUTE_COLD;
72
+
73
+ // Overrides the location inferred from the callsite. The string pointed to
74
+ // by `file` must be valid until the end of the statement.
75
+ LogMessage& AtLocation(absl::string_view file, int line);
76
+ // Omits the prefix from this line. The prefix includes metadata about the
77
+ // logged data such as source code location and timestamp.
78
+ LogMessage& NoPrefix();
79
+ // Sets the verbosity field of the logged message as if it was logged by
80
+ // `VLOG(verbose_level)`. Unlike `VLOG`, this method does not affect
81
+ // evaluation of the statement when the specified `verbose_level` has been
82
+ // disabled. The only effect is on `absl::LogSink` implementations which
83
+ // make use of the `absl::LogSink::verbosity()` value. The value
84
+ // `absl::LogEntry::kNoVerbosityLevel` can be specified to mark the message
85
+ // not verbose.
86
+ LogMessage& WithVerbosity(int verbose_level);
87
+ // Uses the specified timestamp instead of one collected in the constructor.
88
+ LogMessage& WithTimestamp(absl::Time timestamp);
89
+ // Uses the specified thread ID instead of one collected in the constructor.
90
+ LogMessage& WithThreadID(absl::LogEntry::tid_t tid);
91
+ // Copies all metadata (but no data) from the specified `absl::LogEntry`.
92
+ LogMessage& WithMetadataFrom(const absl::LogEntry& entry);
93
+ // Appends to the logged message a colon, a space, a textual description of
94
+ // the current value of `errno` (as by strerror(3)), and the numerical value
95
+ // of `errno`.
96
+ LogMessage& WithPerror();
97
+ // Sends this message to `*sink` in addition to whatever other sinks it would
98
+ // otherwise have been sent to. `sink` must not be null.
99
+ LogMessage& ToSinkAlso(absl::LogSink* sink);
100
+ // Sends this message to `*sink` and no others. `sink` must not be null.
101
+ LogMessage& ToSinkOnly(absl::LogSink* sink);
102
+
103
+ // Don't call this method from outside this library.
104
+ LogMessage& InternalStream() { return *this; }
105
+
106
+ // By-value overloads for small, common types let us overlook common failures
107
+ // to define globals and static data members (i.e. in a .cc file).
108
+ // clang-format off
109
+ // The CUDA toolchain cannot handle these <<<'s:
110
+ LogMessage& operator<<(char v) { return operator<< <char>(v); }
111
+ LogMessage& operator<<(signed char v) { return operator<< <signed char>(v); }
112
+ LogMessage& operator<<(unsigned char v) {
113
+ return operator<< <unsigned char>(v);
114
+ }
115
+ LogMessage& operator<<(signed short v) { // NOLINT
116
+ return operator<< <signed short>(v); // NOLINT
117
+ }
118
+ LogMessage& operator<<(signed int v) { return operator<< <signed int>(v); }
119
+ LogMessage& operator<<(signed long v) { // NOLINT
120
+ return operator<< <signed long>(v); // NOLINT
121
+ }
122
+ LogMessage& operator<<(signed long long v) { // NOLINT
123
+ return operator<< <signed long long>(v); // NOLINT
124
+ }
125
+ LogMessage& operator<<(unsigned short v) { // NOLINT
126
+ return operator<< <unsigned short>(v); // NOLINT
127
+ }
128
+ LogMessage& operator<<(unsigned int v) {
129
+ return operator<< <unsigned int>(v);
130
+ }
131
+ LogMessage& operator<<(unsigned long v) { // NOLINT
132
+ return operator<< <unsigned long>(v); // NOLINT
133
+ }
134
+ LogMessage& operator<<(unsigned long long v) { // NOLINT
135
+ return operator<< <unsigned long long>(v); // NOLINT
136
+ }
137
+ LogMessage& operator<<(void* v) { return operator<< <void*>(v); }
138
+ LogMessage& operator<<(const void* v) { return operator<< <const void*>(v); }
139
+ LogMessage& operator<<(float v) { return operator<< <float>(v); }
140
+ LogMessage& operator<<(double v) { return operator<< <double>(v); }
141
+ LogMessage& operator<<(bool v) { return operator<< <bool>(v); }
142
+ // clang-format on
143
+
144
+ // These overloads are more efficient since no `ostream` is involved.
145
+ LogMessage& operator<<(const std::string& v);
146
+ LogMessage& operator<<(absl::string_view v);
147
+
148
+ // Handle stream manipulators e.g. std::endl.
149
+ LogMessage& operator<<(std::ostream& (*m)(std::ostream& os));
150
+ LogMessage& operator<<(std::ios_base& (*m)(std::ios_base& os));
151
+
152
+ // Literal strings. This allows us to record C string literals as literals in
153
+ // the logging.proto.Value.
154
+ //
155
+ // Allow this overload to be inlined to prevent generating instantiations of
156
+ // this template for every value of `SIZE` encountered in each source code
157
+ // file. That significantly increases linker input sizes. Inlining is cheap
158
+ // because the argument to this overload is almost always a string literal so
159
+ // the call to `strlen` can be replaced at compile time. The overload for
160
+ // `char[]` below should not be inlined. The compiler typically does not have
161
+ // the string at compile time and cannot replace the call to `strlen` so
162
+ // inlining it increases the binary size. See the discussion on
163
+ // cl/107527369.
164
+ template <int SIZE>
165
+ LogMessage& operator<<(const char (&buf)[SIZE]);
166
+
167
+ // This prevents non-const `char[]` arrays from looking like literals.
168
+ template <int SIZE>
169
+ LogMessage& operator<<(char (&buf)[SIZE]) ABSL_ATTRIBUTE_NOINLINE;
170
+
171
+ // Types that support `AbslStringify()` are serialized that way.
172
+ template <typename T,
173
+ typename std::enable_if<absl::HasAbslStringify<T>::value,
174
+ int>::type = 0>
175
+ LogMessage& operator<<(const T& v) ABSL_ATTRIBUTE_NOINLINE;
176
+
177
+ // Types that don't support `AbslStringify()` but do support streaming into a
178
+ // `std::ostream&` are serialized that way.
179
+ template <typename T,
180
+ typename std::enable_if<!absl::HasAbslStringify<T>::value,
181
+ int>::type = 0>
182
+ LogMessage& operator<<(const T& v) ABSL_ATTRIBUTE_NOINLINE;
183
+
184
+ // Note: We explicitly do not support `operator<<` for non-const references
185
+ // because it breaks logging of non-integer bitfield types (i.e., enums).
186
+
187
+ protected:
188
+ // Call `abort()` or similar to perform `LOG(FATAL)` crash. It is assumed
189
+ // that the caller has already generated and written the trace as appropriate.
190
+ ABSL_ATTRIBUTE_NORETURN static void FailWithoutStackTrace();
191
+
192
+ // Similar to `FailWithoutStackTrace()`, but without `abort()`. Terminates
193
+ // the process with an error exit code.
194
+ ABSL_ATTRIBUTE_NORETURN static void FailQuietly();
195
+
196
+ // Dispatches the completed `absl::LogEntry` to applicable `absl::LogSink`s.
197
+ // This might as well be inlined into `~LogMessage` except that
198
+ // `~LogMessageFatal` needs to call it early.
199
+ void Flush();
200
+
201
+ // After this is called, failures are done as quiet as possible for this log
202
+ // message.
203
+ void SetFailQuietly();
204
+
205
+ private:
206
+ struct LogMessageData; // Opaque type containing message state
207
+ friend class AsLiteralImpl;
208
+ friend class StringifySink;
209
+
210
+ // This streambuf writes directly into the structured logging buffer so that
211
+ // arbitrary types can be encoded as string data (using
212
+ // `operator<<(std::ostream &, ...)` without any extra allocation or copying.
213
+ // Space is reserved before the data to store the length field, which is
214
+ // filled in by `~OstreamView`.
215
+ class OstreamView final : public std::streambuf {
216
+ public:
217
+ explicit OstreamView(LogMessageData& message_data);
218
+ ~OstreamView() override;
219
+ OstreamView(const OstreamView&) = delete;
220
+ OstreamView& operator=(const OstreamView&) = delete;
221
+ std::ostream& stream();
222
+
223
+ private:
224
+ LogMessageData& data_;
225
+ absl::Span<char> encoded_remaining_copy_;
226
+ absl::Span<char> message_start_;
227
+ absl::Span<char> string_start_;
228
+ };
229
+
230
+ enum class StringType {
231
+ kLiteral,
232
+ kNotLiteral,
233
+ };
234
+ template <StringType str_type>
235
+ void CopyToEncodedBuffer(absl::string_view str) ABSL_ATTRIBUTE_NOINLINE;
236
+ template <StringType str_type>
237
+ void CopyToEncodedBuffer(char ch, size_t num) ABSL_ATTRIBUTE_NOINLINE;
238
+
239
+ // Returns `true` if the message is fatal or enabled debug-fatal.
240
+ bool IsFatal() const;
241
+
242
+ // Records some tombstone-type data in anticipation of `Die`.
243
+ void PrepareToDie();
244
+ void Die();
245
+
246
+ void SendToLog();
247
+
248
+ // Checks `FLAGS_log_backtrace_at` and appends a backtrace if appropriate.
249
+ void LogBacktraceIfNeeded();
250
+
251
+ // This should be the first data member so that its initializer captures errno
252
+ // before any other initializers alter it (e.g. with calls to new) and so that
253
+ // no other destructors run afterward an alter it (e.g. with calls to delete).
254
+ absl::base_internal::ErrnoSaver errno_saver_;
255
+
256
+ // We keep the data in a separate struct so that each instance of `LogMessage`
257
+ // uses less stack space.
258
+ std::unique_ptr<LogMessageData> data_;
259
+ };
260
+
261
+ // Helper class so that `AbslStringify()` can modify the LogMessage.
262
+ class StringifySink final {
263
+ public:
264
+ explicit StringifySink(LogMessage& message) : message_(message) {}
265
+
266
+ void Append(size_t count, char ch) {
267
+ message_.CopyToEncodedBuffer<LogMessage::StringType::kNotLiteral>(ch,
268
+ count);
269
+ }
270
+
271
+ void Append(absl::string_view v) {
272
+ message_.CopyToEncodedBuffer<LogMessage::StringType::kNotLiteral>(v);
273
+ }
274
+
275
+ // For types that implement `AbslStringify` using `absl::Format()`.
276
+ friend void AbslFormatFlush(StringifySink* sink, absl::string_view v) {
277
+ sink->Append(v);
278
+ }
279
+
280
+ private:
281
+ LogMessage& message_;
282
+ };
283
+
284
+ // Note: the following is declared `ABSL_ATTRIBUTE_NOINLINE`
285
+ template <typename T,
286
+ typename std::enable_if<absl::HasAbslStringify<T>::value, int>::type>
287
+ LogMessage& LogMessage::operator<<(const T& v) {
288
+ StringifySink sink(*this);
289
+ // Replace with public API.
290
+ AbslStringify(sink, v);
291
+ return *this;
292
+ }
293
+
294
+ // Note: the following is declared `ABSL_ATTRIBUTE_NOINLINE`
295
+ template <typename T,
296
+ typename std::enable_if<!absl::HasAbslStringify<T>::value, int>::type>
297
+ LogMessage& LogMessage::operator<<(const T& v) {
298
+ OstreamView view(*data_);
299
+ view.stream() << log_internal::NullGuard<T>().Guard(v);
300
+ return *this;
301
+ }
302
+
303
+ template <int SIZE>
304
+ LogMessage& LogMessage::operator<<(const char (&buf)[SIZE]) {
305
+ CopyToEncodedBuffer<StringType::kLiteral>(buf);
306
+ return *this;
307
+ }
308
+
309
+ // Note: the following is declared `ABSL_ATTRIBUTE_NOINLINE`
310
+ template <int SIZE>
311
+ LogMessage& LogMessage::operator<<(char (&buf)[SIZE]) {
312
+ CopyToEncodedBuffer<StringType::kNotLiteral>(buf);
313
+ return *this;
314
+ }
315
+ // We instantiate these specializations in the library's TU to save space in
316
+ // other TUs. Since the template is marked `ABSL_ATTRIBUTE_NOINLINE` we will be
317
+ // emitting a function call either way.
318
+ extern template LogMessage& LogMessage::operator<<(const char& v);
319
+ extern template LogMessage& LogMessage::operator<<(const signed char& v);
320
+ extern template LogMessage& LogMessage::operator<<(const unsigned char& v);
321
+ extern template LogMessage& LogMessage::operator<<(const short& v); // NOLINT
322
+ extern template LogMessage& LogMessage::operator<<(
323
+ const unsigned short& v); // NOLINT
324
+ extern template LogMessage& LogMessage::operator<<(const int& v);
325
+ extern template LogMessage& LogMessage::operator<<(
326
+ const unsigned int& v); // NOLINT
327
+ extern template LogMessage& LogMessage::operator<<(const long& v); // NOLINT
328
+ extern template LogMessage& LogMessage::operator<<(
329
+ const unsigned long& v); // NOLINT
330
+ extern template LogMessage& LogMessage::operator<<(
331
+ const long long& v); // NOLINT
332
+ extern template LogMessage& LogMessage::operator<<(
333
+ const unsigned long long& v); // NOLINT
334
+ extern template LogMessage& LogMessage::operator<<(void* const& v);
335
+ extern template LogMessage& LogMessage::operator<<(const void* const& v);
336
+ extern template LogMessage& LogMessage::operator<<(const float& v);
337
+ extern template LogMessage& LogMessage::operator<<(const double& v);
338
+ extern template LogMessage& LogMessage::operator<<(const bool& v);
339
+
340
+ extern template void LogMessage::CopyToEncodedBuffer<
341
+ LogMessage::StringType::kLiteral>(absl::string_view str);
342
+ extern template void LogMessage::CopyToEncodedBuffer<
343
+ LogMessage::StringType::kNotLiteral>(absl::string_view str);
344
+ extern template void
345
+ LogMessage::CopyToEncodedBuffer<LogMessage::StringType::kLiteral>(char ch,
346
+ size_t num);
347
+ extern template void LogMessage::CopyToEncodedBuffer<
348
+ LogMessage::StringType::kNotLiteral>(char ch, size_t num);
349
+
350
+ // `LogMessageFatal` ensures the process will exit in failure after logging this
351
+ // message.
352
+ class LogMessageFatal final : public LogMessage {
353
+ public:
354
+ LogMessageFatal(const char* file, int line) ABSL_ATTRIBUTE_COLD;
355
+ LogMessageFatal(const char* file, int line,
356
+ absl::string_view failure_msg) ABSL_ATTRIBUTE_COLD;
357
+ ABSL_ATTRIBUTE_NORETURN ~LogMessageFatal();
358
+ };
359
+
360
+ class LogMessageQuietlyFatal final : public LogMessage {
361
+ public:
362
+ LogMessageQuietlyFatal(const char* file, int line) ABSL_ATTRIBUTE_COLD;
363
+ LogMessageQuietlyFatal(const char* file, int line,
364
+ absl::string_view failure_msg) ABSL_ATTRIBUTE_COLD;
365
+ ABSL_ATTRIBUTE_NORETURN ~LogMessageQuietlyFatal();
366
+ };
367
+
368
+ } // namespace log_internal
369
+ ABSL_NAMESPACE_END
370
+ } // namespace absl
371
+
372
+ extern "C" ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(
373
+ AbslInternalOnFatalLogMessage)(const absl::LogEntry&);
374
+
375
+ #endif // ABSL_LOG_INTERNAL_LOG_MESSAGE_H_
weight/_dep/abseil-cpp/absl/log/internal/log_sink_set.cc ADDED
@@ -0,0 +1,296 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //
2
+ // Copyright 2022 The Abseil Authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // https://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+
16
+ #include "absl/log/internal/log_sink_set.h"
17
+
18
+ #ifndef ABSL_HAVE_THREAD_LOCAL
19
+ #include <pthread.h>
20
+ #endif
21
+
22
+ #ifdef __ANDROID__
23
+ #include <android/log.h>
24
+ #endif
25
+
26
+ #ifdef _WIN32
27
+ #include <windows.h>
28
+ #endif
29
+
30
+ #include <algorithm>
31
+ #include <vector>
32
+
33
+ #include "absl/base/attributes.h"
34
+ #include "absl/base/call_once.h"
35
+ #include "absl/base/config.h"
36
+ #include "absl/base/internal/raw_logging.h"
37
+ #include "absl/base/log_severity.h"
38
+ #include "absl/base/no_destructor.h"
39
+ #include "absl/base/thread_annotations.h"
40
+ #include "absl/cleanup/cleanup.h"
41
+ #include "absl/log/globals.h"
42
+ #include "absl/log/internal/config.h"
43
+ #include "absl/log/internal/globals.h"
44
+ #include "absl/log/log_entry.h"
45
+ #include "absl/log/log_sink.h"
46
+ #include "absl/strings/string_view.h"
47
+ #include "absl/synchronization/mutex.h"
48
+ #include "absl/types/span.h"
49
+
50
+ namespace absl {
51
+ ABSL_NAMESPACE_BEGIN
52
+ namespace log_internal {
53
+ namespace {
54
+
55
+ // Returns a mutable reference to a thread-local variable that should be true if
56
+ // a globally-registered `LogSink`'s `Send()` is currently being invoked on this
57
+ // thread.
58
+ bool& ThreadIsLoggingStatus() {
59
+ #ifdef ABSL_HAVE_THREAD_LOCAL
60
+ ABSL_CONST_INIT thread_local bool thread_is_logging = false;
61
+ return thread_is_logging;
62
+ #else
63
+ ABSL_CONST_INIT static pthread_key_t thread_is_logging_key;
64
+ static const bool unused = [] {
65
+ if (pthread_key_create(&thread_is_logging_key, [](void* data) {
66
+ delete reinterpret_cast<bool*>(data);
67
+ })) {
68
+ perror("pthread_key_create failed!");
69
+ abort();
70
+ }
71
+ return true;
72
+ }();
73
+ (void)unused; // Fixes -wunused-variable warning
74
+ bool* thread_is_logging_ptr =
75
+ reinterpret_cast<bool*>(pthread_getspecific(thread_is_logging_key));
76
+
77
+ if (ABSL_PREDICT_FALSE(!thread_is_logging_ptr)) {
78
+ thread_is_logging_ptr = new bool{false};
79
+ if (pthread_setspecific(thread_is_logging_key, thread_is_logging_ptr)) {
80
+ perror("pthread_setspecific failed");
81
+ abort();
82
+ }
83
+ }
84
+ return *thread_is_logging_ptr;
85
+ #endif
86
+ }
87
+
88
+ class StderrLogSink final : public LogSink {
89
+ public:
90
+ ~StderrLogSink() override = default;
91
+
92
+ void Send(const absl::LogEntry& entry) override {
93
+ if (entry.log_severity() < absl::StderrThreshold() &&
94
+ absl::log_internal::IsInitialized()) {
95
+ return;
96
+ }
97
+
98
+ ABSL_CONST_INIT static absl::once_flag warn_if_not_initialized;
99
+ absl::call_once(warn_if_not_initialized, []() {
100
+ if (absl::log_internal::IsInitialized()) return;
101
+ const char w[] =
102
+ "WARNING: All log messages before absl::InitializeLog() is called"
103
+ " are written to STDERR\n";
104
+ absl::log_internal::WriteToStderr(w, absl::LogSeverity::kWarning);
105
+ });
106
+
107
+ if (!entry.stacktrace().empty()) {
108
+ absl::log_internal::WriteToStderr(entry.stacktrace(),
109
+ entry.log_severity());
110
+ } else {
111
+ // TODO(b/226937039): do this outside else condition once we avoid
112
+ // ReprintFatalMessage
113
+ absl::log_internal::WriteToStderr(
114
+ entry.text_message_with_prefix_and_newline(), entry.log_severity());
115
+ }
116
+ }
117
+ };
118
+
119
+ #if defined(__ANDROID__)
120
+ class AndroidLogSink final : public LogSink {
121
+ public:
122
+ ~AndroidLogSink() override = default;
123
+
124
+ void Send(const absl::LogEntry& entry) override {
125
+ const int level = AndroidLogLevel(entry);
126
+ const char* const tag = GetAndroidNativeTag();
127
+ __android_log_write(level, tag,
128
+ entry.text_message_with_prefix_and_newline_c_str());
129
+ if (entry.log_severity() == absl::LogSeverity::kFatal)
130
+ __android_log_write(ANDROID_LOG_FATAL, tag, "terminating.\n");
131
+ }
132
+
133
+ private:
134
+ static int AndroidLogLevel(const absl::LogEntry& entry) {
135
+ switch (entry.log_severity()) {
136
+ case absl::LogSeverity::kFatal:
137
+ return ANDROID_LOG_FATAL;
138
+ case absl::LogSeverity::kError:
139
+ return ANDROID_LOG_ERROR;
140
+ case absl::LogSeverity::kWarning:
141
+ return ANDROID_LOG_WARN;
142
+ default:
143
+ if (entry.verbosity() >= 2) return ANDROID_LOG_VERBOSE;
144
+ if (entry.verbosity() == 1) return ANDROID_LOG_DEBUG;
145
+ return ANDROID_LOG_INFO;
146
+ }
147
+ }
148
+ };
149
+ #endif // !defined(__ANDROID__)
150
+
151
+ #if defined(_WIN32)
152
+ class WindowsDebuggerLogSink final : public LogSink {
153
+ public:
154
+ ~WindowsDebuggerLogSink() override = default;
155
+
156
+ void Send(const absl::LogEntry& entry) override {
157
+ if (entry.log_severity() < absl::StderrThreshold() &&
158
+ absl::log_internal::IsInitialized()) {
159
+ return;
160
+ }
161
+ ::OutputDebugStringA(entry.text_message_with_prefix_and_newline_c_str());
162
+ }
163
+ };
164
+ #endif // !defined(_WIN32)
165
+
166
+ class GlobalLogSinkSet final {
167
+ public:
168
+ GlobalLogSinkSet() {
169
+ #if defined(__myriad2__) || defined(__Fuchsia__)
170
+ // myriad2 and Fuchsia do not log to stderr by default.
171
+ #else
172
+ static absl::NoDestructor<StderrLogSink> stderr_log_sink;
173
+ AddLogSink(stderr_log_sink.get());
174
+ #endif
175
+ #ifdef __ANDROID__
176
+ static absl::NoDestructor<AndroidLogSink> android_log_sink;
177
+ AddLogSink(android_log_sink.get());
178
+ #endif
179
+ #if defined(_WIN32)
180
+ static absl::NoDestructor<WindowsDebuggerLogSink> debugger_log_sink;
181
+ AddLogSink(debugger_log_sink.get());
182
+ #endif // !defined(_WIN32)
183
+ }
184
+
185
+ void LogToSinks(const absl::LogEntry& entry,
186
+ absl::Span<absl::LogSink*> extra_sinks, bool extra_sinks_only)
187
+ ABSL_LOCKS_EXCLUDED(guard_) {
188
+ SendToSinks(entry, extra_sinks);
189
+
190
+ if (!extra_sinks_only) {
191
+ if (ThreadIsLoggingToLogSink()) {
192
+ absl::log_internal::WriteToStderr(
193
+ entry.text_message_with_prefix_and_newline(), entry.log_severity());
194
+ } else {
195
+ absl::ReaderMutexLock global_sinks_lock(&guard_);
196
+ ThreadIsLoggingStatus() = true;
197
+ // Ensure the "thread is logging" status is reverted upon leaving the
198
+ // scope even in case of exceptions.
199
+ auto status_cleanup =
200
+ absl::MakeCleanup([] { ThreadIsLoggingStatus() = false; });
201
+ SendToSinks(entry, absl::MakeSpan(sinks_));
202
+ }
203
+ }
204
+ }
205
+
206
+ void AddLogSink(absl::LogSink* sink) ABSL_LOCKS_EXCLUDED(guard_) {
207
+ {
208
+ absl::WriterMutexLock global_sinks_lock(&guard_);
209
+ auto pos = std::find(sinks_.begin(), sinks_.end(), sink);
210
+ if (pos == sinks_.end()) {
211
+ sinks_.push_back(sink);
212
+ return;
213
+ }
214
+ }
215
+ ABSL_INTERNAL_LOG(FATAL, "Duplicate log sinks are not supported");
216
+ }
217
+
218
+ void RemoveLogSink(absl::LogSink* sink) ABSL_LOCKS_EXCLUDED(guard_) {
219
+ {
220
+ absl::WriterMutexLock global_sinks_lock(&guard_);
221
+ auto pos = std::find(sinks_.begin(), sinks_.end(), sink);
222
+ if (pos != sinks_.end()) {
223
+ sinks_.erase(pos);
224
+ return;
225
+ }
226
+ }
227
+ ABSL_INTERNAL_LOG(FATAL, "Mismatched log sink being removed");
228
+ }
229
+
230
+ void FlushLogSinks() ABSL_LOCKS_EXCLUDED(guard_) {
231
+ if (ThreadIsLoggingToLogSink()) {
232
+ // The thread_local condition demonstrates that we're already holding the
233
+ // lock in order to iterate over `sinks_` for dispatch. The thread-safety
234
+ // annotations don't know this, so we use `ABSL_NO_THREAD_SAFETY_ANALYSIS`
235
+ guard_.AssertReaderHeld();
236
+ FlushLogSinksLocked();
237
+ } else {
238
+ absl::ReaderMutexLock global_sinks_lock(&guard_);
239
+ // In case if LogSink::Flush overload decides to log
240
+ ThreadIsLoggingStatus() = true;
241
+ // Ensure the "thread is logging" status is reverted upon leaving the
242
+ // scope even in case of exceptions.
243
+ auto status_cleanup =
244
+ absl::MakeCleanup([] { ThreadIsLoggingStatus() = false; });
245
+ FlushLogSinksLocked();
246
+ }
247
+ }
248
+
249
+ private:
250
+ void FlushLogSinksLocked() ABSL_SHARED_LOCKS_REQUIRED(guard_) {
251
+ for (absl::LogSink* sink : sinks_) {
252
+ sink->Flush();
253
+ }
254
+ }
255
+
256
+ // Helper routine for LogToSinks.
257
+ static void SendToSinks(const absl::LogEntry& entry,
258
+ absl::Span<absl::LogSink*> sinks) {
259
+ for (absl::LogSink* sink : sinks) {
260
+ sink->Send(entry);
261
+ }
262
+ }
263
+
264
+ using LogSinksSet = std::vector<absl::LogSink*>;
265
+ absl::Mutex guard_;
266
+ LogSinksSet sinks_ ABSL_GUARDED_BY(guard_);
267
+ };
268
+
269
+ // Returns reference to the global LogSinks set.
270
+ GlobalLogSinkSet& GlobalSinks() {
271
+ static absl::NoDestructor<GlobalLogSinkSet> global_sinks;
272
+ return *global_sinks;
273
+ }
274
+
275
+ } // namespace
276
+
277
+ bool ThreadIsLoggingToLogSink() { return ThreadIsLoggingStatus(); }
278
+
279
+ void LogToSinks(const absl::LogEntry& entry,
280
+ absl::Span<absl::LogSink*> extra_sinks, bool extra_sinks_only) {
281
+ log_internal::GlobalSinks().LogToSinks(entry, extra_sinks, extra_sinks_only);
282
+ }
283
+
284
+ void AddLogSink(absl::LogSink* sink) {
285
+ log_internal::GlobalSinks().AddLogSink(sink);
286
+ }
287
+
288
+ void RemoveLogSink(absl::LogSink* sink) {
289
+ log_internal::GlobalSinks().RemoveLogSink(sink);
290
+ }
291
+
292
+ void FlushLogSinks() { log_internal::GlobalSinks().FlushLogSinks(); }
293
+
294
+ } // namespace log_internal
295
+ ABSL_NAMESPACE_END
296
+ } // namespace absl
weight/_dep/abseil-cpp/absl/log/internal/log_sink_set.h ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/internal/log_sink_set.h
17
+ // -----------------------------------------------------------------------------
18
+
19
+ #ifndef ABSL_LOG_INTERNAL_LOG_SINK_SET_H_
20
+ #define ABSL_LOG_INTERNAL_LOG_SINK_SET_H_
21
+
22
+ #include "absl/base/config.h"
23
+ #include "absl/log/log_entry.h"
24
+ #include "absl/log/log_sink.h"
25
+ #include "absl/types/span.h"
26
+
27
+ namespace absl {
28
+ ABSL_NAMESPACE_BEGIN
29
+ namespace log_internal {
30
+
31
+ // Returns true if a globally-registered `LogSink`'s `Send()` is currently
32
+ // being invoked on this thread.
33
+ bool ThreadIsLoggingToLogSink();
34
+
35
+ // This function may log to two sets of sinks:
36
+ //
37
+ // * If `extra_sinks_only` is true, it will dispatch only to `extra_sinks`.
38
+ // `LogMessage::ToSinkAlso` and `LogMessage::ToSinkOnly` are used to attach
39
+ // extra sinks to the entry.
40
+ // * Otherwise it will also log to the global sinks set. This set is managed
41
+ // by `absl::AddLogSink` and `absl::RemoveLogSink`.
42
+ void LogToSinks(const absl::LogEntry& entry,
43
+ absl::Span<absl::LogSink*> extra_sinks, bool extra_sinks_only);
44
+
45
+ // Implementation for operations with log sink set.
46
+ void AddLogSink(absl::LogSink* sink);
47
+ void RemoveLogSink(absl::LogSink* sink);
48
+ void FlushLogSinks();
49
+
50
+ } // namespace log_internal
51
+ ABSL_NAMESPACE_END
52
+ } // namespace absl
53
+
54
+ #endif // ABSL_LOG_INTERNAL_LOG_SINK_SET_H_
weight/_dep/abseil-cpp/absl/log/internal/nullguard.cc ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2023 The Abseil Authors
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
+ // https://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
+ #include "absl/log/internal/nullguard.h"
16
+
17
+ #include <array>
18
+
19
+ #include "absl/base/attributes.h"
20
+ #include "absl/base/config.h"
21
+
22
+ namespace absl {
23
+ ABSL_NAMESPACE_BEGIN
24
+ namespace log_internal {
25
+
26
+ ABSL_CONST_INIT ABSL_DLL const std::array<char, 7> kCharNull{
27
+ {'(', 'n', 'u', 'l', 'l', ')', '\0'}};
28
+ ABSL_CONST_INIT ABSL_DLL const std::array<signed char, 7> kSignedCharNull{
29
+ {'(', 'n', 'u', 'l', 'l', ')', '\0'}};
30
+ ABSL_CONST_INIT ABSL_DLL const std::array<unsigned char, 7> kUnsignedCharNull{
31
+ {'(', 'n', 'u', 'l', 'l', ')', '\0'}};
32
+
33
+ } // namespace log_internal
34
+ ABSL_NAMESPACE_END
35
+ } // namespace absl
weight/_dep/abseil-cpp/absl/log/internal/nullguard.h ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/internal/nullguard.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // NullGuard exists such that NullGuard<T>::Guard(v) returns v, unless passed a
20
+ // nullptr_t, or a null char* or const char*, in which case it returns "(null)".
21
+ // This allows streaming NullGuard<T>::Guard(v) to an output stream without
22
+ // hitting undefined behavior for null values.
23
+
24
+ #ifndef ABSL_LOG_INTERNAL_NULLGUARD_H_
25
+ #define ABSL_LOG_INTERNAL_NULLGUARD_H_
26
+
27
+ #include <array>
28
+ #include <cstddef>
29
+
30
+ #include "absl/base/attributes.h"
31
+ #include "absl/base/config.h"
32
+
33
+ namespace absl {
34
+ ABSL_NAMESPACE_BEGIN
35
+ namespace log_internal {
36
+
37
+ ABSL_CONST_INIT ABSL_DLL extern const std::array<char, 7> kCharNull;
38
+ ABSL_CONST_INIT ABSL_DLL extern const std::array<signed char, 7>
39
+ kSignedCharNull;
40
+ ABSL_CONST_INIT ABSL_DLL extern const std::array<unsigned char, 7>
41
+ kUnsignedCharNull;
42
+
43
+ template <typename T>
44
+ struct NullGuard final {
45
+ static const T& Guard(const T& v) { return v; }
46
+ };
47
+ template <>
48
+ struct NullGuard<char*> final {
49
+ static const char* Guard(const char* v) { return v ? v : kCharNull.data(); }
50
+ };
51
+ template <>
52
+ struct NullGuard<const char*> final {
53
+ static const char* Guard(const char* v) { return v ? v : kCharNull.data(); }
54
+ };
55
+ template <>
56
+ struct NullGuard<signed char*> final {
57
+ static const signed char* Guard(const signed char* v) {
58
+ return v ? v : kSignedCharNull.data();
59
+ }
60
+ };
61
+ template <>
62
+ struct NullGuard<const signed char*> final {
63
+ static const signed char* Guard(const signed char* v) {
64
+ return v ? v : kSignedCharNull.data();
65
+ }
66
+ };
67
+ template <>
68
+ struct NullGuard<unsigned char*> final {
69
+ static const unsigned char* Guard(const unsigned char* v) {
70
+ return v ? v : kUnsignedCharNull.data();
71
+ }
72
+ };
73
+ template <>
74
+ struct NullGuard<const unsigned char*> final {
75
+ static const unsigned char* Guard(const unsigned char* v) {
76
+ return v ? v : kUnsignedCharNull.data();
77
+ }
78
+ };
79
+ template <>
80
+ struct NullGuard<std::nullptr_t> final {
81
+ static const char* Guard(const std::nullptr_t&) { return kCharNull.data(); }
82
+ };
83
+
84
+ } // namespace log_internal
85
+ ABSL_NAMESPACE_END
86
+ } // namespace absl
87
+
88
+ #endif // ABSL_LOG_INTERNAL_NULLGUARD_H_
weight/_dep/abseil-cpp/absl/log/internal/nullstream.h ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/internal/nullstream.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // Classes `NullStream`, `NullStreamMaybeFatal ` and `NullStreamFatal`
20
+ // implement a subset of the `LogMessage` API and are used instead when logging
21
+ // of messages has been disabled.
22
+
23
+ #ifndef ABSL_LOG_INTERNAL_NULLSTREAM_H_
24
+ #define ABSL_LOG_INTERNAL_NULLSTREAM_H_
25
+
26
+ #ifdef _WIN32
27
+ #include <cstdlib>
28
+ #else
29
+ #include <unistd.h>
30
+ #endif
31
+ #include <ios>
32
+ #include <ostream>
33
+
34
+ #include "absl/base/attributes.h"
35
+ #include "absl/base/config.h"
36
+ #include "absl/base/log_severity.h"
37
+ #include "absl/strings/string_view.h"
38
+
39
+ namespace absl {
40
+ ABSL_NAMESPACE_BEGIN
41
+ namespace log_internal {
42
+
43
+ // A `NullStream` implements the API of `LogMessage` (a few methods and
44
+ // `operator<<`) but does nothing. All methods are defined inline so the
45
+ // compiler can eliminate the whole instance and discard anything that's
46
+ // streamed in.
47
+ class NullStream {
48
+ public:
49
+ NullStream& AtLocation(absl::string_view, int) { return *this; }
50
+ template <typename SourceLocationType>
51
+ NullStream& AtLocation(SourceLocationType) {
52
+ return *this;
53
+ }
54
+ NullStream& NoPrefix() { return *this; }
55
+ NullStream& WithVerbosity(int) { return *this; }
56
+ template <typename TimeType>
57
+ NullStream& WithTimestamp(TimeType) {
58
+ return *this;
59
+ }
60
+ template <typename Tid>
61
+ NullStream& WithThreadID(Tid) {
62
+ return *this;
63
+ }
64
+ template <typename LogEntryType>
65
+ NullStream& WithMetadataFrom(const LogEntryType&) {
66
+ return *this;
67
+ }
68
+ NullStream& WithPerror() { return *this; }
69
+ template <typename LogSinkType>
70
+ NullStream& ToSinkAlso(LogSinkType*) {
71
+ return *this;
72
+ }
73
+ template <typename LogSinkType>
74
+ NullStream& ToSinkOnly(LogSinkType*) {
75
+ return *this;
76
+ }
77
+ template <typename LogSinkType>
78
+ NullStream& OutputToSink(LogSinkType*, bool) {
79
+ return *this;
80
+ }
81
+ NullStream& InternalStream() { return *this; }
82
+ };
83
+ template <typename T>
84
+ inline NullStream& operator<<(NullStream& str, const T&) {
85
+ return str;
86
+ }
87
+ inline NullStream& operator<<(NullStream& str,
88
+ std::ostream& (*)(std::ostream& os)) {
89
+ return str;
90
+ }
91
+ inline NullStream& operator<<(NullStream& str,
92
+ std::ios_base& (*)(std::ios_base& os)) {
93
+ return str;
94
+ }
95
+
96
+ // `NullStreamMaybeFatal` implements the process termination semantics of
97
+ // `LogMessage`, which is used for `DFATAL` severity and expression-defined
98
+ // severity e.g. `LOG(LEVEL(HowBadIsIt()))`. Like `LogMessage`, it terminates
99
+ // the process when destroyed if the passed-in severity equals `FATAL`.
100
+ class NullStreamMaybeFatal final : public NullStream {
101
+ public:
102
+ explicit NullStreamMaybeFatal(absl::LogSeverity severity)
103
+ : fatal_(severity == absl::LogSeverity::kFatal) {}
104
+ ~NullStreamMaybeFatal() {
105
+ if (fatal_) {
106
+ _exit(1);
107
+ }
108
+ }
109
+
110
+ private:
111
+ bool fatal_;
112
+ };
113
+
114
+ // `NullStreamFatal` implements the process termination semantics of
115
+ // `LogMessageFatal`, which means it always terminates the process. `DFATAL`
116
+ // and expression-defined severity use `NullStreamMaybeFatal` above.
117
+ class NullStreamFatal final : public NullStream {
118
+ public:
119
+ NullStreamFatal() = default;
120
+ // ABSL_ATTRIBUTE_NORETURN doesn't seem to work on destructors with msvc, so
121
+ // disable msvc's warning about the d'tor never returning.
122
+ #if defined(_MSC_VER) && !defined(__clang__)
123
+ #pragma warning(push)
124
+ #pragma warning(disable : 4722)
125
+ #endif
126
+ ABSL_ATTRIBUTE_NORETURN ~NullStreamFatal() { _exit(1); }
127
+ #if defined(_MSC_VER) && !defined(__clang__)
128
+ #pragma warning(pop)
129
+ #endif
130
+ };
131
+
132
+ } // namespace log_internal
133
+ ABSL_NAMESPACE_END
134
+ } // namespace absl
135
+
136
+ #endif // ABSL_LOG_INTERNAL_GLOBALS_H_
weight/_dep/abseil-cpp/absl/log/internal/proto.cc ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2020 The Abseil Authors.
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
+ // https://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
+ #include "absl/log/internal/proto.h"
16
+
17
+ #include <algorithm>
18
+ #include <cassert>
19
+ #include <cstddef>
20
+ #include <cstdint>
21
+ #include <cstring>
22
+
23
+ #include "absl/base/attributes.h"
24
+ #include "absl/base/config.h"
25
+ #include "absl/types/span.h"
26
+
27
+ namespace absl {
28
+ ABSL_NAMESPACE_BEGIN
29
+ namespace log_internal {
30
+ namespace {
31
+ void EncodeRawVarint(uint64_t value, size_t size, absl::Span<char> *buf) {
32
+ for (size_t s = 0; s < size; s++) {
33
+ (*buf)[s] = static_cast<char>((value & 0x7f) | (s + 1 == size ? 0 : 0x80));
34
+ value >>= 7;
35
+ }
36
+ buf->remove_prefix(size);
37
+ }
38
+ constexpr uint64_t MakeTagType(uint64_t tag, WireType type) {
39
+ return tag << 3 | static_cast<uint64_t>(type);
40
+ }
41
+ } // namespace
42
+
43
+ bool EncodeVarint(uint64_t tag, uint64_t value, absl::Span<char> *buf) {
44
+ const uint64_t tag_type = MakeTagType(tag, WireType::kVarint);
45
+ const size_t tag_type_size = VarintSize(tag_type);
46
+ const size_t value_size = VarintSize(value);
47
+ if (tag_type_size + value_size > buf->size()) {
48
+ buf->remove_suffix(buf->size());
49
+ return false;
50
+ }
51
+ EncodeRawVarint(tag_type, tag_type_size, buf);
52
+ EncodeRawVarint(value, value_size, buf);
53
+ return true;
54
+ }
55
+
56
+ bool Encode64Bit(uint64_t tag, uint64_t value, absl::Span<char> *buf) {
57
+ const uint64_t tag_type = MakeTagType(tag, WireType::k64Bit);
58
+ const size_t tag_type_size = VarintSize(tag_type);
59
+ if (tag_type_size + sizeof(value) > buf->size()) {
60
+ buf->remove_suffix(buf->size());
61
+ return false;
62
+ }
63
+ EncodeRawVarint(tag_type, tag_type_size, buf);
64
+ for (size_t s = 0; s < sizeof(value); s++) {
65
+ (*buf)[s] = static_cast<char>(value & 0xff);
66
+ value >>= 8;
67
+ }
68
+ buf->remove_prefix(sizeof(value));
69
+ return true;
70
+ }
71
+
72
+ bool Encode32Bit(uint64_t tag, uint32_t value, absl::Span<char> *buf) {
73
+ const uint64_t tag_type = MakeTagType(tag, WireType::k32Bit);
74
+ const size_t tag_type_size = VarintSize(tag_type);
75
+ if (tag_type_size + sizeof(value) > buf->size()) {
76
+ buf->remove_suffix(buf->size());
77
+ return false;
78
+ }
79
+ EncodeRawVarint(tag_type, tag_type_size, buf);
80
+ for (size_t s = 0; s < sizeof(value); s++) {
81
+ (*buf)[s] = static_cast<char>(value & 0xff);
82
+ value >>= 8;
83
+ }
84
+ buf->remove_prefix(sizeof(value));
85
+ return true;
86
+ }
87
+
88
+ bool EncodeBytes(uint64_t tag, absl::Span<const char> value,
89
+ absl::Span<char> *buf) {
90
+ const uint64_t tag_type = MakeTagType(tag, WireType::kLengthDelimited);
91
+ const size_t tag_type_size = VarintSize(tag_type);
92
+ uint64_t length = value.size();
93
+ const size_t length_size = VarintSize(length);
94
+ if (tag_type_size + length_size + value.size() > buf->size()) {
95
+ buf->remove_suffix(buf->size());
96
+ return false;
97
+ }
98
+ EncodeRawVarint(tag_type, tag_type_size, buf);
99
+ EncodeRawVarint(length, length_size, buf);
100
+ memcpy(buf->data(), value.data(), value.size());
101
+ buf->remove_prefix(value.size());
102
+ return true;
103
+ }
104
+
105
+ bool EncodeBytesTruncate(uint64_t tag, absl::Span<const char> value,
106
+ absl::Span<char> *buf) {
107
+ const uint64_t tag_type = MakeTagType(tag, WireType::kLengthDelimited);
108
+ const size_t tag_type_size = VarintSize(tag_type);
109
+ uint64_t length = value.size();
110
+ const size_t length_size =
111
+ VarintSize(std::min<uint64_t>(length, buf->size()));
112
+ if (tag_type_size + length_size <= buf->size() &&
113
+ tag_type_size + length_size + value.size() > buf->size()) {
114
+ value.remove_suffix(tag_type_size + length_size + value.size() -
115
+ buf->size());
116
+ length = value.size();
117
+ }
118
+ if (tag_type_size + length_size + value.size() > buf->size()) {
119
+ buf->remove_suffix(buf->size());
120
+ return false;
121
+ }
122
+ EncodeRawVarint(tag_type, tag_type_size, buf);
123
+ EncodeRawVarint(length, length_size, buf);
124
+ memcpy(buf->data(), value.data(), value.size());
125
+ buf->remove_prefix(value.size());
126
+ return true;
127
+ }
128
+
129
+ ABSL_MUST_USE_RESULT absl::Span<char> EncodeMessageStart(
130
+ uint64_t tag, uint64_t max_size, absl::Span<char> *buf) {
131
+ const uint64_t tag_type = MakeTagType(tag, WireType::kLengthDelimited);
132
+ const size_t tag_type_size = VarintSize(tag_type);
133
+ max_size = std::min<uint64_t>(max_size, buf->size());
134
+ const size_t length_size = VarintSize(max_size);
135
+ if (tag_type_size + length_size > buf->size()) {
136
+ buf->remove_suffix(buf->size());
137
+ return absl::Span<char>();
138
+ }
139
+ EncodeRawVarint(tag_type, tag_type_size, buf);
140
+ const absl::Span<char> ret = buf->subspan(0, length_size);
141
+ EncodeRawVarint(0, length_size, buf);
142
+ return ret;
143
+ }
144
+
145
+ void EncodeMessageLength(absl::Span<char> msg, const absl::Span<char> *buf) {
146
+ if (!msg.data()) return;
147
+ assert(buf->data() >= msg.data());
148
+ if (buf->data() < msg.data()) return;
149
+ EncodeRawVarint(
150
+ static_cast<uint64_t>(buf->data() - (msg.data() + msg.size())),
151
+ msg.size(), &msg);
152
+ }
153
+
154
+ namespace {
155
+ uint64_t DecodeVarint(absl::Span<const char> *buf) {
156
+ uint64_t value = 0;
157
+ size_t s = 0;
158
+ while (s < buf->size()) {
159
+ value |= static_cast<uint64_t>(static_cast<unsigned char>((*buf)[s]) & 0x7f)
160
+ << 7 * s;
161
+ if (!((*buf)[s++] & 0x80)) break;
162
+ }
163
+ buf->remove_prefix(s);
164
+ return value;
165
+ }
166
+
167
+ uint64_t Decode64Bit(absl::Span<const char> *buf) {
168
+ uint64_t value = 0;
169
+ size_t s = 0;
170
+ while (s < buf->size()) {
171
+ value |= static_cast<uint64_t>(static_cast<unsigned char>((*buf)[s]))
172
+ << 8 * s;
173
+ if (++s == sizeof(value)) break;
174
+ }
175
+ buf->remove_prefix(s);
176
+ return value;
177
+ }
178
+
179
+ uint32_t Decode32Bit(absl::Span<const char> *buf) {
180
+ uint32_t value = 0;
181
+ size_t s = 0;
182
+ while (s < buf->size()) {
183
+ value |= static_cast<uint32_t>(static_cast<unsigned char>((*buf)[s]))
184
+ << 8 * s;
185
+ if (++s == sizeof(value)) break;
186
+ }
187
+ buf->remove_prefix(s);
188
+ return value;
189
+ }
190
+ } // namespace
191
+
192
+ bool ProtoField::DecodeFrom(absl::Span<const char> *data) {
193
+ if (data->empty()) return false;
194
+ const uint64_t tag_type = DecodeVarint(data);
195
+ tag_ = tag_type >> 3;
196
+ type_ = static_cast<WireType>(tag_type & 0x07);
197
+ switch (type_) {
198
+ case WireType::kVarint:
199
+ value_ = DecodeVarint(data);
200
+ break;
201
+ case WireType::k64Bit:
202
+ value_ = Decode64Bit(data);
203
+ break;
204
+ case WireType::kLengthDelimited: {
205
+ value_ = DecodeVarint(data);
206
+ data_ = data->subspan(
207
+ 0, static_cast<size_t>(std::min<uint64_t>(value_, data->size())));
208
+ data->remove_prefix(data_.size());
209
+ break;
210
+ }
211
+ case WireType::k32Bit:
212
+ value_ = Decode32Bit(data);
213
+ break;
214
+ }
215
+ return true;
216
+ }
217
+
218
+ } // namespace log_internal
219
+ ABSL_NAMESPACE_END
220
+ } // namespace absl
weight/_dep/abseil-cpp/absl/log/internal/proto.h ADDED
@@ -0,0 +1,288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2020 The Abseil Authors.
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
+ // https://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
+ // File: internal/proto.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // Declares functions for serializing and deserializing data to and from memory
20
+ // buffers in protocol buffer wire format. This library takes no steps to
21
+ // ensure that the encoded data matches with any message specification.
22
+
23
+ #ifndef ABSL_LOG_INTERNAL_PROTO_H_
24
+ #define ABSL_LOG_INTERNAL_PROTO_H_
25
+
26
+ #include <cstddef>
27
+ #include <cstdint>
28
+ #include <limits>
29
+
30
+ #include "absl/base/attributes.h"
31
+ #include "absl/base/casts.h"
32
+ #include "absl/base/config.h"
33
+ #include "absl/strings/string_view.h"
34
+ #include "absl/types/span.h"
35
+
36
+ namespace absl {
37
+ ABSL_NAMESPACE_BEGIN
38
+ namespace log_internal {
39
+
40
+ // absl::Span<char> represents a view into the available space in a mutable
41
+ // buffer during encoding. Encoding functions shrink the span as they go so
42
+ // that the same view can be passed to a series of Encode functions. If the
43
+ // data do not fit, nothing is encoded, the view is set to size zero (so that
44
+ // all subsequent encode calls fail), and false is returned. Otherwise true is
45
+ // returned.
46
+
47
+ // In particular, attempting to encode a series of data into an insufficient
48
+ // buffer has consistent and efficient behavior without any caller-side error
49
+ // checking. Individual values will be encoded in their entirety or not at all
50
+ // (unless one of the `Truncate` functions is used). Once a value is omitted
51
+ // because it does not fit, no subsequent values will be encoded to preserve
52
+ // ordering; the decoded sequence will be a prefix of the original sequence.
53
+
54
+ // There are two ways to encode a message-typed field:
55
+ //
56
+ // * Construct its contents in a separate buffer and use `EncodeBytes` to copy
57
+ // it into the primary buffer with type, tag, and length.
58
+ // * Use `EncodeMessageStart` to write type and tag fields and reserve space for
59
+ // the length field, then encode the contents directly into the buffer, then
60
+ // use `EncodeMessageLength` to write the actual length into the reserved
61
+ // bytes. This works fine if the actual length takes fewer bytes to encode
62
+ // than were reserved, although you don't get your extra bytes back.
63
+ // This approach will always produce a valid encoding, but your protocol may
64
+ // require that the whole message field by omitted if the buffer is too small
65
+ // to contain all desired subfields. In this case, operate on a copy of the
66
+ // buffer view and assign back only if everything fit, i.e. if the last
67
+ // `Encode` call returned true.
68
+
69
+ // Encodes the specified integer as a varint field and returns true if it fits.
70
+ // Used for int32_t, int64_t, uint32_t, uint64_t, bool, and enum field types.
71
+ // Consumes up to kMaxVarintSize * 2 bytes (20).
72
+ bool EncodeVarint(uint64_t tag, uint64_t value, absl::Span<char> *buf);
73
+ inline bool EncodeVarint(uint64_t tag, int64_t value, absl::Span<char> *buf) {
74
+ return EncodeVarint(tag, static_cast<uint64_t>(value), buf);
75
+ }
76
+ inline bool EncodeVarint(uint64_t tag, uint32_t value, absl::Span<char> *buf) {
77
+ return EncodeVarint(tag, static_cast<uint64_t>(value), buf);
78
+ }
79
+ inline bool EncodeVarint(uint64_t tag, int32_t value, absl::Span<char> *buf) {
80
+ return EncodeVarint(tag, static_cast<uint64_t>(value), buf);
81
+ }
82
+
83
+ // Encodes the specified integer as a varint field using ZigZag encoding and
84
+ // returns true if it fits.
85
+ // Used for sint32 and sint64 field types.
86
+ // Consumes up to kMaxVarintSize * 2 bytes (20).
87
+ inline bool EncodeVarintZigZag(uint64_t tag, int64_t value,
88
+ absl::Span<char> *buf) {
89
+ if (value < 0)
90
+ return EncodeVarint(tag, 2 * static_cast<uint64_t>(-(value + 1)) + 1, buf);
91
+ return EncodeVarint(tag, 2 * static_cast<uint64_t>(value), buf);
92
+ }
93
+
94
+ // Encodes the specified integer as a 64-bit field and returns true if it fits.
95
+ // Used for fixed64 and sfixed64 field types.
96
+ // Consumes up to kMaxVarintSize + 8 bytes (18).
97
+ bool Encode64Bit(uint64_t tag, uint64_t value, absl::Span<char> *buf);
98
+ inline bool Encode64Bit(uint64_t tag, int64_t value, absl::Span<char> *buf) {
99
+ return Encode64Bit(tag, static_cast<uint64_t>(value), buf);
100
+ }
101
+ inline bool Encode64Bit(uint64_t tag, uint32_t value, absl::Span<char> *buf) {
102
+ return Encode64Bit(tag, static_cast<uint64_t>(value), buf);
103
+ }
104
+ inline bool Encode64Bit(uint64_t tag, int32_t value, absl::Span<char> *buf) {
105
+ return Encode64Bit(tag, static_cast<uint64_t>(value), buf);
106
+ }
107
+
108
+ // Encodes the specified double as a 64-bit field and returns true if it fits.
109
+ // Used for double field type.
110
+ // Consumes up to kMaxVarintSize + 8 bytes (18).
111
+ inline bool EncodeDouble(uint64_t tag, double value, absl::Span<char> *buf) {
112
+ return Encode64Bit(tag, absl::bit_cast<uint64_t>(value), buf);
113
+ }
114
+
115
+ // Encodes the specified integer as a 32-bit field and returns true if it fits.
116
+ // Used for fixed32 and sfixed32 field types.
117
+ // Consumes up to kMaxVarintSize + 4 bytes (14).
118
+ bool Encode32Bit(uint64_t tag, uint32_t value, absl::Span<char> *buf);
119
+ inline bool Encode32Bit(uint64_t tag, int32_t value, absl::Span<char> *buf) {
120
+ return Encode32Bit(tag, static_cast<uint32_t>(value), buf);
121
+ }
122
+
123
+ // Encodes the specified float as a 32-bit field and returns true if it fits.
124
+ // Used for float field type.
125
+ // Consumes up to kMaxVarintSize + 4 bytes (14).
126
+ inline bool EncodeFloat(uint64_t tag, float value, absl::Span<char> *buf) {
127
+ return Encode32Bit(tag, absl::bit_cast<uint32_t>(value), buf);
128
+ }
129
+
130
+ // Encodes the specified bytes as a length-delimited field and returns true if
131
+ // they fit.
132
+ // Used for string, bytes, message, and packed-repeated field type.
133
+ // Consumes up to kMaxVarintSize * 2 + value.size() bytes (20 + value.size()).
134
+ bool EncodeBytes(uint64_t tag, absl::Span<const char> value,
135
+ absl::Span<char> *buf);
136
+
137
+ // Encodes as many of the specified bytes as will fit as a length-delimited
138
+ // field and returns true as long as the field header (`tag_type` and `length`)
139
+ // fits.
140
+ // Used for string, bytes, message, and packed-repeated field type.
141
+ // Consumes up to kMaxVarintSize * 2 + value.size() bytes (20 + value.size()).
142
+ bool EncodeBytesTruncate(uint64_t tag, absl::Span<const char> value,
143
+ absl::Span<char> *buf);
144
+
145
+ // Encodes the specified string as a length-delimited field and returns true if
146
+ // it fits.
147
+ // Used for string, bytes, message, and packed-repeated field type.
148
+ // Consumes up to kMaxVarintSize * 2 + value.size() bytes (20 + value.size()).
149
+ inline bool EncodeString(uint64_t tag, absl::string_view value,
150
+ absl::Span<char> *buf) {
151
+ return EncodeBytes(tag, value, buf);
152
+ }
153
+
154
+ // Encodes as much of the specified string as will fit as a length-delimited
155
+ // field and returns true as long as the field header (`tag_type` and `length`)
156
+ // fits.
157
+ // Used for string, bytes, message, and packed-repeated field type.
158
+ // Consumes up to kMaxVarintSize * 2 + value.size() bytes (20 + value.size()).
159
+ inline bool EncodeStringTruncate(uint64_t tag, absl::string_view value,
160
+ absl::Span<char> *buf) {
161
+ return EncodeBytesTruncate(tag, value, buf);
162
+ }
163
+
164
+ // Encodes the header for a length-delimited field containing up to `max_size`
165
+ // bytes or the number remaining in the buffer, whichever is less. If the
166
+ // header fits, a non-nullptr `Span` is returned; this must be passed to
167
+ // `EncodeMessageLength` after all contents are encoded to finalize the length
168
+ // field. If the header does not fit, a nullptr `Span` is returned which is
169
+ // safe to pass to `EncodeMessageLength` but need not be.
170
+ // Used for string, bytes, message, and packed-repeated field type.
171
+ // Consumes up to kMaxVarintSize * 2 bytes (20).
172
+ ABSL_MUST_USE_RESULT absl::Span<char> EncodeMessageStart(uint64_t tag,
173
+ uint64_t max_size,
174
+ absl::Span<char> *buf);
175
+
176
+ // Finalizes the length field in `msg` so that it encompasses all data encoded
177
+ // since the call to `EncodeMessageStart` which returned `msg`. Does nothing if
178
+ // `msg` is a `nullptr` `Span`.
179
+ void EncodeMessageLength(absl::Span<char> msg, const absl::Span<char> *buf);
180
+
181
+ enum class WireType : uint64_t {
182
+ kVarint = 0,
183
+ k64Bit = 1,
184
+ kLengthDelimited = 2,
185
+ k32Bit = 5,
186
+ };
187
+
188
+ constexpr size_t VarintSize(uint64_t value) {
189
+ return value < 128 ? 1 : 1 + VarintSize(value >> 7);
190
+ }
191
+ constexpr size_t MinVarintSize() {
192
+ return VarintSize((std::numeric_limits<uint64_t>::min)());
193
+ }
194
+ constexpr size_t MaxVarintSize() {
195
+ return VarintSize((std::numeric_limits<uint64_t>::max)());
196
+ }
197
+
198
+ constexpr uint64_t MaxVarintForSize(size_t size) {
199
+ return size >= 10 ? (std::numeric_limits<uint64_t>::max)()
200
+ : (static_cast<uint64_t>(1) << size * 7) - 1;
201
+ }
202
+
203
+ // `BufferSizeFor` returns a number of bytes guaranteed to be sufficient to
204
+ // store encoded fields of the specified WireTypes regardless of tag numbers and
205
+ // data values. This only makes sense for `WireType::kLengthDelimited` if you
206
+ // add in the length of the contents yourself, e.g. for string and bytes fields
207
+ // by adding the lengths of any encoded strings to the return value or for
208
+ // submessage fields by enumerating the fields you may encode into their
209
+ // contents.
210
+ constexpr size_t BufferSizeFor() { return 0; }
211
+ template <typename... T>
212
+ constexpr size_t BufferSizeFor(WireType type, T... tail) {
213
+ // tag_type + data + ...
214
+ return MaxVarintSize() +
215
+ (type == WireType::kVarint ? MaxVarintSize() : //
216
+ type == WireType::k64Bit ? 8 : //
217
+ type == WireType::k32Bit ? 4 : MaxVarintSize()) + //
218
+ BufferSizeFor(tail...);
219
+ }
220
+
221
+ // absl::Span<const char> represents a view into the un-processed space in a
222
+ // buffer during decoding. Decoding functions shrink the span as they go so
223
+ // that the same view can be decoded iteratively until all data are processed.
224
+ // In general, if the buffer is exhausted but additional bytes are expected by
225
+ // the decoder, it will return values as if the additional bytes were zeros.
226
+ // Length-delimited fields are an exception - if the encoded length field
227
+ // indicates more data bytes than are available in the buffer, the `bytes_value`
228
+ // and `string_value` accessors will return truncated views.
229
+
230
+ class ProtoField final {
231
+ public:
232
+ // Consumes bytes from `data` and returns true if there were any bytes to
233
+ // decode.
234
+ bool DecodeFrom(absl::Span<const char> *data);
235
+ uint64_t tag() const { return tag_; }
236
+ WireType type() const { return type_; }
237
+
238
+ // These value accessors will return nonsense if the data were not encoded in
239
+ // the corresponding wiretype from the corresponding C++ (or other language)
240
+ // type.
241
+
242
+ double double_value() const { return absl::bit_cast<double>(value_); }
243
+ float float_value() const {
244
+ return absl::bit_cast<float>(static_cast<uint32_t>(value_));
245
+ }
246
+ int32_t int32_value() const { return static_cast<int32_t>(value_); }
247
+ int64_t int64_value() const { return static_cast<int64_t>(value_); }
248
+ int32_t sint32_value() const {
249
+ if (value_ % 2) return static_cast<int32_t>(0 - ((value_ - 1) / 2) - 1);
250
+ return static_cast<int32_t>(value_ / 2);
251
+ }
252
+ int64_t sint64_value() const {
253
+ if (value_ % 2) return 0 - ((value_ - 1) / 2) - 1;
254
+ return value_ / 2;
255
+ }
256
+ uint32_t uint32_value() const { return static_cast<uint32_t>(value_); }
257
+ uint64_t uint64_value() const { return value_; }
258
+ bool bool_value() const { return value_ != 0; }
259
+ // To decode an enum, call int32_value() and cast to the appropriate type.
260
+ // Note that the official C++ proto compiler treats enum fields with values
261
+ // that do not correspond to a defined enumerator as unknown fields.
262
+
263
+ // To decode fields within a submessage field, call
264
+ // `DecodeNextField(field.BytesValue())`.
265
+ absl::Span<const char> bytes_value() const { return data_; }
266
+ absl::string_view string_value() const {
267
+ const auto data = bytes_value();
268
+ return absl::string_view(data.data(), data.size());
269
+ }
270
+ // Returns the encoded length of a length-delimited field. This equals
271
+ // `bytes_value().size()` except when the latter has been truncated due to
272
+ // buffer underrun.
273
+ uint64_t encoded_length() const { return value_; }
274
+
275
+ private:
276
+ uint64_t tag_;
277
+ WireType type_;
278
+ // For `kTypeVarint`, `kType64Bit`, and `kType32Bit`, holds the decoded value.
279
+ // For `kTypeLengthDelimited`, holds the decoded length.
280
+ uint64_t value_;
281
+ absl::Span<const char> data_;
282
+ };
283
+
284
+ } // namespace log_internal
285
+ ABSL_NAMESPACE_END
286
+ } // namespace absl
287
+
288
+ #endif // ABSL_LOG_INTERNAL_PROTO_H_
weight/_dep/abseil-cpp/absl/log/internal/stderr_log_sink_test.cc ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //
2
+ // Copyright 2022 The Abseil Authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // https://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+
16
+ #include <stdlib.h>
17
+
18
+ #include <string>
19
+
20
+ #include "gmock/gmock.h"
21
+ #include "gtest/gtest.h"
22
+ #include "absl/base/attributes.h"
23
+ #include "absl/base/log_severity.h"
24
+ #include "absl/log/globals.h"
25
+ #include "absl/log/internal/test_helpers.h"
26
+ #include "absl/log/log.h"
27
+
28
+ namespace {
29
+ using ::testing::AllOf;
30
+ using ::testing::HasSubstr;
31
+
32
+ auto* test_env ABSL_ATTRIBUTE_UNUSED = ::testing::AddGlobalTestEnvironment(
33
+ new absl::log_internal::LogTestEnvironment);
34
+
35
+ MATCHER_P2(HasSubstrTimes, substr, expected_count, "") {
36
+ int count = 0;
37
+ std::string::size_type pos = 0;
38
+ std::string needle(substr);
39
+ while ((pos = arg.find(needle, pos)) != std::string::npos) {
40
+ ++count;
41
+ pos += needle.size();
42
+ }
43
+
44
+ return count == expected_count;
45
+ }
46
+
47
+ TEST(StderrLogSinkDeathTest, InfoMessagesInStderr) {
48
+ EXPECT_DEATH_IF_SUPPORTED(
49
+ {
50
+ absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
51
+ LOG(INFO) << "INFO message";
52
+ exit(1);
53
+ },
54
+ "INFO message");
55
+ }
56
+
57
+ TEST(StderrLogSinkDeathTest, WarningMessagesInStderr) {
58
+ EXPECT_DEATH_IF_SUPPORTED(
59
+ {
60
+ absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
61
+ LOG(WARNING) << "WARNING message";
62
+ exit(1);
63
+ },
64
+ "WARNING message");
65
+ }
66
+
67
+ TEST(StderrLogSinkDeathTest, ErrorMessagesInStderr) {
68
+ EXPECT_DEATH_IF_SUPPORTED(
69
+ {
70
+ absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
71
+ LOG(ERROR) << "ERROR message";
72
+ exit(1);
73
+ },
74
+ "ERROR message");
75
+ }
76
+
77
+ TEST(StderrLogSinkDeathTest, FatalMessagesInStderr) {
78
+ char message[] = "FATAL message";
79
+ char stacktrace[] = "*** Check failure stack trace: ***";
80
+
81
+ int expected_count = 1;
82
+
83
+ EXPECT_DEATH_IF_SUPPORTED(
84
+ {
85
+ absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
86
+ LOG(FATAL) << message;
87
+ },
88
+ AllOf(HasSubstrTimes(message, expected_count), HasSubstr(stacktrace)));
89
+ }
90
+
91
+ TEST(StderrLogSinkDeathTest, SecondaryFatalMessagesInStderr) {
92
+ auto MessageGen = []() -> std::string {
93
+ LOG(FATAL) << "Internal failure";
94
+ return "External failure";
95
+ };
96
+
97
+ EXPECT_DEATH_IF_SUPPORTED(
98
+ {
99
+ absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
100
+ LOG(FATAL) << MessageGen();
101
+ },
102
+ "Internal failure");
103
+ }
104
+
105
+ } // namespace
weight/_dep/abseil-cpp/absl/log/internal/strip.h ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/internal/strip.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+
20
+ #ifndef ABSL_LOG_INTERNAL_STRIP_H_
21
+ #define ABSL_LOG_INTERNAL_STRIP_H_
22
+
23
+ #include "absl/base/log_severity.h"
24
+ #include "absl/log/internal/log_message.h"
25
+ #include "absl/log/internal/nullstream.h"
26
+
27
+ // `ABSL_LOGGING_INTERNAL_LOG_*` evaluates to a temporary `LogMessage` object or
28
+ // to a related object with a compatible API but different behavior. This set
29
+ // of defines comes in three flavors: vanilla, plus two variants that strip some
30
+ // logging in subtly different ways for subtly different reasons (see below).
31
+ #if defined(STRIP_LOG) && STRIP_LOG
32
+ #define ABSL_LOGGING_INTERNAL_LOG_INFO ::absl::log_internal::NullStream()
33
+ #define ABSL_LOGGING_INTERNAL_LOG_WARNING ::absl::log_internal::NullStream()
34
+ #define ABSL_LOGGING_INTERNAL_LOG_ERROR ::absl::log_internal::NullStream()
35
+ #define ABSL_LOGGING_INTERNAL_LOG_FATAL ::absl::log_internal::NullStreamFatal()
36
+ #define ABSL_LOGGING_INTERNAL_LOG_QFATAL ::absl::log_internal::NullStreamFatal()
37
+ #define ABSL_LOGGING_INTERNAL_LOG_DFATAL \
38
+ ::absl::log_internal::NullStreamMaybeFatal(::absl::kLogDebugFatal)
39
+ #define ABSL_LOGGING_INTERNAL_LOG_LEVEL(severity) \
40
+ ::absl::log_internal::NullStreamMaybeFatal(absl_log_internal_severity)
41
+ #define ABSL_LOG_INTERNAL_CHECK(failure_message) ABSL_LOGGING_INTERNAL_LOG_FATAL
42
+ #define ABSL_LOG_INTERNAL_QCHECK(failure_message) \
43
+ ABSL_LOGGING_INTERNAL_LOG_QFATAL
44
+ #else // !defined(STRIP_LOG) || !STRIP_LOG
45
+ #define ABSL_LOGGING_INTERNAL_LOG_INFO \
46
+ ::absl::log_internal::LogMessage( \
47
+ __FILE__, __LINE__, ::absl::log_internal::LogMessage::InfoTag{})
48
+ #define ABSL_LOGGING_INTERNAL_LOG_WARNING \
49
+ ::absl::log_internal::LogMessage( \
50
+ __FILE__, __LINE__, ::absl::log_internal::LogMessage::WarningTag{})
51
+ #define ABSL_LOGGING_INTERNAL_LOG_ERROR \
52
+ ::absl::log_internal::LogMessage( \
53
+ __FILE__, __LINE__, ::absl::log_internal::LogMessage::ErrorTag{})
54
+ #define ABSL_LOGGING_INTERNAL_LOG_FATAL \
55
+ ::absl::log_internal::LogMessageFatal(__FILE__, __LINE__)
56
+ #define ABSL_LOGGING_INTERNAL_LOG_QFATAL \
57
+ ::absl::log_internal::LogMessageQuietlyFatal(__FILE__, __LINE__)
58
+ #define ABSL_LOGGING_INTERNAL_LOG_DFATAL \
59
+ ::absl::log_internal::LogMessage(__FILE__, __LINE__, ::absl::kLogDebugFatal)
60
+ #define ABSL_LOGGING_INTERNAL_LOG_LEVEL(severity) \
61
+ ::absl::log_internal::LogMessage(__FILE__, __LINE__, \
62
+ absl_log_internal_severity)
63
+ // These special cases dispatch to special-case constructors that allow us to
64
+ // avoid an extra function call and shrink non-LTO binaries by a percent or so.
65
+ #define ABSL_LOG_INTERNAL_CHECK(failure_message) \
66
+ ::absl::log_internal::LogMessageFatal(__FILE__, __LINE__, failure_message)
67
+ #define ABSL_LOG_INTERNAL_QCHECK(failure_message) \
68
+ ::absl::log_internal::LogMessageQuietlyFatal(__FILE__, __LINE__, \
69
+ failure_message)
70
+ #endif // !defined(STRIP_LOG) || !STRIP_LOG
71
+
72
+ #endif // ABSL_LOG_INTERNAL_STRIP_H_
weight/_dep/abseil-cpp/absl/log/internal/structured.h ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/internal/structured.h
17
+ // -----------------------------------------------------------------------------
18
+
19
+ #ifndef ABSL_LOG_INTERNAL_STRUCTURED_H_
20
+ #define ABSL_LOG_INTERNAL_STRUCTURED_H_
21
+
22
+ #include <ostream>
23
+
24
+ #include "absl/base/config.h"
25
+ #include "absl/log/internal/log_message.h"
26
+ #include "absl/strings/string_view.h"
27
+
28
+ namespace absl {
29
+ ABSL_NAMESPACE_BEGIN
30
+ namespace log_internal {
31
+
32
+ class ABSL_MUST_USE_RESULT AsLiteralImpl final {
33
+ public:
34
+ explicit AsLiteralImpl(absl::string_view str) : str_(str) {}
35
+ AsLiteralImpl(const AsLiteralImpl&) = default;
36
+ AsLiteralImpl& operator=(const AsLiteralImpl&) = default;
37
+
38
+ private:
39
+ absl::string_view str_;
40
+
41
+ friend std::ostream& operator<<(std::ostream& os, AsLiteralImpl as_literal) {
42
+ return os << as_literal.str_;
43
+ }
44
+ void AddToMessage(log_internal::LogMessage& m) {
45
+ m.CopyToEncodedBuffer<log_internal::LogMessage::StringType::kLiteral>(str_);
46
+ }
47
+ friend log_internal::LogMessage& operator<<(log_internal::LogMessage& m,
48
+ AsLiteralImpl as_literal) {
49
+ as_literal.AddToMessage(m);
50
+ return m;
51
+ }
52
+ };
53
+
54
+ } // namespace log_internal
55
+ ABSL_NAMESPACE_END
56
+ } // namespace absl
57
+
58
+ #endif // ABSL_LOG_INTERNAL_STRUCTURED_H_
weight/_dep/abseil-cpp/absl/log/internal/test_actions.cc ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //
2
+ // Copyright 2022 The Abseil Authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // https://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+
16
+ #include "absl/log/internal/test_actions.h"
17
+
18
+ #include <cassert>
19
+ #include <iostream>
20
+ #include <string>
21
+ #include <type_traits>
22
+
23
+ #include "absl/base/attributes.h"
24
+ #include "absl/base/config.h"
25
+ #include "absl/strings/escaping.h"
26
+ #include "absl/strings/str_cat.h"
27
+ #include "absl/strings/string_view.h"
28
+ #include "absl/time/time.h"
29
+
30
+ namespace absl {
31
+ ABSL_NAMESPACE_BEGIN
32
+ namespace log_internal {
33
+
34
+ void WriteToStderrWithFilename::operator()(const absl::LogEntry& entry) const {
35
+ std::cerr << message << " (file: " << entry.source_filename() << ")\n";
36
+ }
37
+
38
+ void WriteEntryToStderr::operator()(const absl::LogEntry& entry) const {
39
+ if (!message.empty()) std::cerr << message << "\n";
40
+
41
+ const std::string source_filename = absl::CHexEscape(entry.source_filename());
42
+ const std::string source_basename = absl::CHexEscape(entry.source_basename());
43
+ const std::string text_message = absl::CHexEscape(entry.text_message());
44
+ const std::string encoded_message = absl::CHexEscape(entry.encoded_message());
45
+ std::string encoded_message_str;
46
+ std::cerr << "LogEntry{\n" //
47
+ << " source_filename: \"" << source_filename << "\"\n" //
48
+ << " source_basename: \"" << source_basename << "\"\n" //
49
+ << " source_line: " << entry.source_line() << "\n" //
50
+ << " prefix: " << (entry.prefix() ? "true\n" : "false\n") //
51
+ << " log_severity: " << entry.log_severity() << "\n" //
52
+ << " timestamp: " << entry.timestamp() << "\n" //
53
+ << " text_message: \"" << text_message << "\"\n" //
54
+ << " verbosity: " << entry.verbosity() << "\n" //
55
+ << " encoded_message (raw): \"" << encoded_message << "\"\n" //
56
+ << encoded_message_str //
57
+ << "}\n";
58
+ }
59
+
60
+ void WriteEntryToStderr::operator()(absl::LogSeverity severity,
61
+ absl::string_view filename,
62
+ absl::string_view log_message) const {
63
+ if (!message.empty()) std::cerr << message << "\n";
64
+ const std::string source_filename = absl::CHexEscape(filename);
65
+ const std::string text_message = absl::CHexEscape(log_message);
66
+ std::cerr << "LogEntry{\n" //
67
+ << " source_filename: \"" << source_filename << "\"\n" //
68
+ << " log_severity: " << severity << "\n" //
69
+ << " text_message: \"" << text_message << "\"\n" //
70
+ << "}\n";
71
+ }
72
+
73
+ } // namespace log_internal
74
+ ABSL_NAMESPACE_END
75
+ } // namespace absl
weight/_dep/abseil-cpp/absl/log/internal/test_actions.h ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/internal/test_actions.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This file declares Googletest's actions used in the Abseil Logging library
20
+ // unit tests.
21
+
22
+ #ifndef ABSL_LOG_INTERNAL_TEST_ACTIONS_H_
23
+ #define ABSL_LOG_INTERNAL_TEST_ACTIONS_H_
24
+
25
+ #include <iostream>
26
+ #include <ostream>
27
+ #include <string>
28
+
29
+ #include "absl/base/config.h"
30
+ #include "absl/base/log_severity.h"
31
+ #include "absl/log/log_entry.h"
32
+ #include "absl/strings/string_view.h"
33
+
34
+ namespace absl {
35
+ ABSL_NAMESPACE_BEGIN
36
+ namespace log_internal {
37
+
38
+ // These actions are used by the child process in a death test.
39
+ //
40
+ // Expectations set in the child cannot cause test failure in the parent
41
+ // directly. Instead, the child can use these actions with
42
+ // `EXPECT_CALL`/`WillOnce` and `ON_CALL`/`WillByDefault` (for unexpected calls)
43
+ // to write messages to stderr that the parent can match against.
44
+ struct WriteToStderr final {
45
+ explicit WriteToStderr(absl::string_view m) : message(m) {}
46
+ std::string message;
47
+
48
+ template <typename... Args>
49
+ void operator()(const Args&...) const {
50
+ std::cerr << message << std::endl;
51
+ }
52
+ };
53
+
54
+ struct WriteToStderrWithFilename final {
55
+ explicit WriteToStderrWithFilename(absl::string_view m) : message(m) {}
56
+
57
+ std::string message;
58
+
59
+ void operator()(const absl::LogEntry& entry) const;
60
+ };
61
+
62
+ struct WriteEntryToStderr final {
63
+ explicit WriteEntryToStderr(absl::string_view m) : message(m) {}
64
+
65
+ std::string message = "";
66
+
67
+ void operator()(const absl::LogEntry& entry) const;
68
+ void operator()(absl::LogSeverity, absl::string_view,
69
+ absl::string_view) const;
70
+ };
71
+
72
+ // See the documentation for `DeathTestValidateExpectations` above.
73
+ // `DeathTestExpectedLogging` should be used once in a given death test, and the
74
+ // applicable severity level is the one that should be passed to
75
+ // `DeathTestValidateExpectations`.
76
+ inline WriteEntryToStderr DeathTestExpectedLogging() {
77
+ return WriteEntryToStderr{"Mock received expected entry:"};
78
+ }
79
+
80
+ // `DeathTestUnexpectedLogging` should be used zero or more times to mark
81
+ // messages that should not hit the logs as the process dies.
82
+ inline WriteEntryToStderr DeathTestUnexpectedLogging() {
83
+ return WriteEntryToStderr{"Mock received unexpected entry:"};
84
+ }
85
+
86
+ } // namespace log_internal
87
+ ABSL_NAMESPACE_END
88
+ } // namespace absl
89
+
90
+ #endif // ABSL_LOG_INTERNAL_TEST_ACTIONS_H_
weight/_dep/abseil-cpp/absl/log/internal/test_helpers.cc ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ #include "absl/log/internal/test_helpers.h"
16
+
17
+ #ifdef __Fuchsia__
18
+ #include <zircon/syscalls.h>
19
+ #endif
20
+
21
+ #include "gtest/gtest.h"
22
+ #include "absl/base/config.h"
23
+ #include "absl/base/log_severity.h"
24
+ #include "absl/log/globals.h"
25
+ #include "absl/log/initialize.h"
26
+ #include "absl/log/internal/globals.h"
27
+
28
+ namespace absl {
29
+ ABSL_NAMESPACE_BEGIN
30
+ namespace log_internal {
31
+
32
+ // Returns false if the specified severity level is disabled by
33
+ // `ABSL_MIN_LOG_LEVEL` or `absl::MinLogLevel()`.
34
+ bool LoggingEnabledAt(absl::LogSeverity severity) {
35
+ return severity >= kAbslMinLogLevel && severity >= absl::MinLogLevel();
36
+ }
37
+
38
+ // -----------------------------------------------------------------------------
39
+ // Googletest Death Test Predicates
40
+ // -----------------------------------------------------------------------------
41
+
42
+ #if GTEST_HAS_DEATH_TEST
43
+
44
+ bool DiedOfFatal(int exit_status) {
45
+ #if defined(_WIN32)
46
+ // Depending on NDEBUG and (configuration?) MSVC's abort either results
47
+ // in error code 3 (SIGABRT) or error code 0x80000003 (breakpoint
48
+ // triggered).
49
+ return ::testing::ExitedWithCode(3)(exit_status & 0x7fffffff);
50
+ #elif defined(__Fuchsia__)
51
+ // The Fuchsia death test implementation kill()'s the process when it detects
52
+ // an exception, so it should exit with the corresponding code. See
53
+ // FuchsiaDeathTest::Wait().
54
+ return ::testing::ExitedWithCode(ZX_TASK_RETCODE_SYSCALL_KILL)(exit_status);
55
+ #elif defined(__ANDROID__) && defined(__aarch64__)
56
+ // These are all run under a qemu config that eats died-due-to-signal exit
57
+ // statuses.
58
+ return true;
59
+ #else
60
+ return ::testing::KilledBySignal(SIGABRT)(exit_status);
61
+ #endif
62
+ }
63
+
64
+ bool DiedOfQFatal(int exit_status) {
65
+ return ::testing::ExitedWithCode(1)(exit_status);
66
+ }
67
+
68
+ #endif
69
+
70
+ // -----------------------------------------------------------------------------
71
+ // Helper for Log initialization in test
72
+ // -----------------------------------------------------------------------------
73
+
74
+ void LogTestEnvironment::SetUp() {
75
+ if (!absl::log_internal::IsInitialized()) {
76
+ absl::InitializeLog();
77
+ }
78
+ }
79
+
80
+ } // namespace log_internal
81
+ ABSL_NAMESPACE_END
82
+ } // namespace absl
weight/_dep/abseil-cpp/absl/log/internal/test_helpers.h ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/internal/test_helpers.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This file declares testing helpers for the logging library.
20
+
21
+ #ifndef ABSL_LOG_INTERNAL_TEST_HELPERS_H_
22
+ #define ABSL_LOG_INTERNAL_TEST_HELPERS_H_
23
+
24
+ #include "gtest/gtest.h"
25
+ #include "absl/base/config.h"
26
+ #include "absl/base/log_severity.h"
27
+ #include "absl/log/globals.h"
28
+
29
+ namespace absl {
30
+ ABSL_NAMESPACE_BEGIN
31
+ namespace log_internal {
32
+
33
+ // `ABSL_MIN_LOG_LEVEL` can't be used directly since it is not always defined.
34
+ constexpr auto kAbslMinLogLevel =
35
+ #ifdef ABSL_MIN_LOG_LEVEL
36
+ static_cast<absl::LogSeverityAtLeast>(ABSL_MIN_LOG_LEVEL);
37
+ #else
38
+ absl::LogSeverityAtLeast::kInfo;
39
+ #endif
40
+
41
+ // Returns false if the specified severity level is disabled by
42
+ // `ABSL_MIN_LOG_LEVEL` or `absl::MinLogLevel()`.
43
+ bool LoggingEnabledAt(absl::LogSeverity severity);
44
+
45
+ // -----------------------------------------------------------------------------
46
+ // Googletest Death Test Predicates
47
+ // -----------------------------------------------------------------------------
48
+
49
+ #if GTEST_HAS_DEATH_TEST
50
+
51
+ bool DiedOfFatal(int exit_status);
52
+ bool DiedOfQFatal(int exit_status);
53
+
54
+ #endif
55
+
56
+ // -----------------------------------------------------------------------------
57
+ // Helper for Log initialization in test
58
+ // -----------------------------------------------------------------------------
59
+
60
+ class LogTestEnvironment : public ::testing::Environment {
61
+ public:
62
+ ~LogTestEnvironment() override = default;
63
+
64
+ void SetUp() override;
65
+ };
66
+
67
+ } // namespace log_internal
68
+ ABSL_NAMESPACE_END
69
+ } // namespace absl
70
+
71
+ #endif // ABSL_LOG_INTERNAL_TEST_HELPERS_H_
weight/_dep/abseil-cpp/absl/log/internal/test_matchers.cc ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //
2
+ // Copyright 2022 The Abseil Authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // https://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+
16
+ #include "absl/log/internal/test_matchers.h"
17
+
18
+ #include <ostream>
19
+ #include <sstream>
20
+ #include <string>
21
+ #include <type_traits>
22
+ #include <utility>
23
+
24
+ #include "gmock/gmock.h"
25
+ #include "gtest/gtest.h"
26
+ #include "absl/base/attributes.h"
27
+ #include "absl/base/config.h"
28
+ #include "absl/log/internal/test_helpers.h"
29
+ #include "absl/strings/string_view.h"
30
+ #include "absl/time/clock.h"
31
+ #include "absl/time/time.h"
32
+
33
+ namespace absl {
34
+ ABSL_NAMESPACE_BEGIN
35
+ namespace log_internal {
36
+ namespace {
37
+ using ::testing::_;
38
+ using ::testing::AllOf;
39
+ using ::testing::Ge;
40
+ using ::testing::HasSubstr;
41
+ using ::testing::MakeMatcher;
42
+ using ::testing::Matcher;
43
+ using ::testing::MatcherInterface;
44
+ using ::testing::MatchResultListener;
45
+ using ::testing::Not;
46
+ using ::testing::Property;
47
+ using ::testing::ResultOf;
48
+ using ::testing::Truly;
49
+
50
+ class AsStringImpl final
51
+ : public MatcherInterface<absl::string_view> {
52
+ public:
53
+ explicit AsStringImpl(
54
+ const Matcher<const std::string&>& str_matcher)
55
+ : str_matcher_(str_matcher) {}
56
+ bool MatchAndExplain(
57
+ absl::string_view actual,
58
+ MatchResultListener* listener) const override {
59
+ return str_matcher_.MatchAndExplain(std::string(actual), listener);
60
+ }
61
+ void DescribeTo(std::ostream* os) const override {
62
+ return str_matcher_.DescribeTo(os);
63
+ }
64
+
65
+ void DescribeNegationTo(std::ostream* os) const override {
66
+ return str_matcher_.DescribeNegationTo(os);
67
+ }
68
+
69
+ private:
70
+ const Matcher<const std::string&> str_matcher_;
71
+ };
72
+
73
+ class MatchesOstreamImpl final
74
+ : public MatcherInterface<absl::string_view> {
75
+ public:
76
+ explicit MatchesOstreamImpl(std::string expected)
77
+ : expected_(std::move(expected)) {}
78
+ bool MatchAndExplain(absl::string_view actual,
79
+ MatchResultListener*) const override {
80
+ return actual == expected_;
81
+ }
82
+ void DescribeTo(std::ostream* os) const override {
83
+ *os << "matches the contents of the ostringstream, which are \""
84
+ << expected_ << "\"";
85
+ }
86
+
87
+ void DescribeNegationTo(std::ostream* os) const override {
88
+ *os << "does not match the contents of the ostringstream, which are \""
89
+ << expected_ << "\"";
90
+ }
91
+
92
+ private:
93
+ const std::string expected_;
94
+ };
95
+ } // namespace
96
+
97
+ Matcher<absl::string_view> AsString(
98
+ const Matcher<const std::string&>& str_matcher) {
99
+ return MakeMatcher(new AsStringImpl(str_matcher));
100
+ }
101
+
102
+ Matcher<const absl::LogEntry&> SourceFilename(
103
+ const Matcher<absl::string_view>& source_filename) {
104
+ return Property("source_filename", &absl::LogEntry::source_filename,
105
+ source_filename);
106
+ }
107
+
108
+ Matcher<const absl::LogEntry&> SourceBasename(
109
+ const Matcher<absl::string_view>& source_basename) {
110
+ return Property("source_basename", &absl::LogEntry::source_basename,
111
+ source_basename);
112
+ }
113
+
114
+ Matcher<const absl::LogEntry&> SourceLine(
115
+ const Matcher<int>& source_line) {
116
+ return Property("source_line", &absl::LogEntry::source_line, source_line);
117
+ }
118
+
119
+ Matcher<const absl::LogEntry&> Prefix(
120
+ const Matcher<bool>& prefix) {
121
+ return Property("prefix", &absl::LogEntry::prefix, prefix);
122
+ }
123
+
124
+ Matcher<const absl::LogEntry&> LogSeverity(
125
+ const Matcher<absl::LogSeverity>& log_severity) {
126
+ return Property("log_severity", &absl::LogEntry::log_severity, log_severity);
127
+ }
128
+
129
+ Matcher<const absl::LogEntry&> Timestamp(
130
+ const Matcher<absl::Time>& timestamp) {
131
+ return Property("timestamp", &absl::LogEntry::timestamp, timestamp);
132
+ }
133
+
134
+ Matcher<const absl::LogEntry&> TimestampInMatchWindow() {
135
+ return Property("timestamp", &absl::LogEntry::timestamp,
136
+ AllOf(Ge(absl::Now()), Truly([](absl::Time arg) {
137
+ return arg <= absl::Now();
138
+ })));
139
+ }
140
+
141
+ Matcher<const absl::LogEntry&> ThreadID(
142
+ const Matcher<absl::LogEntry::tid_t>& tid) {
143
+ return Property("tid", &absl::LogEntry::tid, tid);
144
+ }
145
+
146
+ Matcher<const absl::LogEntry&> TextMessageWithPrefixAndNewline(
147
+ const Matcher<absl::string_view>&
148
+ text_message_with_prefix_and_newline) {
149
+ return Property("text_message_with_prefix_and_newline",
150
+ &absl::LogEntry::text_message_with_prefix_and_newline,
151
+ text_message_with_prefix_and_newline);
152
+ }
153
+
154
+ Matcher<const absl::LogEntry&> TextMessageWithPrefix(
155
+ const Matcher<absl::string_view>& text_message_with_prefix) {
156
+ return Property("text_message_with_prefix",
157
+ &absl::LogEntry::text_message_with_prefix,
158
+ text_message_with_prefix);
159
+ }
160
+
161
+ Matcher<const absl::LogEntry&> TextMessage(
162
+ const Matcher<absl::string_view>& text_message) {
163
+ return Property("text_message", &absl::LogEntry::text_message, text_message);
164
+ }
165
+
166
+ Matcher<const absl::LogEntry&> TextPrefix(
167
+ const Matcher<absl::string_view>& text_prefix) {
168
+ return ResultOf(
169
+ [](const absl::LogEntry& entry) {
170
+ absl::string_view msg = entry.text_message_with_prefix();
171
+ msg.remove_suffix(entry.text_message().size());
172
+ return msg;
173
+ },
174
+ text_prefix);
175
+ }
176
+ Matcher<const absl::LogEntry&> RawEncodedMessage(
177
+ const Matcher<absl::string_view>& raw_encoded_message) {
178
+ return Property("encoded_message", &absl::LogEntry::encoded_message,
179
+ raw_encoded_message);
180
+ }
181
+
182
+ Matcher<const absl::LogEntry&> Verbosity(
183
+ const Matcher<int>& verbosity) {
184
+ return Property("verbosity", &absl::LogEntry::verbosity, verbosity);
185
+ }
186
+
187
+ Matcher<const absl::LogEntry&> Stacktrace(
188
+ const Matcher<absl::string_view>& stacktrace) {
189
+ return Property("stacktrace", &absl::LogEntry::stacktrace, stacktrace);
190
+ }
191
+
192
+ Matcher<absl::string_view> MatchesOstream(
193
+ const std::ostringstream& stream) {
194
+ return MakeMatcher(new MatchesOstreamImpl(stream.str()));
195
+ }
196
+
197
+ // We need to validate what is and isn't logged as the process dies due to
198
+ // `FATAL`, `QFATAL`, `CHECK`, etc., but assertions inside a death test
199
+ // subprocess don't directly affect the pass/fail status of the parent process.
200
+ // Instead, we use the mock actions `DeathTestExpectedLogging` and
201
+ // `DeathTestUnexpectedLogging` to write specific phrases to `stderr` that we
202
+ // can validate in the parent process using this matcher.
203
+ Matcher<const std::string&> DeathTestValidateExpectations() {
204
+ if (log_internal::LoggingEnabledAt(absl::LogSeverity::kFatal)) {
205
+ return Matcher<const std::string&>(
206
+ AllOf(HasSubstr("Mock received expected entry"),
207
+ Not(HasSubstr("Mock received unexpected entry"))));
208
+ }
209
+ // If `FATAL` logging is disabled, neither message should have been written.
210
+ return Matcher<const std::string&>(
211
+ AllOf(Not(HasSubstr("Mock received expected entry")),
212
+ Not(HasSubstr("Mock received unexpected entry"))));
213
+ }
214
+
215
+ } // namespace log_internal
216
+ ABSL_NAMESPACE_END
217
+ } // namespace absl
weight/_dep/abseil-cpp/absl/log/internal/test_matchers.h ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/internal/test_matchers.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This file declares Googletest's matchers used in the Abseil Logging library
20
+ // unit tests.
21
+
22
+ #ifndef ABSL_LOG_INTERNAL_TEST_MATCHERS_H_
23
+ #define ABSL_LOG_INTERNAL_TEST_MATCHERS_H_
24
+
25
+ #include <iosfwd>
26
+ #include <sstream>
27
+ #include <string>
28
+
29
+ #include "gmock/gmock.h"
30
+ #include "gtest/gtest.h"
31
+ #include "absl/base/config.h"
32
+ #include "absl/base/log_severity.h"
33
+ #include "absl/log/internal/test_helpers.h"
34
+ #include "absl/log/log_entry.h"
35
+ #include "absl/strings/string_view.h"
36
+ #include "absl/time/time.h"
37
+
38
+ namespace absl {
39
+ ABSL_NAMESPACE_BEGIN
40
+ namespace log_internal {
41
+ // In some configurations, Googletest's string matchers (e.g.
42
+ // `::testing::EndsWith`) need help to match `absl::string_view`.
43
+ ::testing::Matcher<absl::string_view> AsString(
44
+ const ::testing::Matcher<const std::string&>& str_matcher);
45
+
46
+ // These matchers correspond to the components of `absl::LogEntry`.
47
+ ::testing::Matcher<const absl::LogEntry&> SourceFilename(
48
+ const ::testing::Matcher<absl::string_view>& source_filename);
49
+ ::testing::Matcher<const absl::LogEntry&> SourceBasename(
50
+ const ::testing::Matcher<absl::string_view>& source_basename);
51
+ // Be careful with this one; multi-line statements using `__LINE__` evaluate
52
+ // differently on different platforms. In particular, the MSVC implementation
53
+ // of `EXPECT_DEATH` returns the line number of the macro expansion to all lines
54
+ // within the code block that's expected to die.
55
+ ::testing::Matcher<const absl::LogEntry&> SourceLine(
56
+ const ::testing::Matcher<int>& source_line);
57
+ ::testing::Matcher<const absl::LogEntry&> Prefix(
58
+ const ::testing::Matcher<bool>& prefix);
59
+ ::testing::Matcher<const absl::LogEntry&> LogSeverity(
60
+ const ::testing::Matcher<absl::LogSeverity>& log_severity);
61
+ ::testing::Matcher<const absl::LogEntry&> Timestamp(
62
+ const ::testing::Matcher<absl::Time>& timestamp);
63
+ // Matches if the `LogEntry`'s timestamp falls after the instantiation of this
64
+ // matcher and before its execution, as is normal when used with EXPECT_CALL.
65
+ ::testing::Matcher<const absl::LogEntry&> TimestampInMatchWindow();
66
+ ::testing::Matcher<const absl::LogEntry&> ThreadID(
67
+ const ::testing::Matcher<absl::LogEntry::tid_t>&);
68
+ ::testing::Matcher<const absl::LogEntry&> TextMessageWithPrefixAndNewline(
69
+ const ::testing::Matcher<absl::string_view>&
70
+ text_message_with_prefix_and_newline);
71
+ ::testing::Matcher<const absl::LogEntry&> TextMessageWithPrefix(
72
+ const ::testing::Matcher<absl::string_view>& text_message_with_prefix);
73
+ ::testing::Matcher<const absl::LogEntry&> TextMessage(
74
+ const ::testing::Matcher<absl::string_view>& text_message);
75
+ ::testing::Matcher<const absl::LogEntry&> TextPrefix(
76
+ const ::testing::Matcher<absl::string_view>& text_prefix);
77
+ ::testing::Matcher<const absl::LogEntry&> Verbosity(
78
+ const ::testing::Matcher<int>& verbosity);
79
+ ::testing::Matcher<const absl::LogEntry&> Stacktrace(
80
+ const ::testing::Matcher<absl::string_view>& stacktrace);
81
+ // Behaves as `Eq(stream.str())`, but produces better failure messages.
82
+ ::testing::Matcher<absl::string_view> MatchesOstream(
83
+ const std::ostringstream& stream);
84
+ ::testing::Matcher<const std::string&> DeathTestValidateExpectations();
85
+
86
+ ::testing::Matcher<const absl::LogEntry&> RawEncodedMessage(
87
+ const ::testing::Matcher<absl::string_view>& raw_encoded_message);
88
+ #define ENCODED_MESSAGE(message_matcher) ::testing::_
89
+
90
+ } // namespace log_internal
91
+ ABSL_NAMESPACE_END
92
+ } // namespace absl
93
+
94
+ #endif // ABSL_LOG_INTERNAL_TEST_MATCHERS_H_
weight/_dep/abseil-cpp/absl/log/internal/vlog_config.cc ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors
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
+ // https://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
+ #include "absl/log/internal/vlog_config.h"
16
+
17
+ #include <stddef.h>
18
+
19
+ #include <algorithm>
20
+ #include <atomic>
21
+ #include <functional>
22
+ #include <memory>
23
+ #include <string>
24
+ #include <utility>
25
+ #include <vector>
26
+
27
+ #include "absl/base/attributes.h"
28
+ #include "absl/base/config.h"
29
+ #include "absl/base/const_init.h"
30
+ #include "absl/base/internal/spinlock.h"
31
+ #include "absl/base/no_destructor.h"
32
+ #include "absl/base/optimization.h"
33
+ #include "absl/base/thread_annotations.h"
34
+ #include "absl/log/internal/fnmatch.h"
35
+ #include "absl/memory/memory.h"
36
+ #include "absl/strings/numbers.h"
37
+ #include "absl/strings/str_split.h"
38
+ #include "absl/strings/string_view.h"
39
+ #include "absl/strings/strip.h"
40
+ #include "absl/synchronization/mutex.h"
41
+ #include "absl/types/optional.h"
42
+
43
+ namespace absl {
44
+ ABSL_NAMESPACE_BEGIN
45
+ namespace log_internal {
46
+
47
+ namespace {
48
+ bool ModuleIsPath(absl::string_view module_pattern) {
49
+ #ifdef _WIN32
50
+ return module_pattern.find_first_of("/\\") != module_pattern.npos;
51
+ #else
52
+ return module_pattern.find('/') != module_pattern.npos;
53
+ #endif
54
+ }
55
+ } // namespace
56
+
57
+ bool VLogSite::SlowIsEnabled(int stale_v, int level) {
58
+ if (ABSL_PREDICT_TRUE(stale_v != kUninitialized)) {
59
+ // Because of the prerequisites to this function, we know that stale_v is
60
+ // either uninitialized or >= level. If it's not uninitialized, that means
61
+ // it must be >= level, thus we should log.
62
+ return true;
63
+ }
64
+ stale_v = log_internal::RegisterAndInitialize(this);
65
+ return ABSL_PREDICT_FALSE(stale_v >= level);
66
+ }
67
+
68
+ bool VLogSite::SlowIsEnabled0(int stale_v) { return SlowIsEnabled(stale_v, 0); }
69
+ bool VLogSite::SlowIsEnabled1(int stale_v) { return SlowIsEnabled(stale_v, 1); }
70
+ bool VLogSite::SlowIsEnabled2(int stale_v) { return SlowIsEnabled(stale_v, 2); }
71
+ bool VLogSite::SlowIsEnabled3(int stale_v) { return SlowIsEnabled(stale_v, 3); }
72
+ bool VLogSite::SlowIsEnabled4(int stale_v) { return SlowIsEnabled(stale_v, 4); }
73
+ bool VLogSite::SlowIsEnabled5(int stale_v) { return SlowIsEnabled(stale_v, 5); }
74
+
75
+ namespace {
76
+ struct VModuleInfo final {
77
+ std::string module_pattern;
78
+ bool module_is_path; // i.e. it contains a path separator.
79
+ int vlog_level;
80
+
81
+ // Allocates memory.
82
+ VModuleInfo(absl::string_view module_pattern_arg, bool module_is_path_arg,
83
+ int vlog_level_arg)
84
+ : module_pattern(std::string(module_pattern_arg)),
85
+ module_is_path(module_is_path_arg),
86
+ vlog_level(vlog_level_arg) {}
87
+ };
88
+
89
+ // `mutex` guards all of the data structures that aren't lock-free.
90
+ // To avoid problems with the heap checker which calls into `VLOG`, `mutex` must
91
+ // be a `SpinLock` that prevents fiber scheduling instead of a `Mutex`.
92
+ ABSL_CONST_INIT absl::base_internal::SpinLock mutex(
93
+ absl::kConstInit, absl::base_internal::SCHEDULE_KERNEL_ONLY);
94
+
95
+ // `GetUpdateSitesMutex()` serializes updates to all of the sites (i.e. those in
96
+ // `site_list_head`) themselves.
97
+ absl::Mutex* GetUpdateSitesMutex() {
98
+ // Chromium requires no global destructors, so we can't use the
99
+ // absl::kConstInit idiom since absl::Mutex as a non-trivial destructor.
100
+ static absl::NoDestructor<absl::Mutex> update_sites_mutex ABSL_ACQUIRED_AFTER(
101
+ mutex);
102
+ return update_sites_mutex.get();
103
+ }
104
+
105
+ ABSL_CONST_INIT int global_v ABSL_GUARDED_BY(mutex) = 0;
106
+ // `site_list_head` is the head of a singly-linked list. Traversal, insertion,
107
+ // and reads are atomic, so no locks are required, but updates to existing
108
+ // elements are guarded by `GetUpdateSitesMutex()`.
109
+ ABSL_CONST_INIT std::atomic<VLogSite*> site_list_head{nullptr};
110
+ ABSL_CONST_INIT std::vector<VModuleInfo>* vmodule_info ABSL_GUARDED_BY(mutex)
111
+ ABSL_PT_GUARDED_BY(mutex){nullptr};
112
+
113
+ // Only used for lisp.
114
+ ABSL_CONST_INIT std::vector<std::function<void()>>* update_callbacks
115
+ ABSL_GUARDED_BY(GetUpdateSitesMutex())
116
+ ABSL_PT_GUARDED_BY(GetUpdateSitesMutex()){nullptr};
117
+
118
+ // Allocates memory.
119
+ std::vector<VModuleInfo>& get_vmodule_info()
120
+ ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex) {
121
+ if (!vmodule_info) vmodule_info = new std::vector<VModuleInfo>;
122
+ return *vmodule_info;
123
+ }
124
+
125
+ // Does not allocate or take locks.
126
+ int VLogLevel(absl::string_view file, const std::vector<VModuleInfo>* infos,
127
+ int current_global_v) {
128
+ // `infos` is null during a call to `VLOG` prior to setting `vmodule` (e.g. by
129
+ // parsing flags). We can't allocate in `VLOG`, so we treat null as empty
130
+ // here and press on.
131
+ if (!infos || infos->empty()) return current_global_v;
132
+ // Get basename for file
133
+ absl::string_view basename = file;
134
+ {
135
+ const size_t sep = basename.rfind('/');
136
+ if (sep != basename.npos) {
137
+ basename.remove_prefix(sep + 1);
138
+ #ifdef _WIN32
139
+ } else {
140
+ const size_t sep = basename.rfind('\\');
141
+ if (sep != basename.npos) basename.remove_prefix(sep + 1);
142
+ #endif
143
+ }
144
+ }
145
+
146
+ absl::string_view stem = file, stem_basename = basename;
147
+ {
148
+ const size_t sep = stem_basename.find('.');
149
+ if (sep != stem_basename.npos) {
150
+ stem.remove_suffix(stem_basename.size() - sep);
151
+ stem_basename.remove_suffix(stem_basename.size() - sep);
152
+ }
153
+ if (absl::ConsumeSuffix(&stem_basename, "-inl")) {
154
+ stem.remove_suffix(absl::string_view("-inl").size());
155
+ }
156
+ }
157
+ for (const auto& info : *infos) {
158
+ if (info.module_is_path) {
159
+ // If there are any slashes in the pattern, try to match the full
160
+ // name.
161
+ if (FNMatch(info.module_pattern, stem)) {
162
+ return info.vlog_level == kUseFlag ? current_global_v : info.vlog_level;
163
+ }
164
+ } else if (FNMatch(info.module_pattern, stem_basename)) {
165
+ return info.vlog_level == kUseFlag ? current_global_v : info.vlog_level;
166
+ }
167
+ }
168
+
169
+ return current_global_v;
170
+ }
171
+
172
+ // Allocates memory.
173
+ int AppendVModuleLocked(absl::string_view module_pattern, int log_level)
174
+ ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex) {
175
+ for (const auto& info : get_vmodule_info()) {
176
+ if (FNMatch(info.module_pattern, module_pattern)) {
177
+ // This is a memory optimization to avoid storing patterns that will never
178
+ // match due to exit early semantics. Primarily optimized for our own unit
179
+ // tests.
180
+ return info.vlog_level;
181
+ }
182
+ }
183
+ bool module_is_path = ModuleIsPath(module_pattern);
184
+ get_vmodule_info().emplace_back(std::string(module_pattern), module_is_path,
185
+ log_level);
186
+ return global_v;
187
+ }
188
+
189
+ // Allocates memory.
190
+ int PrependVModuleLocked(absl::string_view module_pattern, int log_level)
191
+ ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex) {
192
+ absl::optional<int> old_log_level;
193
+ for (const auto& info : get_vmodule_info()) {
194
+ if (FNMatch(info.module_pattern, module_pattern)) {
195
+ old_log_level = info.vlog_level;
196
+ break;
197
+ }
198
+ }
199
+ bool module_is_path = ModuleIsPath(module_pattern);
200
+ auto iter = get_vmodule_info().emplace(get_vmodule_info().cbegin(),
201
+ std::string(module_pattern),
202
+ module_is_path, log_level);
203
+
204
+ // This is a memory optimization to avoid storing patterns that will never
205
+ // match due to exit early semantics. Primarily optimized for our own unit
206
+ // tests.
207
+ get_vmodule_info().erase(
208
+ std::remove_if(++iter, get_vmodule_info().end(),
209
+ [module_pattern](const VModuleInfo& info) {
210
+ return FNMatch(info.module_pattern, module_pattern);
211
+ }),
212
+ get_vmodule_info().cend());
213
+ return old_log_level.value_or(global_v);
214
+ }
215
+ } // namespace
216
+
217
+ int VLogLevel(absl::string_view file) ABSL_LOCKS_EXCLUDED(mutex) {
218
+ absl::base_internal::SpinLockHolder l(&mutex);
219
+ return VLogLevel(file, vmodule_info, global_v);
220
+ }
221
+
222
+ int RegisterAndInitialize(VLogSite* v) ABSL_LOCKS_EXCLUDED(mutex) {
223
+ // std::memory_order_seq_cst is overkill in this function, but given that this
224
+ // path is intended to be slow, it's not worth the brain power to relax that.
225
+ VLogSite* h = site_list_head.load(std::memory_order_seq_cst);
226
+
227
+ VLogSite* old = nullptr;
228
+ if (v->next_.compare_exchange_strong(old, h, std::memory_order_seq_cst,
229
+ std::memory_order_seq_cst)) {
230
+ // Multiple threads may attempt to register this site concurrently.
231
+ // By successfully setting `v->next` this thread commits to being *the*
232
+ // thread that installs `v` in the list.
233
+ while (!site_list_head.compare_exchange_weak(
234
+ h, v, std::memory_order_seq_cst, std::memory_order_seq_cst)) {
235
+ v->next_.store(h, std::memory_order_seq_cst);
236
+ }
237
+ }
238
+
239
+ int old_v = VLogSite::kUninitialized;
240
+ int new_v = VLogLevel(v->file_);
241
+ // No loop, if someone else set this, we should respect their evaluation of
242
+ // `VLogLevel`. This may mean we return a stale `v`, but `v` itself will
243
+ // always arrive at the freshest value. Otherwise, we could be writing a
244
+ // stale value and clobbering the fresher one.
245
+ if (v->v_.compare_exchange_strong(old_v, new_v, std::memory_order_seq_cst,
246
+ std::memory_order_seq_cst)) {
247
+ return new_v;
248
+ }
249
+ return old_v;
250
+ }
251
+
252
+ void UpdateVLogSites() ABSL_UNLOCK_FUNCTION(mutex)
253
+ ABSL_LOCKS_EXCLUDED(GetUpdateSitesMutex()) {
254
+ std::vector<VModuleInfo> infos = get_vmodule_info();
255
+ int current_global_v = global_v;
256
+ // We need to grab `GetUpdateSitesMutex()` before we release `mutex` to ensure
257
+ // that updates are not interleaved (resulting in an inconsistent final state)
258
+ // and to ensure that the final state in the sites matches the final state of
259
+ // `vmodule_info`. We unlock `mutex` to ensure that uninitialized sites don't
260
+ // have to wait on all updates in order to acquire `mutex` and initialize
261
+ // themselves.
262
+ absl::MutexLock ul(GetUpdateSitesMutex());
263
+ mutex.Unlock();
264
+ VLogSite* n = site_list_head.load(std::memory_order_seq_cst);
265
+ // Because sites are added to the list in the order they are executed, there
266
+ // tend to be clusters of entries with the same file.
267
+ const char* last_file = nullptr;
268
+ int last_file_level = 0;
269
+ while (n != nullptr) {
270
+ if (n->file_ != last_file) {
271
+ last_file = n->file_;
272
+ last_file_level = VLogLevel(n->file_, &infos, current_global_v);
273
+ }
274
+ n->v_.store(last_file_level, std::memory_order_seq_cst);
275
+ n = n->next_.load(std::memory_order_seq_cst);
276
+ }
277
+ if (update_callbacks) {
278
+ for (auto& cb : *update_callbacks) {
279
+ cb();
280
+ }
281
+ }
282
+ }
283
+
284
+ void UpdateVModule(absl::string_view vmodule)
285
+ ABSL_LOCKS_EXCLUDED(mutex, GetUpdateSitesMutex()) {
286
+ std::vector<std::pair<absl::string_view, int>> glob_levels;
287
+ for (absl::string_view glob_level : absl::StrSplit(vmodule, ',')) {
288
+ const size_t eq = glob_level.rfind('=');
289
+ if (eq == glob_level.npos) continue;
290
+ const absl::string_view glob = glob_level.substr(0, eq);
291
+ int level;
292
+ if (!absl::SimpleAtoi(glob_level.substr(eq + 1), &level)) continue;
293
+ glob_levels.emplace_back(glob, level);
294
+ }
295
+ mutex.Lock(); // Unlocked by UpdateVLogSites().
296
+ get_vmodule_info().clear();
297
+ for (const auto& it : glob_levels) {
298
+ const absl::string_view glob = it.first;
299
+ const int level = it.second;
300
+ AppendVModuleLocked(glob, level);
301
+ }
302
+ UpdateVLogSites();
303
+ }
304
+
305
+ int UpdateGlobalVLogLevel(int v)
306
+ ABSL_LOCKS_EXCLUDED(mutex, GetUpdateSitesMutex()) {
307
+ mutex.Lock(); // Unlocked by UpdateVLogSites().
308
+ const int old_global_v = global_v;
309
+ if (v == global_v) {
310
+ mutex.Unlock();
311
+ return old_global_v;
312
+ }
313
+ global_v = v;
314
+ UpdateVLogSites();
315
+ return old_global_v;
316
+ }
317
+
318
+ int PrependVModule(absl::string_view module_pattern, int log_level)
319
+ ABSL_LOCKS_EXCLUDED(mutex, GetUpdateSitesMutex()) {
320
+ mutex.Lock(); // Unlocked by UpdateVLogSites().
321
+ int old_v = PrependVModuleLocked(module_pattern, log_level);
322
+ UpdateVLogSites();
323
+ return old_v;
324
+ }
325
+
326
+ void OnVLogVerbosityUpdate(std::function<void()> cb)
327
+ ABSL_LOCKS_EXCLUDED(GetUpdateSitesMutex()) {
328
+ absl::MutexLock ul(GetUpdateSitesMutex());
329
+ if (!update_callbacks)
330
+ update_callbacks = new std::vector<std::function<void()>>;
331
+ update_callbacks->push_back(std::move(cb));
332
+ }
333
+
334
+ VLogSite* SetVModuleListHeadForTestOnly(VLogSite* v) {
335
+ return site_list_head.exchange(v, std::memory_order_seq_cst);
336
+ }
337
+
338
+ } // namespace log_internal
339
+ ABSL_NAMESPACE_END
340
+ } // namespace absl
weight/_dep/abseil-cpp/absl/log/internal/vlog_config.h ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors
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
+ // https://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
+ // vlog_config.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This header file defines `VLogSite`, a public primitive that represents
20
+ // a callsite for the `VLOG` family of macros and related libraries.
21
+ // It also declares and defines multiple internal utilities used to implement
22
+ // `VLOG`, such as `VLogSiteManager`.
23
+
24
+ #ifndef ABSL_LOG_INTERNAL_VLOG_CONFIG_H_
25
+ #define ABSL_LOG_INTERNAL_VLOG_CONFIG_H_
26
+
27
+ // IWYU pragma: private, include "absl/log/log.h"
28
+
29
+ #include <atomic>
30
+ #include <cstdint>
31
+ #include <functional>
32
+ #include <limits>
33
+ #include <type_traits>
34
+
35
+ #include "absl/base/attributes.h"
36
+ #include "absl/base/config.h"
37
+ #include "absl/base/optimization.h"
38
+ #include "absl/base/thread_annotations.h"
39
+ #include "absl/strings/string_view.h"
40
+
41
+ namespace absl {
42
+ ABSL_NAMESPACE_BEGIN
43
+ namespace log_internal {
44
+
45
+ class SyntheticBinary;
46
+ class VLogSite;
47
+
48
+ int RegisterAndInitialize(VLogSite* v);
49
+ void UpdateVLogSites();
50
+ constexpr int kUseFlag = (std::numeric_limits<int16_t>::min)();
51
+
52
+ // Represents a unique callsite for a `VLOG()` or `VLOG_IS_ON()` call.
53
+ //
54
+ // Libraries that provide `VLOG`-like functionality should use this to
55
+ // efficiently handle --vmodule.
56
+ //
57
+ // VLogSite objects must not be destroyed until the program exits. Doing so will
58
+ // probably yield nasty segfaults in VLogSiteManager::UpdateLogSites(). The
59
+ // recommendation is to make all such objects function-local statics.
60
+ class VLogSite final {
61
+ public:
62
+ // `f` must not be destroyed until the program exits.
63
+ explicit constexpr VLogSite(const char* f)
64
+ : file_(f), v_(kUninitialized), next_(nullptr) {}
65
+ VLogSite(const VLogSite&) = delete;
66
+ VLogSite& operator=(const VLogSite&) = delete;
67
+
68
+ // Inlining the function yields a ~3x performance improvement at the cost of a
69
+ // 1.5x code size increase at the call site.
70
+ // Takes locks but does not allocate memory.
71
+ ABSL_ATTRIBUTE_ALWAYS_INLINE
72
+ bool IsEnabled(int level) {
73
+ int stale_v = v_.load(std::memory_order_relaxed);
74
+ if (ABSL_PREDICT_TRUE(level > stale_v)) {
75
+ return false;
76
+ }
77
+
78
+ // We put everything other than the fast path, i.e. vlogging is initialized
79
+ // but not on, behind an out-of-line function to reduce code size.
80
+ // "level" is almost always a call-site constant, so we can save a bit
81
+ // of code space by special-casing for a few common levels.
82
+ #if ABSL_HAVE_BUILTIN(__builtin_constant_p) || defined(__GNUC__)
83
+ if (__builtin_constant_p(level)) {
84
+ if (level == 0) return SlowIsEnabled0(stale_v);
85
+ if (level == 1) return SlowIsEnabled1(stale_v);
86
+ if (level == 2) return SlowIsEnabled2(stale_v);
87
+ if (level == 3) return SlowIsEnabled3(stale_v);
88
+ if (level == 4) return SlowIsEnabled4(stale_v);
89
+ if (level == 5) return SlowIsEnabled5(stale_v);
90
+ }
91
+ #endif
92
+ return SlowIsEnabled(stale_v, level);
93
+ }
94
+
95
+ private:
96
+ friend int log_internal::RegisterAndInitialize(VLogSite* v);
97
+ friend void log_internal::UpdateVLogSites();
98
+ friend class log_internal::SyntheticBinary;
99
+ static constexpr int kUninitialized = (std::numeric_limits<int>::max)();
100
+
101
+ // SlowIsEnabled performs slower checks to determine whether a log site is
102
+ // enabled. Because it is expected to be called somewhat rarely
103
+ // (comparatively), it is not inlined to save on code size.
104
+ //
105
+ // Prerequisites to calling SlowIsEnabled:
106
+ // 1) stale_v is uninitialized OR
107
+ // 2) stale_v is initialized and >= level (meaning we must log).
108
+ // Takes locks but does not allocate memory.
109
+ ABSL_ATTRIBUTE_NOINLINE
110
+ bool SlowIsEnabled(int stale_v, int level);
111
+ ABSL_ATTRIBUTE_NOINLINE bool SlowIsEnabled0(int stale_v);
112
+ ABSL_ATTRIBUTE_NOINLINE bool SlowIsEnabled1(int stale_v);
113
+ ABSL_ATTRIBUTE_NOINLINE bool SlowIsEnabled2(int stale_v);
114
+ ABSL_ATTRIBUTE_NOINLINE bool SlowIsEnabled3(int stale_v);
115
+ ABSL_ATTRIBUTE_NOINLINE bool SlowIsEnabled4(int stale_v);
116
+ ABSL_ATTRIBUTE_NOINLINE bool SlowIsEnabled5(int stale_v);
117
+
118
+ // This object is too size-sensitive to use absl::string_view.
119
+ const char* const file_;
120
+ std::atomic<int> v_;
121
+ std::atomic<VLogSite*> next_;
122
+ };
123
+ static_assert(std::is_trivially_destructible<VLogSite>::value,
124
+ "VLogSite must be trivially destructible");
125
+
126
+ // Returns the current verbose log level of `file`.
127
+ // Does not allocate memory.
128
+ int VLogLevel(absl::string_view file);
129
+
130
+ // Registers a site `v` to get updated as `vmodule` and `v` change. Also
131
+ // initializes the site based on their current values, and returns that result.
132
+ // Does not allocate memory.
133
+ int RegisterAndInitialize(VLogSite* v);
134
+
135
+ // Allocates memory.
136
+ void UpdateVLogSites();
137
+
138
+ // Completely overwrites the saved value of `vmodule`.
139
+ // Allocates memory.
140
+ void UpdateVModule(absl::string_view vmodule);
141
+
142
+ // Updates the global verbosity level to `v` and returns the prior value.
143
+ // Allocates memory.
144
+ int UpdateGlobalVLogLevel(int v);
145
+
146
+ // Atomically prepends `module_pattern=log_level` to the start of vmodule.
147
+ // Returns the prior value for `module_pattern` if there was an exact match and
148
+ // `global_v` otherwise.
149
+ // Allocates memory.
150
+ int PrependVModule(absl::string_view module_pattern, int log_level);
151
+
152
+ // Registers `on_update` to be called whenever `v` or `vmodule` change.
153
+ // Allocates memory.
154
+ void OnVLogVerbosityUpdate(std::function<void()> cb);
155
+
156
+ // Does not allocate memory.
157
+ VLogSite* SetVModuleListHeadForTestOnly(VLogSite* v);
158
+
159
+ } // namespace log_internal
160
+ ABSL_NAMESPACE_END
161
+ } // namespace absl
162
+
163
+ #endif // ABSL_LOG_INTERNAL_VLOG_CONFIG_H_
weight/_dep/abseil-cpp/absl/log/internal/vlog_config_benchmark.cc ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors
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
+ // https://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
+ #include <algorithm>
16
+ #include <atomic>
17
+ #include <cstddef>
18
+ #include <cstring>
19
+ #include <memory>
20
+ #include <new>
21
+ #include <random>
22
+ #include <string>
23
+ #include <type_traits>
24
+ #include <utility>
25
+ #include <vector>
26
+
27
+ #include "absl/base/config.h"
28
+ #include "absl/container/internal/layout.h"
29
+ #include "absl/log/internal/vlog_config.h"
30
+ #include "absl/memory/memory.h"
31
+ #include "absl/random/distributions.h"
32
+ #include "absl/strings/str_cat.h"
33
+ #include "benchmark/benchmark.h"
34
+
35
+ namespace absl {
36
+ ABSL_NAMESPACE_BEGIN
37
+ namespace log_internal {
38
+ // Performance of `UpdateLogSites` depends upon the number and organization of
39
+ // `VLogSite`s in the program. We can synthesize some on the heap to mimic
40
+ // their layout and linkage in static data.
41
+ class SyntheticBinary {
42
+ public:
43
+ explicit SyntheticBinary(const size_t num_tus,
44
+ const size_t max_extra_static_data_bytes_per_tu,
45
+ const size_t max_sites_per_tu,
46
+ const int num_shuffles) {
47
+ per_tu_data_.reserve(num_tus);
48
+ auto sites = absl::make_unique<VLogSite *[]>(num_tus * max_sites_per_tu);
49
+ for (size_t i = 0; i < num_tus; i++) {
50
+ const std::string filename =
51
+ absl::StrCat("directory-", i / 100, "/subdirectory-", i % 100 / 10,
52
+ "/file-", i % 10, ".cc");
53
+ container_internal::Layout<char, VLogSite, char> layout(
54
+ filename.size() + 1,
55
+ absl::LogUniform<size_t>(bitgen_, 1, max_sites_per_tu),
56
+ absl::LogUniform<size_t>(bitgen_, 0,
57
+ max_extra_static_data_bytes_per_tu));
58
+ auto buf = absl::make_unique<char[]>(layout.AllocSize());
59
+ layout.PoisonPadding(buf.get());
60
+ memcpy(layout.Pointer<0>(buf.get()), filename.c_str(),
61
+ filename.size() + 1);
62
+ for (VLogSite &site : layout.Slice<1>(buf.get())) {
63
+ sites[num_sites_++] =
64
+ new (&site) VLogSite(layout.Pointer<0>(buf.get()));
65
+ // The last one is a dangling pointer but will be fixed below.
66
+ site.next_.store(&site + 1, std::memory_order_seq_cst);
67
+ }
68
+ num_extra_static_data_bytes_ += layout.Size<2>();
69
+ per_tu_data_.push_back(PerTU{layout, std::move(buf)});
70
+ }
71
+ // Now link the files together back-to-front into a circular list.
72
+ for (size_t i = 0; i < num_tus; i++) {
73
+ auto &tu = per_tu_data_[i];
74
+ auto &next_tu = per_tu_data_[(i + 1) % num_tus];
75
+ tu.layout.Slice<1>(tu.buf.get())
76
+ .back()
77
+ .next_.store(next_tu.layout.Pointer<1>(next_tu.buf.get()),
78
+ std::memory_order_seq_cst);
79
+ }
80
+ // Now do some shufflin'.
81
+ auto new_sites = absl::make_unique<VLogSite *[]>(num_sites_);
82
+ for (int shuffle_num = 0; shuffle_num < num_shuffles; shuffle_num++) {
83
+ // Each shuffle cuts the ring into three pieces and rearranges them.
84
+ const size_t cut_a = absl::Uniform(bitgen_, size_t{0}, num_sites_);
85
+ const size_t cut_b = absl::Uniform(bitgen_, size_t{0}, num_sites_);
86
+ const size_t cut_c = absl::Uniform(bitgen_, size_t{0}, num_sites_);
87
+ if (cut_a == cut_b || cut_b == cut_c || cut_a == cut_c) continue;
88
+ // The same cuts, sorted:
89
+ const size_t cut_1 = std::min({cut_a, cut_b, cut_c});
90
+ const size_t cut_3 = std::max({cut_a, cut_b, cut_c});
91
+ const size_t cut_2 = cut_a ^ cut_b ^ cut_c ^ cut_1 ^ cut_3;
92
+ VLogSite *const tmp = sites[cut_1]->next_.load(std::memory_order_seq_cst);
93
+ sites[cut_1]->next_.store(
94
+ sites[cut_2]->next_.load(std::memory_order_seq_cst),
95
+ std::memory_order_seq_cst);
96
+ sites[cut_2]->next_.store(
97
+ sites[cut_3]->next_.load(std::memory_order_seq_cst),
98
+ std::memory_order_seq_cst);
99
+ sites[cut_3]->next_.store(tmp, std::memory_order_seq_cst);
100
+ memcpy(&new_sites[0], &sites[0], sizeof(VLogSite *) * (cut_1 + 1));
101
+ memcpy(&new_sites[cut_1 + 1], &sites[cut_2 + 1],
102
+ sizeof(VLogSite *) * (cut_3 - cut_2));
103
+ memcpy(&new_sites[cut_1 + 1 + cut_3 - cut_2], &sites[cut_1 + 1],
104
+ sizeof(VLogSite *) * (cut_2 - cut_1));
105
+ memcpy(&new_sites[cut_3 + 1], &sites[cut_3 + 1],
106
+ sizeof(VLogSite *) * (num_sites_ - cut_3 - 1));
107
+ sites.swap(new_sites);
108
+ }
109
+ const char *last_file = nullptr;
110
+ for (size_t i = 0; i < num_sites_; i++) {
111
+ if (sites[i]->file_ == last_file) continue;
112
+ last_file = sites[i]->file_;
113
+ num_new_files_++;
114
+ }
115
+ absl::log_internal::SetVModuleListHeadForTestOnly(sites[0]);
116
+ sites[num_tus - 1]->next_.store(nullptr, std::memory_order_seq_cst);
117
+ }
118
+ ~SyntheticBinary() {
119
+ static_assert(std::is_trivially_destructible<VLogSite>::value, "");
120
+ absl::log_internal::SetVModuleListHeadForTestOnly(nullptr);
121
+ }
122
+
123
+ size_t num_sites() const { return num_sites_; }
124
+ size_t num_new_files() const { return num_new_files_; }
125
+ size_t num_extra_static_data_bytes() const {
126
+ return num_extra_static_data_bytes_;
127
+ }
128
+
129
+ private:
130
+ struct PerTU {
131
+ container_internal::Layout<char, VLogSite, char> layout;
132
+ std::unique_ptr<char[]> buf;
133
+ };
134
+
135
+ std::mt19937 bitgen_;
136
+ std::vector<PerTU> per_tu_data_;
137
+ size_t num_sites_ = 0;
138
+ size_t num_new_files_ = 0;
139
+ size_t num_extra_static_data_bytes_ = 0;
140
+ };
141
+
142
+ namespace {
143
+ void BM_UpdateVModuleEmpty(benchmark::State& state) {
144
+ SyntheticBinary bin(static_cast<size_t>(state.range(0)), 10 * 1024 * 1024,
145
+ 256, state.range(1));
146
+ for (auto s : state) {
147
+ absl::log_internal::UpdateVModule("");
148
+ }
149
+ state.SetItemsProcessed(static_cast<int>(bin.num_new_files()));
150
+ }
151
+ BENCHMARK(BM_UpdateVModuleEmpty)
152
+ ->ArgPair(100, 200)
153
+ ->ArgPair(1000, 2000)
154
+ ->ArgPair(10000, 20000);
155
+
156
+ void BM_UpdateVModuleShort(benchmark::State& state) {
157
+ SyntheticBinary bin(static_cast<size_t>(state.range(0)), 10 * 1024 * 1024,
158
+ 256, state.range(1));
159
+ for (auto s : state) {
160
+ absl::log_internal::UpdateVModule("directory2/*=4");
161
+ }
162
+ state.SetItemsProcessed(static_cast<int>(bin.num_new_files()));
163
+ }
164
+ BENCHMARK(BM_UpdateVModuleShort)
165
+ ->ArgPair(100, 200)
166
+ ->ArgPair(1000, 2000)
167
+ ->ArgPair(10000, 20000);
168
+
169
+ void BM_UpdateVModuleLong(benchmark::State& state) {
170
+ SyntheticBinary bin(static_cast<size_t>(state.range(0)), 10 * 1024 * 1024,
171
+ 256, state.range(1));
172
+ for (auto s : state) {
173
+ absl::log_internal::UpdateVModule(
174
+ "d?r?c?o?y2/*=4,d?*r?*c?**o?*y1/*=2,d?*rc?**o?*y3/*=2,,"
175
+ "d?*r?*c?**o?*1/*=1,d?*r?**o?*y1/*=2,d?*r???***y1/*=7,"
176
+ "d?*r?**o?*y1/aaa=6");
177
+ }
178
+ state.SetItemsProcessed(static_cast<int>(bin.num_new_files()));
179
+ }
180
+ BENCHMARK(BM_UpdateVModuleLong)
181
+ ->ArgPair(100, 200)
182
+ ->ArgPair(1000, 2000)
183
+ ->ArgPair(10000, 20000);
184
+ } // namespace
185
+ } // namespace log_internal
186
+ ABSL_NAMESPACE_END
187
+ } // namespace absl
weight/_dep/abseil-cpp/absl/log/internal/voidify.h ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/internal/voidify.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This class is used to explicitly ignore values in the conditional logging
20
+ // macros. This avoids compiler warnings like "value computed is not used" and
21
+ // "statement has no effect".
22
+
23
+ #ifndef ABSL_LOG_INTERNAL_VOIDIFY_H_
24
+ #define ABSL_LOG_INTERNAL_VOIDIFY_H_
25
+
26
+ #include "absl/base/config.h"
27
+
28
+ namespace absl {
29
+ ABSL_NAMESPACE_BEGIN
30
+ namespace log_internal {
31
+
32
+ class Voidify final {
33
+ public:
34
+ // This has to be an operator with a precedence lower than << but higher than
35
+ // ?:
36
+ template <typename T>
37
+ void operator&&(const T&) const&& {}
38
+ };
39
+
40
+ } // namespace log_internal
41
+ ABSL_NAMESPACE_END
42
+ } // namespace absl
43
+
44
+ #endif // ABSL_LOG_INTERNAL_VOIDIFY_H_
weight/_dep/abseil-cpp/absl/log/scoped_mock_log_test.cc ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //
2
+ // Copyright 2022 The Abseil Authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // https://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+
16
+ #include "absl/log/scoped_mock_log.h"
17
+
18
+ #include <memory>
19
+ #include <thread> // NOLINT(build/c++11)
20
+
21
+ #include "gmock/gmock.h"
22
+ #include "gtest/gtest-spi.h"
23
+ #include "gtest/gtest.h"
24
+ #include "absl/base/attributes.h"
25
+ #include "absl/base/log_severity.h"
26
+ #include "absl/log/globals.h"
27
+ #include "absl/log/internal/test_helpers.h"
28
+ #include "absl/log/internal/test_matchers.h"
29
+ #include "absl/log/log.h"
30
+ #include "absl/memory/memory.h"
31
+ #include "absl/strings/match.h"
32
+ #include "absl/strings/string_view.h"
33
+ #include "absl/synchronization/barrier.h"
34
+ #include "absl/synchronization/notification.h"
35
+
36
+ namespace {
37
+
38
+ using ::testing::_;
39
+ using ::testing::AnyNumber;
40
+ using ::testing::Eq;
41
+ using ::testing::HasSubstr;
42
+ using ::testing::InSequence;
43
+ using ::testing::Lt;
44
+ using ::testing::Truly;
45
+ using absl::log_internal::SourceBasename;
46
+ using absl::log_internal::SourceFilename;
47
+ using absl::log_internal::SourceLine;
48
+ using absl::log_internal::TextMessageWithPrefix;
49
+ using absl::log_internal::ThreadID;
50
+
51
+ auto* test_env ABSL_ATTRIBUTE_UNUSED = ::testing::AddGlobalTestEnvironment(
52
+ new absl::log_internal::LogTestEnvironment);
53
+
54
+ #if GTEST_HAS_DEATH_TEST
55
+ TEST(ScopedMockLogDeathTest,
56
+ StartCapturingLogsCannotBeCalledWhenAlreadyCapturing) {
57
+ EXPECT_DEATH(
58
+ {
59
+ absl::ScopedMockLog log;
60
+ log.StartCapturingLogs();
61
+ log.StartCapturingLogs();
62
+ },
63
+ "StartCapturingLogs");
64
+ }
65
+
66
+ TEST(ScopedMockLogDeathTest, StopCapturingLogsCannotBeCalledWhenNotCapturing) {
67
+ EXPECT_DEATH(
68
+ {
69
+ absl::ScopedMockLog log;
70
+ log.StopCapturingLogs();
71
+ },
72
+ "StopCapturingLogs");
73
+ }
74
+
75
+ TEST(ScopedMockLogDeathTest, FailsCheckIfStartCapturingLogsIsNeverCalled) {
76
+ EXPECT_DEATH({ absl::ScopedMockLog log; },
77
+ "Did you forget to call StartCapturingLogs");
78
+ }
79
+ #endif
80
+
81
+ // Tests that ScopedMockLog intercepts LOG()s when it's alive.
82
+ TEST(ScopedMockLogTest, LogMockCatchAndMatchStrictExpectations) {
83
+ absl::ScopedMockLog log;
84
+
85
+ // The following expectations must match in the order they appear.
86
+ InSequence s;
87
+ EXPECT_CALL(log,
88
+ Log(absl::LogSeverity::kWarning, HasSubstr(__FILE__), "Danger."));
89
+ EXPECT_CALL(log, Log(absl::LogSeverity::kInfo, _, "Working...")).Times(2);
90
+ EXPECT_CALL(log, Log(absl::LogSeverity::kError, _, "Bad!!"));
91
+
92
+ log.StartCapturingLogs();
93
+ LOG(WARNING) << "Danger.";
94
+ LOG(INFO) << "Working...";
95
+ LOG(INFO) << "Working...";
96
+ LOG(ERROR) << "Bad!!";
97
+ }
98
+
99
+ TEST(ScopedMockLogTest, LogMockCatchAndMatchSendExpectations) {
100
+ absl::ScopedMockLog log;
101
+
102
+ EXPECT_CALL(
103
+ log,
104
+ Send(AllOf(SourceFilename(Eq("/my/very/very/very_long_source_file.cc")),
105
+ SourceBasename(Eq("very_long_source_file.cc")),
106
+ SourceLine(Eq(777)), ThreadID(Eq(absl::LogEntry::tid_t{1234})),
107
+ TextMessageWithPrefix(Truly([](absl::string_view msg) {
108
+ return absl::EndsWith(
109
+ msg, " very_long_source_file.cc:777] Info message");
110
+ })))));
111
+
112
+ log.StartCapturingLogs();
113
+ LOG(INFO)
114
+ .AtLocation("/my/very/very/very_long_source_file.cc", 777)
115
+ .WithThreadID(1234)
116
+ << "Info message";
117
+ }
118
+
119
+ TEST(ScopedMockLogTest, ScopedMockLogCanBeNice) {
120
+ absl::ScopedMockLog log;
121
+
122
+ InSequence s;
123
+ EXPECT_CALL(log,
124
+ Log(absl::LogSeverity::kWarning, HasSubstr(__FILE__), "Danger."));
125
+ EXPECT_CALL(log, Log(absl::LogSeverity::kInfo, _, "Working...")).Times(2);
126
+ EXPECT_CALL(log, Log(absl::LogSeverity::kError, _, "Bad!!"));
127
+
128
+ log.StartCapturingLogs();
129
+
130
+ // Any number of these are OK.
131
+ LOG(INFO) << "Info message.";
132
+ // Any number of these are OK.
133
+ LOG(WARNING).AtLocation("SomeOtherFile.cc", 100) << "Danger ";
134
+
135
+ LOG(WARNING) << "Danger.";
136
+
137
+ // Any number of these are OK.
138
+ LOG(INFO) << "Info message.";
139
+ // Any number of these are OK.
140
+ LOG(WARNING).AtLocation("SomeOtherFile.cc", 100) << "Danger ";
141
+
142
+ LOG(INFO) << "Working...";
143
+
144
+ // Any number of these are OK.
145
+ LOG(INFO) << "Info message.";
146
+ // Any number of these are OK.
147
+ LOG(WARNING).AtLocation("SomeOtherFile.cc", 100) << "Danger ";
148
+
149
+ LOG(INFO) << "Working...";
150
+
151
+ // Any number of these are OK.
152
+ LOG(INFO) << "Info message.";
153
+ // Any number of these are OK.
154
+ LOG(WARNING).AtLocation("SomeOtherFile.cc", 100) << "Danger ";
155
+
156
+ LOG(ERROR) << "Bad!!";
157
+
158
+ // Any number of these are OK.
159
+ LOG(INFO) << "Info message.";
160
+ // Any number of these are OK.
161
+ LOG(WARNING).AtLocation("SomeOtherFile.cc", 100) << "Danger ";
162
+ }
163
+
164
+ // Tests that ScopedMockLog generates a test failure if a message is logged
165
+ // that is not expected (here, that means ERROR or FATAL).
166
+ TEST(ScopedMockLogTest, RejectsUnexpectedLogs) {
167
+ EXPECT_NONFATAL_FAILURE(
168
+ {
169
+ absl::ScopedMockLog log(absl::MockLogDefault::kDisallowUnexpected);
170
+ // Any INFO and WARNING messages are permitted.
171
+ EXPECT_CALL(log, Log(Lt(absl::LogSeverity::kError), _, _))
172
+ .Times(AnyNumber());
173
+ log.StartCapturingLogs();
174
+ LOG(INFO) << "Ignored";
175
+ LOG(WARNING) << "Ignored";
176
+ LOG(ERROR) << "Should not be ignored";
177
+ },
178
+ "Should not be ignored");
179
+ }
180
+
181
+ TEST(ScopedMockLogTest, CapturesLogsAfterStartCapturingLogs) {
182
+ absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfinity);
183
+ absl::ScopedMockLog log;
184
+
185
+ // The ScopedMockLog object shouldn't see these LOGs, as it hasn't
186
+ // started capturing LOGs yet.
187
+ LOG(INFO) << "Ignored info";
188
+ LOG(WARNING) << "Ignored warning";
189
+ LOG(ERROR) << "Ignored error";
190
+
191
+ EXPECT_CALL(log, Log(absl::LogSeverity::kInfo, _, "Expected info"));
192
+ log.StartCapturingLogs();
193
+
194
+ // Only this LOG will be seen by the ScopedMockLog.
195
+ LOG(INFO) << "Expected info";
196
+ }
197
+
198
+ TEST(ScopedMockLogTest, DoesNotCaptureLogsAfterStopCapturingLogs) {
199
+ absl::ScopedMockLog log;
200
+ EXPECT_CALL(log, Log(absl::LogSeverity::kInfo, _, "Expected info"));
201
+
202
+ log.StartCapturingLogs();
203
+
204
+ // This LOG should be seen by the ScopedMockLog.
205
+ LOG(INFO) << "Expected info";
206
+
207
+ log.StopCapturingLogs();
208
+
209
+ // The ScopedMockLog object shouldn't see these LOGs, as it has
210
+ // stopped capturing LOGs.
211
+ LOG(INFO) << "Ignored info";
212
+ LOG(WARNING) << "Ignored warning";
213
+ LOG(ERROR) << "Ignored error";
214
+ }
215
+
216
+ // Tests that all messages are intercepted regardless of issuing thread. The
217
+ // purpose of this test is NOT to exercise thread-safety.
218
+ TEST(ScopedMockLogTest, LogFromMultipleThreads) {
219
+ absl::ScopedMockLog log;
220
+
221
+ // We don't establish an order to expectations here, since the threads may
222
+ // execute their log statements in different order.
223
+ EXPECT_CALL(log, Log(absl::LogSeverity::kInfo, __FILE__, "Thread 1"));
224
+ EXPECT_CALL(log, Log(absl::LogSeverity::kInfo, __FILE__, "Thread 2"));
225
+
226
+ log.StartCapturingLogs();
227
+
228
+ absl::Barrier barrier(2);
229
+ std::thread thread1([&barrier]() {
230
+ barrier.Block();
231
+ LOG(INFO) << "Thread 1";
232
+ });
233
+ std::thread thread2([&barrier]() {
234
+ barrier.Block();
235
+ LOG(INFO) << "Thread 2";
236
+ });
237
+
238
+ thread1.join();
239
+ thread2.join();
240
+ }
241
+
242
+ // Tests that no sequence will be imposed on two LOG message expectations from
243
+ // different threads. This test would actually deadlock if replaced to two LOG
244
+ // statements from the same thread.
245
+ TEST(ScopedMockLogTest, NoSequenceWithMultipleThreads) {
246
+ absl::ScopedMockLog log;
247
+
248
+ absl::Barrier barrier(2);
249
+ EXPECT_CALL(log, Log(absl::LogSeverity::kInfo, _, _))
250
+ .Times(2)
251
+ .WillRepeatedly([&barrier]() { barrier.Block(); });
252
+
253
+ log.StartCapturingLogs();
254
+
255
+ std::thread thread1([]() { LOG(INFO) << "Thread 1"; });
256
+ std::thread thread2([]() { LOG(INFO) << "Thread 2"; });
257
+
258
+ thread1.join();
259
+ thread2.join();
260
+ }
261
+
262
+ TEST(ScopedMockLogTsanTest,
263
+ ScopedMockLogCanBeDeletedWhenAnotherThreadIsLogging) {
264
+ auto log = absl::make_unique<absl::ScopedMockLog>();
265
+ EXPECT_CALL(*log, Log(absl::LogSeverity::kInfo, __FILE__, "Thread log"))
266
+ .Times(AnyNumber());
267
+
268
+ log->StartCapturingLogs();
269
+
270
+ absl::Notification logging_started;
271
+
272
+ std::thread thread([&logging_started]() {
273
+ for (int i = 0; i < 100; ++i) {
274
+ if (i == 50) logging_started.Notify();
275
+ LOG(INFO) << "Thread log";
276
+ }
277
+ });
278
+
279
+ logging_started.WaitForNotification();
280
+ log.reset();
281
+ thread.join();
282
+ }
283
+
284
+ TEST(ScopedMockLogTest, AsLocalSink) {
285
+ absl::ScopedMockLog log(absl::MockLogDefault::kDisallowUnexpected);
286
+
287
+ EXPECT_CALL(log, Log(_, _, "two"));
288
+ EXPECT_CALL(log, Log(_, _, "three"));
289
+
290
+ LOG(INFO) << "one";
291
+ LOG(INFO).ToSinkOnly(&log.UseAsLocalSink()) << "two";
292
+ LOG(INFO).ToSinkAlso(&log.UseAsLocalSink()) << "three";
293
+ }
294
+
295
+ } // namespace
weight/_dep/abseil-cpp/absl/log/stripping_test.cc ADDED
@@ -0,0 +1,502 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //
2
+ // Copyright 2022 The Abseil Authors.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // https://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ //
16
+ // Tests for stripping of literal strings.
17
+ // ---------------------------------------
18
+ //
19
+ // When a `LOG` statement can be trivially proved at compile time to never fire,
20
+ // e.g. due to `ABSL_MIN_LOG_LEVEL`, `NDEBUG`, or some explicit condition, data
21
+ // streamed in can be dropped from the compiled program completely if they are
22
+ // not used elsewhere. This most commonly affects string literals, which users
23
+ // often want to strip to reduce binary size and/or redact information about
24
+ // their program's internals (e.g. in a release build).
25
+ //
26
+ // These tests log strings and then validate whether they appear in the compiled
27
+ // binary. This is done by opening the file corresponding to the running test
28
+ // and running a simple string search on its contents. The strings to be logged
29
+ // and searched for must be unique, and we must take care not to emit them into
30
+ // the binary in any other place, e.g. when searching for them. The latter is
31
+ // accomplished by computing them using base64; the source string appears in the
32
+ // binary but the target string is computed at runtime.
33
+
34
+ #include <stdio.h>
35
+
36
+ #if defined(__MACH__)
37
+ #include <mach-o/dyld.h>
38
+ #elif defined(_WIN32)
39
+ #include <Windows.h>
40
+ #include <tchar.h>
41
+ #endif
42
+
43
+ #include <algorithm>
44
+ #include <functional>
45
+ #include <memory>
46
+ #include <ostream>
47
+ #include <string>
48
+
49
+ #include "gmock/gmock.h"
50
+ #include "gtest/gtest.h"
51
+ #include "absl/base/internal/strerror.h"
52
+ #include "absl/base/log_severity.h"
53
+ #include "absl/flags/internal/program_name.h"
54
+ #include "absl/log/check.h"
55
+ #include "absl/log/internal/test_helpers.h"
56
+ #include "absl/log/log.h"
57
+ #include "absl/status/status.h"
58
+ #include "absl/strings/escaping.h"
59
+ #include "absl/strings/str_format.h"
60
+ #include "absl/strings/string_view.h"
61
+
62
+ // Set a flag that controls whether we actually execute fatal statements, but
63
+ // prevent the compiler from optimizing it out.
64
+ static volatile bool kReallyDie = false;
65
+
66
+ namespace {
67
+ using ::testing::_;
68
+ using ::testing::Eq;
69
+ using ::testing::NotNull;
70
+
71
+ using absl::log_internal::kAbslMinLogLevel;
72
+
73
+ std::string Base64UnescapeOrDie(absl::string_view data) {
74
+ std::string decoded;
75
+ CHECK(absl::Base64Unescape(data, &decoded));
76
+ return decoded;
77
+ }
78
+
79
+ // -----------------------------------------------------------------------------
80
+ // A Googletest matcher which searches the running binary for a given string
81
+ // -----------------------------------------------------------------------------
82
+
83
+ // This matcher is used to validate that literal strings streamed into
84
+ // `LOG` statements that ought to be compiled out (e.g. `LOG_IF(INFO, false)`)
85
+ // do not appear in the binary.
86
+ //
87
+ // Note that passing the string to be sought directly to `FileHasSubstr()` all
88
+ // but forces its inclusion in the binary regardless of the logging library's
89
+ // behavior. For example:
90
+ //
91
+ // LOG_IF(INFO, false) << "you're the man now dog";
92
+ // // This will always pass:
93
+ // // EXPECT_THAT(fp, FileHasSubstr("you're the man now dog"));
94
+ // // So use this instead:
95
+ // EXPECT_THAT(fp, FileHasSubstr(
96
+ // Base64UnescapeOrDie("eW91J3JlIHRoZSBtYW4gbm93IGRvZw==")));
97
+
98
+ class FileHasSubstrMatcher final : public ::testing::MatcherInterface<FILE*> {
99
+ public:
100
+ explicit FileHasSubstrMatcher(absl::string_view needle) : needle_(needle) {}
101
+
102
+ bool MatchAndExplain(
103
+ FILE* fp, ::testing::MatchResultListener* listener) const override {
104
+ std::string buf(
105
+ std::max<std::string::size_type>(needle_.size() * 2, 163840000), '\0');
106
+ size_t buf_start_offset = 0; // The file offset of the byte at `buf[0]`.
107
+ size_t buf_data_size = 0; // The number of bytes of `buf` which contain
108
+ // data.
109
+
110
+ ::fseek(fp, 0, SEEK_SET);
111
+ while (true) {
112
+ // Fill the buffer to capacity or EOF:
113
+ while (buf_data_size < buf.size()) {
114
+ const size_t ret = fread(&buf[buf_data_size], sizeof(char),
115
+ buf.size() - buf_data_size, fp);
116
+ if (ret == 0) break;
117
+ buf_data_size += ret;
118
+ }
119
+ if (ferror(fp)) {
120
+ *listener << "error reading file";
121
+ return false;
122
+ }
123
+ const absl::string_view haystack(&buf[0], buf_data_size);
124
+ const auto off = haystack.find(needle_);
125
+ if (off != haystack.npos) {
126
+ *listener << "string found at offset " << buf_start_offset + off;
127
+ return true;
128
+ }
129
+ if (feof(fp)) {
130
+ *listener << "string not found";
131
+ return false;
132
+ }
133
+ // Copy the end of `buf` to the beginning so we catch matches that span
134
+ // buffer boundaries. `buf` and `buf_data_size` are always large enough
135
+ // that these ranges don't overlap.
136
+ memcpy(&buf[0], &buf[buf_data_size - needle_.size()], needle_.size());
137
+ buf_start_offset += buf_data_size - needle_.size();
138
+ buf_data_size = needle_.size();
139
+ }
140
+ }
141
+ void DescribeTo(std::ostream* os) const override {
142
+ *os << "contains the string \"" << needle_ << "\" (base64(\""
143
+ << Base64UnescapeOrDie(needle_) << "\"))";
144
+ }
145
+
146
+ void DescribeNegationTo(std::ostream* os) const override {
147
+ *os << "does not ";
148
+ DescribeTo(os);
149
+ }
150
+
151
+ private:
152
+ std::string needle_;
153
+ };
154
+
155
+ class StrippingTest : public ::testing::Test {
156
+ protected:
157
+ void SetUp() override {
158
+ #ifndef NDEBUG
159
+ // Non-optimized builds don't necessarily eliminate dead code at all, so we
160
+ // don't attempt to validate stripping against such builds.
161
+ GTEST_SKIP() << "StrippingTests skipped since this build is not optimized";
162
+ #elif defined(__EMSCRIPTEN__)
163
+ // These tests require a way to examine the running binary and look for
164
+ // strings; there's no portable way to do that.
165
+ GTEST_SKIP()
166
+ << "StrippingTests skipped since this platform is not optimized";
167
+ #endif
168
+ }
169
+
170
+ // Opens this program's executable file. Returns `nullptr` and writes to
171
+ // `stderr` on failure.
172
+ std::unique_ptr<FILE, std::function<void(FILE*)>> OpenTestExecutable() {
173
+ #if defined(__linux__)
174
+ std::unique_ptr<FILE, std::function<void(FILE*)>> fp(
175
+ fopen("/proc/self/exe", "rb"), [](FILE* fp) { fclose(fp); });
176
+ if (!fp) {
177
+ const std::string err = absl::base_internal::StrError(errno);
178
+ absl::FPrintF(stderr, "Failed to open /proc/self/exe: %s\n", err);
179
+ }
180
+ return fp;
181
+ #elif defined(__Fuchsia__)
182
+ // TODO(b/242579714): We need to restore the test coverage on this platform.
183
+ std::unique_ptr<FILE, std::function<void(FILE*)>> fp(
184
+ fopen(absl::StrCat("/pkg/bin/",
185
+ absl::flags_internal::ShortProgramInvocationName())
186
+ .c_str(),
187
+ "rb"),
188
+ [](FILE* fp) { fclose(fp); });
189
+ if (!fp) {
190
+ const std::string err = absl::base_internal::StrError(errno);
191
+ absl::FPrintF(stderr, "Failed to open /pkg/bin/<binary name>: %s\n", err);
192
+ }
193
+ return fp;
194
+ #elif defined(__MACH__)
195
+ uint32_t size = 0;
196
+ int ret = _NSGetExecutablePath(nullptr, &size);
197
+ if (ret != -1) {
198
+ absl::FPrintF(stderr,
199
+ "Failed to get executable path: "
200
+ "_NSGetExecutablePath(nullptr) returned %d\n",
201
+ ret);
202
+ return nullptr;
203
+ }
204
+ std::string path(size, '\0');
205
+ ret = _NSGetExecutablePath(&path[0], &size);
206
+ if (ret != 0) {
207
+ absl::FPrintF(
208
+ stderr,
209
+ "Failed to get executable path: _NSGetExecutablePath(buffer) "
210
+ "returned %d\n",
211
+ ret);
212
+ return nullptr;
213
+ }
214
+ std::unique_ptr<FILE, std::function<void(FILE*)>> fp(
215
+ fopen(path.c_str(), "rb"), [](FILE* fp) { fclose(fp); });
216
+ if (!fp) {
217
+ const std::string err = absl::base_internal::StrError(errno);
218
+ absl::FPrintF(stderr, "Failed to open executable at %s: %s\n", path, err);
219
+ }
220
+ return fp;
221
+ #elif defined(_WIN32)
222
+ std::basic_string<TCHAR> path(4096, _T('\0'));
223
+ while (true) {
224
+ const uint32_t ret = ::GetModuleFileName(nullptr, &path[0],
225
+ static_cast<DWORD>(path.size()));
226
+ if (ret == 0) {
227
+ absl::FPrintF(
228
+ stderr,
229
+ "Failed to get executable path: GetModuleFileName(buffer) "
230
+ "returned 0\n");
231
+ return nullptr;
232
+ }
233
+ if (ret < path.size()) break;
234
+ path.resize(path.size() * 2, _T('\0'));
235
+ }
236
+ std::unique_ptr<FILE, std::function<void(FILE*)>> fp(
237
+ _tfopen(path.c_str(), _T("rb")), [](FILE* fp) { fclose(fp); });
238
+ if (!fp) absl::FPrintF(stderr, "Failed to open executable\n");
239
+ return fp;
240
+ #else
241
+ absl::FPrintF(stderr,
242
+ "OpenTestExecutable() unimplemented on this platform\n");
243
+ return nullptr;
244
+ #endif
245
+ }
246
+
247
+ ::testing::Matcher<FILE*> FileHasSubstr(absl::string_view needle) {
248
+ return MakeMatcher(new FileHasSubstrMatcher(needle));
249
+ }
250
+ };
251
+
252
+ // This tests whether out methodology for testing stripping works on this
253
+ // platform by looking for one string that definitely ought to be there and one
254
+ // that definitely ought not to. If this fails, none of the `StrippingTest`s
255
+ // are going to produce meaningful results.
256
+ TEST_F(StrippingTest, Control) {
257
+ constexpr char kEncodedPositiveControl[] =
258
+ "U3RyaXBwaW5nVGVzdC5Qb3NpdGl2ZUNvbnRyb2w=";
259
+ const std::string encoded_negative_control =
260
+ absl::Base64Escape("StrippingTest.NegativeControl");
261
+
262
+ // Verify this mainly so we can encode other strings and know definitely they
263
+ // won't encode to `kEncodedPositiveControl`.
264
+ EXPECT_THAT(Base64UnescapeOrDie("U3RyaXBwaW5nVGVzdC5Qb3NpdGl2ZUNvbnRyb2w="),
265
+ Eq("StrippingTest.PositiveControl"));
266
+
267
+ auto exe = OpenTestExecutable();
268
+ ASSERT_THAT(exe, NotNull());
269
+ EXPECT_THAT(exe.get(), FileHasSubstr(kEncodedPositiveControl));
270
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(encoded_negative_control)));
271
+ }
272
+
273
+ TEST_F(StrippingTest, Literal) {
274
+ // We need to load a copy of the needle string into memory (so we can search
275
+ // for it) without leaving it lying around in plaintext in the executable file
276
+ // as would happen if we used a literal. We might (or might not) leave it
277
+ // lying around later; that's what the tests are for!
278
+ const std::string needle = absl::Base64Escape("StrippingTest.Literal");
279
+ LOG(INFO) << "U3RyaXBwaW5nVGVzdC5MaXRlcmFs";
280
+ auto exe = OpenTestExecutable();
281
+ ASSERT_THAT(exe, NotNull());
282
+ if (absl::LogSeverity::kInfo >= kAbslMinLogLevel) {
283
+ EXPECT_THAT(exe.get(), FileHasSubstr(needle));
284
+ } else {
285
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(needle)));
286
+ }
287
+ }
288
+
289
+ TEST_F(StrippingTest, LiteralInExpression) {
290
+ // We need to load a copy of the needle string into memory (so we can search
291
+ // for it) without leaving it lying around in plaintext in the executable file
292
+ // as would happen if we used a literal. We might (or might not) leave it
293
+ // lying around later; that's what the tests are for!
294
+ const std::string needle =
295
+ absl::Base64Escape("StrippingTest.LiteralInExpression");
296
+ LOG(INFO) << absl::StrCat("secret: ",
297
+ "U3RyaXBwaW5nVGVzdC5MaXRlcmFsSW5FeHByZXNzaW9u");
298
+ std::unique_ptr<FILE, std::function<void(FILE*)>> exe = OpenTestExecutable();
299
+ ASSERT_THAT(exe, NotNull());
300
+ if (absl::LogSeverity::kInfo >= kAbslMinLogLevel) {
301
+ EXPECT_THAT(exe.get(), FileHasSubstr(needle));
302
+ } else {
303
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(needle)));
304
+ }
305
+ }
306
+
307
+ TEST_F(StrippingTest, Fatal) {
308
+ // We need to load a copy of the needle string into memory (so we can search
309
+ // for it) without leaving it lying around in plaintext in the executable file
310
+ // as would happen if we used a literal. We might (or might not) leave it
311
+ // lying around later; that's what the tests are for!
312
+ const std::string needle = absl::Base64Escape("StrippingTest.Fatal");
313
+ // We don't care if the LOG statement is actually executed, we're just
314
+ // checking that it's stripped.
315
+ if (kReallyDie) LOG(FATAL) << "U3RyaXBwaW5nVGVzdC5GYXRhbA==";
316
+
317
+ std::unique_ptr<FILE, std::function<void(FILE*)>> exe = OpenTestExecutable();
318
+ ASSERT_THAT(exe, NotNull());
319
+ if (absl::LogSeverity::kFatal >= kAbslMinLogLevel) {
320
+ EXPECT_THAT(exe.get(), FileHasSubstr(needle));
321
+ } else {
322
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(needle)));
323
+ }
324
+ }
325
+
326
+ TEST_F(StrippingTest, DFatal) {
327
+ // We need to load a copy of the needle string into memory (so we can search
328
+ // for it) without leaving it lying around in plaintext in the executable file
329
+ // as would happen if we used a literal. We might (or might not) leave it
330
+ // lying around later; that's what the tests are for!
331
+ const std::string needle = absl::Base64Escape("StrippingTest.DFatal");
332
+ // We don't care if the LOG statement is actually executed, we're just
333
+ // checking that it's stripped.
334
+ if (kReallyDie) LOG(DFATAL) << "U3RyaXBwaW5nVGVzdC5ERmF0YWw=";
335
+
336
+ std::unique_ptr<FILE, std::function<void(FILE*)>> exe = OpenTestExecutable();
337
+ ASSERT_THAT(exe, NotNull());
338
+ // `DFATAL` can be `ERROR` or `FATAL`, and a compile-time optimizer doesn't
339
+ // know which, because `absl::kLogDebugFatal` is declared `extern` and defined
340
+ // in another TU. Link-time optimization might do better. We have six cases:
341
+ // | `AMLL` is-> | `<=ERROR` | `FATAL` | `>FATAL` |
342
+ // | ------------------- | --------- | ------- | -------- |
343
+ // | `DFATAL` is `ERROR` | present | ? | stripped |
344
+ // | `DFATAL` is `FATAL` | present | present | stripped |
345
+
346
+ // These constexpr variables are used to suppress unreachable code warnings
347
+ // in the if-else statements below.
348
+
349
+ // "present" in the table above: `DFATAL` exceeds `ABSL_MIN_LOG_LEVEL`, so
350
+ // `DFATAL` statements should not be stripped (and they should be logged
351
+ // when executed, but that's a different testsuite).
352
+ constexpr bool kExpectPresent = absl::kLogDebugFatal >= kAbslMinLogLevel;
353
+
354
+ // "stripped" in the table above: even though the compiler may not know
355
+ // which value `DFATAL` has, it should be able to strip it since both
356
+ // possible values ought to be stripped.
357
+ constexpr bool kExpectStripped = kAbslMinLogLevel > absl::LogSeverity::kFatal;
358
+
359
+ if (kExpectPresent) {
360
+ EXPECT_THAT(exe.get(), FileHasSubstr(needle));
361
+ } else if (kExpectStripped) {
362
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(needle)));
363
+ } else {
364
+ // "?" in the table above; may or may not be stripped depending on whether
365
+ // any link-time optimization is done. Either outcome is ok.
366
+ }
367
+ }
368
+
369
+ TEST_F(StrippingTest, Level) {
370
+ const std::string needle = absl::Base64Escape("StrippingTest.Level");
371
+ volatile auto severity = absl::LogSeverity::kWarning;
372
+ // Ensure that `severity` is not a compile-time constant to prove that
373
+ // stripping works regardless:
374
+ LOG(LEVEL(severity)) << "U3RyaXBwaW5nVGVzdC5MZXZlbA==";
375
+ std::unique_ptr<FILE, std::function<void(FILE*)>> exe = OpenTestExecutable();
376
+ ASSERT_THAT(exe, NotNull());
377
+ if (absl::LogSeverity::kFatal >= kAbslMinLogLevel) {
378
+ // This can't be stripped at compile-time because it might evaluate to a
379
+ // level that shouldn't be stripped.
380
+ EXPECT_THAT(exe.get(), FileHasSubstr(needle));
381
+ } else {
382
+ #if (defined(_MSC_VER) && !defined(__clang__)) || defined(__APPLE__)
383
+ // Dead code elimination misses this case.
384
+ #else
385
+ // All levels should be stripped, so it doesn't matter what the severity
386
+ // winds up being.
387
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(needle)));
388
+ #endif
389
+ }
390
+ }
391
+
392
+ TEST_F(StrippingTest, Check) {
393
+ // Here we also need a variable name with enough entropy that it's unlikely to
394
+ // appear in the binary by chance. `volatile` keeps the tautological
395
+ // comparison (and the rest of the `CHECK`) from being optimized away.
396
+ const std::string var_needle = absl::Base64Escape("StrippingTestCheckVar");
397
+ const std::string msg_needle = absl::Base64Escape("StrippingTest.Check");
398
+ volatile int U3RyaXBwaW5nVGVzdENoZWNrVmFy = 0xCAFE;
399
+ // We don't care if the CHECK is actually executed, just that stripping works.
400
+ // Hiding it behind `kReallyDie` works around some overly aggressive
401
+ // optimizations in older versions of MSVC.
402
+ if (kReallyDie) {
403
+ CHECK(U3RyaXBwaW5nVGVzdENoZWNrVmFy != U3RyaXBwaW5nVGVzdENoZWNrVmFy)
404
+ << "U3RyaXBwaW5nVGVzdC5DaGVjaw==";
405
+ }
406
+
407
+ std::unique_ptr<FILE, std::function<void(FILE*)>> exe = OpenTestExecutable();
408
+ ASSERT_THAT(exe, NotNull());
409
+ if (absl::LogSeverity::kFatal >= kAbslMinLogLevel) {
410
+ EXPECT_THAT(exe.get(), FileHasSubstr(var_needle));
411
+ EXPECT_THAT(exe.get(), FileHasSubstr(msg_needle));
412
+ } else {
413
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(var_needle)));
414
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(msg_needle)));
415
+ }
416
+ }
417
+
418
+ TEST_F(StrippingTest, CheckOp) {
419
+ // See `StrippingTest.Check` for some hairy implementation notes.
420
+ const std::string var_needle1 =
421
+ absl::Base64Escape("StrippingTestCheckOpVar1");
422
+ const std::string var_needle2 =
423
+ absl::Base64Escape("StrippingTestCheckOpVar2");
424
+ const std::string msg_needle = absl::Base64Escape("StrippingTest.CheckOp");
425
+ volatile int U3RyaXBwaW5nVGVzdENoZWNrT3BWYXIx = 0xFEED;
426
+ volatile int U3RyaXBwaW5nVGVzdENoZWNrT3BWYXIy = 0xCAFE;
427
+ if (kReallyDie) {
428
+ CHECK_EQ(U3RyaXBwaW5nVGVzdENoZWNrT3BWYXIx, U3RyaXBwaW5nVGVzdENoZWNrT3BWYXIy)
429
+ << "U3RyaXBwaW5nVGVzdC5DaGVja09w";
430
+ }
431
+
432
+ std::unique_ptr<FILE, std::function<void(FILE*)>> exe = OpenTestExecutable();
433
+ ASSERT_THAT(exe, NotNull());
434
+
435
+ if (absl::LogSeverity::kFatal >= kAbslMinLogLevel) {
436
+ EXPECT_THAT(exe.get(), FileHasSubstr(var_needle1));
437
+ EXPECT_THAT(exe.get(), FileHasSubstr(var_needle2));
438
+ EXPECT_THAT(exe.get(), FileHasSubstr(msg_needle));
439
+ } else {
440
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(var_needle1)));
441
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(var_needle2)));
442
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(msg_needle)));
443
+ }
444
+ }
445
+
446
+ TEST_F(StrippingTest, CheckStrOp) {
447
+ // See `StrippingTest.Check` for some hairy implementation notes.
448
+ const std::string var_needle1 =
449
+ absl::Base64Escape("StrippingTestCheckStrOpVar1");
450
+ const std::string var_needle2 =
451
+ absl::Base64Escape("StrippingTestCheckStrOpVar2");
452
+ const std::string msg_needle = absl::Base64Escape("StrippingTest.CheckStrOp");
453
+ const char *volatile U3RyaXBwaW5nVGVzdENoZWNrU3RyT3BWYXIx = "FEED";
454
+ const char *volatile U3RyaXBwaW5nVGVzdENoZWNrU3RyT3BWYXIy = "CAFE";
455
+ if (kReallyDie) {
456
+ CHECK_STREQ(U3RyaXBwaW5nVGVzdENoZWNrU3RyT3BWYXIx,
457
+ U3RyaXBwaW5nVGVzdENoZWNrU3RyT3BWYXIy)
458
+ << "U3RyaXBwaW5nVGVzdC5DaGVja1N0ck9w";
459
+ }
460
+
461
+ std::unique_ptr<FILE, std::function<void(FILE*)>> exe = OpenTestExecutable();
462
+ ASSERT_THAT(exe, NotNull());
463
+
464
+ if (absl::LogSeverity::kFatal >= kAbslMinLogLevel) {
465
+ EXPECT_THAT(exe.get(), FileHasSubstr(var_needle1));
466
+ EXPECT_THAT(exe.get(), FileHasSubstr(var_needle2));
467
+ EXPECT_THAT(exe.get(), FileHasSubstr(msg_needle));
468
+ } else {
469
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(var_needle1)));
470
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(var_needle2)));
471
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(msg_needle)));
472
+ }
473
+ }
474
+
475
+ TEST_F(StrippingTest, CheckOk) {
476
+ // See `StrippingTest.Check` for some hairy implementation notes.
477
+ const std::string var_needle = absl::Base64Escape("StrippingTestCheckOkVar1");
478
+ const std::string msg_needle = absl::Base64Escape("StrippingTest.CheckOk");
479
+ volatile bool x = false;
480
+ auto U3RyaXBwaW5nVGVzdENoZWNrT2tWYXIx = absl::OkStatus();
481
+ if (x) {
482
+ U3RyaXBwaW5nVGVzdENoZWNrT2tWYXIx =
483
+ absl::InvalidArgumentError("Stripping this is not my job!");
484
+ }
485
+ if (kReallyDie) {
486
+ CHECK_OK(U3RyaXBwaW5nVGVzdENoZWNrT2tWYXIx)
487
+ << "U3RyaXBwaW5nVGVzdC5DaGVja09r";
488
+ }
489
+
490
+ std::unique_ptr<FILE, std::function<void(FILE*)>> exe = OpenTestExecutable();
491
+ ASSERT_THAT(exe, NotNull());
492
+
493
+ if (absl::LogSeverity::kFatal >= kAbslMinLogLevel) {
494
+ EXPECT_THAT(exe.get(), FileHasSubstr(var_needle));
495
+ EXPECT_THAT(exe.get(), FileHasSubstr(msg_needle));
496
+ } else {
497
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(var_needle)));
498
+ EXPECT_THAT(exe.get(), Not(FileHasSubstr(msg_needle)));
499
+ }
500
+ }
501
+
502
+ } // namespace
weight/_dep/abseil-cpp/absl/log/vlog_is_on.h ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2022 The Abseil Authors.
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
+ // https://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
+ // File: log/vlog_is_on.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This header defines the `VLOG_IS_ON()` macro that controls the
20
+ // variable-verbosity conditional logging.
21
+ //
22
+ // It's used by `VLOG` in log.h, or it can also be used directly like this:
23
+ //
24
+ // if (VLOG_IS_ON(2)) {
25
+ // foo_server.RecomputeStatisticsExpensive();
26
+ // LOG(INFO) << foo_server.LastStatisticsAsString();
27
+ // }
28
+ //
29
+ // Each source file has an effective verbosity level that's a non-negative
30
+ // integer computed from the `--vmodule` and `--v` flags.
31
+ // `VLOG_IS_ON(n)` is true, and `VLOG(n)` logs, if that effective verbosity
32
+ // level is greater than or equal to `n`.
33
+ //
34
+ // `--vmodule` takes a comma-delimited list of key=value pairs. Each key is a
35
+ // pattern matched against filenames, and the values give the effective severity
36
+ // level applied to matching files. '?' and '*' characters in patterns are
37
+ // interpreted as single-character and zero-or-more-character wildcards.
38
+ // Patterns including a slash character are matched against full pathnames,
39
+ // while those without are matched against basenames only. One suffix (i.e. the
40
+ // last . and everything after it) is stripped from each filename prior to
41
+ // matching, as is the special suffix "-inl".
42
+ //
43
+ // Files are matched against globs in `--vmodule` in order, and the first match
44
+ // determines the verbosity level.
45
+ //
46
+ // Files which do not match any pattern in `--vmodule` use the value of `--v` as
47
+ // their effective verbosity level. The default is 0.
48
+ //
49
+ // SetVLOGLevel helper function is provided to do limited dynamic control over
50
+ // V-logging by appending to `--vmodule`. Because these go at the beginning of
51
+ // the list, they take priority over any globs previously added.
52
+ //
53
+ // Resetting --vmodule will override all previous modifications to `--vmodule`,
54
+ // including via SetVLOGLevel.
55
+
56
+ #ifndef ABSL_LOG_VLOG_IS_ON_H_
57
+ #define ABSL_LOG_VLOG_IS_ON_H_
58
+
59
+ #include "absl/log/absl_vlog_is_on.h" // IWYU pragma: export
60
+
61
+ // IWYU pragma: private, include "absl/log/log.h"
62
+
63
+ // Each VLOG_IS_ON call site gets its own VLogSite that registers with the
64
+ // global linked list of sites to asynchronously update its verbosity level on
65
+ // changes to --v or --vmodule. The verbosity can also be set by manually
66
+ // calling SetVLOGLevel.
67
+ //
68
+ // VLOG_IS_ON is not async signal safe, but it is guaranteed not to allocate
69
+ // new memory.
70
+ #define VLOG_IS_ON(verbose_level) ABSL_VLOG_IS_ON(verbose_level)
71
+
72
+ #endif // ABSL_LOG_VLOG_IS_ON_H_
weight/_dep/abseil-cpp/absl/memory/BUILD.bazel ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # Copyright 2019 The Abseil Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # https://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ load(
18
+ "//absl:copts/configure_copts.bzl",
19
+ "ABSL_DEFAULT_COPTS",
20
+ "ABSL_DEFAULT_LINKOPTS",
21
+ "ABSL_TEST_COPTS",
22
+ )
23
+
24
+ package(
25
+ default_visibility = ["//visibility:public"],
26
+ features = [
27
+ "header_modules",
28
+ "layering_check",
29
+ "parse_headers",
30
+ ],
31
+ )
32
+
33
+ licenses(["notice"])
34
+
35
+ cc_library(
36
+ name = "memory",
37
+ hdrs = ["memory.h"],
38
+ copts = ABSL_DEFAULT_COPTS,
39
+ defines = select({
40
+ "//conditions:default": [],
41
+ }),
42
+ linkopts = ABSL_DEFAULT_LINKOPTS,
43
+ deps = [
44
+ "//absl/base:core_headers",
45
+ "//absl/meta:type_traits",
46
+ ],
47
+ )
48
+
49
+ cc_test(
50
+ name = "memory_test",
51
+ srcs = ["memory_test.cc"],
52
+ copts = ABSL_TEST_COPTS,
53
+ linkopts = ABSL_DEFAULT_LINKOPTS,
54
+ deps = [
55
+ ":memory",
56
+ "//absl/base:core_headers",
57
+ "@com_google_googletest//:gtest",
58
+ "@com_google_googletest//:gtest_main",
59
+ ],
60
+ )
weight/_dep/abseil-cpp/absl/memory/CMakeLists.txt ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # Copyright 2017 The Abseil Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # https://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ absl_cc_library(
18
+ NAME
19
+ memory
20
+ HDRS
21
+ "memory.h"
22
+ COPTS
23
+ ${ABSL_DEFAULT_COPTS}
24
+ DEPS
25
+ absl::core_headers
26
+ absl::meta
27
+ PUBLIC
28
+ )
29
+
30
+ absl_cc_test(
31
+ NAME
32
+ memory_test
33
+ SRCS
34
+ "memory_test.cc"
35
+ COPTS
36
+ ${ABSL_TEST_COPTS}
37
+ DEPS
38
+ absl::memory
39
+ absl::core_headers
40
+ GTest::gmock_main
41
+ )
weight/_dep/abseil-cpp/absl/memory/memory.h ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2017 The Abseil Authors.
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
+ // https://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
+ // File: memory.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This header file contains utility functions for managing the creation and
20
+ // conversion of smart pointers. This file is an extension to the C++
21
+ // standard <memory> library header file.
22
+
23
+ #ifndef ABSL_MEMORY_MEMORY_H_
24
+ #define ABSL_MEMORY_MEMORY_H_
25
+
26
+ #include <cstddef>
27
+ #include <limits>
28
+ #include <memory>
29
+ #include <new>
30
+ #include <type_traits>
31
+ #include <utility>
32
+
33
+ #include "absl/base/macros.h"
34
+ #include "absl/meta/type_traits.h"
35
+
36
+ namespace absl {
37
+ ABSL_NAMESPACE_BEGIN
38
+
39
+ // -----------------------------------------------------------------------------
40
+ // Function Template: WrapUnique()
41
+ // -----------------------------------------------------------------------------
42
+ //
43
+ // Adopts ownership from a raw pointer and transfers it to the returned
44
+ // `std::unique_ptr`, whose type is deduced. Because of this deduction, *do not*
45
+ // specify the template type `T` when calling `WrapUnique`.
46
+ //
47
+ // Example:
48
+ // X* NewX(int, int);
49
+ // auto x = WrapUnique(NewX(1, 2)); // 'x' is std::unique_ptr<X>.
50
+ //
51
+ // Do not call WrapUnique with an explicit type, as in
52
+ // `WrapUnique<X>(NewX(1, 2))`. The purpose of WrapUnique is to automatically
53
+ // deduce the pointer type. If you wish to make the type explicit, just use
54
+ // `std::unique_ptr` directly.
55
+ //
56
+ // auto x = std::unique_ptr<X>(NewX(1, 2));
57
+ // - or -
58
+ // std::unique_ptr<X> x(NewX(1, 2));
59
+ //
60
+ // While `absl::WrapUnique` is useful for capturing the output of a raw
61
+ // pointer factory, prefer 'absl::make_unique<T>(args...)' over
62
+ // 'absl::WrapUnique(new T(args...))'.
63
+ //
64
+ // auto x = WrapUnique(new X(1, 2)); // works, but nonideal.
65
+ // auto x = make_unique<X>(1, 2); // safer, standard, avoids raw 'new'.
66
+ //
67
+ // Note that `absl::WrapUnique(p)` is valid only if `delete p` is a valid
68
+ // expression. In particular, `absl::WrapUnique()` cannot wrap pointers to
69
+ // arrays, functions or void, and it must not be used to capture pointers
70
+ // obtained from array-new expressions (even though that would compile!).
71
+ template <typename T>
72
+ std::unique_ptr<T> WrapUnique(T* ptr) {
73
+ static_assert(!std::is_array<T>::value, "array types are unsupported");
74
+ static_assert(std::is_object<T>::value, "non-object types are unsupported");
75
+ return std::unique_ptr<T>(ptr);
76
+ }
77
+
78
+ // -----------------------------------------------------------------------------
79
+ // Function Template: make_unique<T>()
80
+ // -----------------------------------------------------------------------------
81
+ //
82
+ // Creates a `std::unique_ptr<>`, while avoiding issues creating temporaries
83
+ // during the construction process. `absl::make_unique<>` also avoids redundant
84
+ // type declarations, by avoiding the need to explicitly use the `new` operator.
85
+ //
86
+ // https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique
87
+ //
88
+ // For more background on why `std::unique_ptr<T>(new T(a,b))` is problematic,
89
+ // see Herb Sutter's explanation on
90
+ // (Exception-Safe Function Calls)[https://herbsutter.com/gotw/_102/].
91
+ // (In general, reviewers should treat `new T(a,b)` with scrutiny.)
92
+ //
93
+ // Historical note: Abseil once provided a C++11 compatible implementation of
94
+ // the C++14's `std::make_unique`. Now that C++11 support has been sunsetted,
95
+ // `absl::make_unique` simply uses the STL-provided implementation. New code
96
+ // should use `std::make_unique`.
97
+ using std::make_unique;
98
+
99
+ // -----------------------------------------------------------------------------
100
+ // Function Template: RawPtr()
101
+ // -----------------------------------------------------------------------------
102
+ //
103
+ // Extracts the raw pointer from a pointer-like value `ptr`. `absl::RawPtr` is
104
+ // useful within templates that need to handle a complement of raw pointers,
105
+ // `std::nullptr_t`, and smart pointers.
106
+ template <typename T>
107
+ auto RawPtr(T&& ptr) -> decltype(std::addressof(*ptr)) {
108
+ // ptr is a forwarding reference to support Ts with non-const operators.
109
+ return (ptr != nullptr) ? std::addressof(*ptr) : nullptr;
110
+ }
111
+ inline std::nullptr_t RawPtr(std::nullptr_t) { return nullptr; }
112
+
113
+ // -----------------------------------------------------------------------------
114
+ // Function Template: ShareUniquePtr()
115
+ // -----------------------------------------------------------------------------
116
+ //
117
+ // Adopts a `std::unique_ptr` rvalue and returns a `std::shared_ptr` of deduced
118
+ // type. Ownership (if any) of the held value is transferred to the returned
119
+ // shared pointer.
120
+ //
121
+ // Example:
122
+ //
123
+ // auto up = absl::make_unique<int>(10);
124
+ // auto sp = absl::ShareUniquePtr(std::move(up)); // shared_ptr<int>
125
+ // CHECK_EQ(*sp, 10);
126
+ // CHECK(up == nullptr);
127
+ //
128
+ // Note that this conversion is correct even when T is an array type, and more
129
+ // generally it works for *any* deleter of the `unique_ptr` (single-object
130
+ // deleter, array deleter, or any custom deleter), since the deleter is adopted
131
+ // by the shared pointer as well. The deleter is copied (unless it is a
132
+ // reference).
133
+ //
134
+ // Implements the resolution of [LWG 2415](http://wg21.link/lwg2415), by which a
135
+ // null shared pointer does not attempt to call the deleter.
136
+ template <typename T, typename D>
137
+ std::shared_ptr<T> ShareUniquePtr(std::unique_ptr<T, D>&& ptr) {
138
+ return ptr ? std::shared_ptr<T>(std::move(ptr)) : std::shared_ptr<T>();
139
+ }
140
+
141
+ // -----------------------------------------------------------------------------
142
+ // Function Template: WeakenPtr()
143
+ // -----------------------------------------------------------------------------
144
+ //
145
+ // Creates a weak pointer associated with a given shared pointer. The returned
146
+ // value is a `std::weak_ptr` of deduced type.
147
+ //
148
+ // Example:
149
+ //
150
+ // auto sp = std::make_shared<int>(10);
151
+ // auto wp = absl::WeakenPtr(sp);
152
+ // CHECK_EQ(sp.get(), wp.lock().get());
153
+ // sp.reset();
154
+ // CHECK(wp.lock() == nullptr);
155
+ //
156
+ template <typename T>
157
+ std::weak_ptr<T> WeakenPtr(const std::shared_ptr<T>& ptr) {
158
+ return std::weak_ptr<T>(ptr);
159
+ }
160
+
161
+ // -----------------------------------------------------------------------------
162
+ // Class Template: pointer_traits
163
+ // -----------------------------------------------------------------------------
164
+ //
165
+ // Historical note: Abseil once provided an implementation of
166
+ // `std::pointer_traits` for platforms that had not yet provided it. Those
167
+ // platforms are no longer supported. New code should simply use
168
+ // `std::pointer_traits`.
169
+ using std::pointer_traits;
170
+
171
+ // -----------------------------------------------------------------------------
172
+ // Class Template: allocator_traits
173
+ // -----------------------------------------------------------------------------
174
+ //
175
+ // Historical note: Abseil once provided an implementation of
176
+ // `std::allocator_traits` for platforms that had not yet provided it. Those
177
+ // platforms are no longer supported. New code should simply use
178
+ // `std::allocator_traits`.
179
+ using std::allocator_traits;
180
+
181
+ namespace memory_internal {
182
+
183
+ // ExtractOr<E, O, D>::type evaluates to E<O> if possible. Otherwise, D.
184
+ template <template <typename> class Extract, typename Obj, typename Default,
185
+ typename>
186
+ struct ExtractOr {
187
+ using type = Default;
188
+ };
189
+
190
+ template <template <typename> class Extract, typename Obj, typename Default>
191
+ struct ExtractOr<Extract, Obj, Default, void_t<Extract<Obj>>> {
192
+ using type = Extract<Obj>;
193
+ };
194
+
195
+ template <template <typename> class Extract, typename Obj, typename Default>
196
+ using ExtractOrT = typename ExtractOr<Extract, Obj, Default, void>::type;
197
+
198
+ // This template alias transforms Alloc::is_nothrow into a metafunction with
199
+ // Alloc as a parameter so it can be used with ExtractOrT<>.
200
+ template <typename Alloc>
201
+ using GetIsNothrow = typename Alloc::is_nothrow;
202
+
203
+ } // namespace memory_internal
204
+
205
+ // ABSL_ALLOCATOR_NOTHROW is a build time configuration macro for user to
206
+ // specify whether the default allocation function can throw or never throws.
207
+ // If the allocation function never throws, user should define it to a non-zero
208
+ // value (e.g. via `-DABSL_ALLOCATOR_NOTHROW`).
209
+ // If the allocation function can throw, user should leave it undefined or
210
+ // define it to zero.
211
+ //
212
+ // allocator_is_nothrow<Alloc> is a traits class that derives from
213
+ // Alloc::is_nothrow if present, otherwise std::false_type. It's specialized
214
+ // for Alloc = std::allocator<T> for any type T according to the state of
215
+ // ABSL_ALLOCATOR_NOTHROW.
216
+ //
217
+ // default_allocator_is_nothrow is a class that derives from std::true_type
218
+ // when the default allocator (global operator new) never throws, and
219
+ // std::false_type when it can throw. It is a convenience shorthand for writing
220
+ // allocator_is_nothrow<std::allocator<T>> (T can be any type).
221
+ // NOTE: allocator_is_nothrow<std::allocator<T>> is guaranteed to derive from
222
+ // the same type for all T, because users should specialize neither
223
+ // allocator_is_nothrow nor std::allocator.
224
+ template <typename Alloc>
225
+ struct allocator_is_nothrow
226
+ : memory_internal::ExtractOrT<memory_internal::GetIsNothrow, Alloc,
227
+ std::false_type> {};
228
+
229
+ #if defined(ABSL_ALLOCATOR_NOTHROW) && ABSL_ALLOCATOR_NOTHROW
230
+ template <typename T>
231
+ struct allocator_is_nothrow<std::allocator<T>> : std::true_type {};
232
+ struct default_allocator_is_nothrow : std::true_type {};
233
+ #else
234
+ struct default_allocator_is_nothrow : std::false_type {};
235
+ #endif
236
+
237
+ namespace memory_internal {
238
+ template <typename Allocator, typename Iterator, typename... Args>
239
+ void ConstructRange(Allocator& alloc, Iterator first, Iterator last,
240
+ const Args&... args) {
241
+ for (Iterator cur = first; cur != last; ++cur) {
242
+ ABSL_INTERNAL_TRY {
243
+ std::allocator_traits<Allocator>::construct(alloc, std::addressof(*cur),
244
+ args...);
245
+ }
246
+ ABSL_INTERNAL_CATCH_ANY {
247
+ while (cur != first) {
248
+ --cur;
249
+ std::allocator_traits<Allocator>::destroy(alloc, std::addressof(*cur));
250
+ }
251
+ ABSL_INTERNAL_RETHROW;
252
+ }
253
+ }
254
+ }
255
+
256
+ template <typename Allocator, typename Iterator, typename InputIterator>
257
+ void CopyRange(Allocator& alloc, Iterator destination, InputIterator first,
258
+ InputIterator last) {
259
+ for (Iterator cur = destination; first != last;
260
+ static_cast<void>(++cur), static_cast<void>(++first)) {
261
+ ABSL_INTERNAL_TRY {
262
+ std::allocator_traits<Allocator>::construct(alloc, std::addressof(*cur),
263
+ *first);
264
+ }
265
+ ABSL_INTERNAL_CATCH_ANY {
266
+ while (cur != destination) {
267
+ --cur;
268
+ std::allocator_traits<Allocator>::destroy(alloc, std::addressof(*cur));
269
+ }
270
+ ABSL_INTERNAL_RETHROW;
271
+ }
272
+ }
273
+ }
274
+ } // namespace memory_internal
275
+ ABSL_NAMESPACE_END
276
+ } // namespace absl
277
+
278
+ #endif // ABSL_MEMORY_MEMORY_H_
weight/_dep/abseil-cpp/absl/memory/memory_test.cc ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright 2017 The Abseil Authors.
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
+ // https://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
+ // Tests for pointer utilities.
16
+
17
+ #include "absl/memory/memory.h"
18
+
19
+ #include <sys/types.h>
20
+
21
+ #include <cstddef>
22
+ #include <memory>
23
+ #include <string>
24
+ #include <type_traits>
25
+ #include <utility>
26
+ #include <vector>
27
+
28
+ #include "gmock/gmock.h"
29
+ #include "gtest/gtest.h"
30
+
31
+ namespace {
32
+
33
+ using ::testing::ElementsAre;
34
+ using ::testing::Return;
35
+
36
+ // This class creates observable behavior to verify that a destructor has
37
+ // been called, via the instance_count variable.
38
+ class DestructorVerifier {
39
+ public:
40
+ DestructorVerifier() { ++instance_count_; }
41
+ DestructorVerifier(const DestructorVerifier&) = delete;
42
+ DestructorVerifier& operator=(const DestructorVerifier&) = delete;
43
+ ~DestructorVerifier() { --instance_count_; }
44
+
45
+ // The number of instances of this class currently active.
46
+ static int instance_count() { return instance_count_; }
47
+
48
+ private:
49
+ // The number of instances of this class currently active.
50
+ static int instance_count_;
51
+ };
52
+
53
+ int DestructorVerifier::instance_count_ = 0;
54
+
55
+ TEST(WrapUniqueTest, WrapUnique) {
56
+ // Test that the unique_ptr is constructed properly by verifying that the
57
+ // destructor for its payload gets called at the proper time.
58
+ {
59
+ auto dv = new DestructorVerifier;
60
+ EXPECT_EQ(1, DestructorVerifier::instance_count());
61
+ std::unique_ptr<DestructorVerifier> ptr = absl::WrapUnique(dv);
62
+ EXPECT_EQ(1, DestructorVerifier::instance_count());
63
+ }
64
+ EXPECT_EQ(0, DestructorVerifier::instance_count());
65
+ }
66
+
67
+ // InitializationVerifier fills in a pattern when allocated so we can
68
+ // distinguish between its default and value initialized states (without
69
+ // accessing truly uninitialized memory).
70
+ struct InitializationVerifier {
71
+ static constexpr int kDefaultScalar = 0x43;
72
+ static constexpr int kDefaultArray = 0x4B;
73
+
74
+ static void* operator new(size_t n) {
75
+ void* ret = ::operator new(n);
76
+ memset(ret, kDefaultScalar, n);
77
+ return ret;
78
+ }
79
+
80
+ static void* operator new[](size_t n) {
81
+ void* ret = ::operator new[](n);
82
+ memset(ret, kDefaultArray, n);
83
+ return ret;
84
+ }
85
+
86
+ int a;
87
+ int b;
88
+ };
89
+
90
+ struct ArrayWatch {
91
+ void* operator new[](size_t n) {
92
+ allocs().push_back(n);
93
+ return ::operator new[](n);
94
+ }
95
+ void operator delete[](void* p) { return ::operator delete[](p); }
96
+ static std::vector<size_t>& allocs() {
97
+ static auto& v = *new std::vector<size_t>;
98
+ return v;
99
+ }
100
+ };
101
+
102
+ TEST(RawPtrTest, RawPointer) {
103
+ int i = 5;
104
+ EXPECT_EQ(&i, absl::RawPtr(&i));
105
+ }
106
+
107
+ TEST(RawPtrTest, SmartPointer) {
108
+ int* o = new int(5);
109
+ std::unique_ptr<int> p(o);
110
+ EXPECT_EQ(o, absl::RawPtr(p));
111
+ }
112
+
113
+ class IntPointerNonConstDeref {
114
+ public:
115
+ explicit IntPointerNonConstDeref(int* p) : p_(p) {}
116
+ friend bool operator!=(const IntPointerNonConstDeref& a, std::nullptr_t) {
117
+ return a.p_ != nullptr;
118
+ }
119
+ int& operator*() { return *p_; }
120
+
121
+ private:
122
+ std::unique_ptr<int> p_;
123
+ };
124
+
125
+ TEST(RawPtrTest, SmartPointerNonConstDereference) {
126
+ int* o = new int(5);
127
+ IntPointerNonConstDeref p(o);
128
+ EXPECT_EQ(o, absl::RawPtr(p));
129
+ }
130
+
131
+ TEST(RawPtrTest, NullValuedRawPointer) {
132
+ int* p = nullptr;
133
+ EXPECT_EQ(nullptr, absl::RawPtr(p));
134
+ }
135
+
136
+ TEST(RawPtrTest, NullValuedSmartPointer) {
137
+ std::unique_ptr<int> p;
138
+ EXPECT_EQ(nullptr, absl::RawPtr(p));
139
+ }
140
+
141
+ TEST(RawPtrTest, Nullptr) {
142
+ auto p = absl::RawPtr(nullptr);
143
+ EXPECT_TRUE((std::is_same<std::nullptr_t, decltype(p)>::value));
144
+ EXPECT_EQ(nullptr, p);
145
+ }
146
+
147
+ TEST(RawPtrTest, Null) {
148
+ auto p = absl::RawPtr(nullptr);
149
+ EXPECT_TRUE((std::is_same<std::nullptr_t, decltype(p)>::value));
150
+ EXPECT_EQ(nullptr, p);
151
+ }
152
+
153
+ TEST(RawPtrTest, Zero) {
154
+ auto p = absl::RawPtr(nullptr);
155
+ EXPECT_TRUE((std::is_same<std::nullptr_t, decltype(p)>::value));
156
+ EXPECT_EQ(nullptr, p);
157
+ }
158
+
159
+ TEST(ShareUniquePtrTest, Share) {
160
+ auto up = absl::make_unique<int>();
161
+ int* rp = up.get();
162
+ auto sp = absl::ShareUniquePtr(std::move(up));
163
+ EXPECT_EQ(sp.get(), rp);
164
+ }
165
+
166
+ TEST(ShareUniquePtrTest, ShareNull) {
167
+ struct NeverDie {
168
+ using pointer = void*;
169
+ void operator()(pointer) {
170
+ ASSERT_TRUE(false) << "Deleter should not have been called.";
171
+ }
172
+ };
173
+
174
+ std::unique_ptr<void, NeverDie> up;
175
+ auto sp = absl::ShareUniquePtr(std::move(up));
176
+ }
177
+
178
+ TEST(WeakenPtrTest, Weak) {
179
+ auto sp = std::make_shared<int>();
180
+ auto wp = absl::WeakenPtr(sp);
181
+ EXPECT_EQ(sp.get(), wp.lock().get());
182
+ sp.reset();
183
+ EXPECT_TRUE(wp.expired());
184
+ }
185
+
186
+ // Should not compile.
187
+ /*
188
+ TEST(RawPtrTest, NotAPointer) {
189
+ absl::RawPtr(1.5);
190
+ }
191
+ */
192
+
193
+ TEST(AllocatorNoThrowTest, DefaultAllocator) {
194
+ #if defined(ABSL_ALLOCATOR_NOTHROW) && ABSL_ALLOCATOR_NOTHROW
195
+ EXPECT_TRUE(absl::default_allocator_is_nothrow::value);
196
+ #else
197
+ EXPECT_FALSE(absl::default_allocator_is_nothrow::value);
198
+ #endif
199
+ }
200
+
201
+ TEST(AllocatorNoThrowTest, StdAllocator) {
202
+ #if defined(ABSL_ALLOCATOR_NOTHROW) && ABSL_ALLOCATOR_NOTHROW
203
+ EXPECT_TRUE(absl::allocator_is_nothrow<std::allocator<int>>::value);
204
+ #else
205
+ EXPECT_FALSE(absl::allocator_is_nothrow<std::allocator<int>>::value);
206
+ #endif
207
+ }
208
+
209
+ TEST(AllocatorNoThrowTest, CustomAllocator) {
210
+ struct NoThrowAllocator {
211
+ using is_nothrow = std::true_type;
212
+ };
213
+ struct CanThrowAllocator {
214
+ using is_nothrow = std::false_type;
215
+ };
216
+ struct UnspecifiedAllocator {};
217
+ EXPECT_TRUE(absl::allocator_is_nothrow<NoThrowAllocator>::value);
218
+ EXPECT_FALSE(absl::allocator_is_nothrow<CanThrowAllocator>::value);
219
+ EXPECT_FALSE(absl::allocator_is_nothrow<UnspecifiedAllocator>::value);
220
+ }
221
+
222
+ } // namespace
weight/_dep/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/America/Cambridge_Bay ADDED
Binary file (883 Bytes). View file
 
weight/_dep/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/America/Campo_Grande ADDED
Binary file (952 Bytes). View file
 
weight/_dep/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/America/Cayman ADDED
Binary file (149 Bytes). View file
 
weight/_dep/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/America/Chihuahua ADDED
Binary file (691 Bytes). View file
 
weight/_dep/abseil-cpp/absl/time/internal/cctz/testdata/zoneinfo/America/Cordoba ADDED
Binary file (708 Bytes). View file