Skip to content

Commit

Permalink
Disable callcc when ASAN is enabled
Browse files Browse the repository at this point in the history
callcc's implementation is fundamentally incompatible with ASAN. Since
callcc is deprecated and almost never used, it's probably OK to disable
callcc when ruby is compiled with ASAN.

[Bug #20273]
  • Loading branch information
KJTsanaktsidis committed Mar 4, 2024
1 parent 0d9a681 commit 5621d79
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 15 deletions.
7 changes: 7 additions & 0 deletions cont.c
Expand Up @@ -1775,6 +1775,13 @@ rb_callcc(VALUE self)
return rb_yield(val);
}
}
#ifdef RUBY_ASAN_ENABLED
/* callcc can't possibly work with ASAN; see bug #20273. Also this function
* definition below avoids a "defined and not used" warning. */
MAYBE_UNUSED(static void notusing_callcc(void)) { rb_callcc(Qnil); }
# define rb_callcc rb_f_notimplement
#endif


static VALUE
make_passing_arg(int argc, const VALUE *argv)
Expand Down
1 change: 1 addition & 0 deletions test/ruby/test_array.rb
Expand Up @@ -3561,6 +3561,7 @@ def need_continuation
unless respond_to?(:callcc, true)
EnvUtil.suppress_warning {require 'continuation'}
end
omit 'requires callcc support' unless respond_to?(:callcc, true)
end
end

Expand Down
3 changes: 3 additions & 0 deletions test/ruby/test_beginendblock.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: false
require 'test/unit'
EnvUtil.suppress_warning {require 'continuation'}

class TestBeginEndBlock < Test::Unit::TestCase
DIR = File.dirname(File.expand_path(__FILE__))
Expand Down Expand Up @@ -131,6 +132,8 @@ def test_rescue_at_exit
end

def test_callcc_at_exit
omit 'requires callcc support' unless respond_to?(:callcc)

bug9110 = '[ruby-core:58329][Bug #9110]'
assert_ruby_status([], "#{<<~"begin;"}\n#{<<~'end;'}", bug9110)
begin;
Expand Down
4 changes: 4 additions & 0 deletions test/ruby/test_continuation.rb
Expand Up @@ -4,6 +4,10 @@
require 'fiber'

class TestContinuation < Test::Unit::TestCase
def setup
omit 'requires callcc support' unless respond_to?(:callcc)
end

def test_create
assert_equal(:ok, callcc{:ok})
assert_equal(:ok, callcc{|c| c.call :ok})
Expand Down
2 changes: 2 additions & 0 deletions test/ruby/test_enum.rb
Expand Up @@ -843,6 +843,8 @@ def test_cycle
end

def test_callcc
omit 'requires callcc support' unless respond_to?(:callcc)

assert_raise(RuntimeError) do
c = nil
@obj.sort_by {|x| callcc {|c2| c ||= c2 }; x }
Expand Down
14 changes: 8 additions & 6 deletions test/ruby/test_fiber.rb
Expand Up @@ -82,12 +82,14 @@ def test_error
f.resume
f.resume
}
assert_raise(RuntimeError){
Fiber.new{
@c = callcc{|c| @c = c}
}.resume
@c.call # cross fiber callcc
}
if respond_to?(:callcc)
assert_raise(RuntimeError){
Fiber.new{
@c = callcc{|c| @c = c}
}.resume
@c.call # cross fiber callcc
}
end
assert_raise(RuntimeError){
Fiber.new{
raise
Expand Down
8 changes: 8 additions & 0 deletions test/ruby/test_hash.rb
Expand Up @@ -1359,6 +1359,8 @@ def test_flatten_arity
end

def test_callcc
omit 'requires callcc support' unless respond_to?(:callcc)

h = @cls[1=>2]
c = nil
f = false
Expand All @@ -1379,6 +1381,8 @@ def test_callcc
end

def test_callcc_iter_level
omit 'requires callcc support' unless respond_to?(:callcc)

bug9105 = '[ruby-dev:47803] [Bug #9105]'
h = @cls[1=>2, 3=>4]
c = nil
Expand All @@ -1397,6 +1401,8 @@ def test_callcc_iter_level
end

def test_callcc_escape
omit 'requires callcc support' unless respond_to?(:callcc)

bug9105 = '[ruby-dev:47803] [Bug #9105]'
assert_nothing_raised(RuntimeError, bug9105) do
h=@cls[]
Expand All @@ -1411,6 +1417,8 @@ def test_callcc_escape
end

def test_callcc_reenter
omit 'requires callcc support' unless respond_to?(:callcc)

bug9105 = '[ruby-dev:47803] [Bug #9105]'
assert_nothing_raised(RuntimeError, bug9105) do
h = @cls[1=>2,3=>4]
Expand Down
2 changes: 2 additions & 0 deletions test/ruby/test_marshal.rb
Expand Up @@ -609,6 +609,8 @@ def marshal_load(v)

def test_continuation
EnvUtil.suppress_warning {require "continuation"}
omit 'requires callcc support' unless respond_to?(:callcc)

c = Bug9523.new
assert_raise_with_message(RuntimeError, /Marshal\.dump reentered at marshal_dump/) do
Marshal.dump(c)
Expand Down
21 changes: 12 additions & 9 deletions test/ruby/test_settracefunc.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: false
require 'test/unit'
EnvUtil.suppress_warning {require 'continuation'}

class TestSetTraceFunc < Test::Unit::TestCase
def setup
Expand Down Expand Up @@ -1258,15 +1259,17 @@ def each
end
}
assert_normal_exit src % %q{obj.zip({}) {}}, bug7774
assert_normal_exit src % %q{
require 'continuation'
begin
c = nil
obj.sort_by {|x| callcc {|c2| c ||= c2 }; x }
c.call
rescue RuntimeError
end
}, bug7774
if respond_to?(:callcc)
assert_normal_exit src % %q{
require 'continuation'
begin
c = nil
obj.sort_by {|x| callcc {|c2| c ||= c2 }; x }
c.call
rescue RuntimeError
end
}, bug7774
end

# TracePoint
tp_b = nil
Expand Down

0 comments on commit 5621d79

Please sign in to comment.