From e2b15aa21d2f31ccc93e35f50928e26a8d9c84ce Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Sun, 28 Jan 2018 13:13:26 -0200 Subject: [PATCH] janitor work on casts --- lapi.c | 8 ++++---- lcode.c | 4 ++-- ldebug.h | 4 ++-- lfunc.h | 10 +++++----- lgc.c | 4 ++-- lgc.h | 6 +++--- llex.c | 4 ++-- llex.h | 4 ++-- llimits.h | 9 +++++++-- lmem.c | 10 +++++----- lmem.h | 14 ++++++++------ lobject.c | 16 ++++++++-------- lobject.h | 8 ++++---- lopcodes.h | 12 ++++++------ lstate.c | 6 +++--- lstring.c | 4 ++-- ltable.c | 10 +++++----- ltests.c | 26 +++++++++++++------------- 18 files changed, 83 insertions(+), 76 deletions(-) diff --git a/lapi.c b/lapi.c index 142baf6a..3d148e09 100644 --- a/lapi.c +++ b/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)); diff --git a/lcode.c b/lcode.c index 7e573f02..7f240580 100644 --- a/lcode.c +++ b/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); } diff --git a/ldebug.h b/ldebug.h index 9062f4bd..e8652d84 100644 --- a/ldebug.h +++ b/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) diff --git a/lfunc.h b/lfunc.h index b7d75869..dbda3fdf 100644 --- a/lfunc.h +++ b/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 */ diff --git a/lgc.c b/lgc.c index d02dc031..7b223bcb 100644 --- a/lgc.c +++ b/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))) /* diff --git a/lgc.h b/lgc.h index 5113e922..fa53f13d 100644 --- a/lgc.h +++ b/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 */ diff --git a/llex.c b/llex.c index eaa400fa..be775146 100644 --- a/llex.c +++ b/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); } diff --git a/llex.h b/llex.h index a50b6873..9f23bd89 100644 --- a/llex.h +++ b/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 { diff --git a/llimits.h b/llimits.h index a9295645..9a3ae8d0 100644 --- a/llimits.h +++ b/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 */ diff --git a/lmem.c b/lmem.c index ecafef49..2c1757f5 100644 --- a/lmem.c +++ b/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? */ diff --git a/lmem.h b/lmem.h index e98aabdb..f87c9132 100644 --- a/lmem.h +++ b/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)))) diff --git a/lobject.c b/lobject.c index c7d4c06a..d5e9c1ce 100644 --- a/lobject.c +++ b/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 */ diff --git a/lobject.h b/lobject.h index 6541dea4..01bd39fa 100644 --- a/lobject.h +++ b/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)) diff --git a/lopcodes.h b/lopcodes.h index 2f4a48fa..1e3974d9 100644 --- a/lopcodes.h +++ b/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)< -#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) { diff --git a/lstring.c b/lstring.c index 60d4702d..f22ac5b8 100644 --- a/lstring.c +++ b/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])); diff --git a/ltable.c b/ltable.c index 419f9f6c..a8929961 100644 --- a/ltable.c +++ b/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))); } diff --git a/ltests.c b/ltests.c index 569c1896..24753d5f 100644 --- a/ltests.c +++ b/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;