title: Lua segfault on coroutine resume
body: <p>I have code</p>
  
  <pre><code>fun = function() 
      coroutine.resume(co); -- here it segfaults
      return true;
  end ;
  
  -- evtimer is my binding to libev
  -- timer = evtimer.new(1,1, fun); -- this works ok and prints "co N" every second
  
  
  co = coroutine.create(function ()
          timer = evtimer.new(1,1, fun); --this segfaults
  
  
           for i=1,100000 do
               print("co", i)
               coroutine.yield(111);
          end
  end)
  -- timer = evtimer.new(1,1, fun); -- this works too
  
  coroutine.resume(co);
  
  timer:start(); --start timer
  -- here main thread ends and libev event loop starts. Timer callback is called by event loop
  </code></pre>
  
  <p>and variant when timer is created inside coroutine segfaults on resume inside lua core. Backtrace:</p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  0x000000000066ec00 in ?? ()
  (gdb) backtrace
  #0  0x000000000066ec00 in ?? () 
  #1  0x0000000000413430 in resume (L=0x6841a0, ud=0x6d8ac0) at ./src/myprogram/lua/ldo.c:522
  #2  0x00000000004120e9 in luaD_rawrunprotected (L=0x6841a0, f=0x4132da &lt;resume&gt;, ud=0x6d8ac0)
      at ./src/myprogram/lua/ldo.c:131
  #3  0x00000000004134ef in lua_resume (L=0x6841a0, from=0x6841a0, nargs=0)
      at ./src/myprogram/lua/ldo.c:543
  #4  0x0000000000429b4e in auxresume (L=0x6841a0, co=0x6841a0, narg=0)
      at ./src/myprogram/lua/lcorolib.c:31
  #5  0x0000000000429c5a in luaB_coresume (L=0x6841a0) at ./src/myprogram/lua/lcorolib.c:53
  #6  0x0000000000412b19 in luaD_precall (L=0x6841a0, func=0x6d8aa0, nresults=2)
      at ./src/myprogram/lua/ldo.c:319
  #7  0x0000000000424b2b in luaV_execute (L=0x6841a0) at ./src/myprogram/lua/lvm.c:709
  #8  0x0000000000412f8a in luaD_call (L=0x6841a0, func=0x6d8a70, nResults=1, allowyield=0)
      at ./src/myprogram/lua/ldo.c:402
  #9  0x000000000040c77a in f_call (L=0x6841a0, ud=0x7fffffffe000) at ./src/myprogram/lua/lapi.c:923
  #10 0x00000000004120e9 in luaD_rawrunprotected (L=0x6841a0, f=0x40c73e &lt;f_call&gt;, ud=0x7fffffffe000)
      at ./src/myprogram/lua/ldo.c:131
  #11 0x0000000000413722 in luaD_pcall (L=0x6841a0, func=0x40c73e &lt;f_call&gt;, u=0x7fffffffe000,
      old_top=112, ef=0) at ./src/myprogram/lua/ldo.c:603
  #12 0x000000000040c84a in lua_pcallk (L=0x6841a0, nargs=0, nresults=1, errfunc=0, ctx=0, k=0x0)
      at ./src/myprogram/lua/lapi.c:949
  #13 0x0000000000433a54 in lua_script_pcall (ls=0x6841a0, nargs=0, nresults=1)
      at ./src/myprogram//lua_script.c:41
  #14 0x00000000004353b0 in lua_evtimer_callback (loop=0x66cc20 &lt;default_loop_struct&gt;, w=0x684938,
      revents=256) at ./src/myprogram//evtimer_lualib.c:21
  #15 0x0000000000406d41 in ev_invoke_pending (loop=0x66cc20 &lt;default_loop_struct&gt;)
      at ./src/myprogram/libev/ev.c:2994
  #16 0x000000000040763b in ev_run (loop=0x66cc20 &lt;default_loop_struct&gt;, flags=0)
      at ./src/myprogram/libev/ev.c:3394
  </code></pre>
  
  <p>it segfaults on line 522(lua 5.2)  n = (<em>ci->u.c.k)(L);  /</em> call continuation */</p>
  
  <p>Is there anyone familiar with lua core? Why this happens?</p>