Browse Source

new global macro 'LUA_MAXUNSIGNED'

Roberto Ierusalimschy 11 năm trước cách đây
mục cha
commit
ef789d4161
3 tập tin đã thay đổi với 6 bổ sung10 xóa
  1. 3 3
      lapi.c
  2. 1 5
      llimits.h
  3. 2 2
      lstrlib.c

+ 3 - 3
lapi.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lapi.c,v 2.201 2014/03/12 20:57:40 roberto Exp roberto $
+** $Id: lapi.c,v 2.202 2014/04/01 18:51:23 roberto Exp roberto $
 ** Lua API
 ** Lua API
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -381,7 +381,7 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) {
       break;
       break;
     }
     }
     case LUA_TNUMFLT: {  /* compute floor(n) % 2^(numbits in an integer) */
     case LUA_TNUMFLT: {  /* compute floor(n) % 2^(numbits in an integer) */
-      const lua_Number twop = cast_num(MAX_UINTEGER) + cast_num(1);  /* 2^n */
+      const lua_Number two2n = cast_num(LUA_MAXUNSIGNED) + cast_num(1);
       lua_Number n = fltvalue(o);  /* get value */
       lua_Number n = fltvalue(o);  /* get value */
       int neg = 0;
       int neg = 0;
       n = l_floor(n);  /* get its floor */
       n = l_floor(n);  /* get its floor */
@@ -389,7 +389,7 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) {
         neg = 1;
         neg = 1;
         n = -n;  /* make 'n' positive, so that 'fmod' is the same as '%' */
         n = -n;  /* make 'n' positive, so that 'fmod' is the same as '%' */
       }
       }
-      n = l_mathop(fmod)(n, twop);  /* n = n % 2^(numbits in an integer) */
+      n = l_mathop(fmod)(n, two2n);  /* n = n % 2^(numbits in an integer) */
       if (luai_numisnan(n))   /* not a number? */
       if (luai_numisnan(n))   /* not a number? */
         break;  /* not an integer, too */
         break;  /* not an integer, too */
       res = cast_unsigned(n);  /* 'n' now must fit in an unsigned */
       res = cast_unsigned(n);  /* 'n' now must fit in an unsigned */

+ 1 - 5
llimits.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: llimits.h,v 1.112 2014/04/11 19:02:16 roberto Exp roberto $
+** $Id: llimits.h,v 1.113 2014/04/11 19:56:04 roberto Exp roberto $
 ** Limits, basic types, and some other `installation-dependent' definitions
 ** Limits, basic types, and some other `installation-dependent' definitions
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -27,10 +27,6 @@ typedef LUAI_MEM l_mem;
 typedef unsigned char lu_byte;
 typedef unsigned char lu_byte;
 
 
 
 
-/* maximum value for a lua_Unsigned */
-#define MAX_UINTEGER	(((lua_Unsigned)LUA_MAXINTEGER << 1) + 1u)
-
-
 /* maximum value for size_t */
 /* maximum value for size_t */
 #define MAX_SIZET	((size_t)(~(size_t)0)-2)
 #define MAX_SIZET	((size_t)(~(size_t)0)-2)
 
 

+ 2 - 2
lstrlib.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lstrlib.c,v 1.193 2014/04/10 18:24:12 roberto Exp roberto $
+** $Id: lstrlib.c,v 1.194 2014/04/10 19:45:43 roberto Exp roberto $
 ** Standard library for string operations and pattern-matching
 ** Standard library for string operations and pattern-matching
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -1008,7 +1008,7 @@ static int dumpint (char *buff, lua_Unsigned n, int littleendian, int size) {
     /* OK if there are only zeros left in higher bytes,
     /* OK if there are only zeros left in higher bytes,
        or only ones left (excluding non-signal bits in last byte) */
        or only ones left (excluding non-signal bits in last byte) */
     return ((n & ~(lua_Integer)MC) == 0 ||
     return ((n & ~(lua_Integer)MC) == 0 ||
-            (n | SM) == (~(lua_Unsigned)0 >> ((size - 1) * NB)));
+            (n | SM) == (LUA_MAXUNSIGNED >> ((size - 1) * NB)));
   }
   }
   else return 1;  /* no overflow can occur with full size */
   else return 1;  /* no overflow can occur with full size */
 }
 }