Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make "offset" arg to lseek a signed integer #1338

Merged
merged 1 commit into from
Jul 2, 2018

Conversation

wingo
Copy link
Contributor

@wingo wingo commented May 2, 2018

This PR merges in a patch to upstream ljsyscall:

justincormack/ljsyscall#224

The original commit log follows:

Otherwise, passing a negative seek amount as a normal Lua number will
involve a cast from double to uint64. In C it's undefined behavior when
a double outside the [0,2^64) range is cast to uint64. In Lua we try to
additionally accomodate the range [-2^63, -1], but there is a bug on
x64-64 and might be a bug on other platforms:

LuaJIT/LuaJIT#415

However it's cheaper to simply target an int64_t when you want to allow
negative numbers, as is our case, because you don't have to do assembly
heroics for it to do what you want. The tonumber call in the return
of linux.lua:lseek indicates anyway that our range is not the full
64-bit range, so we might as well restrict instead to long rather than
ulong.

Otherwise, passing a negative seek amount as a normal Lua number will
involve a cast from double to uint64.  In C it's undefined behavior when
a double outside the [0,2^64) range is cast to uint64.  In Lua we try to
additionally accomodate the range [-2^63, -1], but there is a bug on
x64-64 and might be a bug on other platforms:

  LuaJIT/LuaJIT#415

However it's cheaper to simply target an int64_t when you want to allow
negative numbers, as is our case, because you don't have to do assembly
heroics for it to do what you want.  The `tonumber` call in the return
of `linux.lua:lseek` indicates anyway that our range is not the full
64-bit range, so we might as well restrict instead to long rather than
ulong.
@wingo
Copy link
Contributor Author

wingo commented Jun 1, 2018

Closing, will reopen as a merge from upstream.

@wingo wingo closed this Jun 1, 2018
@wingo
Copy link
Contributor Author

wingo commented Jun 1, 2018

Ah, we don't have ljsyscall's history in our repo -- better to reopen this bug, as it's the right thing.

@wingo wingo reopened this Jun 1, 2018
wingo added a commit that referenced this pull request Jun 1, 2018
@wingo wingo added the merged label Jun 1, 2018
@eugeneia eugeneia merged commit bf4307d into snabbco:master Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants