From 21bc05c920e6289d6d6e1de5c3c8f0eb64e60fb2 Mon Sep 17 00:00:00 2001
From: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Tue, 23 Mar 2004 14:07:34 -0300
Subject: write barrier for C upvalues

---
 lapi.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/lapi.c b/lapi.c
index 48993abf..ba25b89e 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 2.3 2004/02/20 16:01:05 roberto Exp roberto $
+** $Id: lapi.c,v 2.4 2004/03/09 17:34:35 roberto Exp roberto $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -68,11 +68,10 @@ static TValue *luaA_index (lua_State *L, int idx) {
     case LUA_REGISTRYINDEX: return registry(L);
     case LUA_GLOBALSINDEX: return gt(L);
     default: {
-      TValue *func = (L->base - 1);
+      Closure *func = curr_func(L);
       idx = LUA_GLOBALSINDEX - idx;
-      lua_assert(iscfunction(func));
-      return (idx <= clvalue(func)->c.nupvalues)
-                ? &clvalue(func)->c.upvalue[idx-1]
+      return (idx <= func->c.nupvalues)
+                ? &func->c.upvalue[idx-1]
                 : cast(TValue *, &luaO_nilobject);
     }
   }
@@ -194,7 +193,9 @@ LUA_API void lua_replace (lua_State *L, int idx) {
   api_checknelems(L, 1);
   o = luaA_index(L, idx);
   api_checkvalidindex(L, o);
-  setobj(L, o, L->top - 1);  /* write barrier???? */
+  setobj(L, o, L->top - 1);
+  if (idx < LUA_GLOBALSINDEX)  /* function upvalue? */
+    luaC_barrier(L, curr_func(L), L->top - 1);
   L->top--;
   lua_unlock(L);
 }
-- 
cgit v1.2.3-55-g6feb