ffmpeg-6: fix COMPONENT_REVISION
[oi-userland.git] / components / runtime / lua / patches / 5.solaris-64-bit.patch
blob73ade6f50ea59542af0bd0dcde6eaab9d1aa06d0
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.2/gv.so
6 becomes:
7 /usr/lib/lua/5.2/64/gv.so
9 The lua maintainers are not interested in this patch.
11 --- src/loadlib.c.orig 2014-09-19 06:57:40.032464104 -0700
12 +++ src/loadlib.c 2014-09-19 16:39:01.502592411 -0700
13 @@ -346,29 +346,94 @@
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);
93 lua_remove(L, -2); /* remove path template */
94 - if (readable(filename)) /* does file exist and is readable? */
95 + if (readable(filename)) { /* does file exist and is readable? */
96 + free(name64);
97 return filename; /* return that file name */
98 + }
99 lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
100 lua_remove(L, -2); /* remove file name */
101 luaL_addvalue(&msg); /* concatenate error msg. entry */
103 luaL_pushresult(&msg); /* create error message */
104 + free(name64);
105 return NULL; /* not found */
109 static int ll_searchpath (lua_State *L) {
110 const char *f = searchpath(L, luaL_checkstring(L, 1),
111 luaL_checkstring(L, 2),