Skip to content

Commit 1567215

Browse files
committed
[GR-17457] Remove the behavior that rb_funcall() passes the rb_iterate() block
PullRequest: truffleruby/2707
2 parents 214dec6 + e7ddba7 commit 1567215

File tree

5 files changed

+17
-52
lines changed

5 files changed

+17
-52
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Performance:
5151

5252
Changes:
5353

54+
* `rb_iterate()` (deprecated since 1.9) no longer magically passes the block to `rb_funcall()`, use `rb_block_call()` instead.
5455

5556
Security:
5657

lib/truffle/truffle/cext.rb

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -878,14 +878,7 @@ def rb_funcallv(recv, meth, argv)
878878
end
879879

880880
def rb_funcall(recv, meth, n, *args)
881-
# see #call_with_thread_locally_stored_block
882-
thread_local_block = Thread.current[:__C_BLOCK__]
883-
Thread.current[:__C_BLOCK__] = nil
884-
begin
885-
Primitive.send_without_cext_lock(recv, meth, args, thread_local_block)
886-
ensure
887-
Thread.current[:__C_BLOCK__] = thread_local_block
888-
end
881+
Primitive.send_without_cext_lock(recv, meth, args, nil)
889882
end
890883

891884
def rb_apply(recv, meth, args)
@@ -1656,21 +1649,17 @@ def rb_thread_call_without_gvl(function, data1, unblock, data2)
16561649

16571650
def rb_iterate(iteration, iterated_object, callback, callback_arg)
16581651
block = rb_block_proc
1659-
if block
1660-
call_with_thread_locally_stored_block iteration, iterated_object do |block_arg|
1661-
rb_iterate_call_block(callback, block_arg, callback_arg, &block)
1662-
end
1663-
else
1664-
call_with_thread_locally_stored_block iteration, iterated_object do |block_arg|
1665-
Primitive.cext_unwrap(Primitive.call_with_c_mutex(callback, [
1666-
Primitive.cext_wrap(block_arg),
1667-
Primitive.cext_wrap(callback_arg),
1668-
0, # argc
1669-
nil, # argv
1670-
nil, # blockarg
1671-
]))
1672-
end
1673-
end
1652+
wrapped_callback = proc do |block_arg|
1653+
Primitive.cext_unwrap(Primitive.call_with_c_mutex_and_frame(callback, [
1654+
Primitive.cext_wrap(block_arg),
1655+
Primitive.cext_wrap(callback_arg),
1656+
0, # argc
1657+
nil, # argv
1658+
nil, # blockarg
1659+
], block))
1660+
end
1661+
Primitive.cext_unwrap(
1662+
Primitive.call_with_c_mutex_and_frame(iteration, [Primitive.cext_wrap(iterated_object)], wrapped_callback))
16741663
end
16751664

16761665
def rb_thread_wait_fd(fd)

lib/truffle/truffle/cext_ruby.rb

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,4 @@ def rb_define_method(mod, name, function, argc)
5050
method_body_with_arity = Primitive.proc_specify_arity(method_body, arity)
5151
mod.define_method(name, method_body_with_arity)
5252
end
53-
54-
private
55-
56-
def rb_iterate_call_block(callback, block_arg, callback_arg, &block)
57-
Primitive.cext_unwrap(Primitive.call_with_c_mutex_and_frame(callback, [
58-
Primitive.cext_wrap(block_arg),
59-
Primitive.cext_wrap(callback_arg),
60-
0, # argc
61-
nil, # argv
62-
nil, # blockarg
63-
], block))
64-
end
65-
66-
def call_with_thread_locally_stored_block(function, *args, &block)
67-
# MRI puts the block to a thread local th->passed_block and later rb_funcall reads it,
68-
# we have to do the same
69-
# TODO (pitr-ch 14-Dec-2017): This is fixed just for rb_iterate with a rb_funcall in it combination
70-
71-
previous_block = Thread.current[:__C_BLOCK__]
72-
begin
73-
Thread.current[:__C_BLOCK__] = block
74-
Primitive.cext_unwrap(Primitive.call_with_c_mutex_and_frame(function, args.map! { |arg| Primitive.cext_wrap(arg) }, block))
75-
ensure
76-
Thread.current[:__C_BLOCK__] = previous_block
77-
end
78-
end
79-
8053
end

spec/ruby/optional/capi/proc_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@
104104

105105
# Ruby -> C -> Ruby -> Proc.new
106106
it "raises an ArgumentError when the C function calls a Ruby method that calls Proc.new" do
107-
def @p.Proc_new() Proc.new end
108-
-> { @p.rb_Proc_new(2) { :called } }.should raise_error(ArgumentError)
107+
-> {
108+
@p.rb_Proc_new(2) { :called }
109+
}.should raise_error(ArgumentError)
109110
end
110111

111112
# Ruby -> C -> Ruby -> C -> rb_funcall(Proc.new)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fails(deprecated):C-API Array function rb_iterate calls a function with the other function available as a block

0 commit comments

Comments
 (0)