Comments (9)
Lua 5.1 only has 53 bits to storeintegers, so this is a luaposix issue that affects any wrapped API that accepts or returns a long int that doesn't fit in 53 bits.
The solution is to add support for a userdata that holds a long, or a pid_t etc and adjust all affected functions to use that. I expect this would be a non-backwards compatible change, but only for < Lua 5.3 where a true 64 bit integer type was added to the language.
Would you like to work on a patch?
from luaposix.
Makes sense, thanks for the reply. I would be happy to look into providing a patch but I must say that I am fairly new to lua. I do have a background in C/C++ so that will probably help.
IOW, I will have to research your comments above as I 50% understand them :-).
from luaposix.
So essentially:
- Conditional compile (
ifdef
) to enable support when compiling for lua < 5.3. - Register a new userdata with lua runtime: https://www.lua.org/pil/28.1.html
- Provide helper like
checkint()
, maybechecklonglong()
(or modifychecklong()
) or similar that utilizes that data type. - Provide helper like
pushresult()
, maybepushresultlong()
orpushresultlonglong()
. - Modify any luaposix functions such as
seek()
to usechecklonglong()
/pushresultlonglong()
.
from luaposix.
That looks about right. Thanks!
I'm not sure whether this all works already with Lua >=5.3 by virtue of 64bit support, so it would be good to add test cases so that github CI will tell us if things work correctly on each Lua version in the test matrix when >53bit integers come back from or are passed into luaposix APIs.
Feel free to post your progress in a branch of your fork if you get stuck, and I'll try to help out.
from luaposix.
For context, here is how I fixed my issue.
btimby/nginx-lua-upload-module@0d0c86b
In my case I was trying to determine the size of a file I was writing to. Seeking to the end should (and does) return the file size for smaller files. The stat.st_size
member however seems to work for larger files.
from luaposix.
Actually, thinking about it a bit more, maybe it would be better for backwards compatibility to always return at least 53bits from eg lseek, just as we do now, but for numbers that are too big to fit on versions of Lua without 64bit support to also return an optional second value which is the 64bit userdata I described above.
That way existing working code will keep working as before (bugs and all) but new code can access the additional bits that are otherwise lost.
There might be more work in accepting either a 53bit number, or a 64bit userdata as parameters where that makes sense.
from luaposix.
Another backwards compat option would be to add bigseek()
on lua < 5.3.
from luaposix.
I think that would be more difficult to use in client code that wants to work on multiple Lua versions than this:
r, big = seek(blah)
if r and big then r = big end
...and we could even add the wrapper boilerplate to init.lua!
from luaposix.
Note that supporting values up to 2^52 is sufficient for essentially all practical purposes - only people doing extremely weird things with very sparse files or very large raw devices would need to handle more than 4096 TB in one file.
And to answer your question above: no, it does not work on 5.3 as is, because the code is using int
everywhere relevant and not lua_Integer
.
The code for stat.st_size
is using macros that use the lua_Integer
type and not int
, which is why it works (for values representable in a double) when lseek does not.
from luaposix.
Related Issues (20)
- Incorrect fork error-handling HOT 2
- luke: fatal: required symbol 'crypt' not found in any of libc, libcrypt HOT 5
- Using unix sockets in a non-blocking manner / timeouts HOT 2
- Small error in doc for poll(): return is not 0/1 but the number of ready fd's
- pwd.getpwuid fails with 0.0 as input HOT 3
- posix.fcntl is a function, not a table. HOT 15
- luxposix 36.0 won't compile properly on CentOS7 - time.h issues HOT 14
- posix.sys.socket - recv() crashes with socket and timeout in v36.1 (v36.0) HOT 6
- Lazy loading of posix.sys.stat fails in both 35.1 and 36.1 HOT 6
- luaposix won't compile in termux HOT 26
- Missing rockspec file in v36.1 HOT 7
- Get an error when trying to cross-compile HOT 1
- String overflow for unistd.read(). HOT 6
- Epoch inconsistency?
- Error on import: posix/glob.so: wrong ELF class: ELFCLASS64 HOT 7
- invalid elf header HOT 1
- luaposix does not cross compile properly HOT 5
- studio code does not seems to like the require HOT 2
- luaposix installs but I cant use it in cygwin HOT 1
- [MISSING] tcgetwinsize HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from luaposix.