mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
porting of GH-4022
This commit is contained in:
parent
c86f9267ff
commit
f693f22192
4 changed files with 40 additions and 14 deletions
|
@ -3241,10 +3241,11 @@ bool VectorVal::Assign(unsigned int index, ValPtr element) {
|
||||||
|
|
||||||
if ( yield_types ) {
|
if ( yield_types ) {
|
||||||
const auto& t = element->GetType();
|
const auto& t = element->GetType();
|
||||||
(*yield_types)[index] = t;
|
auto& yt_i = (*yield_types)[index];
|
||||||
auto& elem = vector_val[index];
|
auto& elem = vector_val[index];
|
||||||
if ( elem )
|
if ( elem )
|
||||||
ZVal::DeleteIfManaged(*elem, t);
|
ZVal::DeleteIfManaged(*elem, yt_i);
|
||||||
|
yt_i = t;
|
||||||
elem = ZVal(std::move(element), t);
|
elem = ZVal(std::move(element), t);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -1629,6 +1629,9 @@ ExprPtr AssignExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
||||||
StmtPtr lhs_stmt;
|
StmtPtr lhs_stmt;
|
||||||
StmtPtr rhs_stmt;
|
StmtPtr rhs_stmt;
|
||||||
|
|
||||||
|
if ( GetType()->Tag() == TYPE_ANY && op2->GetType()->Tag() != TYPE_ANY )
|
||||||
|
op2 = with_location_of(make_intrusive<CoerceToAnyExpr>(op2), op2);
|
||||||
|
|
||||||
auto lhs_e = field_e->Op()->Reduce(c, lhs_stmt);
|
auto lhs_e = field_e->Op()->Reduce(c, lhs_stmt);
|
||||||
auto rhs_e = op2->ReduceToFieldAssignment(c, rhs_stmt);
|
auto rhs_e = op2->ReduceToFieldAssignment(c, rhs_stmt);
|
||||||
|
|
||||||
|
|
|
@ -934,13 +934,13 @@ eval auto& vsel = frame[z.v2].vector_val->RawVec();
|
||||||
auto& v1 = frame[z.v3].vector_val->RawVec();
|
auto& v1 = frame[z.v3].vector_val->RawVec();
|
||||||
auto& v2 = frame[z.v4].vector_val->RawVec();
|
auto& v2 = frame[z.v4].vector_val->RawVec();
|
||||||
auto n = v1.size();
|
auto n = v1.size();
|
||||||
auto res = new vector<std::optional<ZVal>>(n);
|
vector<std::optional<ZVal>> res(n);
|
||||||
for ( auto i = 0U; i < n; ++i )
|
for ( auto i = 0U; i < n; ++i )
|
||||||
if ( vsel[i] )
|
if ( vsel[i] )
|
||||||
(*res)[i] = vsel[i]->int_val ? v1[i] : v2[i];
|
res[i] = vsel[i]->int_val ? v1[i] : v2[i];
|
||||||
auto& full_res = frame[z.v1].vector_val;
|
auto& full_res = frame[z.v1].vector_val;
|
||||||
Unref(full_res);
|
Unref(full_res);
|
||||||
full_res = new VectorVal(cast_intrusive<VectorType>(z.t), res);
|
full_res = new VectorVal(cast_intrusive<VectorType>(z.t), &res);
|
||||||
|
|
||||||
# Our instruction format doesn't accommodate two constants, so for
|
# Our instruction format doesn't accommodate two constants, so for
|
||||||
# the singular case of a V ? C1 : C2 conditional, we split it into
|
# the singular case of a V ? C1 : C2 conditional, we split it into
|
||||||
|
@ -1254,9 +1254,14 @@ macro AssignFromRec()
|
||||||
for ( size_t i = 0U; i < n; ++i )
|
for ( size_t i = 0U; i < n; ++i )
|
||||||
{
|
{
|
||||||
auto rhs_i = rhs->RawField(rhs_map[i]);
|
auto rhs_i = rhs->RawField(rhs_map[i]);
|
||||||
|
auto& init_i = init_vals[lhs_map[i]];
|
||||||
if ( is_managed[i] )
|
if ( is_managed[i] )
|
||||||
|
{
|
||||||
zeek::Ref(rhs_i.ManagedVal());
|
zeek::Ref(rhs_i.ManagedVal());
|
||||||
init_vals[lhs_map[i]] = rhs_i;
|
if ( init_i )
|
||||||
|
ZVal::DeleteManagedType(*init_i);
|
||||||
|
}
|
||||||
|
init_i = rhs_i;
|
||||||
}
|
}
|
||||||
|
|
||||||
op Construct-Known-Record-From
|
op Construct-Known-Record-From
|
||||||
|
@ -1606,7 +1611,19 @@ op Any-Vector-Elem-Assign
|
||||||
op1-read
|
op1-read
|
||||||
set-type $1
|
set-type $1
|
||||||
type VVV
|
type VVV
|
||||||
eval EvalVectorElemAssign(, vv->Assign(ind, frame[z.v3].ToVal(z.t)))
|
eval auto ind = frame[z.v2].AsCount();
|
||||||
|
auto vv = frame[z.v1].AsVector();
|
||||||
|
auto yt = vv->RawYieldTypes();
|
||||||
|
if ( ind < vv->Size() && yt && (*yt)[ind] && ZVal::IsManagedType((*yt)[ind]) )
|
||||||
|
{
|
||||||
|
auto orig_elem = vv->RawVec()[ind];
|
||||||
|
if ( ! vv->Assign(ind, frame[z.v3].ToVal(z.t)) )
|
||||||
|
ZAM_run_time_error(z.loc, "value used but not set");
|
||||||
|
if ( orig_elem )
|
||||||
|
ZVal::DeleteManagedType(*orig_elem);
|
||||||
|
}
|
||||||
|
else if ( ! vv->Assign(ind, frame[z.v3].ToVal(z.t)) )
|
||||||
|
ZAM_run_time_error(z.loc, "value used but not set");
|
||||||
|
|
||||||
op Vector-Elem-Assign-Any
|
op Vector-Elem-Assign-Any
|
||||||
op1-read
|
op1-read
|
||||||
|
|
|
@ -214,8 +214,9 @@ static void vec_exec(ZOp op, TypePtr t, VectorVal*& v1, const VectorVal* v2, con
|
||||||
std::string err = "overflow promoting from "; \
|
std::string err = "overflow promoting from "; \
|
||||||
err += ov_err; \
|
err += ov_err; \
|
||||||
err += " arithmetic value"; \
|
err += " arithmetic value"; \
|
||||||
|
/* The run-time error will throw an exception, so recover intermediary memory. */ \
|
||||||
|
delete res_zv; \
|
||||||
ZAM_run_time_error(z.loc, err.c_str()); \
|
ZAM_run_time_error(z.loc, err.c_str()); \
|
||||||
res[i] = std::nullopt; \
|
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
res[i] = ZVal(cast(vi)); \
|
res[i] = ZVal(cast(vi)); \
|
||||||
|
@ -604,8 +605,7 @@ static void vec_exec(ZOp op, TypePtr t, VectorVal*& v1, const VectorVal* v2, con
|
||||||
|
|
||||||
auto& vec2 = v2->RawVec();
|
auto& vec2 = v2->RawVec();
|
||||||
auto n = vec2.size();
|
auto n = vec2.size();
|
||||||
auto vec1_ptr = new vector<std::optional<ZVal>>(n);
|
vector<std::optional<ZVal>> vec1(n);
|
||||||
auto& vec1 = *vec1_ptr;
|
|
||||||
|
|
||||||
for ( auto i = 0U; i < n; ++i ) {
|
for ( auto i = 0U; i < n; ++i ) {
|
||||||
if ( vec2[i] )
|
if ( vec2[i] )
|
||||||
|
@ -620,7 +620,7 @@ static void vec_exec(ZOp op, TypePtr t, VectorVal*& v1, const VectorVal* v2, con
|
||||||
|
|
||||||
auto vt = cast_intrusive<VectorType>(std::move(t));
|
auto vt = cast_intrusive<VectorType>(std::move(t));
|
||||||
auto old_v1 = v1;
|
auto old_v1 = v1;
|
||||||
v1 = new VectorVal(std::move(vt), vec1_ptr);
|
v1 = new VectorVal(std::move(vt), &vec1);
|
||||||
Unref(old_v1);
|
Unref(old_v1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -631,8 +631,13 @@ static void vec_exec(ZOp op, TypePtr t, VectorVal*& v1, const VectorVal* v2, con
|
||||||
auto& vec2 = v2->RawVec();
|
auto& vec2 = v2->RawVec();
|
||||||
auto& vec3 = v3->RawVec();
|
auto& vec3 = v3->RawVec();
|
||||||
auto n = vec2.size();
|
auto n = vec2.size();
|
||||||
auto vec1_ptr = new vector<std::optional<ZVal>>(n);
|
|
||||||
auto& vec1 = *vec1_ptr;
|
if ( vec3.size() != n ) {
|
||||||
|
ZAM_run_time_error(util::fmt("vector operands are of different sizes (%d vs. %d)", int(n), int(vec3.size())));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<std::optional<ZVal>> vec1(n);
|
||||||
|
|
||||||
for ( auto i = 0U; i < vec2.size(); ++i ) {
|
for ( auto i = 0U; i < vec2.size(); ++i ) {
|
||||||
if ( vec2[i] && vec3[i] )
|
if ( vec2[i] && vec3[i] )
|
||||||
|
@ -647,7 +652,7 @@ static void vec_exec(ZOp op, TypePtr t, VectorVal*& v1, const VectorVal* v2, con
|
||||||
|
|
||||||
auto vt = cast_intrusive<VectorType>(std::move(t));
|
auto vt = cast_intrusive<VectorType>(std::move(t));
|
||||||
auto old_v1 = v1;
|
auto old_v1 = v1;
|
||||||
v1 = new VectorVal(std::move(vt), vec1_ptr);
|
v1 = new VectorVal(std::move(vt), &vec1);
|
||||||
Unref(old_v1);
|
Unref(old_v1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue