aboutsummaryrefslogtreecommitdiff
path: root/lundump.c
diff options
context:
space:
mode:
Diffstat (limited to 'lundump.c')
-rw-r--r--lundump.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/lundump.c b/lundump.c
index bb34fdd1..022b25ba 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 1.32 2000/09/21 03:15:36 lhf Exp $ 2** $Id: lundump.c,v 1.32 2000/09/21 03:15:36 lhf Exp lhf $
3** load bytecodes from files 3** load bytecodes from files
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -23,7 +23,7 @@ static const char* ZNAME (ZIO* Z)
23 23
24static void unexpectedEOZ (lua_State* L, ZIO* Z) 24static void unexpectedEOZ (lua_State* L, ZIO* Z)
25{ 25{
26 luaO_verror(L,"unexpected end of file in `%.255s'",ZNAME(Z)); 26 luaO_verror(L,"unexpected end of file in `%.99s'",ZNAME(Z));
27} 27}
28 28
29static int ezgetc (lua_State* L, ZIO* Z) 29static int ezgetc (lua_State* L, ZIO* Z)
@@ -107,7 +107,8 @@ static void LoadCode (lua_State* L, Proto* tf, ZIO* Z, int swap)
107 int size=LoadInt(L,Z,swap); 107 int size=LoadInt(L,Z,swap);
108 tf->code=luaM_newvector(L,size,Instruction); 108 tf->code=luaM_newvector(L,size,Instruction);
109 LoadVector(L,tf->code,size,sizeof(*tf->code),Z,swap); 109 LoadVector(L,tf->code,size,sizeof(*tf->code),Z,swap);
110 if (tf->code[size-1]!=OP_END) luaO_verror(L,"bad code in `%.255s'",ZNAME(Z)); 110 if (tf->code[size-1]!=OP_END) luaO_verror(L,"bad code in `%.99s'",ZNAME(Z));
111 luaF_protook(L,tf,size);
111} 112}
112 113
113static void LoadLocals (lua_State* L, Proto* tf, ZIO* Z, int swap) 114static void LoadLocals (lua_State* L, Proto* tf, ZIO* Z, int swap)
@@ -125,8 +126,8 @@ static void LoadLocals (lua_State* L, Proto* tf, ZIO* Z, int swap)
125 126
126static void LoadLines (lua_State* L, Proto* tf, ZIO* Z, int swap) 127static void LoadLines (lua_State* L, Proto* tf, ZIO* Z, int swap)
127{ 128{
128 int n=LoadInt(L,Z,swap); 129 int n;
129 if (n==0) return; 130 tf->nlineinfo=n=LoadInt(L,Z,swap);
130 tf->lineinfo=luaM_newvector(L,n,int); 131 tf->lineinfo=luaM_newvector(L,n,int);
131 LoadVector(L,tf->lineinfo,n,sizeof(*tf->lineinfo),Z,swap); 132 LoadVector(L,tf->lineinfo,n,sizeof(*tf->lineinfo),Z,swap);
132} 133}
@@ -157,10 +158,10 @@ static Proto* LoadFunction (lua_State* L, ZIO* Z, int swap)
157 tf->numparams=LoadInt(L,Z,swap); 158 tf->numparams=LoadInt(L,Z,swap);
158 tf->is_vararg=LoadByte(L,Z); 159 tf->is_vararg=LoadByte(L,Z);
159 tf->maxstacksize=LoadInt(L,Z,swap); 160 tf->maxstacksize=LoadInt(L,Z,swap);
160 LoadCode(L,tf,Z,swap);
161 LoadLocals(L,tf,Z,swap); 161 LoadLocals(L,tf,Z,swap);
162 LoadLines(L,tf,Z,swap); 162 LoadLines(L,tf,Z,swap);
163 LoadConstants(L,tf,Z,swap); 163 LoadConstants(L,tf,Z,swap);
164 LoadCode(L,tf,Z,swap);
164 return tf; 165 return tf;
165} 166}
166 167
@@ -169,14 +170,14 @@ static void LoadSignature (lua_State* L, ZIO* Z)
169 const char* s=SIGNATURE; 170 const char* s=SIGNATURE;
170 while (*s!=0 && ezgetc(L,Z)==*s) 171 while (*s!=0 && ezgetc(L,Z)==*s)
171 ++s; 172 ++s;
172 if (*s!=0) luaO_verror(L,"bad signature in `%.255s'",ZNAME(Z)); 173 if (*s!=0) luaO_verror(L,"bad signature in `%.99s'",ZNAME(Z));
173} 174}
174 175
175static void TestSize (lua_State* L, int s, const char* what, ZIO* Z) 176static void TestSize (lua_State* L, int s, const char* what, ZIO* Z)
176{ 177{
177 int r=ezgetc(L,Z); 178 int r=ezgetc(L,Z);
178 if (r!=s) 179 if (r!=s)
179 luaO_verror(L,"virtual machine mismatch in `%.255s':\n" 180 luaO_verror(L,"virtual machine mismatch in `%.99s':\n"
180 " %s is %d but read %d",ZNAME(Z),what,s,r); 181 " %s is %d but read %d",ZNAME(Z),what,s,r);
181} 182}
182 183
@@ -190,11 +191,11 @@ static int LoadHeader (lua_State* L, ZIO* Z)
190 LoadSignature(L,Z); 191 LoadSignature(L,Z);
191 version=ezgetc(L,Z); 192 version=ezgetc(L,Z);
192 if (version>VERSION) 193 if (version>VERSION)
193 luaO_verror(L,"`%.255s' too new:\n" 194 luaO_verror(L,"`%.99s' too new:\n"
194 " read version %d.%d; expected at most %d.%d", 195 " read version %d.%d; expected at most %d.%d",
195 ZNAME(Z),V(version),V(VERSION)); 196 ZNAME(Z),V(version),V(VERSION));
196 if (version<VERSION0) /* check last major change */ 197 if (version<VERSION0) /* check last major change */
197 luaO_verror(L,"`%.255s' too old:\n" 198 luaO_verror(L,"`%.99s' too old:\n"
198 " read version %d.%d; expected at least %d.%d", 199 " read version %d.%d; expected at least %d.%d",
199 ZNAME(Z),V(version),V(VERSION)); 200 ZNAME(Z),V(version),V(VERSION));
200 swap=(luaU_endianess()!=ezgetc(L,Z)); /* need to swap bytes? */ 201 swap=(luaU_endianess()!=ezgetc(L,Z)); /* need to swap bytes? */
@@ -207,9 +208,8 @@ static int LoadHeader (lua_State* L, ZIO* Z)
207 TESTSIZE(sizeof(Number)); 208 TESTSIZE(sizeof(Number));
208 f=LoadNumber(L,Z,swap); 209 f=LoadNumber(L,Z,swap);
209 if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */ 210 if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */
210 luaO_verror(L,"unknown number format in `%.255s':\n" 211 luaO_verror(L,"unknown number format in `%.99s':\n"
211 " read " NUMBER_FMT "; expected " NUMBER_FMT, 212 " read " NUMBER_FMT "; expected " NUMBER_FMT, ZNAME(Z),f,tf);
212 ZNAME(Z),f,tf);
213 return swap; 213 return swap;
214} 214}
215 215
@@ -230,7 +230,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z)
230 tf=LoadChunk(L,Z); 230 tf=LoadChunk(L,Z);
231 c=zgetc(Z); 231 c=zgetc(Z);
232 if (c!=EOZ) 232 if (c!=EOZ)
233 luaO_verror(L,"`%.255s' apparently contains more than one chunk",ZNAME(Z)); 233 luaO_verror(L,"`%.99s' apparently contains more than one chunk",ZNAME(Z));
234 return tf; 234 return tf;
235} 235}
236 236