diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-03-11 15:56:27 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-03-11 15:56:27 -0300 |
| commit | 80fe8504f5d7be0a3ddf939981bf4b18266861b6 (patch) | |
| tree | c3cceb1009cb3dce2344facf30798c10631faf38 | |
| parent | e9763842134ac807262e3b86d5f40d25a8d69f1b (diff) | |
| download | lua-80fe8504f5d7be0a3ddf939981bf4b18266861b6.tar.gz lua-80fe8504f5d7be0a3ddf939981bf4b18266861b6.tar.bz2 lua-80fe8504f5d7be0a3ddf939981bf4b18266861b6.zip | |
make all dumps/loads go trhough Load/DumpVector (so it is easier
to adapt the code to correct endianess, if needed)
| -rw-r--r-- | ldump.c | 14 | ||||
| -rw-r--r-- | lundump.c | 14 |
2 files changed, 20 insertions, 8 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldump.c,v 2.25 2014/03/10 17:56:32 roberto Exp roberto $ | 2 | ** $Id: ldump.c,v 2.26 2014/03/11 18:05:46 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 | */ |
| @@ -25,9 +25,14 @@ typedef struct { | |||
| 25 | } DumpState; | 25 | } DumpState; |
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | #define DumpVar(x,D) DumpBlock(&x,sizeof(x),D) | 28 | /* |
| 29 | ** All high-level dumps go through DumpVector; you can change it to | ||
| 30 | ** change the endianess of the result | ||
| 31 | */ | ||
| 29 | #define DumpVector(v,n,D) DumpBlock(v,(n)*sizeof((v)[0]),D) | 32 | #define DumpVector(v,n,D) DumpBlock(v,(n)*sizeof((v)[0]),D) |
| 30 | 33 | ||
| 34 | #define DumpLiteral(s,D) DumpBlock(s, sizeof(s) - sizeof(char), D) | ||
| 35 | |||
| 31 | 36 | ||
| 32 | static void DumpBlock (const void *b, size_t size, DumpState *D) { | 37 | static void DumpBlock (const void *b, size_t size, DumpState *D) { |
| 33 | if (D->status == 0) { | 38 | if (D->status == 0) { |
| @@ -38,6 +43,9 @@ static void DumpBlock (const void *b, size_t size, DumpState *D) { | |||
| 38 | } | 43 | } |
| 39 | 44 | ||
| 40 | 45 | ||
| 46 | #define DumpVar(x,D) DumpVector(&x,1,D) | ||
| 47 | |||
| 48 | |||
| 41 | static void DumpByte (int y, DumpState *D) { | 49 | static void DumpByte (int y, DumpState *D) { |
| 42 | lu_byte x = (lu_byte)y; | 50 | lu_byte x = (lu_byte)y; |
| 43 | DumpVar(x, D); | 51 | DumpVar(x, D); |
| @@ -160,8 +168,6 @@ static void DumpFunction (const Proto *f, DumpState *D) { | |||
| 160 | } | 168 | } |
| 161 | 169 | ||
| 162 | 170 | ||
| 163 | #define DumpLiteral(s,D) DumpBlock(s, sizeof(s) - sizeof(char), D) | ||
| 164 | |||
| 165 | static void DumpHeader (DumpState *D) { | 171 | static void DumpHeader (DumpState *D) { |
| 166 | DumpLiteral(LUA_SIGNATURE, D); | 172 | DumpLiteral(LUA_SIGNATURE, D); |
| 167 | DumpByte(LUAC_VERSION, D); | 173 | DumpByte(LUAC_VERSION, D); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lundump.c,v 2.32 2014/03/10 19:50:19 roberto Exp roberto $ | 2 | ** $Id: lundump.c,v 2.33 2014/03/11 18:05:46 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 | */ |
| @@ -21,9 +21,6 @@ | |||
| 21 | #include "lzio.h" | 21 | #include "lzio.h" |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | #define LoadVar(S,x) LoadBlock(S,&x,sizeof(x)) | ||
| 25 | #define LoadVector(S,b,n) LoadBlock(S,b,(n)*sizeof((b)[0])) | ||
| 26 | |||
| 27 | #if !defined(luai_verifycode) | 24 | #if !defined(luai_verifycode) |
| 28 | #define luai_verifycode(L,b,f) /* empty */ | 25 | #define luai_verifycode(L,b,f) /* empty */ |
| 29 | #endif | 26 | #endif |
| @@ -43,12 +40,21 @@ static l_noret error(LoadState *S, const char *why) { | |||
| 43 | } | 40 | } |
| 44 | 41 | ||
| 45 | 42 | ||
| 43 | /* | ||
| 44 | ** All high-level loads go through LoadVector; you can change it to | ||
| 45 | ** adapt to the endianess of the input | ||
| 46 | */ | ||
| 47 | #define LoadVector(S,b,n) LoadBlock(S,b,(n)*sizeof((b)[0])) | ||
| 48 | |||
| 46 | static void LoadBlock (LoadState *S, void *b, size_t size) { | 49 | static void LoadBlock (LoadState *S, void *b, size_t size) { |
| 47 | if (luaZ_read(S->Z, b, size) != 0) | 50 | if (luaZ_read(S->Z, b, size) != 0) |
| 48 | error(S, "truncated"); | 51 | error(S, "truncated"); |
| 49 | } | 52 | } |
| 50 | 53 | ||
| 51 | 54 | ||
| 55 | #define LoadVar(S,x) LoadVector(S,&x,1) | ||
| 56 | |||
| 57 | |||
| 52 | static lu_byte LoadByte (LoadState *S) { | 58 | static lu_byte LoadByte (LoadState *S) { |
| 53 | lu_byte x; | 59 | lu_byte x; |
| 54 | LoadVar(S, x); | 60 | LoadVar(S, x); |
