Skip to content

Commit 7c409fb

Browse files
committed
FIX: Conversion of bitset to binary does not count with complement bitset state
fixes: Oldes/Rebol-issues#2436
1 parent 64aaf29 commit 7c409fb

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

src/core/t-bitset.c

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
#define MAX_BITSET 0x7fffffff
3333

34-
#define BITS_NOT(s) ((s)->size)
35-
3634
// use if you want compatibility with R3-alpha for returning NONE on non existing bit
3735
// #define PICK_BITSET_AS_NONE
3836

src/core/t-string.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,11 @@ static REBSER *make_binary(REBVAL *arg, REBOOL make)
249249

250250
// MAKE/TO BINARY! <bitset!>
251251
case REB_BITSET:
252-
ser = Copy_Bytes(VAL_BIN(arg), VAL_TAIL(arg));
252+
if(VAL_BITSET_NOT(arg)) {
253+
ser = Complement_Binary(arg);
254+
} else {
255+
ser = Copy_Bytes(VAL_BIN(arg), VAL_TAIL(arg));
256+
}
253257
break;
254258

255259
// MAKE/TO BINARY! <image!>

src/include/sys-value.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,9 @@ typedef struct Reb_Series_Ref
698698
**
699699
***********************************************************************/
700700

701-
#define VAL_BITSET(v) VAL_SERIES(v)
701+
#define BITS_NOT(s) ((s)->size)
702+
#define VAL_BITSET(v) VAL_SERIES(v)
703+
#define VAL_BITSET_NOT(v) BITS_NOT(VAL_SERIES(v))
702704

703705
#define VAL_BIT_DATA(v) VAL_BIN(v)
704706

src/tests/units/bitset-test.r3

+8-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,14 @@
273273
--test-- "issue-1271"
274274
;@@ https://github.com/Oldes/Rebol-issues/issues/1271
275275
chars: complement charset "ther "
276-
--assert "it goes" = find "there it goes" chars
276+
--assert "it goes" = find "there it goes" chars
277+
278+
--test-- "to-binary bitset"
279+
;@@ https://github.com/Oldes/Rebol-issues/issues/2436
280+
bits: make bitset! [1]
281+
--assert #{40} = to binary! bits
282+
--assert #{BF} = to binary! complement bits
283+
--assert #{BF} = complement to binary! bits
277284

278285

279286
===end-group===

0 commit comments

Comments
 (0)