From 9da6b8dfdd14e2afe66ffeed86e5456469b1fb19 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 10 Feb 2018 01:23:47 +0000 Subject: [PATCH] mjit.c: chomp suffix first git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62339 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- mjit.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/mjit.c b/mjit.c index fa12a3f7d6..3755bd32cd 100644 --- a/mjit.c +++ b/mjit.c @@ -786,16 +786,21 @@ convert_unit_to_func(struct rb_mjit_unit *unit) /* -include-pch is used for Clang */ if (mjit_opts.cc == MJIT_CC_GCC) { const char *s = pch_file; + const char *e = s + strlen(s); + static const char suffix[] = ".gch"; + fprintf(f, "#include \""); + /* chomp .gch suffix */ + if (e > s+sizeof(suffix)-1 && strcmp(e-sizeof(suffix)+1, suffix) == 0) { + e -= sizeof(suffix)-1; + } /* print pch_file except .gch */ - for (; strcmp(s, ".gch") != 0; s++) { + for (; s < e; s++) { switch(*s) { - case '\\': - fprintf(f, "\\%c", *s); - break; - default: - fprintf(f, "%c", *s); + case '\\': case '"': + fputc('\\', f); } + fputc(*s, f); } fprintf(f, "\"\n"); }