aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-11-05 15:26:00 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-11-05 15:26:00 -0200
commitb7d5f18d71f691df752e220f844ea613a8f6d722 (patch)
tree9f9ba3cd43799389c1564be16b7836e09fcf7317 /lapi.c
parent5598b2bc558ba0c755068f21e786d3a6d59eb1ca (diff)
downloadlua-b7d5f18d71f691df752e220f844ea613a8f6d722.tar.gz
lua-b7d5f18d71f691df752e220f844ea613a8f6d722.tar.bz2
lua-b7d5f18d71f691df752e220f844ea613a8f6d722.zip
api functions to manipulate upvalues do not need to check their
arguments (the caller must check them before calling)
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/lapi.c b/lapi.c
index 4d85508e..a79eb19f 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.94 2009/10/23 19:12:19 roberto Exp roberto $ 2** $Id: lapi.c,v 2.95 2009/11/05 16:48:31 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -1092,43 +1092,36 @@ static UpVal **getupvalref (lua_State *L, int fidx, int n, Closure **pf) {
1092 Closure *f; 1092 Closure *f;
1093 Proto *p; 1093 Proto *p;
1094 StkId fi = index2addr(L, fidx); 1094 StkId fi = index2addr(L, fidx);
1095 if (!ttisfunction(fi)) return NULL; /* not a function? */ 1095 api_check(L, ttisfunction(fi), "function expected");
1096 f = clvalue(fi); 1096 f = clvalue(fi);
1097 if (f->c.isC) return NULL; /* not a Lua function? */ 1097 api_check(L, !f->c.isC, "Lua function expected");
1098 p = f->l.p; 1098 p = f->l.p;
1099 if (!(1 <= n && n <= p->sizeupvalues)) return NULL; 1099 api_check(L, (1 <= n && n <= p->sizeupvalues), "invalid upvalue index");
1100 else { 1100 if (pf) *pf = f;
1101 if (pf) *pf = f; 1101 return &f->l.upvals[n - 1]; /* get its upvalue pointer */
1102 return &f->l.upvals[n - 1]; /* get its upvalue pointer */
1103 }
1104} 1102}
1105 1103
1106 1104
1107LUA_API void *(lua_upvaladdr) (lua_State *L, int fidx, int n) { 1105LUA_API void *(lua_upvaladdr) (lua_State *L, int fidx, int n) {
1108 Closure *f; 1106 Closure *f;
1109 StkId fi = index2addr(L, fidx); 1107 StkId fi = index2addr(L, fidx);
1110 if (!ttisfunction(fi)) return NULL; 1108 api_check(L, ttisfunction(fi), "function expected");
1111 f = clvalue(fi); 1109 f = clvalue(fi);
1112 if (f->c.isC) { 1110 if (f->c.isC) {
1113 if (!(1 <= n && n <= f->c.nupvalues)) return NULL; 1111 api_check(L, 1 <= n && n <= f->c.nupvalues, "invalid upvalue index");
1114 else return &f->c.upvalue[n - 1]; 1112 return &f->c.upvalue[n - 1];
1115 }
1116 else {
1117 UpVal **uv = getupvalref(L, fidx, n, NULL);
1118 return (uv == NULL) ? NULL : *uv;
1119 } 1113 }
1114 else return *getupvalref(L, fidx, n, NULL);
1120} 1115}
1121 1116
1122 1117
1123LUA_API int (lua_upvaljoin) (lua_State *L, int fidx1, int n1, 1118LUA_API void (lua_upvaljoin) (lua_State *L, int fidx1, int n1,
1124 int fidx2, int n2) { 1119 int fidx2, int n2) {
1125 Closure *f1; 1120 Closure *f1;
1126 UpVal **up1 = getupvalref(L, fidx1, n1, &f1); 1121 UpVal **up1 = getupvalref(L, fidx1, n1, &f1);
1127 UpVal **up2 = getupvalref(L, fidx2, n2, NULL); 1122 UpVal **up2 = getupvalref(L, fidx2, n2, NULL);
1128 if (up1 == NULL || up2 == NULL) return 0;
1129 *up1 = *up2; 1123 *up1 = *up2;
1130 luaC_objbarrier(L, f1, *up2); 1124 luaC_objbarrier(L, f1, *up2);
1131 return 1;
1132} 1125}
1133 1126
1134 1127