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 least
1304413044 # 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- end
13046+ ca = compile_proc_call_args(nid)
1305013047 return "sp_proc_call(lv_" + rname + ", (mrb_int[]){" + ca + "})"
1305113048 end
1305213049 end
@@ -13067,10 +13064,7 @@
1306713064 end
1306813065 rt = infer_type(recv)
1306913066 if rt == "proc"
13070- ca = compile_call_args(nid)
13071- if ca == ""
13072- ca = "0"
13073- end
13067+ 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 result
2003420028 end
2003520029
20030+ def compile_proc_call_args(nid)
20031+ args_id = @nd_arguments[nid]
20032+ if args_id < 0
20033+ return "0"
20034+ end
20035+ arg_ids = get_args(args_id)
20036+ if arg_ids.length == 0
20037+ return "0"
20038+ end
20039+ result = ""
20040+ k = 0
20041+ while k < arg_ids.length
20042+ if k > 0
20043+ result = result + ", "
20044+ end
20045+ val = compile_expr(arg_ids[k])
20046+ at = infer_type(arg_ids[k])
20047+ if type_is_pointer(at) == 1
20048+ result = result + "(mrb_int)(uintptr_t)(" + val + ")"
20049+ else
20050+ result = result + val
20051+ end
20052+ k = k + 1
20053+ end
20054+ result
20055+ end
20056+
2003620057 def compile_gc_safe_args(arg_ids)
2003720058 temps = "".split(",")
2003820059 k = 0