diff options
author | Nobuyoshi Nakada <[email protected]> | 2023-11-26 00:28:36 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2023-11-26 11:42:02 +0900 |
commit | 7fe7b7bc5a7a3d79280c9dbf2a2383d386386b0f (patch) | |
tree | 2894afd71d3565eefefad51952a854e08df9da3e /compile.c | |
parent | 003f06bde40008159e871411cae5a928121490ba (diff) |
Fix portability of bignum in ISeq Binary Format
- Unless `sizeof(BDIGIT) == 4`, (8-byte integer not available), the
size to be loaded was wrong.
- Since `BDIGIT`s are dumped as raw binary, the loaded byte order was
inverted unless little-endian.
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -12859,8 +12859,12 @@ ibf_load_object_bignum(const struct ibf_load *load, const struct ibf_object_head const struct ibf_object_bignum *bignum = IBF_OBJBODY(struct ibf_object_bignum, offset); int sign = bignum->slen > 0; ssize_t len = sign > 0 ? bignum->slen : -1 * bignum->slen; - VALUE obj = rb_integer_unpack(bignum->digits, len * 2, 2, 0, - INTEGER_PACK_LITTLE_ENDIAN | (sign == 0 ? INTEGER_PACK_NEGATIVE : 0)); + const int big_unpack_flags = /* c.f. rb_big_unpack() */ + INTEGER_PACK_LSWORD_FIRST | + INTEGER_PACK_NATIVE_BYTE_ORDER; + VALUE obj = rb_integer_unpack(bignum->digits, len, sizeof(BDIGIT), 0, + big_unpack_flags | + (sign == 0 ? INTEGER_PACK_NEGATIVE : 0)); if (header->internal) rb_obj_hide(obj); if (header->frozen) rb_obj_freeze(obj); return obj; |