Skip to content

Commit

Permalink
FIX: incorrectly dealing with vector item's width
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Sep 6, 2022
1 parent 7089e80 commit aacacc9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/t-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ static REBSER *make_binary(REBVAL *arg, REBOOL make)
// MAKE/TO BINARY! <vector!>
case REB_VECTOR:
// result is in little-endian!
ser = Copy_Bytes(VAL_BIN_DATA(arg), VAL_LEN(arg) * VAL_VEC_WIDTH(arg));
ser = Copy_Bytes(VAL_DATA(arg), VAL_LEN(arg) * VAL_VEC_WIDTH(arg));
break;

case REB_BLOCK:
Expand Down
4 changes: 2 additions & 2 deletions src/core/t-vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ static void reverse_vector(REBVAL *value, REBCNT len)
}
}
else if (width == 4) {
REBCNT *i4 = (REBCNT*)VAL_BIN_DATA(value);
REBCNT *i4 = (REBCNT*)VAL_DATA(value);
REBCNT c4;
for (n = 0, m = len-1; n < len / 2; n++, m--) {
c4 = i4[n];
Expand All @@ -717,7 +717,7 @@ static void reverse_vector(REBVAL *value, REBCNT len)
}
}
else if (width == 8) {
REBU64 *i8 = (REBU64*)VAL_BIN_DATA(value);
REBU64 *i8 = (REBU64*)VAL_DATA(value);
REBU64 c8;
for (n = 0, m = len-1; n < len / 2; n++, m--) {
c8 = i8[n];
Expand Down
10 changes: 10 additions & 0 deletions src/tests/units/vector-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ Rebol [

--test-- "to-binary vector!"
--assert #{01000200} = to binary! #[u16! [1 2]]
--assert #{0100000002000000} = to binary! #[i32! [1 2]]
--assert #{0000803F00000040} = to binary! #[f32! [1 2]]
--assert #{01000000000000000200000000000000} = to binary! #[i64! [1 2]]
--assert #{000000000000F03F0000000000000040} = to binary! #[f64! [1 2]]
;@@ https://github.com/Oldes/Rebol-issues/issues/2518
--assert #{0200} = to binary! next #[u16! [1 2]]
--assert #{02000000} = to binary! next #[i32! [1 2]]
--assert #{00000040} = to binary! next #[f32! [1 2]]
--assert #{0200000000000000} = to binary! next #[i64! [1 2]]
--assert #{0000000000000040} = to binary! next #[f64! [1 2]]
;@@ https://github.com/Oldes/Rebol-issues/issues/2458
--assert #{01000200} = to binary! protect #[u16! [1 2]]

Expand Down

0 comments on commit aacacc9

Please sign in to comment.