You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bugs caused by lack of GC.@preserveability of pointers to InineString #90
julia>functionfoo(s)
GC.@preserve s findfirst(==(0x0a), codeunits(s))
end
foo (generic function with 1 method)
julia> s =String7("abc\nss\n")
"abc\nss\n"
julia>foo(s) ===nothingtrue
Which is caused by:
julia> s =String7("abc\nss\n")
"abc\nss\n"
julia>functionfoo(s)
u =reinterpret(UInt, s)
GC.@preserve s begin
p =pointer(codeunits(s))
p2 =@ccallmemchr(p::Ptr{UInt8}, 0x0a::Cchar, 7::Csize_t)::Ptr{Nothing}
p2 ==C_NULL?nothing: p2 - p +1endend
foo (generic function with 1 method)
julia>foo(s) ===nothingtrue
Which I believe ultimately is caused by the lack of GC.@preserve in the pointer function.
To check it, let's compare:
julia>functionfoo(s)
GC.@preserve s begin
p =pointer(codeunits(s))
p2 =@ccallmemchr(p::Ptr{UInt8}, 0x0a::Cchar, 7::Csize_t)::Ptr{Nothing}
p2 ==C_NULL?nothing: p2 - p +1endend
foo (generic function with 1 method)
julia>functionbar(s)
r =Ref(bswap(reinterpret(UInt, s)))
GC.@preserve r begin
p =Ptr{UInt8}(pointer_from_objref(r))
p2 =@ccallmemchr(p::Ptr{UInt8}, 0x0a::Cchar, 7::Csize_t)::Ptr{Nothing}
p2 ==C_NULL?nothing: p2 - p +1endend
bar (generic function with 1 method)
julia>foo(s)
julia>bar(s)
0x0000000000000004
Note that foo and bar do the same thing - the definition of pointer(codeunits(::InlineString)) is just inlined into bar. The only difference is that in bar, the Ref is GC.@preserved, which it isn't in foo
changed the title [-]Something is very wrong with InlineString's pointer-based functions[/-][+]Bugs caused by lack of `GC.@preserve`ability of pointers to `InineString`[/+]on Sep 28, 2025
Activity
[-]Something is very wrong with InlineString's pointer-based functions[/-][+]Bugs caused by lack of `GC.@preserve`ability of pointers to `InineString`[/+]InlineStrings 2.0: C-compatible layout, safe codeunits, Base radix so…
quinnj commentedon Sep 4, 2026
Fixed in #94 by giving
codeunitsstable owned storage.