Commit b7f2a1bb
b7f2a1bb8737Merged
Dmitry Bochkarev <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): cast pointer args through proc ABI via uintptr_t
compile_dot_call_expr passed arguments to sp_proc_call via the (mrb_int[]){...} compound literal using native C types. This failed when an argument was a pointer (sp_Defer *, Wrapper *, etc.).
Add compile_proc_call_args helper that wraps pointer-typed args with (mrb_int)(uintptr_t) before placing them in the compound literal, matching the unboxing casts already generated in get_block_param on the receiving side.
Details
- Commit
- b7f2a1bb8737
- Parent
- b258716b233a
spinel_codegen.rbmodifiedView file
@@ -13043,10 +13043,7 @@
1304313043
# "" for zero args; pad with "0" so the array has at least1304413044
# one slot (the proc fn's `_unused` fallback expects args[0]1304513045
# to be addressable).13046-
ca = compile_call_args(nid)13047-
if ca == ""13048-
ca = "0"13049-
end13046+
ca = compile_proc_call_args(nid)1305013047
return "sp_proc_call(lv_" + rname + ", (mrb_int[]){" + ca + "})"1305113048
end1305213049
end@@ -13067,10 +13064,7 @@
1306713064
end1306813065
rt = infer_type(recv)1306913066
if rt == "proc"13070-
ca = compile_call_args(nid)13071-
if ca == ""13072-
ca = "0"13073-
end13067+
ca = compile_proc_call_args(nid)1307413068
rc = compile_expr_gc_rooted(recv)1307513069
return "sp_proc_call(" + rc + ", (mrb_int[]){" + ca + "})"1307613070
end@@ -20033,6 +20027,33 @@
2003320027
result2003420028
end2003520029
20030+
def compile_proc_call_args(nid)20031+
args_id = @nd_arguments[nid]20032+
if args_id < 020033+
return "0"20034+
end20035+
arg_ids = get_args(args_id)20036+
if arg_ids.length == 020037+
return "0"20038+
end20039+
result = ""20040+
k = 020041+
while k < arg_ids.length20042+
if k > 020043+
result = result + ", "20044+
end20045+
val = compile_expr(arg_ids[k])20046+
at = infer_type(arg_ids[k])20047+
if type_is_pointer(at) == 120048+
result = result + "(mrb_int)(uintptr_t)(" + val + ")"20049+
else20050+
result = result + val20051+
end20052+
k = k + 120053+
end20054+
result20055+
end20056+
2003620057
def compile_gc_safe_args(arg_ids)2003720058
temps = "".split(",")2003820059
k = 0test/proc_arg_object.rbaddedView file
Loading diff…
test/proc_arg_object.rb.expectedaddedView file
Loading diff…