Repository navigation
An ffi_func's :binstr or :string argument takes a String as :str does - #8471
Conversation
:binstr and the ffi gem's :string are `const char *` like :str, but the argument lowering and the count of String arguments compared the spec to "str" alone, so both fell through to the integer path. A String-typed value still worked, by accident; a boxed one (a mixed Array's element, a mixed Hash's value, a poly local) raised `no implicit conversion of String into Integer`, nil raised instead of passing NULL, and a boxed Integer went to C as a pointer. An ffi_callback trampoline did the same for a poly parameter: the method got the pointer as an Integer and NULL as 0. All three places ask ffi_spec_is_str now, which the String rooting beside them already did. The return side is unchanged: a :str return is read up to the first NUL, a :binstr return is sp_ffi_bin_len bytes. FFI.md says so instead of calling :binstr return-only. test/ffi_str_spec_aliases_arg.rb covers both specs as an argument (typed, nil, mixed Array and Hash element, poly local, a boxed Integer, two in one call) and as a callback parameter; before, it stops at the first nil. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk | ⚪ Minimal · up to
|
What this changes
:binstr and the ffi gem's :string are
const char *like :str, but the argument lowering and the count of String arguments compared the spec to "str" alone, so both fell through to the integer path. A String-typed value still worked, by accident; a boxed one (a mixed Array's element, a mixed Hash's value, a poly local) raisedno implicit conversion of String into Integer, nil raised instead of passing NULL, and a boxed Integer went to C as a pointer. An ffi_callback trampoline did the same for a poly parameter: the method got the pointer as an Integer and NULL as 0.All three places ask ffi_spec_is_str now, which the String rooting beside them already did. The return side is unchanged: a :str return is read up to the first NUL, a :binstr return is sp_ffi_bin_len bytes. FFI.md says so instead of calling :binstr return-only.
test/ffi_str_spec_aliases_arg.rb covers both specs as an argument (typed, nil, mixed Array and Hash element, poly local, a boxed Integer, two in one call) and as a callback parameter; before, it stops at the first nil.
make gate(on this branch merged with current master)progressing
.expectedfiles that match CRuby 4.0 run with--enable-frozen-string-literal# spinel: int64Summary by CodeRabbit
:binstrand:stringalongside:strfor call arguments and callback parameters.nilis passed asNULL, and non-String values raiseTypeError.:binstrreturns binary-safe strings. When passing input that may contain NUL bytes, provide its byte length separately.