diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-02-28 13:13:01 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-02-28 13:13:01 -0300 |
commit | 99a1c06ea34c823e7692deac3a23fec4831d8f79 (patch) | |
tree | 23e8781389ab725ce07529377fe61a6eb88c4004 | |
parent | 93e28031de81efacb7f84b142f57d5c2cdf4744e (diff) | |
download | lua-99a1c06ea34c823e7692deac3a23fec4831d8f79.tar.gz lua-99a1c06ea34c823e7692deac3a23fec4831d8f79.tar.bz2 lua-99a1c06ea34c823e7692deac3a23fec4831d8f79.zip |
more regularity with vectors + sizeof computed by the macros themselves
-rw-r--r-- | ldump.c | 22 | ||||
-rw-r--r-- | lundump.c | 15 |
2 files changed, 18 insertions, 19 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldump.c,v 2.21 2014/02/27 18:56:15 roberto Exp roberto $ | 2 | ** $Id: ldump.c,v 2.22 2014/02/28 12:25:12 roberto Exp roberto $ |
3 | ** save precompiled Lua chunks | 3 | ** save precompiled Lua chunks |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -23,8 +23,9 @@ typedef struct { | |||
23 | int status; | 23 | int status; |
24 | } DumpState; | 24 | } DumpState; |
25 | 25 | ||
26 | #define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) | 26 | |
27 | #define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) | 27 | #define DumpVar(x,D) DumpBlock(&x,sizeof(x),D) |
28 | #define DumpVector(v,n,D) DumpBlock(v,(n)*sizeof((v)[0]),D) | ||
28 | 29 | ||
29 | static void DumpBlock(const void* b, size_t size, DumpState* D) | 30 | static void DumpBlock(const void* b, size_t size, DumpState* D) |
30 | { | 31 | { |
@@ -57,12 +58,6 @@ static void DumpInteger(lua_Integer x, DumpState* D) | |||
57 | DumpVar(x,D); | 58 | DumpVar(x,D); |
58 | } | 59 | } |
59 | 60 | ||
60 | static void DumpVector(const void* b, int n, size_t size, DumpState* D) | ||
61 | { | ||
62 | DumpInt(n,D); | ||
63 | DumpMem(b,n,size,D); | ||
64 | } | ||
65 | |||
66 | static void DumpString(const TString* s, DumpState* D) | 61 | static void DumpString(const TString* s, DumpState* D) |
67 | { | 62 | { |
68 | if (s==NULL) | 63 | if (s==NULL) |
@@ -78,7 +73,11 @@ static void DumpString(const TString* s, DumpState* D) | |||
78 | } | 73 | } |
79 | } | 74 | } |
80 | 75 | ||
81 | #define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) | 76 | static void DumpCode(const Proto* f, DumpState* D) |
77 | { | ||
78 | DumpInt(f->sizecode,D); | ||
79 | DumpVector(f->code,f->sizecode,D); | ||
80 | } | ||
82 | 81 | ||
83 | static void DumpFunction(const Proto* f, DumpState* D); | 82 | static void DumpFunction(const Proto* f, DumpState* D); |
84 | 83 | ||
@@ -130,7 +129,8 @@ static void DumpDebug(const Proto* f, DumpState* D) | |||
130 | int i,n; | 129 | int i,n; |
131 | DumpString((D->strip) ? NULL : f->source,D); | 130 | DumpString((D->strip) ? NULL : f->source,D); |
132 | n= (D->strip) ? 0 : f->sizelineinfo; | 131 | n= (D->strip) ? 0 : f->sizelineinfo; |
133 | DumpVector(f->lineinfo,n,sizeof(int),D); | 132 | DumpInt(n,D); |
133 | DumpVector(f->lineinfo,n,D); | ||
134 | n= (D->strip) ? 0 : f->sizelocvars; | 134 | n= (D->strip) ? 0 : f->sizelocvars; |
135 | DumpInt(n,D); | 135 | DumpInt(n,D); |
136 | for (i=0; i<n; i++) | 136 | for (i=0; i<n; i++) |
@@ -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 | ||
100 | static void LoadFunction(LoadState* S, Proto* f); | 99 | static 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) | |||
193 | static void checkstring(LoadState *S, const char *s, const char *msg) | 192 | static 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 | ||