Commit a7f1d9b6
a7f1d9b68dcaMerged
Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): box pointer-typed values to poly via sp_box_obj
box_val_to_poly and box_expr_to_poly had a final fallback that
emitted sp_box_int(val) for any type they didn't explicitly know
about. For pointer-typed expressions (hashes, mutable strings,
arrays of object types, user objects, etc.) this silently passed
the pointer to a function expecting mrb_int, producing
-Wint-conversion errors and (if compiled) truncating the pointer
to a 64-bit int.
Add explicit boxing for the array-of-X variants and obj_X (matching
what box_expr_to_poly already did for those), then a generic
type_is_pointer fallback that routes through sp_box_obj(p, 0).
The cls_id of 0 means dispatch on the resulting poly value can't
recover the original concrete type, but that's the caller's problem
— this just makes the boxing produce a valid sp_RbVal instead of a
silently-corrupted int, which is the right floor for a fallback.
In optcarrot, this drops the C-compile error count by ~30 — every
lv_opt = sp_box_int(<some_hash>) style assignment generated by
the unify-to-poly widening was failing.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- a7f1d9b68dca
- Parent
- bee7e89d5b64
spinel_codegen.rbmodifiedView file
if at == "proc" || at == "lambda" return "sp_box_proc(" + val + ")" end # Other pointer types (hashes, mutable strings, etc.) — box with a # neutral cls_id of 0 rather than truncating the pointer to int. if type_is_pointer(at) == 1 return "sp_box_obj((void *)(" + val + "), 0)" end "sp_box_int(" + val + ")" end if at == "symbol" return "sp_box_sym(" + val + ")" end if at == "int_array" return "sp_box_int_array(" + val + ")" end if at == "float_array" return "sp_box_float_array(" + val + ")" end if at == "str_array" return "sp_box_str_array(" + val + ")" end if at == "sym_array" return "sp_box_sym_array(" + val + ")" end if is_ptr_array_type(at) == 1 return "sp_box_ptr_array(" + val + ")" end if is_obj_type(at) == 1 cname = at[4, at.length - 4] ci = find_class_idx(cname) return "sp_box_obj(" + val + ", " + ci.to_s + ")" end # Other pointer types (hashes, mutable strings, etc.) — box with a # neutral cls_id of 0. Round-tripping back to the original concrete # type is the caller's problem; this just makes the assignment # type-check rather than silently truncating a pointer to mrb_int. if type_is_pointer(at) == 1 return "sp_box_obj((void *)(" + val + "), 0)" end "sp_box_int(" + val + ")" endtest/box_pointer_to_poly.rbaddedView file
Loading diff…