Skip to content

Move embedded-NUL error of cconvert(Cstring, ::InlineString) into @noinline function - #101

Merged
quinnj-bot[bot] merged 1 commit into
JuliaStrings:mainfrom
ParadaCarleton:noinline-cstring-error
Nov 25, 2026
Merged

quinnj-bot[bot] merged 1 commit into
JuliaStrings:mainfrom
ParadaCarleton:noinline-cstring-error

Conversation

@ParadaCarleton

@ParadaCarleton ParadaCarleton commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

+@noinline throw_embedded_nul(x::InlineString) =
+    throw(ArgumentError("embedded NULs are not allowed in C strings: $(repr(x))"))
 function Base.cconvert(::Type{Cstring}, x::InlineString)
     ref = Ref(x)
     GC.@preserve ref Base.containsnul(Ptr{Int8}(pointer_from_objref(ref)), sizeof(x)) &&
-        throw(ArgumentError("embedded NULs are not allowed in C strings: $(repr(x))"))
+        throw_embedded_nul(x)
     return ref
 end

The inline repr made cconvert infer the whole show machinery for the error path. When downstream code calls cconvert(Cstring, x) with x::Any, inference visits this method and records edges into that machinery. Any package that later defines a promote_rule for its own number type then invalidates the downstream code. With a separate @noinline function, inference stops at its call.

Evidence

Measured in Corset.jl, with a test that loads a package defining promote_rule for its own number type:

The existing embedded-NUL test now also checks the error message, which stays the same. The full suite passes locally on Julia 1.13.

Merge Danger

Door: two-way

Blast Radius: none. The error type and message stay the same.

https://claude.ai/code/session_011JVX1FUvj2TmSZj7moQwDk

…@noinline` function

The inline `repr` call made `cconvert` infer the whole `show` machinery.
Downstream code that calls `cconvert(Cstring, ::Any)` then gets
invalidated by unrelated `promote_rule` methods.

Claude-Session: https://claude.ai/code/session_011JVX1FUvj2TmSZj7moQwDk
@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.82%. Comparing base (2930a7b) to head (056282c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #101      +/-   ##
==========================================
+ Coverage   91.80%   91.82%   +0.02%     
==========================================
  Files           5        5              
  Lines         744      746       +2     
==========================================
+ Hits          683      685       +2     
  Misses         61       61              

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

@quinnj-bot quinnj-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[review generated via AI] Thanks @ParadaCarleton, this looks good.

  • Behavior is unchanged. The error type and message are the same; the message is now built only when the error is thrown, in a @noinline function. The tightened test pins the full message.
  • CI. The package's own jobs pass on 1.10, 1 and pre, and so do the Parsers 2/3 jobs.
  • The TimeZones.jl integration failure is pre-existing. It fails the same way on main (9 failures in TimeZones' own tests in the Nov 19 runs), so it isn't caused by this PR.

🤖 Generated with Claude Code

@quinnj-bot
quinnj-bot Bot merged commit afbd844 into JuliaStrings:main Nov 25, 2026
13 of 14 checks passed
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