Commit 22ba670b
22ba670b3567Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #87 from mame/fix/ptr-array-value-type
fix(codegen): exclude classes stored in ptr_array from value-type optimization
Details
- Commit
- 22ba670b3567
- Parent
- 0c3c5d918fc5
- Merge parent
- cede08371e1a
spinel_codegen.rbmodifiedView file
@@ -9359,6 +9359,30 @@
93599359
""93609360
end93619361
9362+
def detect_ptr_array_stored_types9363+
# Find object types `obj_<C>` that appear as the element type of an9364+
# array literal. Such an array becomes a `sp_PtrArray *` whose9365+
# `_push` takes `void *`; if `<C>` were optimized into a value type9366+
# then `sp_<C>_new(...)` would return the struct by value and the9367+
# generated push call would be a C type error.9368+
@ptr_array_stored_types = "".split(",")9369+
nid = 09370+
while nid < @nd_type.length9371+
if @nd_type[nid] == "ArrayNode"9372+
at = infer_array_elem_type(nid)9373+
if is_ptr_array_type(at) == 19374+
obj_t = ptr_array_elem_type(at)9375+
if is_obj_type(obj_t) == 19376+
if not_in(obj_t, @ptr_array_stored_types) == 19377+
@ptr_array_stored_types.push(obj_t)9378+
end9379+
end9380+
end9381+
end9382+
nid = nid + 19383+
end9384+
end9385+
93629386
def detect_param_mutated_types93639387
# Find classes whose instances are mutated when passed as method parameters93649388
@param_mutated_types = "".split(",")@@ -9491,6 +9515,7 @@
94919515
auto_register_attr_readers94929516
auto_register_attr_writers94939517
detect_param_mutated_types9518+
detect_ptr_array_stored_types94949519
# Multiple passes: value type detection depends on other classes94959520
2.times do94969521
i = 0@@ -9544,6 +9569,20 @@
95449569
pmi = pmi + 195459570
end95469571
end9572+
# Exclude classes whose instances are pushed into a ptr_array9573+
# (array literal of `obj_<C>` becomes a `sp_PtrArray *` whose9574+
# `_push` takes `void *`; a value-type return from `Foo.new`9575+
# is a struct by value and can't be passed through `void *`).9576+
if all_val == 19577+
type_str = "obj_" + @cls_names[i]9578+
psi = 09579+
while psi < @ptr_array_stored_types.length9580+
if @ptr_array_stored_types[psi] == type_str9581+
all_val = 09582+
end9583+
psi = psi + 19584+
end9585+
end95479586
if all_val == 195489587
@cls_is_value_type[i] = 195499588
endtest/ptr_array_of_value_class.rbaddedView file
Loading diff…