forked from len0rd/rockbox
Revert "Update lua plugin to 5.2.3"
FILE typedef to *void needs more work to not break sim and application builds. I checked only a few random native builds unfortunately. Sorry for inconvenience.
This commit is contained in:
parent
36378988ad
commit
bfd0179042
64 changed files with 5733 additions and 9088 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lundump.c,v 2.22.1.1 2013/04/12 18:48:47 roberto Exp $
|
||||
** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $
|
||||
** load precompiled Lua chunks
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -27,24 +27,28 @@ typedef struct {
|
|||
const char* name;
|
||||
} LoadState;
|
||||
|
||||
static l_noret error(LoadState* S, const char* why)
|
||||
#ifdef LUAC_TRUST_BINARIES
|
||||
#define IF(c,s)
|
||||
#define error(S,s)
|
||||
#else
|
||||
#define IF(c,s) if (c) error(S,s)
|
||||
|
||||
static void error(LoadState* S, const char* why)
|
||||
{
|
||||
luaO_pushfstring(S->L,"%s: %s precompiled chunk",S->name,why);
|
||||
luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why);
|
||||
luaD_throw(S->L,LUA_ERRSYNTAX);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
|
||||
#define LoadByte(S) (lu_byte)LoadChar(S)
|
||||
#define LoadByte(S) (lu_byte)LoadChar(S)
|
||||
#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
|
||||
#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
|
||||
|
||||
#if !defined(luai_verifycode)
|
||||
#define luai_verifycode(L,b,f) /* empty */
|
||||
#endif
|
||||
|
||||
static void LoadBlock(LoadState* S, void* b, size_t size)
|
||||
{
|
||||
if (luaZ_read(S->Z,b,size)!=0) error(S,"truncated");
|
||||
size_t r=luaZ_read(S->Z,b,size);
|
||||
IF (r!=0, "unexpected end");
|
||||
}
|
||||
|
||||
static int LoadChar(LoadState* S)
|
||||
|
@ -58,7 +62,7 @@ static int LoadInt(LoadState* S)
|
|||
{
|
||||
int x;
|
||||
LoadVar(S,x);
|
||||
if (x<0) error(S,"corrupted");
|
||||
IF (x<0, "bad integer");
|
||||
return x;
|
||||
}
|
||||
|
||||
|
@ -78,7 +82,7 @@ static TString* LoadString(LoadState* S)
|
|||
else
|
||||
{
|
||||
char* s=luaZ_openspace(S->L,S->b,size);
|
||||
LoadBlock(S,s,size*sizeof(char));
|
||||
LoadBlock(S,s,size);
|
||||
return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +95,7 @@ static void LoadCode(LoadState* S, Proto* f)
|
|||
LoadVector(S,f->code,n,sizeof(Instruction));
|
||||
}
|
||||
|
||||
static void LoadFunction(LoadState* S, Proto* f);
|
||||
static Proto* LoadFunction(LoadState* S, TString* p);
|
||||
|
||||
static void LoadConstants(LoadState* S, Proto* f)
|
||||
{
|
||||
|
@ -107,10 +111,10 @@ static void LoadConstants(LoadState* S, Proto* f)
|
|||
switch (t)
|
||||
{
|
||||
case LUA_TNIL:
|
||||
setnilvalue(o);
|
||||
setnilvalue(o);
|
||||
break;
|
||||
case LUA_TBOOLEAN:
|
||||
setbvalue(o,LoadChar(S));
|
||||
setbvalue(o,LoadChar(S)!=0);
|
||||
break;
|
||||
case LUA_TNUMBER:
|
||||
setnvalue(o,LoadNumber(S));
|
||||
|
@ -118,38 +122,21 @@ static void LoadConstants(LoadState* S, Proto* f)
|
|||
case LUA_TSTRING:
|
||||
setsvalue2n(S->L,o,LoadString(S));
|
||||
break;
|
||||
default: lua_assert(0);
|
||||
default:
|
||||
error(S,"bad constant");
|
||||
break;
|
||||
}
|
||||
}
|
||||
n=LoadInt(S);
|
||||
f->p=luaM_newvector(S->L,n,Proto*);
|
||||
f->sizep=n;
|
||||
for (i=0; i<n; i++) f->p[i]=NULL;
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
f->p[i]=luaF_newproto(S->L);
|
||||
LoadFunction(S,f->p[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadUpvalues(LoadState* S, Proto* f)
|
||||
{
|
||||
int i,n;
|
||||
n=LoadInt(S);
|
||||
f->upvalues=luaM_newvector(S->L,n,Upvaldesc);
|
||||
f->sizeupvalues=n;
|
||||
for (i=0; i<n; i++) f->upvalues[i].name=NULL;
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
f->upvalues[i].instack=LoadByte(S);
|
||||
f->upvalues[i].idx=LoadByte(S);
|
||||
}
|
||||
for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source);
|
||||
}
|
||||
|
||||
static void LoadDebug(LoadState* S, Proto* f)
|
||||
{
|
||||
int i,n;
|
||||
f->source=LoadString(S);
|
||||
n=LoadInt(S);
|
||||
f->lineinfo=luaM_newvector(S->L,n,int);
|
||||
f->sizelineinfo=n;
|
||||
|
@ -165,48 +152,49 @@ static void LoadDebug(LoadState* S, Proto* f)
|
|||
f->locvars[i].endpc=LoadInt(S);
|
||||
}
|
||||
n=LoadInt(S);
|
||||
for (i=0; i<n; i++) f->upvalues[i].name=LoadString(S);
|
||||
f->upvalues=luaM_newvector(S->L,n,TString*);
|
||||
f->sizeupvalues=n;
|
||||
for (i=0; i<n; i++) f->upvalues[i]=NULL;
|
||||
for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);
|
||||
}
|
||||
|
||||
static void LoadFunction(LoadState* S, Proto* f)
|
||||
static Proto* LoadFunction(LoadState* S, TString* p)
|
||||
{
|
||||
Proto* f;
|
||||
if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep");
|
||||
f=luaF_newproto(S->L);
|
||||
setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
|
||||
f->source=LoadString(S); if (f->source==NULL) f->source=p;
|
||||
f->linedefined=LoadInt(S);
|
||||
f->lastlinedefined=LoadInt(S);
|
||||
f->nups=LoadByte(S);
|
||||
f->numparams=LoadByte(S);
|
||||
f->is_vararg=LoadByte(S);
|
||||
f->maxstacksize=LoadByte(S);
|
||||
LoadCode(S,f);
|
||||
LoadConstants(S,f);
|
||||
LoadUpvalues(S,f);
|
||||
LoadDebug(S,f);
|
||||
IF (!luaG_checkcode(f), "bad code");
|
||||
S->L->top--;
|
||||
S->L->nCcalls--;
|
||||
return f;
|
||||
}
|
||||
|
||||
/* the code below must be consistent with the code in luaU_header */
|
||||
#define N0 LUAC_HEADERSIZE
|
||||
#define N1 (sizeof(LUA_SIGNATURE)-sizeof(char))
|
||||
#define N2 N1+2
|
||||
#define N3 N2+6
|
||||
|
||||
static void LoadHeader(LoadState* S)
|
||||
{
|
||||
lu_byte h[LUAC_HEADERSIZE];
|
||||
lu_byte s[LUAC_HEADERSIZE];
|
||||
char h[LUAC_HEADERSIZE];
|
||||
char s[LUAC_HEADERSIZE];
|
||||
luaU_header(h);
|
||||
memcpy(s,h,sizeof(char)); /* first char already read */
|
||||
LoadBlock(S,s+sizeof(char),LUAC_HEADERSIZE-sizeof(char));
|
||||
if (memcmp(h,s,N0)==0) return;
|
||||
if (memcmp(h,s,N1)!=0) error(S,"not a");
|
||||
if (memcmp(h,s,N2)!=0) error(S,"version mismatch in");
|
||||
if (memcmp(h,s,N3)!=0) error(S,"incompatible"); else error(S,"corrupted");
|
||||
LoadBlock(S,s,LUAC_HEADERSIZE);
|
||||
IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
|
||||
}
|
||||
|
||||
/*
|
||||
** load precompiled chunk
|
||||
*/
|
||||
Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
|
||||
Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
|
||||
{
|
||||
LoadState S;
|
||||
Closure* cl;
|
||||
if (*name=='@' || *name=='=')
|
||||
S.name=name+1;
|
||||
else if (*name==LUA_SIGNATURE[0])
|
||||
|
@ -217,43 +205,23 @@ Closure* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
|
|||
S.Z=Z;
|
||||
S.b=buff;
|
||||
LoadHeader(&S);
|
||||
cl=luaF_newLclosure(L,1);
|
||||
setclLvalue(L,L->top,cl); incr_top(L);
|
||||
cl->l.p=luaF_newproto(L);
|
||||
LoadFunction(&S,cl->l.p);
|
||||
if (cl->l.p->sizeupvalues != 1)
|
||||
{
|
||||
Proto* p=cl->l.p;
|
||||
cl=luaF_newLclosure(L,cl->l.p->sizeupvalues);
|
||||
cl->l.p=p;
|
||||
setclLvalue(L,L->top-1,cl);
|
||||
}
|
||||
luai_verifycode(L,buff,cl->l.p);
|
||||
return cl;
|
||||
return LoadFunction(&S,luaS_newliteral(L,"=?"));
|
||||
}
|
||||
|
||||
#define MYINT(s) (s[0]-'0')
|
||||
#undef VERSION
|
||||
#define VERSION MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)
|
||||
#define FORMAT 0 /* this is the official format */
|
||||
|
||||
/*
|
||||
* make header for precompiled chunks
|
||||
* if you change the code below be sure to update LoadHeader and FORMAT above
|
||||
* and LUAC_HEADERSIZE in lundump.h
|
||||
* make header
|
||||
*/
|
||||
void luaU_header (lu_byte* h)
|
||||
void luaU_header (char* h)
|
||||
{
|
||||
int x=1;
|
||||
memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-sizeof(char));
|
||||
h+=sizeof(LUA_SIGNATURE)-sizeof(char);
|
||||
*h++=cast_byte(VERSION);
|
||||
*h++=cast_byte(FORMAT);
|
||||
*h++=cast_byte(*(char*)&x); /* endianness */
|
||||
*h++=cast_byte(sizeof(int));
|
||||
*h++=cast_byte(sizeof(size_t));
|
||||
*h++=cast_byte(sizeof(Instruction));
|
||||
*h++=cast_byte(sizeof(lua_Number));
|
||||
*h++=cast_byte(((lua_Number)0.5)==0); /* is lua_Number integral? */
|
||||
memcpy(h,LUAC_TAIL,sizeof(LUAC_TAIL)-sizeof(char));
|
||||
memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
|
||||
h+=sizeof(LUA_SIGNATURE)-1;
|
||||
*h++=(char)LUAC_VERSION;
|
||||
*h++=(char)LUAC_FORMAT;
|
||||
*h++=(char)*(char*)&x; /* endianness */
|
||||
*h++=(char)sizeof(int);
|
||||
*h++=(char)sizeof(size_t);
|
||||
*h++=(char)sizeof(Instruction);
|
||||
*h++=(char)sizeof(lua_Number);
|
||||
*h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue