Skip to content

Make InlineStrings have the same byte order as C-strings - #82

Closed
KristofferC wants to merge 1 commit into
JuliaStrings:mainfrom
KristofferC:kc/c_compat
Closed

KristofferC wants to merge 1 commit into
JuliaStrings:mainfrom
KristofferC:kc/c_compat

Conversation

@KristofferC

@KristofferC KristofferC commented Jul 23, 2024 •

Copy link
Copy Markdown
Member

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).

@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
@codecov

codecov Bot commented Sep 29, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.93617% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.48%. Comparing base (15cd44b) to head (8ffbd13).

Files with missing lines Patch % Lines
src/InlineStrings.jl 98.93% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #82      +/-   ##
==========================================
+ Coverage   93.23%   93.48%   +0.24%     
==========================================
  Files           3        3              
  Lines         636      645       +9     
==========================================
+ Hits          593      603      +10     
+ Misses         43       42       -1     

☔ View full report in Codecov by Harness.
📢 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.

…nversion to a pointer to pass into C-functions
@quinnj

quinnj commented Jun 16, 2026

Copy link
Copy Markdown
Member

Sorry for the slowness here; yes, I'd like to do this. I'm worried about breaking the serialized string case and not being able to read them back unless we do a major version bump? or maybe we provide a best effort compat shim to try and figure out which direction a serialized string should be read as? I think that could probably be 95%+ accurate, but not sure if that would get us in trouble or not.

quinnj added a commit that referenced this pull request Sep 4, 2026
…rt (#94)

* InlineStrings 2.0: C-compatible layout, safe codeunits, Base radix sort

Store codeunits in String order with a trailing capacity byte that doubles
as the NUL terminator (from #82), so inline strings can be passed straight
to C via `Ref`. Rework every operation around the new layout, with a byte
tuple for random access on the wide types.

Also:
- `write`/`print` write codeunits like `String`; Serialization via extension
- `codeunits` returns a non-Dense vector and `pointer` throws (#90)
- Base `UIntMappable` hooks replace the custom radix sort (#64 defalg)
- resolve all Aqua ambiguities and run Aqua in CI (#64)
- fix matrix alignment (#89), `isascii` tail bytes, `reverse` of 2/3-byte
  chars, mixed `String`/inline `cmp`, `isvalid` out of range, buffer
  constructor bounds, non-UInt8 code unit sources (from #92)
- `map`/`filter`/`uppercase`/`lowercase` keep the inline type (#5)
- minimum Julia 1.10, Parsers as a weak dependency

Co-authored-by: Kristoffer Carlsson <kcarlsson89@gmail.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Test the Arrow extension through ArrowTypes; move Arrow.jl and TimeZones.jl to the integration workflow

Arrow.jl depends on TimeZones.jl, which pins InlineStrings 1, so a 2.0 test
environment resolves TimeZones 1.5.9 whose build step fails on Julia 1.12.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Drop arrow-julia from the integration matrix until TimeZones.jl bumps its InlineStrings compat

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Compute the first UTF-8 byte directly; Base.first_utf8_byte is gone on Julia 1.13

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix(core): harden v2 string operations

Fix overflow-safe buffer bounds, single-pass map fallback, cross-encoding chop operations, collection widening, and search index validation.

Speed up wide slicing, long-needle searches, and empty-string repetition. Add focused regressions and a migration-only invalidation budget.

---------

Co-authored-by: Kristoffer Carlsson <kcarlsson89@gmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
@quinnj

quinnj commented Sep 4, 2026

Copy link
Copy Markdown
Member

Superseded by #94, which is now merged for 2.0. Thanks @KristofferC!

@quinnj quinnj closed this Sep 4, 2026
@KristofferC

Copy link
Copy Markdown
Member Author

🎉

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.

2 participants