summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mjit.c17
1 files 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");
}