diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 0f100cb57..c37f476a5 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -7538,6 +7538,22 @@ dump_cpath(mrb_state *mrb, node *tree, int offset, uint16_t lineno) printf("name: %s\n", mrb_sym_dump(mrb, node_to_sym(tree->cdr))); } +/* + * This function restores the GC arena on return. + * For this reason, if a process that further generates an object is + * performed at the caller, the string pointer returned as the return + * value may become invalid. + */ +static const char* +str_dump(mrb_state *mrb, const char *str, int len) +{ + int ai = mrb_gc_arena_save(mrb); + mrb_value s = mrb_str_new(mrb, str, (mrb_int)len); + s = mrb_str_dump(mrb, s); + mrb_gc_arena_restore(mrb, ai); + return RSTRING_PTR(s); +} + static void dump_str(mrb_state *mrb, node *n, int offset, uint16_t lineno) { @@ -7545,7 +7561,7 @@ dump_str(mrb_state *mrb, node *n, int offset, uint16_t lineno) dump_prefix(offset, lineno); int len = node_to_int(n->car->car); if (len >= 0) { - printf("str: \"%.*s\"\n", len, (char*)n->car->cdr); + printf("str: %s\n", str_dump(mrb, (char*)n->car->cdr, node_to_int(n->car->car))); } else { printf("interpolation:\n"); @@ -7661,31 +7677,6 @@ dump_callargs(mrb_state *mrb, node *n, int offset, uint16_t lineno) } } -/* - * This function restores the GC arena on return. - * For this reason, if a process that further generates an object is - * performed at the caller, the string pointer returned as the return - * value may become invalid. - */ -#if 0 -static const char* -str_dump(mrb_state *mrb, const char *str, int len) -{ - int ai = mrb_gc_arena_save(mrb); - mrb_value s; -# if INT_MAX > MRB_INT_MAX / 4 - /* check maximum length with "\xNN" character */ - if (len > MRB_INT_MAX / 4) { - len = MRB_INT_MAX / 4; - } -# endif - s = mrb_str_new(mrb, str, (mrb_int)len); - s = mrb_str_dump(mrb, s); - mrb_gc_arena_restore(mrb, ai); - return RSTRING_PTR(s); -} -#endif - #endif void diff --git a/mrbgems/mruby-compiler/core/y.tab.c b/mrbgems/mruby-compiler/core/y.tab.c index f53a19bcf..c199e1ee2 100644 --- a/mrbgems/mruby-compiler/core/y.tab.c +++ b/mrbgems/mruby-compiler/core/y.tab.c @@ -14367,6 +14367,22 @@ dump_cpath(mrb_state *mrb, node *tree, int offset, uint16_t lineno) printf("name: %s\n", mrb_sym_dump(mrb, node_to_sym(tree->cdr))); } +/* + * This function restores the GC arena on return. + * For this reason, if a process that further generates an object is + * performed at the caller, the string pointer returned as the return + * value may become invalid. + */ +static const char* +str_dump(mrb_state *mrb, const char *str, int len) +{ + int ai = mrb_gc_arena_save(mrb); + mrb_value s = mrb_str_new(mrb, str, (mrb_int)len); + s = mrb_str_dump(mrb, s); + mrb_gc_arena_restore(mrb, ai); + return RSTRING_PTR(s); +} + static void dump_str(mrb_state *mrb, node *n, int offset, uint16_t lineno) { @@ -14374,7 +14390,7 @@ dump_str(mrb_state *mrb, node *n, int offset, uint16_t lineno) dump_prefix(offset, lineno); int len = node_to_int(n->car->car); if (len >= 0) { - printf("str: \"%.*s\"\n", len, (char*)n->car->cdr); + printf("str: %s\n", str_dump(mrb, (char*)n->car->cdr, node_to_int(n->car->car))); } else { printf("interpolation:\n"); @@ -14490,31 +14506,6 @@ dump_callargs(mrb_state *mrb, node *n, int offset, uint16_t lineno) } } -/* - * This function restores the GC arena on return. - * For this reason, if a process that further generates an object is - * performed at the caller, the string pointer returned as the return - * value may become invalid. - */ -#if 0 -static const char* -str_dump(mrb_state *mrb, const char *str, int len) -{ - int ai = mrb_gc_arena_save(mrb); - mrb_value s; -# if INT_MAX > MRB_INT_MAX / 4 - /* check maximum length with "\xNN" character */ - if (len > MRB_INT_MAX / 4) { - len = MRB_INT_MAX / 4; - } -# endif - s = mrb_str_new(mrb, str, (mrb_int)len); - s = mrb_str_dump(mrb, s); - mrb_gc_arena_restore(mrb, ai); - return RSTRING_PTR(s); -} -#endif - #endif void