Roberto Ierusalimschy 26 年之前
父节点
当前提交
c8d219798a
共有 1 个文件被更改,包括 15 次插入17 次删除
  1. 15 17
      lundump.c

+ 15 - 17
lundump.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lundump.c,v 1.18 1999/04/09 03:10:40 lhf Exp lhf $
+** $Id: lundump.c,v 1.19 1999/04/15 12:30:03 lhf Exp lhf $
 ** load bytecodes from files
 ** load bytecodes from files
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -15,12 +15,6 @@
 
 
 #define	LoadBlock(b,size,Z)	ezread(Z,b,size)
 #define	LoadBlock(b,size,Z)	ezread(Z,b,size)
 
 
-#if LUAC_NATIVE
-	#define doLoadNumber(x,Z)	LoadBlock(&x,sizeof(x),Z)
-#else
-	#define doLoadNumber(x,Z)	x=LoadNumber(Z)
-#endif
-
 static void unexpectedEOZ (ZIO* Z)
 static void unexpectedEOZ (ZIO* Z)
 {
 {
  luaL_verror("unexpected end of file in %s",zname(Z));
  luaL_verror("unexpected end of file in %s",zname(Z));
@@ -55,6 +49,11 @@ static unsigned long LoadLong (ZIO* Z)
 
 
 static real LoadNumber (ZIO* Z)
 static real LoadNumber (ZIO* Z)
 {
 {
+#ifdef LUAC_NATIVE
+ real x;
+ LoadBlock(&x,sizeof(x),Z);
+ return x;
+#else
  char b[256];
  char b[256];
  int size=ezgetc(Z);
  int size=ezgetc(Z);
  LoadBlock(b,size,Z);
  LoadBlock(b,size,Z);
@@ -62,7 +61,8 @@ static real LoadNumber (ZIO* Z)
  if (b[0]=='-')
  if (b[0]=='-')
   return -luaO_str2d(b+1);
   return -luaO_str2d(b+1);
  else
  else
-  return luaO_str2d(b);
+  return  luaO_str2d(b);
+#endif
 }
 }
 
 
 static int LoadInt (ZIO* Z, char* message)
 static int LoadInt (ZIO* Z, char* message)
@@ -127,7 +127,7 @@ static void LoadConstants (TProtoFunc* tf, ZIO* Z)
   switch (ttype(o))
   switch (ttype(o))
   {
   {
    case LUA_T_NUMBER:
    case LUA_T_NUMBER:
-	doLoadNumber(nvalue(o),Z);
+	nvalue(o)=LoadNumber(Z);
 	break;
 	break;
    case LUA_T_STRING:
    case LUA_T_STRING:
 	tsvalue(o)=LoadTString(Z);
 	tsvalue(o)=LoadTString(Z);
@@ -178,10 +178,9 @@ static void LoadHeader (ZIO* Z)
 	"%s too old: version=0x%02x; expected at least 0x%02x",
 	"%s too old: version=0x%02x; expected at least 0x%02x",
 	zname(Z),version,VERSION0);
 	zname(Z),version,VERSION0);
  sizeofR=ezgetc(Z);			/* test number representation */
  sizeofR=ezgetc(Z);			/* test number representation */
-#if LUAC_NATIVE
+#ifdef LUAC_NATIVE
  if (sizeofR==0)
  if (sizeofR==0)
-  luaL_verror("cannot read numbers in %s: "
-	"support for decimal format not enabled",
+  luaL_verror("cannot read numbers in %s: no support for decimal format",
 	zname(Z));
 	zname(Z));
  if (sizeofR!=sizeof(real))
  if (sizeofR!=sizeof(real))
   luaL_verror("unknown number size in %s: read %d; expected %d",
   luaL_verror("unknown number size in %s: read %d; expected %d",
@@ -189,16 +188,15 @@ static void LoadHeader (ZIO* Z)
  else
  else
  {
  {
  real f=-TEST_NUMBER,tf=TEST_NUMBER;
  real f=-TEST_NUMBER,tf=TEST_NUMBER;
- doLoadNumber(f,Z);
- if (f!=tf)
-  luaL_verror("unknown number representation in %s: "
+ f=LoadNumber(Z);
+ if ((long)f!=(long)tf)
+  luaL_verror("unknown number format in %s: "
 	"read " NUMBER_FMT "; expected " NUMBER_FMT,
 	"read " NUMBER_FMT "; expected " NUMBER_FMT,
 	zname(Z),f,tf);
 	zname(Z),f,tf);
  }
  }
 #else
 #else
  if (sizeofR!=0)
  if (sizeofR!=0)
-  luaL_verror("cannot read numbers in %s: "
-	"support for native format not enabled",
+  luaL_verror("cannot read numbers in %s: no support for native format",
 	zname(Z));
 	zname(Z));
 #endif
 #endif
 }
 }