From cd91518d79388d5d42820a2b48918a7bf1e6d1a2 Mon Sep 17 00:00:00 2001 From: osch Date: Mon, 27 Aug 2018 19:06:15 +0200 Subject: interrupted error message now contains llthreads module name as prefix and is also available in the public api --- src/llthread.c | 14 ++++++++++++-- test/test_interrupt.lua | 6 +++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/llthread.c b/src/llthread.c index c78d766..66efe7c 100644 --- a/src/llthread.c +++ b/src/llthread.c @@ -98,11 +98,17 @@ typedef pthread_t os_thread_t; #define LLTHREAD_OPEN_NAME LLTHREAD_OPEN_NAME_IMPL(LLTHREAD_MODULE_NAME) +#define LLTHREAD_STRINGIFY(x) #x +#define LLTHREAD_TOSTRING(x) LLTHREAD_STRINGIFY(x) +#define LLTHREAD_MODULE_NAME_STRING LLTHREAD_TOSTRING(LLTHREAD_MODULE_NAME) + + LLTHREADS_EXPORT_API int LLTHREAD_OPEN_NAME(lua_State *L); #define LLTHREAD_NAME "LLThread" static const char *LLTHREAD_TAG = LLTHREAD_NAME; static const char *LLTHREAD_LOGGER_HOLDER = LLTHREAD_NAME " logger holder"; +static const char* LLTHREAD_INTERRUPTED_ERROR = LLTHREAD_MODULE_NAME_STRING ": thread was interrupted"; typedef struct llthread_child_t { lua_State *L; @@ -697,11 +703,11 @@ static int l_llthread_new(lua_State *L) { static void llthread_interrupt1(lua_State *L, lua_Debug *ar) { (void)ar; /* unused arg. */ lua_sethook(L, NULL, 0, 0); /* reset hook */ - luaL_error(L, "interrupted!"); + luaL_error(L, LLTHREAD_INTERRUPTED_ERROR); } static void llthread_interrupt2(lua_State *L, lua_Debug *ar) { (void)ar; /* unused arg. */ - luaL_error(L, "interrupted!"); + luaL_error(L, LLTHREAD_INTERRUPTED_ERROR); } static int l_llthread_interrupt(lua_State *L) { @@ -796,5 +802,9 @@ LLTHREADS_EXPORT_API int LLTHREAD_OPEN_NAME(lua_State *L) { l_llthread_push_version(L); lua_rawset(L, -3); + lua_pushliteral(L, "interrupted_error"); + lua_pushstring(L, LLTHREAD_INTERRUPTED_ERROR); + lua_rawset(L, -3); + return 1; } diff --git a/test/test_interrupt.lua b/test/test_interrupt.lua index 6a7a255..22c168e 100644 --- a/test/test_interrupt.lua +++ b/test/test_interrupt.lua @@ -18,7 +18,7 @@ do local ok, err = thread:join() print("thread1:join(): ", ok, err) - assert(ok == false and err:match("interrupted!"), "thread1 result") + assert(ok == false and err:match(llthreads.interrupted_error), "thread1 result") print("--- Done interrupt1!") end @@ -27,7 +27,7 @@ do local thread = llthreads.new(include .. [[ local ok, err = pcall(function() for i = 1, 10 do sleep(1) end end) print("thread2:", ok, err) - assert(ok == false and err:match("interrupted!"), "interrupt2 result") + assert(ok == false and err:match(llthreads.interrupted_error), "interrupt2 result") ]]) thread:start() @@ -52,7 +52,7 @@ do local ok, err = thread:join() print("thread3:join(): ", ok, err) - assert(ok == false and err:match("interrupted!"), "thread3 result") + assert(ok == false and err:match(llthreads.interrupted_error), "thread3 result") print("--- Done interrupt3!") end -- cgit v1.2.3-55-g6feb