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

ruby-changes:62185

From: Alan <ko1@a...>
Date: Sat, 11 Jul 2020 11:42:55 +0900 (JST)
Subject: [ruby-changes:62185] cbf52087a2 (master): Fix missing imemo cases in objspace_dump by refactoring

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

From cbf52087a2d4ac3c2db698ddc5b0b023f6bb2eca Mon Sep 17 00:00:00 2001
From: Alan Wu <XrXr@u...>
Date: Thu, 9 Jul 2020 18:37:03 -0400
Subject: Fix missing imemo cases in objspace_dump by refactoring

imemo_callcache and imemo_callinfo were not handled by the `objspace`
module and were showing up as "unknown" in the dump. Extract the code for
naming imemos and use that in both the GC and the `objspace` module.

diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c
index 7dd0731..95bd8ac 100644
--- a/ext/objspace/objspace_dump.c
+++ b/ext/objspace/objspace_dump.c
@@ -195,28 +195,6 @@ dump_append_string_content(struct dump_config *dc, VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L195
     }
 }
 
-static const char *
-imemo_name(int imemo)
-{
-    switch(imemo) {
-#define TYPE_STR(t) case(imemo_##t): return #t
-	TYPE_STR(env);
-	TYPE_STR(cref);
-	TYPE_STR(svar);
-	TYPE_STR(throw_data);
-	TYPE_STR(ifunc);
-	TYPE_STR(memo);
-	TYPE_STR(ment);
-	TYPE_STR(iseq);
-	TYPE_STR(tmpbuf);
-	TYPE_STR(ast);
-	TYPE_STR(parser_strterm);
-      default:
-	return "unknown";
-#undef TYPE_STR
-    }
-}
-
 static void
 dump_object(VALUE obj, struct dump_config *dc)
 {
@@ -251,7 +229,7 @@ dump_object(VALUE obj, struct dump_config *dc) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L229
 	return;
 
       case T_IMEMO:
-	dump_append(dc, ", \"imemo_type\":\"%s\"", imemo_name(imemo_type(obj)));
+	dump_append(dc, ", \"imemo_type\":\"%s\"", rb_imemo_name(imemo_type(obj)));
 	break;
 
       case T_SYMBOL:
diff --git a/gc.c b/gc.c
index 1e3b6c2..9baddb9 100644
--- a/gc.c
+++ b/gc.c
@@ -2256,6 +2256,30 @@ rb_newobj_of(VALUE klass, VALUE flags) https://github.com/ruby/ruby/blob/trunk/gc.c#L2256
     rb_bug(#func"(): GC does not handle T_NODE 0x%x(%p) 0x%"PRIxVALUE, \
 	   BUILTIN_TYPE(obj), (void*)(obj), RBASIC(obj)->flags)
 
+const char *
+rb_imemo_name(enum imemo_type type)
+{
+    // put no default case to get a warning if an imemo type is missing
+    switch (type) {
+#define IMEMO_NAME(x) case imemo_##x: return #x;
+        IMEMO_NAME(env);
+        IMEMO_NAME(cref);
+        IMEMO_NAME(svar);
+        IMEMO_NAME(throw_data);
+        IMEMO_NAME(ifunc);
+        IMEMO_NAME(memo);
+        IMEMO_NAME(ment);
+        IMEMO_NAME(iseq);
+        IMEMO_NAME(tmpbuf);
+        IMEMO_NAME(ast);
+        IMEMO_NAME(parser_strterm);
+        IMEMO_NAME(callinfo);
+        IMEMO_NAME(callcache);
+#undef IMEMO_NAME
+    }
+    return "unknown";
+}
+
 #undef rb_imemo_new
 
 VALUE
@@ -11662,26 +11686,7 @@ rb_raw_obj_info(char *buff, const int buff_size, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L11686
 	    break;
 	  }
 	  case T_IMEMO: {
-	    const char *imemo_name = "\0";
-	    switch (imemo_type(obj)) {
-#define IMEMO_NAME(x) case imemo_##x: imemo_name = #x; break;
-		IMEMO_NAME(env);
-		IMEMO_NAME(cref);
-		IMEMO_NAME(svar);
-		IMEMO_NAME(throw_data);
-		IMEMO_NAME(ifunc);
-		IMEMO_NAME(memo);
-		IMEMO_NAME(ment);
-		IMEMO_NAME(iseq);
-		IMEMO_NAME(tmpbuf);
-                IMEMO_NAME(ast);
-                IMEMO_NAME(parser_strterm);
-                IMEMO_NAME(callinfo);
-                IMEMO_NAME(callcache);
-#undef IMEMO_NAME
-	      default: UNREACHABLE;
-	    }
-            APPENDF((BUFF_ARGS, "<%s> ", imemo_name));
+            APPENDF((BUFF_ARGS, "<%s> ", rb_imemo_name(imemo_type(obj))));
 
 	    switch (imemo_type(obj)) {
 	      case imemo_ment: {
diff --git a/internal/imemo.h b/internal/imemo.h
index 812b2a4..29318f1 100644
--- a/internal/imemo.h
+++ b/internal/imemo.h
@@ -150,6 +150,7 @@ VALUE rb_imemo_new_debug(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VAL https://github.com/ruby/ruby/blob/trunk/internal/imemo.h#L150
 #else
 VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0);
 #endif
+const char *rb_imemo_name(enum imemo_type type);
 RUBY_SYMBOL_EXPORT_END
 
 static inline enum imemo_type
-- 
cgit v0.10.2


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

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