aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Harning Jr <harningt@gmail.com>2007-09-06 00:05:55 -0400
committerThomas Harning Jr <harningt@gmail.com>2007-09-06 00:05:55 -0400
commit64a4223203928443ee5a49dbb7579e1db53a4056 (patch)
tree8eb5f119e98e57e75186c4b1c4bc7cb23503337b
parent35c12fdb05ee081794f621688bb299a9a63ebf2c (diff)
downloadluaevent-prosody-64a4223203928443ee5a49dbb7579e1db53a4056.tar.gz
luaevent-prosody-64a4223203928443ee5a49dbb7579e1db53a4056.zip
Added timertest. Prevented GC-ed events from causing an abort.
-rw-r--r--src/event_callback.c8
-rw-r--r--test/timertest.lua19
2 files changed, 26 insertions, 1 deletions
diff --git a/src/event_callback.c b/src/event_callback.c
index bbcd51c..76a7789 100644
--- a/src/event_callback.c
+++ b/src/event_callback.c
@@ -23,7 +23,13 @@ void luaevent_callback(int fd, short event, void* p) {
lua_State* L;
int ret;
double newTimeout = -1;
- assert(cb && cb->base && cb->base->loop_L);
+ assert(cb);
+ if(!cb->base) {
+ /* Callback has been collected... die */
+ /* TODO: What should really be done here... */
+ return;
+ }
+ assert(cb->base->loop_L);
L = cb->base->loop_L;
lua_rawgeti(L, LUA_REGISTRYINDEX, cb->callbackRef);
lua_pushinteger(L, event);
diff --git a/test/timertest.lua b/test/timertest.lua
new file mode 100644
index 0000000..ec1257c
--- /dev/null
+++ b/test/timertest.lua
@@ -0,0 +1,19 @@
+require("luaevent.core")
+
+c = luaevent.core.new()
+local f = 100
+local function createEvent()
+ return c:addevent(nil, luaevent.core.EV_TIMEOUT, function(ev) io.write(".." .. f) f = f - 1 if f < 0 then return -1 end collectgarbage() end, 0.01)
+end
+ev = createEvent()
+print("TESTING Garbage-collect-safe version")
+c:loop()
+assert(f < 0, "DID NOT FINISH LOOPING")
+io.write("\n")
+print("TESTING Garbage-collect unsafe version")
+f = 100
+createEvent()
+c:loop()
+assert(f >= 0, "Did not perform expected collection")
+io.write("\n")
+print("Completed both tests")