summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <[email protected]>2024-10-31 11:31:12 -0400
committerPeter Zhu <[email protected]>2024-10-31 13:52:24 -0400
commit843b4f49ee82c572405d466f28d4305e21d6e6c2 (patch)
treed16692a8987c7d9267609982c87ce83358436c36
parent4bcfff07ab3dc8e6e66f3eeebdebb276f65412b0 (diff)
Fix assertion when envval of proc is Qundef
The following code crashes with assertions enabled because envval could be Qundef: {}.to_proc.dup
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11970
-rw-r--r--test/ruby/test_proc.rb19
-rw-r--r--vm_core.h2
2 files changed, 20 insertions, 1 deletions
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index 304717e43c..fcf00776a6 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -377,6 +377,7 @@ class TestProc < Test::Unit::TestCase
end
def test_dup_clone
+ # iseq backed proc
b = proc {|x| x + "bar" }
class << b; attr_accessor :foo; end
@@ -389,6 +390,24 @@ class TestProc < Test::Unit::TestCase
assert_equal("foobar", bc.call("foo"))
bc.foo = :foo
assert_equal(:foo, bc.foo)
+
+ # ifunc backed proc
+ b = {foo: "bar"}.to_proc
+
+ bd = b.dup
+ assert_equal("bar", bd.call(:foo))
+
+ bc = b.clone
+ assert_equal("bar", bc.call(:foo))
+
+ # symbol backed proc
+ b = :to_s.to_proc
+
+ bd = b.dup
+ assert_equal("testing", bd.call(:testing))
+
+ bc = b.clone
+ assert_equal("testing", bc.call(:testing))
end
def test_dup_subclass
diff --git a/vm_core.h b/vm_core.h
index 9aa93b7e21..e5169685f1 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -1493,7 +1493,7 @@ VM_ENV_ESCAPED_P(const VALUE *ep)
static inline int
vm_assert_env(VALUE obj)
{
- VM_ASSERT(imemo_type_p(obj, imemo_env));
+ VM_ASSERT(obj == Qundef || imemo_type_p(obj, imemo_env));
return 1;
}
#endif