aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-04-15 13:32:49 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-04-15 13:32:49 -0300
commit037a70dfea9de66e8d27c8d3ce2ed9f159a1b094 (patch)
treea31c77b6da44e543a1ec01f916e31d99fb64b238
parent8f961da3dbf8c45389d1431e6dff8e44e41f1a57 (diff)
downloadlua-037a70dfea9de66e8d27c8d3ce2ed9f159a1b094.tar.gz
lua-037a70dfea9de66e8d27c8d3ce2ed9f159a1b094.tar.bz2
lua-037a70dfea9de66e8d27c8d3ce2ed9f159a1b094.zip
cast_u2s/cast_s2u renamed l_castS2U/l_castU2S to be configurable from
outside (mostly for testing)
-rw-r--r--lapi.c6
-rw-r--r--llimits.h14
-rw-r--r--lobject.c6
-rw-r--r--ltable.c4
-rw-r--r--lvm.c8
-rw-r--r--lvm.h4
6 files changed, 23 insertions, 19 deletions
diff --git a/lapi.c b/lapi.c
index dc620081..7f85ebd5 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.203 2014/04/12 14:45:10 roberto Exp roberto $ 2** $Id: lapi.c,v 2.204 2014/04/15 14:29:30 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -376,7 +376,7 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) {
376 int isnum = 0; 376 int isnum = 0;
377 switch (ttype(o)) { 377 switch (ttype(o)) {
378 case LUA_TNUMINT: { 378 case LUA_TNUMINT: {
379 res = cast_s2u(ivalue(o)); 379 res = l_castS2U(ivalue(o));
380 isnum = 1; 380 isnum = 1;
381 break; 381 break;
382 } 382 }
@@ -514,7 +514,7 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
514 514
515LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) { 515LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) {
516 lua_lock(L); 516 lua_lock(L);
517 setivalue(L->top, cast_u2s(u)); 517 setivalue(L->top, l_castU2S(u));
518 api_incr_top(L); 518 api_incr_top(L);
519 lua_unlock(L); 519 lua_unlock(L);
520} 520}
diff --git a/llimits.h b/llimits.h
index 0feba1d9..41f207e6 100644
--- a/llimits.h
+++ b/llimits.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llimits.h,v 1.114 2014/04/12 14:45:10 roberto Exp roberto $ 2** $Id: llimits.h,v 1.115 2014/04/15 14:28:20 roberto Exp roberto $
3** Limits, basic types, and some other `installation-dependent' definitions 3** Limits, basic types, and some other `installation-dependent' definitions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -107,15 +107,19 @@ typedef LUAI_UACINT l_uacInt;
107#define cast_uchar(i) cast(unsigned char, (i)) 107#define cast_uchar(i) cast(unsigned char, (i))
108 108
109 109
110/* cast a signed lua_Integer to lua_Unsigned */
111#if !defined(l_castS2U)
112#define l_castS2U(i) ((lua_Unsigned)(i))
113#endif
114
110/* 115/*
111** cast a lua_Unsigned to a signed lua_Integer; this cast is 116** cast a lua_Unsigned to a signed lua_Integer; this cast is
112** not strict ANSI C, but two-complement architectures should 117** not strict ANSI C, but two-complement architectures should
113** work fine. 118** work fine.
114*/ 119*/
115#define cast_u2s(i) ((lua_Integer)(i)) 120#if !defined(l_castU2S)
116 121#define l_castU2S(i) ((lua_Integer)(i))
117/* cast a signed lua_Integer to lua_Unsigned */ 122#endif
118#define cast_s2u(i) ((lua_Unsigned)(i))
119 123
120 124
121/* 125/*
diff --git a/lobject.c b/lobject.c
index c736c8a8..2c437527 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 2.78 2014/04/11 19:52:26 roberto Exp roberto $ 2** $Id: lobject.c,v 2.79 2014/04/15 14:28:20 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -85,7 +85,7 @@ static lua_Integer intarith (lua_State *L, int op, lua_Integer v1,
85 case LUA_OPSHL: return luaV_shiftl(v1, v2); 85 case LUA_OPSHL: return luaV_shiftl(v1, v2);
86 case LUA_OPSHR: return luaV_shiftl(v1, -v2); 86 case LUA_OPSHR: return luaV_shiftl(v1, -v2);
87 case LUA_OPUNM: return intop(-, 0, v1); 87 case LUA_OPUNM: return intop(-, 0, v1);
88 case LUA_OPBNOT: return intop(^, ~cast_s2u(0), v1); 88 case LUA_OPBNOT: return intop(^, ~l_castS2U(0), v1);
89 default: lua_assert(0); return 0; 89 default: lua_assert(0); return 0;
90 } 90 }
91} 91}
@@ -291,7 +291,7 @@ int luaO_str2int (const char *s, size_t len, lua_Integer *result) {
291 while (lisspace(cast_uchar(*s))) s++; /* skip trailing spaces */ 291 while (lisspace(cast_uchar(*s))) s++; /* skip trailing spaces */
292 if (empty || s != ends) return 0; /* something wrong in the numeral */ 292 if (empty || s != ends) return 0; /* something wrong in the numeral */
293 else { 293 else {
294 *result = cast_u2s((neg) ? 0u - a : a); 294 *result = l_castU2S((neg) ? 0u - a : a);
295 return 1; 295 return 1;
296 } 296 }
297} 297}
diff --git a/ltable.c b/ltable.c
index 520ba98c..945123af 100644
--- a/ltable.c
+++ b/ltable.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltable.c,v 2.86 2014/04/13 21:11:19 roberto Exp roberto $ 2** $Id: ltable.c,v 2.87 2014/04/15 14:28:20 roberto Exp roberto $
3** Lua tables (hash) 3** Lua tables (hash)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -472,7 +472,7 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
472*/ 472*/
473const TValue *luaH_getint (Table *t, lua_Integer key) { 473const TValue *luaH_getint (Table *t, lua_Integer key) {
474 /* (1 <= key && key <= t->sizearray) */ 474 /* (1 <= key && key <= t->sizearray) */
475 if (cast_s2u(key - 1) < cast(unsigned int, t->sizearray)) 475 if (l_castS2U(key - 1) < cast(unsigned int, t->sizearray))
476 return &t->array[key - 1]; 476 return &t->array[key - 1];
477 else { 477 else {
478 Node *n = hashint(t, key); 478 Node *n = hashint(t, key);
diff --git a/lvm.c b/lvm.c
index 4efc2949..653e6a16 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.196 2014/04/11 19:02:16 roberto Exp roberto $ 2** $Id: lvm.c,v 2.197 2014/04/15 14:28:20 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -343,7 +343,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {
343 343
344 344
345lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y) { 345lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y) {
346 if (cast_s2u(y) + 1u <= 1u) { /* special cases: -1 or 0 */ 346 if (l_castS2U(y) + 1u <= 1u) { /* special cases: -1 or 0 */
347 if (y == 0) 347 if (y == 0)
348 luaG_runerror(L, "attempt to divide by zero"); 348 luaG_runerror(L, "attempt to divide by zero");
349 return intop(-, 0, x); /* y==-1; avoid overflow with 0x80000...//-1 */ 349 return intop(-, 0, x); /* y==-1; avoid overflow with 0x80000...//-1 */
@@ -359,7 +359,7 @@ lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y) {
359 359
360 360
361lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y) { 361lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y) {
362 if (cast_s2u(y) + 1u <= 1u) { /* special cases: -1 or 0 */ 362 if (l_castS2U(y) + 1u <= 1u) { /* special cases: -1 or 0 */
363 if (y == 0) 363 if (y == 0)
364 luaG_runerror(L, "attempt to perform 'n%%0'"); 364 luaG_runerror(L, "attempt to perform 'n%%0'");
365 return 0; /* y==-1; avoid overflow with 0x80000...%-1 */ 365 return 0; /* y==-1; avoid overflow with 0x80000...%-1 */
@@ -792,7 +792,7 @@ void luaV_execute (lua_State *L) {
792 TValue *rb = RB(i); 792 TValue *rb = RB(i);
793 lua_Integer ib; 793 lua_Integer ib;
794 if (tointeger(rb, &ib)) { 794 if (tointeger(rb, &ib)) {
795 setivalue(ra, intop(^, ~cast_s2u(0), ib)); 795 setivalue(ra, intop(^, ~l_castS2U(0), ib));
796 } 796 }
797 else { 797 else {
798 Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT)); 798 Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));
diff --git a/lvm.h b/lvm.h
index d85c3a4e..669cf391 100644
--- a/lvm.h
+++ b/lvm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.h,v 2.26 2014/03/31 18:37:52 roberto Exp roberto $ 2** $Id: lvm.h,v 2.27 2014/04/15 14:28:20 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -19,7 +19,7 @@
19#define tointeger(o,i) \ 19#define tointeger(o,i) \
20 (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger_(o,i)) 20 (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger_(o,i))
21 21
22#define intop(op,v1,v2) cast_u2s(cast_s2u(v1) op cast_s2u(v2)) 22#define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2))
23 23
24#define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) 24#define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2)
25 25