summaryrefslogtreecommitdiff
path: root/lundump.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-02-28 13:13:01 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-02-28 13:13:01 -0300
commit99a1c06ea34c823e7692deac3a23fec4831d8f79 (patch)
tree23e8781389ab725ce07529377fe61a6eb88c4004 /lundump.c
parent93e28031de81efacb7f84b142f57d5c2cdf4744e (diff)
downloadlua-github-99a1c06ea34c823e7692deac3a23fec4831d8f79.tar.gz
more regularity with vectors + sizeof computed by the macros themselves
Diffstat (limited to 'lundump.c')
-rw-r--r--lundump.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/lundump.c b/lundump.c
index 1fd1eb18..ef7444e0 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
/*
-** $Id: lundump.c,v 2.27 2014/02/27 18:56:15 roberto Exp roberto $
+** $Id: lundump.c,v 2.28 2014/02/28 12:25:12 roberto Exp roberto $
** load precompiled Lua chunks
** See Copyright Notice in lua.h
*/
@@ -33,9 +33,8 @@ static l_noret error(LoadState* S, const char* why)
luaD_throw(S->L,LUA_ERRSYNTAX);
}
-#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
-#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
-#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
+#define LoadVar(S,x) LoadBlock(S,&x,sizeof(x))
+#define LoadVector(S,b,n) LoadBlock(S,b,(n)*sizeof((b)[0]))
#if !defined(luai_verifycode)
#define luai_verifycode(L,b,f) /* empty */
@@ -84,7 +83,7 @@ static TString* LoadString(LoadState* S)
else
{
char* s=luaZ_openspace(S->L,S->b,size);
- LoadBlock(S,s,size*sizeof(char));
+ LoadVector(S,s,size);
return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
}
}
@@ -94,7 +93,7 @@ static void LoadCode(LoadState* S, Proto* f)
int n=LoadInt(S);
f->code=luaM_newvector(S->L,n,Instruction);
f->sizecode=n;
- LoadVector(S,f->code,n,sizeof(Instruction));
+ LoadVector(S,f->code,n);
}
static void LoadFunction(LoadState* S, Proto* f);
@@ -162,7 +161,7 @@ static void LoadDebug(LoadState* S, Proto* f)
n=LoadInt(S);
f->lineinfo=luaM_newvector(S->L,n,int);
f->sizelineinfo=n;
- LoadVector(S,f->lineinfo,n,sizeof(int));
+ LoadVector(S,f->lineinfo,n);
n=LoadInt(S);
f->locvars=luaM_newvector(S->L,n,LocVar);
f->sizelocvars=n;
@@ -193,7 +192,7 @@ static void LoadFunction(LoadState* S, Proto* f)
static void checkstring(LoadState *S, const char *s, const char *msg)
{
char buff[sizeof(LUA_SIGNATURE)+sizeof(LUAC_DATA)]; /* larger than each */
- LoadMem(S,buff,strlen(s)+1,sizeof(char));
+ LoadVector(S,buff,strlen(s)+1);
if (strcmp(s,buff)!=0) error(S,msg);
}