19065730 64-bit lua doesn't have a separate path to find native modules
authorRich Burridge <rich.burridge@oracle.com>
Mon, 22 Sep 2014 08:30:56 -0700
changeset 2104 72ce614559ff
parent 2103 92b50cf5c69e
child 2105 b5dd48f1394b
19065730 64-bit lua doesn't have a separate path to find native modules 19636481 The lua binaries in /usr/bin should be 64-bit
components/lua/lua.p5m
components/lua/patches/solaris-64-bit.patch
--- a/components/lua/lua.p5m	Fri Sep 19 14:19:10 2014 -0700
+++ b/components/lua/lua.p5m	Mon Sep 22 08:30:56 2014 -0700
@@ -35,10 +35,8 @@
 set name=info.upstream-url value=$(COMPONENT_PROJECT_URL)
 set name=org.opensolaris.arc-caseid value=LSARC/2009/013
 set name=org.opensolaris.consolidation value=$(CONSOLIDATION)
-file path=usr/bin/$(MACH64)/lua
-file path=usr/bin/$(MACH64)/luac
-file path=usr/bin/lua
-file path=usr/bin/luac
+file usr/bin/$(MACH64)/lua path=usr/bin/lua
+file usr/bin/$(MACH64)/luac path=usr/bin/luac
 file path=usr/include/lauxlib.h
 file path=usr/include/lua.h
 file path=usr/include/luaconf.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/lua/patches/solaris-64-bit.patch	Mon Sep 22 08:30:56 2014 -0700
@@ -0,0 +1,111 @@
+When looking for lua shared objects, dynamically adjust the pathnames to
+include "64/", when running a 64-bit lua executable.
+
+For example:
+  /usr/lib/lua/5.2/gv.so
+becomes:
+  /usr/lib/lua/5.2/64/gv.so
+
+The lua maintainers are not interested in this patch.
+
+--- src/loadlib.c.orig	2014-09-19 06:57:40.032464104 -0700
++++ src/loadlib.c	2014-09-19 16:39:01.502592411 -0700
+@@ -346,29 +346,94 @@
+ }
+ 
+ 
++/*
++** Return 1 if template is a shared object (has an extension of ".so"),
++** otherwise 0.
++*/
++static int
++issharedobj(const char *template) {
++  const char *ext;
++  if (strlen(template) < 3)
++    return 0;
++  ext = template + strlen(template) - 3;
++  return strcmp(ext, ".so") == 0;
++}
++
++/*
++** Return 1 if this is a 64-bit executable, otherwise 0.
++*/
++static int is64bit() {
++  return sizeof(void *) == 8;
++}
++
+ static const char *searchpath (lua_State *L, const char *name,
+                                              const char *path,
+                                              const char *sep,
+                                              const char *dirsep) {
+   luaL_Buffer msg;  /* to build error message */
++  char *name64;
+   luaL_buffinit(L, &msg);
+   if (*sep != '\0')  /* non-empty separator? */
+     name = luaL_gsub(L, name, sep, dirsep);  /* replace it by 'dirsep' */
++  if (is64bit()) {
++    name64 = calloc(strlen(name) + 4, 1);
++    strcpy(name64, "64/");
++    strcat(name64, name);
++  } else
++    name64 = strdup(name);
+   while ((path = pushnexttemplate(L, path)) != NULL) {
+-    const char *filename = luaL_gsub(L, lua_tostring(L, -1),
+-                                     LUA_PATH_MARK, name);
++    char *filename;
++    const char *item = lua_tostring(L, -1);
++
++    if (is64bit() && issharedobj(item)) {
++      name = name64;
++      if (strstr(item, LUA_PATH_MARK))
++        filename = (char *)luaL_gsub(L, item, LUA_PATH_MARK, name);
++      else {
++        /*
++         * There's nothing to substitute, so we have to go digging through the
++         * path to find where to put the 64-bit directory.  Search for "/" in
++         * the template element until we can't find any more, replace that with
++         * "?", and replace that with "/64/".
++         */
++        char *p1, *p2;
++        char *s = strdup(item);
++        for (p1 = s; p1; p1 = strstr(p1 + 1, "/"))
++          p2 = p1;
++        if (p2 != s)
++          *p2 = '?';
++        else {
++          /*
++           * We didn't find any slashes; that either means there aren't any, or
++           * item is in the root directory.
++           */
++          free(s);
++          s = calloc(strlen(item) + 3, 1);
++          if (item[0] == '/')
++            strcpy(s, "/64");
++          else
++            strcpy(s, "64/");
++          strcat(s, item);
++        }
++        filename = (char *)luaL_gsub(L, s, LUA_PATH_MARK, "/64/");
++        free(s);
++      }
++    } else
++      filename = (char *)luaL_gsub(L, item, LUA_PATH_MARK, name);
+     lua_remove(L, -2);  /* remove path template */
+-    if (readable(filename))  /* does file exist and is readable? */
++    if (readable(filename)) {  /* does file exist and is readable? */
++      free(name64);
+       return filename;  /* return that file name */
++    }
+     lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
+     lua_remove(L, -2);  /* remove file name */
+     luaL_addvalue(&msg);  /* concatenate error msg. entry */
+   }
+   luaL_pushresult(&msg);  /* create error message */
++  free(name64);
+   return NULL;  /* not found */
+ }
+ 
+-
+ static int ll_searchpath (lua_State *L) {
+   const char *f = searchpath(L, luaL_checkstring(L, 1),
+                                 luaL_checkstring(L, 2),