lua-users home
lua-l archive

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




On 17/03/16 08:07 PM, Nagaev Boris wrote:
$ cat bug.lua
local function yieldFirst(it)
     return coroutine.wrap(function()
         coroutine.yield(it())
     end)
end

local text = "1 2 3"
local it = text:gmatch("(%d+)")
local head = yieldFirst(it)
local one = head()
print(one)
assert(one == '1')

$ ./lua-5.3.1/src/lua bug.lua
1
$ ./lua-5.3.2/src/lua bug.lua
function: 0x243f820
./lua-5.3.2/src/lua: bug.lua:12: assertion failed!
stack traceback:
         [C]: in function 'assert'
         bug.lua:12: in main chunk
         [C]: in ?

It's even worse than it looks...

--bug.lua--
local function yieldFirst(it)
    return coroutine.wrap(function()
        local v = it()
        coroutine.yield(v)
        print(v) -- ???
    end)
end

local text = "1 2 3"
local it = text:gmatch("(%d+)")
local head = yieldFirst(it)
local one = head()
print(one)
head() -- ???
assert(one == '1')
--end--

$ lua bug.lua
function: 0x11c9030
function: 0x11c9030
lua: bug.lua:15: assertion failed!
stack traceback:
    [C]: in function 'assert'
    bug.lua:15: in main chunk
    [C]: in ?

Either something really bad is happening (because it's affecting locals, not just the yielded values), or string iterators break across coroutines.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.