From fd80e63468f0c08fedd8dbf944fa4954b72d7384 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 13 Jun 2011 11:13:06 -0300 Subject: configuration for NaN trick big-endian + macro 'luai_checknum' to ensure numbers comming from C are not "improper" (some kinds of signaling NaNs) --- lobject.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'lobject.h') diff --git a/lobject.h b/lobject.h index c130dcb6..5221ab68 100644 --- a/lobject.h +++ b/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 2.58 2011/06/07 19:02:33 roberto Exp roberto $ +** $Id: lobject.h,v 2.59 2011/06/09 18:21:25 roberto Exp roberto $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ @@ -262,7 +262,7 @@ typedef struct lua_TValue TValue; ** ======================================================= */ -#if defined(LUA_NANTRICK) +#if defined(LUA_NANTRICKLE) || defined(LUA_NANTRICKBE) /* ** numbers are represented in the 'd_' field. All other values have the @@ -270,11 +270,20 @@ typedef struct lua_TValue TValue; ** a "signaled NaN", which is never generated by regular operations by ** the CPU (nor by 'strtod') */ +#if !defined(NNMARK) #define NNMARK 0x7FF7A500 +#endif #undef TValuefields +#if defined(LUA_NANTRICKLE) +/* little endian */ #define TValuefields \ union { struct { Value v_; int tt_; } i; double d_; } u +#else +/* big endian */ +#define TValuefields \ + union { struct { int tt_; Value v_; } i; double d_; } u +#endif #undef numfield #define numfield /* no such field; numbers are the entire struct */ @@ -322,6 +331,14 @@ typedef struct lua_TValue TValue; (ttisnumber(o1) ? ttisnumber(o2) : ((o1)->u.i.tt_ == (o2)->u.i.tt_)) + +#define luai_checknum(L,o,c) { if (!ttisnumber(o)) c; } + + +#else + +#define luai_checknum(L,o,c) { /* empty */ } + #endif /* }====================================================== */ -- cgit v1.2.3-55-g6feb