aboutsummaryrefslogtreecommitdiff
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-99a1c06ea34c823e7692deac3a23fec4831d8f79.tar.gz
lua-99a1c06ea34c823e7692deac3a23fec4831d8f79.tar.bz2
lua-99a1c06ea34c823e7692deac3a23fec4831d8f79.zip
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 @@
1/* 1/*
2** $Id: lundump.c,v 2.27 2014/02/27 18:56:15 roberto Exp roberto $ 2** $Id: lundump.c,v 2.28 2014/02/28 12:25:12 roberto Exp roberto $
3** load precompiled Lua chunks 3** load precompiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -33,9 +33,8 @@ static l_noret error(LoadState* S, const char* why)
33 luaD_throw(S->L,LUA_ERRSYNTAX); 33 luaD_throw(S->L,LUA_ERRSYNTAX);
34} 34}
35 35
36#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size)) 36#define LoadVar(S,x) LoadBlock(S,&x,sizeof(x))
37#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x)) 37#define LoadVector(S,b,n) LoadBlock(S,b,(n)*sizeof((b)[0]))
38#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
39 38
40#if !defined(luai_verifycode) 39#if !defined(luai_verifycode)
41#define luai_verifycode(L,b,f) /* empty */ 40#define luai_verifycode(L,b,f) /* empty */
@@ -84,7 +83,7 @@ static TString* LoadString(LoadState* S)
84 else 83 else
85 { 84 {
86 char* s=luaZ_openspace(S->L,S->b,size); 85 char* s=luaZ_openspace(S->L,S->b,size);
87 LoadBlock(S,s,size*sizeof(char)); 86 LoadVector(S,s,size);
88 return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */ 87 return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
89 } 88 }
90} 89}
@@ -94,7 +93,7 @@ static void LoadCode(LoadState* S, Proto* f)
94 int n=LoadInt(S); 93 int n=LoadInt(S);
95 f->code=luaM_newvector(S->L,n,Instruction); 94 f->code=luaM_newvector(S->L,n,Instruction);
96 f->sizecode=n; 95 f->sizecode=n;
97 LoadVector(S,f->code,n,sizeof(Instruction)); 96 LoadVector(S,f->code,n);
98} 97}
99 98
100static void LoadFunction(LoadState* S, Proto* f); 99static void LoadFunction(LoadState* S, Proto* f);
@@ -162,7 +161,7 @@ static void LoadDebug(LoadState* S, Proto* f)
162 n=LoadInt(S); 161 n=LoadInt(S);
163 f->lineinfo=luaM_newvector(S->L,n,int); 162 f->lineinfo=luaM_newvector(S->L,n,int);
164 f->sizelineinfo=n; 163 f->sizelineinfo=n;
165 LoadVector(S,f->lineinfo,n,sizeof(int)); 164 LoadVector(S,f->lineinfo,n);
166 n=LoadInt(S); 165 n=LoadInt(S);
167 f->locvars=luaM_newvector(S->L,n,LocVar); 166 f->locvars=luaM_newvector(S->L,n,LocVar);
168 f->sizelocvars=n; 167 f->sizelocvars=n;
@@ -193,7 +192,7 @@ static void LoadFunction(LoadState* S, Proto* f)
193static void checkstring(LoadState *S, const char *s, const char *msg) 192static void checkstring(LoadState *S, const char *s, const char *msg)
194{ 193{
195 char buff[sizeof(LUA_SIGNATURE)+sizeof(LUAC_DATA)]; /* larger than each */ 194 char buff[sizeof(LUA_SIGNATURE)+sizeof(LUAC_DATA)]; /* larger than each */
196 LoadMem(S,buff,strlen(s)+1,sizeof(char)); 195 LoadVector(S,buff,strlen(s)+1);
197 if (strcmp(s,buff)!=0) error(S,msg); 196 if (strcmp(s,buff)!=0) error(S,msg);
198} 197}
199 198