diff options
author | dptr1988 <junk_mail@dptr1988.mooo.com> | 2011-01-22 16:17:06 -0800 |
---|---|---|
committer | dptr1988 <junk_mail@dptr1988.mooo.com> | 2011-01-23 15:20:55 -0800 |
commit | 1a038f4427bdcacb5c2a224dda33165d3eb23acd (patch) | |
tree | db48db0d94409a535d28a33a57aaeee1f2b213ba /src/lanes.c | |
parent | 8ce207a848429e8581e8a900b645927f86e78435 (diff) | |
download | lanes-1a038f4427bdcacb5c2a224dda33165d3eb23acd.tar.gz lanes-1a038f4427bdcacb5c2a224dda33165d3eb23acd.tar.bz2 lanes-1a038f4427bdcacb5c2a224dda33165d3eb23acd.zip |
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.
Diffstat (limited to 'src/lanes.c')
-rw-r--r-- | src/lanes.c | 7 |
1 files changed, 6 insertions, 1 deletions
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_ | |||
1938 | *timer_deep_ref= * (DEEP_PRELUDE**) lua_touserdata( L, -1 ); | 1938 | *timer_deep_ref= * (DEEP_PRELUDE**) lua_touserdata( L, -1 ); |
1939 | ASSERT_L( (*timer_deep_ref) && (*timer_deep_ref)->refcount==1 && (*timer_deep_ref)->deep ); | 1939 | ASSERT_L( (*timer_deep_ref) && (*timer_deep_ref)->refcount==1 && (*timer_deep_ref)->deep ); |
1940 | 1940 | ||
1941 | lua_pop(L,1); // we don't need the proxy | 1941 | // The host Lua state must always have a reference to this Linda object in order for our 'timer_deep_ref' to be valid. |
1942 | // So store a reference that we will never actually use. | ||
1943 | lua_pushlightuserdata(L, (void *)init_once_LOCKED); | ||
1944 | lua_insert(L, -2); // Swap key with the Linda object | ||
1945 | lua_rawset(L, LUA_REGISTRYINDEX); | ||
1946 | |||
1942 | } | 1947 | } |
1943 | STACK_END(L,0) | 1948 | STACK_END(L,0) |
1944 | } | 1949 | } |