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

@@ -37883,8 +37883,11 @@
3788337883 # Proc fn ABI returns mrb_int; a pointer-typed body tail (string,
3788437884 # array, hash, ...) round-trips through the integer slot. Cast
3788537885 # explicitly so the return doesn't warn under -Wint-conversion.
37886- # Issue #709 (string-returning ctor block).
37887- elsif type_is_pointer(bexpr_t_proc) == 1
37886+ # Issue #709 (string-returning ctor block); extended for FFI :ptr
37887+ # (issue #1017) — ffi_read_ptr / ffi_func :ret => :ptr return a
37888+ # raw C pointer that type_is_pointer() reports as 0 (not GC-traced)
37889+ # but still needs the same mrb_int round-trip in the proc-fn ABI.
37890+ elsif type_is_pointer(bexpr_t_proc) == 1 || base_type(bexpr_t_proc) == "ptr"
3788837891 bexpr = "(mrb_int)(uintptr_t)(" + bexpr + ")"
3788937892 end
3789037893 pop_scope