Skip to content

Commit

Permalink
make bswap work for all sizes on 1.6+ (fix #23)
Browse files Browse the repository at this point in the history
On earlier versions, `Base.bswap_int` was segfaulting when
`sizeof` was not a multiple of 2.
  • Loading branch information
rfourquet committed Nov 26, 2021
1 parent c9a3e7e commit 883c261
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/BitIntegers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ leading_zeros( x::XBI) = Int(ctlz_int(x))
trailing_zeros(x::XBI) = Int(cttz_int(x))

function bswap(x::XBI)
if sizeof(x) % 2 != 0
if VERSION < v"1.6" && sizeof(x) % 2 != 0
# llvm instruction is invalid
error("unimplemented")
else
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ end
k, l = rand(Int(typemin(Int8)):-1, 2)
for X in XInts
for op in (~, bswap)
if sizeof(X) % 2 != 0 && op == bswap
if VERSION < v"1.6" && sizeof(X) % 2 != 0 && op == bswap
@test_throws ErrorException op(X(i))
continue
end
Expand Down

0 comments on commit 883c261

Please sign in to comment.