From 1a038f4427bdcacb5c2a224dda33165d3eb23acd Mon Sep 17 00:00:00 2001 From: dptr1988 Date: Sat, 22 Jan 2011 16:17:06 -0800 Subject: Fixed bug where reference to Linda object was dropped for a short time ( crashing if GC was run during that time ). The reference could have also been stored in the module table ( or globals ) but those can be overwritten by the user. With the Lua registry, it should be inaccessible by the user and since it's referenced by a unique key, it should also normally be in accessible to C libraries, making it a relativily safe place to store the reference. --- src/lanes.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lanes.c b/src/lanes.c index ba9e59a..aef023e 100644 --- a/src/lanes.c +++ b/src/lanes.c @@ -1938,7 +1938,12 @@ static void init_once_LOCKED( lua_State *L, volatile DEEP_PRELUDE ** timer_deep_ *timer_deep_ref= * (DEEP_PRELUDE**) lua_touserdata( L, -1 ); ASSERT_L( (*timer_deep_ref) && (*timer_deep_ref)->refcount==1 && (*timer_deep_ref)->deep ); - lua_pop(L,1); // we don't need the proxy + // The host Lua state must always have a reference to this Linda object in order for our 'timer_deep_ref' to be valid. + // So store a reference that we will never actually use. + lua_pushlightuserdata(L, (void *)init_once_LOCKED); + lua_insert(L, -2); // Swap key with the Linda object + lua_rawset(L, LUA_REGISTRYINDEX); + } STACK_END(L,0) } -- cgit v1.2.3-55-g6feb