зеркало из https://github.com/github/ruby.git
Fix unaligned access to `double` in RFloat
This commit is contained in:
Родитель
e1ecda297e
Коммит
afdca0e780
|
@ -206,10 +206,22 @@ rb_float_flonum_value(VALUE v)
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
#if SIZEOF_VALUE >= SIZEOF_DOUBLE || defined(UNALIGNED_WORD_ACCESS)
|
||||
# define UNALIGNED_DOUBLE_ACCESS 1
|
||||
#else
|
||||
# define UNALIGNED_DOUBLE_ACCESS 0
|
||||
#endif
|
||||
|
||||
static inline double
|
||||
rb_float_noflonum_value(VALUE v)
|
||||
{
|
||||
#if UNALIGNED_DOUBLE_ACCESS
|
||||
return RFLOAT(v)->float_value;
|
||||
#else
|
||||
double d;
|
||||
memcpy(&d, &RFLOAT(v)->float_value, sizeof(double));
|
||||
return d;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline double
|
||||
|
|
|
@ -951,7 +951,11 @@ rb_float_new_in_heap(double d)
|
|||
{
|
||||
NEWOBJ_OF(flt, struct RFloat, rb_cFloat, T_FLOAT | (RGENGC_WB_PROTECTED_FLOAT ? FL_WB_PROTECTED : 0));
|
||||
|
||||
#if UNALIGNED_DOUBLE_ACCESS
|
||||
flt->float_value = d;
|
||||
#else
|
||||
memcpy(&flt->float_value, &d, sizeof(double));
|
||||
#endif
|
||||
OBJ_FREEZE((VALUE)flt);
|
||||
return (VALUE)flt;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче