Deprecant ListVal::Append(Val*) and add IntrusivePtr version

This commit is contained in:
Jon Siwek 2020-05-05 11:36:35 -07:00
parent df65d1e829
commit b422f68b88
9 changed files with 43 additions and 31 deletions

View file

@ -229,7 +229,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
while ( tbl->NextEntry(k, it) )
{
hashkeys[k] = idx++;
lv->Append(tv->RecoverIndex(k).release());
lv->Append(tv->RecoverIndex(k));
}
for ( auto& kv : hashkeys )
@ -349,8 +349,7 @@ HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const
// re-introduce const on the recursive call, it should
// be okay; the only thing is that the ListVal unref's it.
Val* ncv = (Val*) v;
ncv->Ref();
lv.Append(ncv);
lv.Append({NewRef{}, ncv});
HashKey* hk = ComputeHash(&lv, type_check);
return hk;
}
@ -726,7 +725,7 @@ IntrusivePtr<ListVal> CompositeHash::RecoverVals(const HashKey* k) const
IntrusivePtr<Val> v;
kp = RecoverOneVal(k, kp, k_end, type, &v, false);
ASSERT(v);
l->Append(v.release());
l->Append(std::move(v));
}
if ( kp != k_end )
@ -1016,7 +1015,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
IntrusivePtr<Val> v;
BroType* it = (*tl->Types())[i];
kp1 = RecoverOneVal(k, kp1, k_end, it, &v, false);
lv->Append(v.release());
lv->Append(std::move(v));
}
*pval = std::move(lv);

View file

@ -285,7 +285,7 @@ IntrusivePtr<ListVal> DNS_Mapping::Addrs()
auto addrs_val = make_intrusive<ListVal>(TYPE_ADDR);
for ( int i = 0; i < num_addrs; ++i )
addrs_val->Append(new AddrVal(addrs[i]));
addrs_val->Append(make_intrusive<AddrVal>(addrs[i]));
}
return addrs_val;
@ -478,7 +478,7 @@ static IntrusivePtr<TableVal> fake_name_lookup_result(const char* name)
hash128_t hash;
KeyedHash::StaticHash128(name, strlen(name), &hash);
auto hv = make_intrusive<ListVal>(TYPE_ADDR);
hv->Append(new AddrVal(reinterpret_cast<const uint32_t*>(&hash)));
hv->Append(make_intrusive<AddrVal>(reinterpret_cast<const uint32_t*>(&hash)));
return hv->ToSetVal();
}
@ -900,7 +900,7 @@ IntrusivePtr<ListVal> DNS_Mgr::AddrListDelta(ListVal* al1, ListVal* al2)
if ( j >= al2->Length() )
// Didn't find it.
delta->Append(al1->Index(i)->Ref());
delta->Append({NewRef{}, al1->Index(i)});
}
return delta;

View file

@ -3830,13 +3830,13 @@ IntrusivePtr<Val> FlattenExpr::Fold(Val* v) const
{
if ( Val* fv = rv->Lookup(i) )
{
l->Append(fv->Ref());
l->Append({NewRef{}, fv});
continue;
}
const RecordType* rv_t = rv->Type()->AsRecordType();
if ( const Attr* fa = rv_t->FieldDecl(i)->FindAttr(ATTR_DEFAULT) )
l->Append(fa->AttrExpr()->Eval(nullptr).release());
l->Append(fa->AttrExpr()->Eval(nullptr));
else
RuntimeError("missing field value");
@ -4478,7 +4478,7 @@ IntrusivePtr<Val> ListExpr::Eval(Frame* f) const
return nullptr;
}
v->Append(ev.release());
v->Append(std::move(ev));
}
return v;
@ -4570,7 +4570,7 @@ IntrusivePtr<Val> ListExpr::InitVal(const BroType* t, IntrusivePtr<Val> aggr) co
if ( ! vi )
return nullptr;
v->Append(vi.release());
v->Append(std::move(vi));
}
return v;
@ -4601,7 +4601,7 @@ IntrusivePtr<Val> ListExpr::InitVal(const BroType* t, IntrusivePtr<Val> aggr) co
if ( ! vi )
return nullptr;
v->Append(vi.release());
v->Append(std::move(vi));
}
return v;

View file

@ -1214,7 +1214,7 @@ RE_Matcher* ListVal::BuildRE() const
return re;
}
void ListVal::Append(Val* v)
void ListVal::Append(IntrusivePtr<Val> v)
{
if ( type->AsTypeList()->IsPure() )
{
@ -1222,8 +1222,14 @@ void ListVal::Append(Val* v)
Internal("heterogeneous list in ListVal::Append");
}
vals.push_back(v);
type->AsTypeList()->Append({NewRef{}, v->Type()});
auto vt = v->Type();
vals.push_back(v.release());
type->AsTypeList()->Append({NewRef{}, vt});
}
void ListVal::Append(Val* v)
{
Append({AdoptRef{}, v});
}
IntrusivePtr<TableVal> ListVal::ToSetVal() const
@ -1280,7 +1286,7 @@ IntrusivePtr<Val> ListVal::DoClone(CloneState* state)
state->NewClone(this, lv);
for ( const auto& val : vals )
lv->Append(val->Clone(state).release());
lv->Append(val->Clone(state));
return lv;
}
@ -2116,14 +2122,14 @@ ListVal* TableVal::ConvertToList(TypeTag t) const
auto index = table_hash->RecoverVals(k);
if ( t == TYPE_ANY )
l->Append(index.release());
l->Append(std::move(index));
else
{
// We're expecting a pure list, flatten the ListVal.
if ( index->Length() != 1 )
InternalWarning("bad index in TableVal::ConvertToList");
l->Append(index->Index(0)->Ref());
l->Append({NewRef{}, index->Index(0)});
}
delete k;
@ -2249,9 +2255,9 @@ bool TableVal::ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr<Val> new_
loop_over_list(*vl, j)
{
if ( j == k )
expd->Append(ind_k_i->Ref());
expd->Append({NewRef{}, ind_k_i});
else
expd->Append((*vl)[j]->Ref());
expd->Append({NewRef{}, (*vl)[j]});
}
if ( ! ExpandAndInit(std::move(expd), new_val) )

View file

@ -641,6 +641,13 @@ public:
// The return RE_Matcher has not yet been compiled.
RE_Matcher* BuildRE() const;
/**
* Appends a value to the list.
* @param v the value to append.
*/
void Append(IntrusivePtr<Val> v);
[[deprecated("Remove in v4.1. Use Append(IntrusivePtr) instead.")]]
void Append(Val* v);
// Returns a Set representation of the list (which must be homogeneous).

View file

@ -252,7 +252,7 @@ struct val_converter {
if ( ! index_val )
return nullptr;
list_val->Append(index_val.release());
list_val->Append(std::move(index_val));
}
@ -312,7 +312,7 @@ struct val_converter {
if ( ! index_val )
return nullptr;
list_val->Append(index_val.release());
list_val->Append(std::move(index_val));
}
auto value_val = bro_broker::data_to_val(move(item.second),

View file

@ -164,8 +164,8 @@ bool AnalyzerSet::RemoveMod::Perform(AnalyzerSet* set)
HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const
{
ListVal* lv = new ListVal(TYPE_ANY);
lv->Append(t.AsEnumVal()->Ref());
lv->Append(args->Ref());
lv->Append({NewRef{}, t.AsEnumVal()});
lv->Append({NewRef{}, args});
HashKey* key = analyzer_hash->ComputeHash(lv, true);
Unref(lv);
if ( ! key )

View file

@ -1010,7 +1010,7 @@ Val* Manager::RecordValToIndexVal(RecordVal *r) const
{
auto l = make_intrusive<ListVal>(TYPE_ANY);
for ( int j = 0 ; j < num_fields; j++ )
l->Append(r->LookupWithDefault(j).release());
l->Append(r->LookupWithDefault(j));
idxval = std::move(l);
}
@ -1037,11 +1037,11 @@ Val* Manager::ValueToIndexVal(const Stream* i, int num_fields, const RecordType
for ( int j = 0 ; j < type->NumFields(); j++ )
{
if ( type->FieldType(j)->Tag() == TYPE_RECORD )
l->Append(ValueToRecordVal(i, vals,
type->FieldType(j)->AsRecordType(), &position, have_error));
l->Append({AdoptRef{}, ValueToRecordVal(i, vals,
type->FieldType(j)->AsRecordType(), &position, have_error)});
else
{
l->Append(ValueToVal(i, vals[position], type->FieldType(j), have_error));
l->Append({AdoptRef{}, ValueToVal(i, vals[position], type->FieldType(j), have_error)});
position++;
}
}

View file

@ -3524,7 +3524,7 @@ public:
else
{
ListVal* lv = new ListVal(TYPE_ADDR);
lv->Append(new AddrVal("0.0.0.0"));
lv->Append(make_intrusive<AddrVal>("0.0.0.0"));
auto result = lv->ToSetVal();
trigger->Cache(call, result.get());
Unref(lv);