diff options
author | Warner Losh <imp@FreeBSD.org> | 2018-02-23 04:04:18 +0000 |
---|---|---|
committer | Warner Losh <imp@FreeBSD.org> | 2018-02-23 04:04:18 +0000 |
commit | 07c17b2b00d8c1c8a2d58d4d8f99e64ec1182476 (patch) | |
tree | 306db484b77d89118dc228e4fabb04b547b133c7 /contrib/lua | |
parent | ff4cd9bfb12c6ac3a1a8483386673338def0fdf6 (diff) | |
download | src-test-07c17b2b00d8c1c8a2d58d4d8f99e64ec1182476.tar.gz src-test-07c17b2b00d8c1c8a2d58d4d8f99e64ec1182476.zip |
When the LUA_FLOAT_TYPE != LUA_FLOAT_INT64, we can't reference float
or double so ifdef that code out when the numbers aren't float at all.
There's still references in the lmathlib.c, but we don't compile that
for the loader yet.
Differential Revision: https://reviews.freebsd.org/D14472
Notes
Notes:
svn path=/head/; revision=329858
Diffstat (limited to 'contrib/lua')
-rw-r--r-- | contrib/lua/src/llimits.h | 2 | ||||
-rw-r--r-- | contrib/lua/src/lstrlib.c | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/contrib/lua/src/llimits.h b/contrib/lua/src/llimits.h index f21377fef981c..0bdd3db0120d2 100644 --- a/contrib/lua/src/llimits.h +++ b/contrib/lua/src/llimits.h @@ -66,7 +66,9 @@ typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; #else typedef union { lua_Number n; +#if LUA_FLOAT_TYPE != LUA_FLOAT_INT64 double u; +#endif void *s; lua_Integer i; long l; diff --git a/contrib/lua/src/lstrlib.c b/contrib/lua/src/lstrlib.c index 1d53765e57327..d6aac616add5c 100644 --- a/contrib/lua/src/lstrlib.c +++ b/contrib/lua/src/lstrlib.c @@ -1134,7 +1134,11 @@ static const union { /* dummy structure to get native alignment requirements */ struct cD { char c; - union { double d; void *p; lua_Integer i; lua_Number n; } u; + union { +#if LUA_FLOAT_TYPE != LUA_FLOAT_INT64 + double d; +#endif + void *p; lua_Integer i; lua_Number n; } u; }; #define MAXALIGN (offsetof(struct cD, u)) @@ -1144,8 +1148,10 @@ struct cD { ** Union for serializing floats */ typedef union Ftypes { +#if LUA_FLOAT_TYPE != LUA_FLOAT_INT64 float f; double d; +#endif lua_Number n; char buff[5 * sizeof(lua_Number)]; /* enough for any float type */ } Ftypes; @@ -1235,8 +1241,10 @@ static KOption getoption (Header *h, const char **fmt, int *size) { case 'j': *size = sizeof(lua_Integer); return Kint; case 'J': *size = sizeof(lua_Integer); return Kuint; case 'T': *size = sizeof(size_t); return Kuint; +#if LUA_FLOAT_TYPE != LUA_FLOAT_INT64 case 'f': *size = sizeof(float); return Kfloat; case 'd': *size = sizeof(double); return Kfloat; +#endif case 'n': *size = sizeof(lua_Number); return Kfloat; case 'i': *size = getnumlimit(h, fmt, sizeof(int)); return Kint; case 'I': *size = getnumlimit(h, fmt, sizeof(int)); return Kuint; @@ -1369,9 +1377,13 @@ static int str_pack (lua_State *L) { volatile Ftypes u; char *buff = luaL_prepbuffsize(&b, size); lua_Number n = luaL_checknumber(L, arg); /* get argument */ +#if LUA_FLOAT_TYPE != LUA_FLOAT_INT64 if (size == sizeof(u.f)) u.f = (float)n; /* copy it into 'u' */ else if (size == sizeof(u.d)) u.d = (double)n; else u.n = n; +#else + u.n = n; +#endif /* move 'u' to final result, correcting endianness if needed */ copywithendian(buff, u.buff, size, h.islittle); luaL_addsize(&b, size); @@ -1507,9 +1519,13 @@ static int str_unpack (lua_State *L) { volatile Ftypes u; lua_Number num; copywithendian(u.buff, data + pos, size, h.islittle); +#if LUA_FLOAT_TYPE != LUA_FLOAT_INT64 if (size == sizeof(u.f)) num = (lua_Number)u.f; else if (size == sizeof(u.d)) num = (lua_Number)u.d; else num = u.n; +#else + num = u.n; +#endif lua_pushnumber(L, num); break; } |