summaryrefslogtreecommitdiff
path: root/deps/lua/src/lapi.c
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2022-04-27 16:32:17 +0300
committerGitHub <noreply@github.com>2022-04-27 16:32:17 +0300
commitd375595d5e3ae2e5c29e6c00a2dc3d60578fd9fc (patch)
treec4d753d3ee0109e3513a879af8c5487e002d10a3 /deps/lua/src/lapi.c
parentfb4e0d400ff82117104bde5296c477ad95f8dd41 (diff)
parentc1f3020631ea8640f2b6aa666a245dd76635a807 (diff)
downloadredis-7.0.0.tar.gz
Merge pull request #10652 from oranagra/redis-7.0.07.0.0
Redis 7.0.0
Diffstat (limited to 'deps/lua/src/lapi.c')
-rw-r--r--deps/lua/src/lapi.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/deps/lua/src/lapi.c b/deps/lua/src/lapi.c
index 5d5145d2e..e8ef41ea2 100644
--- a/deps/lua/src/lapi.c
+++ b/deps/lua/src/lapi.c
@@ -674,6 +674,8 @@ LUA_API void lua_rawset (lua_State *L, int idx) {
api_checknelems(L, 2);
t = index2adr(L, idx);
api_check(L, ttistable(t));
+ if (hvalue(t)->readonly)
+ luaG_runerror(L, "Attempt to modify a readonly table");
setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
luaC_barriert(L, hvalue(t), L->top-1);
L->top -= 2;
@@ -687,6 +689,8 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
api_checknelems(L, 1);
o = index2adr(L, idx);
api_check(L, ttistable(o));
+ if (hvalue(o)->readonly)
+ luaG_runerror(L, "Attempt to modify a readonly table");
setobj2t(L, luaH_setnum(L, hvalue(o), n), L->top-1);
luaC_barriert(L, hvalue(o), L->top-1);
L->top--;
@@ -709,6 +713,8 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
}
switch (ttype(obj)) {
case LUA_TTABLE: {
+ if (hvalue(obj)->readonly)
+ luaG_runerror(L, "Attempt to modify a readonly table");
hvalue(obj)->metatable = mt;
if (mt)
luaC_objbarriert(L, hvalue(obj), mt);
@@ -1085,3 +1091,19 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
return name;
}
+LUA_API void lua_enablereadonlytable (lua_State *L, int objindex, int enabled) {
+ const TValue* o = index2adr(L, objindex);
+ api_check(L, ttistable(o));
+ Table* t = hvalue(o);
+ api_check(L, t != hvalue(registry(L)));
+ t->readonly = enabled;
+}
+
+LUA_API int lua_isreadonlytable (lua_State *L, int objindex) {
+ const TValue* o = index2adr(L, objindex);
+ api_check(L, ttistable(o));
+ Table* t = hvalue(o);
+ api_check(L, t != hvalue(registry(L)));
+ return t->readonly;
+}
+