Skip to content

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
@KristofferC KristofferC changed the title WIP Towards C-compat: Store the capacity minus length as the trailing byte Make InlineStrings have the same byte order as C-strings Sep 29, 2025
KristofferC and others added 2 commits September 29, 2025 13:43
This adds a clean abstraction layer for all bit manipulation operations
and updates the codebase to use these abstractions instead of raw bit
operations.

Key changes:
- Add byte access functions: get_byte(), set_byte()
- Add capacity management: get_capacity_byte(), set_capacity_byte()
- Add data manipulation: get_string_data(), resize_string_data()
- Add byte clearing: clear_suffix_bytes(), clear_prefix_bytes()
- Update all functions to use abstractions instead of raw bit ops
- Refactor addcodeunit() to use clean abstractions
- Update constructors and type conversions to use abstractions

All existing functionality maintained, 4495+ tests pass.
Foundation for future C-compatibility improvements.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…nversion to a pointer to pass into C-functions
Copy link

codecov bot commented Sep 29, 2025

Codecov Report

❌ Patch coverage is 99.18033% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.62%. Comparing base (98907bc) to head (9c6f48f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/InlineStrings.jl 99.18% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #82      +/-   ##
==========================================
+ Coverage   93.23%   93.62%   +0.38%     
==========================================
  Files           3        3              
  Lines         636      690      +54     
==========================================
+ Hits          593      646      +53     
- Misses         43       44       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@KristofferC
Copy link
Member Author

I poked on this together with Claude to finish it up. The first commit is to add some abstractions, the second one actualyl does the byte order swap. Needs benchmarking etc.

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