re2 2.19.0 → 2.19.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8e51111f2667e113eca7b6b1778c68106c6f08946aa4f08420cfbae304f8bcf
4
- data.tar.gz: 28fe3a356868e09dd02767e39913e5138719dec83272e6d9d1efbfb3b8a6210b
3
+ metadata.gz: 687a91fb04d7c8f6d5082fd85a53b8cc08d57207dc2dd73a9d2de7ddc5700094
4
+ data.tar.gz: 0f2be0a7f418f1dc21bec364b8464b1e7afbd849ef51dd6fcbbdf9795afad302
5
5
  SHA512:
6
- metadata.gz: 12cf8c85a1ca08a1058b63613ccb01062875831077a2b1c5903c9828fc2406888272f2f4854f8738f4c50f24aaa16c375523964047cfd43cf388f7b5942e3c02
7
- data.tar.gz: 841bf575092d4e78d4380bb4adda70d1cade4c8bdd2060a0c71e6e02853e83ea1fe40a34f5d07dc16d34988084000d0da46d0c2e202d143c9014accaf5ad592b
6
+ metadata.gz: c084f2d6e64dece6fa322d22217bc40cfc82ce9f25360c0e69accf1c22e633a072d8d162698d98f1cc8e5caa6f23bed5843dfbe3f1e0d88f3fe5b92df68edaf3
7
+ data.tar.gz: ab17cd9b2443fb6717d8f6995254cf1547af83914ef9e0ce7c34e5babb8639f04157d6c6239da45b59e5b30a1b014b136dc4945a6ce5a4fe02112e691c159e51
data/README.md CHANGED
@@ -6,7 +6,7 @@ Python".
6
6
 
7
7
  [![Build Status](https://github.com/mudge/re2/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/mudge/re2/actions)
8
8
 
9
- **Current version:** 2.19.0
9
+ **Current version:** 2.19.1
10
10
  **Bundled RE2 version:** libre2.11 (2025-08-05)
11
11
 
12
12
  ```ruby
data/Rakefile CHANGED
@@ -76,7 +76,7 @@ namespace :gem do
76
76
  sudo apt-get install -y cmake=3.22.2-0kitware1ubuntu20.04.1 cmake-data=3.22.2-0kitware1ubuntu20.04.1 &&
77
77
  rbenv shell 3.1.6 &&
78
78
  gem install bundler --no-document &&
79
- bundle &&
79
+ bundle install &&
80
80
  bundle exec rake native:#{platform} pkg/#{re2_gemspec.full_name}-#{Gem::Platform.new(platform)}.gem PATH="/usr/local/bin:$PATH"
81
81
  SCRIPT
82
82
  end
data/ext/re2/re2.cc CHANGED
@@ -136,14 +136,13 @@ static void parse_re2_options(RE2::Options* re2_options, const VALUE options) {
136
136
  static void re2_matchdata_mark(void *ptr) {
137
137
  re2_matchdata *m = reinterpret_cast<re2_matchdata *>(ptr);
138
138
  rb_gc_mark_movable(m->regexp);
139
- rb_gc_mark_movable(m->text);
139
+ rb_gc_mark(m->text);
140
140
  }
141
141
 
142
142
  #ifdef HAVE_RB_GC_MARK_MOVABLE
143
143
  static void re2_matchdata_compact(void *ptr) {
144
144
  re2_matchdata *m = reinterpret_cast<re2_matchdata *>(ptr);
145
145
  m->regexp = rb_gc_location(m->regexp);
146
- m->text = rb_gc_location(m->text);
147
146
  }
148
147
  #endif
149
148
 
@@ -183,14 +182,13 @@ static const rb_data_type_t re2_matchdata_data_type = {
183
182
  static void re2_scanner_mark(void *ptr) {
184
183
  re2_scanner *s = reinterpret_cast<re2_scanner *>(ptr);
185
184
  rb_gc_mark_movable(s->regexp);
186
- rb_gc_mark_movable(s->text);
185
+ rb_gc_mark(s->text);
187
186
  }
188
187
 
189
188
  #ifdef HAVE_RB_GC_MARK_MOVABLE
190
189
  static void re2_scanner_compact(void *ptr) {
191
190
  re2_scanner *s = reinterpret_cast<re2_scanner *>(ptr);
192
191
  s->regexp = rb_gc_location(s->regexp);
193
- s->text = rb_gc_location(s->text);
194
192
  }
195
193
  #endif
196
194
 
@@ -290,9 +288,11 @@ static VALUE re2_matchdata_string(const VALUE self) {
290
288
  }
291
289
 
292
290
  /*
293
- * Returns the text supplied when incrementally matching with
291
+ * Returns a frozen copy of the text supplied when incrementally matching with
294
292
  * {RE2::Regexp#scan}.
295
293
  *
294
+ * If the text was already a frozen string, returns the original.
295
+ *
296
296
  * @return [String] the original string passed to {RE2::Regexp#scan}
297
297
  * @example
298
298
  * c = RE2::Regexp.new('(\d+)').scan("foo")
@@ -1534,10 +1534,7 @@ static VALUE re2_regexp_match(int argc, VALUE *argv, const VALUE self) {
1534
1534
  TypedData_Get_Struct(matchdata, re2_matchdata, &re2_matchdata_data_type, m);
1535
1535
  m->matches = new(std::nothrow) re2::StringPiece[n];
1536
1536
  RB_OBJ_WRITE(matchdata, &m->regexp, self);
1537
- if (!RTEST(rb_obj_frozen_p(text))) {
1538
- text = rb_str_freeze(rb_str_dup(text));
1539
- }
1540
- RB_OBJ_WRITE(matchdata, &m->text, text);
1537
+ RB_OBJ_WRITE(matchdata, &m->text, rb_str_new_frozen(text));
1541
1538
 
1542
1539
  if (m->matches == 0) {
1543
1540
  rb_raise(rb_eNoMemError,
@@ -1626,10 +1623,10 @@ static VALUE re2_regexp_scan(const VALUE self, VALUE text) {
1626
1623
  VALUE scanner = rb_class_new_instance(0, 0, re2_cScanner);
1627
1624
  TypedData_Get_Struct(scanner, re2_scanner, &re2_scanner_data_type, c);
1628
1625
 
1629
- c->input = new(std::nothrow) re2::StringPiece(
1630
- RSTRING_PTR(text), RSTRING_LEN(text));
1631
1626
  RB_OBJ_WRITE(scanner, &c->regexp, self);
1632
- RB_OBJ_WRITE(scanner, &c->text, text);
1627
+ RB_OBJ_WRITE(scanner, &c->text, rb_str_new_frozen(text));
1628
+ c->input = new(std::nothrow) re2::StringPiece(
1629
+ RSTRING_PTR(c->text), RSTRING_LEN(c->text));
1633
1630
 
1634
1631
  if (p->pattern->ok()) {
1635
1632
  c->number_of_capturing_groups = p->pattern->NumberOfCapturingGroups();
data/lib/re2/version.rb CHANGED
@@ -10,5 +10,5 @@
10
10
 
11
11
 
12
12
  module RE2
13
- VERSION = "2.19.0"
13
+ VERSION = "2.19.1"
14
14
  end
@@ -11,7 +11,39 @@ RSpec.describe RE2::Scanner do
11
11
  end
12
12
 
13
13
  describe "#string" do
14
- it "returns the original text for the scanner" do
14
+ it "returns the text for the scanner" do
15
+ re = RE2::Regexp.new('(\w+)')
16
+ text = "It is a truth"
17
+ scanner = re.scan(text)
18
+
19
+ expect(scanner.string).to eq("It is a truth")
20
+ end
21
+
22
+ it "returns a frozen string" do
23
+ re = RE2::Regexp.new('(\w+)')
24
+ text = "It is a truth"
25
+ scanner = re.scan(text)
26
+
27
+ expect(scanner.string).to be_frozen
28
+ end
29
+
30
+ it "freezes unfrozen strings" do
31
+ re = RE2::Regexp.new('(\w+)')
32
+ text = +"It is a truth"
33
+ scanner = re.scan(text)
34
+
35
+ expect(scanner.string).to be_frozen
36
+ end
37
+
38
+ it "copies unfrozen strings" do
39
+ re = RE2::Regexp.new('(\w+)')
40
+ text = +"It is a truth"
41
+ scanner = re.scan(text)
42
+
43
+ expect(scanner.string).to_not equal(text)
44
+ end
45
+
46
+ it "does not copy the string if it was already frozen" do
15
47
  re = RE2::Regexp.new('(\w+)')
16
48
  text = "It is a truth"
17
49
  scanner = re.scan(text)
@@ -162,6 +194,15 @@ RSpec.describe RE2::Scanner do
162
194
  expect(scanner.scan).to eq(["world"])
163
195
  expect(scanner.scan).to be_nil
164
196
  end
197
+
198
+ it "works even if the original input is mutated" do
199
+ r = RE2::Regexp.new('(\w+)')
200
+ text = +"It is a truth universally acknowledged"
201
+ scanner = r.scan(text)
202
+ text.upcase!
203
+
204
+ expect(scanner.scan).to eq(["It"])
205
+ end
165
206
  end
166
207
 
167
208
  it "is enumerable" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: re2
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.19.0
4
+ version: 2.19.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Mucur