summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/re.h1
-rw-r--r--lib/prism/translation/parser/compiler.rb2
-rw-r--r--re.c8
-rw-r--r--test/prism/fixtures/escaped_newline_with_trailing_content.txt2
-rw-r--r--thread_sync.rb38
-rw-r--r--yjit/bindgen/src/main.rs2
-rw-r--r--yjit/src/codegen.rs37
-rw-r--r--yjit/src/cruby_bindings.inc.rs6
-rw-r--r--zjit/bindgen/src/main.rs1
-rw-r--r--zjit/src/cruby_bindings.inc.rs1
10 files changed, 34 insertions, 64 deletions
diff --git a/internal/re.h b/internal/re.h
index 3ad364a1a6..6c0aee6d06 100644
--- a/internal/re.h
+++ b/internal/re.h
@@ -68,7 +68,6 @@ VALUE rb_reg_equal(VALUE re1, VALUE re2);
VALUE rb_backref_set_string(VALUE string, long pos, long len);
void rb_match_unbusy(VALUE);
int rb_match_count(VALUE match);
-VALUE rb_reg_new_ary(VALUE ary, int options);
VALUE rb_reg_new_from_values(long cnt, const VALUE *elements, int opt);
VALUE rb_reg_last_defined(VALUE match);
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb
index aaccee64c1..d11db12ae6 100644
--- a/lib/prism/translation/parser/compiler.rb
+++ b/lib/prism/translation/parser/compiler.rb
@@ -2178,7 +2178,7 @@ module Prism
else
lines.sum do |line|
count = line.scan(/(\\*)n/).count { |(backslashes)| backslashes&.length&.odd? }
- count -= 1 if !line.end_with?("\n") && count > 0
+ count -= 1 if line.match?(/(?:\A|[^\\])(?:\\\\)*\\n\z/) && count > 0
count
end
end
diff --git a/re.c b/re.c
index ec337cd21c..63e2db81ac 100644
--- a/re.c
+++ b/re.c
@@ -3523,16 +3523,10 @@ rb_reg_init_str_enc(VALUE re, VALUE s, rb_encoding *enc, int options)
}
VALUE
-rb_reg_new_ary(VALUE ary, int opt)
-{
- return rb_reg_new_str(rb_reg_preprocess_dregexp(ary, opt), opt);
-}
-
-VALUE
rb_reg_new_from_values(long cnt, const VALUE *elements, int opt)
{
const VALUE ary = rb_ary_tmp_new_from_values(0, cnt, elements);
- VALUE val = rb_reg_new_ary(ary, (int)opt);
+ VALUE val = rb_reg_new_str(rb_reg_preprocess_dregexp(ary, opt), opt);
rb_ary_clear(ary);
return val;
}
diff --git a/test/prism/fixtures/escaped_newline_with_trailing_content.txt b/test/prism/fixtures/escaped_newline_with_trailing_content.txt
new file mode 100644
index 0000000000..fe947a3f10
--- /dev/null
+++ b/test/prism/fixtures/escaped_newline_with_trailing_content.txt
@@ -0,0 +1,2 @@
+"A
+B\nCC"
diff --git a/thread_sync.rb b/thread_sync.rb
index c9d37772d7..18c7cc7adc 100644
--- a/thread_sync.rb
+++ b/thread_sync.rb
@@ -11,23 +11,23 @@ class Thread
#
# Example:
#
- # queue = Thread::Queue.new
+ # queue = Thread::Queue.new
#
- # producer = Thread.new do
- # 5.times do |i|
- # sleep rand(i) # simulate expense
- # queue << i
- # puts "#{i} produced"
- # end
- # end
+ # producer = Thread.new do
+ # 5.times do |i|
+ # sleep rand(i) # simulate expense
+ # queue << i
+ # puts "#{i} produced"
+ # end
+ # end
#
- # consumer = Thread.new do
- # 5.times do |i|
- # value = queue.pop
- # sleep rand(i/2) # simulate expense
- # puts "consumed #{value}"
- # end
- # end
+ # consumer = Thread.new do
+ # 5.times do |i|
+ # value = queue.pop
+ # sleep rand(i/2) # simulate expense
+ # puts "consumed #{value}"
+ # end
+ # end
#
# consumer.join
class Queue
@@ -42,13 +42,13 @@ class Thread
#
# Example:
#
- # q = Thread::Queue.new
+ # q = Thread::Queue.new
# #=> #<Thread::Queue:0x00007ff7501110d0>
# q.empty?
# #=> true
#
- # q = Thread::Queue.new([1, 2, 3])
- # #=> #<Thread::Queue:0x00007ff7500ec500>
+ # q = Thread::Queue.new([1, 2, 3])
+ # #=> #<Thread::Queue:0x00007ff7500ec500>
# q.empty?
# #=> false
# q.pop
@@ -113,7 +113,7 @@ class Thread
#
# Example:
#
- # q = Thread::Queue.new
+ # q = Thread::Queue.new
# Thread.new{
# while e = q.deq # wait for nil to break loop
# # ...
diff --git a/yjit/bindgen/src/main.rs b/yjit/bindgen/src/main.rs
index a6a24387b3..373d5abb42 100644
--- a/yjit/bindgen/src/main.rs
+++ b/yjit/bindgen/src/main.rs
@@ -180,7 +180,7 @@ fn main() {
.allowlist_function("rb_reg_match_post")
.allowlist_function("rb_reg_match_last")
.allowlist_function("rb_reg_nth_match")
- .allowlist_function("rb_reg_new_ary")
+ .allowlist_function("rb_reg_new_from_values")
// `ruby_value_type` is a C enum and this stops it from
// prefixing all the members with the name of the type
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs
index 1146192dc4..743a10e15a 100644
--- a/yjit/src/codegen.rs
+++ b/yjit/src/codegen.rs
@@ -10180,45 +10180,18 @@ fn gen_toregexp(
let opt = jit.get_arg(0).as_i64();
let cnt = jit.get_arg(1).as_usize();
- // Save the PC and SP because this allocates an object and could
- // raise an exception.
+ // Allocates objects and could raise an exception.
jit_prepare_non_leaf_call(jit, asm);
let values_ptr = asm.lea(asm.ctx.sp_opnd(-(cnt as i32)));
- let ary = asm.ccall(
- rb_ary_tmp_new_from_values as *const u8,
- vec![
- Opnd::Imm(0),
- cnt.into(),
- values_ptr,
- ]
+ let regexp = asm.ccall(
+ rb_reg_new_from_values as _,
+ vec![cnt.into(), values_ptr, opt.into()],
);
asm.stack_pop(cnt); // Let ccall spill them
-
- // Save the array so we can clear it later
- asm.cpush(ary);
- asm.cpush(ary); // Alignment
-
- let val = asm.ccall(
- rb_reg_new_ary as *const u8,
- vec![
- ary,
- Opnd::Imm(opt),
- ]
- );
-
- // The actual regex is in RAX now. Pop the temp array from
- // rb_ary_tmp_new_from_values into C arg regs so we can clear it
- let ary = asm.cpop(); // Alignment
- asm.cpop_into(ary);
-
- // The value we want to push on the stack is in RAX right now
let stack_ret = asm.stack_push(Type::UnknownHeap);
- asm.mov(stack_ret, val);
-
- // Clear the temp array.
- asm.ccall(rb_ary_clear as *const u8, vec![ary]);
+ asm.mov(stack_ret, regexp);
Some(KeepCompiling)
}
diff --git a/yjit/src/cruby_bindings.inc.rs b/yjit/src/cruby_bindings.inc.rs
index 4ad88bb7d0..ef7f6c0a9e 100644
--- a/yjit/src/cruby_bindings.inc.rs
+++ b/yjit/src/cruby_bindings.inc.rs
@@ -1076,7 +1076,11 @@ extern "C" {
pub fn rb_obj_info_dump(obj: VALUE);
pub fn rb_class_allocate_instance(klass: VALUE) -> VALUE;
pub fn rb_obj_equal(obj1: VALUE, obj2: VALUE) -> VALUE;
- pub fn rb_reg_new_ary(ary: VALUE, options: ::std::os::raw::c_int) -> VALUE;
+ pub fn rb_reg_new_from_values(
+ cnt: ::std::os::raw::c_long,
+ elements: *const VALUE,
+ opt: ::std::os::raw::c_int,
+ ) -> VALUE;
pub fn rb_ary_tmp_new_from_values(
arg1: VALUE,
arg2: ::std::os::raw::c_long,
diff --git a/zjit/bindgen/src/main.rs b/zjit/bindgen/src/main.rs
index 2cde74facd..32b75117c8 100644
--- a/zjit/bindgen/src/main.rs
+++ b/zjit/bindgen/src/main.rs
@@ -215,7 +215,6 @@ fn main() {
.allowlist_function("rb_reg_match_post")
.allowlist_function("rb_reg_match_last")
.allowlist_function("rb_reg_nth_match")
- .allowlist_function("rb_reg_new_ary")
.allowlist_function("rb_reg_new_from_values")
.allowlist_var("ARG_ENCODING_FIXED")
.allowlist_var("ARG_ENCODING_NONE")
diff --git a/zjit/src/cruby_bindings.inc.rs b/zjit/src/cruby_bindings.inc.rs
index 5a7c3de606..21a2f6bbb4 100644
--- a/zjit/src/cruby_bindings.inc.rs
+++ b/zjit/src/cruby_bindings.inc.rs
@@ -2059,7 +2059,6 @@ unsafe extern "C" {
pub fn rb_const_get(space: VALUE, name: ID) -> VALUE;
pub fn rb_class_allocate_instance(klass: VALUE) -> VALUE;
pub fn rb_obj_equal(obj1: VALUE, obj2: VALUE) -> VALUE;
- pub fn rb_reg_new_ary(ary: VALUE, options: ::std::os::raw::c_int) -> VALUE;
pub fn rb_reg_new_from_values(
cnt: ::std::os::raw::c_long,
elements: *const VALUE,