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

WIP Towards C-compat: Store the capacity minus length as the trailing byte #82

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

KristofferC
Copy link
Member

@KristofferC KristofferC commented Jul 23, 2024

The point is that on master we have:

julia> reinterpret(UInt32, String3("a"))
0x61000001

julia> reinterpret(UInt32, String3("ab"))
0x61620002

julia> reinterpret(UInt32, String3("abc"))
0x61626303

Instead, with this PR we store the capacity minus the length as the last byte (and not the length itself) leading to:

julia> reinterpret(UInt32, String3("a"))
0x61000002

julia> reinterpret(UInt32, String3("ab"))
0x61620001

julia> reinterpret(UInt32, String3("abc"))
0x61626300

This means that in the case of the inline string being at full capacity the last byte double dips as a null terminator and showing that there is no capacity left (another way of saying that the length of the string is 3).

In order for "full C-compat" I think the byte order has to be swapped as well. I am not sure how worth this endeavour is tbh.

@KristofferC KristofferC changed the title Store the capacity minus length as the trailing byte in order for an inline string to be C-compatible Towards C-compat: Store the capacity minus length as the trailing byte Jul 23, 2024
@KristofferC KristofferC changed the title Towards C-compat: Store the capacity minus length as the trailing byte WIP Towards C-compat: Store the capacity minus length as the trailing byte Jul 24, 2024
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

Successfully merging this pull request may close these issues.

1 participant