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

ruby-changes:50877

From: nobu <ko1@a...>
Date: Wed, 4 Apr 2018 13:28:52 +0900 (JST)
Subject: [ruby-changes:50877] nobu:r63084 (trunk): iseq.c: strip trailing spaces in dump

nobu	2018-04-04 13:28:47 +0900 (Wed, 04 Apr 2018)

  New Revision: 63084

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

  Log:
    iseq.c: strip trailing spaces in dump

  Modified files:
    trunk/iseq.c
Index: iseq.c
===================================================================
--- iseq.c	(revision 63083)
+++ iseq.c	(revision 63084)
@@ -1806,6 +1806,15 @@ rb_insn_operand_intern(const rb_iseq_t * https://github.com/ruby/ruby/blob/trunk/iseq.c#L1806
     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 VAL https://github.com/ruby/ruby/blob/trunk/iseq.c#L1876
 	}
     }
 
+    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) https://github.com/ruby/ruby/blob/trunk/iseq.c#L2021
 	    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 */

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

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