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

ruby-changes:51974

From: k0kubun <ko1@a...>
Date: Sun, 5 Aug 2018 12:12:13 +0900 (JST)
Subject: [ruby-changes:51974] k0kubun:r64189 (trunk): mjit.c: initialize prebuilt precompiled header

k0kubun	2018-08-05 12:12:09 +0900 (Sun, 05 Aug 2018)

  New Revision: 64189

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

  Log:
    mjit.c: initialize prebuilt precompiled header
    
    file name correctly. This allows to use the header installed by r64188.
    
    win32/Makefile.sub: define prebuilt precompiled header path instead of
    unused min header path

  Modified files:
    trunk/mjit.c
    trunk/win32/Makefile.sub
Index: win32/Makefile.sub
===================================================================
--- win32/Makefile.sub	(revision 64188)
+++ win32/Makefile.sub	(revision 64189)
@@ -1329,7 +1329,7 @@ mjit_config.h: https://github.com/ruby/ruby/blob/trunk/win32/Makefile.sub#L1329
 #define RUBY_MJIT_CONFIG_H 1
 
 #define MJIT_BUILD_DIR "$(MAKEDIR)"
-#define MJIT_MIN_HEADER_NAME "/$(MJIT_HEADER_INSTALL_DIR)/$(MJIT_MIN_HEADER_NAME)"
+#define MJIT_PRECOMPILED_HEADER_NAME "/$(MJIT_HEADER_INSTALL_DIR)/$(MJIT_PRECOMPILED_HEADER_NAME)"
 <<KEEP
 	@
 	@(set sep=#define MJIT_CC_COMMON ) & \
Index: mjit.c
===================================================================
--- mjit.c	(revision 64188)
+++ mjit.c	(revision 64189)
@@ -214,8 +214,6 @@ static int in_jit; https://github.com/ruby/ruby/blob/trunk/mjit.c#L214
 /* Defined in the client thread before starting MJIT threads:  */
 /* Used C compiler path.  */
 static const char *cc_path;
-/* Name of the header file.  */
-static char *header_file;
 /* Name of the precompiled header file.  */
 static char *pch_file;
 /* Path of "/tmp", which can be changed to $TMP in MinGW. */
@@ -226,6 +224,11 @@ static VALUE valid_class_serials; https://github.com/ruby/ruby/blob/trunk/mjit.c#L224
 /* Ruby level interface module.  */
 VALUE rb_mMJIT;
 
+#ifndef _MSC_VER
+/* Name of the header file.  */
+static char *header_file;
+#endif
+
 #ifdef _WIN32
 /* Linker option to enable libruby. */
 static char *libruby_pathflag;
@@ -1064,11 +1067,7 @@ convert_unit_to_func(struct rb_mjit_unit https://github.com/ruby/ruby/blob/trunk/mjit.c#L1067
     /* -include-pch is used for Clang */
 #else
     {
-# ifdef __GNUC__
         const char *s = pch_file;
-# else
-        const char *s = header_file;
-# endif
         const char *e = header_name_end(s);
 
         fprintf(f, "#include \"");
@@ -1457,7 +1456,8 @@ mjit_get_iseq_func(struct rb_iseq_consta https://github.com/ruby/ruby/blob/trunk/mjit.c#L1456
 
 extern VALUE ruby_archlibdir_path, ruby_prefix_path;
 
-static void
+/* Initialize header_file, pch_file, libruby_pathflag. Return TRUE on success. */
+static int
 init_header_filename(void)
 {
     int fd;
@@ -1465,9 +1465,6 @@ init_header_filename(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1465
     VALUE basedir_val;
     const char *basedir;
     size_t baselen;
-    /* A name of the header file included in any C file generated by MJIT for iseqs. */
-    static const char header_name[] = MJIT_MIN_HEADER_NAME;
-    const size_t header_name_len = sizeof(header_name) - 1;
     char *p;
 #ifdef _WIN32
     static const char libpathflag[] =
@@ -1494,16 +1491,44 @@ init_header_filename(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1491
     }
 #endif
 
-    header_file = xmalloc(baselen + header_name_len + 1);
-    p = append_str2(header_file, basedir, baselen);
-    p = append_str2(p, header_name, header_name_len + 1);
-    if ((fd = rb_cloexec_open(header_file, O_RDONLY, 0)) < 0) {
-        verbose(2, "Cannot access header file %s\n", header_file);
-        xfree(header_file);
-        header_file = NULL;
-        return;
+#ifndef _MSC_VER
+    {
+        /* A name of the header file included in any C file generated by MJIT for iseqs. */
+        static const char header_name[] = MJIT_MIN_HEADER_NAME;
+        const size_t header_name_len = sizeof(header_name) - 1;
+
+        header_file = xmalloc(baselen + header_name_len + 1);
+        p = append_str2(header_file, basedir, baselen);
+        p = append_str2(p, header_name, header_name_len + 1);
+        if ((fd = rb_cloexec_open(header_file, O_RDONLY, 0)) < 0) {
+            verbose(1, "Cannot access header file: %s", header_file);
+            xfree(header_file);
+            header_file = NULL;
+            return FALSE;
+        }
+        (void)close(fd);
     }
-    (void)close(fd);
+
+    pch_file = get_uniq_filename(0, MJIT_TMP_PREFIX "h", ".h.gch");
+    if (pch_file == NULL)
+        return FALSE;
+#else
+    {
+        static const char pch_name[] = MJIT_PRECOMPILED_HEADER_NAME;
+        const size_t pch_name_len = sizeof(pch_name) - 1;
+
+        pch_file = xmalloc(baselen + pch_name_len + 1);
+        p = append_str2(pch_file, basedir, baselen);
+        p = append_str2(p, pch_name, pch_name_len + 1);
+        if ((fd = rb_cloexec_open(pch_file, O_RDONLY, 0)) < 0) {
+            verbose(1, "Cannot access precompiled header file: %s", pch_file);
+            xfree(pch_file);
+            pch_file = NULL;
+            return FALSE;
+        }
+        (void)close(fd);
+    }
+#endif
 
 #ifdef _WIN32
     basedir_val = ruby_archlibdir_path;
@@ -1514,6 +1539,8 @@ init_header_filename(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1539
     p = append_str2(p, basedir, baselen);
     *p = '\0';
 #endif
+
+    return TRUE;
 }
 
 /* This is called after each fork in the child in to switch off MJIT
@@ -1676,9 +1703,7 @@ mjit_init(struct mjit_options *opts) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1703
     tmp_dir = system_tmpdir();
     verbose(2, "MJIT: tmp_dir is %s", tmp_dir);
 
-    init_header_filename();
-    pch_file = get_uniq_filename(0, MJIT_TMP_PREFIX "h", ".h.gch");
-    if (header_file == NULL || pch_file == NULL) {
+    if (!init_header_filename()) {
         mjit_enabled = FALSE;
         verbose(1, "Failure in MJIT header file name initialization\n");
         return;
@@ -1792,13 +1817,14 @@ mjit_finish(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1817
     rb_native_cond_destroy(&mjit_worker_wakeup);
     rb_native_cond_destroy(&mjit_gc_wakeup);
 
-    /* cleanup temps */
+#ifndef _MSC_VER /* mswin has prebuilt precompiled header */
     if (!mjit_opts.save_temps)
         remove_file(pch_file);
 
+    xfree(header_file); header_file = NULL;
+#endif
     xfree(tmp_dir); tmp_dir = NULL;
     xfree(pch_file); pch_file = NULL;
-    xfree(header_file); header_file = NULL;
 
     mjit_call_p = FALSE;
     free_list(&unit_queue);

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

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