summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authorLuke Gruber <[email protected]>2025-06-12 11:10:29 -0400
committerJohn Hawthorn <[email protected]>2025-06-12 13:13:18 -0700
commit97994c77fb5b82ca959e1188ecaee7d633d60a8e ()
treec65989346e50cdfbc06c9b24b3a1c11d75dc2e31 /re.c
parent6e36841dbd5f52b572b690b8a4c3c534fec43ba8 (diff)
Only use regex internal reg_cache when in main ractor
Using this `reg_cache` is racy across ractors, so don't use it when in a ractor. Also, its use across ractors can cause a regular expression created in 1 ractor to be used in another ractor (an isolation bug).
Notes: Merged: https://.com/ruby/ruby/pull/13598
-rw-r--r--re.c15
1 files changed, 10 insertions, 5 deletions
@@ -28,6 +28,7 @@
#include "ruby/encoding.h"
#include "ruby/re.h"
#include "ruby/util.h"
VALUE rb_eRegexpError, rb_eRegexpTimeoutError;
@@ -3499,12 +3500,16 @@ static VALUE reg_cache;
VALUE
rb_reg_regcomp(VALUE str)
{
- if (reg_cache && RREGEXP_SRC_LEN(reg_cache) == RSTRING_LEN(str)
- && ENCODING_GET(reg_cache) == ENCODING_GET(str)
- && memcmp(RREGEXP_SRC_PTR(reg_cache), RSTRING_PTR(str), RSTRING_LEN(str)) == 0)
- return reg_cache;
- return reg_cache = rb_reg_new_str(str, 0);
}
static st_index_t reg_hash(VALUE re);