Commit 48ac4966
48ac49664a7bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #160 from mame/pr/box-pointer-types-to-poly
fix(codegen): box pointer-typed values to poly via sp_box_obj
Details
- Commit
- 48ac49664a7b
- Parent
- 78c568dfd64b
- Merge parent
- a7f1d9b68dca
spinel_codegen.rbmodifiedView file
@@ -19320,6 +19320,11 @@
1932019320
if at == "proc" || at == "lambda"1932119321
return "sp_box_proc(" + val + ")"1932219322
end19323+
# Other pointer types (hashes, mutable strings, etc.) — box with a19324+
# neutral cls_id of 0 rather than truncating the pointer to int.19325+
if type_is_pointer(at) == 119326+
return "sp_box_obj((void *)(" + val + "), 0)"19327+
end1932319328
"sp_box_int(" + val + ")"1932419329
end1932519330
@@ -19345,6 +19350,33 @@
1934519350
if at == "symbol"1934619351
return "sp_box_sym(" + val + ")"1934719352
end19353+
if at == "int_array"19354+
return "sp_box_int_array(" + val + ")"19355+
end19356+
if at == "float_array"19357+
return "sp_box_float_array(" + val + ")"19358+
end19359+
if at == "str_array"19360+
return "sp_box_str_array(" + val + ")"19361+
end19362+
if at == "sym_array"19363+
return "sp_box_sym_array(" + val + ")"19364+
end19365+
if is_ptr_array_type(at) == 119366+
return "sp_box_ptr_array(" + val + ")"19367+
end19368+
if is_obj_type(at) == 119369+
cname = at[4, at.length - 4]19370+
ci = find_class_idx(cname)19371+
return "sp_box_obj(" + val + ", " + ci.to_s + ")"19372+
end19373+
# Other pointer types (hashes, mutable strings, etc.) — box with a19374+
# neutral cls_id of 0. Round-tripping back to the original concrete19375+
# type is the caller's problem; this just makes the assignment19376+
# type-check rather than silently truncating a pointer to mrb_int.19377+
if type_is_pointer(at) == 119378+
return "sp_box_obj((void *)(" + val + "), 0)"19379+
end1934819380
"sp_box_int(" + val + ")"1934919381
end1935019382
test/box_pointer_to_poly.rbaddedView file
Loading diff…