mirror of https://github.com/lua/lua
cast_u2s/cast_s2u renamed l_castS2U/l_castU2S to be configurable from
outside (mostly for testing)
This commit is contained in:
parent
8f961da3db
commit
037a70dfea
6
lapi.c
6
lapi.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lapi.c,v 2.203 2014/04/12 14:45:10 roberto Exp roberto $
|
||||
** $Id: lapi.c,v 2.204 2014/04/15 14:29:30 roberto Exp roberto $
|
||||
** Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -376,7 +376,7 @@ LUA_API lua_Unsigned lua_tounsignedx (lua_State *L, int idx, int *pisnum) {
|
|||
int isnum = 0;
|
||||
switch (ttype(o)) {
|
||||
case LUA_TNUMINT: {
|
||||
res = cast_s2u(ivalue(o));
|
||||
res = l_castS2U(ivalue(o));
|
||||
isnum = 1;
|
||||
break;
|
||||
}
|
||||
|
@ -514,7 +514,7 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
|
|||
|
||||
LUA_API void lua_pushunsigned (lua_State *L, lua_Unsigned u) {
|
||||
lua_lock(L);
|
||||
setivalue(L->top, cast_u2s(u));
|
||||
setivalue(L->top, l_castU2S(u));
|
||||
api_incr_top(L);
|
||||
lua_unlock(L);
|
||||
}
|
||||
|
|
14
llimits.h
14
llimits.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: llimits.h,v 1.114 2014/04/12 14:45:10 roberto Exp roberto $
|
||||
** $Id: llimits.h,v 1.115 2014/04/15 14:28:20 roberto Exp roberto $
|
||||
** Limits, basic types, and some other `installation-dependent' definitions
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -107,15 +107,19 @@ typedef LUAI_UACINT l_uacInt;
|
|||
#define cast_uchar(i) cast(unsigned char, (i))
|
||||
|
||||
|
||||
/* cast a signed lua_Integer to lua_Unsigned */
|
||||
#if !defined(l_castS2U)
|
||||
#define l_castS2U(i) ((lua_Unsigned)(i))
|
||||
#endif
|
||||
|
||||
/*
|
||||
** cast a lua_Unsigned to a signed lua_Integer; this cast is
|
||||
** not strict ANSI C, but two-complement architectures should
|
||||
** work fine.
|
||||
*/
|
||||
#define cast_u2s(i) ((lua_Integer)(i))
|
||||
|
||||
/* cast a signed lua_Integer to lua_Unsigned */
|
||||
#define cast_s2u(i) ((lua_Unsigned)(i))
|
||||
#if !defined(l_castU2S)
|
||||
#define l_castU2S(i) ((lua_Integer)(i))
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lobject.c,v 2.78 2014/04/11 19:52:26 roberto Exp roberto $
|
||||
** $Id: lobject.c,v 2.79 2014/04/15 14:28:20 roberto Exp roberto $
|
||||
** Some generic functions over Lua objects
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -85,7 +85,7 @@ static lua_Integer intarith (lua_State *L, int op, lua_Integer v1,
|
|||
case LUA_OPSHL: return luaV_shiftl(v1, v2);
|
||||
case LUA_OPSHR: return luaV_shiftl(v1, -v2);
|
||||
case LUA_OPUNM: return intop(-, 0, v1);
|
||||
case LUA_OPBNOT: return intop(^, ~cast_s2u(0), v1);
|
||||
case LUA_OPBNOT: return intop(^, ~l_castS2U(0), v1);
|
||||
default: lua_assert(0); return 0;
|
||||
}
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ int luaO_str2int (const char *s, size_t len, lua_Integer *result) {
|
|||
while (lisspace(cast_uchar(*s))) s++; /* skip trailing spaces */
|
||||
if (empty || s != ends) return 0; /* something wrong in the numeral */
|
||||
else {
|
||||
*result = cast_u2s((neg) ? 0u - a : a);
|
||||
*result = l_castU2S((neg) ? 0u - a : a);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
4
ltable.c
4
ltable.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: ltable.c,v 2.86 2014/04/13 21:11:19 roberto Exp roberto $
|
||||
** $Id: ltable.c,v 2.87 2014/04/15 14:28:20 roberto Exp roberto $
|
||||
** Lua tables (hash)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -472,7 +472,7 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
|
|||
*/
|
||||
const TValue *luaH_getint (Table *t, lua_Integer key) {
|
||||
/* (1 <= key && key <= t->sizearray) */
|
||||
if (cast_s2u(key - 1) < cast(unsigned int, t->sizearray))
|
||||
if (l_castS2U(key - 1) < cast(unsigned int, t->sizearray))
|
||||
return &t->array[key - 1];
|
||||
else {
|
||||
Node *n = hashint(t, key);
|
||||
|
|
8
lvm.c
8
lvm.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lvm.c,v 2.196 2014/04/11 19:02:16 roberto Exp roberto $
|
||||
** $Id: lvm.c,v 2.197 2014/04/15 14:28:20 roberto Exp roberto $
|
||||
** Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -343,7 +343,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {
|
|||
|
||||
|
||||
lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y) {
|
||||
if (cast_s2u(y) + 1u <= 1u) { /* special cases: -1 or 0 */
|
||||
if (l_castS2U(y) + 1u <= 1u) { /* special cases: -1 or 0 */
|
||||
if (y == 0)
|
||||
luaG_runerror(L, "attempt to divide by zero");
|
||||
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) {
|
|||
|
||||
|
||||
lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y) {
|
||||
if (cast_s2u(y) + 1u <= 1u) { /* special cases: -1 or 0 */
|
||||
if (l_castS2U(y) + 1u <= 1u) { /* special cases: -1 or 0 */
|
||||
if (y == 0)
|
||||
luaG_runerror(L, "attempt to perform 'n%%0'");
|
||||
return 0; /* y==-1; avoid overflow with 0x80000...%-1 */
|
||||
|
@ -792,7 +792,7 @@ void luaV_execute (lua_State *L) {
|
|||
TValue *rb = RB(i);
|
||||
lua_Integer ib;
|
||||
if (tointeger(rb, &ib)) {
|
||||
setivalue(ra, intop(^, ~cast_s2u(0), ib));
|
||||
setivalue(ra, intop(^, ~l_castS2U(0), ib));
|
||||
}
|
||||
else {
|
||||
Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));
|
||||
|
|
4
lvm.h
4
lvm.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lvm.h,v 2.26 2014/03/31 18:37:52 roberto Exp roberto $
|
||||
** $Id: lvm.h,v 2.27 2014/04/15 14:28:20 roberto Exp roberto $
|
||||
** Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -19,7 +19,7 @@
|
|||
#define tointeger(o,i) \
|
||||
(ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger_(o,i))
|
||||
|
||||
#define intop(op,v1,v2) cast_u2s(cast_s2u(v1) op cast_s2u(v2))
|
||||
#define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2))
|
||||
|
||||
#define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2)
|
||||
|
||||
|
|
Loading…
Reference in New Issue