1 |
commit: 4ad1abce782d98f32c7ba77d1c59f92f6417b2ff |
2 |
Author: Conrad Kostecki <conikost <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Oct 10 15:26:26 2020 +0000 |
4 |
Commit: Conrad Kostecki <conikost <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Oct 10 15:26:26 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4ad1abce |
7 |
|
8 |
dev-lua/lua-bit32: fix 32bit conversion |
9 |
|
10 |
Running bit32 on 32bit systems was broken, |
11 |
so returned value was '-1'. |
12 |
|
13 |
Closes: https://bugs.gentoo.org/746836 |
14 |
Package-Manager: Portage-3.0.8, Repoman-3.0.1 |
15 |
Signed-off-by: Conrad Kostecki <conikost <AT> gentoo.org> |
16 |
|
17 |
.../lua-bit32-5.3.5-fix-32bit-conversion.patch | 51 ++++++++++++++++++++++ |
18 |
dev-lua/lua-bit32/lua-bit32-5.3.5-r1.ebuild | 51 ++++++++++++++++++++++ |
19 |
2 files changed, 102 insertions(+) |
20 |
|
21 |
diff --git a/dev-lua/lua-bit32/files/lua-bit32-5.3.5-fix-32bit-conversion.patch b/dev-lua/lua-bit32/files/lua-bit32-5.3.5-fix-32bit-conversion.patch |
22 |
new file mode 100644 |
23 |
index 00000000000..36c0ef16cec |
24 |
--- /dev/null |
25 |
+++ b/dev-lua/lua-bit32/files/lua-bit32-5.3.5-fix-32bit-conversion.patch |
26 |
@@ -0,0 +1,51 @@ |
27 |
+From e245d3a18957e43ef902a59a72c8902e2e4435b9 Mon Sep 17 00:00:00 2001 |
28 |
+From: Philipp Janda <siffiejoe@×××.net> |
29 |
+Date: Sat, 10 Oct 2020 16:43:46 +0200 |
30 |
+Subject: [PATCH] Fix bit32 conversion issues for Lua 5.1 on 32 bit |
31 |
+ |
32 |
+The default unsigned conversion procedure from upstream using |
33 |
+`lua_Integer` as an intermediate value fails if `lua_Integer` has only |
34 |
+32 bits (as is the case on 32 bit Lua 5.1). This fix uses a `lua_Number` |
35 |
+(hopefully double) as intermediate value in those cases. |
36 |
+--- |
37 |
+ lbitlib.c | 14 ++++++++++++-- |
38 |
+ tests/test-bit32.lua | 1 + |
39 |
+ 2 files changed, 13 insertions(+), 2 deletions(-) |
40 |
+ |
41 |
+diff --git a/lbitlib.c b/lbitlib.c |
42 |
+index 4786c0d..db2652a 100644 |
43 |
+--- a/lbitlib.c |
44 |
++++ b/lbitlib.c |
45 |
+@@ -19,8 +19,18 @@ |
46 |
+ #if defined(LUA_COMPAT_BITLIB) /* { */ |
47 |
+ |
48 |
+ |
49 |
+-#define pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n)) |
50 |
+-#define checkunsigned(L,i) ((lua_Unsigned)luaL_checkinteger(L,i)) |
51 |
++#define pushunsigned(L,n) (sizeof(lua_Integer) > 4 ? lua_pushinteger(L, (lua_Integer)(n)) : lua_pushnumber(L, (lua_Number)(n))) |
52 |
++static lua_Unsigned checkunsigned(lua_State *L, int i) { |
53 |
++ if (sizeof(lua_Integer) > 4) |
54 |
++ return (lua_Unsigned)luaL_checkinteger(L, i); |
55 |
++ else { |
56 |
++ lua_Number d = luaL_checknumber(L, i); |
57 |
++ if (d < 0) |
58 |
++ d = (d + 1) + (~(lua_Unsigned)0); |
59 |
++ luaL_argcheck(L, d >= 0 && d <= (~(lua_Unsigned)0), i, "value out of range"); |
60 |
++ return (lua_Unsigned)d; |
61 |
++ } |
62 |
++} |
63 |
+ |
64 |
+ |
65 |
+ /* number of bits to consider in a number */ |
66 |
+diff --git a/tests/test-bit32.lua b/tests/test-bit32.lua |
67 |
+index cc91e52..a408b7d 100755 |
68 |
+--- a/tests/test-bit32.lua |
69 |
++++ b/tests/test-bit32.lua |
70 |
+@@ -4,6 +4,7 @@ local bit32 = require("bit32") |
71 |
+ |
72 |
+ |
73 |
+ assert(bit32.bnot(0) == 2^32-1) |
74 |
++assert(bit32.bnot(-1) == 0) |
75 |
+ assert(bit32.band(1, 3, 5) == 1) |
76 |
+ assert(bit32.bor(1, 3, 5) == 7) |
77 |
+ |
78 |
|
79 |
diff --git a/dev-lua/lua-bit32/lua-bit32-5.3.5-r1.ebuild b/dev-lua/lua-bit32/lua-bit32-5.3.5-r1.ebuild |
80 |
new file mode 100644 |
81 |
index 00000000000..32d81d68f9f |
82 |
--- /dev/null |
83 |
+++ b/dev-lua/lua-bit32/lua-bit32-5.3.5-r1.ebuild |
84 |
@@ -0,0 +1,51 @@ |
85 |
+# Copyright 2020 Gentoo Authors |
86 |
+# Distributed under the terms of the GNU General Public License v2 |
87 |
+ |
88 |
+EAPI=7 |
89 |
+ |
90 |
+inherit toolchain-funcs |
91 |
+ |
92 |
+# Weird upstream version descisions... |
93 |
+# Result tarball may be reused for future lua-compat53 package |
94 |
+LUA_COMPAT_PN="lua-compat-5.3" |
95 |
+LUA_COMPAT_PV="0.9" |
96 |
+ |
97 |
+DESCRIPTION="Backported Lua bit manipulation library" |
98 |
+HOMEPAGE="https://github.com/keplerproject/lua-compat-5.3" |
99 |
+SRC_URI="https://github.com/keplerproject/${LUA_COMPAT_PN}/archive/v${LUA_COMPAT_PV}.tar.gz -> lua-compat53-${LUA_COMPAT_PV}.tar.gz" |
100 |
+ |
101 |
+S="${WORKDIR}/${LUA_COMPAT_PN}-${LUA_COMPAT_PV}" |
102 |
+ |
103 |
+LICENSE="MIT" |
104 |
+SLOT="0" |
105 |
+KEYWORDS="~amd64 ~x86 ~amd64-linux ~x86-linux" |
106 |
+IUSE="test" |
107 |
+ |
108 |
+RESTRICT="!test? ( test )" |
109 |
+ |
110 |
+DEPEND="dev-lang/lua:0=" |
111 |
+RDEPEND="${DEPEND}" |
112 |
+BDEPEND="virtual/pkgconfig" |
113 |
+ |
114 |
+PATCHES=( "${FILESDIR}/${P}-fix-32bit-conversion.patch" ) |
115 |
+ |
116 |
+src_compile() { |
117 |
+ # TODO maybe sometime there will be luarocks eclass... |
118 |
+ compile="$(tc-getCC) ${CFLAGS} ${LDFLAGS} -fPIC -I/usr/include -c lbitlib.c -o lbitlib.o -DLUA_COMPAT_BITLIB -Ic-api" |
119 |
+ einfo "${compile}" |
120 |
+ eval "${compile}" || die |
121 |
+ |
122 |
+ link="$(tc-getCC) -shared ${LDFLAGS} -o bit32.so lbitlib.o" |
123 |
+ einfo "${link}" |
124 |
+ eval "${link}" || die |
125 |
+} |
126 |
+ |
127 |
+src_test() { |
128 |
+ LUA_CPATH=./?.so lua tests/test-bit32.lua || die |
129 |
+} |
130 |
+ |
131 |
+src_install() { |
132 |
+ exeinto $($(tc-getPKG_CONFIG) --variable INSTALL_CMOD lua) |
133 |
+ doexe bit32.so |
134 |
+ dodoc README.md |
135 |
+} |