aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-02-27 15:17:44 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-02-27 15:17:44 -0300
commite8a52281d9cba1c8dd49a06e7523d7e39794ecc1 (patch)
tree25c6b35371e795bda67efe9db71be3b2f6421f28
parent6eb53b752617fae9e1329bfe2cfecdcbb593c398 (diff)
downloadlua-e8a52281d9cba1c8dd49a06e7523d7e39794ecc1.tar.gz
lua-e8a52281d9cba1c8dd49a06e7523d7e39794ecc1.tar.bz2
lua-e8a52281d9cba1c8dd49a06e7523d7e39794ecc1.zip
Code style in 'ldump'/'lundump'.
- function names start with lower case; - state is always the first parameter.
-rw-r--r--ldump.c152
-rw-r--r--lundump.c146
2 files changed, 149 insertions, 149 deletions
diff --git a/ldump.c b/ldump.c
index 4d29b94e..fbadbcc9 100644
--- a/ldump.c
+++ b/ldump.c
@@ -29,15 +29,15 @@ typedef struct {
29 29
30 30
31/* 31/*
32** All high-level dumps go through DumpVector; you can change it to 32** All high-level dumps go through dumpVector; you can change it to
33** change the endianness of the result 33** change the endianness of the result
34*/ 34*/
35#define DumpVector(v,n,D) DumpBlock(v,(n)*sizeof((v)[0]),D) 35#define dumpVector(D,v,n) dumpBlock(D,v,(n)*sizeof((v)[0]))
36 36
37#define DumpLiteral(s,D) DumpBlock(s, sizeof(s) - sizeof(char), D) 37#define dumpLiteral(D, s) dumpBlock(D,s,sizeof(s) - sizeof(char))
38 38
39 39
40static void DumpBlock (const void *b, size_t size, DumpState *D) { 40static void dumpBlock (DumpState *D, const void *b, size_t size) {
41 if (D->status == 0 && size > 0) { 41 if (D->status == 0 && size > 0) {
42 lua_unlock(D->L); 42 lua_unlock(D->L);
43 D->status = (*D->writer)(D->L, b, size, D->data); 43 D->status = (*D->writer)(D->L, b, size, D->data);
@@ -46,19 +46,19 @@ static void DumpBlock (const void *b, size_t size, DumpState *D) {
46} 46}
47 47
48 48
49#define DumpVar(x,D) DumpVector(&x,1,D) 49#define dumpVar(D,x) dumpVector(D,&x,1)
50 50
51 51
52static void DumpByte (int y, DumpState *D) { 52static void dumpByte (DumpState *D, int y) {
53 lu_byte x = (lu_byte)y; 53 lu_byte x = (lu_byte)y;
54 DumpVar(x, D); 54 dumpVar(D, x);
55} 55}
56 56
57 57
58/* DumpInt Buff Size */ 58/* dumpInt Buff Size */
59#define DIBS ((sizeof(size_t) * 8 / 7) + 1) 59#define DIBS ((sizeof(size_t) * 8 / 7) + 1)
60 60
61static void DumpSize (size_t x, DumpState *D) { 61static void dumpSize (DumpState *D, size_t x) {
62 lu_byte buff[DIBS]; 62 lu_byte buff[DIBS];
63 int n = 0; 63 int n = 0;
64 do { 64 do {
@@ -66,63 +66,63 @@ static void DumpSize (size_t x, DumpState *D) {
66 x >>= 7; 66 x >>= 7;
67 } while (x != 0); 67 } while (x != 0);
68 buff[DIBS - 1] |= 0x80; /* mark last byte */ 68 buff[DIBS - 1] |= 0x80; /* mark last byte */
69 DumpVector(buff + DIBS - n, n, D); 69 dumpVector(D, buff + DIBS - n, n);
70} 70}
71 71
72 72
73static void DumpInt (int x, DumpState *D) { 73static void dumpInt (DumpState *D, int x) {
74 DumpSize(x, D); 74 dumpSize(D, x);
75} 75}
76 76
77 77
78static void DumpNumber (lua_Number x, DumpState *D) { 78static void dumpNumber (DumpState *D, lua_Number x) {
79 DumpVar(x, D); 79 dumpVar(D, x);
80} 80}
81 81
82 82
83static void DumpInteger (lua_Integer x, DumpState *D) { 83static void dumpInteger (DumpState *D, lua_Integer x) {
84 DumpVar(x, D); 84 dumpVar(D, x);
85} 85}
86 86
87 87
88static void DumpString (const TString *s, DumpState *D) { 88static void dumpString (DumpState *D, const TString *s) {
89 if (s == NULL) 89 if (s == NULL)
90 DumpSize(0, D); 90 dumpSize(D, 0);
91 else { 91 else {
92 size_t size = tsslen(s); 92 size_t size = tsslen(s);
93 const char *str = getstr(s); 93 const char *str = getstr(s);
94 DumpSize(size + 1, D); 94 dumpSize(D, size + 1);
95 DumpVector(str, size, D); 95 dumpVector(D, str, size);
96 } 96 }
97} 97}
98 98
99 99
100static void DumpCode (const Proto *f, DumpState *D) { 100static void dumpCode (DumpState *D, const Proto *f) {
101 DumpInt(f->sizecode, D); 101 dumpInt(D, f->sizecode);
102 DumpVector(f->code, f->sizecode, D); 102 dumpVector(D, f->code, f->sizecode);
103} 103}
104 104
105 105
106static void DumpFunction(const Proto *f, TString *psource, DumpState *D); 106static void dumpFunction(DumpState *D, const Proto *f, TString *psource);
107 107
108static void DumpConstants (const Proto *f, DumpState *D) { 108static void dumpConstants (DumpState *D, const Proto *f) {
109 int i; 109 int i;
110 int n = f->sizek; 110 int n = f->sizek;
111 DumpInt(n, D); 111 dumpInt(D, n);
112 for (i = 0; i < n; i++) { 112 for (i = 0; i < n; i++) {
113 const TValue *o = &f->k[i]; 113 const TValue *o = &f->k[i];
114 int tt = ttypetag(o); 114 int tt = ttypetag(o);
115 DumpByte(tt, D); 115 dumpByte(D, tt);
116 switch (tt) { 116 switch (tt) {
117 case LUA_VNUMFLT: 117 case LUA_VNUMFLT:
118 DumpNumber(fltvalue(o), D); 118 dumpNumber(D, fltvalue(o));
119 break; 119 break;
120 case LUA_VNUMINT: 120 case LUA_VNUMINT:
121 DumpInteger(ivalue(o), D); 121 dumpInteger(D, ivalue(o));
122 break; 122 break;
123 case LUA_VSHRSTR: 123 case LUA_VSHRSTR:
124 case LUA_VLNGSTR: 124 case LUA_VLNGSTR:
125 DumpString(tsvalue(o), D); 125 dumpString(D, tsvalue(o));
126 break; 126 break;
127 default: 127 default:
128 lua_assert(tt == LUA_VNIL || tt == LUA_VFALSE || tt == LUA_VTRUE); 128 lua_assert(tt == LUA_VNIL || tt == LUA_VFALSE || tt == LUA_VTRUE);
@@ -131,79 +131,79 @@ static void DumpConstants (const Proto *f, DumpState *D) {
131} 131}
132 132
133 133
134static void DumpProtos (const Proto *f, DumpState *D) { 134static void dumpProtos (DumpState *D, const Proto *f) {
135 int i; 135 int i;
136 int n = f->sizep; 136 int n = f->sizep;
137 DumpInt(n, D); 137 dumpInt(D, n);
138 for (i = 0; i < n; i++) 138 for (i = 0; i < n; i++)
139 DumpFunction(f->p[i], f->source, D); 139 dumpFunction(D, f->p[i], f->source);
140} 140}
141 141
142 142
143static void DumpUpvalues (const Proto *f, DumpState *D) { 143static void dumpUpvalues (DumpState *D, const Proto *f) {
144 int i, n = f->sizeupvalues; 144 int i, n = f->sizeupvalues;
145 DumpInt(n, D); 145 dumpInt(D, n);
146 for (i = 0; i < n; i++) { 146 for (i = 0; i < n; i++) {
147 DumpByte(f->upvalues[i].instack, D); 147 dumpByte(D, f->upvalues[i].instack);
148 DumpByte(f->upvalues[i].idx, D); 148 dumpByte(D, f->upvalues[i].idx);
149 DumpByte(f->upvalues[i].kind, D); 149 dumpByte(D, f->upvalues[i].kind);
150 } 150 }
151} 151}
152 152
153 153
154static void DumpDebug (const Proto *f, DumpState *D) { 154static void dumpDebug (DumpState *D, const Proto *f) {
155 int i, n; 155 int i, n;
156 n = (D->strip) ? 0 : f->sizelineinfo; 156 n = (D->strip) ? 0 : f->sizelineinfo;
157 DumpInt(n, D); 157 dumpInt(D, n);
158 DumpVector(f->lineinfo, n, D); 158 dumpVector(D, f->lineinfo, n);
159 n = (D->strip) ? 0 : f->sizeabslineinfo; 159 n = (D->strip) ? 0 : f->sizeabslineinfo;
160 DumpInt(n, D); 160 dumpInt(D, n);
161 for (i = 0; i < n; i++) { 161 for (i = 0; i < n; i++) {
162 DumpInt(f->abslineinfo[i].pc, D); 162 dumpInt(D, f->abslineinfo[i].pc);
163 DumpInt(f->abslineinfo[i].line, D); 163 dumpInt(D, f->abslineinfo[i].line);
164 } 164 }
165 n = (D->strip) ? 0 : f->sizelocvars; 165 n = (D->strip) ? 0 : f->sizelocvars;
166 DumpInt(n, D); 166 dumpInt(D, n);
167 for (i = 0; i < n; i++) { 167 for (i = 0; i < n; i++) {
168 DumpString(f->locvars[i].varname, D); 168 dumpString(D, f->locvars[i].varname);
169 DumpInt(f->locvars[i].startpc, D); 169 dumpInt(D, f->locvars[i].startpc);
170 DumpInt(f->locvars[i].endpc, D); 170 dumpInt(D, f->locvars[i].endpc);
171 } 171 }
172 n = (D->strip) ? 0 : f->sizeupvalues; 172 n = (D->strip) ? 0 : f->sizeupvalues;
173 DumpInt(n, D); 173 dumpInt(D, n);
174 for (i = 0; i < n; i++) 174 for (i = 0; i < n; i++)
175 DumpString(f->upvalues[i].name, D); 175 dumpString(D, f->upvalues[i].name);
176} 176}
177 177
178 178
179static void DumpFunction (const Proto *f, TString *psource, DumpState *D) { 179static void dumpFunction (DumpState *D, const Proto *f, TString *psource) {
180 if (D->strip || f->source == psource) 180 if (D->strip || f->source == psource)
181 DumpString(NULL, D); /* no debug info or same source as its parent */ 181 dumpString(D, NULL); /* no debug info or same source as its parent */
182 else 182 else
183 DumpString(f->source, D); 183 dumpString(D, f->source);
184 DumpInt(f->linedefined, D); 184 dumpInt(D, f->linedefined);
185 DumpInt(f->lastlinedefined, D); 185 dumpInt(D, f->lastlinedefined);
186 DumpByte(f->numparams, D); 186 dumpByte(D, f->numparams);
187 DumpByte(f->is_vararg, D); 187 dumpByte(D, f->is_vararg);
188 DumpByte(f->maxstacksize, D); 188 dumpByte(D, f->maxstacksize);
189 DumpCode(f, D); 189 dumpCode(D, f);
190 DumpConstants(f, D); 190 dumpConstants(D, f);
191 DumpUpvalues(f, D); 191 dumpUpvalues(D, f);
192 DumpProtos(f, D); 192 dumpProtos(D, f);
193 DumpDebug(f, D); 193 dumpDebug(D, f);
194} 194}
195 195
196 196
197static void DumpHeader (DumpState *D) { 197static void dumpHeader (DumpState *D) {
198 DumpLiteral(LUA_SIGNATURE, D); 198 dumpLiteral(D, LUA_SIGNATURE);
199 DumpInt(LUAC_VERSION, D); 199 dumpInt(D, LUAC_VERSION);
200 DumpByte(LUAC_FORMAT, D); 200 dumpByte(D, LUAC_FORMAT);
201 DumpLiteral(LUAC_DATA, D); 201 dumpLiteral(D, LUAC_DATA);
202 DumpByte(sizeof(Instruction), D); 202 dumpByte(D, sizeof(Instruction));
203 DumpByte(sizeof(lua_Integer), D); 203 dumpByte(D, sizeof(lua_Integer));
204 DumpByte(sizeof(lua_Number), D); 204 dumpByte(D, sizeof(lua_Number));
205 DumpInteger(LUAC_INT, D); 205 dumpInteger(D, LUAC_INT);
206 DumpNumber(LUAC_NUM, D); 206 dumpNumber(D, LUAC_NUM);
207} 207}
208 208
209 209
@@ -218,9 +218,9 @@ int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data,
218 D.data = data; 218 D.data = data;
219 D.strip = strip; 219 D.strip = strip;
220 D.status = 0; 220 D.status = 0;
221 DumpHeader(&D); 221 dumpHeader(&D);
222 DumpByte(f->sizeupvalues, &D); 222 dumpByte(&D, f->sizeupvalues);
223 DumpFunction(f, NULL, &D); 223 dumpFunction(&D, f, NULL);
224 return D.status; 224 return D.status;
225} 225}
226 226
diff --git a/lundump.c b/lundump.c
index 1fa322f6..17364999 100644
--- a/lundump.c
+++ b/lundump.c
@@ -44,21 +44,21 @@ static l_noret error (LoadState *S, const char *why) {
44 44
45 45
46/* 46/*
47** All high-level loads go through LoadVector; you can change it to 47** All high-level loads go through loadVector; you can change it to
48** adapt to the endianness of the input 48** adapt to the endianness of the input
49*/ 49*/
50#define LoadVector(S,b,n) LoadBlock(S,b,(n)*sizeof((b)[0])) 50#define loadVector(S,b,n) loadBlock(S,b,(n)*sizeof((b)[0]))
51 51
52static void LoadBlock (LoadState *S, void *b, size_t size) { 52static void loadBlock (LoadState *S, void *b, size_t size) {
53 if (luaZ_read(S->Z, b, size) != 0) 53 if (luaZ_read(S->Z, b, size) != 0)
54 error(S, "truncated chunk"); 54 error(S, "truncated chunk");
55} 55}
56 56
57 57
58#define LoadVar(S,x) LoadVector(S,&x,1) 58#define loadVar(S,x) loadVector(S,&x,1)
59 59
60 60
61static lu_byte LoadByte (LoadState *S) { 61static lu_byte loadByte (LoadState *S) {
62 int b = zgetc(S->Z); 62 int b = zgetc(S->Z);
63 if (b == EOZ) 63 if (b == EOZ)
64 error(S, "truncated chunk"); 64 error(S, "truncated chunk");
@@ -66,12 +66,12 @@ static lu_byte LoadByte (LoadState *S) {
66} 66}
67 67
68 68
69static size_t LoadUnsigned (LoadState *S, size_t limit) { 69static size_t loadUnsigned (LoadState *S, size_t limit) {
70 size_t x = 0; 70 size_t x = 0;
71 int b; 71 int b;
72 limit >>= 7; 72 limit >>= 7;
73 do { 73 do {
74 b = LoadByte(S); 74 b = loadByte(S);
75 if (x >= limit) 75 if (x >= limit)
76 error(S, "integer overflow"); 76 error(S, "integer overflow");
77 x = (x << 7) | (b & 0x7f); 77 x = (x << 7) | (b & 0x7f);
@@ -80,45 +80,45 @@ static size_t LoadUnsigned (LoadState *S, size_t limit) {
80} 80}
81 81
82 82
83static size_t LoadSize (LoadState *S) { 83static size_t loadSize (LoadState *S) {
84 return LoadUnsigned(S, ~(size_t)0); 84 return loadUnsigned(S, ~(size_t)0);
85} 85}
86 86
87 87
88static int LoadInt (LoadState *S) { 88static int loadInt (LoadState *S) {
89 return cast_int(LoadUnsigned(S, INT_MAX)); 89 return cast_int(loadUnsigned(S, INT_MAX));
90} 90}
91 91
92 92
93static lua_Number LoadNumber (LoadState *S) { 93static lua_Number loadNumber (LoadState *S) {
94 lua_Number x; 94 lua_Number x;
95 LoadVar(S, x); 95 loadVar(S, x);
96 return x; 96 return x;
97} 97}
98 98
99 99
100static lua_Integer LoadInteger (LoadState *S) { 100static lua_Integer loadInteger (LoadState *S) {
101 lua_Integer x; 101 lua_Integer x;
102 LoadVar(S, x); 102 loadVar(S, x);
103 return x; 103 return x;
104} 104}
105 105
106 106
107/* 107/*
108** Load a nullable string 108** Load a nullable string.
109*/ 109*/
110static TString *LoadStringN (LoadState *S) { 110static TString *loadStringN (LoadState *S) {
111 size_t size = LoadSize(S); 111 size_t size = loadSize(S);
112 if (size == 0) 112 if (size == 0)
113 return NULL; 113 return NULL;
114 else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */ 114 else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */
115 char buff[LUAI_MAXSHORTLEN]; 115 char buff[LUAI_MAXSHORTLEN];
116 LoadVector(S, buff, size); 116 loadVector(S, buff, size);
117 return luaS_newlstr(S->L, buff, size); 117 return luaS_newlstr(S->L, buff, size);
118 } 118 }
119 else { /* long string */ 119 else { /* long string */
120 TString *ts = luaS_createlngstrobj(S->L, size); 120 TString *ts = luaS_createlngstrobj(S->L, size);
121 LoadVector(S, getstr(ts), size); /* load directly in final place */ 121 loadVector(S, getstr(ts), size); /* load directly in final place */
122 return ts; 122 return ts;
123 } 123 }
124} 124}
@@ -127,35 +127,35 @@ static TString *LoadStringN (LoadState *S) {
127/* 127/*
128** Load a non-nullable string. 128** Load a non-nullable string.
129*/ 129*/
130static TString *LoadString (LoadState *S) { 130static TString *loadString (LoadState *S) {
131 TString *st = LoadStringN(S); 131 TString *st = loadStringN(S);
132 if (st == NULL) 132 if (st == NULL)
133 error(S, "bad format for constant string"); 133 error(S, "bad format for constant string");
134 return st; 134 return st;
135} 135}
136 136
137 137
138static void LoadCode (LoadState *S, Proto *f) { 138static void loadCode (LoadState *S, Proto *f) {
139 int n = LoadInt(S); 139 int n = loadInt(S);
140 f->code = luaM_newvectorchecked(S->L, n, Instruction); 140 f->code = luaM_newvectorchecked(S->L, n, Instruction);
141 f->sizecode = n; 141 f->sizecode = n;
142 LoadVector(S, f->code, n); 142 loadVector(S, f->code, n);
143} 143}
144 144
145 145
146static void LoadFunction(LoadState *S, Proto *f, TString *psource); 146static void loadFunction(LoadState *S, Proto *f, TString *psource);
147 147
148 148
149static void LoadConstants (LoadState *S, Proto *f) { 149static void loadConstants (LoadState *S, Proto *f) {
150 int i; 150 int i;
151 int n = LoadInt(S); 151 int n = loadInt(S);
152 f->k = luaM_newvectorchecked(S->L, n, TValue); 152 f->k = luaM_newvectorchecked(S->L, n, TValue);
153 f->sizek = n; 153 f->sizek = n;
154 for (i = 0; i < n; i++) 154 for (i = 0; i < n; i++)
155 setnilvalue(&f->k[i]); 155 setnilvalue(&f->k[i]);
156 for (i = 0; i < n; i++) { 156 for (i = 0; i < n; i++) {
157 TValue *o = &f->k[i]; 157 TValue *o = &f->k[i];
158 int t = LoadByte(S); 158 int t = loadByte(S);
159 switch (t) { 159 switch (t) {
160 case LUA_VNIL: 160 case LUA_VNIL:
161 setnilvalue(o); 161 setnilvalue(o);
@@ -167,14 +167,14 @@ static void LoadConstants (LoadState *S, Proto *f) {
167 setbtvalue(o); 167 setbtvalue(o);
168 break; 168 break;
169 case LUA_VNUMFLT: 169 case LUA_VNUMFLT:
170 setfltvalue(o, LoadNumber(S)); 170 setfltvalue(o, loadNumber(S));
171 break; 171 break;
172 case LUA_VNUMINT: 172 case LUA_VNUMINT:
173 setivalue(o, LoadInteger(S)); 173 setivalue(o, loadInteger(S));
174 break; 174 break;
175 case LUA_VSHRSTR: 175 case LUA_VSHRSTR:
176 case LUA_VLNGSTR: 176 case LUA_VLNGSTR:
177 setsvalue2n(S->L, o, LoadString(S)); 177 setsvalue2n(S->L, o, loadString(S));
178 break; 178 break;
179 default: lua_assert(0); 179 default: lua_assert(0);
180 } 180 }
@@ -182,91 +182,91 @@ static void LoadConstants (LoadState *S, Proto *f) {
182} 182}
183 183
184 184
185static void LoadProtos (LoadState *S, Proto *f) { 185static void loadProtos (LoadState *S, Proto *f) {
186 int i; 186 int i;
187 int n = LoadInt(S); 187 int n = loadInt(S);
188 f->p = luaM_newvectorchecked(S->L, n, Proto *); 188 f->p = luaM_newvectorchecked(S->L, n, Proto *);
189 f->sizep = n; 189 f->sizep = n;
190 for (i = 0; i < n; i++) 190 for (i = 0; i < n; i++)
191 f->p[i] = NULL; 191 f->p[i] = NULL;
192 for (i = 0; i < n; i++) { 192 for (i = 0; i < n; i++) {
193 f->p[i] = luaF_newproto(S->L); 193 f->p[i] = luaF_newproto(S->L);
194 LoadFunction(S, f->p[i], f->source); 194 loadFunction(S, f->p[i], f->source);
195 } 195 }
196} 196}
197 197
198 198
199static void LoadUpvalues (LoadState *S, Proto *f) { 199static void loadUpvalues (LoadState *S, Proto *f) {
200 int i, n; 200 int i, n;
201 n = LoadInt(S); 201 n = loadInt(S);
202 f->upvalues = luaM_newvectorchecked(S->L, n, Upvaldesc); 202 f->upvalues = luaM_newvectorchecked(S->L, n, Upvaldesc);
203 f->sizeupvalues = n; 203 f->sizeupvalues = n;
204 for (i = 0; i < n; i++) { 204 for (i = 0; i < n; i++) {
205 f->upvalues[i].name = NULL; 205 f->upvalues[i].name = NULL;
206 f->upvalues[i].instack = LoadByte(S); 206 f->upvalues[i].instack = loadByte(S);
207 f->upvalues[i].idx = LoadByte(S); 207 f->upvalues[i].idx = loadByte(S);
208 f->upvalues[i].kind = LoadByte(S); 208 f->upvalues[i].kind = loadByte(S);
209 } 209 }
210} 210}
211 211
212 212
213static void LoadDebug (LoadState *S, Proto *f) { 213static void loadDebug (LoadState *S, Proto *f) {
214 int i, n; 214 int i, n;
215 n = LoadInt(S); 215 n = loadInt(S);
216 f->lineinfo = luaM_newvectorchecked(S->L, n, ls_byte); 216 f->lineinfo = luaM_newvectorchecked(S->L, n, ls_byte);
217 f->sizelineinfo = n; 217 f->sizelineinfo = n;
218 LoadVector(S, f->lineinfo, n); 218 loadVector(S, f->lineinfo, n);
219 n = LoadInt(S); 219 n = loadInt(S);
220 f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo); 220 f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo);
221 f->sizeabslineinfo = n; 221 f->sizeabslineinfo = n;
222 for (i = 0; i < n; i++) { 222 for (i = 0; i < n; i++) {
223 f->abslineinfo[i].pc = LoadInt(S); 223 f->abslineinfo[i].pc = loadInt(S);
224 f->abslineinfo[i].line = LoadInt(S); 224 f->abslineinfo[i].line = loadInt(S);
225 } 225 }
226 n = LoadInt(S); 226 n = loadInt(S);
227 f->locvars = luaM_newvectorchecked(S->L, n, LocVar); 227 f->locvars = luaM_newvectorchecked(S->L, n, LocVar);
228 f->sizelocvars = n; 228 f->sizelocvars = n;
229 for (i = 0; i < n; i++) 229 for (i = 0; i < n; i++)
230 f->locvars[i].varname = NULL; 230 f->locvars[i].varname = NULL;
231 for (i = 0; i < n; i++) { 231 for (i = 0; i < n; i++) {
232 f->locvars[i].varname = LoadStringN(S); 232 f->locvars[i].varname = loadStringN(S);
233 f->locvars[i].startpc = LoadInt(S); 233 f->locvars[i].startpc = loadInt(S);
234 f->locvars[i].endpc = LoadInt(S); 234 f->locvars[i].endpc = loadInt(S);
235 } 235 }
236 n = LoadInt(S); 236 n = loadInt(S);
237 for (i = 0; i < n; i++) 237 for (i = 0; i < n; i++)
238 f->upvalues[i].name = LoadStringN(S); 238 f->upvalues[i].name = loadStringN(S);
239} 239}
240 240
241 241
242static void LoadFunction (LoadState *S, Proto *f, TString *psource) { 242static void loadFunction (LoadState *S, Proto *f, TString *psource) {
243 f->source = LoadStringN(S); 243 f->source = loadStringN(S);
244 if (f->source == NULL) /* no source in dump? */ 244 if (f->source == NULL) /* no source in dump? */
245 f->source = psource; /* reuse parent's source */ 245 f->source = psource; /* reuse parent's source */
246 f->linedefined = LoadInt(S); 246 f->linedefined = loadInt(S);
247 f->lastlinedefined = LoadInt(S); 247 f->lastlinedefined = loadInt(S);
248 f->numparams = LoadByte(S); 248 f->numparams = loadByte(S);
249 f->is_vararg = LoadByte(S); 249 f->is_vararg = loadByte(S);
250 f->maxstacksize = LoadByte(S); 250 f->maxstacksize = loadByte(S);
251 LoadCode(S, f); 251 loadCode(S, f);
252 LoadConstants(S, f); 252 loadConstants(S, f);
253 LoadUpvalues(S, f); 253 loadUpvalues(S, f);
254 LoadProtos(S, f); 254 loadProtos(S, f);
255 LoadDebug(S, f); 255 loadDebug(S, f);
256} 256}
257 257
258 258
259static void checkliteral (LoadState *S, const char *s, const char *msg) { 259static void checkliteral (LoadState *S, const char *s, const char *msg) {
260 char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */ 260 char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */
261 size_t len = strlen(s); 261 size_t len = strlen(s);
262 LoadVector(S, buff, len); 262 loadVector(S, buff, len);
263 if (memcmp(s, buff, len) != 0) 263 if (memcmp(s, buff, len) != 0)
264 error(S, msg); 264 error(S, msg);
265} 265}
266 266
267 267
268static void fchecksize (LoadState *S, size_t size, const char *tname) { 268static void fchecksize (LoadState *S, size_t size, const char *tname) {
269 if (LoadByte(S) != size) 269 if (loadByte(S) != size)
270 error(S, luaO_pushfstring(S->L, "%s size mismatch", tname)); 270 error(S, luaO_pushfstring(S->L, "%s size mismatch", tname));
271} 271}
272 272
@@ -276,23 +276,23 @@ static void fchecksize (LoadState *S, size_t size, const char *tname) {
276static void checkHeader (LoadState *S) { 276static void checkHeader (LoadState *S) {
277 /* skip 1st char (already read and checked) */ 277 /* skip 1st char (already read and checked) */
278 checkliteral(S, &LUA_SIGNATURE[1], "not a binary chunk"); 278 checkliteral(S, &LUA_SIGNATURE[1], "not a binary chunk");
279 if (LoadInt(S) != LUAC_VERSION) 279 if (loadInt(S) != LUAC_VERSION)
280 error(S, "version mismatch"); 280 error(S, "version mismatch");
281 if (LoadByte(S) != LUAC_FORMAT) 281 if (loadByte(S) != LUAC_FORMAT)
282 error(S, "format mismatch"); 282 error(S, "format mismatch");
283 checkliteral(S, LUAC_DATA, "corrupted chunk"); 283 checkliteral(S, LUAC_DATA, "corrupted chunk");
284 checksize(S, Instruction); 284 checksize(S, Instruction);
285 checksize(S, lua_Integer); 285 checksize(S, lua_Integer);
286 checksize(S, lua_Number); 286 checksize(S, lua_Number);
287 if (LoadInteger(S) != LUAC_INT) 287 if (loadInteger(S) != LUAC_INT)
288 error(S, "integer format mismatch"); 288 error(S, "integer format mismatch");
289 if (LoadNumber(S) != LUAC_NUM) 289 if (loadNumber(S) != LUAC_NUM)
290 error(S, "float format mismatch"); 290 error(S, "float format mismatch");
291} 291}
292 292
293 293
294/* 294/*
295** load precompiled chunk 295** Load precompiled chunk.
296*/ 296*/
297LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) { 297LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {
298 LoadState S; 298 LoadState S;
@@ -306,11 +306,11 @@ LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {
306 S.L = L; 306 S.L = L;
307 S.Z = Z; 307 S.Z = Z;
308 checkHeader(&S); 308 checkHeader(&S);
309 cl = luaF_newLclosure(L, LoadByte(&S)); 309 cl = luaF_newLclosure(L, loadByte(&S));
310 setclLvalue2s(L, L->top, cl); 310 setclLvalue2s(L, L->top, cl);
311 luaD_inctop(L); 311 luaD_inctop(L);
312 cl->p = luaF_newproto(L); 312 cl->p = luaF_newproto(L);
313 LoadFunction(&S, cl->p, NULL); 313 loadFunction(&S, cl->p, NULL);
314 lua_assert(cl->nupvalues == cl->p->sizeupvalues); 314 lua_assert(cl->nupvalues == cl->p->sizeupvalues);
315 luai_verifycode(L, buff, cl->p); 315 luai_verifycode(L, buff, cl->p);
316 return cl; 316 return cl;