Commit 662e4079
662e40796596Merged
Sam Ruby <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
codegen: cast FFI :ptr proc body tail to mrb_int round-trip (#1017)
compile_proc_literal already casts pointer-typed proc body tails to
(mrb_int)(uintptr_t) so the mrb_int-returning proc-fn ABI doesn't
warn under -Wint-conversion (issue #709, for string/array/hash tails).
The guard at spinel_codegen.rb:37887 uses type_is_pointer == 1,
which intentionally reports 0 for FFI raw :ptr (non-GC, user-managed).
Result: a proc whose tail is an FFI :ptr value — e.g.
Pool.new(1) { Buf.first_ptr(Buf.scratch) }
— emits return ((void *)(...)); from a mrb_int-returning
_sp_proc_fn_N and cc rejects it. Surfaces in roundhouse's
sqlite ConnectionPool factory once #709 unblocked the constructor
yield.
Extend the guard with || base_type == "ptr" so the same cast site
covers FFI :ptr too. Adds test/i1017.rb (uses ffi_buffer +
ffi_read_ptr to deterministically read NULL from a zero-init BSS
buffer through a yielding-constructor block).
Details
- Commit
- 662e40796596
- Parent
- 87061dae35a7
spinel_codegen.rbmodifiedView file
# Proc fn ABI returns mrb_int; a pointer-typed body tail (string, # array, hash, ...) round-trips through the integer slot. Cast # explicitly so the return doesn't warn under -Wint-conversion. # Issue #709 (string-returning ctor block). elsif type_is_pointer(bexpr_t_proc) == 1 # Issue #709 (string-returning ctor block); extended for FFI :ptr # (issue #1017) — ffi_read_ptr / ffi_func :ret => :ptr return a # raw C pointer that type_is_pointer() reports as 0 (not GC-traced) # but still needs the same mrb_int round-trip in the proc-fn ABI. elsif type_is_pointer(bexpr_t_proc) == 1 || base_type(bexpr_t_proc) == "ptr" bexpr = "(mrb_int)(uintptr_t)(" + bexpr + ")" end pop_scopetest/i1017.rbaddedView file
Loading diff…
test/i1017.rb.expectedaddedView file
Loading diff…