ruby-changes:39026
From: ko1 <ko1@a...>
Date: Thu, 2 Jul 2015 18:37:14 +0900 (JST)
Subject: [ruby-changes:39026] ko1:r51107 (trunk): * gc.c (rb_raw_obj_info): separated from rb_obj_info().
ko1 2015-07-02 18:36:59 +0900 (Thu, 02 Jul 2015) New Revision: 51107 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51107 Log: * gc.c (rb_raw_obj_info): separated from rb_obj_info(). Fill internal object information into passed buffer. * gc.h: declare rb_raw_obj_info(). Modified files: trunk/ChangeLog trunk/gc.c trunk/gc.h Index: ChangeLog =================================================================== --- ChangeLog (revision 51106) +++ ChangeLog (revision 51107) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Jul 2 18:34:26 2015 Koichi Sasada <ko1@a...> + + * gc.c (rb_raw_obj_info): separated from rb_obj_info(). + Fill internal object information into passed buffer. + + * gc.h: declare rb_raw_obj_info(). + Thu Jul 2 16:15:04 2015 Nobuyoshi Nakada <nobu@r...> * dir.c (replace_real_basename): update path type by the target Index: gc.c =================================================================== --- gc.c (revision 51106) +++ gc.c (revision 51107) @@ -8839,8 +8839,6 @@ obj_type_name(VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L8839 return type_name(TYPE(obj), obj); } -#if RGENGC_OBJ_INFO - static const char * method_type_name(rb_method_type_t type) { @@ -8861,12 +8859,6 @@ method_type_name(rb_method_type_t type) https://github.com/ruby/ruby/blob/trunk/gc.c#L8859 rb_bug("method_type_name: unreachable (type: %d)", type); } - -#define OBJ_INFO_BUFFERS_NUM 10 -#define OBJ_INFO_BUFFERS_SIZE 0x100 -static int obj_info_buffers_index = 0; -static char obj_info_buffers[OBJ_INFO_BUFFERS_NUM][OBJ_INFO_BUFFERS_SIZE]; - /* from array.c */ # define ARY_SHARED_P(ary) \ (assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)), \ @@ -8875,21 +8867,15 @@ static char obj_info_buffers[OBJ_INFO_BU https://github.com/ruby/ruby/blob/trunk/gc.c#L8867 (assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)), \ FL_TEST((ary), RARRAY_EMBED_FLAG)!=0) -static const char * -obj_info(VALUE obj) +const char * +rb_raw_obj_info(char *buff, const int buff_size, VALUE obj) { - const int index = obj_info_buffers_index++; - char *const buff = &obj_info_buffers[index][0]; const int age = RVALUE_FLAGS_AGE(RBASIC(obj)->flags); const int type = BUILTIN_TYPE(obj); - if (obj_info_buffers_index >= OBJ_INFO_BUFFERS_NUM) { - obj_info_buffers_index = 0; - } - #define TF(c) ((c) != 0 ? "true" : "false") #define C(c, s) ((c) != 0 ? (s) : " ") - snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%p [%d%s%s%s%s] %s", + snprintf(buff, buff_size, "%p [%d%s%s%s%s] %s", (void *)obj, age, C(RVALUE_UNCOLLECTIBLE_BITMAP(obj), "L"), C(RVALUE_MARK_BITMAP(obj), "M"), @@ -8901,76 +8887,76 @@ obj_info(VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L8887 /* ignore */ } else if (RBASIC(obj)->klass == 0) { - snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s (temporary internal)", buff); + snprintf(buff, buff_size, "%s (temporary internal)", buff); } else { VALUE class_path = rb_class_path_cached(RBASIC(obj)->klass); if (!NIL_P(class_path)) { - snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s (%s)", buff, RSTRING_PTR(class_path)); + snprintf(buff, buff_size, "%s (%s)", buff, RSTRING_PTR(class_path)); } } #if GC_DEBUG - snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s @%s:%d", buff, RANY(obj)->file, RANY(obj)->line); + snprintf(buff, buff_size, "%s @%s:%d", buff, RANY(obj)->file, RANY(obj)->line); #endif switch (type) { case T_NODE: - snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s (%s)", buff, + snprintf(buff, buff_size, "%s (%s)", buff, ruby_node_name(nd_type(obj))); break; case T_ARRAY: - snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s [%s%s] len: %d", buff, + snprintf(buff, buff_size, "%s [%s%s] len: %d", buff, C(ARY_EMBED_P(obj), "E"), C(ARY_SHARED_P(obj), "S"), (int)RARRAY_LEN(obj)); break; case T_STRING: { - snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s %s", buff, RSTRING_PTR(obj)); - break; + snprintf(buff, buff_size, "%s %s", buff, RSTRING_PTR(obj)); + break; } case T_CLASS: { - VALUE class_path = rb_class_path_cached(obj); - if (!NIL_P(class_path)) { - snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s %s", buff, RSTRING_PTR(class_path)); - } - break; + VALUE class_path = rb_class_path_cached(obj); + if (!NIL_P(class_path)) { + snprintf(buff, buff_size, "%s %s", buff, RSTRING_PTR(class_path)); + } + break; } case T_DATA: { - const char * const type_name = rb_objspace_data_type_name(obj); - if (type_name && strcmp(type_name, "iseq") == 0) { - rb_iseq_t *iseq; - GetISeqPtr(obj, iseq); - if (iseq->location.label) { - snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s %s@%s:%d", buff, - RSTRING_PTR(iseq->location.label), RSTRING_PTR(iseq->location.path), (int)iseq->location.first_lineno); - } - } - else if (type_name) { - snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s %s", buff, type_name); - } - break; + const char * const type_name = rb_objspace_data_type_name(obj); + if (type_name && strcmp(type_name, "iseq") == 0) { + rb_iseq_t *iseq; + GetISeqPtr(obj, iseq); + if (iseq->location.label) { + snprintf(buff, buff_size, "%s %s@%s:%d", buff, + RSTRING_PTR(iseq->location.label), RSTRING_PTR(iseq->location.path), (int)iseq->location.first_lineno); + } + } + else if (type_name) { + snprintf(buff, buff_size, "%s %s", buff, type_name); + } + break; } case T_IMEMO: { - const char *imemo_name; - switch (imemo_type(obj)) { + const char *imemo_name; + switch (imemo_type(obj)) { #define IMEMO_NAME(x) case imemo_##x: imemo_name = #x; break; - IMEMO_NAME(none); - IMEMO_NAME(cref); - IMEMO_NAME(svar); - IMEMO_NAME(throw_data); - IMEMO_NAME(ifunc); - IMEMO_NAME(memo); - IMEMO_NAME(ment); - default: rb_bug("unknown IMEMO"); + IMEMO_NAME(none); + IMEMO_NAME(cref); + IMEMO_NAME(svar); + IMEMO_NAME(throw_data); + IMEMO_NAME(ifunc); + IMEMO_NAME(memo); + IMEMO_NAME(ment); + default: rb_bug("unknown IMEMO"); #undef IMEMO_NAME - } - snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s %s", buff, imemo_name); - if (imemo_type(obj) == imemo_ment) { - const rb_method_entry_t *me = &RANY(obj)->as.imemo.ment; - snprintf(buff, OBJ_INFO_BUFFERS_SIZE, "%s (called_id: %s, type: %s, alias: %d, class: %s)", buff, - rb_id2name(me->called_id), method_type_name(me->def->type), me->def->alias_count, obj_info(me->klass)); - } + } + snprintf(buff, buff_size, "%s %s", buff, imemo_name); + if (imemo_type(obj) == imemo_ment) { + const rb_method_entry_t *me = &RANY(obj)->as.imemo.ment; + snprintf(buff, buff_size, "%s (called_id: %s, type: %s, alias: %d, class: %s)", buff, + rb_id2name(me->called_id), method_type_name(me->def->type), me->def->alias_count, obj_info(me->klass)); + } } default: break; @@ -8981,6 +8967,24 @@ obj_info(VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L8967 return buff; } +#if RGENGC_OBJ_INFO +#define OBJ_INFO_BUFFERS_NUM 10 +#define OBJ_INFO_BUFFERS_SIZE 0x100 +static int obj_info_buffers_index = 0; +static char obj_info_buffers[OBJ_INFO_BUFFERS_NUM][OBJ_INFO_BUFFERS_SIZE]; + +static const char * +obj_info(VALUE obj) +{ + const int index = obj_info_buffers_index++; + char *const buff = &obj_info_buffers[index][0]; + + if (obj_info_buffers_index >= OBJ_INFO_BUFFERS_NUM) { + obj_info_buffers_index = 0; + } + + return rb_raw_obj_info(buff, OBJ_INFO_BUFFERS_SIZE, obj); +} #else static const char * obj_info(VALUE obj) Index: gc.h =================================================================== --- gc.h (revision 51106) +++ gc.h (revision 51107) @@ -84,6 +84,7 @@ int ruby_get_stack_grow_direction(volati https://github.com/ruby/ruby/blob/trunk/gc.h#L84 #define IS_STACK_DIR_UPPER() STACK_DIR_UPPER(1,0) const char *rb_obj_info(VALUE obj); +const char *rb_raw_obj_info(char *buff, const int buff_size, VALUE obj); RUBY_SYMBOL_EXPORT_BEGIN -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/