summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConrad Kostecki <conikost@gentoo.org>2020-10-10 17:26:26 +0200
committerConrad Kostecki <conikost@gentoo.org>2020-10-10 17:26:26 +0200
commit4ad1abce782d98f32c7ba77d1c59f92f6417b2ff (patch)
treeddd6a898792d4b55c335c1b610ec3b71763667db /dev-lua/lua-bit32
parentgames-roguelike/stone-soup: Remove old versions (diff)
downloadgentoo-4ad1abce782d98f32c7ba77d1c59f92f6417b2ff.tar.gz
gentoo-4ad1abce782d98f32c7ba77d1c59f92f6417b2ff.tar.bz2
gentoo-4ad1abce782d98f32c7ba77d1c59f92f6417b2ff.zip
dev-lua/lua-bit32: fix 32bit conversion
Running bit32 on 32bit systems was broken, so returned value was '-1'. Closes: https://bugs.gentoo.org/746836 Package-Manager: Portage-3.0.8, Repoman-3.0.1 Signed-off-by: Conrad Kostecki <conikost@gentoo.org>
Diffstat (limited to 'dev-lua/lua-bit32')
-rw-r--r--dev-lua/lua-bit32/files/lua-bit32-5.3.5-fix-32bit-conversion.patch51
-rw-r--r--dev-lua/lua-bit32/lua-bit32-5.3.5-r1.ebuild51
2 files changed, 102 insertions, 0 deletions
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
new file mode 100644
index 000000000000..36c0ef16cec5
--- /dev/null
+++ b/dev-lua/lua-bit32/files/lua-bit32-5.3.5-fix-32bit-conversion.patch
@@ -0,0 +1,51 @@
+From e245d3a18957e43ef902a59a72c8902e2e4435b9 Mon Sep 17 00:00:00 2001
+From: Philipp Janda <siffiejoe@gmx.net>
+Date: Sat, 10 Oct 2020 16:43:46 +0200
+Subject: [PATCH] Fix bit32 conversion issues for Lua 5.1 on 32 bit
+
+The default unsigned conversion procedure from upstream using
+`lua_Integer` as an intermediate value fails if `lua_Integer` has only
+32 bits (as is the case on 32 bit Lua 5.1). This fix uses a `lua_Number`
+(hopefully double) as intermediate value in those cases.
+---
+ lbitlib.c | 14 ++++++++++++--
+ tests/test-bit32.lua | 1 +
+ 2 files changed, 13 insertions(+), 2 deletions(-)
+
+diff --git a/lbitlib.c b/lbitlib.c
+index 4786c0d..db2652a 100644
+--- a/lbitlib.c
++++ b/lbitlib.c
+@@ -19,8 +19,18 @@
+ #if defined(LUA_COMPAT_BITLIB) /* { */
+
+
+-#define pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
+-#define checkunsigned(L,i) ((lua_Unsigned)luaL_checkinteger(L,i))
++#define pushunsigned(L,n) (sizeof(lua_Integer) > 4 ? lua_pushinteger(L, (lua_Integer)(n)) : lua_pushnumber(L, (lua_Number)(n)))
++static lua_Unsigned checkunsigned(lua_State *L, int i) {
++ if (sizeof(lua_Integer) > 4)
++ return (lua_Unsigned)luaL_checkinteger(L, i);
++ else {
++ lua_Number d = luaL_checknumber(L, i);
++ if (d < 0)
++ d = (d + 1) + (~(lua_Unsigned)0);
++ luaL_argcheck(L, d >= 0 && d <= (~(lua_Unsigned)0), i, "value out of range");
++ return (lua_Unsigned)d;
++ }
++}
+
+
+ /* number of bits to consider in a number */
+diff --git a/tests/test-bit32.lua b/tests/test-bit32.lua
+index cc91e52..a408b7d 100755
+--- a/tests/test-bit32.lua
++++ b/tests/test-bit32.lua
+@@ -4,6 +4,7 @@ local bit32 = require("bit32")
+
+
+ assert(bit32.bnot(0) == 2^32-1)
++assert(bit32.bnot(-1) == 0)
+ assert(bit32.band(1, 3, 5) == 1)
+ assert(bit32.bor(1, 3, 5) == 7)
+
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
new file mode 100644
index 000000000000..32d81d68f9f1
--- /dev/null
+++ b/dev-lua/lua-bit32/lua-bit32-5.3.5-r1.ebuild
@@ -0,0 +1,51 @@
+# Copyright 2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+inherit toolchain-funcs
+
+# Weird upstream version descisions...
+# Result tarball may be reused for future lua-compat53 package
+LUA_COMPAT_PN="lua-compat-5.3"
+LUA_COMPAT_PV="0.9"
+
+DESCRIPTION="Backported Lua bit manipulation library"
+HOMEPAGE="https://github.com/keplerproject/lua-compat-5.3"
+SRC_URI="https://github.com/keplerproject/${LUA_COMPAT_PN}/archive/v${LUA_COMPAT_PV}.tar.gz -> lua-compat53-${LUA_COMPAT_PV}.tar.gz"
+
+S="${WORKDIR}/${LUA_COMPAT_PN}-${LUA_COMPAT_PV}"
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="~amd64 ~x86 ~amd64-linux ~x86-linux"
+IUSE="test"
+
+RESTRICT="!test? ( test )"
+
+DEPEND="dev-lang/lua:0="
+RDEPEND="${DEPEND}"
+BDEPEND="virtual/pkgconfig"
+
+PATCHES=( "${FILESDIR}/${P}-fix-32bit-conversion.patch" )
+
+src_compile() {
+ # TODO maybe sometime there will be luarocks eclass...
+ compile="$(tc-getCC) ${CFLAGS} ${LDFLAGS} -fPIC -I/usr/include -c lbitlib.c -o lbitlib.o -DLUA_COMPAT_BITLIB -Ic-api"
+ einfo "${compile}"
+ eval "${compile}" || die
+
+ link="$(tc-getCC) -shared ${LDFLAGS} -o bit32.so lbitlib.o"
+ einfo "${link}"
+ eval "${link}" || die
+}
+
+src_test() {
+ LUA_CPATH=./?.so lua tests/test-bit32.lua || die
+}
+
+src_install() {
+ exeinto $($(tc-getPKG_CONFIG) --variable INSTALL_CMOD lua)
+ doexe bit32.so
+ dodoc README.md
+}