aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-12-04 13:38:25 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-12-04 13:38:25 -0200
commit76de732745d5781fe3ee1af4fd43f01a6c4b8ce4 (patch)
treea0f557ac472507dbcfea7ca50d39ad5e1194af01
parent90d7892007e399765cf8d14f65f7e3bc4a96e087 (diff)
downloadlua-76de732745d5781fe3ee1af4fd43f01a6c4b8ce4.tar.gz
lua-76de732745d5781fe3ee1af4fd43f01a6c4b8ce4.tar.bz2
lua-76de732745d5781fe3ee1af4fd43f01a6c4b8ce4.zip
avoid non-raw accesses to globals when variable may not exist
-rw-r--r--lbaselib.c8
-rw-r--r--lua.c11
2 files changed, 12 insertions, 7 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 6025addc..2c233569 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.111 2002/11/26 08:45:36 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.112 2002/11/26 12:53:29 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -213,7 +213,8 @@ static int luaB_next (lua_State *L) {
213 213
214static int luaB_pairs (lua_State *L) { 214static int luaB_pairs (lua_State *L) {
215 luaL_checktype(L, 1, LUA_TTABLE); 215 luaL_checktype(L, 1, LUA_TTABLE);
216 lua_getglobal(L, "next"); /* return generator, */ 216 lua_pushliteral(L, "next");
217 lua_rawget(L, LUA_GLOBALSINDEX); /* return generator, */
217 lua_pushvalue(L, 1); /* state, */ 218 lua_pushvalue(L, 1); /* state, */
218 lua_pushnil(L); /* and initial value */ 219 lua_pushnil(L); /* and initial value */
219 return 3; 220 return 3;
@@ -224,7 +225,8 @@ static int luaB_ipairs (lua_State *L) {
224 lua_Number i = lua_tonumber(L, 2); 225 lua_Number i = lua_tonumber(L, 2);
225 luaL_checktype(L, 1, LUA_TTABLE); 226 luaL_checktype(L, 1, LUA_TTABLE);
226 if (i == 0 && lua_isnone(L, 2)) { /* `for' start? */ 227 if (i == 0 && lua_isnone(L, 2)) { /* `for' start? */
227 lua_getglobal(L, "ipairs"); /* return generator, */ 228 lua_pushliteral(L, "ipairs");
229 lua_rawget(L, LUA_GLOBALSINDEX); /* return generator, */
228 lua_pushvalue(L, 1); /* state, */ 230 lua_pushvalue(L, 1); /* state, */
229 lua_pushnumber(L, 0); /* and initial value */ 231 lua_pushnumber(L, 0); /* and initial value */
230 return 3; 232 return 3;
diff --git a/lua.c b/lua.c
index cc03d08f..3dc0069d 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.109 2002/11/19 13:49:43 roberto Exp roberto $ 2** $Id: lua.c,v 1.110 2002/11/25 17:47:13 roberto Exp roberto $
3** Lua stand-alone interpreter 3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -121,7 +121,8 @@ static int report (int status) {
121static int lcall (int narg, int clear) { 121static int lcall (int narg, int clear) {
122 int status; 122 int status;
123 int base = lua_gettop(L) - narg; /* function index */ 123 int base = lua_gettop(L) - narg; /* function index */
124 lua_getglobal(L, "_TRACEBACK"); /* get traceback function */ 124 lua_pushliteral(L, "_TRACEBACK");
125 lua_rawget(L, LUA_GLOBALSINDEX); /* get traceback function */
125 lua_insert(L, base); /* put it under chunk and args */ 126 lua_insert(L, base); /* put it under chunk and args */
126 signal(SIGINT, laction); 127 signal(SIGINT, laction);
127 status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); 128 status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
@@ -175,7 +176,8 @@ static int dostring (const char *s, const char *name) {
175 176
176 177
177static int load_file (const char *name) { 178static int load_file (const char *name) {
178 lua_getglobal(L, "require"); 179 lua_pushliteral(L, "require");
180 lua_rawget(L, LUA_GLOBALSINDEX);
179 if (!lua_isfunction(L, -1)) { /* no `require' defined? */ 181 if (!lua_isfunction(L, -1)) { /* no `require' defined? */
180 lua_pop(L, 1); 182 lua_pop(L, 1);
181 return file_input(name); 183 return file_input(name);
@@ -228,7 +230,8 @@ static int readline (lua_State *l, const char *prompt) {
228 230
229static const char *get_prompt (int firstline) { 231static const char *get_prompt (int firstline) {
230 const char *p = NULL; 232 const char *p = NULL;
231 lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2"); 233 lua_pushstring(L, firstline ? "_PROMPT" : "_PROMPT2");
234 lua_rawget(L, LUA_GLOBALSINDEX);
232 p = lua_tostring(L, -1); 235 p = lua_tostring(L, -1);
233 if (p == NULL) p = (firstline ? PROMPT : PROMPT2); 236 if (p == NULL) p = (firstline ? PROMPT : PROMPT2);
234 lua_pop(L, 1); /* remove global */ 237 lua_pop(L, 1); /* remove global */