From ae19ebab381e6902cce2c7a3efd4a0949357c866 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 22 Jan 2014 16:16:46 +0100 Subject: 2 crash fixes and 1 experiment * bumped version to 3.8.3 * fixed a possible Lua stack overflow when sending complex function through lindas or as lane body * experimental: lanes.nameof() scans the registry if a regular search didn't yield anything interesting * fixed lanes.nameof() misbehaving when encountering a LUA_TTHREAD object --- CHANGES | 6 ++++++ docs/index.html | 10 +++++++--- src/lanes.c | 2 +- src/tools.c | 22 +++++++++++++--------- tests/nameof.lua | 1 + 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/CHANGES b/CHANGES index 8575e8d..e92c813 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,11 @@ CHANGES: +CHANGE 95: BGe 22-Jan-14 + * version 3.8.3 + * fixed a possible Lua stack overflow when sending complex function through lindas or as lane body + * experimental: lanes.nameof() scans the registry if a regular search didn't yield anything interesting + * fixed lanes.nameof() misbehaving when encountering a LUA_TTHREAD object + CHANGE 94: BGe 22-Jan-14 * version 3.8.2 * new lane launcher option gc_cb to set a callback that is invoked when a lane is garbage collected diff --git a/docs/index.html b/docs/index.html index c662a14..f639f18 100644 --- a/docs/index.html +++ b/docs/index.html @@ -70,7 +70,7 @@

- This document was revised on 22-Jan-14, and applies to version 3.8.2. + This document was revised on 22-Jan-14, and applies to version 3.8.3.

@@ -645,8 +645,8 @@

- If a lane body pulls a C function imported by a module required before Lanes itself (thus not through a hooked require), the lane generator creation will raise an error. - The function name it shows is a path where it was found by scanning _G. As a utility, the name guessing functionality is exposed as such: + If a lane body pulls a C function imported by a module required before Lanes itself (thus not through a hooked require), the lane generator creation will raise an error. + The function name it shows is a path where it was found by scanning _G. As a utility, the name guessing functionality is exposed as such: @@ -657,6 +657,10 @@

+

+ Starting with version 3.8.3, lanes.nameof() searches the registry as well. +

+

Free running lanes

diff --git a/src/lanes.c b/src/lanes.c index a806c16..270c01d 100644 --- a/src/lanes.c +++ b/src/lanes.c @@ -52,7 +52,7 @@ * ... */ -char const* VERSION = "3.8.2"; +char const* VERSION = "3.8.3"; /* =============================================================================== diff --git a/src/tools.c b/src/tools.c index 9f36858..e456db7 100644 --- a/src/tools.c +++ b/src/tools.c @@ -1443,14 +1443,7 @@ static int discover_object_name_recur( lua_State* L, int shortest_, int depth_) break; case LUA_TTHREAD: // o "r" {c} {fqn} ... {?} k T - // search in the object's uservalue if it is a table - lua_getuservalue( L, -1); // o "r" {c} {fqn} ... {?} k T {u} - if( lua_istable( L, -1)) - { - shortest_ = discover_object_name_recur( L, shortest_, depth_); - } - lua_pop( L, 1); // o "r" {c} {fqn} ... {?} k T - STACK_MID( L, 2); + // TODO: explore the thread's stack frame looking for our culprit? break; case LUA_TUSERDATA: // o "r" {c} {fqn} ... {?} k U @@ -1531,9 +1524,19 @@ int luaG_nameof( lua_State* L) lua_newtable( L); // o nil {c} // push a table whose contents are strings that, when concatenated, produce unique name lua_newtable( L); // o nil {c} {fqn} + lua_pushliteral( L, "_G"); // o nil {c} {fqn} "_G" + lua_rawseti( L, -2, 1); // o nil {c} {fqn} // this is where we start the search lua_pushglobaltable( L); // o nil {c} {fqn} _G - (void) discover_object_name_recur( L, 6666, 0); + (void) discover_object_name_recur( L, 6666, 1); + if( lua_isnil( L, 2)) // try again with registry, just in case... + { + lua_pop( L, 1); // o nil {c} {fqn} + lua_pushliteral( L, "_R"); // o nil {c} {fqn} "_R" + lua_rawseti( L, -2, 1); // o nil {c} {fqn} + lua_pushvalue( L, LUA_REGISTRYINDEX); // o nil {c} {fqn} _R + (void) discover_object_name_recur( L, 6666, 1); + } lua_pop( L, 3); // o "result" STACK_END( L, 1); lua_pushstring( L, luaL_typename( L, 1)); // o "result" "type" @@ -1606,6 +1609,7 @@ static void lookup_native_func( lua_State* L2, lua_State* L, uint_t i, enum eLoo STACK_END( L, 0); // push the equivalent function in the destination's stack, retrieved from the lookup table STACK_CHECK( L2); + STACK_GROW( L2, 2); if( mode_ == eLM_ToKeeper) { // push a sentinel closure that holds the lookup name as upvalue diff --git a/tests/nameof.lua b/tests/nameof.lua index ed20a32..221c893 100644 --- a/tests/nameof.lua +++ b/tests/nameof.lua @@ -1,4 +1,5 @@ lanes = require "lanes".configure() +print( lanes.nameof( {})) print( lanes.nameof( string.sub)) print( lanes.nameof( print)) -- cgit v1.2.3-55-g6feb