gen-zam: fix memory management for vector-of-strings operations

This commit is contained in:
Vern Paxson 2022-07-30 11:44:03 -07:00 committed by Tim Wojtulewicz
parent f330505e83
commit 789b06b1ea

View file

@ -1390,9 +1390,24 @@ void ZAM_ExprOpTemplate::InstantiateEval(const vector<ZAM_OperandType>& ot_orig,
if ( ! is_none && ! is_default && find_type_info(ei.LHS_ET()).is_managed && if ( ! is_none && ! is_default && find_type_info(ei.LHS_ET()).is_managed &&
! HasExplicitResultType() ) ! HasExplicitResultType() )
{ {
auto delim = zc == ZIC_VEC ? "->" : "."; auto pre = "auto hold_lhs = " + lhs;
auto pre = "auto hold_lhs = " + lhs + delim + "ManagedVal();\n\t";
if ( zc == ZIC_VEC )
// For vectors, we have to check for whether
// the previous value is present, or a hole.
pre += string(" ? ") + lhs + "->";
else
pre += ".";
pre += "ManagedVal()";
if ( zc == ZIC_VEC )
pre += " : nullptr";
pre += ";\n\t";
auto post = "\tUnref(hold_lhs);"; auto post = "\tUnref(hold_lhs);";
eval = pre + eval + post; eval = pre + eval + post;
} }