Skip to content

Commit

Permalink
FIX: Conversion of bitset to binary does not count with complement bi…
Browse files Browse the repository at this point in the history
…tset state

fixes: Oldes/Rebol-issues#2436
  • Loading branch information
Oldes committed Nov 2, 2020
1 parent 64aaf29 commit 7c409fb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/core/t-bitset.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

#define MAX_BITSET 0x7fffffff

#define BITS_NOT(s) ((s)->size)

// use if you want compatibility with R3-alpha for returning NONE on non existing bit
// #define PICK_BITSET_AS_NONE

Expand Down
6 changes: 5 additions & 1 deletion src/core/t-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ static REBSER *make_binary(REBVAL *arg, REBOOL make)

// MAKE/TO BINARY! <bitset!>
case REB_BITSET:
ser = Copy_Bytes(VAL_BIN(arg), VAL_TAIL(arg));
if(VAL_BITSET_NOT(arg)) {
ser = Complement_Binary(arg);
} else {
ser = Copy_Bytes(VAL_BIN(arg), VAL_TAIL(arg));
}
break;

// MAKE/TO BINARY! <image!>
Expand Down
4 changes: 3 additions & 1 deletion src/include/sys-value.h
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,9 @@ typedef struct Reb_Series_Ref
**
***********************************************************************/

#define VAL_BITSET(v) VAL_SERIES(v)
#define BITS_NOT(s) ((s)->size)
#define VAL_BITSET(v) VAL_SERIES(v)
#define VAL_BITSET_NOT(v) BITS_NOT(VAL_SERIES(v))

#define VAL_BIT_DATA(v) VAL_BIN(v)

Expand Down
9 changes: 8 additions & 1 deletion src/tests/units/bitset-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,14 @@
--test-- "issue-1271"
;@@ https://github.com/Oldes/Rebol-issues/issues/1271
chars: complement charset "ther "
--assert "it goes" = find "there it goes" chars
--assert "it goes" = find "there it goes" chars

--test-- "to-binary bitset"
;@@ https://github.com/Oldes/Rebol-issues/issues/2436
bits: make bitset! [1]
--assert #{40} = to binary! bits
--assert #{BF} = to binary! complement bits
--assert #{BF} = complement to binary! bits


===end-group===
Expand Down

0 comments on commit 7c409fb

Please sign in to comment.