better syntax for type casts

This commit is contained in:
Roberto Ierusalimschy
2001-08-31 16:46:07 -03:00
parent 7651a5c6b2
commit e1d072571e
26 changed files with 148 additions and 141 deletions

10
lapi.c
View File

@@ -544,8 +544,8 @@ LUA_API int lua_dostring (lua_State *L, const l_char *str) {
*/ */
/* GC values are expressed in Kbytes: #bytes/2^10 */ /* GC values are expressed in Kbytes: #bytes/2^10 */
#define GCscale(x) ((int)((x)>>10)) #define GCscale(x) (cast(int, (x)>>10))
#define GCunscale(x) ((lu_mem)(x)<<10) #define GCunscale(x) (cast(lu_mem, (x)<<10))
LUA_API int lua_getgcthreshold (lua_State *L) { LUA_API int lua_getgcthreshold (lua_State *L) {
int threshold; int threshold;
@@ -602,7 +602,7 @@ LUA_API int lua_name2tag (lua_State *L, const l_char *name) {
tag = LUA_TNONE; tag = LUA_TNONE;
else { else {
lua_assert(ttype(v) == LUA_TNUMBER); lua_assert(ttype(v) == LUA_TNUMBER);
tag = (int)nvalue(v); tag = cast(int, nvalue(v));
} }
lua_unlock(L); lua_unlock(L);
return tag; return tag;
@@ -695,7 +695,7 @@ LUA_API int lua_getn (lua_State *L, int index) {
api_check(L, ttype(t) == LUA_TTABLE); api_check(L, ttype(t) == LUA_TTABLE);
value = luaH_getstr(hvalue(t), luaS_newliteral(L, l_s("n"))); /* = t.n */ value = luaH_getstr(hvalue(t), luaS_newliteral(L, l_s("n"))); /* = t.n */
if (ttype(value) == LUA_TNUMBER) if (ttype(value) == LUA_TNUMBER)
n = (int)nvalue(value); n = cast(int, nvalue(value));
else { else {
lua_Number max = 0; lua_Number max = 0;
int i = hvalue(t)->size; int i = hvalue(t)->size;
@@ -707,7 +707,7 @@ LUA_API int lua_getn (lua_State *L, int index) {
max = nvalue(key(nd)); max = nvalue(key(nd));
nd++; nd++;
} }
n = (int)max; n = cast(int, max);
} }
lua_unlock(L); lua_unlock(L);
return n; return n;

View File

@@ -141,7 +141,7 @@ static int luaB_getglobal (lua_State *L) {
static int gettag (lua_State *L, int narg) { static int gettag (lua_State *L, int narg) {
switch (lua_rawtag(L, narg)) { switch (lua_rawtag(L, narg)) {
case LUA_TNUMBER: case LUA_TNUMBER:
return (int)lua_tonumber(L, narg); return (int)(lua_tonumber(L, narg));
case LUA_TSTRING: { case LUA_TSTRING: {
const l_char *name = lua_tostring(L, narg); const l_char *name = lua_tostring(L, narg);
int tag = lua_name2tag(L, name); int tag = lua_name2tag(L, name);

10
lcode.c
View File

@@ -41,7 +41,7 @@ static Instruction previous_instruction (FuncState *fs) {
if (fs->pc > fs->lasttarget) /* no jumps to current position? */ if (fs->pc > fs->lasttarget) /* no jumps to current position? */
return fs->f->code[fs->pc-1]; /* returns previous instruction */ return fs->f->code[fs->pc-1]; /* returns previous instruction */
else else
return (Instruction)(-1);/* no optimizations after an invalid instruction */ return cast(Instruction, -1);/* invalid instruction avoids optimizations */
} }
@@ -203,7 +203,7 @@ void luaK_reserveregs (FuncState *fs, int n) {
if (fs->freereg > fs->f->maxstacksize) { if (fs->freereg > fs->f->maxstacksize) {
if (fs->freereg >= MAXSTACK) if (fs->freereg >= MAXSTACK)
luaK_error(fs->ls, l_s("function or expression too complex")); luaK_error(fs->ls, l_s("function or expression too complex"));
fs->f->maxstacksize = (short)fs->freereg; fs->f->maxstacksize = cast(short, fs->freereg);
} }
} }
@@ -225,8 +225,8 @@ static void freeexp (FuncState *fs, expdesc *e) {
static int addk (FuncState *fs, TObject *k) { static int addk (FuncState *fs, TObject *k) {
const TObject *index = luaH_get(fs->h, k); const TObject *index = luaH_get(fs->h, k);
if (ttype(index) == LUA_TNUMBER) { if (ttype(index) == LUA_TNUMBER) {
lua_assert(luaO_equalObj(&fs->f->k[(int)nvalue(index)], k)); lua_assert(luaO_equalObj(&fs->f->k[cast(int, nvalue(index))], k));
return (int)nvalue(index); return cast(int, nvalue(index));
} }
else { /* constant not found; create a new entry */ else { /* constant not found; create a new entry */
TObject o; TObject o;
@@ -329,7 +329,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
} }
case VNUMBER: { case VNUMBER: {
lua_Number f = e->u.n; lua_Number f = e->u.n;
int i = (int)f; int i = cast(int, f);
if ((lua_Number)i == f && -MAXARG_sBc <= i && i <= MAXARG_sBc) if ((lua_Number)i == f && -MAXARG_sBc <= i && i <= MAXARG_sBc)
luaK_codeAsBc(fs, OP_LOADINT, reg, i); /* f has a small int value */ luaK_codeAsBc(fs, OP_LOADINT, reg, i); /* f has a small int value */
else else

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ldblib.c,v 1.36 2001/03/26 14:31:49 roberto Exp roberto $ ** $Id: ldblib.c,v 1.37 2001/06/06 18:00:19 roberto Exp $
** Interface from Lua to its debug API ** Interface from Lua to its debug API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -37,7 +37,7 @@ static int getinfo (lua_State *L) {
const l_char *options = luaL_opt_string(L, 2, l_s("flnSu")); const l_char *options = luaL_opt_string(L, 2, l_s("flnSu"));
l_char buff[20]; l_char buff[20];
if (lua_isnumber(L, 1)) { if (lua_isnumber(L, 1)) {
if (!lua_getstack(L, (int)lua_tonumber(L, 1), &ar)) { if (!lua_getstack(L, (int)(lua_tonumber(L, 1)), &ar)) {
lua_pushnil(L); /* level out of range */ lua_pushnil(L); /* level out of range */
return 1; return 1;
} }

6
ldo.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ldo.c,v 1.137 2001/07/12 19:34:03 roberto Exp roberto $ ** $Id: ldo.c,v 1.138 2001/07/16 20:24:48 roberto Exp $
** Stack and Call structure of Lua ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -176,7 +176,7 @@ struct CallS { /* data to `f_call' */
}; };
static void f_call (lua_State *L, void *ud) { static void f_call (lua_State *L, void *ud) {
struct CallS *c = (struct CallS *)ud; struct CallS *c = cast(struct CallS *, ud);
luaD_call(L, c->func); luaD_call(L, c->func);
if (c->nresults != LUA_MULTRET) if (c->nresults != LUA_MULTRET)
luaD_adjusttop(L, c->func + c->nresults); luaD_adjusttop(L, c->func + c->nresults);
@@ -207,7 +207,7 @@ struct SParser { /* data to `f_parser' */
}; };
static void f_parser (lua_State *L, void *ud) { static void f_parser (lua_State *L, void *ud) {
struct SParser *p = (struct SParser *)ud; struct SParser *p = cast(struct SParser *, ud);
Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z); Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z);
luaV_Lclosure(L, tf, 0); luaV_Lclosure(L, tf, 0);
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lfunc.c,v 1.44 2001/06/05 18:17:01 roberto Exp roberto $ ** $Id: lfunc.c,v 1.45 2001/06/28 14:57:17 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures ** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -15,11 +15,12 @@
#include "lstate.h" #include "lstate.h"
#define sizeclosure(n) ((int)sizeof(Closure) + (int)sizeof(TObject)*((n)-1)) #define sizeclosure(n) (cast(int, sizeof(Closure)) + \
cast(int, sizeof(TObject)*((n)-1)))
Closure *luaF_newclosure (lua_State *L, int nelems) { Closure *luaF_newclosure (lua_State *L, int nelems) {
Closure *c = (Closure *)luaM_malloc(L, sizeclosure(nelems)); Closure *c = cast(Closure *, luaM_malloc(L, sizeclosure(nelems)));
c->next = G(L)->rootcl; c->next = G(L)->rootcl;
G(L)->rootcl = c; G(L)->rootcl = c;
c->mark = c; c->mark = c;

4
lgc.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lgc.c,v 1.108 2001/06/26 13:20:45 roberto Exp roberto $ ** $Id: lgc.c,v 1.109 2001/06/28 14:57:17 roberto Exp $
** Garbage Collector ** Garbage Collector
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -305,7 +305,7 @@ static void collectstrings (lua_State *L, int all) {
} }
} }
} }
if (G(L)->strt.nuse < (ls_nstr)(G(L)->strt.size/4) && if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) &&
G(L)->strt.size > MINPOWER2) G(L)->strt.size > MINPOWER2)
luaS_resize(L, G(L)->strt.size/2); /* table is too big */ luaS_resize(L, G(L)->strt.size/2); /* table is too big */
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: liolib.c,v 1.120 2001/07/16 18:48:31 roberto Exp roberto $ ** $Id: liolib.c,v 1.121 2001/07/22 00:59:36 roberto Exp $
** Standard I/O (and system) library ** Standard I/O (and system) library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -73,7 +73,7 @@ static int pushresult (lua_State *L, int i) {
static FILE *getopthandle (lua_State *L, int inout) { static FILE *getopthandle (lua_State *L, int inout) {
FILE *p = (FILE *)lua_touserdata(L, 1); FILE *p = (FILE *)(lua_touserdata(L, 1));
if (p != NULL) { /* is it a userdata ? */ if (p != NULL) { /* is it a userdata ? */
if (!checkfile(L, 1)) { /* not a valid file handle? */ if (!checkfile(L, 1)) { /* not a valid file handle? */
if (strcmp(lua_type(L, 1), CLOSEDFILEHANDLE) == 0) if (strcmp(lua_type(L, 1), CLOSEDFILEHANDLE) == 0)
@@ -88,7 +88,7 @@ static FILE *getopthandle (lua_State *L, int inout) {
if (!checkfile(L,-1)) if (!checkfile(L,-1))
luaL_verror(L, l_s("global variable `%.10s' is not a valid file handle"), luaL_verror(L, l_s("global variable `%.10s' is not a valid file handle"),
filenames[inout]); filenames[inout]);
p = (FILE *)lua_touserdata(L, -1); p = (FILE *)(lua_touserdata(L, -1));
} }
return p; /* leave handle at stack top to avoid GC */ return p; /* leave handle at stack top to avoid GC */
} }
@@ -127,7 +127,7 @@ static void resetfile (lua_State *L, int inout) {
static int io_close (lua_State *L) { static int io_close (lua_State *L) {
FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE); FILE *f = (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE));
int status = 1; int status = 1;
if (f != stdin && f != stdout && f != stderr) { if (f != stdin && f != stdout && f != stderr) {
lua_settop(L, 1); /* make sure file is on top */ lua_settop(L, 1); /* make sure file is on top */
@@ -139,7 +139,7 @@ static int io_close (lua_State *L) {
static int file_collect (lua_State *L) { static int file_collect (lua_State *L) {
FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE); FILE *f = (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE));
if (f != stdin && f != stdout && f != stderr) if (f != stdin && f != stdout && f != stderr)
CLOSEFILE(L, f); CLOSEFILE(L, f);
return 0; return 0;
@@ -328,7 +328,7 @@ static int io_read (lua_State *L) {
size_t pl = lua_strlen(L, n) - 2; size_t pl = lua_strlen(L, n) - 2;
luaL_arg_check(L, 0 < pl && pl <= LUA_MAXUNTIL, n, luaL_arg_check(L, 0 < pl && pl <= LUA_MAXUNTIL, n,
l_s("invalid read-until length")); l_s("invalid read-until length"));
success = read_until(L, f, p+2, (int)pl); success = read_until(L, f, p+2, (int)(pl));
break; break;
} }
default: default:
@@ -373,7 +373,7 @@ static int io_write (lua_State *L) {
static int io_seek (lua_State *L) { static int io_seek (lua_State *L) {
static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
static const l_char *const modenames[] = {l_s("set"), l_s("cur"), l_s("end"), NULL}; static const l_char *const modenames[] = {l_s("set"), l_s("cur"), l_s("end"), NULL};
FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE); FILE *f = (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE));
int op = luaL_findstring(luaL_opt_string(L, 2, l_s("cur")), modenames); int op = luaL_findstring(luaL_opt_string(L, 2, l_s("cur")), modenames);
long offset = luaL_opt_long(L, 3, 0); long offset = luaL_opt_long(L, 3, 0);
luaL_arg_check(L, op != -1, 2, l_s("invalid mode")); luaL_arg_check(L, op != -1, 2, l_s("invalid mode"));
@@ -388,8 +388,8 @@ static int io_seek (lua_State *L) {
static int io_flush (lua_State *L) { static int io_flush (lua_State *L) {
FILE *f = (lua_isnull(L, 1)) ? (FILE *)NULL : FILE *f = (lua_isnull(L, 1)) ? (FILE *)(NULL) :
(FILE *)luaL_check_userdata(L, 1, FILEHANDLE); (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE));
return pushresult(L, fflush(f) == 0); return pushresult(L, fflush(f) == 0);
} }
@@ -461,7 +461,7 @@ static int getfield (lua_State *L, const l_char *key, int d) {
lua_pushstring(L, key); lua_pushstring(L, key);
lua_rawget(L, -2); lua_rawget(L, -2);
if (lua_isnumber(L, -1)) if (lua_isnumber(L, -1))
res = (int)lua_tonumber(L, -1); res = (int)(lua_tonumber(L, -1));
else { else {
if (d == -2) if (d == -2)
luaL_verror(L, l_s("field `%.20s' missing in date table"), key); luaL_verror(L, l_s("field `%.20s' missing in date table"), key);
@@ -474,9 +474,9 @@ static int getfield (lua_State *L, const l_char *key, int d) {
static int io_date (lua_State *L) { static int io_date (lua_State *L) {
const l_char *s = luaL_opt_string(L, 1, l_s("%c")); const l_char *s = luaL_opt_string(L, 1, l_s("%c"));
time_t t = (time_t)luaL_opt_number(L, 2, -1); time_t t = (time_t)(luaL_opt_number(L, 2, -1));
struct tm *stm; struct tm *stm;
if (t == (time_t)-1) /* no time given? */ if (t == (time_t)(-1)) /* no time given? */
t = time(NULL); /* use current time */ t = time(NULL); /* use current time */
if (*s == l_c('!')) { /* UTC? */ if (*s == l_c('!')) { /* UTC? */
stm = gmtime(&t); stm = gmtime(&t);
@@ -525,7 +525,7 @@ static int io_time (lua_State *L) {
ts.tm_year = getfield(L, l_s("year"), -2)-1900; ts.tm_year = getfield(L, l_s("year"), -2)-1900;
ts.tm_isdst = getfield(L, l_s("isdst"), -1); ts.tm_isdst = getfield(L, l_s("isdst"), -1);
t = mktime(&ts); t = mktime(&ts);
if (t == (time_t)-1) if (t == (time_t)(-1))
lua_pushnil(L); lua_pushnil(L);
else else
lua_pushnumber(L, t); lua_pushnumber(L, t);
@@ -535,8 +535,8 @@ static int io_time (lua_State *L) {
static int io_difftime (lua_State *L) { static int io_difftime (lua_State *L) {
lua_pushnumber(L, difftime((time_t)luaL_check_number(L, 1), lua_pushnumber(L, difftime((time_t)(luaL_check_number(L, 1)),
(time_t)luaL_opt_number(L, 2, 0))); (time_t)(luaL_opt_number(L, 2, 0))));
return 1; return 1;
} }

14
llex.c
View File

@@ -41,7 +41,7 @@ void luaX_init (lua_State *L) {
for (i=0; i<NUM_RESERVED; i++) { for (i=0; i<NUM_RESERVED; i++) {
TString *ts = luaS_new(L, token2string[i]); TString *ts = luaS_new(L, token2string[i]);
lua_assert(strlen(token2string[i])+1 <= TOKEN_LEN); lua_assert(strlen(token2string[i])+1 <= TOKEN_LEN);
ts->tsv.marked = (unsigned short)(RESERVEDMARK+i); /* reserved word */ ts->tsv.marked = cast(unsigned short, RESERVEDMARK+i); /* reserved word */
} }
} }
@@ -71,7 +71,7 @@ void luaX_error (LexState *ls, const l_char *s, int token) {
l_char buff[TOKEN_LEN]; l_char buff[TOKEN_LEN];
luaX_token2str(token, buff); luaX_token2str(token, buff);
if (buff[0] == l_c('\0')) if (buff[0] == l_c('\0'))
luaX_syntaxerror(ls, s, (l_char *)G(ls->L)->Mbuffer); luaX_syntaxerror(ls, s, cast(l_char *, G(ls->L)->Mbuffer));
else else
luaX_syntaxerror(ls, s, buff); luaX_syntaxerror(ls, s, buff);
} }
@@ -134,7 +134,7 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source) {
if (((len)+(n))*sizeof(l_char) > G(L)->Mbuffsize) \ if (((len)+(n))*sizeof(l_char) > G(L)->Mbuffsize) \
luaO_openspace(L, (len)+(n)+EXTRABUFF, l_char) luaO_openspace(L, (len)+(n)+EXTRABUFF, l_char)
#define save(L, c, l) (((l_char *)G(L)->Mbuffer)[l++] = (l_char)c) #define save(L, c, l) (cast(l_char *, G(L)->Mbuffer)[l++] = (l_char)c)
#define save_and_next(L, LS, l) (save(L, LS->current, l), next(LS)) #define save_and_next(L, LS, l) (save(L, LS->current, l), next(LS))
@@ -185,7 +185,7 @@ static void read_number (LexState *LS, int comma, SemInfo *seminfo) {
} }
} }
save(L, l_c('\0'), l); save(L, l_c('\0'), l);
if (!luaO_str2d((l_char *)G(L)->Mbuffer, &seminfo->r)) if (!luaO_str2d(cast(l_char *, G(L)->Mbuffer), &seminfo->r))
luaX_error(LS, l_s("malformed number"), TK_NUMBER); luaX_error(LS, l_s("malformed number"), TK_NUMBER);
} }
@@ -231,7 +231,7 @@ static void read_long_string (LexState *LS, SemInfo *seminfo) {
} endloop: } endloop:
save_and_next(L, LS, l); /* skip the second `]' */ save_and_next(L, LS, l); /* skip the second `]' */
save(L, l_c('\0'), l); save(L, l_c('\0'), l);
seminfo->ts = luaS_newlstr(L, (l_char *)G(L)->Mbuffer+2, l-5); seminfo->ts = luaS_newlstr(L, cast(l_char *, G(L)->Mbuffer)+2, l-5);
} }
@@ -283,7 +283,7 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) {
} }
save_and_next(L, LS, l); /* skip delimiter */ save_and_next(L, LS, l); /* skip delimiter */
save(L, l_c('\0'), l); save(L, l_c('\0'), l);
seminfo->ts = luaS_newlstr(L, (l_char *)G(L)->Mbuffer+1, l-3); seminfo->ts = luaS_newlstr(L, cast(l_char *, G(L)->Mbuffer)+1, l-3);
} }
@@ -371,7 +371,7 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) {
else if (isalpha(LS->current) || LS->current == l_c('_')) { else if (isalpha(LS->current) || LS->current == l_c('_')) {
/* identifier or reserved word */ /* identifier or reserved word */
size_t l = readname(LS); size_t l = readname(LS);
TString *ts = luaS_newlstr(LS->L, (l_char *)G(LS->L)->Mbuffer, l); TString *ts = luaS_newlstr(LS->L, cast(l_char *, G(LS->L)->Mbuffer), l);
if (ts->tsv.marked >= RESERVEDMARK) /* reserved word? */ if (ts->tsv.marked >= RESERVEDMARK) /* reserved word? */
return ts->tsv.marked-RESERVEDMARK+FIRST_RESERVED; return ts->tsv.marked-RESERVEDMARK+FIRST_RESERVED;
seminfo->ts = ts; seminfo->ts = ts;

4
llex.h
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: llex.h,v 1.36 2001/06/20 21:07:57 roberto Exp roberto $ ** $Id: llex.h,v 1.37 2001/07/22 00:59:36 roberto Exp $
** Lexical Analyzer ** Lexical Analyzer
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -33,7 +33,7 @@ enum RESERVED {
}; };
/* number of reserved words */ /* number of reserved words */
#define NUM_RESERVED ((int)(TK_WHILE-FIRST_RESERVED+1)) #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
typedef union { typedef union {

7
lmem.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lmem.c,v 1.48 2001/02/23 17:17:25 roberto Exp roberto $ ** $Id: lmem.c,v 1.49 2001/03/26 14:31:49 roberto Exp $
** Interface to Memory Manager ** Interface to Memory Manager
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -34,8 +34,9 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elems,
newsize = limit; /* still have at least MINPOWER2 free places */ newsize = limit; /* still have at least MINPOWER2 free places */
else luaD_error(L, errormsg); else luaD_error(L, errormsg);
} }
newblock = luaM_realloc(L, block, (lu_mem)(*size)*(lu_mem)size_elems, newblock = luaM_realloc(L, block,
(lu_mem)newsize*(lu_mem)size_elems); cast(lu_mem, *size)*cast(lu_mem, size_elems),
cast(lu_mem, newsize)*cast(lu_mem, size_elems));
*size = newsize; /* update only when everything else is OK */ *size = newsize; /* update only when everything else is OK */
return newblock; return newblock;
} }

16
lmem.h
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lmem.h,v 1.21 2001/02/20 18:15:33 roberto Exp roberto $ ** $Id: lmem.h,v 1.22 2001/02/23 17:17:25 roberto Exp $
** Interface to Memory Manager ** Interface to Memory Manager
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -21,20 +21,20 @@ void *luaM_growaux (lua_State *L, void *block, int *size, int size_elem,
#define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0) #define luaM_free(L, b, s) luaM_realloc(L, (b), (s), 0)
#define luaM_freelem(L, b, t) luaM_realloc(L, (b), sizeof(t), 0) #define luaM_freelem(L, b, t) luaM_realloc(L, (b), sizeof(t), 0)
#define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \ #define luaM_freearray(L, b, n, t) luaM_realloc(L, (b), \
((lu_mem)(n)*(lu_mem)sizeof(t)), 0) cast(lu_mem, n)*cast(lu_mem, sizeof(t)), 0)
#define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t)) #define luaM_malloc(L, t) luaM_realloc(L, NULL, 0, (t))
#define luaM_new(L, t) ((t *)luaM_malloc(L, sizeof(t))) #define luaM_new(L, t) cast(t *, luaM_malloc(L, sizeof(t)))
#define luaM_newvector(L, n,t) ((t *)luaM_malloc(L, \ #define luaM_newvector(L, n,t) cast(t *, luaM_malloc(L, \
(lu_mem)(n)*(lu_mem)sizeof(t))) cast(lu_mem, n)*cast(lu_mem, sizeof(t))))
#define luaM_growvector(L,v,nelems,size,t,limit,e) \ #define luaM_growvector(L,v,nelems,size,t,limit,e) \
if (((nelems)+1) > (size)) \ if (((nelems)+1) > (size)) \
((v)=(t *)luaM_growaux(L,v,&(size),sizeof(t),limit,e)) ((v)=cast(t *, luaM_growaux(L,v,&(size),sizeof(t),limit,e)))
#define luaM_reallocvector(L, v,oldn,n,t) \ #define luaM_reallocvector(L, v,oldn,n,t) \
((v)=(t *)luaM_realloc(L, v,(lu_mem)(oldn)*(lu_mem)sizeof(t), \ ((v)=cast(t *, luaM_realloc(L, v,cast(lu_mem, oldn)*cast(lu_mem, sizeof(t)), \
(lu_mem)(n)*(lu_mem)sizeof(t))) cast(lu_mem, n)*cast(lu_mem, sizeof(t)))))
#endif #endif

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lobject.h,v 1.109 2001/06/28 14:56:25 roberto Exp roberto $ ** $Id: lobject.h,v 1.110 2001/08/27 15:16:28 roberto Exp $
** Type definitions for Lua objects ** Type definitions for Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -22,6 +22,10 @@
#endif #endif
#ifndef cast
#define cast(t, exp) ((t)(exp))
#endif
/* tags for values visible from Lua == first user-created tag */ /* tags for values visible from Lua == first user-created tag */
#define NUM_TAGS 6 #define NUM_TAGS 6
@@ -96,7 +100,7 @@ typedef union TString {
} TString; } TString;
#define getstr(ts) ((l_char *)((ts) + 1)) #define getstr(ts) cast(l_char *, (ts) + 1)
#define svalue(o) getstr(tsvalue(o)) #define svalue(o) getstr(tsvalue(o))
@@ -196,7 +200,7 @@ typedef struct Hash {
/* /*
** `module' operation for hashing (size is always a power of 2) ** `module' operation for hashing (size is always a power of 2)
*/ */
#define lmod(s,size) ((int)((s) & ((size)-1))) #define lmod(s,size) (cast(int, (s) & ((size)-1)))
/* /*
@@ -217,7 +221,7 @@ typedef struct CallInfo {
extern const TObject luaO_nilobject; extern const TObject luaO_nilobject;
#define luaO_openspace(L,n,t) ((t *)luaO_openspaceaux(L,(n)*sizeof(t))) #define luaO_openspace(L,n,t) cast(t *, luaO_openspaceaux(L,(n)*sizeof(t)))
void *luaO_openspaceaux (lua_State *L, size_t n); void *luaO_openspaceaux (lua_State *L, size_t n);
int luaO_equalObj (const TObject *t1, const TObject *t2); int luaO_equalObj (const TObject *t1, const TObject *t2);

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lopcodes.c,v 1.2 2001/07/03 17:02:02 roberto Exp roberto $ ** $Id: lopcodes.c,v 1.3 2001/08/27 15:14:57 roberto Exp $
** extracted automatically from lopcodes.h by mkprint.lua ** extracted automatically from lopcodes.h by mkprint.lua
** DO NOT EDIT ** DO NOT EDIT
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
@@ -9,6 +9,7 @@
#define LUA_PRIVATE #define LUA_PRIVATE
#include "lua.h" #include "lua.h"
#include "lobject.h"
#include "lopcodes.h" #include "lopcodes.h"

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lopcodes.h,v 1.78 2001/07/24 17:19:07 roberto Exp roberto $ ** $Id: lopcodes.h,v 1.79 2001/08/27 15:14:57 roberto Exp $
** Opcodes for Lua virtual machine ** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -76,37 +76,37 @@ enum OpMode {iABC, iABc, iAsBc}; /* basic instruction format */
** the following macros help to manipulate instructions ** the following macros help to manipulate instructions
*/ */
#define GET_OPCODE(i) ((OpCode)((i)&MASK1(SIZE_OP,0))) #define GET_OPCODE(i) (cast(OpCode, (i)&MASK1(SIZE_OP,0)))
#define SET_OPCODE(i,o) (((i)&MASK0(SIZE_OP,0)) | (Instruction)(o)) #define SET_OPCODE(i,o) (((i)&MASK0(SIZE_OP,0)) | cast(Instruction, o))
#define GETARG_A(i) ((int)((i)>>POS_A)) #define GETARG_A(i) (cast(int, (i)>>POS_A))
#define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ #define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \
((Instruction)(u)<<POS_A))) (cast(Instruction, u)<<POS_A)))
#define GETARG_B(i) ((int)(((i)>>POS_B) & MASK1(SIZE_B,0))) #define GETARG_B(i) (cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0)))
#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ #define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \
((Instruction)(b)<<POS_B))) (cast(Instruction, b)<<POS_B)))
#define GETARG_C(i) ((int)(((i)>>POS_C) & MASK1(SIZE_C,0))) #define GETARG_C(i) (cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0)))
#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ #define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \
((Instruction)(b)<<POS_C))) (cast(Instruction, b)<<POS_C)))
#define GETARG_Bc(i) ((int)(((i)>>POS_Bc) & MASK1(SIZE_Bc,0))) #define GETARG_Bc(i) (cast(int, ((i)>>POS_Bc) & MASK1(SIZE_Bc,0)))
#define SETARG_Bc(i,b) ((i) = (((i)&MASK0(SIZE_Bc,POS_Bc)) | \ #define SETARG_Bc(i,b) ((i) = (((i)&MASK0(SIZE_Bc,POS_Bc)) | \
((Instruction)(b)<<POS_Bc))) (cast(Instruction, b)<<POS_Bc)))
#define GETARG_sBc(i) (GETARG_Bc(i)-MAXARG_sBc) #define GETARG_sBc(i) (GETARG_Bc(i)-MAXARG_sBc)
#define SETARG_sBc(i,b) SETARG_Bc((i),(unsigned int)((b)+MAXARG_sBc)) #define SETARG_sBc(i,b) SETARG_Bc((i),cast(unsigned int, (b)+MAXARG_sBc))
#define CREATE_ABC(o,a,b,c) ((Instruction)(o) \ #define CREATE_ABC(o,a,b,c) (cast(Instruction, o) \
| ((Instruction)(a)<<POS_A) \ | (cast(Instruction, a)<<POS_A) \
| ((Instruction)(b)<<POS_B) \ | (cast(Instruction, b)<<POS_B) \
| ((Instruction)(c)<<POS_C)) | (cast(Instruction, c)<<POS_C))
#define CREATE_ABc(o,a,bc) ((Instruction)(o) \ #define CREATE_ABc(o,a,bc) (cast(Instruction, o) \
| ((Instruction)(a)<<POS_A) \ | (cast(Instruction, a)<<POS_A) \
| ((Instruction)(bc)<<POS_Bc)) | (cast(Instruction, bc)<<POS_Bc))
@@ -184,7 +184,7 @@ OP_CLOSURE /* A Bc R(A) := closure(KPROTO[Bc], R(A), ... ,R(A+n)) */
} OpCode; } OpCode;
#define NUM_OPCODES ((int)OP_CLOSURE+1) #define NUM_OPCODES (cast(int, OP_CLOSURE+1))
@@ -215,7 +215,7 @@ enum OpModeMask {
extern const lu_byte luaP_opmodes[NUM_OPCODES]; extern const lu_byte luaP_opmodes[NUM_OPCODES];
#define getOpMode(m) ((enum OpMode)(luaP_opmodes[m] & 3)) #define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3))
#define testOpMode(m, b) (luaP_opmodes[m] & (1 << (b))) #define testOpMode(m, b) (luaP_opmodes[m] & (1 << (b)))

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lparser.c,v 1.153 2001/08/10 20:53:03 roberto Exp roberto $ ** $Id: lparser.c,v 1.154 2001/08/27 15:16:28 roberto Exp $
** Lua Parser ** Lua Parser
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -266,7 +266,7 @@ static void code_params (LexState *ls, int nparams, short dots) {
FuncState *fs = ls->fs; FuncState *fs = ls->fs;
adjustlocalvars(ls, nparams); adjustlocalvars(ls, nparams);
luaX_checklimit(ls, fs->nactloc, MAXPARAMS, l_s("parameters")); luaX_checklimit(ls, fs->nactloc, MAXPARAMS, l_s("parameters"));
fs->f->numparams = (short)fs->nactloc; /* `self' could be there already */ fs->f->numparams = cast(short, fs->nactloc); /* `self' could be there already */
fs->f->is_vararg = dots; fs->f->is_vararg = dots;
if (dots) { if (dots) {
new_localvarstr(ls, l_s("arg"), 0); new_localvarstr(ls, l_s("arg"), 0);
@@ -758,13 +758,13 @@ static BinOpr subexpr (LexState *ls, expdesc *v, int limit) {
else simpleexp(ls, v); else simpleexp(ls, v);
/* expand while operators have priorities higher than `limit' */ /* expand while operators have priorities higher than `limit' */
op = getbinopr(ls->t.token); op = getbinopr(ls->t.token);
while (op != OPR_NOBINOPR && (int)priority[op].left > limit) { while (op != OPR_NOBINOPR && cast(int, priority[op].left) > limit) {
expdesc v2; expdesc v2;
BinOpr nextop; BinOpr nextop;
next(ls); next(ls);
luaK_infix(ls->fs, op, v); luaK_infix(ls->fs, op, v);
/* read sub-expression with higher priority */ /* read sub-expression with higher priority */
nextop = subexpr(ls, &v2, (int)priority[op].right); nextop = subexpr(ls, &v2, cast(int, priority[op].right));
luaK_posfix(ls->fs, op, v, &v2); luaK_posfix(ls->fs, op, v, &v2);
op = nextop; op = nextop;
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstate.c,v 1.65 2001/06/21 16:41:34 roberto Exp roberto $ ** $Id: lstate.c,v 1.66 2001/07/17 17:54:46 roberto Exp $
** Global State ** Global State
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -33,7 +33,7 @@ static void close_state (lua_State *L, lua_State *OL);
** open parts that may cause memory-allocation errors ** open parts that may cause memory-allocation errors
*/ */
static void f_luaopen (lua_State *L, void *ud) { static void f_luaopen (lua_State *L, void *ud) {
struct Sopen *so = (struct Sopen *)ud; struct Sopen *so = cast(struct Sopen *, ud);
if (so->stacksize == 0) if (so->stacksize == 0)
so->stacksize = DEFAULT_STACK_SIZE; so->stacksize = DEFAULT_STACK_SIZE;
else else

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstring.c,v 1.65 2001/06/15 20:36:57 roberto Exp roberto $ ** $Id: lstring.c,v 1.66 2001/08/27 15:16:28 roberto Exp $
** String table (keeps all strings handled by Lua) ** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -35,7 +35,7 @@ void luaS_resize (lua_State *L, int newsize) {
TString *next = p->tsv.nexthash; /* save next */ TString *next = p->tsv.nexthash; /* save next */
lu_hash h = p->tsv.hash; lu_hash h = p->tsv.hash;
int h1 = lmod(h, newsize); /* new position */ int h1 = lmod(h, newsize); /* new position */
lua_assert((int)(h%newsize) == lmod(h, newsize)); lua_assert(cast(int, h%newsize) == lmod(h, newsize));
p->tsv.nexthash = newhash[h1]; /* chain it in new position */ p->tsv.nexthash = newhash[h1]; /* chain it in new position */
newhash[h1] = p; newhash[h1] = p;
p = next; p = next;
@@ -48,7 +48,7 @@ void luaS_resize (lua_State *L, int newsize) {
static TString *newlstr (lua_State *L, const l_char *str, size_t l, lu_hash h) { static TString *newlstr (lua_State *L, const l_char *str, size_t l, lu_hash h) {
TString *ts = (TString *)luaM_malloc(L, sizestring(l)); TString *ts = cast(TString *, luaM_malloc(L, sizestring(l)));
stringtable *tb; stringtable *tb;
ts->tsv.nexthash = NULL; ts->tsv.nexthash = NULL;
ts->tsv.len = l; ts->tsv.len = l;
@@ -61,7 +61,7 @@ static TString *newlstr (lua_State *L, const l_char *str, size_t l, lu_hash h) {
ts->tsv.nexthash = tb->hash[h]; /* chain new entry */ ts->tsv.nexthash = tb->hash[h]; /* chain new entry */
tb->hash[h] = ts; tb->hash[h] = ts;
tb->nuse++; tb->nuse++;
if (tb->nuse > (ls_nstr)tb->size && tb->size <= MAX_INT/2) if (tb->nuse > cast(ls_nstr, tb->size) && tb->size <= MAX_INT/2)
luaS_resize(L, tb->size*2); /* too crowded */ luaS_resize(L, tb->size*2); /* too crowded */
return ts; return ts;
} }
@@ -85,7 +85,7 @@ TString *luaS_newlstr (lua_State *L, const l_char *str, size_t l) {
Udata *luaS_newudata (lua_State *L, size_t s) { Udata *luaS_newudata (lua_State *L, size_t s) {
Udata *u = (Udata *)luaM_malloc(L, sizeudata(s)); Udata *u = cast(Udata *, luaM_malloc(L, sizeudata(s)));
u->uv.len = s; u->uv.len = s;
u->uv.tag = 0; u->uv.tag = 0;
u->uv.value = u + 1; u->uv.value = u + 1;

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstring.h,v 1.32 2001/06/06 18:00:19 roberto Exp roberto $ ** $Id: lstring.h,v 1.33 2001/06/15 20:36:57 roberto Exp $
** String table (keep all strings handled by Lua) ** String table (keep all strings handled by Lua)
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -21,10 +21,10 @@
#define RESERVEDMARK 3 #define RESERVEDMARK 3
#define sizestring(l) ((lu_mem)sizeof(union TString)+ \ #define sizestring(l) (cast(lu_mem, sizeof(union TString))+ \
((lu_mem)(l)+1)*sizeof(l_char)) (cast(lu_mem, l)+1)*sizeof(l_char))
#define sizeudata(l) ((lu_mem)sizeof(union Udata)+(l)) #define sizeudata(l) (cast(lu_mem, sizeof(union Udata))+(l))
#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
#define luaS_newliteral(L, s) (luaS_newlstr(L, l_s("") s, \ #define luaS_newliteral(L, s) (luaS_newlstr(L, l_s("") s, \

View File

@@ -91,7 +91,7 @@ static int str_byte (lua_State *L) {
size_t l; size_t l;
const l_char *s = luaL_check_lstr(L, 1, &l); const l_char *s = luaL_check_lstr(L, 1, &l);
sint32 pos = posrelat(luaL_opt_long(L, 2, 1), l); sint32 pos = posrelat(luaL_opt_long(L, 2, 1), l);
luaL_arg_check(L, 0<pos && (size_t)pos<=l, 2, l_s("out of range")); luaL_arg_check(L, 0 < pos && (size_t)(pos) <= l, 2, l_s("out of range"));
lua_pushnumber(L, uchar(s[pos-1])); lua_pushnumber(L, uchar(s[pos-1]));
return 1; return 1;
} }
@@ -424,7 +424,7 @@ static int str_find (lua_State *L) {
const l_char *s = luaL_check_lstr(L, 1, &l1); const l_char *s = luaL_check_lstr(L, 1, &l1);
const l_char *p = luaL_check_lstr(L, 2, &l2); const l_char *p = luaL_check_lstr(L, 2, &l2);
sint32 init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1; sint32 init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1;
luaL_arg_check(L, 0 <= init && (size_t)init <= l1, 3, l_s("out of range")); luaL_arg_check(L, 0 <= init && (size_t)(init) <= l1, 3, l_s("out of range"));
if (lua_gettop(L) > 3 || /* extra argument? */ if (lua_gettop(L) > 3 || /* extra argument? */
strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */
const l_char *s2 = lmemfind(s+init, l1-init, p, l2); const l_char *s2 = lmemfind(s+init, l1-init, p, l2);
@@ -603,7 +603,7 @@ static int str_format (lua_State *L) {
sprintf(buff, form, luaL_check_int(L, arg)); sprintf(buff, form, luaL_check_int(L, arg));
break; break;
case l_c('o'): case l_c('u'): case l_c('x'): case l_c('X'): case l_c('o'): case l_c('u'): case l_c('x'): case l_c('X'):
sprintf(buff, form, (unsigned int)luaL_check_number(L, arg)); sprintf(buff, form, (unsigned int)(luaL_check_number(L, arg)));
break; break;
case l_c('e'): case l_c('E'): case l_c('f'): case l_c('e'): case l_c('E'): case l_c('f'):
case l_c('g'): case l_c('G'): case l_c('g'): case l_c('G'):

View File

@@ -32,9 +32,9 @@
#define TagDefault LUA_TTABLE #define TagDefault LUA_TTABLE
#define hashnum(t,n) (node(t, lmod((lu_hash)(ls_hash)(n), t->size))) #define hashnum(t,n) (node(t, lmod(cast(lu_hash, cast(ls_hash, n)), t->size)))
#define hashstr(t,str) (node(t, lmod((str)->tsv.hash, t->size))) #define hashstr(t,str) (node(t, lmod((str)->tsv.hash, t->size)))
#define hashpointer(t,p) (node(t, lmod(IntPoint(p), t->size))) #define hashpointer(t,p) (node(t, lmod(IntPoint(p), t->size)))
/* /*
@@ -61,8 +61,8 @@ Node *luaH_next (lua_State *L, Hash *t, const TObject *key) {
const TObject *v = luaH_get(t, key); const TObject *v = luaH_get(t, key);
if (v == &luaO_nilobject) if (v == &luaO_nilobject)
luaD_error(L, l_s("invalid key for `next'")); luaD_error(L, l_s("invalid key for `next'"));
i = (int)(((const lu_byte *)v - i = cast(int, (cast(const lu_byte *, v) -
(const lu_byte *)(val(node(t, 0)))) / sizeof(Node)) + 1; cast(const lu_byte *, val(node(t, 0)))) / sizeof(Node)) + 1;
} }
for (; i<t->size; i++) { for (; i<t->size; i++) {
Node *n = node(t, i); Node *n = node(t, i);
@@ -259,8 +259,8 @@ const TObject *luaH_get (Hash *t, const TObject *key) {
switch (ttype(key)) { switch (ttype(key)) {
case LUA_TSTRING: return luaH_getstr(t, tsvalue(key)); case LUA_TSTRING: return luaH_getstr(t, tsvalue(key));
case LUA_TNUMBER: { case LUA_TNUMBER: {
int k = (int)nvalue(key); int k = cast(int, nvalue(key));
if ((lua_Number)k == nvalue(key)) /* is an integer index? */ if (cast(lua_Number, k) == nvalue(key)) /* is an integer index? */
return luaH_getnum(t, k); /* use specialized version */ return luaH_getnum(t, k); /* use specialized version */
/* else go through */ /* else go through */
} }

View File

@@ -14,7 +14,7 @@
#define key(_n) (&(_n)->key) #define key(_n) (&(_n)->key)
#define val(_n) (&(_n)->val) #define val(_n) (&(_n)->val)
#define settableval(p,v) setobj((TObject *)p, v) #define settableval(p,v) setobj(cast(TObject *, p), v)
const TObject *luaH_getnum (Hash *t, int key); const TObject *luaH_getnum (Hash *t, int key);

View File

@@ -64,7 +64,7 @@ static void setnameval (lua_State *L, const l_char *name, int val) {
#define MARK 0x55 /* 01010101 (a nice pattern) */ #define MARK 0x55 /* 01010101 (a nice pattern) */
#define blocksize(b) ((size_t *)(b) - HEADER/sizeof(size_t)) #define blocksize(b) (cast(size_t *, b) - HEADER/sizeof(size_t))
unsigned long memdebug_numblocks = 0; unsigned long memdebug_numblocks = 0;
unsigned long memdebug_total = 0; unsigned long memdebug_total = 0;
@@ -77,7 +77,7 @@ static void *checkblock (void *block) {
size_t size = *b; size_t size = *b;
int i; int i;
for (i=0;i<MARKSIZE;i++) for (i=0;i<MARKSIZE;i++)
lua_assert(*(((char *)b)+HEADER+size+i) == MARK+i); /* corrupted block? */ lua_assert(*(cast(char *, b)+HEADER+size+i) == MARK+i); /* corrupted block? */
return b; return b;
} }
@@ -111,19 +111,19 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) {
if (newblock == NULL) return NULL; if (newblock == NULL) return NULL;
if (oldsize > size) oldsize = size; if (oldsize > size) oldsize = size;
if (block) { if (block) {
memcpy((char *)newblock+HEADER, block, oldsize); memcpy(cast(char *, newblock)+HEADER, block, oldsize);
freeblock(block); /* erase (and check) old copy */ freeblock(block); /* erase (and check) old copy */
} }
/* initialize new part of the block with something `weird' */ /* initialize new part of the block with something `weird' */
memset((char *)newblock+HEADER+oldsize, -MARK, size-oldsize); memset(cast(char *, newblock)+HEADER+oldsize, -MARK, size-oldsize);
memdebug_total += size; memdebug_total += size;
if (memdebug_total > memdebug_maxmem) if (memdebug_total > memdebug_maxmem)
memdebug_maxmem = memdebug_total; memdebug_maxmem = memdebug_total;
memdebug_numblocks++; memdebug_numblocks++;
*(size_t *)newblock = size; *cast(size_t *, newblock) = size;
for (i=0;i<MARKSIZE;i++) for (i=0;i<MARKSIZE;i++)
*((char *)newblock+HEADER+size+i) = (char)(MARK+i); *(cast(char *, newblock)+HEADER+size+i) = cast(char, MARK+i);
return (char *)newblock+HEADER; return cast(char *, newblock)+HEADER;
} }
} }
@@ -343,13 +343,13 @@ static int unref (lua_State *L) {
static int newuserdata (lua_State *L) { static int newuserdata (lua_State *L) {
size_t size = luaL_check_int(L, 1); size_t size = luaL_check_int(L, 1);
l_char *p = (l_char *)lua_newuserdata(L, size); l_char *p = cast(l_char *, lua_newuserdata(L, size));
while (size--) *p++ = l_c('\0'); while (size--) *p++ = l_c('\0');
return 1; return 1;
} }
static int newuserdatabox (lua_State *L) { static int newuserdatabox (lua_State *L) {
lua_newuserdatabox(L, (void *)luaL_check_int(L, 1)); lua_newuserdatabox(L, cast(void *, luaL_check_int(L, 1)));
return 1; return 1;
} }
@@ -362,20 +362,20 @@ static int settag (lua_State *L) {
static int udataval (lua_State *L) { static int udataval (lua_State *L) {
luaL_checktype(L, 1, LUA_TUSERDATA); luaL_checktype(L, 1, LUA_TUSERDATA);
lua_pushnumber(L, (int)lua_touserdata(L, 1)); lua_pushnumber(L, cast(int, lua_touserdata(L, 1)));
return 1; return 1;
} }
static int newtag (lua_State *L) { static int newtag (lua_State *L) {
lua_pushnumber(L, lua_newtype(L, lua_tostring(L, 1), lua_pushnumber(L, lua_newtype(L, lua_tostring(L, 1),
(int)lua_tonumber(L, 2))); cast(int, lua_tonumber(L, 2))));
return 1; return 1;
} }
static int doonnewstack (lua_State *L) { static int doonnewstack (lua_State *L) {
lua_State *L1 = lua_newthread(L, luaL_check_int(L, 1)); lua_State *L1 = lua_newthread(L, luaL_check_int(L, 1));
if (L1 == NULL) return 0; if (L1 == NULL) return 0;
*((int **)L1) = &islocked; /* initialize the lock */ *cast(int **, L1) = &islocked; /* initialize the lock */
lua_dostring(L1, luaL_check_string(L, 2)); lua_dostring(L1, luaL_check_string(L, 2));
lua_pushnumber(L, 1); lua_pushnumber(L, 1);
lua_close(L1); lua_close(L1);
@@ -384,13 +384,13 @@ static int doonnewstack (lua_State *L) {
static int s2d (lua_State *L) { static int s2d (lua_State *L) {
lua_pushnumber(L, *(double *)luaL_check_string(L, 1)); lua_pushnumber(L, *cast(double *, luaL_check_string(L, 1)));
return 1; return 1;
} }
static int d2s (lua_State *L) { static int d2s (lua_State *L) {
double d = luaL_check_number(L, 1); double d = luaL_check_number(L, 1);
lua_pushlstring(L, (l_char *)&d, sizeof(d)); lua_pushlstring(L, cast(l_char *, &d), sizeof(d));
return 1; return 1;
} }
@@ -398,7 +398,7 @@ static int d2s (lua_State *L) {
static int newstate (lua_State *L) { static int newstate (lua_State *L) {
lua_State *L1 = lua_open(luaL_check_int(L, 1)); lua_State *L1 = lua_open(luaL_check_int(L, 1));
if (L1) { if (L1) {
*((int **)L1) = &islocked; /* initialize the lock */ *cast(int **, L1) = &islocked; /* initialize the lock */
lua_pushnumber(L, (unsigned long)L1); lua_pushnumber(L, (unsigned long)L1);
} }
else else
@@ -407,7 +407,7 @@ static int newstate (lua_State *L) {
} }
static int loadlib (lua_State *L) { static int loadlib (lua_State *L) {
lua_State *L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1); lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1)));
lua_register(L1, "mathlibopen", lua_mathlibopen); lua_register(L1, "mathlibopen", lua_mathlibopen);
lua_register(L1, "strlibopen", lua_strlibopen); lua_register(L1, "strlibopen", lua_strlibopen);
lua_register(L1, "iolibopen", lua_iolibopen); lua_register(L1, "iolibopen", lua_iolibopen);
@@ -417,7 +417,7 @@ static int loadlib (lua_State *L) {
} }
static int closestate (lua_State *L) { static int closestate (lua_State *L) {
lua_State *L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1); lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1)));
lua_close(L1); lua_close(L1);
lua_unlock(L); /* close cannot unlock that */ lua_unlock(L); /* close cannot unlock that */
return 0; return 0;
@@ -427,7 +427,7 @@ static int doremote (lua_State *L) {
lua_State *L1; lua_State *L1;
const l_char *code = luaL_check_string(L, 2); const l_char *code = luaL_check_string(L, 2);
int status; int status;
L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1); L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1)));
status = lua_dostring(L1, code); status = lua_dostring(L1, code);
if (status != 0) { if (status != 0) {
lua_pushnil(L); lua_pushnil(L);
@@ -472,12 +472,12 @@ static void skip (const l_char **pc) {
while (**pc != l_c('\0') && strchr(delimits, **pc)) (*pc)++; while (**pc != l_c('\0') && strchr(delimits, **pc)) (*pc)++;
} }
static int getnum (lua_State *L, const l_char **pc) { static int getnum_aux (lua_State *L, const l_char **pc) {
int res = 0; int res = 0;
int sig = 1; int sig = 1;
skip(pc); skip(pc);
if (**pc == l_c('.')) { if (**pc == l_c('.')) {
res = (int)lua_tonumber(L, -1); res = cast(int, lua_tonumber(L, -1));
lua_pop(L, 1); lua_pop(L, 1);
(*pc)++; (*pc)++;
return res; return res;
@@ -486,11 +486,11 @@ static int getnum (lua_State *L, const l_char **pc) {
sig = -1; sig = -1;
(*pc)++; (*pc)++;
} }
while (isdigit((int)**pc)) res = res*10 + (*(*pc)++) - l_c('0'); while (isdigit(cast(int, **pc))) res = res*10 + (*(*pc)++) - l_c('0');
return sig*res; return sig*res;
} }
static const l_char *getname (l_char *buff, const l_char **pc) { static const l_char *getname_aux (l_char *buff, const l_char **pc) {
int i = 0; int i = 0;
skip(pc); skip(pc);
while (**pc != l_c('\0') && !strchr(delimits, **pc)) while (**pc != l_c('\0') && !strchr(delimits, **pc))
@@ -502,8 +502,8 @@ static const l_char *getname (l_char *buff, const l_char **pc) {
#define EQ(s1) (strcmp(s1, inst) == 0) #define EQ(s1) (strcmp(s1, inst) == 0)
#define getnum ((getnum)(L, &pc)) #define getnum (getnum_aux(L, &pc))
#define getname ((getname)(buff, &pc)) #define getname (getname_aux(buff, &pc))
static int testC (lua_State *L) { static int testC (lua_State *L) {
@@ -661,7 +661,7 @@ static const struct luaL_reg tests_funcs[] = {
void luaB_opentests (lua_State *L) { void luaB_opentests (lua_State *L) {
*((int **)L) = &islocked; /* init lock */ *cast(int **, L) = &islocked; /* init lock */
lua_state = L; /* keep first state to be opened */ lua_state = L; /* keep first state to be opened */
/* open lib in a new table */ /* open lib in a new table */
lua_newtable(L); lua_newtable(L);

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: ltests.h,v 1.6 2001/03/02 17:27:50 roberto Exp roberto $ ** $Id: ltests.h,v 1.7 2001/06/28 19:58:57 roberto Exp $
** Internal Header for Debugging of the Lua Implementation ** Internal Header for Debugging of the Lua Implementation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -43,8 +43,8 @@ void *debug_realloc (void *block, size_t oldsize, size_t size);
/* test for lock/unlock */ /* test for lock/unlock */
#define LUA_USERSTATE int *lock; #define LUA_USERSTATE int *lock;
extern int islocked; extern int islocked;
#define lua_lock(L) lua_assert((**((int **)L))++ == 0) #define lua_lock(L) lua_assert((**cast(int **, L))++ == 0)
#define lua_unlock(L) lua_assert(--(**((int **)L)) == 0) #define lua_unlock(L) lua_assert(--(**cast(int **, L)) == 0)
extern lua_State *lua_state; extern lua_State *lua_state;

4
ltm.c
View File

@@ -61,7 +61,7 @@ static const lu_byte luaT_validevents[NUM_TAGS][TM_N] = {
}; };
int luaT_validevent (int t, int e) { /* ORDER LUA_T */ int luaT_validevent (int t, int e) { /* ORDER LUA_T */
return (t >= NUM_TAGS) ? 1 : (int)luaT_validevents[t][e]; return (t >= NUM_TAGS) ? 1 : cast(int, luaT_validevents[t][e]);
} }
@@ -88,7 +88,7 @@ int luaT_newtag (lua_State *L, const l_char *name, int basictype) {
TObject otag; TObject otag;
ts = luaS_new(L, name); ts = luaS_new(L, name);
v = luaH_getstr(G(L)->type2tag, ts); v = luaH_getstr(G(L)->type2tag, ts);
if (ttype(v) == LUA_TNUMBER) return (int)nvalue(v); if (ttype(v) == LUA_TNUMBER) return cast(int, nvalue(v));
setnvalue(&otag, tag); setnvalue(&otag, tag);
luaH_setstr(L, G(L)->type2tag, ts, &otag); luaH_setstr(L, G(L)->type2tag, ts, &otag);
} }

6
lvm.c
View File

@@ -293,8 +293,8 @@ void luaV_strconc (lua_State *L, int total, StkId top) {
luaG_concaterror(L, top-2, top-1); luaG_concaterror(L, top-2, top-1);
} else if (tsvalue(top-1)->tsv.len > 0) { /* if len=0, do nothing */ } else if (tsvalue(top-1)->tsv.len > 0) { /* if len=0, do nothing */
/* at least two string values; get as many as possible */ /* at least two string values; get as many as possible */
lu_mem tl = (lu_mem)tsvalue(top-1)->tsv.len + lu_mem tl = cast(lu_mem, tsvalue(top-1)->tsv.len) +
(lu_mem)tsvalue(top-2)->tsv.len; cast(lu_mem, tsvalue(top-2)->tsv.len);
l_char *buffer; l_char *buffer;
int i; int i;
while (n < total && !tostring(L, top-n-1)) { /* collect total length */ while (n < total && !tostring(L, top-n-1)) { /* collect total length */
@@ -618,7 +618,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
runtime_check(L, ttype(ra) == LUA_TTABLE && runtime_check(L, ttype(ra) == LUA_TTABLE &&
ttype(ra+1) == LUA_TNUMBER); ttype(ra+1) == LUA_TNUMBER);
t = hvalue(ra); t = hvalue(ra);
n = (int)nvalue(ra+1); n = cast(int, nvalue(ra+1));
n = luaH_nexti(t, n); n = luaH_nexti(t, n);
if (n != -1) { /* repeat loop? */ if (n != -1) { /* repeat loop? */
Node *node = node(t, n); Node *node = node(t, n);