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

ruby-changes:52722

From: k0kubun <ko1@a...>
Date: Sun, 7 Oct 2018 17:03:41 +0900 (JST)
Subject: [ruby-changes:52722] k0kubun:r64934 (trunk): mjit_worker.c: clean up .obj file on mswin

k0kubun	2018-10-07 17:03:36 +0900 (Sun, 07 Oct 2018)

  New Revision: 64934

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

  Log:
    mjit_worker.c: clean up .obj file on mswin
    
    prior to this commit, .obj file is generated on current directory and nobody deletes that.
    This changes it to make sure it's generated to temporary directory and removes that.

  Modified files:
    trunk/mjit_worker.c
Index: mjit_worker.c
===================================================================
--- mjit_worker.c	(revision 64933)
+++ mjit_worker.c	(revision 64934)
@@ -691,9 +691,9 @@ static int https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L691
 compile_c_to_so(const char *c_file, const char *so_file)
 {
     int exit_code;
-    const char *files[] = { NULL, NULL, NULL, NULL, "-link", libruby_pathflag, NULL };
+    const char *files[] = { NULL, NULL, NULL, NULL, NULL, "-link", libruby_pathflag, NULL };
     char **args;
-    char *p;
+    char *p, *obj_file;
 
     /* files[0] = "-Fe*.dll" */
     files[0] = p = alloca(sizeof(char) * (rb_strlen_lit("-Fe") + strlen(so_file) + 1));
@@ -701,20 +701,28 @@ compile_c_to_so(const char *c_file, cons https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L701
     p = append_str2(p, so_file, strlen(so_file));
     *p = '\0';
 
-    /* files[1] = "-Yu*.pch" */
-    files[1] = p = alloca(sizeof(char) * (rb_strlen_lit("-Yu") + strlen(pch_file) + 1));
+    /* files[1] = "-Fo*.obj" */
+    /* We don't need .obj file, but it's somehow created to cwd without -Fo and we want to control the output directory. */
+    files[1] = p = alloca(sizeof(char) * (rb_strlen_lit("-Fo") + strlen(so_file) - rb_strlen_lit(DLEXT) + rb_strlen_lit(".obj") + 1));
+    obj_file = p = append_lit(p, "-Fo");
+    p = append_str2(p, so_file, strlen(so_file) - rb_strlen_lit(DLEXT));
+    p = append_lit(p, ".obj");
+    *p = '\0';
+
+    /* files[2] = "-Yu*.pch" */
+    files[2] = p = alloca(sizeof(char) * (rb_strlen_lit("-Yu") + strlen(pch_file) + 1));
     p = append_lit(p, "-Yu");
     p = append_str2(p, pch_file, strlen(pch_file));
     *p = '\0';
 
-    /* files[2] = "C:/.../rb_mjit_header-*.obj" */
-    files[2] = p = alloca(sizeof(char) * (strlen(pch_file) + 1));
+    /* files[3] = "C:/.../rb_mjit_header-*.obj" */
+    files[3] = p = alloca(sizeof(char) * (strlen(pch_file) + 1));
     p = append_str2(p, pch_file, strlen(pch_file) - strlen(".pch"));
     p = append_lit(p, ".obj");
     *p = '\0';
 
-    /* files[3] = "-Tc*.c" */
-    files[3] = p = alloca(sizeof(char) * (rb_strlen_lit("-Tc") + strlen(c_file) + 1));
+    /* files[4] = "-Tc*.c" */
+    files[4] = p = alloca(sizeof(char) * (rb_strlen_lit("-Tc") + strlen(c_file) + 1));
     p = append_lit(p, "-Tc");
     p = append_str2(p, c_file, strlen(c_file));
     *p = '\0';
@@ -742,8 +750,13 @@ compile_c_to_so(const char *c_file, cons https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L750
     }
     free(args);
 
-    if (exit_code != 0)
+    if (exit_code == 0) {
+        /* remove never-used .obj file. XXX: Is there any way not to generate this? */
+        if (!mjit_opts.save_temps) remove_file(obj_file);
+    }
+    else {
         verbose(2, "compile_c_to_so: compile error: %d", exit_code);
+    }
     return exit_code == 0;
 }
 #else /* _MSC_VER */

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

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