configuration for NaN trick big-endian + macro 'luai_checknum' to
ensure numbers comming from C are not "improper" (some kinds of signaling NaNs)
This commit is contained in:
21
lobject.h
21
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
|
||||
/* }====================================================== */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user