Browse Source

Add NaN normalization asserts to duk_tval macros

pull/297/head
Sami Vaarala 9 years ago
parent
commit
36d8a4f94c
  1. 6
      src/duk_error.h
  2. 20
      src/duk_tval.h

6
src/duk_error.h

@ -184,9 +184,9 @@
#if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_PACKED_TVAL) #if defined(DUK_USE_ASSERTIONS) && defined(DUK_USE_PACKED_TVAL)
#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) do { \ #define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) do { \
duk_double_union assert_tmp_du; \ duk_double_union duk__assert_tmp_du; \
assert_tmp_du.d = (dval); \ duk__assert_tmp_du.d = (dval); \
DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&assert_tmp_du)); \ DUK_ASSERT(DUK_DBLUNION_IS_NORMALIZED(&duk__assert_tmp_du)); \
} while (0) } while (0)
#else #else
#define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) /* nop */ #define DUK_ASSERT_DOUBLE_IS_NORMALIZED(dval) /* nop */

20
src/duk_tval.h

@ -153,12 +153,17 @@ typedef union duk_double_union duk_tval;
/* Assumes that caller has normalized NaNs, otherwise trouble ahead. */ /* Assumes that caller has normalized NaNs, otherwise trouble ahead. */
#if defined(DUK_USE_FASTINT) #if defined(DUK_USE_FASTINT)
#define DUK_TVAL_SET_DOUBLE(v,d) DUK_DBLUNION_SET_DOUBLE((v), (d)) #define DUK_TVAL_SET_DOUBLE(v,d) do { \
duk_double_t duk__dblval; \
duk__dblval = (d); \
DUK_ASSERT_DOUBLE_IS_NORMALIZED(duk__dblval); \
DUK_DBLUNION_SET_DOUBLE((v), duk__dblval); \
} while (0)
#define DUK_TVAL_SET_FASTINT(v,i) DUK__TVAL_SET_FASTINT((v), (i)) #define DUK_TVAL_SET_FASTINT(v,i) DUK__TVAL_SET_FASTINT((v), (i))
#define DUK_TVAL_SET_FASTINT_I32(v,i) DUK__TVAL_SET_FASTINT_I32((v), (i)) #define DUK_TVAL_SET_FASTINT_I32(v,i) DUK__TVAL_SET_FASTINT_I32((v), (i))
#define DUK_TVAL_SET_FASTINT_U32(v,i) DUK__TVAL_SET_FASTINT_U32((v), (i)) #define DUK_TVAL_SET_FASTINT_U32(v,i) DUK__TVAL_SET_FASTINT_U32((v), (i))
#define DUK_TVAL_SET_NUMBER_CHKFAST(v,d) duk_tval_set_number_chkfast((v), (d)) #define DUK_TVAL_SET_NUMBER_CHKFAST(v,d) duk_tval_set_number_chkfast((v), (d))
#define DUK_TVAL_SET_NUMBER(v,d) DUK_DBLUNION_SET_DOUBLE((v), (d)) #define DUK_TVAL_SET_NUMBER(v,d) DUK_TVAL_SET_DOUBLE((v), (d))
#define DUK_TVAL_CHKFAST_INPLACE(v) do { \ #define DUK_TVAL_CHKFAST_INPLACE(v) do { \
duk_tval *duk__tv; \ duk_tval *duk__tv; \
duk_double_t duk__d; \ duk_double_t duk__d; \
@ -169,9 +174,14 @@ typedef union duk_double_union duk_tval;
} \ } \
} while (0) } while (0)
#else #else
#define DUK_TVAL_SET_NUMBER(v,d) DUK_DBLUNION_SET_DOUBLE((v), (d)) #define DUK_TVAL_SET_DOUBLE(v,d) do { \
#define DUK_TVAL_SET_NUMBER_CHKFAST(v,d) DUK_TVAL_SET_NUMBER((v), (d)) duk_double_t duk__dblval; \
#define DUK_TVAL_SET_DOUBLE(v,d) DUK_TVAL_SET_NUMBER((v), (d)) duk__dblval = (d); \
DUK_ASSERT_DOUBLE_IS_NORMALIZED(duk__dblval); \
DUK_DBLUNION_SET_DOUBLE((v), duk__dblval); \
} while (0)
#define DUK_TVAL_SET_NUMBER_CHKFAST(v,d) DUK_TVAL_SET_DOUBLE((v), (d))
#define DUK_TVAL_SET_NUMBER(v,d) DUK_TVAL_SET_DOUBLE((v), (d))
#define DUK_TVAL_CHKFAST_INPLACE(v) do { } while (0) #define DUK_TVAL_CHKFAST_INPLACE(v) do { } while (0)
#endif #endif

Loading…
Cancel
Save