perl/Test-Simple: update to 1.302205
[oi-userland.git] / components / runtime / lua-53 / patches / 03-solaris-64-bit.patch
blob285b0977a26eb80372e4ad17677d54cb92e3c750
1 When looking for lua shared objects, dynamically adjust the pathnames to
2 include "64/", when running a 64-bit lua executable.
4 For example:
5 /usr/lib/lua/5.3/gv.so
6 becomes:
7 /usr/lib/lua/5.3/64/gv.so
9 The lua maintainers are not interested in this patch.
11 --- lua-5.3.2/src/loadlib.c.~1~ 2017-03-10 20:14:16.979286128 +0300
12 +++ lua-5.3.2/src/loadlib.c 2017-03-10 20:20:03.100208291 +0300
13 @@ -393,25 +393,92 @@
17 +/*
18 +** Return 1 if template is a shared object (has an extension of ".so"),
19 +** otherwise 0.
20 +*/
21 +static int
22 +issharedobj(const char *template) {
23 + const char *ext;
24 + if (strlen(template) < 3)
25 + return 0;
26 + ext = template + strlen(template) - 3;
27 + return strcmp(ext, ".so") == 0;
30 +/*
31 +** Return 1 if this is a 64-bit executable, otherwise 0.
32 +*/
33 +static int is64bit() {
34 + return sizeof(void *) == 8;
37 static const char *searchpath (lua_State *L, const char *name,
38 const char *path,
39 const char *sep,
40 const char *dirsep) {
41 luaL_Buffer msg; /* to build error message */
42 + char *name64;
43 luaL_buffinit(L, &msg);
44 if (*sep != '\0') /* non-empty separator? */
45 name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */
46 + if (is64bit()) {
47 + name64 = calloc(strlen(name) + 4, 1);
48 + strcpy(name64, "64/");
49 + strcat(name64, name);
50 + } else
51 + name64 = strdup(name);
52 while ((path = pushnexttemplate(L, path)) != NULL) {
53 - const char *filename = luaL_gsub(L, lua_tostring(L, -1),
54 - LUA_PATH_MARK, name);
55 + char *filename;
56 + const char *item = lua_tostring(L, -1);
58 + if (is64bit() && issharedobj(item)) {
59 + name = name64;
60 + if (strstr(item, LUA_PATH_MARK))
61 + filename = (char *)luaL_gsub(L, item, LUA_PATH_MARK, name);
62 + else {
63 + /*
64 + * There's nothing to substitute, so we have to go digging through the
65 + * path to find where to put the 64-bit directory. Search for "/" in
66 + * the template element until we can't find any more, replace that with
67 + * "?", and replace that with "/64/".
68 + */
69 + char *p1, *p2;
70 + char *s = strdup(item);
71 + for (p1 = s; p1; p1 = strstr(p1 + 1, "/"))
72 + p2 = p1;
73 + if (p2 != s)
74 + *p2 = '?';
75 + else {
76 + /*
77 + * We didn't find any slashes; that either means there aren't any, or
78 + * item is in the root directory.
79 + */
80 + free(s);
81 + s = calloc(strlen(item) + 3, 1);
82 + if (item[0] == '/')
83 + strcpy(s, "/64");
84 + else
85 + strcpy(s, "64/");
86 + strcat(s, item);
87 + }
88 + filename = (char *)luaL_gsub(L, s, LUA_PATH_MARK, "/64/");
89 + free(s);
90 + }
91 + } else
92 + filename = (char *)luaL_gsub(L, item, LUA_PATH_MARK, name);
94 lua_remove(L, -2); /* remove path template */
95 - if (readable(filename)) /* does file exist and is readable? */
96 + if (readable(filename)) { /* does file exist and is readable? */
97 + free(name64);
98 return filename; /* return that file name */
99 + }
100 lua_pushfstring(L, "\n\tno file '%s'", filename);
101 lua_remove(L, -2); /* remove file name */
102 luaL_addvalue(&msg); /* concatenate error msg. entry */
104 luaL_pushresult(&msg); /* create error message */
105 + free(name64);
106 return NULL; /* not found */