Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UInt24 : cannot convert to/from big endian format #23

Closed
tk3369 opened this issue Nov 26, 2021 · 2 comments
Closed

UInt24 : cannot convert to/from big endian format #23

tk3369 opened this issue Nov 26, 2021 · 2 comments

Comments

@tk3369
Copy link

tk3369 commented Nov 26, 2021

Hi, this is a great package! Thanks.

I'm trying to use this for a project that requires UInt24. Because I have to handle big endian, I normally just call ntoh and hton when reading/writing such data. However:

julia> BitIntegers.@define_integers 24
@uint24_str (macro with 1 method)

julia> UInt24(0x010203)
0x010203

julia> hton(UInt24(0x010203))
ERROR: unimplemented
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] bswap(x::UInt24)
   @ BitIntegers ~/.julia/dev/BitIntegers/src/BitIntegers.jl:356
 [3] hton(x::UInt24)
   @ Base ./io.jl:568
@tk3369
Copy link
Author

tk3369 commented Nov 26, 2021

If I replace the bswap function with:

function bswap(x::XBI)
    return bswap_int(x)
end

Then it seems to work correctly.

julia> hton(UInt24(0x010203))
0x030201

The comment says LLVM instruction is invalid though...

function bswap(x::XBI)
if sizeof(x) % 2 != 0
# llvm instruction is invalid
error("unimplemented")
else
bswap_int(x)
end
end

@rfourquet
Copy link
Owner

Thanks for your issue! It indeed works now. Up until julia v1.5, it was segfaulting (at least on my machine). I will enable this function on 1.6+.

rfourquet added a commit that referenced this issue Nov 26, 2021
On earlier versions, `Base.bswap_int` was segfaulting when
`sizeof` was not a multiple of 2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants