lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2012/5/1 Dirk Laurie <dirk.laurie@gmail.com>:
>>
>> While looking into one nasty bug (was posted here
>> http://lua-list.2524044.n2.nabble.com/Strange-intermittent-LuaJIT-errors-likely-my-fault-td7438216.html)
>> I encountered curious error
>>
>> ./luajit: ../../etc/replay.lua:112: return values check failed: load 00000131
>>  -- return value #2 mismatch: actual `""', expected `""'
>>  -- return value #4 mismatch: actual `"luatexts"', expected `"luatexts"'
>> stack traceback:
>>     [C]: in function 'error'
>>     ./lua-nucleo/ensure.lua:329: in function 'ensure_returns'
>>     ../../etc/replay.lua:112: in main chunk
>>
>> This happens during running the test, that reveals the bug I mentioned
>> above, so any kind of things may happen.  But I wonder, how can it
>> ever be, that two similar strings are not equal.  The test uses
>> standard comparator for string.
>
> Easy.
>
>    a="snap"
>    b="sn\7ap"
>    assert(a==b,("parameter mismatch: expected `%s`, got `%s`"):format(a,b))
> stdin:1: parameter mismatch: expected `snap`, got `snap`
> stack traceback:
>        [C]: in function 'assert'
>        stdin:1: in main chunk
>        [C]: in ?
> But show us the file replay.lua.
>

It runs through data files, loads them in pairs (eg: 00000131.lua and
00000131.luatext ) and compares the output.  Here is the main patrt of
replay.lua

for i = 1, #filenames do
  local filename = filenames[i]
  n_str = assert(filename:match("^"..PREFIX.."/(%d+).luatexts$"))

  local n = assert(tonumber(n_str, 10))
  if n >= OFFSET then
    local tuple, tuple_size = assert(dofile(PREFIX.."/"..n_str..".lua"))
    local data = assert(read_file(filename))

    ensure_returns(
            "load " .. n_str,
            tuple_size + 1,
            { true, unpack(tuple, 1, tuple_size) },
            luatexts.load(data)
          )
  end
end

I think there's nothing obviously wrong with luatexts, because this
error occurs not every time. And I also believe ensure_returns() (part
of lua-nucleo library) works correctly.

As for your exapmle - it's informative, thank you, but I doubt that's
the reason. ensure_returns() escapes output data, so we would see the
difference in the log. When I run this code (with all needed imports):

  local f = function() return "sn\7ap" end
  ensure_returns("ensure_returns", 1, { "snap" }, f())

I get this output:

ensure_returns_test.lua:23: return values check failed: ensure_returns
 -- return value #1 mismatch: actual `"sn\7ap"', expected `"snap"'
stack traceback:
    ....

Can there be other possibilities?

Thanks,
Valeriy