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

ruby-changes:50130

From: nobu <ko1@a...>
Date: Tue, 6 Feb 2018 19:30:58 +0900 (JST)
Subject: [ruby-changes:50130] nobu:r62248 (trunk): mjit.c: build dir prefix

nobu	2018-02-06 19:30:53 +0900 (Tue, 06 Feb 2018)

  New Revision: 62248

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

  Log:
    mjit.c: build dir prefix
    
    * mjit.c (init_header_filename): prepend basedir to header build
      dir too, so that the header can be found when running not in the
      build directory.

  Modified files:
    trunk/mjit.c
Index: mjit.c
===================================================================
--- mjit.c	(revision 62247)
+++ mjit.c	(revision 62248)
@@ -1043,12 +1043,32 @@ mjit_get_iseq_func(const struct rb_iseq_ https://github.com/ruby/ruby/blob/trunk/mjit.c#L1043
 }
 
 /* A name of the header file included in any C file generated by MJIT for iseqs.  */
-#define RUBY_MJIT_HEADER_FILE ("rb_mjit_min_header-" RUBY_VERSION ".h")
+#define RUBY_MJIT_HEADER_FILE "rb_mjit_min_header-" RUBY_VERSION ".h"
 /* GCC and CLANG executable paths.  TODO: The paths should absolute
    ones to prevent changing C compiler for security reasons.  */
 #define GCC_PATH "gcc"
 #define CLANG_PATH "clang"
 
+#define append_str2(p, str, len) ((char *)memcpy((p), str, (len))+(len))
+#define append_str(p, str) append_str2(p, str, sizeof(str)-1)
+
+static char *
+build_header_path(const char *basedir, size_t baselen, const char *dir, size_t dirlen)
+{
+    static const char header_basename[] = "/" RUBY_MJIT_HEADER_FILE;
+    char *p, *path = xmalloc(baselen + dirlen + sizeof(header_basename));
+    if (path == NULL)
+        return NULL;
+    p = path;
+    p = append_str2(p, basedir, baselen);
+    p = append_str2(p, dir, dirlen);
+    append_str2(p, header_basename, sizeof(header_basename));
+    return path;
+}
+
+#define BUILD_HEADER_PATH(basedir, baselen, dir) \
+    build_header_path(basedir, baselen, dir, rb_strlen_lit(dir))
+
 static void
 init_header_filename(void)
 {
@@ -1056,27 +1076,20 @@ init_header_filename(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1076
     /* Root path of the running ruby process. Equal to RbConfig::TOPDIR.  */
     VALUE basedir_val;
     char *basedir;
+    size_t baselen;
 
     basedir_val = rb_const_get(rb_cObject, rb_intern_const("TMP_RUBY_PREFIX"));
-    basedir = StringValueCStr(basedir_val);
+    basedir = StringValuePtr(basedir_val);
+    baselen = RSTRING_LEN(basedir_val);
 
-    header_file = xmalloc(strlen(MJIT_HEADER_BUILD_DIR) + 2 + strlen(RUBY_MJIT_HEADER_FILE));
+    header_file = BUILD_HEADER_PATH(basedir, baselen, "/"MJIT_HEADER_BUILD_DIR);
     if (header_file == NULL)
         return;
-    strcpy(header_file, MJIT_HEADER_BUILD_DIR);
-    strcat(header_file, "/");
-    strcat(header_file, RUBY_MJIT_HEADER_FILE);
-
     if ((f = fopen(header_file, "r")) == NULL) {
         xfree(header_file);
-        header_file = xmalloc(strlen(basedir) + 1 + strlen(MJIT_HEADER_INSTALL_DIR) + 1 + strlen(RUBY_MJIT_HEADER_FILE) + 1);
+        header_file = BUILD_HEADER_PATH(basedir, baselen, "/"MJIT_HEADER_INSTALL_DIR);
         if (header_file == NULL)
             return;
-        strcpy(header_file, basedir);
-        strcat(header_file, "/");
-        strcat(header_file, MJIT_HEADER_INSTALL_DIR);
-        strcat(header_file, "/");
-        strcat(header_file, RUBY_MJIT_HEADER_FILE);
         if ((f = fopen(header_file, "r")) == NULL) {
             xfree(header_file);
             header_file = NULL;
@@ -1086,13 +1099,14 @@ init_header_filename(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1099
     fclose(f);
 
 #ifdef _WIN32
-    libruby_build = xmalloc(2 + strlen(basedir) + 1);
-    strcpy(libruby_build, "-L");
-    strcat(libruby_build, basedir);
-    libruby_installed = xmalloc(2 + strlen(basedir) + 4 + 1);
-    strcpy(libruby_installed, "-L");
-    strcat(libruby_installed, basedir);
-    strcat(libruby_installed, "/lib");
+    p = libruby_build = xmalloc(2 + baselen + 1);
+    p = append_str(p, "-L");
+    p = append_str2(p, basedir, baselen);
+    *p = '\0';
+    libruby_installed = xmalloc(2 + baselen + 4 + 1);
+    p = append_str2(libruby_installed, libruby_build, p - libruby_build);
+    p = append_str(p, "/lib");
+    *p = '\0';
 #endif
 }
 

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

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