Browse Source

Added lock/unlock to API function 'lua_rawlen'

The call to 'luaH_getn' can change the "field" 'lenhint' of a table.
Roberto I 2 weeks ago
parent
commit
907d172c11
1 changed files with 7 additions and 1 deletions
  1. 7 1
      lapi.c

+ 7 - 1
lapi.c

@@ -440,7 +440,13 @@ LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) {
     case LUA_VSHRSTR: return cast(lua_Unsigned, tsvalue(o)->shrlen);
     case LUA_VLNGSTR: return cast(lua_Unsigned, tsvalue(o)->u.lnglen);
     case LUA_VUSERDATA: return cast(lua_Unsigned, uvalue(o)->len);
-    case LUA_VTABLE: return luaH_getn(L, hvalue(o));
+    case LUA_VTABLE: {
+      lua_Unsigned res;
+      lua_lock(L);
+      res = luaH_getn(L, hvalue(o));
+      lua_unlock(L);
+      return res;
+    }
     default: return 0;
   }
 }