From 5ff72d05693bbb2aba9094144b6ee8d8da77f1ca Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 4 Apr 2018 04:28:47 +0000 Subject: iseq.c: strip trailing spaces in dump git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- iseq.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/iseq.c b/iseq.c index fcf74fc017..1bd89408d1 100644 --- a/iseq.c +++ b/iseq.c @@ -1806,6 +1806,15 @@ rb_insn_operand_intern(const rb_iseq_t *iseq, return ret; } +static VALUE +right_strip(VALUE str) +{ + const char *beg = RSTRING_PTR(str), *end = RSTRING_END(str); + while (end-- > beg && *end == ' '); + rb_str_set_len(str, end - beg + 1); + return str; +} + /** * Disassemble a instruction * Iseq -> Iseq inspect object @@ -1867,12 +1876,13 @@ rb_iseq_disasm_insn(VALUE ret, const VALUE *code, size_t pos, } } + right_strip(str); if (ret) { rb_str_cat2(str, "\n"); rb_str_concat(ret, str); } else { - printf("%s\n", RSTRING_PTR(str)); + printf("%.*s\n", (int)RSTRING_LEN(str), RSTRING_PTR(str)); } return len; } @@ -2011,7 +2021,7 @@ rb_iseq_disasm(const rb_iseq_t *iseq) if (*argi) rb_str_catf(str, "<%s>", argi); if ((width -= RSTRING_LEN(str)) > 0) rb_str_catf(str, "%*s", (int)width, ""); } - rb_str_cat2(str, "\n"); + rb_str_cat_cstr(right_strip(str), "\n"); } /* show each line */ -- cgit v1.2.3