|
@@ -1,11 +1,9 @@
|
|
/*
|
|
/*
|
|
-** $Id: lundump.c,v 1.47 2002/05/15 18:57:44 roberto Exp roberto $
|
|
|
|
|
|
+** $Id: lundump.c,v 1.40 2002/03/01 01:48:42 lhf Exp lhf $
|
|
** load pre-compiled Lua chunks
|
|
** load pre-compiled Lua chunks
|
|
** See Copyright Notice in lua.h
|
|
** See Copyright Notice in lua.h
|
|
*/
|
|
*/
|
|
|
|
|
|
-#include <string.h>
|
|
|
|
-
|
|
|
|
#include "lua.h"
|
|
#include "lua.h"
|
|
|
|
|
|
#include "ldebug.h"
|
|
#include "ldebug.h"
|
|
@@ -14,19 +12,24 @@
|
|
#include "lopcodes.h"
|
|
#include "lopcodes.h"
|
|
#include "lstring.h"
|
|
#include "lstring.h"
|
|
#include "lundump.h"
|
|
#include "lundump.h"
|
|
|
|
+#include "lzio.h"
|
|
|
|
|
|
-#define LoadByte ezgetc
|
|
|
|
-#define LoadShort (short) LoadInt
|
|
|
|
|
|
+#define LoadByte (lu_byte) ezgetc
|
|
|
|
|
|
static const char* ZNAME (ZIO* Z)
|
|
static const char* ZNAME (ZIO* Z)
|
|
{
|
|
{
|
|
const char* s=zname(Z);
|
|
const char* s=zname(Z);
|
|
- return (*s=='@') ? s+1 : s;
|
|
|
|
|
|
+ if (*s=='@' || *s=='=')
|
|
|
|
+ return s+1;
|
|
|
|
+ else if (*s==LUA_SIGNATURE[0])
|
|
|
|
+ return "binary string";
|
|
|
|
+ else
|
|
|
|
+ return s;
|
|
}
|
|
}
|
|
|
|
|
|
static void unexpectedEOZ (lua_State* L, ZIO* Z)
|
|
static void unexpectedEOZ (lua_State* L, ZIO* Z)
|
|
{
|
|
{
|
|
- luaG_runerror(L,"unexpected end of file in `%s'",ZNAME(Z));
|
|
|
|
|
|
+ luaG_runerror(L,"unexpected end of file in %s",ZNAME(Z));
|
|
}
|
|
}
|
|
|
|
|
|
static int ezgetc (lua_State* L, ZIO* Z)
|
|
static int ezgetc (lua_State* L, ZIO* Z)
|
|
@@ -75,6 +78,7 @@ static int LoadInt (lua_State* L, ZIO* Z, int swap)
|
|
{
|
|
{
|
|
int x;
|
|
int x;
|
|
LoadBlock(L,&x,sizeof(x),Z,swap);
|
|
LoadBlock(L,&x,sizeof(x),Z,swap);
|
|
|
|
+ if (x<0) luaG_runerror(L,"bad integer in %s",ZNAME(Z));
|
|
return x;
|
|
return x;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -155,8 +159,10 @@ static void LoadConstants (lua_State* L, Proto* f, ZIO* Z, int swap)
|
|
case LUA_TSTRING:
|
|
case LUA_TSTRING:
|
|
tsvalue(o)=LoadString(L,Z,swap);
|
|
tsvalue(o)=LoadString(L,Z,swap);
|
|
break;
|
|
break;
|
|
|
|
+ case LUA_TNIL:
|
|
|
|
+ break;
|
|
default:
|
|
default:
|
|
- luaG_runerror(L,"bad constant type (%d) in `%s'",ttype(o),ZNAME(Z));
|
|
|
|
|
|
+ luaG_runerror(L,"bad constant type (%d) in %s",ttype(o),ZNAME(Z));
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -171,16 +177,16 @@ static Proto* LoadFunction (lua_State* L, TString* p, ZIO* Z, int swap)
|
|
Proto* f=luaF_newproto(L);
|
|
Proto* f=luaF_newproto(L);
|
|
f->source=LoadString(L,Z,swap); if (f->source==NULL) f->source=p;
|
|
f->source=LoadString(L,Z,swap); if (f->source==NULL) f->source=p;
|
|
f->lineDefined=LoadInt(L,Z,swap);
|
|
f->lineDefined=LoadInt(L,Z,swap);
|
|
- f->nupvalues=LoadShort(L,Z,swap);
|
|
|
|
- f->numparams=LoadShort(L,Z,swap);
|
|
|
|
- f->is_vararg=LoadShort(L,Z,swap);
|
|
|
|
- f->maxstacksize=LoadShort(L,Z,swap);
|
|
|
|
|
|
+ f->nupvalues=LoadByte(L,Z);
|
|
|
|
+ f->numparams=LoadByte(L,Z);
|
|
|
|
+ f->is_vararg=LoadByte(L,Z);
|
|
|
|
+ f->maxstacksize=LoadByte(L,Z);
|
|
LoadLocals(L,f,Z,swap);
|
|
LoadLocals(L,f,Z,swap);
|
|
LoadLines(L,f,Z,swap);
|
|
LoadLines(L,f,Z,swap);
|
|
LoadConstants(L,f,Z,swap);
|
|
LoadConstants(L,f,Z,swap);
|
|
LoadCode(L,f,Z,swap);
|
|
LoadCode(L,f,Z,swap);
|
|
#ifndef TRUST_BINARIES
|
|
#ifndef TRUST_BINARIES
|
|
- if (!luaG_checkcode(f)) luaG_runerror(L,"bad code in `%s'",ZNAME(Z));
|
|
|
|
|
|
+ if (!luaG_checkcode(f)) luaG_runerror(L,"bad code in %s",ZNAME(Z));
|
|
#endif
|
|
#endif
|
|
return f;
|
|
return f;
|
|
}
|
|
}
|
|
@@ -190,15 +196,15 @@ static void LoadSignature (lua_State* L, ZIO* Z)
|
|
const char* s=LUA_SIGNATURE;
|
|
const char* s=LUA_SIGNATURE;
|
|
while (*s!=0 && ezgetc(L,Z)==*s)
|
|
while (*s!=0 && ezgetc(L,Z)==*s)
|
|
++s;
|
|
++s;
|
|
- if (*s!=0) luaG_runerror(L,"bad signature in `%s'",ZNAME(Z));
|
|
|
|
|
|
+ if (*s!=0) luaG_runerror(L,"bad signature in %s",ZNAME(Z));
|
|
}
|
|
}
|
|
|
|
|
|
static void TestSize (lua_State* L, int s, const char* what, ZIO* Z)
|
|
static void TestSize (lua_State* L, int s, const char* what, ZIO* Z)
|
|
{
|
|
{
|
|
int r=LoadByte(L,Z);
|
|
int r=LoadByte(L,Z);
|
|
if (r!=s)
|
|
if (r!=s)
|
|
- luaG_runerror(L,"virtual machine mismatch in `%s':\n"
|
|
|
|
- " size of %.20s is %d but read %d",ZNAME(Z),what,s,r);
|
|
|
|
|
|
+ luaG_runerror(L,"virtual machine mismatch in %s: "
|
|
|
|
+ "size of %s is %d but read %d",ZNAME(Z),what,s,r);
|
|
}
|
|
}
|
|
|
|
|
|
#define TESTSIZE(s,w) TestSize(L,s,w,Z)
|
|
#define TESTSIZE(s,w) TestSize(L,s,w,Z)
|
|
@@ -211,17 +217,17 @@ static int LoadHeader (lua_State* L, ZIO* Z)
|
|
LoadSignature(L,Z);
|
|
LoadSignature(L,Z);
|
|
version=LoadByte(L,Z);
|
|
version=LoadByte(L,Z);
|
|
if (version>VERSION)
|
|
if (version>VERSION)
|
|
- luaG_runerror(L,"`%s' too new:\n"
|
|
|
|
- " read version %d.%d; expected at most %d.%d",
|
|
|
|
|
|
+ luaG_runerror(L,"%s too new: "
|
|
|
|
+ "read version %d.%d; expected at most %d.%d",
|
|
ZNAME(Z),V(version),V(VERSION));
|
|
ZNAME(Z),V(version),V(VERSION));
|
|
if (version<VERSION0) /* check last major change */
|
|
if (version<VERSION0) /* check last major change */
|
|
- luaG_runerror(L,"`%s' too old:\n"
|
|
|
|
- " read version %d.%d; expected at least %d.%d",
|
|
|
|
- ZNAME(Z),V(version),V(VERSION));
|
|
|
|
|
|
+ luaG_runerror(L,"%s too old: "
|
|
|
|
+ "read version %d.%d; expected at least %d.%d",
|
|
|
|
+ ZNAME(Z),V(version),V(VERSION0));
|
|
swap=(luaU_endianness()!=LoadByte(L,Z)); /* need to swap bytes? */
|
|
swap=(luaU_endianness()!=LoadByte(L,Z)); /* need to swap bytes? */
|
|
TESTSIZE(sizeof(int),"int");
|
|
TESTSIZE(sizeof(int),"int");
|
|
TESTSIZE(sizeof(size_t), "size_t");
|
|
TESTSIZE(sizeof(size_t), "size_t");
|
|
- TESTSIZE(sizeof(Instruction), "size_t");
|
|
|
|
|
|
+ TESTSIZE(sizeof(Instruction), "Instruction");
|
|
TESTSIZE(SIZE_OP, "OP");
|
|
TESTSIZE(SIZE_OP, "OP");
|
|
TESTSIZE(SIZE_A, "A");
|
|
TESTSIZE(SIZE_A, "A");
|
|
TESTSIZE(SIZE_B, "B");
|
|
TESTSIZE(SIZE_B, "B");
|
|
@@ -229,8 +235,7 @@ static int LoadHeader (lua_State* L, ZIO* Z)
|
|
TESTSIZE(sizeof(lua_Number), "number");
|
|
TESTSIZE(sizeof(lua_Number), "number");
|
|
x=LoadNumber(L,Z,swap);
|
|
x=LoadNumber(L,Z,swap);
|
|
if ((long)x!=(long)tx) /* disregard errors in last bits of fraction */
|
|
if ((long)x!=(long)tx) /* disregard errors in last bits of fraction */
|
|
- luaG_runerror(L,"unknown number format in `%s':\n"
|
|
|
|
- " read " LUA_NUMBER_FMT "; expected " LUA_NUMBER_FMT,
|
|
|
|
|
|
+ luaG_runerror(L,"unknown number format in %s: read %f; expected %f",
|
|
ZNAME(Z),x,tx);
|
|
ZNAME(Z),x,tx);
|
|
return swap;
|
|
return swap;
|
|
}
|
|
}
|
|
@@ -247,7 +252,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z)
|
|
{
|
|
{
|
|
Proto* f=LoadChunk(L,Z);
|
|
Proto* f=LoadChunk(L,Z);
|
|
if (zgetc(Z)!=EOZ)
|
|
if (zgetc(Z)!=EOZ)
|
|
- luaG_runerror(L,"`%s' apparently contains more than one chunk",ZNAME(Z));
|
|
|
|
|
|
+ luaG_runerror(L,"%s apparently contains more than one chunk",ZNAME(Z));
|
|
return f;
|
|
return f;
|
|
}
|
|
}
|
|
|
|
|