diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2011-02-14 21:19:28 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2011-02-14 21:19:28 +0100 |
commit | baeb379c2e4eb436ecb0bcc4d88cb50930ef378e (patch) | |
tree | 3f6f0f919305afbe671eee31bcc7ac22bf531f57 /src/tools.c | |
parent | a661736f7984292a41d71847de68590f6b8ca08a (diff) | |
download | lanes-baeb379c2e4eb436ecb0bcc4d88cb50930ef378e.tar.gz lanes-baeb379c2e4eb436ecb0bcc4d88cb50930ef378e.tar.bz2 lanes-baeb379c2e4eb436ecb0bcc4d88cb50930ef378e.zip |
Fixed application hang-up because keeper state was not released in case of errors thrown by inter-state data copy for unsupported types
Diffstat (limited to 'src/tools.c')
-rw-r--r-- | src/tools.c | 78 |
1 files changed, 47 insertions, 31 deletions
diff --git a/src/tools.c b/src/tools.c index d09b11e..41163c4 100644 --- a/src/tools.c +++ b/src/tools.c | |||
@@ -1183,45 +1183,61 @@ ASSERT_L( lua_istable(L,-1) ); | |||
1183 | * | 1183 | * |
1184 | * Note: Parameters are in this order ('L' = from first) to be same as 'lua_xmove'. | 1184 | * Note: Parameters are in this order ('L' = from first) to be same as 'lua_xmove'. |
1185 | */ | 1185 | */ |
1186 | void luaG_inter_copy( lua_State* L, lua_State *L2, uint_t n ) | 1186 | int luaG_inter_copy( lua_State* L, lua_State *L2, uint_t n) |
1187 | { | 1187 | { |
1188 | uint_t top_L= lua_gettop(L); | 1188 | uint_t top_L = lua_gettop( L); |
1189 | uint_t top_L2= lua_gettop(L2); | 1189 | uint_t top_L2 = lua_gettop( L2); |
1190 | uint_t i; | 1190 | uint_t i; |
1191 | bool_t copyok = TRUE; | ||
1191 | 1192 | ||
1192 | if (n > top_L) | 1193 | if( n > top_L) |
1193 | luaL_error( L, "Not enough values: %d < %d", top_L, n ); | 1194 | { |
1194 | 1195 | // requesting to copy more than is available? | |
1195 | STACK_GROW( L2, n+1 ); | 1196 | return -1; |
1197 | } | ||
1196 | 1198 | ||
1197 | /* | 1199 | STACK_GROW( L2, n + 1); |
1198 | * Make a cache table for the duration of this copy. Collects tables and | ||
1199 | * function entries, avoiding the same entries to be passed on as multiple | ||
1200 | * copies. ESSENTIAL i.e. for handling upvalue tables in the right manner! | ||
1201 | */ | ||
1202 | lua_newtable(L2); | ||
1203 | 1200 | ||
1204 | for (i=top_L-n+1; i <= top_L; i++) { | 1201 | /* |
1205 | if (!inter_copy_one_( L2, top_L2+1, L, i, VT_NORMAL )) { | 1202 | * Make a cache table for the duration of this copy. Collects tables and |
1206 | 1203 | * function entries, avoiding the same entries to be passed on as multiple | |
1207 | luaL_error( L, "Cannot copy type: %s", luaG_typename(L,i) ); | 1204 | * copies. ESSENTIAL i.e. for handling upvalue tables in the right manner! |
1208 | } | 1205 | */ |
1209 | } | 1206 | lua_newtable( L2); |
1210 | 1207 | ||
1211 | /* | 1208 | for( i = top_L - n + 1; i <= top_L; ++ i) |
1212 | * Remove the cache table. Persistant caching would cause i.e. multiple | 1209 | { |
1213 | * messages passed in the same table to use the same table also in receiving | 1210 | copyok = inter_copy_one_( L2, top_L2 + 1, L, i, VT_NORMAL); |
1214 | * end. | 1211 | if( !copyok) |
1215 | */ | 1212 | { |
1216 | lua_remove( L2, top_L2+1 ); | 1213 | break; |
1214 | } | ||
1215 | } | ||
1217 | 1216 | ||
1218 | ASSERT_L( (uint_t)lua_gettop(L) == top_L ); | 1217 | /* |
1219 | ASSERT_L( (uint_t)lua_gettop(L2) == top_L2+n ); | 1218 | * Remove the cache table. Persistant caching would cause i.e. multiple |
1219 | * messages passed in the same table to use the same table also in receiving | ||
1220 | * end. | ||
1221 | */ | ||
1222 | ASSERT_L( (uint_t) lua_gettop( L) == top_L); | ||
1223 | if( copyok) | ||
1224 | { | ||
1225 | lua_remove( L2, top_L2 + 1); | ||
1226 | ASSERT_L( (uint_t) lua_gettop( L2) == top_L2 + n); | ||
1227 | return 0; | ||
1228 | } | ||
1229 | else | ||
1230 | { | ||
1231 | // error -> pop everything from the target state stack | ||
1232 | lua_settop( L2, top_L2); | ||
1233 | return -2; | ||
1234 | } | ||
1220 | } | 1235 | } |
1221 | 1236 | ||
1222 | 1237 | ||
1223 | void luaG_inter_move( lua_State* L, lua_State *L2, uint_t n ) | 1238 | int luaG_inter_move( lua_State* L, lua_State *L2, uint_t n ) |
1224 | { | 1239 | { |
1225 | luaG_inter_copy( L, L2, n ); | 1240 | int ret = luaG_inter_copy( L, L2, n); |
1226 | lua_pop( L,(int)n ); | 1241 | lua_pop( L, (int) n); |
1242 | return ret; | ||
1227 | } | 1243 | } |