mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
68f374727a
commit
6916130566
2 changed files with 7 additions and 8 deletions
2
parse.y
2
parse.y
|
@ -4889,7 +4889,7 @@ yycompile(VALUE vparser, struct parser_params *p, VALUE fname, int line)
|
|||
{
|
||||
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();
|
||||
|
|
|
@ -86,9 +86,7 @@ Prelude.new(output && output[/\w+(?=_prelude.c\b)/] || 'prelude', ARGV, vpath).i
|
|||
% 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)
|
|||
% 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)
|
|||
% @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)
|
|||
% 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);
|
||||
|
|
Loading…
Reference in a new issue