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

ruby-changes:43681

From: ko1 <ko1@a...>
Date: Tue, 26 Jul 2016 19:07:16 +0900 (JST)
Subject: [ruby-changes:43681] ko1:r55754 (trunk): * gc.c (rb_raw_obj_info): support to show Proc obj.

ko1	2016-07-26 19:07:12 +0900 (Tue, 26 Jul 2016)

  New Revision: 55754

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55754

  Log:
    * gc.c (rb_raw_obj_info): support to show Proc obj.

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55753)
+++ ChangeLog	(revision 55754)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jul 26 19:06:39 2016  Koichi Sasada  <ko1@a...>
+
+	* gc.c (rb_raw_obj_info): support to show Proc obj.
+
 Tue Jul 26 18:55:55 2016  Koichi Sasada  <ko1@a...>
 
 	* gc.c (gc_mark): add `inline' explicitly.
Index: gc.c
===================================================================
--- gc.c	(revision 55753)
+++ gc.c	(revision 55754)
@@ -9139,6 +9139,30 @@ method_type_name(rb_method_type_t type) https://github.com/ruby/ruby/blob/trunk/gc.c#L9139
     (assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)), \
      FL_TEST((ary), RARRAY_EMBED_FLAG)!=0)
 
+static void
+rb_raw_iseq_info(char *buff, const int buff_size, const rb_iseq_t *iseq)
+{
+    if (iseq->body->location.label) {
+	snprintf(buff, buff_size, "%s %s@%s:%d", buff,
+		 RSTRING_PTR(iseq->body->location.label),
+		 RSTRING_PTR(iseq->body->location.path),
+		 FIX2INT(iseq->body->location.first_lineno));
+    }
+}
+
+static const rb_iseq_t *
+vm_proc_iseq(VALUE procval)
+{
+    rb_proc_t *proc = RTYPEDDATA_DATA(procval);
+
+    if (RUBY_VM_NORMAL_ISEQ_P(proc->block.iseq)) {
+	return proc->block.iseq;
+    }
+    else {
+	return NULL;
+    }
+}
+
 const char *
 rb_raw_obj_info(char *buff, const int buff_size, VALUE obj)
 {
@@ -9206,9 +9230,15 @@ rb_raw_obj_info(char *buff, const int bu https://github.com/ruby/ruby/blob/trunk/gc.c#L9230
 	      break;
 	  }
 	  case T_DATA: {
-	      const char * const type_name = rb_objspace_data_type_name(obj);
-	      if (type_name) {
-		  snprintf(buff, buff_size, "%s %s", buff, type_name);
+	      const rb_iseq_t *iseq;
+	      if (rb_obj_is_proc(obj) && (iseq = vm_proc_iseq(obj)) != NULL) {
+		  rb_raw_iseq_info(buff, buff_size, iseq);
+	      }
+	      else {
+		  const char * const type_name = rb_objspace_data_type_name(obj);
+		  if (type_name) {
+		      snprintf(buff, buff_size, "%s %s", buff, type_name);
+		  }
 	      }
 	      break;
 	  }
@@ -9242,13 +9272,7 @@ rb_raw_obj_info(char *buff, const int bu https://github.com/ruby/ruby/blob/trunk/gc.c#L9272
 		}
 		case imemo_iseq: {
 		    const rb_iseq_t *iseq = (const rb_iseq_t *)obj;
-
-		    if (iseq->body->location.label) {
-			snprintf(buff, buff_size, "%s %s@%s:%d", buff,
-				 RSTRING_PTR(iseq->body->location.label),
-				 RSTRING_PTR(iseq->body->location.path),
-				 FIX2INT(iseq->body->location.first_lineno));
-		    }
+		    rb_raw_iseq_info(buff, buff_size, iseq);
 		    break;
 		}
 		default:

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

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