re2 1.10.2 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/.prettierrc +3 -1
  2. package/.travis.yml +1 -1
  3. package/README.md +9 -8
  4. package/lib/addon.cc +4 -6
  5. package/lib/exec.cc +8 -0
  6. package/lib/wrapped_re2.h +1 -1
  7. package/package.json +5 -3
  8. package/re2.d.ts +5 -1
  9. package/tests/test_exec.js +1 -0
  10. package/vendor/re2/bitstate.cc +5 -1
  11. package/vendor/re2/compile.cc +1 -1
  12. package/vendor/re2/dfa.cc +8 -11
  13. package/vendor/re2/nfa.cc +33 -16
  14. package/vendor/re2/onepass.cc +4 -4
  15. package/vendor/re2/parse.cc +32 -32
  16. package/vendor/{util → re2}/pod_array.h +3 -3
  17. package/vendor/re2/prefilter_tree.h +1 -1
  18. package/vendor/re2/prog.h +3 -3
  19. package/vendor/re2/re2.cc +3 -3
  20. package/vendor/re2/set.cc +2 -2
  21. package/vendor/re2/simplify.cc +1 -1
  22. package/vendor/{util → re2}/sparse_array.h +4 -4
  23. package/vendor/{util → re2}/sparse_set.h +4 -4
  24. package/vendor/re2/testing/backtrack.cc +4 -0
  25. package/vendor/re2/testing/dfa_test.cc +12 -10
  26. package/vendor/re2/testing/dump.cc +4 -10
  27. package/vendor/re2/testing/exhaustive1_test.cc +2 -7
  28. package/vendor/re2/testing/exhaustive2_test.cc +0 -1
  29. package/vendor/re2/testing/exhaustive_tester.cc +11 -8
  30. package/vendor/re2/testing/random_test.cc +9 -7
  31. package/vendor/re2/testing/regexp_benchmark.cc +435 -404
  32. package/vendor/re2/testing/regexp_generator.cc +1 -1
  33. package/vendor/re2/testing/tester.cc +19 -14
  34. package/vendor/re2/walker-inl.h +1 -1
  35. package/vendor/util/benchmark.cc +83 -113
  36. package/vendor/util/benchmark.h +138 -25
  37. package/vendor/util/flags.h +8 -11
  38. package/vendor/util/malloc_counter.h +19 -0
  39. package/vendor/util/pcre.cc +7 -31
  40. package/vendor/util/test.cc +4 -1
  41. package/vendor/util/test.h +4 -12
  42. package/vendor/util/util.h +8 -0
@@ -256,7 +256,7 @@ std::vector<std::string> Explode(const StringPiece& s) {
256
256
  std::vector<std::string> Split(const StringPiece& sep, const StringPiece& s) {
257
257
  std::vector<std::string> v;
258
258
 
259
- if (sep.size() == 0)
259
+ if (sep.empty())
260
260
  return Explode(s);
261
261
 
262
262
  const char *p = s.data();
@@ -18,14 +18,15 @@
18
18
  #include "re2/re2.h"
19
19
  #include "re2/regexp.h"
20
20
 
21
- DEFINE_bool(dump_prog, false, "dump regexp program");
22
- DEFINE_bool(log_okay, false, "log successful runs");
23
- DEFINE_bool(dump_rprog, false, "dump reversed regexp program");
21
+ DEFINE_FLAG(bool, dump_prog, false, "dump regexp program");
22
+ DEFINE_FLAG(bool, log_okay, false, "log successful runs");
23
+ DEFINE_FLAG(bool, dump_rprog, false, "dump reversed regexp program");
24
24
 
25
- DEFINE_int32(max_regexp_failures, 100,
26
- "maximum number of regexp test failures (-1 = unlimited)");
25
+ DEFINE_FLAG(int, max_regexp_failures, 100,
26
+ "maximum number of regexp test failures (-1 = unlimited)");
27
27
 
28
- DEFINE_string(regexp_engines, "", "pattern to select regexp engines to test");
28
+ DEFINE_FLAG(std::string, regexp_engines, "",
29
+ "pattern to select regexp engines to test");
29
30
 
30
31
  namespace re2 {
31
32
 
@@ -62,11 +63,11 @@ static uint32_t Engines() {
62
63
  if (did_parse)
63
64
  return cached_engines;
64
65
 
65
- if (FLAGS_regexp_engines.empty()) {
66
+ if (GetFlag(FLAGS_regexp_engines).empty()) {
66
67
  cached_engines = ~0;
67
68
  } else {
68
69
  for (Engine i = static_cast<Engine>(0); i < kEngineMax; i++)
69
- if (FLAGS_regexp_engines.find(EngineName(i)) != std::string::npos)
70
+ if (GetFlag(FLAGS_regexp_engines).find(EngineName(i)) != std::string::npos)
70
71
  cached_engines |= 1<<i;
71
72
  }
72
73
 
@@ -102,7 +103,8 @@ static std::string FormatCapture(const StringPiece& text,
102
103
  if (s.data() == NULL)
103
104
  return "(?,?)";
104
105
  return StringPrintf("(%td,%td)",
105
- s.begin() - text.begin(), s.end() - text.begin());
106
+ s.begin() - text.begin(),
107
+ s.end() - text.begin());
106
108
  }
107
109
 
108
110
  // Returns whether text contains non-ASCII (>= 0x80) bytes.
@@ -198,7 +200,7 @@ TestInstance::TestInstance(const StringPiece& regexp_str, Prog::MatchKind kind,
198
200
  error_ = true;
199
201
  return;
200
202
  }
201
- if (FLAGS_dump_prog) {
203
+ if (GetFlag(FLAGS_dump_prog)) {
202
204
  LOG(INFO) << "Prog for "
203
205
  << " regexp "
204
206
  << CEscape(regexp_str_)
@@ -216,7 +218,7 @@ TestInstance::TestInstance(const StringPiece& regexp_str, Prog::MatchKind kind,
216
218
  error_ = true;
217
219
  return;
218
220
  }
219
- if (FLAGS_dump_rprog)
221
+ if (GetFlag(FLAGS_dump_rprog))
220
222
  LOG(INFO) << rprog_->Dump();
221
223
  }
222
224
 
@@ -528,7 +530,7 @@ bool TestInstance::RunCase(const StringPiece& text, const StringPiece& context,
528
530
  Result r;
529
531
  RunSearch(i, text, context, anchor, &r);
530
532
  if (ResultOkay(r, correct)) {
531
- if (FLAGS_log_okay)
533
+ if (GetFlag(FLAGS_log_okay))
532
534
  LogMatch(r.skipped ? "Skipped: " : "Okay: ", i, text, context, anchor);
533
535
  continue;
534
536
  }
@@ -571,7 +573,10 @@ bool TestInstance::RunCase(const StringPiece& text, const StringPiece& context,
571
573
  }
572
574
 
573
575
  if (!all_okay) {
574
- if (FLAGS_max_regexp_failures > 0 && --FLAGS_max_regexp_failures == 0)
576
+ // This will be initialised once (after flags have been initialised)
577
+ // and that is desirable because we want to enforce a global limit.
578
+ static int max_regexp_failures = GetFlag(FLAGS_max_regexp_failures);
579
+ if (max_regexp_failures > 0 && --max_regexp_failures == 0)
575
580
  LOG(QFATAL) << "Too many regexp failures.";
576
581
  }
577
582
 
@@ -640,7 +645,7 @@ static Prog::Anchor anchors[] = {
640
645
 
641
646
  bool Tester::TestInput(const StringPiece& text) {
642
647
  bool okay = TestInputInContext(text, text);
643
- if (text.size() > 0) {
648
+ if (!text.empty()) {
644
649
  StringPiece sp;
645
650
  sp = text;
646
651
  sp.remove_prefix(1);
@@ -150,7 +150,7 @@ template<typename T> void Regexp::Walker<T>::Reset() {
150
150
  if (stack_ && stack_->size() > 0) {
151
151
  LOG(DFATAL) << "Stack not empty.";
152
152
  while (stack_->size() > 0) {
153
- delete stack_->top().child_args;
153
+ delete[] stack_->top().child_args;
154
154
  stack_->pop();
155
155
  }
156
156
  }
@@ -7,155 +7,125 @@
7
7
  #include <stdlib.h>
8
8
  #include <algorithm>
9
9
  #include <chrono>
10
- #include <thread>
11
10
 
12
- #include "util/util.h"
13
- #include "util/flags.h"
14
11
  #include "util/benchmark.h"
12
+ #include "util/flags.h"
15
13
  #include "re2/re2.h"
16
14
 
17
- DEFINE_string(test_tmpdir, "/var/tmp", "temp directory");
18
-
19
15
  #ifdef _WIN32
20
16
  #define snprintf _snprintf
21
17
  #endif
22
18
 
23
- using testing::Benchmark;
19
+ using ::testing::Benchmark;
24
20
 
25
21
  static Benchmark* benchmarks[10000];
26
22
  static int nbenchmarks;
27
23
 
28
24
  void Benchmark::Register() {
29
- benchmarks[nbenchmarks] = this;
30
- if(lo < 1)
31
- lo = 1;
32
- if(hi < lo)
33
- hi = lo;
34
- nbenchmarks++;
25
+ lo_ = std::max(1, lo_);
26
+ hi_ = std::max(lo_, hi_);
27
+ benchmarks[nbenchmarks++] = this;
35
28
  }
36
29
 
37
30
  static int64_t nsec() {
38
- return std::chrono::duration_cast<std::chrono::nanoseconds>(
39
- std::chrono::steady_clock::now().time_since_epoch()).count();
31
+ return std::chrono::duration_cast<std::chrono::nanoseconds>(
32
+ std::chrono::steady_clock::now().time_since_epoch())
33
+ .count();
40
34
  }
41
35
 
42
- static int64_t bytes;
43
- static int64_t ns;
44
36
  static int64_t t0;
37
+ static int64_t ns;
38
+ static int64_t bytes;
45
39
  static int64_t items;
46
40
 
47
- void SetBenchmarkBytesProcessed(int64_t x) {
48
- bytes = x;
49
- }
50
-
51
- void StopBenchmarkTiming() {
52
- if(t0 != 0)
53
- ns += nsec() - t0;
54
- t0 = 0;
55
- }
56
-
57
41
  void StartBenchmarkTiming() {
58
- if(t0 == 0)
59
- t0 = nsec();
42
+ if (t0 == 0) {
43
+ t0 = nsec();
44
+ }
60
45
  }
61
46
 
62
- void SetBenchmarkItemsProcessed(int n) {
63
- items = n;
47
+ void StopBenchmarkTiming() {
48
+ if (t0 != 0) {
49
+ ns += nsec() - t0;
50
+ t0 = 0;
51
+ }
64
52
  }
65
53
 
66
- void BenchmarkMemoryUsage() {
67
- // TODO(rsc): Implement.
68
- }
54
+ void SetBenchmarkBytesProcessed(int64_t b) { bytes = b; }
69
55
 
70
- int NumCPUs() {
71
- return static_cast<int>(std::thread::hardware_concurrency());
72
- }
56
+ void SetBenchmarkItemsProcessed(int64_t i) { items = i; }
73
57
 
74
- static void runN(Benchmark *b, int n, int siz) {
75
- bytes = 0;
76
- items = 0;
77
- ns = 0;
78
- t0 = nsec();
79
- if(b->fn)
80
- b->fn(n);
81
- else if(b->fnr)
82
- b->fnr(n, siz);
83
- else {
84
- fprintf(stderr, "%s: missing function\n", b->name);
85
- abort();
86
- }
87
- if(t0 != 0)
88
- ns += nsec() - t0;
58
+ static void RunFunc(Benchmark* b, int iters, int arg) {
59
+ t0 = nsec();
60
+ ns = 0;
61
+ bytes = 0;
62
+ items = 0;
63
+ b->func()(iters, arg);
64
+ StopBenchmarkTiming();
89
65
  }
90
66
 
91
67
  static int round(int n) {
92
- int base = 1;
93
-
94
- while(base*10 < n)
95
- base *= 10;
96
- if(n < 2*base)
97
- return 2*base;
98
- if(n < 5*base)
99
- return 5*base;
100
- return 10*base;
68
+ int base = 1;
69
+ while (base * 10 < n) base *= 10;
70
+ if (n < 2 * base) return 2 * base;
71
+ if (n < 5 * base) return 5 * base;
72
+ return 10 * base;
101
73
  }
102
74
 
103
- void RunBench(Benchmark* b, int nthread, int siz) {
104
- int n, last;
105
-
106
- // TODO(rsc): Threaded benchmarks.
107
- if(nthread != 1)
108
- return;
109
-
110
- // run once in case it's expensive
111
- n = 1;
112
- runN(b, n, siz);
113
- while(ns < (int)1e9 && n < (int)1e9) {
114
- last = n;
115
- if(ns/n == 0)
116
- n = (int)1e9;
117
- else
118
- n = (int)1e9 / static_cast<int>(ns/n);
119
-
120
- n = std::max(last+1, std::min(n+n/2, 100*last));
121
- n = round(n);
122
- runN(b, n, siz);
123
- }
124
-
125
- char mb[100];
126
- char suf[100];
127
- mb[0] = '\0';
128
- suf[0] = '\0';
129
- if(ns > 0 && bytes > 0)
130
- snprintf(mb, sizeof mb, "\t%7.2f MB/s", ((double)bytes/1e6)/((double)ns/1e9));
131
- if(b->fnr || b->lo != b->hi) {
132
- if(siz >= (1<<20))
133
- snprintf(suf, sizeof suf, "/%dM", siz/(1<<20));
134
- else if(siz >= (1<<10))
135
- snprintf(suf, sizeof suf, "/%dK", siz/(1<<10));
136
- else
137
- snprintf(suf, sizeof suf, "/%d", siz);
138
- }
139
- printf("%s%s\t%8lld\t%10lld ns/op%s\n", b->name, suf, (long long)n, (long long)ns/n, mb);
140
- fflush(stdout);
75
+ static void RunBench(Benchmark* b, int arg) {
76
+ int iters, last;
77
+
78
+ // Run once just in case it's expensive.
79
+ iters = 1;
80
+ RunFunc(b, iters, arg);
81
+ while (ns < (int)1e9 && iters < (int)1e9) {
82
+ last = iters;
83
+ if (ns / iters == 0) {
84
+ iters = (int)1e9;
85
+ } else {
86
+ iters = (int)1e9 / static_cast<int>(ns / iters);
87
+ }
88
+ iters = std::max(last + 1, std::min(iters + iters / 2, 100 * last));
89
+ iters = round(iters);
90
+ RunFunc(b, iters, arg);
91
+ }
92
+
93
+ char mb[100];
94
+ char suf[100];
95
+ mb[0] = '\0';
96
+ suf[0] = '\0';
97
+ if (ns > 0 && bytes > 0)
98
+ snprintf(mb, sizeof mb, "\t%7.2f MB/s",
99
+ ((double)bytes / 1e6) / ((double)ns / 1e9));
100
+ if (b->has_arg()) {
101
+ if (arg >= (1 << 20)) {
102
+ snprintf(suf, sizeof suf, "/%dM", arg / (1 << 20));
103
+ } else if (arg >= (1 << 10)) {
104
+ snprintf(suf, sizeof suf, "/%dK", arg / (1 << 10));
105
+ } else {
106
+ snprintf(suf, sizeof suf, "/%d", arg);
107
+ }
108
+ }
109
+ printf("%s%s\t%8d\t%10lld ns/op%s\n", b->name(), suf, iters,
110
+ (long long)ns / iters, mb);
111
+ fflush(stdout);
141
112
  }
142
113
 
143
- static int match(const char* name, int argc, const char** argv) {
144
- if(argc == 1)
145
- return 1;
146
- for(int i = 1; i < argc; i++)
147
- if(RE2::PartialMatch(name, argv[i]))
148
- return 1;
149
- return 0;
114
+ static bool WantBench(const char* name, int argc, const char** argv) {
115
+ if (argc == 1) return true;
116
+ for (int i = 1; i < argc; i++) {
117
+ if (RE2::PartialMatch(name, argv[i]))
118
+ return true;
119
+ }
120
+ return false;
150
121
  }
151
122
 
152
123
  int main(int argc, const char** argv) {
153
- for(int i = 0; i < nbenchmarks; i++) {
154
- Benchmark* b = benchmarks[i];
155
- if(match(b->name, argc, argv))
156
- for(int j = b->threadlo; j <= b->threadhi; j++)
157
- for(int k = std::max(b->lo, 1); k <= std::max(b->hi, 1); k<<=1)
158
- RunBench(b, j, k);
159
- }
124
+ for (int i = 0; i < nbenchmarks; i++) {
125
+ Benchmark* b = benchmarks[i];
126
+ if (!WantBench(b->name(), argc, argv))
127
+ continue;
128
+ for (int arg = b->lo(); arg <= b->hi(); arg <<= 1)
129
+ RunBench(b, arg);
130
+ }
160
131
  }
161
-
@@ -6,38 +6,151 @@
6
6
  #define UTIL_BENCHMARK_H_
7
7
 
8
8
  #include <stdint.h>
9
+ #include <functional>
10
+
11
+ #include "util/logging.h"
12
+ #include "util/util.h"
13
+
14
+ // Globals for the old benchmark API.
15
+ void StartBenchmarkTiming();
16
+ void StopBenchmarkTiming();
17
+ void SetBenchmarkBytesProcessed(int64_t b);
18
+ void SetBenchmarkItemsProcessed(int64_t i);
19
+
20
+ namespace benchmark {
21
+
22
+ // The new benchmark API implemented as a layer over the old benchmark API.
23
+ // (Please refer to https://github.com/google/benchmark for documentation.)
24
+ class State {
25
+ private:
26
+ class Iterator {
27
+ public:
28
+ // Benchmark code looks like this:
29
+ //
30
+ // for (auto _ : state) {
31
+ // // ...
32
+ // }
33
+ //
34
+ // We try to avoid compiler warnings about such variables being unused.
35
+ struct ATTRIBUTE_UNUSED Value {};
36
+
37
+ explicit Iterator(int64_t iters) : iters_(iters) {}
38
+
39
+ bool operator!=(const Iterator& that) const {
40
+ if (iters_ != that.iters_) {
41
+ return true;
42
+ } else {
43
+ // We are about to stop the loop, so stop timing.
44
+ StopBenchmarkTiming();
45
+ return false;
46
+ }
47
+ }
48
+
49
+ Value operator*() const {
50
+ return Value();
51
+ }
52
+
53
+ Iterator& operator++() {
54
+ --iters_;
55
+ return *this;
56
+ }
57
+
58
+ private:
59
+ int64_t iters_;
60
+ };
61
+
62
+ public:
63
+ explicit State(int64_t iters)
64
+ : iters_(iters), arg_(0), has_arg_(false) {}
65
+
66
+ State(int64_t iters, int64_t arg)
67
+ : iters_(iters), arg_(arg), has_arg_(true) {}
68
+
69
+ Iterator begin() {
70
+ // We are about to start the loop, so start timing.
71
+ StartBenchmarkTiming();
72
+ return Iterator(iters_);
73
+ }
74
+
75
+ Iterator end() {
76
+ return Iterator(0);
77
+ }
78
+
79
+ void SetBytesProcessed(int64_t b) { SetBenchmarkBytesProcessed(b); }
80
+ void SetItemsProcessed(int64_t i) { SetBenchmarkItemsProcessed(i); }
81
+ int64_t iterations() const { return iters_; }
82
+ // Pretend to support multiple arguments.
83
+ int64_t range(int pos) const { CHECK(has_arg_); return arg_; }
84
+
85
+ private:
86
+ int64_t iters_;
87
+ int64_t arg_;
88
+ bool has_arg_;
89
+
90
+ State(const State&) = delete;
91
+ State& operator=(const State&) = delete;
92
+ };
93
+
94
+ } // namespace benchmark
9
95
 
10
96
  namespace testing {
11
- struct Benchmark {
12
- const char* name;
13
- void (*fn)(int);
14
- void (*fnr)(int, int);
15
- int lo;
16
- int hi;
17
- int threadlo;
18
- int threadhi;
19
97
 
98
+ class Benchmark {
99
+ public:
100
+ Benchmark(const char* name, void (*func)(benchmark::State&))
101
+ : name_(name),
102
+ func_([func](int iters, int arg) {
103
+ benchmark::State state(iters);
104
+ func(state);
105
+ }),
106
+ lo_(0),
107
+ hi_(0),
108
+ has_arg_(false) {
109
+ Register();
110
+ }
111
+
112
+ Benchmark(const char* name, void (*func)(benchmark::State&), int lo, int hi)
113
+ : name_(name),
114
+ func_([func](int iters, int arg) {
115
+ benchmark::State state(iters, arg);
116
+ func(state);
117
+ }),
118
+ lo_(lo),
119
+ hi_(hi),
120
+ has_arg_(true) {
121
+ Register();
122
+ }
123
+
124
+ // Pretend to support multiple threads.
125
+ Benchmark* ThreadRange(int lo, int hi) { return this; }
126
+
127
+ const char* name() const { return name_; }
128
+ const std::function<void(int, int)>& func() const { return func_; }
129
+ int lo() const { return lo_; }
130
+ int hi() const { return hi_; }
131
+ bool has_arg() const { return has_arg_; }
132
+
133
+ private:
20
134
  void Register();
21
- Benchmark(const char* name, void (*f)(int)) { Clear(name); fn = f; Register(); }
22
- Benchmark(const char* name, void (*f)(int, int), int l, int h) { Clear(name); fnr = f; lo = l; hi = h; Register(); }
23
- void Clear(const char* n) { name = n; fn = 0; fnr = 0; lo = 0; hi = 0; threadlo = 0; threadhi = 0; }
24
- Benchmark* ThreadRange(int lo, int hi) { threadlo = lo; threadhi = hi; return this; }
25
- };
26
- } // namespace testing
27
135
 
28
- void SetBenchmarkBytesProcessed(int64_t);
29
- void StopBenchmarkTiming();
30
- void StartBenchmarkTiming();
31
- void BenchmarkMemoryUsage();
32
- void SetBenchmarkItemsProcessed(int);
136
+ const char* name_;
137
+ std::function<void(int, int)> func_;
138
+ int lo_;
139
+ int hi_;
140
+ bool has_arg_;
33
141
 
34
- int NumCPUs();
142
+ Benchmark(const Benchmark&) = delete;
143
+ Benchmark& operator=(const Benchmark&) = delete;
144
+ };
145
+
146
+ } // namespace testing
35
147
 
36
- #define BENCHMARK(f) \
37
- ::testing::Benchmark* _benchmark_##f = (new ::testing::Benchmark(#f, f))
148
+ #define BENCHMARK(f) \
149
+ ::testing::Benchmark* _benchmark_##f = \
150
+ (new ::testing::Benchmark(#f, f))
38
151
 
39
- #define BENCHMARK_RANGE(f, lo, hi) \
40
- ::testing::Benchmark* _benchmark_##f = \
41
- (new ::testing::Benchmark(#f, f, lo, hi))
152
+ #define BENCHMARK_RANGE(f, lo, hi) \
153
+ ::testing::Benchmark* _benchmark_##f = \
154
+ (new ::testing::Benchmark(#f, f, lo, hi))
42
155
 
43
156
  #endif // UTIL_BENCHMARK_H_
@@ -10,20 +10,17 @@
10
10
  // If you want to do that, see
11
11
  // https://gflags.github.io/gflags/
12
12
 
13
- #include <stdint.h>
14
-
15
- #define DEFINE_flag(type, name, deflt, desc) \
13
+ #define DEFINE_FLAG(type, name, deflt, desc) \
16
14
  namespace re2 { type FLAGS_##name = deflt; }
17
15
 
18
- #define DECLARE_flag(type, name) \
16
+ #define DECLARE_FLAG(type, name) \
19
17
  namespace re2 { extern type FLAGS_##name; }
20
18
 
21
- #define DEFINE_bool(name, deflt, desc) DEFINE_flag(bool, name, deflt, desc)
22
- #define DEFINE_int32(name, deflt, desc) DEFINE_flag(int32_t, name, deflt, desc)
23
- #define DEFINE_string(name, deflt, desc) DEFINE_flag(std::string, name, deflt, desc)
24
-
25
- #define DECLARE_bool(name) DECLARE_flag(bool, name)
26
- #define DECLARE_int32(name) DECLARE_flag(int32_t, name)
27
- #define DECLARE_string(name) DECLARE_flag(std::string, name)
19
+ namespace re2 {
20
+ template <typename T>
21
+ T GetFlag(const T& flag) {
22
+ return flag;
23
+ }
24
+ } // namespace re2
28
25
 
29
26
  #endif // UTIL_FLAGS_H_
@@ -0,0 +1,19 @@
1
+ // Copyright 2009 The RE2 Authors. All Rights Reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ #ifndef UTIL_MALLOC_COUNTER_H_
6
+ #define UTIL_MALLOC_COUNTER_H_
7
+
8
+ namespace testing {
9
+ class MallocCounter {
10
+ public:
11
+ MallocCounter(int x) {}
12
+ static const int THIS_THREAD_ONLY = 0;
13
+ long long HeapGrowth() { return 0; }
14
+ long long PeakHeapGrowth() { return 0; }
15
+ void Reset() {}
16
+ };
17
+ } // namespace testing
18
+
19
+ #endif // UTIL_MALLOC_COUNTER_H_
@@ -35,9 +35,10 @@
35
35
  // not exceed main thread stacks. Note that other threads
36
36
  // often have smaller stacks, and therefore tightening
37
37
  // regexp_stack_limit may frequently be necessary.
38
- DEFINE_int32(regexp_stack_limit, 256<<10, "default PCRE stack limit (bytes)");
39
- DEFINE_int32(regexp_match_limit, 1000000,
40
- "default PCRE match limit (function calls)");
38
+ DEFINE_FLAG(int, regexp_stack_limit, 256 << 10,
39
+ "default PCRE stack limit (bytes)");
40
+ DEFINE_FLAG(int, regexp_match_limit, 1000000,
41
+ "default PCRE match limit (function calls)");
41
42
 
42
43
  #ifndef USEPCRE
43
44
 
@@ -523,12 +524,12 @@ int PCRE::TryMatch(const StringPiece& text,
523
524
 
524
525
  int match_limit = match_limit_;
525
526
  if (match_limit <= 0) {
526
- match_limit = FLAGS_regexp_match_limit;
527
+ match_limit = GetFlag(FLAGS_regexp_match_limit);
527
528
  }
528
529
 
529
530
  int stack_limit = stack_limit_;
530
531
  if (stack_limit <= 0) {
531
- stack_limit = FLAGS_regexp_stack_limit;
532
+ stack_limit = GetFlag(FLAGS_regexp_stack_limit);
532
533
  }
533
534
 
534
535
  pcre_extra extra = { 0 };
@@ -977,32 +978,7 @@ static bool parse_double_float(const char* str, size_t n, bool isfloat,
977
978
  } else {
978
979
  r = strtod(buf, &end);
979
980
  }
980
- if (end != buf + n) {
981
- #ifdef _WIN32
982
- // Microsoft's strtod() doesn't handle inf and nan, so we have to
983
- // handle it explicitly. Speed is not important here because this
984
- // code is only called in unit tests.
985
- bool pos = true;
986
- const char* i = buf;
987
- if ('-' == *i) {
988
- pos = false;
989
- ++i;
990
- } else if ('+' == *i) {
991
- ++i;
992
- }
993
- if (0 == _stricmp(i, "inf") || 0 == _stricmp(i, "infinity")) {
994
- r = std::numeric_limits<double>::infinity();
995
- if (!pos)
996
- r = -r;
997
- } else if (0 == _stricmp(i, "nan")) {
998
- r = std::numeric_limits<double>::quiet_NaN();
999
- } else {
1000
- return false;
1001
- }
1002
- #else
1003
- return false; // Leftover junk
1004
- #endif
1005
- }
981
+ if (end != buf + n) return false; // Leftover junk
1006
982
  if (errno) return false;
1007
983
  if (dest == NULL) return true;
1008
984
  if (isfloat) {
@@ -3,10 +3,13 @@
3
3
  // license that can be found in the LICENSE file.
4
4
 
5
5
  #include <stdio.h>
6
+ #include <string>
6
7
 
7
8
  #include "util/test.h"
8
9
 
9
- DEFINE_string(test_tmpdir, "/var/tmp", "temp directory");
10
+ namespace testing {
11
+ std::string TempDir() { return "/tmp/"; }
12
+ } // namespace testing
10
13
 
11
14
  struct Test {
12
15
  void (*fn)(void);