Added lock/unlock to API function 'lua_rawlen'

The call to 'luaH_getn' can change the "field" 'lenhint' of a table.
This commit is contained in:
Roberto I
2025-08-20 15:00:53 -03:00
parent 88aa4049ad
commit 907d172c11

8
lapi.c
View File

@@ -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;
}
}