lua-users home
lua-l archive

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


(As usual, C-level assertions need lua_assert #defined.)

-- begin test case --
A = coroutine.wrap( function( ) pcall( A, _ ) end)
A( )
-- end test case --

(needs at least 1 arg for pcall, no crash without args)
-->

ldo.c:661: lua_resume: Assertion
    `(((L->status == 0) ? nargs + 1 : nargs) < (L->top - L->ci->func))
     && "not enough elements in the stack"' failed.

-----

( for the curious, some context :)

Motivated by yesterday's surprises, I built a small grammar targeting
just coroutines... (included here so you know what's (not) tested)

goal = stats/{in_func=false}
stats = Many( stat ) .. "return _" -- 'Many' is usually < 10 reps
stat = var .. "=" .. exp
     | "_ = coroutine.resume(" .. var .. ", _ )"
     | "_ = coroutine.yield( _ )"
     | "__, _ = pcall( " .. var .. ", _ )"
     | "_ = "..var.."( _ )"
     | "error( _ )"%"in_func" -- only use when in a nested function/coro
     | "hard_assert( coroutine.isyieldable( ) )"  -- exit(134) if false
func = "function(" .. var .. ")" .. stats/{in_func=true} .. "end"
     | "coroutine.wrap(" .. func .. ")"
exp = func
    | "coroutine.create(" .. func .. ")"
    | "coroutine.running( )"
var = Set"[A-G]"

...made coroutines __call-able by implicit resume, made nil __call-able
as identity, assigned the main thread to 'A' and let it run like...

  local co = coroutine.create( load( g.goal:random( ) ) )
  B = co
  repeat until not coroutine.resume( co, "foo" )

for a crash+hang rate of ~25%!  99.75% of that hits the assertion from
the previous mail, 0.15% run into the assertion at the top of this mail
and the remaining 0.1% hang by self-loop (function A() A() end A()) as
far as I checked.

I'll leave it running overnight but I *hope* that there's no more
coroutine-related stuff.

(And with that off my stack I'll go take a closer look at the
codebinexpval thing again...)

-- Marco