Add early type validation for ObjectSpace.memsize_of_all klass argument

This commit is contained in:
Augustin Gottlieb 2026-01-23 03:00:37 +01:00 committed by GitHub
parent 1d497946af
commit 6ef0eb29c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2026-01-23 02:01:08 +00:00
Merged: https://github.com/ruby/ruby/pull/15937

Merged-By: nobu <nobu@ruby-lang.org>
2 changed files with 6 additions and 1 deletions

View File

@ -137,6 +137,7 @@ memsize_of_all_m(int argc, VALUE *argv, VALUE self)
if (argc > 0) {
rb_scan_args(argc, argv, "01", &data.klass);
if (!NIL_P(data.klass)) rb_obj_is_kind_of(Qnil, data.klass);
}
each_object_with_flags(total_i, &data);

View File

@ -54,7 +54,11 @@ class TestObjSpace < Test::Unit::TestCase
assert_operator(a, :>, b)
assert_operator(a, :>, 0)
assert_operator(b, :>, 0)
assert_raise(TypeError) {ObjectSpace.memsize_of_all('error')}
assert_kind_of(Integer, ObjectSpace.memsize_of_all(Enumerable))
end
def test_memsize_of_all_with_wrong_type
assert_raise(TypeError) { ObjectSpace.memsize_of_all(Object.new) }
end
def test_count_objects_size