summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/objspace/objspace.c9
-rw-r--r--test/objspace/test_objspace.rb5
2 files changed, 12 insertions, 2 deletions
diff --git a/ext/objspace/objspace.c b/ext/objspace/objspace.c
index 262640d30c..3bfb79dc1f 100644
--- a/ext/objspace/objspace.c
+++ b/ext/objspace/objspace.c
@@ -895,8 +895,13 @@ objspace_internal_class_of(VALUE self, VALUE obj)
obj = (VALUE)DATA_PTR(obj);
}
- klass = CLASS_OF(obj);
- return wrap_klass_iow(klass);
+ if (RB_TYPE_P(obj, T_IMEMO)) {
+ return Qnil;
+ }
+ else {
+ klass = CLASS_OF(obj);
+ return wrap_klass_iow(klass);
+ }
}
/*
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index f9e6e82e8f..b3f7a56e51 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -516,6 +516,11 @@ class TestObjSpace < Test::Unit::TestCase
assert_operator i, :>, 0
end
+ def test_internal_class_of_on_ast
+ children = ObjectSpace.reachable_objects_from(RubyVM::AbstractSyntaxTree.parse("kadomatsu"))
+ children.each {|child| ObjectSpace.internal_class_of(child).itself} # this used to crash
+ end
+
def traverse_super_classes klass
while klass
klass = ObjectSpace.internal_super_of(klass)