first (big) step to support wide chars

This commit is contained in:
Roberto Ierusalimschy
2001-02-23 14:17:25 -03:00
parent d164e2294f
commit 39b7978329
40 changed files with 1151 additions and 1121 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: lundump.c,v 1.37 2000/12/28 12:59:41 roberto Exp roberto $
** $Id: lundump.c,v 1.38 2001/01/15 16:13:24 roberto Exp roberto $
** load bytecodes from files
** See Copyright Notice in lua.h
*/
@@ -15,15 +15,15 @@
#define LoadByte ezgetc
static const char* ZNAME (ZIO* Z)
static const l_char* ZNAME (ZIO* Z)
{
const char* s=zname(Z);
return (*s=='@') ? s+1 : s;
const l_char* s=zname(Z);
return (*s==l_c('@')) ? s+1 : s;
}
static void unexpectedEOZ (lua_State* L, ZIO* Z)
{
luaO_verror(L,"unexpected end of file in `%.99s'",ZNAME(Z));
luaO_verror(L,l_s("unexpected end of file in `%.99s'"),ZNAME(Z));
}
static int ezgetc (lua_State* L, ZIO* Z)
@@ -43,9 +43,9 @@ static void LoadBlock (lua_State* L, void* b, size_t size, ZIO* Z, int swap)
{
if (swap)
{
char *p=(char *) b+size-1;
l_char *p=(l_char *) b+size-1;
int n=size;
while (n--) *p--=(char)ezgetc(L,Z);
while (n--) *p--=(l_char)ezgetc(L,Z);
}
else
ezread(L,Z,b,size);
@@ -55,12 +55,12 @@ static void LoadVector (lua_State* L, void* b, int m, size_t size, ZIO* Z, int s
{
if (swap)
{
char *q=(char *) b;
l_char *q=(l_char *) b;
while (m--)
{
char *p=q+size-1;
l_char *p=q+size-1;
int n=size;
while (n--) *p--=(char)ezgetc(L,Z);
while (n--) *p--=(l_char)ezgetc(L,Z);
q+=size;
}
}
@@ -96,9 +96,9 @@ static TString* LoadString (lua_State* L, ZIO* Z, int swap)
return NULL;
else
{
char* s=luaO_openspace(L,size);
l_char* s=luaO_openspace(L,size);
LoadBlock(L,s,size,Z,0);
return luaS_newlstr(L,s,size-1); /* remove trailing '\0' */
return luaS_newlstr(L,s,size-1); /* remove trailing l_c('\0') */
}
}
@@ -171,18 +171,18 @@ static Proto* LoadFunction (lua_State* L, ZIO* Z, int swap)
static void LoadSignature (lua_State* L, ZIO* Z)
{
const char* s=SIGNATURE;
const l_char* s=SIGNATURE;
while (*s!=0 && ezgetc(L,Z)==*s)
++s;
if (*s!=0) luaO_verror(L,"bad signature in `%.99s'",ZNAME(Z));
if (*s!=0) luaO_verror(L,l_s("bad signature in `%.99s'"),ZNAME(Z));
}
static void TestSize (lua_State* L, int s, const char* what, ZIO* Z)
static void TestSize (lua_State* L, int s, const l_char* what, ZIO* Z)
{
int r=ezgetc(L,Z);
if (r!=s)
luaO_verror(L,"virtual machine mismatch in `%.99s':\n"
" %.20s is %d but read %d",ZNAME(Z),what,s,r);
luaO_verror(L,l_s("virtual machine mismatch in `%.99s':\n")
l_s(" %.20s is %d but read %d"),ZNAME(Z),what,s,r);
}
#define TESTSIZE(s) TestSize(L,s,#s,Z)
@@ -195,12 +195,12 @@ static int LoadHeader (lua_State* L, ZIO* Z)
LoadSignature(L,Z);
version=ezgetc(L,Z);
if (version>VERSION)
luaO_verror(L,"`%.99s' too new:\n"
" read version %d.%d; expected at most %d.%d",
luaO_verror(L,l_s("`%.99s' too new:\n")
l_s(" read version %d.%d; expected at most %d.%d"),
ZNAME(Z),V(version),V(VERSION));
if (version<VERSION0) /* check last major change */
luaO_verror(L,"`%.99s' too old:\n"
" read version %d.%d; expected at least %d.%d",
luaO_verror(L,l_s("`%.99s' too old:\n")
l_s(" read version %d.%d; expected at least %d.%d"),
ZNAME(Z),V(version),V(VERSION));
swap=(luaU_endianess()!=ezgetc(L,Z)); /* need to swap bytes? */
TESTSIZE(sizeof(int));
@@ -212,8 +212,8 @@ static int LoadHeader (lua_State* L, ZIO* Z)
TESTSIZE(sizeof(lua_Number));
f=LoadNumber(L,Z,swap);
if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */
luaO_verror(L,"unknown number format in `%.99s':\n"
" read " NUMBER_FMT "; expected " NUMBER_FMT, ZNAME(Z),f,tf);
luaO_verror(L,l_s("unknown number format in `%.99s':\n")
l_s(" read ") NUMBER_FMT l_s("; expected ") NUMBER_FMT, ZNAME(Z),f,tf);
return swap;
}
@@ -234,7 +234,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z)
tf=LoadChunk(L,Z);
c=zgetc(Z);
if (c!=EOZ)
luaO_verror(L,"`%.99s' apparently contains more than one chunk",ZNAME(Z));
luaO_verror(L,l_s("`%.99s' apparently contains more than one chunk"),ZNAME(Z));
return tf;
}
@@ -244,5 +244,5 @@ Proto* luaU_undump (lua_State* L, ZIO* Z)
int luaU_endianess (void)
{
int x=1;
return *(char*)&x;
return *(l_char*)&x;
}