Commit 7743f25b

7743f25b4508Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

codegen: box FFI :ptr as obj when widening to poly

box_value_to_poly fell through to sp_box_int(...) for the FFI :ptr type because type_is_pointer("ptr") returns 0 (raw C pointer, intentionally not GC-traced). When a function had mixed return paths -- one int, one :ptr from an int_ptr_array -- the analyzer widened the return to poly and codegen emitted sp_box_int(((void *)...)) which fails to compile.

Add an explicit :ptr arm before the int fallback, boxing as sp_box_obj((void *)val, 0) so the pointer survives the round trip.

Fixes #828

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
7743f25b4508
Parent
08740b9d30b9

spinel_codegen.rbmodifiedView file

@@ -25808,6 +25808,12 @@
2580825808 if type_is_pointer(at) == 1
2580925809 return "sp_box_obj((void *)(" + val + "), 0)"
2581025810 end
25811+ # FFI :ptr is a raw C pointer that type_is_pointer() reports as
25812+ # non-pointer (user-managed, not GC-traced). Boxing it into a poly
25813+ # slot still needs to survive as a pointer, not as an int.
25814+ if at == "ptr"
25815+ return "sp_box_obj((void *)(" + val + "), 0)"
25816+ end
2581125817 "sp_box_int(" + val + ")"
2581225818 end
2581325819