Skip to content

Commit aacacc9

Browse files
committed
FIX: incorrectly dealing with vector item's width
resolves: Oldes/Rebol-issues#2518 related: Oldes/Rebol-issues#2515
1 parent 7089e80 commit aacacc9

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/core/t-string.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static REBSER *make_binary(REBVAL *arg, REBOOL make)
234234
// MAKE/TO BINARY! <vector!>
235235
case REB_VECTOR:
236236
// result is in little-endian!
237-
ser = Copy_Bytes(VAL_BIN_DATA(arg), VAL_LEN(arg) * VAL_VEC_WIDTH(arg));
237+
ser = Copy_Bytes(VAL_DATA(arg), VAL_LEN(arg) * VAL_VEC_WIDTH(arg));
238238
break;
239239

240240
case REB_BLOCK:

src/core/t-vector.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ static void reverse_vector(REBVAL *value, REBCNT len)
708708
}
709709
}
710710
else if (width == 4) {
711-
REBCNT *i4 = (REBCNT*)VAL_BIN_DATA(value);
711+
REBCNT *i4 = (REBCNT*)VAL_DATA(value);
712712
REBCNT c4;
713713
for (n = 0, m = len-1; n < len / 2; n++, m--) {
714714
c4 = i4[n];
@@ -717,7 +717,7 @@ static void reverse_vector(REBVAL *value, REBCNT len)
717717
}
718718
}
719719
else if (width == 8) {
720-
REBU64 *i8 = (REBU64*)VAL_BIN_DATA(value);
720+
REBU64 *i8 = (REBU64*)VAL_DATA(value);
721721
REBU64 c8;
722722
for (n = 0, m = len-1; n < len / 2; n++, m--) {
723723
c8 = i8[n];

src/tests/units/vector-test.r3

+10
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ Rebol [
6868

6969
--test-- "to-binary vector!"
7070
--assert #{01000200} = to binary! #[u16! [1 2]]
71+
--assert #{0100000002000000} = to binary! #[i32! [1 2]]
72+
--assert #{0000803F00000040} = to binary! #[f32! [1 2]]
73+
--assert #{01000000000000000200000000000000} = to binary! #[i64! [1 2]]
74+
--assert #{000000000000F03F0000000000000040} = to binary! #[f64! [1 2]]
75+
;@@ https://github.com/Oldes/Rebol-issues/issues/2518
76+
--assert #{0200} = to binary! next #[u16! [1 2]]
77+
--assert #{02000000} = to binary! next #[i32! [1 2]]
78+
--assert #{00000040} = to binary! next #[f32! [1 2]]
79+
--assert #{0200000000000000} = to binary! next #[i64! [1 2]]
80+
--assert #{0000000000000040} = to binary! next #[f64! [1 2]]
7181
;@@ https://github.com/Oldes/Rebol-issues/issues/2458
7282
--assert #{01000200} = to binary! protect #[u16! [1 2]]
7383

0 commit comments

Comments
 (0)