ruby-changes:72490
From: Nobuyoshi <ko1@a...>
Date: Sun, 10 Jul 2022 16:38:47 +0900 (JST)
Subject: [ruby-changes:72490] ec303e49af (master): Split `rb_raw_obj_info`
https://git.ruby-lang.org/ruby.git/commit/?id=ec303e49af From ec303e49afeee9f6070d06f55650bbd373c33dd6 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 6 Jul 2022 00:23:49 +0900 Subject: Split `rb_raw_obj_info` --- gc.c | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/gc.c b/gc.c index f487cb88ed..86e1885fec 100644 --- a/gc.c +++ b/gc.c @@ -13671,12 +13671,6 @@ str_len_no_raise(VALUE str) https://github.com/ruby/ruby/blob/trunk/gc.c#L13671 return (int)len; } -const char * -rb_raw_obj_info(char *const buff, const size_t buff_size, VALUE obj) -{ - size_t pos = 0; - void *poisoned = asan_unpoison_object_temporary(obj); - #define BUFF_ARGS buff + pos, buff_size - pos #define APPEND_F(...) if ((pos += snprintf(BUFF_ARGS, "" __VA_ARGS__)) >= buff_size) goto end #define APPEND_S(s) do { \ @@ -13687,6 +13681,13 @@ rb_raw_obj_info(char *const buff, const size_t buff_size, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L13681 memcpy(buff + pos, (s), rb_strlen_lit(s) + 1); \ } \ } while (0) +#define TF(c) ((c) != 0 ? "true" : "false") +#define C(c, s) ((c) != 0 ? (s) : " ") + +static size_t +rb_raw_obj_info_common(char *const buff, const size_t buff_size, const VALUE obj) +{ + size_t pos = 0; if (SPECIAL_CONST_P(obj)) { APPEND_F("%s", obj_type_name(obj)); @@ -13699,9 +13700,6 @@ rb_raw_obj_info(char *const buff, const size_t buff_size, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L13700 } } else { -#define TF(c) ((c) != 0 ? "true" : "false") -#define C(c, s) ((c) != 0 ? (s) : " ") - const int type = BUILTIN_TYPE(obj); const int age = RVALUE_FLAGS_AGE(RBASIC(obj)->flags); if (is_pointer_to_heap(&rb_objspace, (void *)obj)) { @@ -13738,6 +13736,17 @@ rb_raw_obj_info(char *const buff, const size_t buff_size, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L13736 #if GC_DEBUG APPEND_F("@%s:%d", RANY(obj)->file, RANY(obj)->line); #endif + } + end: + + return pos; +} + +static size_t +rb_raw_obj_info_buitin_type(char *const buff, const size_t buff_size, const VALUE obj, size_t pos) +{ + if (LIKELY(pos < buff_size) && !SPECIAL_CONST_P(obj)) { + const enum ruby_value_type type = BUILTIN_TYPE(obj); switch (type) { case T_NODE: @@ -13924,20 +13933,34 @@ rb_raw_obj_info(char *const buff, const size_t buff_size, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L13933 default: break; } -#undef TF -#undef C } end: + + return pos; +} + +#undef TF +#undef C + +const char * +rb_raw_obj_info(char *const buff, const size_t buff_size, VALUE obj) +{ + void *poisoned = asan_unpoison_object_temporary(obj); + + size_t pos = rb_raw_obj_info_common(buff, buff_size, obj); + pos = rb_raw_obj_info_buitin_type(buff, buff_size, obj, pos); + if (pos >= buff_size) {} // truncated + if (poisoned) { asan_poison_object(obj); } return buff; +} #undef APPEND_S #undef APPEND_F #undef BUFF_ARGS -} #if RGENGC_OBJ_INFO #define OBJ_INFO_BUFFERS_NUM 10 -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/