Skip to content

Commit

Permalink
Fixed NaN boxing for 64-bit configrations on platforms that use full …
Browse files Browse the repository at this point in the history
…48-bit usermode pointers

Definition of boxed pointer is following:
`111111111111TTTT TTPPPPPPPPPPPPPP PPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPP`

Previously, only the last 32-bit were set, and remaining 14 bits were zeroed when setting `ttt`.
  • Loading branch information
dabroz committed Nov 21, 2016
1 parent d86f5d2 commit 8cdaf1e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/mruby/boxing_nan.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ typedef struct mrb_value {
#define mrb_fixnum(o) (o).value.i
#define mrb_symbol(o) (o).value.sym

#ifdef MRB_64BIT
#define BOXNAN_SHIFT_LONG_POINTER(v) (((uintptr_t)(v)>>34)&0x3fff)
#else
#define BOXNAN_SHIFT_LONG_POINTER(v) 0
#endif

#define BOXNAN_SET_VALUE(o, tt, attr, v) do {\
switch (tt) {\
case MRB_TT_FALSE:\
Expand All @@ -69,7 +75,7 @@ typedef struct mrb_value {
case MRB_TT_SYMBOL: (o).attr = (v); break;\
default: (o).value.i = 0; (o).value.p = (void*)((uintptr_t)(o).value.p | (((uintptr_t)(v))>>2)); break;\
}\
(o).value.ttt = (0xfff00000|(((tt)+1)<<14));\
(o).value.ttt = (0xfff00000|(((tt)+1)<<14)|BOXNAN_SHIFT_LONG_POINTER(v));\
} while (0)

#define SET_FLOAT_VALUE(mrb,r,v) do { \
Expand Down

0 comments on commit 8cdaf1e

Please sign in to comment.