ruby-changes:50676
From: nobu <ko1@a...>
Date: Mon, 19 Mar 2018 23:12:05 +0900 (JST)
Subject: [ruby-changes:50676] nobu:r62841 (trunk): parse.y: NUL-terminate ruby_sourcefile
nobu 2018-03-19 23:12:00 +0900 (Mon, 19 Mar 2018) New Revision: 62841 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62841 Log: parse.y: NUL-terminate ruby_sourcefile * parse.y (yycompile): in some cases (warning, error, dtrace,...), ruby_sourcefile is expected to be NUL-terminated, so ensure it. * template/prelude.c.tmpl (prelude_name): NUL-terminate to get rid of copying static data. Modified files: trunk/parse.y trunk/template/prelude.c.tmpl Index: template/prelude.c.tmpl =================================================================== --- template/prelude.c.tmpl (revision 62840) +++ template/prelude.c.tmpl (revision 62841) @@ -86,9 +86,7 @@ Prelude.new(output && output[/\w+(?=_pre https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L86 % preludes.each {|i, prelude, lines, sub| % name = prelude_name(*prelude) -static const struct { - char L0[<%=name.size%><%=%>]; -} prelude_name<%=i%><%=%> = {"<%=c_esc(name)%>"}; +static const char prelude_name<%=i%><%=%>[] = "<%=c_esc(name)%>"; static const struct { % size = beg = 0 % lines.each_with_index {|(line, comment), n| @@ -138,7 +136,8 @@ prelude_prefix_path(VALUE self) https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L136 % end % unless preludes.empty? -#define PRELUDE_STR(n) rb_usascii_str_new_static(prelude_##n.L0, sizeof(prelude_##n)) +#define PRELUDE_NAME(n) rb_usascii_str_new_static(prelude_name##n, sizeof(prelude_name##n)-1) +#define PRELUDE_CODE(n) rb_usascii_str_new_static(prelude_code##n.L0, sizeof(prelude_code##n)) #if defined __GNUC__ && __GNUC__ >= 5 # pragma GCC diagnostic push # pragma GCC diagnostic error "-Wmissing-field-initializers" @@ -189,8 +188,8 @@ prelude_require(VALUE self, VALUE nth) https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L188 % @preludes.each_value do |i, prelude, lines, sub| % if sub case <%=i%><%=%>: - code = PRELUDE_STR(code<%=i%><%=%>); - name = PRELUDE_STR(name<%=i%><%=%>); + code = PRELUDE_CODE(<%=i%><%=%>); + name = PRELUDE_NAME(<%=i%><%=%>); break; % end % end @@ -222,7 +221,7 @@ Init_<%=@init_name%><%=%>(void) https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L221 % end % preludes.each do |i, prelude, lines, sub| % next if sub - prelude_eval(PRELUDE_STR(code<%=i%><%=%>), PRELUDE_STR(name<%=i%><%=%>), 1); + prelude_eval(PRELUDE_CODE(<%=i%><%=%>), PRELUDE_NAME(<%=i%><%=%>), 1); % end % if @have_sublib rb_gc_force_recycle(prelude); Index: parse.y =================================================================== --- parse.y (revision 62840) +++ parse.y (revision 62841) @@ -4889,7 +4889,7 @@ yycompile(VALUE vparser, struct parser_p https://github.com/ruby/ruby/blob/trunk/parse.y#L4889 { rb_ast_t *ast; p->ruby_sourcefile_string = rb_str_new_frozen(fname); - p->ruby_sourcefile = RSTRING_PTR(fname); + p->ruby_sourcefile = StringValueCStr(fname); p->ruby_sourceline = line - 1; p->ast = ast = rb_ast_new(); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/