From 7263b3d0f93aabbe653ffc4ab8d39aa274b9d203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E9=A3=8E?= Date: Mon, 16 Sep 2013 13:01:37 +0800 Subject: [PATCH] trace throw error instead of assert in C --- lualib-src/lua-skynet.c | 3 +++ lualib-src/trace_service.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lualib-src/lua-skynet.c b/lualib-src/lua-skynet.c index fe909a44..1424c92d 100644 --- a/lualib-src/lua-skynet.c +++ b/lualib-src/lua-skynet.c @@ -399,6 +399,9 @@ static int _trace_new(lua_State *L) { struct trace_pool *p = lua_touserdata(L,1); struct trace_info *t = trace_new(p); + if (t==NULL) { + return luaL_error(L, "Last trace didn't close"); + } lua_pushlightuserdata(L,t); return 1; } diff --git a/lualib-src/trace_service.c b/lualib-src/trace_service.c index 453f2202..23deb40f 100644 --- a/lualib-src/trace_service.c +++ b/lualib-src/trace_service.c @@ -81,7 +81,9 @@ trace_release(struct trace_pool *p) { struct trace_info * trace_new(struct trace_pool *p) { - assert(p->current == NULL); + if (p->current) { + return NULL; + } struct trace_info *t = malloc(sizeof(*t)); p->current = t; t->session = 0;