summaryrefslogtreecommitdiff
path: root/ruby-runner.c
diff options
context:
space:
mode:
Diffstat (limited to 'ruby-runner.c')
-rw-r--r--ruby-runner.c91
1 files changed, 44 insertions, 47 deletions
diff --git a/ruby-runner.c b/ruby-runner.c
index b756c219fa..48acf4396e 100644
--- a/ruby-runner.c
+++ b/ruby-runner.c
@@ -7,14 +7,11 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include "ruby-runner.h"
-
-#ifdef MAKE_MJIT_BUILD_DIR
-const char MJIT_HEADER[] = BUILDDIR "/" MJIT_MIN_HEADER;
-#else
+#ifdef _WIN32
+# error This feature is unnecessary on Windows in favor of SxS.
+#endif
-#define STRINGIZE(expr) STRINGIZE0(expr)
-#define STRINGIZE0(expr) #expr
+#include "ruby-runner.h"
static void
insert_env_path(const char *envname, const char *paths, size_t size, int prepend)
@@ -24,29 +21,41 @@ insert_env_path(const char *envname, const char *paths, size_t size, int prepend
size_t n = 0;
if (env) {
- while ((c = *env) == PATH_SEP) ++env;
- n = strlen(env);
- while (n > 0 && env[n-1] == PATH_SEP) --n;
+ while ((c = *env) == PATH_SEP) ++env;
+ n = strlen(env);
+ while (n > 0 && env[n-1] == PATH_SEP) --n;
}
if (c) {
- char *e = malloc(size+n+1);
- size_t pos = 0;
- if (prepend) {
- memcpy(e, paths, pos = size-1);
- e[pos++] = PATH_SEP;
- }
- memcpy(e+pos, env, n);
- pos += n;
- if (!prepend) {
- e[pos++] = PATH_SEP;
- memcpy(e+pos, paths, size-1);
- pos += size-1;
- }
- e[pos] = '\0';
- env = e;
+ char *e = malloc(size+n+1);
+ size_t pos = 0;
+ if (prepend) {
+ if (size == n || (size < n && env[size] == PATH_SEP)) {
+ if (strncmp(paths, env, size) == 0) {
+ free(e);
+ return;
+ }
+ }
+ memcpy(e, paths, pos = size-1);
+ e[pos++] = PATH_SEP;
+ }
+ memcpy(e+pos, env, n);
+ pos += n;
+ if (!prepend) {
+ if (size == n || (size < n && env[n-size-1] == PATH_SEP)) {
+ if (strncmp(paths, &env[n-size], size) == 0) {
+ free(e);
+ return;
+ }
+ }
+ e[pos++] = PATH_SEP;
+ memcpy(e+pos, paths, size-1);
+ pos += size-1;
+ }
+ e[pos] = '\0';
+ env = e;
}
else {
- env = paths;
+ env = paths;
}
setenv(envname, env, 1);
}
@@ -58,16 +67,12 @@ main(int argc, char **argv)
static const char builddir[] = BUILDDIR;
static const char rubypath[] = BUILDDIR"/"STRINGIZE(RUBY_INSTALL_NAME);
static const char rubylib[] =
- ABS_SRCDIR"/lib"
- PATH_SEPARATOR
- EXTOUT_DIR"/common"
- PATH_SEPARATOR
- EXTOUT_DIR"/"ARCH
- ;
-#ifndef LOAD_RELATIVE
- static const char mjit_build_dir[] = BUILDDIR"/mjit_build_dir."SOEXT;
- struct stat stbuf;
-#endif
+ ABS_SRCDIR"/lib"
+ PATH_SEPARATOR
+ EXTOUT_DIR"/common"
+ PATH_SEPARATOR
+ EXTOUT_DIR"/"ARCH
+ ;
const size_t dirsize = sizeof(builddir);
const size_t namesize = sizeof(rubypath) - dirsize;
const char *rubyname = rubypath + dirsize;
@@ -75,18 +80,12 @@ main(int argc, char **argv)
insert_env_path(LIBPATHENV, builddir, dirsize, 1);
insert_env_path("RUBYLIB", rubylib, sizeof(rubylib), 0);
-#ifndef LOAD_RELATIVE
- if (PRELOADENV[0] && stat(mjit_build_dir, &stbuf) == 0) {
- insert_env_path(PRELOADENV, mjit_build_dir, sizeof(mjit_build_dir), 1);
- setenv("MJIT_SEARCH_BUILD_DIR", "true", 0);
- }
-#endif
if (!(p = strrchr(arg0, '/'))) p = arg0; else p++;
if (strlen(p) < namesize - 1) {
- argv[0] = malloc(p - arg0 + namesize);
- memcpy(argv[0], arg0, p - arg0);
- p = argv[0] + (p - arg0);
+ argv[0] = malloc(p - arg0 + namesize);
+ memcpy(argv[0], arg0, p - arg0);
+ p = argv[0] + (p - arg0);
}
memcpy(p, rubyname, namesize);
@@ -94,5 +93,3 @@ main(int argc, char **argv)
perror(rubypath);
return -1;
}
-
-#endif /* MAKE_MJIT_BUILD_DIR */