Skip to content

Commit 5621d79

Browse files
Disable callcc when ASAN is enabled
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]
1 parent 0d9a681 commit 5621d79

File tree

9 files changed

+47
-15
lines changed

9 files changed

+47
-15
lines changed

cont.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,13 @@ rb_callcc(VALUE self)
17751775
return rb_yield(val);
17761776
}
17771777
}
1778+
#ifdef RUBY_ASAN_ENABLED
1779+
/* callcc can't possibly work with ASAN; see bug #20273. Also this function
1780+
* definition below avoids a "defined and not used" warning. */
1781+
MAYBE_UNUSED(static void notusing_callcc(void)) { rb_callcc(Qnil); }
1782+
# define rb_callcc rb_f_notimplement
1783+
#endif
1784+
17781785

17791786
static VALUE
17801787
make_passing_arg(int argc, const VALUE *argv)

test/ruby/test_array.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,6 +3561,7 @@ def need_continuation
35613561
unless respond_to?(:callcc, true)
35623562
EnvUtil.suppress_warning {require 'continuation'}
35633563
end
3564+
omit 'requires callcc support' unless respond_to?(:callcc, true)
35643565
end
35653566
end
35663567

test/ruby/test_beginendblock.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: false
22
require 'test/unit'
3+
EnvUtil.suppress_warning {require 'continuation'}
34

45
class TestBeginEndBlock < Test::Unit::TestCase
56
DIR = File.dirname(File.expand_path(__FILE__))
@@ -131,6 +132,8 @@ def test_rescue_at_exit
131132
end
132133

133134
def test_callcc_at_exit
135+
omit 'requires callcc support' unless respond_to?(:callcc)
136+
134137
bug9110 = '[ruby-core:58329][Bug #9110]'
135138
assert_ruby_status([], "#{<<~"begin;"}\n#{<<~'end;'}", bug9110)
136139
begin;

test/ruby/test_continuation.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
require 'fiber'
55

66
class TestContinuation < Test::Unit::TestCase
7+
def setup
8+
omit 'requires callcc support' unless respond_to?(:callcc)
9+
end
10+
711
def test_create
812
assert_equal(:ok, callcc{:ok})
913
assert_equal(:ok, callcc{|c| c.call :ok})

test/ruby/test_enum.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,8 @@ def test_cycle
843843
end
844844

845845
def test_callcc
846+
omit 'requires callcc support' unless respond_to?(:callcc)
847+
846848
assert_raise(RuntimeError) do
847849
c = nil
848850
@obj.sort_by {|x| callcc {|c2| c ||= c2 }; x }

test/ruby/test_fiber.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,14 @@ def test_error
8282
f.resume
8383
f.resume
8484
}
85-
assert_raise(RuntimeError){
86-
Fiber.new{
87-
@c = callcc{|c| @c = c}
88-
}.resume
89-
@c.call # cross fiber callcc
90-
}
85+
if respond_to?(:callcc)
86+
assert_raise(RuntimeError){
87+
Fiber.new{
88+
@c = callcc{|c| @c = c}
89+
}.resume
90+
@c.call # cross fiber callcc
91+
}
92+
end
9193
assert_raise(RuntimeError){
9294
Fiber.new{
9395
raise

test/ruby/test_hash.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,8 @@ def test_flatten_arity
13591359
end
13601360

13611361
def test_callcc
1362+
omit 'requires callcc support' unless respond_to?(:callcc)
1363+
13621364
h = @cls[1=>2]
13631365
c = nil
13641366
f = false
@@ -1379,6 +1381,8 @@ def test_callcc
13791381
end
13801382

13811383
def test_callcc_iter_level
1384+
omit 'requires callcc support' unless respond_to?(:callcc)
1385+
13821386
bug9105 = '[ruby-dev:47803] [Bug #9105]'
13831387
h = @cls[1=>2, 3=>4]
13841388
c = nil
@@ -1397,6 +1401,8 @@ def test_callcc_iter_level
13971401
end
13981402

13991403
def test_callcc_escape
1404+
omit 'requires callcc support' unless respond_to?(:callcc)
1405+
14001406
bug9105 = '[ruby-dev:47803] [Bug #9105]'
14011407
assert_nothing_raised(RuntimeError, bug9105) do
14021408
h=@cls[]
@@ -1411,6 +1417,8 @@ def test_callcc_escape
14111417
end
14121418

14131419
def test_callcc_reenter
1420+
omit 'requires callcc support' unless respond_to?(:callcc)
1421+
14141422
bug9105 = '[ruby-dev:47803] [Bug #9105]'
14151423
assert_nothing_raised(RuntimeError, bug9105) do
14161424
h = @cls[1=>2,3=>4]

test/ruby/test_marshal.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@ def marshal_load(v)
609609

610610
def test_continuation
611611
EnvUtil.suppress_warning {require "continuation"}
612+
omit 'requires callcc support' unless respond_to?(:callcc)
613+
612614
c = Bug9523.new
613615
assert_raise_with_message(RuntimeError, /Marshal\.dump reentered at marshal_dump/) do
614616
Marshal.dump(c)

test/ruby/test_settracefunc.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: false
22
require 'test/unit'
3+
EnvUtil.suppress_warning {require 'continuation'}
34

45
class TestSetTraceFunc < Test::Unit::TestCase
56
def setup
@@ -1258,15 +1259,17 @@ def each
12581259
end
12591260
}
12601261
assert_normal_exit src % %q{obj.zip({}) {}}, bug7774
1261-
assert_normal_exit src % %q{
1262-
require 'continuation'
1263-
begin
1264-
c = nil
1265-
obj.sort_by {|x| callcc {|c2| c ||= c2 }; x }
1266-
c.call
1267-
rescue RuntimeError
1268-
end
1269-
}, bug7774
1262+
if respond_to?(:callcc)
1263+
assert_normal_exit src % %q{
1264+
require 'continuation'
1265+
begin
1266+
c = nil
1267+
obj.sort_by {|x| callcc {|c2| c ||= c2 }; x }
1268+
c.call
1269+
rescue RuntimeError
1270+
end
1271+
}, bug7774
1272+
end
12701273

12711274
# TracePoint
12721275
tp_b = nil

0 commit comments

Comments
 (0)