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

ruby-changes:48838

From: nobu <ko1@a...>
Date: Fri, 1 Dec 2017 13:27:36 +0900 (JST)
Subject: [ruby-changes:48838] nobu:r60955 (trunk): prelude.c.tmpl: escape comments

nobu	2017-12-01 13:27:32 +0900 (Fri, 01 Dec 2017)

  New Revision: 60955

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

  Log:
    prelude.c.tmpl: escape comments

  Modified files:
    trunk/template/prelude.c.tmpl
Index: template/prelude.c.tmpl
===================================================================
--- template/prelude.c.tmpl	(revision 60954)
+++ template/prelude.c.tmpl	(revision 60955)
@@ -9,6 +9,8 @@ class Prelude https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L9
   LINE_LIMIT = 509 # by C89
 
   C_ESC = {
+    "/*" => "/\\*",
+    "*/" => "*\\/",
     "\\" => "\\\\",
     '"' => '\"',
     "\n" => '\n',
@@ -19,7 +21,7 @@ class Prelude https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L21
   C_ESC_PAT = Regexp.union(*C_ESC.keys)
 
   def c_esc(str)
-    '"' + str.gsub(C_ESC_PAT) { C_ESC[$&] } + '"'
+    str.gsub(C_ESC_PAT) { C_ESC[$&] }
   end
   def prelude_base(filename)
     filename.chomp(".rb")
@@ -83,7 +85,7 @@ Prelude.new(output && output[/\w+(?=_pre https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L85
 % preludes = @preludes.values.sort
 % preludes.each {|i, prelude, lines, sub|
 
-static const char prelude_name<%=i%><%=%>[] = <%=c_esc(prelude_name(*prelude))%><%=%>;
+static const char prelude_name<%=i%><%=%>[] = "<%=c_esc(prelude_name(*prelude))%>";
 static const struct {
 %   size = beg = 0
 %   lines.each_with_index {|(line, comment), n|
@@ -100,15 +102,15 @@ static const struct { https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L102
 %   end
 } prelude_code<%=i%><%=%> = {
 %   size = 0
-#line 1 <%=c_esc(prelude)%>
+#line 1 "<%=c_esc(prelude)%>"
 %   lines.each_with_index {|(line, comment), n|
 %     if size + line.size >= Prelude::LINE_LIMIT
 %       size = 0
 ,
-#line <%=n+1%> <%=c_esc(prelude)%>
+#line <%=n+1%> "<%=c_esc(prelude)%>"
 %     end
 %     size += line.size
-<%=c_esc(line)%><%=%><%if comment%>/* <%=comment%> */<%end%>
+"<%=c_esc(line)%>"<%if comment%>/* <%=c_esc(comment)%> */<%end%>
 %   }
 #line <%=_erbout.count("\n")+2%> "<%=@init_name%>.c"
 };

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

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