Created
September 13, 2023 19:28
-
-
Save sampersand/ba5ec96b8c6edeeb7290df8a3e7dd357 to your computer and use it in GitHub Desktop.
GC stress diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[12:27:12 PM 1029] ruby % git diff | |
diff --git a/gc.c b/gc.c | |
index 3fd2a3b33f..f909e5b81b 100644 | |
--- a/gc.c | |
+++ b/gc.c | |
@@ -11460,6 +11460,10 @@ gc_stress_get(rb_execution_context_t *ec, VALUE self) | |
static void | |
gc_stress_set(rb_objspace_t *objspace, VALUE flag) | |
{ | |
+ if (flag != Qtrue && flag != Qfalse) { | |
+ flag = rb_to_int(flag); | |
+ } | |
+ | |
objspace->flags.gc_stressful = RTEST(flag); | |
objspace->gc_stress_mode = flag; | |
} | |
diff --git a/spec/ruby/core/gc/stress_spec.rb b/spec/ruby/core/gc/stress_spec.rb | |
index ca62c0cb4e..be8d095179 100644 | |
--- a/spec/ruby/core/gc/stress_spec.rb | |
+++ b/spec/ruby/core/gc/stress_spec.rb | |
@@ -20,8 +20,26 @@ | |
GC.stress = false | |
end | |
- it "sets the stress mode" do | |
+ it "accepts true, false, and integers" do | |
GC.stress = true | |
GC.stress.should be_true | |
+ GC.stress = false | |
+ GC.stress.should be_false | |
+ GC.stress = 4 | |
+ GC.stress.should equal 4 | |
+ end | |
+ | |
+ it "tries to convert non-boolean argument to an integer using to_int" do | |
+ a = mock('4') | |
+ a.should_receive(:to_int).and_return(4) | |
+ | |
+ GC.stress = a | |
+ GC.stress.should equal 5 | |
+ end | |
+ | |
+ it "raises TypeError for non-boolean and `to_int` types" do | |
+ -> { GC.stress = nil }.should raise_error(TypeError) | |
+ -> { GC.stress = Object.new }.should raise_error(TypeError) | |
+ -> { GC.stress = :hello }.should raise_error(TypeError) | |
end | |
: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment