aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-08-31 16:46:07 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-08-31 16:46:07 -0300
commite1d072571ec6f9d830e575a2ecdc95fd43428e53 (patch)
tree830fab7f2acb9adaee2d63073d339cc9557a5437 /ltests.c
parent7651a5c6b2ee6ec59cadec6199319d482071f176 (diff)
downloadlua-e1d072571ec6f9d830e575a2ecdc95fd43428e53.tar.gz
lua-e1d072571ec6f9d830e575a2ecdc95fd43428e53.tar.bz2
lua-e1d072571ec6f9d830e575a2ecdc95fd43428e53.zip
better syntax for type casts
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/ltests.c b/ltests.c
index 3eb0ec1b..35c6f027 100644
--- a/ltests.c
+++ b/ltests.c
@@ -64,7 +64,7 @@ static void setnameval (lua_State *L, const l_char *name, int val) {
64#define MARK 0x55 /* 01010101 (a nice pattern) */ 64#define MARK 0x55 /* 01010101 (a nice pattern) */
65 65
66 66
67#define blocksize(b) ((size_t *)(b) - HEADER/sizeof(size_t)) 67#define blocksize(b) (cast(size_t *, b) - HEADER/sizeof(size_t))
68 68
69unsigned long memdebug_numblocks = 0; 69unsigned long memdebug_numblocks = 0;
70unsigned long memdebug_total = 0; 70unsigned long memdebug_total = 0;
@@ -77,7 +77,7 @@ static void *checkblock (void *block) {
77 size_t size = *b; 77 size_t size = *b;
78 int i; 78 int i;
79 for (i=0;i<MARKSIZE;i++) 79 for (i=0;i<MARKSIZE;i++)
80 lua_assert(*(((char *)b)+HEADER+size+i) == MARK+i); /* corrupted block? */ 80 lua_assert(*(cast(char *, b)+HEADER+size+i) == MARK+i); /* corrupted block? */
81 return b; 81 return b;
82} 82}
83 83
@@ -111,19 +111,19 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) {
111 if (newblock == NULL) return NULL; 111 if (newblock == NULL) return NULL;
112 if (oldsize > size) oldsize = size; 112 if (oldsize > size) oldsize = size;
113 if (block) { 113 if (block) {
114 memcpy((char *)newblock+HEADER, block, oldsize); 114 memcpy(cast(char *, newblock)+HEADER, block, oldsize);
115 freeblock(block); /* erase (and check) old copy */ 115 freeblock(block); /* erase (and check) old copy */
116 } 116 }
117 /* initialize new part of the block with something `weird' */ 117 /* initialize new part of the block with something `weird' */
118 memset((char *)newblock+HEADER+oldsize, -MARK, size-oldsize); 118 memset(cast(char *, newblock)+HEADER+oldsize, -MARK, size-oldsize);
119 memdebug_total += size; 119 memdebug_total += size;
120 if (memdebug_total > memdebug_maxmem) 120 if (memdebug_total > memdebug_maxmem)
121 memdebug_maxmem = memdebug_total; 121 memdebug_maxmem = memdebug_total;
122 memdebug_numblocks++; 122 memdebug_numblocks++;
123 *(size_t *)newblock = size; 123 *cast(size_t *, newblock) = size;
124 for (i=0;i<MARKSIZE;i++) 124 for (i=0;i<MARKSIZE;i++)
125 *((char *)newblock+HEADER+size+i) = (char)(MARK+i); 125 *(cast(char *, newblock)+HEADER+size+i) = cast(char, MARK+i);
126 return (char *)newblock+HEADER; 126 return cast(char *, newblock)+HEADER;
127 } 127 }
128} 128}
129 129
@@ -343,13 +343,13 @@ static int unref (lua_State *L) {
343 343
344static int newuserdata (lua_State *L) { 344static int newuserdata (lua_State *L) {
345 size_t size = luaL_check_int(L, 1); 345 size_t size = luaL_check_int(L, 1);
346 l_char *p = (l_char *)lua_newuserdata(L, size); 346 l_char *p = cast(l_char *, lua_newuserdata(L, size));
347 while (size--) *p++ = l_c('\0'); 347 while (size--) *p++ = l_c('\0');
348 return 1; 348 return 1;
349} 349}
350 350
351static int newuserdatabox (lua_State *L) { 351static int newuserdatabox (lua_State *L) {
352 lua_newuserdatabox(L, (void *)luaL_check_int(L, 1)); 352 lua_newuserdatabox(L, cast(void *, luaL_check_int(L, 1)));
353 return 1; 353 return 1;
354} 354}
355 355
@@ -362,20 +362,20 @@ static int settag (lua_State *L) {
362 362
363static int udataval (lua_State *L) { 363static int udataval (lua_State *L) {
364 luaL_checktype(L, 1, LUA_TUSERDATA); 364 luaL_checktype(L, 1, LUA_TUSERDATA);
365 lua_pushnumber(L, (int)lua_touserdata(L, 1)); 365 lua_pushnumber(L, cast(int, lua_touserdata(L, 1)));
366 return 1; 366 return 1;
367} 367}
368 368
369static int newtag (lua_State *L) { 369static int newtag (lua_State *L) {
370 lua_pushnumber(L, lua_newtype(L, lua_tostring(L, 1), 370 lua_pushnumber(L, lua_newtype(L, lua_tostring(L, 1),
371 (int)lua_tonumber(L, 2))); 371 cast(int, lua_tonumber(L, 2))));
372 return 1; 372 return 1;
373} 373}
374 374
375static int doonnewstack (lua_State *L) { 375static int doonnewstack (lua_State *L) {
376 lua_State *L1 = lua_newthread(L, luaL_check_int(L, 1)); 376 lua_State *L1 = lua_newthread(L, luaL_check_int(L, 1));
377 if (L1 == NULL) return 0; 377 if (L1 == NULL) return 0;
378 *((int **)L1) = &islocked; /* initialize the lock */ 378 *cast(int **, L1) = &islocked; /* initialize the lock */
379 lua_dostring(L1, luaL_check_string(L, 2)); 379 lua_dostring(L1, luaL_check_string(L, 2));
380 lua_pushnumber(L, 1); 380 lua_pushnumber(L, 1);
381 lua_close(L1); 381 lua_close(L1);
@@ -384,13 +384,13 @@ static int doonnewstack (lua_State *L) {
384 384
385 385
386static int s2d (lua_State *L) { 386static int s2d (lua_State *L) {
387 lua_pushnumber(L, *(double *)luaL_check_string(L, 1)); 387 lua_pushnumber(L, *cast(double *, luaL_check_string(L, 1)));
388 return 1; 388 return 1;
389} 389}
390 390
391static int d2s (lua_State *L) { 391static int d2s (lua_State *L) {
392 double d = luaL_check_number(L, 1); 392 double d = luaL_check_number(L, 1);
393 lua_pushlstring(L, (l_char *)&d, sizeof(d)); 393 lua_pushlstring(L, cast(l_char *, &d), sizeof(d));
394 return 1; 394 return 1;
395} 395}
396 396
@@ -398,7 +398,7 @@ static int d2s (lua_State *L) {
398static int newstate (lua_State *L) { 398static int newstate (lua_State *L) {
399 lua_State *L1 = lua_open(luaL_check_int(L, 1)); 399 lua_State *L1 = lua_open(luaL_check_int(L, 1));
400 if (L1) { 400 if (L1) {
401 *((int **)L1) = &islocked; /* initialize the lock */ 401 *cast(int **, L1) = &islocked; /* initialize the lock */
402 lua_pushnumber(L, (unsigned long)L1); 402 lua_pushnumber(L, (unsigned long)L1);
403 } 403 }
404 else 404 else
@@ -407,7 +407,7 @@ static int newstate (lua_State *L) {
407} 407}
408 408
409static int loadlib (lua_State *L) { 409static int loadlib (lua_State *L) {
410 lua_State *L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1); 410 lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1)));
411 lua_register(L1, "mathlibopen", lua_mathlibopen); 411 lua_register(L1, "mathlibopen", lua_mathlibopen);
412 lua_register(L1, "strlibopen", lua_strlibopen); 412 lua_register(L1, "strlibopen", lua_strlibopen);
413 lua_register(L1, "iolibopen", lua_iolibopen); 413 lua_register(L1, "iolibopen", lua_iolibopen);
@@ -417,7 +417,7 @@ static int loadlib (lua_State *L) {
417} 417}
418 418
419static int closestate (lua_State *L) { 419static int closestate (lua_State *L) {
420 lua_State *L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1); 420 lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1)));
421 lua_close(L1); 421 lua_close(L1);
422 lua_unlock(L); /* close cannot unlock that */ 422 lua_unlock(L); /* close cannot unlock that */
423 return 0; 423 return 0;
@@ -427,7 +427,7 @@ static int doremote (lua_State *L) {
427 lua_State *L1; 427 lua_State *L1;
428 const l_char *code = luaL_check_string(L, 2); 428 const l_char *code = luaL_check_string(L, 2);
429 int status; 429 int status;
430 L1 = (lua_State *)(unsigned long)luaL_check_number(L, 1); 430 L1 = cast(lua_State *, cast(unsigned long, luaL_check_number(L, 1)));
431 status = lua_dostring(L1, code); 431 status = lua_dostring(L1, code);
432 if (status != 0) { 432 if (status != 0) {
433 lua_pushnil(L); 433 lua_pushnil(L);
@@ -472,12 +472,12 @@ static void skip (const l_char **pc) {
472 while (**pc != l_c('\0') && strchr(delimits, **pc)) (*pc)++; 472 while (**pc != l_c('\0') && strchr(delimits, **pc)) (*pc)++;
473} 473}
474 474
475static int getnum (lua_State *L, const l_char **pc) { 475static int getnum_aux (lua_State *L, const l_char **pc) {
476 int res = 0; 476 int res = 0;
477 int sig = 1; 477 int sig = 1;
478 skip(pc); 478 skip(pc);
479 if (**pc == l_c('.')) { 479 if (**pc == l_c('.')) {
480 res = (int)lua_tonumber(L, -1); 480 res = cast(int, lua_tonumber(L, -1));
481 lua_pop(L, 1); 481 lua_pop(L, 1);
482 (*pc)++; 482 (*pc)++;
483 return res; 483 return res;
@@ -486,11 +486,11 @@ static int getnum (lua_State *L, const l_char **pc) {
486 sig = -1; 486 sig = -1;
487 (*pc)++; 487 (*pc)++;
488 } 488 }
489 while (isdigit((int)**pc)) res = res*10 + (*(*pc)++) - l_c('0'); 489 while (isdigit(cast(int, **pc))) res = res*10 + (*(*pc)++) - l_c('0');
490 return sig*res; 490 return sig*res;
491} 491}
492 492
493static const l_char *getname (l_char *buff, const l_char **pc) { 493static const l_char *getname_aux (l_char *buff, const l_char **pc) {
494 int i = 0; 494 int i = 0;
495 skip(pc); 495 skip(pc);
496 while (**pc != l_c('\0') && !strchr(delimits, **pc)) 496 while (**pc != l_c('\0') && !strchr(delimits, **pc))
@@ -502,8 +502,8 @@ static const l_char *getname (l_char *buff, const l_char **pc) {
502 502
503#define EQ(s1) (strcmp(s1, inst) == 0) 503#define EQ(s1) (strcmp(s1, inst) == 0)
504 504
505#define getnum ((getnum)(L, &pc)) 505#define getnum (getnum_aux(L, &pc))
506#define getname ((getname)(buff, &pc)) 506#define getname (getname_aux(buff, &pc))
507 507
508 508
509static int testC (lua_State *L) { 509static int testC (lua_State *L) {
@@ -661,7 +661,7 @@ static const struct luaL_reg tests_funcs[] = {
661 661
662 662
663void luaB_opentests (lua_State *L) { 663void luaB_opentests (lua_State *L) {
664 *((int **)L) = &islocked; /* init lock */ 664 *cast(int **, L) = &islocked; /* init lock */
665 lua_state = L; /* keep first state to be opened */ 665 lua_state = L; /* keep first state to be opened */
666 /* open lib in a new table */ 666 /* open lib in a new table */
667 lua_newtable(L); 667 lua_newtable(L);