3194N/AWhen looking for lua shared objects, dynamically adjust the pathnames to
3194N/Ainclude "64/", when running a 64-bit lua executable.
3194N/A
3194N/AFor example:
3194N/A /usr/lib/lua/5.2/gv.so
3194N/Abecomes:
3194N/A /usr/lib/lua/5.2/64/gv.so
3194N/A
3194N/AThe lua maintainers are not interested in this patch.
3194N/A
3194N/A--- src/loadlib.c.orig 2014-09-19 06:57:40.032464104 -0700
3194N/A+++ src/loadlib.c 2014-09-19 16:39:01.502592411 -0700
3194N/A@@ -346,29 +346,94 @@
3194N/A }
3194N/A
3194N/A
3194N/A+/*
3194N/A+** Return 1 if template is a shared object (has an extension of ".so"),
3194N/A+** otherwise 0.
3194N/A+*/
3194N/A+static int
3194N/A+issharedobj(const char *template) {
3194N/A+ const char *ext;
3194N/A+ if (strlen(template) < 3)
3194N/A+ return 0;
3194N/A+ ext = template + strlen(template) - 3;
3194N/A+ return strcmp(ext, ".so") == 0;
3194N/A+}
3194N/A+
3194N/A+/*
3194N/A+** Return 1 if this is a 64-bit executable, otherwise 0.
3194N/A+*/
3194N/A+static int is64bit() {
3194N/A+ return sizeof(void *) == 8;
3194N/A+}
3194N/A+
3194N/A static const char *searchpath (lua_State *L, const char *name,
3194N/A const char *path,
3194N/A const char *sep,
3194N/A const char *dirsep) {
3194N/A luaL_Buffer msg; /* to build error message */
3194N/A+ char *name64;
3194N/A luaL_buffinit(L, &msg);
3194N/A if (*sep != '\0') /* non-empty separator? */
3194N/A name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */
3194N/A+ if (is64bit()) {
3194N/A+ name64 = calloc(strlen(name) + 4, 1);
3194N/A+ strcpy(name64, "64/");
3194N/A+ strcat(name64, name);
3194N/A+ } else
3194N/A+ name64 = strdup(name);
3194N/A while ((path = pushnexttemplate(L, path)) != NULL) {
3194N/A- const char *filename = luaL_gsub(L, lua_tostring(L, -1),
3194N/A- LUA_PATH_MARK, name);
3194N/A+ char *filename;
3194N/A+ const char *item = lua_tostring(L, -1);
3194N/A+
3194N/A+ if (is64bit() && issharedobj(item)) {
3194N/A+ name = name64;
3194N/A+ if (strstr(item, LUA_PATH_MARK))
3194N/A+ filename = (char *)luaL_gsub(L, item, LUA_PATH_MARK, name);
3194N/A+ else {
3194N/A+ /*
3194N/A+ * There's nothing to substitute, so we have to go digging through the
3194N/A+ * path to find where to put the 64-bit directory. Search for "/" in
3194N/A+ * the template element until we can't find any more, replace that with
3194N/A+ * "?", and replace that with "/64/".
3194N/A+ */
3194N/A+ char *p1, *p2;
3194N/A+ char *s = strdup(item);
3194N/A+ for (p1 = s; p1; p1 = strstr(p1 + 1, "/"))
3194N/A+ p2 = p1;
3194N/A+ if (p2 != s)
3194N/A+ *p2 = '?';
3194N/A+ else {
3194N/A+ /*
3194N/A+ * We didn't find any slashes; that either means there aren't any, or
3194N/A+ * item is in the root directory.
3194N/A+ */
3194N/A+ free(s);
3194N/A+ s = calloc(strlen(item) + 3, 1);
3194N/A+ if (item[0] == '/')
3194N/A+ strcpy(s, "/64");
3194N/A+ else
3194N/A+ strcpy(s, "64/");
3194N/A+ strcat(s, item);
3194N/A+ }
3194N/A+ filename = (char *)luaL_gsub(L, s, LUA_PATH_MARK, "/64/");
3194N/A+ free(s);
3194N/A+ }
3194N/A+ } else
3194N/A+ filename = (char *)luaL_gsub(L, item, LUA_PATH_MARK, name);
3194N/A lua_remove(L, -2); /* remove path template */
3194N/A- if (readable(filename)) /* does file exist and is readable? */
3194N/A+ if (readable(filename)) { /* does file exist and is readable? */
3194N/A+ free(name64);
3194N/A return filename; /* return that file name */
3194N/A+ }
3194N/A lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
3194N/A lua_remove(L, -2); /* remove file name */
3194N/A luaL_addvalue(&msg); /* concatenate error msg. entry */
3194N/A }
3194N/A luaL_pushresult(&msg); /* create error message */
3194N/A+ free(name64);
3194N/A return NULL; /* not found */
3194N/A }
3194N/A
3194N/A-
3194N/A static int ll_searchpath (lua_State *L) {
3194N/A const char *f = searchpath(L, luaL_checkstring(L, 1),
3194N/A luaL_checkstring(L, 2),