Using LUAI_UAC* types more consistently on vararg calls

This commit is contained in:
Roberto Ierusalimschy
2016-12-20 16:37:00 -02:00
parent 24f6e236a3
commit 9903dd52a3
5 changed files with 35 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lauxlib.c,v 1.287 2016/12/04 20:09:45 roberto Exp roberto $ ** $Id: lauxlib.c,v 1.288 2016/12/04 20:17:24 roberto Exp roberto $
** Auxiliary functions for building Lua libraries ** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -816,9 +816,9 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
switch (lua_type(L, idx)) { switch (lua_type(L, idx)) {
case LUA_TNUMBER: { case LUA_TNUMBER: {
if (lua_isinteger(L, idx)) if (lua_isinteger(L, idx))
lua_pushfstring(L, "%I", lua_tointeger(L, idx)); lua_pushfstring(L, "%I", (LUAI_UACINT)lua_tointeger(L, idx));
else else
lua_pushfstring(L, "%f", lua_tonumber(L, idx)); lua_pushfstring(L, "%f", (LUAI_UACNUMBER)lua_tonumber(L, idx));
break; break;
} }
case LUA_TSTRING: case LUA_TSTRING:
@@ -1038,6 +1038,6 @@ LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) {
luaL_error(L, "multiple Lua VMs detected"); luaL_error(L, "multiple Lua VMs detected");
else if (*v != ver) else if (*v != ver)
luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f", luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f",
ver, *v); (LUAI_UACNUMBER)ver, (LUAI_UACNUMBER)*v);
} }

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: liolib.c,v 2.149 2016/05/02 14:03:19 roberto Exp roberto $ ** $Id: liolib.c,v 2.150 2016/09/01 16:14:56 roberto Exp roberto $
** Standard I/O (and system) library ** Standard I/O (and system) library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -619,8 +619,10 @@ static int g_write (lua_State *L, FILE *f, int arg) {
if (lua_type(L, arg) == LUA_TNUMBER) { if (lua_type(L, arg) == LUA_TNUMBER) {
/* optimization: could be done exactly as for strings */ /* optimization: could be done exactly as for strings */
int len = lua_isinteger(L, arg) int len = lua_isinteger(L, arg)
? fprintf(f, LUA_INTEGER_FMT, lua_tointeger(L, arg)) ? fprintf(f, LUA_INTEGER_FMT,
: fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)); (LUAI_UACINT)lua_tointeger(L, arg))
: fprintf(f, LUA_NUMBER_FMT,
(LUAI_UACNUMBER)lua_tonumber(L, arg));
status = status && (len > 0); status = status && (len > 0);
} }
else { else {

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lmathlib.c,v 1.116 2015/06/26 19:30:32 roberto Exp $ ** $Id: lmathlib.c,v 1.117 2015/10/02 15:39:23 roberto Exp roberto $
** Standard mathematical library ** Standard mathematical library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -184,10 +184,13 @@ static int math_log (lua_State *L) {
else { else {
lua_Number base = luaL_checknumber(L, 2); lua_Number base = luaL_checknumber(L, 2);
#if !defined(LUA_USE_C89) #if !defined(LUA_USE_C89)
if (base == 2.0) res = l_mathop(log2)(x); else if (base == l_mathop(2.0))
res = l_mathop(log2)(x); else
#endif #endif
if (base == 10.0) res = l_mathop(log10)(x); if (base == l_mathop(10.0))
else res = l_mathop(log)(x)/l_mathop(log)(base); res = l_mathop(log10)(x);
else
res = l_mathop(log)(x)/l_mathop(log)(base);
} }
lua_pushnumber(L, res); lua_pushnumber(L, res);
return 1; return 1;

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lstrlib.c,v 1.251 2016/05/20 14:13:21 roberto Exp roberto $ ** $Id: lstrlib.c,v 1.252 2016/06/27 13:15:08 roberto Exp roberto $
** Standard library for string operations and pattern-matching ** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -839,11 +839,12 @@ static lua_Number adddigit (char *buff, int n, lua_Number x) {
static int num2straux (char *buff, int sz, lua_Number x) { static int num2straux (char *buff, int sz, lua_Number x) {
if (x != x || x == HUGE_VAL || x == -HUGE_VAL) /* inf or NaN? */ /* if 'inf' or 'NaN', format it like '%g' */
return l_sprintf(buff, sz, LUA_NUMBER_FMT, x); /* equal to '%g' */ if (x != x || x == (lua_Number)HUGE_VAL || x == -(lua_Number)HUGE_VAL)
return l_sprintf(buff, sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)x);
else if (x == 0) { /* can be -0... */ else if (x == 0) { /* can be -0... */
/* create "0" or "-0" followed by exponent */ /* create "0" or "-0" followed by exponent */
return l_sprintf(buff, sz, LUA_NUMBER_FMT "x0p+0", x); return l_sprintf(buff, sz, LUA_NUMBER_FMT "x0p+0", (LUAI_UACNUMBER)x);
} }
else { else {
int e; int e;
@@ -960,7 +961,7 @@ static void addliteral (lua_State *L, luaL_Buffer *b, int arg) {
const char *format = (n == LUA_MININTEGER) /* corner case? */ const char *format = (n == LUA_MININTEGER) /* corner case? */
? "0x%" LUA_INTEGER_FRMLEN "x" /* use hexa */ ? "0x%" LUA_INTEGER_FRMLEN "x" /* use hexa */
: LUA_INTEGER_FMT; /* else use default format */ : LUA_INTEGER_FMT; /* else use default format */
nb = l_sprintf(buff, MAX_ITEM, format, n); nb = l_sprintf(buff, MAX_ITEM, format, (LUAI_UACINT)n);
} }
luaL_addsize(b, nb); luaL_addsize(b, nb);
break; break;
@@ -1041,7 +1042,7 @@ static int str_format (lua_State *L) {
case 'o': case 'u': case 'x': case 'X': { case 'o': case 'u': case 'x': case 'X': {
lua_Integer n = luaL_checkinteger(L, arg); lua_Integer n = luaL_checkinteger(L, arg);
addlenmod(form, LUA_INTEGER_FRMLEN); addlenmod(form, LUA_INTEGER_FRMLEN);
nb = l_sprintf(buff, MAX_ITEM, form, n); nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACINT)n);
break; break;
} }
case 'a': case 'A': case 'a': case 'A':
@@ -1051,8 +1052,9 @@ static int str_format (lua_State *L) {
break; break;
case 'e': case 'E': case 'f': case 'e': case 'E': case 'f':
case 'g': case 'G': { case 'g': case 'G': {
lua_Number n = luaL_checknumber(L, arg);
addlenmod(form, LUA_NUMBER_FRMLEN); addlenmod(form, LUA_NUMBER_FRMLEN);
nb = l_sprintf(buff, MAX_ITEM, form, luaL_checknumber(L, arg)); nb = l_sprintf(buff, MAX_ITEM, form, (LUAI_UACNUMBER)n);
break; break;
} }
case 'q': { case 'q': {

View File

@@ -1,5 +1,5 @@
/* /*
** $Id: luaconf.h,v 1.256 2016/07/18 17:55:59 roberto Exp roberto $ ** $Id: luaconf.h,v 1.257 2016/08/22 17:21:12 roberto Exp roberto $
** Configuration file for Lua ** Configuration file for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -416,7 +416,7 @@
/* /*
@@ LUA_NUMBER is the floating-point type used by Lua. @@ LUA_NUMBER is the floating-point type used by Lua.
@@ LUAI_UACNUMBER is the result of an 'usual argument conversion' @@ LUAI_UACNUMBER is the result of a 'default argument promotion'
@@ over a floating number. @@ over a floating number.
@@ l_mathlim(x) corrects limit name 'x' to the proper float type @@ l_mathlim(x) corrects limit name 'x' to the proper float type
** by prefixing it with one of FLT/DBL/LDBL. ** by prefixing it with one of FLT/DBL/LDBL.
@@ -433,7 +433,8 @@
#define l_floor(x) (l_mathop(floor)(x)) #define l_floor(x) (l_mathop(floor)(x))
#define lua_number2str(s,sz,n) l_sprintf((s), sz, LUA_NUMBER_FMT, (n)) #define lua_number2str(s,sz,n) \
l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n))
/* /*
@@ lua_numbertointeger converts a float number to an integer, or @@ lua_numbertointeger converts a float number to an integer, or
@@ -510,7 +511,7 @@
** **
@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER. @@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.
** **
@@ LUAI_UACINT is the result of an 'usual argument conversion' @@ LUAI_UACINT is the result of a 'default argument promotion'
@@ over a lUA_INTEGER. @@ over a lUA_INTEGER.
@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers. @@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.
@@ LUA_INTEGER_FMT is the format for writing integers. @@ LUA_INTEGER_FMT is the format for writing integers.
@@ -523,10 +524,12 @@
/* The following definitions are good for most cases here */ /* The following definitions are good for most cases here */
#define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d" #define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d"
#define lua_integer2str(s,sz,n) l_sprintf((s), sz, LUA_INTEGER_FMT, (n))
#define LUAI_UACINT LUA_INTEGER #define LUAI_UACINT LUA_INTEGER
#define lua_integer2str(s,sz,n) \
l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n))
/* /*
** use LUAI_UACINT here to avoid problems with promotions (which ** use LUAI_UACINT here to avoid problems with promotions (which
** can turn a comparison between unsigneds into a signed comparison) ** can turn a comparison between unsigneds into a signed comparison)
@@ -624,7 +627,8 @@
** provide its own implementation. ** provide its own implementation.
*/ */
#if !defined(LUA_USE_C89) #if !defined(LUA_USE_C89)
#define lua_number2strx(L,b,sz,f,n) ((void)L, l_sprintf(b,sz,f,n)) #define lua_number2strx(L,b,sz,f,n) \
((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))
#endif #endif