Tests fail on 32bit systems
Closed this issue · 18 comments
Running tests on amd64
and arm64
seems to run fine, but fail on arm
and x86
. Do you have an idea, why?
lua: tests/test-bit32.lua:6: assertion failed!
stack traceback:
[C]: in function 'assert'
tests/test-bit32.lua:6: in main chunk
[C]: ?
This is the following test: assert(bit32.bnot(0) == 2^32-1)
.
My first guess would be that maybe you have floats instead of doubles as lua_Number
?! What Lua version are we talking about (and what is the size of lua_Number
)? But it also could actually be a bug in the original code. Conversions between unsigned integers and doubles are tricky, and maybe no one tested the code on ARM, yet.
What Lua version are we talking about (and what is the size of lua_Number)?
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
How do I check lua_Number
?
You can run print(2^30 == 2^30+1)
. If it prints true
, you have floats, otherwise you have doubles.
Allright, I've now tested on lua console:
> local bit32
> bit32 = require("bit32")
> print(bit32.bnot(0))
-1
Why does it give -1
as value?
> print(2^30 == 2^30+1)
false
Funfact: on arm64
everything is okay.
Running with lua5.2 (which as build in bit32?) does work fine on arm.
So it's related to this module and lua5.1 somehow.
There seems to be some sort of overflow? Limited to int32
?
> print(bit32.bnot(2147483649))
-2147483648
> print(bit32.bnot(-2147483649))
2147483647
I have to withdraw about x86
. It fails with the same error!
So basically bit32 seems to fail on 32bit systems (arm
, x86
), while working on 64bit systems (amd64
, arm64
)
Could be this related to newer versions? I noticed, that the compat52
works with lua5.1 correctly, while compact53
seems not?
How did you compile compat53? My hunch is that you've somehow gotten a luaconf.h from a different installation
And how did you compile lua 5.1?
Have a look into https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-lua/lua-bit32/lua-bit32-5.3.5.ebuild
.
I am running Gentoo here, but I am not the maintainer of that package. See src_compile
.
Can you see something?
And how did you compile lua 5.1?
I can rule out, that this is related to lua5.1. If I take the precompiled bit32.so from Ubuntu (5.3.0, compat52) and replace my compiled bit32.so, everything works correctly!
I just recompiled (with the exact steps of the ebuild) lua-compat-5.2-bitlib-5.3.0
. All tests pass! This is also the version, which Ubuntu uses.
So it seems for me, something is broken with lua-compat-5.3-bitlib-0.9
and 32bit systems..
My steps to compile
cd lua-compat-5.3-0.9
gcc -I/usr/include -c lbitlib.c -o lbitlib.o -DLUA_COMPAT_BITLIB -Ic-api
gcc -shared -o bit32.so lbitlib.o
The issue probably has to do with this macro: #define pushunsigned(L,n)>lua_pushinteger(L, (lua_Integer)(n))
and lua_Integer
being 32 bit in Lua 5.1 on 32 bit architectures. I just have to find a way to test/confirm and then fix this ...
Can I test something for you?
There seems to be a very similar problem: ThePhD/sol2#470
@ConiKost Yes, you can test the latest commit I just pushed.
If you are using LuaRocks, you can just execute luarocks --dev install bit32
. Otherwise you probably already know what to do.
I can confirm, that your patch fixed it! All tests on arm
, arm64
, amd64
and x86
passed.
Will you make a new release?
I did a release. I'm planning to add tests for 32bit architectures when I have more time.
Thanks!
I've merged the bit32 tests on arm32 and am64 into master, so I'll close this issue now. If there is still something to be done, please reopen.
@keplerproject/team-lua-compat I've also ported the previous Travis CI tests to GitHub Actions and disabled Travis CI for this repository because Travis has reduced its capacity for running open source jobs, and there currently is a backlog of over 4000. Test runs take hours to complete on Travis at the moment.