Improvements and fixes for luajit msgpack #11
Conversation
Thank you! I will look at it later this week. What do you mean by "floating point precision was truncated randomly"? Do you have an example that reproduces the problem? I would like to add a test for things like this. |
I mean it very hard to reproduce the problem with a test case. The had the following scenario: an array of different numbers with only a few the highest and lowest bits as 1 (like 11100000000101) is given; after pack/unpack this array sometimes has several numbers that are equal. So the code in tests/test.lua:
sometimes fails with the following error:
We use the following luajit 64-bit build: |
I don't understand why you say that's a float. That's an integer that is close to the maximum number Lua can represent in the default (double) number type, but below it. That helps me understand why your patch touches the (u)int64 encoding and not the float encoding. Thank you for the test case. I will try to check why this happens when I have free time, and make one that always fails if possible (if not it may actually be a LuaJIT bug...). |
I mean float because lua numbers are float precision numbers. Sorry for misleading. |
Can you confirm 9119b8c fixes the issue with numbers? If so I prefer this way to fix (I will merge the other two commits). |
Thank you for merging the first two patches! I tested your patch 9119b8c in our environment and seems like it didn't solve the issue - the problem is still reproduced with the test above. |
OK, I really have to find a smaller test that reproduces the problem reliably then... |
As often with LuaJIT, changing any single innocuous line in this file will hide the problem, hence the useless function definition and local declarations... Run it like this: while true; do luajit tests/pr-11.lua || exit 1 done
As LuaJIT issues often are, this is insane. I have written a smaller test file that reproduces the issue, but I have not managed to produce something small enough to send Mike yet. Of course, if I use Even more crazy: if I change the command line to call In hex, it decodes 0xffff000000014 instead of 0xffff000000028, so it drops a 0 at the end... |
https://github.com/Lupus/luajit-bug-repro Can you give it a try? I've reduced it to the following number of lines:
|
Wow, thank you, this is really good. This may be small enough for Mike. If you replace the
If you agree I will try sending a link to this repository to Mike via the LuaJIT list. |
Of course I agree :) I did not place any copyright notices in the repository, but I hope you will not sue me for that. Also I did not test it against git HEAD for 2.1 branch. That's what we have in prod currently:
|
According to Mike Pall, the bug is fixed in LuaJIT git. The test case doesn't fail anymore. Reference of the fix:
I will close this when you confirm that it works on your environment as well. |
The patchset includes several fixes and improvements that let us use this module in our environment. The first patch fixes segmentation faults error if we pass an uncompleted stream buffer for unpacking. The second patch allows to work with raw C pointers. The third patch fixes our scenario where floating point precision was truncated randomly.