[前][次][番号順一覧][スレッド一覧]

ruby-changes:60231

From: Koichi <ko1@a...>
Date: Sat, 29 Feb 2020 04:22:37 +0900 (JST)
Subject: [ruby-changes:60231] b3983c68dd (master): should not expose hidden object.

https://git.ruby-lang.org/ruby.git/commit/?id=b3983c68dd

From b3983c68dd74ba013f7ac41a3df67ad2e4fdcc23 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Sat, 29 Feb 2020 04:20:13 +0900
Subject: should not expose hidden object.

Hidden object (T_CLASS) can be exposed (BUG).
Also rename rb_mInternalObjectWrapper to rb_cInternalObjectWrapper
because it is a class.

diff --git a/ext/objspace/objspace.c b/ext/objspace/objspace.c
index dc1a0cb..f470f74 100644
--- a/ext/objspace/objspace.c
+++ b/ext/objspace/objspace.c
@@ -665,12 +665,12 @@ static const rb_data_type_t iow_data_type = { https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L665
     0, 0, RUBY_TYPED_FREE_IMMEDIATELY
 };
 
-static VALUE rb_mInternalObjectWrapper;
+static VALUE rb_cInternalObjectWrapper;
 
 static VALUE
 iow_newobj(VALUE obj)
 {
-    return TypedData_Wrap_Struct(rb_mInternalObjectWrapper, &iow_data_type, (void *)obj);
+    return TypedData_Wrap_Struct(rb_cInternalObjectWrapper, &iow_data_type, (void *)obj);
 }
 
 /* Returns the type of the internal object. */
@@ -866,7 +866,8 @@ wrap_klass_iow(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L866
     if (!RTEST(klass)) {
 	return Qnil;
     }
-    else if (RB_TYPE_P(klass, T_ICLASS)) {
+    else if (RB_TYPE_P(klass, T_ICLASS) ||
+             CLASS_OF(klass) == Qfalse /* hidden object */) {
 	return iow_newobj(klass);
     }
     else {
@@ -979,10 +980,10 @@ Init_objspace(void) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L980
      *
      * You can use the #type method to check the type of the internal object.
      */
-    rb_mInternalObjectWrapper = rb_define_class_under(rb_mObjSpace, "InternalObjectWrapper", rb_cObject);
-    rb_define_method(rb_mInternalObjectWrapper, "type", iow_type, 0);
-    rb_define_method(rb_mInternalObjectWrapper, "inspect", iow_inspect, 0);
-    rb_define_method(rb_mInternalObjectWrapper, "internal_object_id", iow_internal_object_id, 0);
+    rb_cInternalObjectWrapper = rb_define_class_under(rb_mObjSpace, "InternalObjectWrapper", rb_cObject);
+    rb_define_method(rb_cInternalObjectWrapper, "type", iow_type, 0);
+    rb_define_method(rb_cInternalObjectWrapper, "inspect", iow_inspect, 0);
+    rb_define_method(rb_cInternalObjectWrapper, "internal_object_id", iow_internal_object_id, 0);
 
     Init_object_tracing(rb_mObjSpace);
     Init_objspace_dump(rb_mObjSpace);
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]