Bläddra i källkod

janitor work on casts

Roberto Ierusalimschy 7 år sedan
förälder
incheckning
e2b15aa21d
18 ändrade filer med 83 tillägg och 76 borttagningar
  1. 4 4
      lapi.c
  2. 2 2
      lcode.c
  3. 2 2
      ldebug.h
  4. 5 5
      lfunc.h
  5. 2 2
      lgc.c
  6. 3 3
      lgc.h
  7. 2 2
      llex.c
  8. 2 2
      llex.h
  9. 7 2
      llimits.h
  10. 5 5
      lmem.c
  11. 8 6
      lmem.h
  12. 8 8
      lobject.c
  13. 4 4
      lobject.h
  14. 6 6
      lopcodes.h
  15. 3 3
      lstate.c
  16. 2 2
      lstring.c
  17. 5 5
      ltable.c
  18. 13 13
      ltests.c

+ 4 - 4
lapi.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 2.279 2017/12/08 17:28:25 roberto Exp roberto $
+** $Id: lapi.c,v 2.280 2018/01/10 12:02:35 roberto Exp roberto $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -439,7 +439,7 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) {
     case LUA_TTABLE: return hvalue(o);
     case LUA_TLCL: return clLvalue(o);
     case LUA_TCCL: return clCvalue(o);
-    case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));
+    case LUA_TLCF: return cast_voidp(cast_sizet(fvalue(o)));
     case LUA_TTHREAD: return thvalue(o);
     case LUA_TUSERDATA: return getudatamem(uvalue(o));
     case LUA_TLIGHTUSERDATA: return pvalue(o);
@@ -685,7 +685,7 @@ LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) {
   lua_lock(L);
   t = index2value(L, idx);
   api_check(L, ttistable(t), "table expected");
-  setpvalue(&k, cast(void *, p));
+  setpvalue(&k, cast_voidp(p));
   setobj2s(L, L->top, luaH_get(hvalue(t), &k));
   api_incr_top(L);
   lua_unlock(L);
@@ -854,7 +854,7 @@ LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
   api_checknelems(L, 1);
   o = index2value(L, idx);
   api_check(L, ttistable(o), "table expected");
-  setpvalue(&k, cast(void *, p));
+  setpvalue(&k, cast_voidp(p));
   slot = luaH_set(L, hvalue(o), &k);
   setobj2t(L, slot, s2v(L->top - 1));
   luaC_barrierback(L, hvalue(o), s2v(L->top - 1));

+ 2 - 2
lcode.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lcode.c,v 2.150 2018/01/18 16:24:31 roberto Exp roberto $
+** $Id: lcode.c,v 2.151 2018/01/27 16:56:33 roberto Exp roberto $
 ** Code generator for Lua
 ** See Copyright Notice in lua.h
 */
@@ -545,7 +545,7 @@ int luaK_stringK (FuncState *fs, TString *s) {
 */
 static int luaK_intK (FuncState *fs, lua_Integer n) {
   TValue k, o;
-  setpvalue(&k, cast(void*, cast(size_t, n)));
+  setpvalue(&k, cast_voidp(cast_sizet(n)));
   setivalue(&o, n);
   return addk(fs, &k, &o);
 }

+ 2 - 2
ldebug.h

@@ -1,5 +1,5 @@
 /*
-** $Id: ldebug.h,v 2.14 2015/05/22 17:45:56 roberto Exp roberto $
+** $Id: ldebug.h,v 2.15 2017/06/27 11:35:31 roberto Exp roberto $
 ** Auxiliary functions from Debug Interface module
 ** See Copyright Notice in lua.h
 */
@@ -11,7 +11,7 @@
 #include "lstate.h"
 
 
-#define pcRel(pc, p)	(cast(int, (pc) - (p)->code) - 1)
+#define pcRel(pc, p)	(cast_int((pc) - (p)->code) - 1)
 
 #define resethookcount(L)	(L->hookcount = L->basehookcount)
 

+ 5 - 5
lfunc.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lfunc.h,v 2.17 2017/05/04 13:32:01 roberto Exp roberto $
+** $Id: lfunc.h,v 2.18 2017/06/29 15:06:44 roberto Exp roberto $
 ** Auxiliary functions to manipulate prototypes and closures
 ** See Copyright Notice in lua.h
 */
@@ -11,11 +11,11 @@
 #include "lobject.h"
 
 
-#define sizeCclosure(n)	(cast(int, sizeof(CClosure)) + \
-                         cast(int, sizeof(TValue)*((n)-1)))
+#define sizeCclosure(n)	(cast_int(sizeof(CClosure)) + \
+                         cast_int(sizeof(TValue)*((n)-1)))
 
-#define sizeLclosure(n)	(cast(int, sizeof(LClosure)) + \
-                         cast(int, sizeof(TValue *)*((n)-1)))
+#define sizeLclosure(n)	(cast_int(sizeof(LClosure)) + \
+                         cast_int(sizeof(TValue *)*((n)-1)))
 
 
 /* test whether thread is in 'twups' list */

+ 2 - 2
lgc.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lgc.c,v 2.243 2017/12/20 14:58:05 roberto Exp roberto $
+** $Id: lgc.c,v 2.244 2017/12/28 15:42:57 roberto Exp roberto $
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 */
@@ -107,7 +107,7 @@ static lu_mem atomic (lua_State *L);
 /*
 ** one after last element in a hash array
 */
-#define gnodelast(h)	gnode(h, cast(size_t, sizenode(h)))
+#define gnodelast(h)	gnode(h, cast_sizet(sizenode(h)))
 
 
 /*

+ 3 - 3
lgc.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lgc.h,v 2.98 2017/05/26 19:14:29 roberto Exp roberto $
+** $Id: lgc.h,v 2.99 2017/10/11 12:38:45 roberto Exp roberto $
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 */
@@ -57,7 +57,7 @@
 /*
 ** some useful bit tricks
 */
-#define resetbits(x,m)		((x) &= cast(lu_byte, ~(m)))
+#define resetbits(x,m)		((x) &= cast_byte(~(m)))
 #define setbits(x,m)		((x) |= (m))
 #define testbits(x,m)		((x) & (m))
 #define bitmask(b)		(1<<(b))
@@ -95,7 +95,7 @@
 #define changewhite(x)	((x)->marked ^= WHITEBITS)
 #define gray2black(x)	l_setbit((x)->marked, BLACKBIT)
 
-#define luaC_white(g)	cast(lu_byte, (g)->currentwhite & WHITEBITS)
+#define luaC_white(g)	cast_byte((g)->currentwhite & WHITEBITS)
 
 
 /* object age in generational mode */

+ 2 - 2
llex.c

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.c,v 2.97 2017/06/09 16:48:44 roberto Exp roberto $
+** $Id: llex.c,v 2.98 2017/06/29 15:06:44 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -63,7 +63,7 @@ static void save (LexState *ls, int c) {
     newsize = luaZ_sizebuffer(b) * 2;
     luaZ_resizebuffer(ls->L, b, newsize);
   }
-  b->buffer[luaZ_bufflen(b)++] = cast(char, c);
+  b->buffer[luaZ_bufflen(b)++] = cast_char(c);
 }
 
 

+ 2 - 2
llex.h

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.h,v 1.78 2014/10/29 15:38:24 roberto Exp roberto $
+** $Id: llex.h,v 1.79 2016/05/02 14:02:12 roberto Exp roberto $
 ** Lexical Analyzer
 ** See Copyright Notice in lua.h
 */
@@ -37,7 +37,7 @@ enum RESERVED {
 };
 
 /* number of reserved words */
-#define NUM_RESERVED	(cast(int, TK_WHILE-FIRST_RESERVED+1))
+#define NUM_RESERVED	(cast_int(TK_WHILE-FIRST_RESERVED + 1))
 
 
 typedef union {

+ 7 - 2
llimits.h

@@ -1,5 +1,5 @@
 /*
-** $Id: llimits.h,v 1.147 2017/12/11 18:53:53 roberto Exp roberto $
+** $Id: llimits.h,v 1.148 2017/12/28 11:51:00 roberto Exp roberto $
 ** Limits, basic types, and some other 'installation-dependent' definitions
 ** See Copyright Notice in lua.h
 */
@@ -104,10 +104,15 @@ typedef LUAI_UACINT l_uacInt;
 #define cast(t, exp)	((t)(exp))
 
 #define cast_void(i)	cast(void, (i))
-#define cast_byte(i)	cast(lu_byte, (i))
+#define cast_voidp(i)	cast(void *, (i))
 #define cast_num(i)	cast(lua_Number, (i))
 #define cast_int(i)	cast(int, (i))
+#define cast_uint(i)	cast(unsigned int, (i))
+#define cast_byte(i)	cast(lu_byte, (i))
 #define cast_uchar(i)	cast(unsigned char, (i))
+#define cast_char(i)	cast(char, (i))
+#define cast_charp(i)	cast(char *, (i))
+#define cast_sizet(i)	cast(size_t, (i))
 
 
 /* cast a signed lua_Integer to lua_Unsigned */

+ 5 - 5
lmem.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lmem.c,v 1.94 2017/12/08 17:28:25 roberto Exp roberto $
+** $Id: lmem.c,v 1.95 2017/12/11 12:27:48 roberto Exp roberto $
 ** Interface to Memory Manager
 ** See Copyright Notice in lua.h
 */
@@ -71,8 +71,8 @@ void *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize,
   }
   lua_assert(nelems + 1 <= size && size <= limit);
   /* 'limit' ensures that multiplication will not overflow */
-  newblock = luaM_realloc_(L, block, cast(size_t, *psize) * size_elems,
-                                     cast(size_t, size) * size_elems);
+  newblock = luaM_realloc_(L, block, cast_sizet(*psize) * size_elems,
+                                     cast_sizet(size) * size_elems);
   if (newblock == NULL)
     luaM_error(L);
   *psize = size;  /* update only when everything else is OK */
@@ -84,8 +84,8 @@ void *luaM_shrinkvector_ (lua_State *L, void *block, int *size,
                           int final_n, int size_elem) {
   global_State *g = G(L);
   void *newblock;
-  size_t oldsize = cast(size_t, (*size) * size_elem);
-  size_t newsize = cast(size_t, final_n * size_elem);
+  size_t oldsize = cast_sizet((*size) * size_elem);
+  size_t newsize = cast_sizet(final_n * size_elem);
   lua_assert(newsize <= oldsize);
   newblock = (*g->frealloc)(g->ud, block, oldsize, newsize);
   if (newblock == NULL && final_n > 0)  /* allocation failed? */

+ 8 - 6
lmem.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lmem.h,v 1.45 2017/12/07 18:59:52 roberto Exp roberto $
+** $Id: lmem.h,v 1.46 2017/12/08 17:28:25 roberto Exp roberto $
 ** Interface to Memory Manager
 ** See Copyright Notice in lua.h
 */
@@ -29,7 +29,7 @@
 ** avoiding this warning but also this optimization.)
 */
 #define luaM_testsize(n,e)  \
-	(sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e))
+	(sizeof(n) >= sizeof(size_t) && cast_sizet((n)) + 1 > MAX_SIZET/(e))
 
 #define luaM_checksize(L,n,e)  \
 	(luaM_testsize(n,e) ? luaM_toobig(L) : cast_void(0))
@@ -42,13 +42,15 @@
 ** 'int' or 'unsigned int' and that 'int' is not larger than 'size_t'.)
 */
 #define luaM_limitN(n,t)  \
-  ((cast(size_t, n) > MAX_SIZET/sizeof(t)) ? (MAX_SIZET/sizeof(t)) : (n))
+  ((cast_sizet(n) <= MAX_SIZET/sizeof(t)) ? (n) :  \
+     cast_uint((MAX_SIZET/sizeof(t))))
+
 
 /*
 ** Arrays of chars do not need any test
 */
 #define luaM_reallocvchar(L,b,on,n)  \
-  cast(char *, luaM_saferealloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char)))
+  cast_charp(luaM_saferealloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char)))
 
 #define luaM_freemem(L, b, s)	luaM_free_(L, (b), (s))
 #define luaM_free(L, b)		luaM_free_(L, (b), sizeof(*(b)))
@@ -66,8 +68,8 @@
                          luaM_limitN(limit,t),e)))
 
 #define luaM_reallocvector(L, v,oldn,n,t) \
-   (cast(t *, luaM_realloc_(L, v, cast(size_t, oldn) * sizeof(t), \
-                                  cast(size_t, n) * sizeof(t))))
+   (cast(t *, luaM_realloc_(L, v, cast_sizet(oldn) * sizeof(t), \
+                                  cast_sizet(n) * sizeof(t))))
 
 #define luaM_shrinkvector(L,v,size,fs,t) \
    ((v)=cast(t *, luaM_shrinkvector_(L, v, &(size), fs, sizeof(t))))

+ 8 - 8
lobject.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.c,v 2.121 2017/11/23 19:29:04 roberto Exp roberto $
+** $Id: lobject.c,v 2.122 2017/12/30 20:46:18 roberto Exp roberto $
 ** Some generic functions over Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -204,7 +204,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
   int e = 0;  /* exponent correction */
   int neg;  /* 1 if number is negative */
   int hasdot = 0;  /* true after seen a dot */
-  *endptr = cast(char *, s);  /* nothing is valid yet */
+  *endptr = cast_charp(s);  /* nothing is valid yet */
   while (lisspace(cast_uchar(*s))) s++;  /* skip initial spaces */
   neg = isneg(&s);  /* check sign */
   if (!(*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X')))  /* check '0x' */
@@ -226,7 +226,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
   }
   if (nosigdig + sigdig == 0)  /* no digits? */
     return 0.0;  /* invalid format */
-  *endptr = cast(char *, s);  /* valid up to here */
+  *endptr = cast_charp(s);  /* valid up to here */
   e *= 4;  /* each digit multiplies/divides value by 2^4 */
   if (*s == 'p' || *s == 'P') {  /* exponent part? */
     int exp1 = 0;  /* exponent value */
@@ -239,7 +239,7 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
       exp1 = exp1 * 10 + *(s++) - '0';
     if (neg1) exp1 = -exp1;
     e += exp1;
-    *endptr = cast(char *, s);  /* valid up to here */
+    *endptr = cast_charp(s);  /* valid up to here */
   }
   if (neg) r = -r;
   return l_mathop(ldexp)(r, e);
@@ -353,15 +353,15 @@ int luaO_utf8esc (char *buff, unsigned long x) {
   int n = 1;  /* number of bytes put in buffer (backwards) */
   lua_assert(x <= 0x10FFFF);
   if (x < 0x80)  /* ascii? */
-    buff[UTF8BUFFSZ - 1] = cast(char, x);
+    buff[UTF8BUFFSZ - 1] = cast_char(x);
   else {  /* need continuation bytes */
     unsigned int mfb = 0x3f;  /* maximum that fits in first byte */
     do {  /* add continuation bytes */
-      buff[UTF8BUFFSZ - (n++)] = cast(char, 0x80 | (x & 0x3f));
+      buff[UTF8BUFFSZ - (n++)] = cast_char(0x80 | (x & 0x3f));
       x >>= 6;  /* remove added bits */
       mfb >>= 1;  /* now there is one less bit available in first byte */
     } while (x > mfb);  /* still needs continuation byte? */
-    buff[UTF8BUFFSZ - n] = cast(char, (~mfb << 1) | x);  /* add first byte */
+    buff[UTF8BUFFSZ - n] = cast_char((~mfb << 1) | x);  /* add first byte */
   }
   return n;
 }
@@ -417,7 +417,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
         break;
       }
       case 'c': {  /* an 'int' as a character */
-        char buff = cast(char, va_arg(argp, int));
+        char buff = cast_char(va_arg(argp, int));
         if (lisprint(cast_uchar(buff)))
           pushstr(L, &buff, 1);
         else  /* non-printable character; print its code */

+ 4 - 4
lobject.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.h,v 2.131 2017/11/23 19:29:04 roberto Exp roberto $
+** $Id: lobject.h,v 2.132 2018/01/28 12:07:53 roberto Exp roberto $
 ** Type definitions for Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -351,7 +351,7 @@ typedef union UTString {
 ** (Access to 'extra' ensures that value is really a 'TString'.)
 */
 #define getstr(ts)  \
-  check_exp(sizeof((ts)->extra), cast(char *, (ts)) + sizeof(UTString))
+  check_exp(sizeof((ts)->extra), cast_charp((ts)) + sizeof(UTString))
 
 
 /* get the actual string (array of bytes) from a Lua value */
@@ -391,7 +391,7 @@ typedef union UUdata {
 ** (Access to 'ttuv_' ensures that value is really a 'Udata'.)
 */
 #define getudatamem(u)  \
-  check_exp(sizeof((u)->ttuv_), (cast(char*, (u)) + sizeof(UUdata)))
+  check_exp(sizeof((u)->ttuv_), (cast_charp(u) + sizeof(UUdata)))
 
 #define setuservalue(L,u,o) \
 	{ const TValue *io=(o); Udata *iu = (u); \
@@ -607,7 +607,7 @@ typedef struct Table {
 ** 'module' operation for hashing (size is always a power of 2)
 */
 #define lmod(s,size) \
-	(check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))
+	(check_exp((size&(size-1))==0, (cast_int((s) & ((size)-1)))))
 
 
 #define twoto(x)	(1<<(x))

+ 6 - 6
lopcodes.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lopcodes.h,v 1.182 2018/01/09 11:24:12 roberto Exp roberto $
+** $Id: lopcodes.h,v 1.183 2018/01/27 16:56:33 roberto Exp roberto $
 ** Opcodes for Lua virtual machine
 ** See Copyright Notice in lua.h
 */
@@ -111,7 +111,7 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ};  /* basic instruction formats */
 #define checkopm(i,m)	(getOpMode(GET_OPCODE(i)) == m)
 
 
-#define getarg(i,pos,size)	(cast(int, ((i)>>(pos)) & MASK1(size,0)))
+#define getarg(i,pos,size)	(cast_int(((i)>>(pos)) & MASK1(size,0)))
 #define setarg(i,v,pos,size)	((i) = (((i)&MASK0(size,pos)) | \
                 ((cast(Instruction, v)<<pos)&MASK1(size,pos))))
 
@@ -126,7 +126,7 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ};  /* basic instruction formats */
 #define GETARG_sC(i)	(GETARG_C(i) - OFFSET_sC)
 #define SETARG_C(i,v)	setarg(i, v, POS_C, SIZE_C)
 
-#define TESTARG_k(i)	(cast(int, ((i) & (1u << POS_k))))
+#define TESTARG_k(i)	(cast_int(((i) & (1u << POS_k))))
 #define GETARG_k(i)	check_exp(checkopm(i, iABC), getarg(i, POS_k, 1))
 #define SETARG_k(i,v)	setarg(i, v, POS_k, 1)
 
@@ -138,12 +138,12 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ};  /* basic instruction formats */
 
 #define GETARG_sBx(i)  \
 	check_exp(checkopm(i, iAsBx), getarg(i, POS_Bx, SIZE_Bx) - OFFSET_sBx)
-#define SETARG_sBx(i,b)	SETARG_Bx((i),cast(unsigned int, (b)+OFFSET_sBx))
+#define SETARG_sBx(i,b)	SETARG_Bx((i),cast_uint((b)+OFFSET_sBx))
 
 #define GETARG_sJ(i)  \
 	check_exp(checkopm(i, isJ), getarg(i, POS_sJ, SIZE_sJ) - OFFSET_sJ)
 #define SETARG_sJ(i,j) \
-	setarg(i, cast(unsigned int, (j)+OFFSET_sJ), POS_sJ, SIZE_sJ)
+	setarg(i, cast_uint((j)+OFFSET_sJ), POS_sJ, SIZE_sJ)
 #define GETARG_m(i)	check_exp(checkopm(i, isJ), getarg(i, POS_m, 1))
 #define SETARG_m(i,m)	setarg(i, m, POS_m, 1)
 
@@ -292,7 +292,7 @@ OP_EXTRAARG/*	Ax	extra (larger) argument for previous opcode	*/
 } OpCode;
 
 
-#define NUM_OPCODES	(cast(int, OP_EXTRAARG) + 1)
+#define NUM_OPCODES	(cast_int(OP_EXTRAARG) + 1)
 
 
 

+ 3 - 3
lstate.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstate.c,v 2.148 2017/11/23 16:35:54 roberto Exp roberto $
+** $Id: lstate.c,v 2.149 2017/12/19 16:40:17 roberto Exp roberto $
 ** Global State
 ** See Copyright Notice in lua.h
 */
@@ -35,7 +35,7 @@
 */
 #if !defined(luai_makeseed)
 #include <time.h>
-#define luai_makeseed()		cast(unsigned int, time(NULL))
+#define luai_makeseed()		cast_uint(time(NULL))
 #endif
 
 
@@ -67,7 +67,7 @@ typedef struct LG {
 ** Layout Randomization (if present) to increase randomness..
 */
 #define addbuff(b,p,e) \
-  { size_t t = cast(size_t, e); \
+  { size_t t = cast_sizet(e); \
     memcpy(b + p, &t, sizeof(t)); p += sizeof(t); }
 
 static unsigned int makeseed (lua_State *L) {

+ 2 - 2
lstring.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstring.c,v 2.61 2017/12/12 11:52:35 roberto Exp roberto $
+** $Id: lstring.c,v 2.62 2017/12/18 13:00:57 roberto Exp roberto $
 ** String table (keeps all strings handled by Lua)
 ** See Copyright Notice in lua.h
 */
@@ -51,7 +51,7 @@ int luaS_eqlngstr (TString *a, TString *b) {
 
 
 unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) {
-  unsigned int h = seed ^ cast(unsigned int, l);
+  unsigned int h = seed ^ cast_uint(l);
   size_t step = (l >> LUAI_HASHLIMIT) + 1;
   for (; l >= step; l -= step)
     h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1]));

+ 5 - 5
ltable.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltable.c,v 2.129 2017/12/08 17:28:25 roberto Exp roberto $
+** $Id: ltable.c,v 2.130 2017/12/29 15:58:23 roberto Exp roberto $
 ** Lua tables (hash)
 ** See Copyright Notice in lua.h
 */
@@ -116,8 +116,8 @@ static int l_hashfloat (lua_Number n) {
     return 0;
   }
   else {  /* normal case */
-    unsigned int u = cast(unsigned int, i) + cast(unsigned int, ni);
-    return cast_int(u <= cast(unsigned int, INT_MAX) ? u : ~u);
+    unsigned int u = cast_uint(i) + cast_uint(ni);
+    return cast_int(u <= cast_uint(INT_MAX) ? u : ~u);
   }
 }
 #endif
@@ -213,7 +213,7 @@ static const TValue *getgeneric (Table *t, const TValue *key) {
 */
 static unsigned int arrayindex (lua_Integer k) {
   if (0 < k && l_castS2U(k) <= MAXASIZE)
-    return cast(unsigned int, k);  /* 'key' is an appropriate array index */
+    return cast_uint(k);  /* 'key' is an appropriate array index */
   else
     return 0;
 }
@@ -264,7 +264,7 @@ int luaH_next (lua_State *L, Table *t, StkId key) {
 
 static void freehash (lua_State *L, Table *t) {
   if (!isdummy(t))
-    luaM_freearray(L, t->node, cast(size_t, sizenode(t)));
+    luaM_freearray(L, t->node, cast_sizet(sizenode(t)));
 }
 
 

+ 13 - 13
ltests.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltests.c,v 2.239 2018/01/09 11:21:41 roberto Exp $
+** $Id: ltests.c,v 2.239 2018/01/09 11:24:12 roberto Exp roberto $
 ** Internal Module for Debugging of the Lua Implementation
 ** See Copyright Notice in lua.h
 */
@@ -110,7 +110,7 @@ static void freeblock (Memcontrol *mc, Header *block) {
     size_t size = block->d.size;
     int i;
     for (i = 0; i < MARKSIZE; i++)  /* check marks after block */
-      lua_assert(*(cast(char *, block + 1) + size + i) == MARK);
+      lua_assert(*(cast_charp(block + 1) + size + i) == MARK);
     mc->objcount[block->d.type]--;
     fillmem(block, sizeof(Header) + size + MARKSIZE);  /* erase block */
     free(block);  /* actually free block */
@@ -161,10 +161,10 @@ void *debug_realloc (void *ud, void *b, size_t oldsize, size_t size) {
       freeblock(mc, block);  /* erase (and check) old copy */
     }
     /* initialize new part of the block with something weird */
-    fillmem(cast(char *, newblock + 1) + commonsize, size - commonsize);
+    fillmem(cast_charp(newblock + 1) + commonsize, size - commonsize);
     /* initialize marks after block */
     for (i = 0; i < MARKSIZE; i++)
-      *(cast(char *, newblock + 1) + size + i) = MARK;
+      *(cast_charp(newblock + 1) + size + i) = MARK;
     newblock->d.size = size;
     newblock->d.type = type;
     mc->total += size;
@@ -919,8 +919,8 @@ static int upvalue (lua_State *L) {
 
 
 static int newuserdata (lua_State *L) {
-  size_t size = cast(size_t, luaL_checkinteger(L, 1));
-  char *p = cast(char *, lua_newuserdata(L, size));
+  size_t size = cast_sizet(luaL_checkinteger(L, 1));
+  char *p = cast_charp(lua_newuserdata(L, size));
   while (size--) *p++ = '\0';
   return 1;
 }
@@ -928,7 +928,7 @@ static int newuserdata (lua_State *L) {
 
 static int pushuserdata (lua_State *L) {
   lua_Integer u = luaL_checkinteger(L, 1);
-  lua_pushlightuserdata(L, cast(void *, cast(size_t, u)));
+  lua_pushlightuserdata(L, cast_voidp(cast_sizet(u)));
   return 1;
 }
 
@@ -959,7 +959,7 @@ static int s2d (lua_State *L) {
 
 static int d2s (lua_State *L) {
   double d = luaL_checknumber(L, 1);
-  lua_pushlstring(L, cast(char *, &d), sizeof(d));
+  lua_pushlstring(L, cast_charp(&d), sizeof(d));
   return 1;
 }
 
@@ -1277,7 +1277,7 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
     }
     else if EQ("func2num") {
       lua_CFunction func = lua_tocfunction(L1, getindex);
-      lua_pushnumber(L1, cast(size_t, func));
+      lua_pushnumber(L1, cast_sizet(func));
     }
     else if EQ("getfield") {
       int t = getindex;
@@ -1422,11 +1422,11 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
     }
     else if EQ("rawgetp") {
       int t = getindex;
-      lua_rawgetp(L1, t, cast(void *, cast(size_t, getnum)));
+      lua_rawgetp(L1, t, cast_voidp(cast_sizet(getnum)));
     }
     else if EQ("rawsetp") {
       int t = getindex;
-      lua_rawsetp(L1, t, cast(void *, cast(size_t, getnum)));
+      lua_rawsetp(L1, t, cast_voidp(cast_sizet(getnum)));
     }
     else if EQ("remove") {
       lua_remove(L1, getnum);
@@ -1511,7 +1511,7 @@ static struct X { int x; } x;
       lua_pushnumber(L1, lua_tonumber(L1, getindex));
     }
     else if EQ("topointer") {
-      lua_pushnumber(L1, cast(size_t, lua_topointer(L1, getindex)));
+      lua_pushnumber(L1, cast_sizet(lua_topointer(L1, getindex)));
     }
     else if EQ("tostring") {
       const char *s = lua_tostring(L1, getindex);
@@ -1725,7 +1725,7 @@ int luaB_opentests (lua_State *L) {
   lua_atpanic(L, &tpanic);
   atexit(checkfinalmem);
   lua_assert(lua_getallocf(L, &ud) == debug_realloc);
-  lua_assert(ud == cast(void *, &l_memcontrol));
+  lua_assert(ud == cast_voidp(&l_memcontrol));
   lua_setallocf(L, lua_getallocf(L, NULL), ud);
   luaL_newlib(L, tests_funcs);
   return 1;