From df97c3a7dc32c840434cbc80fbf75214bcab4524 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Fri, 23 Nov 2018 12:12:13 +0100 Subject: Raise an error instead of crashing when attempting to transfer a non-deep full userdata --- CHANGES | 3 +++ src/tools.c | 9 ++++++++- tests/lanes_as_upvalue.lua | 9 ++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index fba1392..c730ae5 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ CHANGES: +CHANGE 140: BGe 22-Nov-18 + * Raise an error instead of crashing when attempting to transfer a non-deep full userdata + CHANGE 139: BGe 21-Nov-18 * more DEBUGSPEW diff --git a/src/tools.c b/src/tools.c index d358e96..b00cef5 100644 --- a/src/tools.c +++ b/src/tools.c @@ -1617,6 +1617,12 @@ static void inter_copy_keyvaluepair( Universe* U, lua_State* L2, uint_t L2_cache valPath = (char*) alloca( strlen( upName_) + 16 + 5); sprintf( valPath, "%s[U:%p]", upName_, key); } + else if( lua_type( L, key_i) == LUA_TBOOLEAN) + { + int key = lua_toboolean( L, key_i); + valPath = (char*) alloca( strlen( upName_) + 7); + sprintf( valPath, "%s[%s]", upName_, key ? "true" : "false"); + } } /* * Contents of metatables are copied with cache checking; @@ -1629,7 +1635,7 @@ static void inter_copy_keyvaluepair( Universe* U, lua_State* L2, uint_t L2_cache } else { - luaL_error( L, "Unable to copy over type '%s' (in %s)", luaL_typename( L, val_i), (vt == VT_NORMAL) ? "table" : "metatable"); + luaL_error( L, "Unable to copy %s entry '%s' because of value is of type '%s'", (vt == VT_NORMAL) ? "table" : "metatable", valPath, luaL_typename( L, val_i)); } } } @@ -1740,6 +1746,7 @@ static bool_t inter_copy_one_( Universe* U, lua_State* L2, uint_t L2_cache_i, lu if( lua_isnil( L, -1)) { lua_pop( L, 2); // ... + ret = FALSE; } else { diff --git a/tests/lanes_as_upvalue.lua b/tests/lanes_as_upvalue.lua index 7cc5e14..c1944b0 100644 --- a/tests/lanes_as_upvalue.lua +++ b/tests/lanes_as_upvalue.lua @@ -1,8 +1,11 @@ -local lanes = require "lanes".configure() -- with timers enabled +local lanes = require "lanes".configure{ verbose_errors = true} -- with timers enabled local function foo() local lanes = lanes -- lanes as upvalue end -local h = lanes.gen( "*", foo)() -h:join() +local g = lanes.gen( "*", foo) + +-- this should raise an error as lanes.timer_lane is a Lane (a non-deep full userdata) +local res, err = pcall( g) +print( "Generating lane yielded: ", tostring( res), tostring( err)) -- cgit v1.2.3-55-g6feb