mirror of
https://github.com/zeek/zeek.git
synced 2025-10-03 23:28:20 +00:00
Deprecant ListVal::Append(Val*) and add IntrusivePtr version
This commit is contained in:
parent
df65d1e829
commit
b422f68b88
9 changed files with 43 additions and 31 deletions
|
@ -229,7 +229,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
|
||||||
while ( tbl->NextEntry(k, it) )
|
while ( tbl->NextEntry(k, it) )
|
||||||
{
|
{
|
||||||
hashkeys[k] = idx++;
|
hashkeys[k] = idx++;
|
||||||
lv->Append(tv->RecoverIndex(k).release());
|
lv->Append(tv->RecoverIndex(k));
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( auto& kv : hashkeys )
|
for ( auto& kv : hashkeys )
|
||||||
|
@ -349,9 +349,8 @@ HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const
|
||||||
// re-introduce const on the recursive call, it should
|
// re-introduce const on the recursive call, it should
|
||||||
// be okay; the only thing is that the ListVal unref's it.
|
// be okay; the only thing is that the ListVal unref's it.
|
||||||
Val* ncv = (Val*) v;
|
Val* ncv = (Val*) v;
|
||||||
ncv->Ref();
|
lv.Append({NewRef{}, ncv});
|
||||||
lv.Append(ncv);
|
HashKey* hk = ComputeHash(&lv, type_check);
|
||||||
HashKey* hk = ComputeHash(&lv, type_check);
|
|
||||||
return hk;
|
return hk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -726,7 +725,7 @@ IntrusivePtr<ListVal> CompositeHash::RecoverVals(const HashKey* k) const
|
||||||
IntrusivePtr<Val> v;
|
IntrusivePtr<Val> v;
|
||||||
kp = RecoverOneVal(k, kp, k_end, type, &v, false);
|
kp = RecoverOneVal(k, kp, k_end, type, &v, false);
|
||||||
ASSERT(v);
|
ASSERT(v);
|
||||||
l->Append(v.release());
|
l->Append(std::move(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( kp != k_end )
|
if ( kp != k_end )
|
||||||
|
@ -1016,7 +1015,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
|
||||||
IntrusivePtr<Val> v;
|
IntrusivePtr<Val> v;
|
||||||
BroType* it = (*tl->Types())[i];
|
BroType* it = (*tl->Types())[i];
|
||||||
kp1 = RecoverOneVal(k, kp1, k_end, it, &v, false);
|
kp1 = RecoverOneVal(k, kp1, k_end, it, &v, false);
|
||||||
lv->Append(v.release());
|
lv->Append(std::move(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
*pval = std::move(lv);
|
*pval = std::move(lv);
|
||||||
|
|
|
@ -285,7 +285,7 @@ IntrusivePtr<ListVal> DNS_Mapping::Addrs()
|
||||||
auto addrs_val = make_intrusive<ListVal>(TYPE_ADDR);
|
auto addrs_val = make_intrusive<ListVal>(TYPE_ADDR);
|
||||||
|
|
||||||
for ( int i = 0; i < num_addrs; ++i )
|
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;
|
return addrs_val;
|
||||||
|
@ -478,7 +478,7 @@ static IntrusivePtr<TableVal> fake_name_lookup_result(const char* name)
|
||||||
hash128_t hash;
|
hash128_t hash;
|
||||||
KeyedHash::StaticHash128(name, strlen(name), &hash);
|
KeyedHash::StaticHash128(name, strlen(name), &hash);
|
||||||
auto hv = make_intrusive<ListVal>(TYPE_ADDR);
|
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();
|
return hv->ToSetVal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -900,7 +900,7 @@ IntrusivePtr<ListVal> DNS_Mgr::AddrListDelta(ListVal* al1, ListVal* al2)
|
||||||
|
|
||||||
if ( j >= al2->Length() )
|
if ( j >= al2->Length() )
|
||||||
// Didn't find it.
|
// Didn't find it.
|
||||||
delta->Append(al1->Index(i)->Ref());
|
delta->Append({NewRef{}, al1->Index(i)});
|
||||||
}
|
}
|
||||||
|
|
||||||
return delta;
|
return delta;
|
||||||
|
|
10
src/Expr.cc
10
src/Expr.cc
|
@ -3830,13 +3830,13 @@ IntrusivePtr<Val> FlattenExpr::Fold(Val* v) const
|
||||||
{
|
{
|
||||||
if ( Val* fv = rv->Lookup(i) )
|
if ( Val* fv = rv->Lookup(i) )
|
||||||
{
|
{
|
||||||
l->Append(fv->Ref());
|
l->Append({NewRef{}, fv});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RecordType* rv_t = rv->Type()->AsRecordType();
|
const RecordType* rv_t = rv->Type()->AsRecordType();
|
||||||
if ( const Attr* fa = rv_t->FieldDecl(i)->FindAttr(ATTR_DEFAULT) )
|
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
|
else
|
||||||
RuntimeError("missing field value");
|
RuntimeError("missing field value");
|
||||||
|
@ -4478,7 +4478,7 @@ IntrusivePtr<Val> ListExpr::Eval(Frame* f) const
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
v->Append(ev.release());
|
v->Append(std::move(ev));
|
||||||
}
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
|
@ -4570,7 +4570,7 @@ IntrusivePtr<Val> ListExpr::InitVal(const BroType* t, IntrusivePtr<Val> aggr) co
|
||||||
if ( ! vi )
|
if ( ! vi )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
v->Append(vi.release());
|
v->Append(std::move(vi));
|
||||||
}
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
|
@ -4601,7 +4601,7 @@ IntrusivePtr<Val> ListExpr::InitVal(const BroType* t, IntrusivePtr<Val> aggr) co
|
||||||
if ( ! vi )
|
if ( ! vi )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
v->Append(vi.release());
|
v->Append(std::move(vi));
|
||||||
}
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
|
|
22
src/Val.cc
22
src/Val.cc
|
@ -1214,7 +1214,7 @@ RE_Matcher* ListVal::BuildRE() const
|
||||||
return re;
|
return re;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListVal::Append(Val* v)
|
void ListVal::Append(IntrusivePtr<Val> v)
|
||||||
{
|
{
|
||||||
if ( type->AsTypeList()->IsPure() )
|
if ( type->AsTypeList()->IsPure() )
|
||||||
{
|
{
|
||||||
|
@ -1222,8 +1222,14 @@ void ListVal::Append(Val* v)
|
||||||
Internal("heterogeneous list in ListVal::Append");
|
Internal("heterogeneous list in ListVal::Append");
|
||||||
}
|
}
|
||||||
|
|
||||||
vals.push_back(v);
|
auto vt = v->Type();
|
||||||
type->AsTypeList()->Append({NewRef{}, 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
|
IntrusivePtr<TableVal> ListVal::ToSetVal() const
|
||||||
|
@ -1280,7 +1286,7 @@ IntrusivePtr<Val> ListVal::DoClone(CloneState* state)
|
||||||
state->NewClone(this, lv);
|
state->NewClone(this, lv);
|
||||||
|
|
||||||
for ( const auto& val : vals )
|
for ( const auto& val : vals )
|
||||||
lv->Append(val->Clone(state).release());
|
lv->Append(val->Clone(state));
|
||||||
|
|
||||||
return lv;
|
return lv;
|
||||||
}
|
}
|
||||||
|
@ -2116,14 +2122,14 @@ ListVal* TableVal::ConvertToList(TypeTag t) const
|
||||||
auto index = table_hash->RecoverVals(k);
|
auto index = table_hash->RecoverVals(k);
|
||||||
|
|
||||||
if ( t == TYPE_ANY )
|
if ( t == TYPE_ANY )
|
||||||
l->Append(index.release());
|
l->Append(std::move(index));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// We're expecting a pure list, flatten the ListVal.
|
// We're expecting a pure list, flatten the ListVal.
|
||||||
if ( index->Length() != 1 )
|
if ( index->Length() != 1 )
|
||||||
InternalWarning("bad index in TableVal::ConvertToList");
|
InternalWarning("bad index in TableVal::ConvertToList");
|
||||||
|
|
||||||
l->Append(index->Index(0)->Ref());
|
l->Append({NewRef{}, index->Index(0)});
|
||||||
}
|
}
|
||||||
|
|
||||||
delete k;
|
delete k;
|
||||||
|
@ -2249,9 +2255,9 @@ bool TableVal::ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr<Val> new_
|
||||||
loop_over_list(*vl, j)
|
loop_over_list(*vl, j)
|
||||||
{
|
{
|
||||||
if ( j == k )
|
if ( j == k )
|
||||||
expd->Append(ind_k_i->Ref());
|
expd->Append({NewRef{}, ind_k_i});
|
||||||
else
|
else
|
||||||
expd->Append((*vl)[j]->Ref());
|
expd->Append({NewRef{}, (*vl)[j]});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! ExpandAndInit(std::move(expd), new_val) )
|
if ( ! ExpandAndInit(std::move(expd), new_val) )
|
||||||
|
|
|
@ -641,6 +641,13 @@ public:
|
||||||
// The return RE_Matcher has not yet been compiled.
|
// The return RE_Matcher has not yet been compiled.
|
||||||
RE_Matcher* BuildRE() const;
|
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);
|
void Append(Val* v);
|
||||||
|
|
||||||
// Returns a Set representation of the list (which must be homogeneous).
|
// Returns a Set representation of the list (which must be homogeneous).
|
||||||
|
|
|
@ -252,7 +252,7 @@ struct val_converter {
|
||||||
if ( ! index_val )
|
if ( ! index_val )
|
||||||
return nullptr;
|
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 )
|
if ( ! index_val )
|
||||||
return nullptr;
|
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),
|
auto value_val = bro_broker::data_to_val(move(item.second),
|
||||||
|
|
|
@ -164,8 +164,8 @@ bool AnalyzerSet::RemoveMod::Perform(AnalyzerSet* set)
|
||||||
HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const
|
HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const
|
||||||
{
|
{
|
||||||
ListVal* lv = new ListVal(TYPE_ANY);
|
ListVal* lv = new ListVal(TYPE_ANY);
|
||||||
lv->Append(t.AsEnumVal()->Ref());
|
lv->Append({NewRef{}, t.AsEnumVal()});
|
||||||
lv->Append(args->Ref());
|
lv->Append({NewRef{}, args});
|
||||||
HashKey* key = analyzer_hash->ComputeHash(lv, true);
|
HashKey* key = analyzer_hash->ComputeHash(lv, true);
|
||||||
Unref(lv);
|
Unref(lv);
|
||||||
if ( ! key )
|
if ( ! key )
|
||||||
|
|
|
@ -1010,7 +1010,7 @@ Val* Manager::RecordValToIndexVal(RecordVal *r) const
|
||||||
{
|
{
|
||||||
auto l = make_intrusive<ListVal>(TYPE_ANY);
|
auto l = make_intrusive<ListVal>(TYPE_ANY);
|
||||||
for ( int j = 0 ; j < num_fields; j++ )
|
for ( int j = 0 ; j < num_fields; j++ )
|
||||||
l->Append(r->LookupWithDefault(j).release());
|
l->Append(r->LookupWithDefault(j));
|
||||||
|
|
||||||
idxval = std::move(l);
|
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++ )
|
for ( int j = 0 ; j < type->NumFields(); j++ )
|
||||||
{
|
{
|
||||||
if ( type->FieldType(j)->Tag() == TYPE_RECORD )
|
if ( type->FieldType(j)->Tag() == TYPE_RECORD )
|
||||||
l->Append(ValueToRecordVal(i, vals,
|
l->Append({AdoptRef{}, ValueToRecordVal(i, vals,
|
||||||
type->FieldType(j)->AsRecordType(), &position, have_error));
|
type->FieldType(j)->AsRecordType(), &position, have_error)});
|
||||||
else
|
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++;
|
position++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3524,7 +3524,7 @@ public:
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ListVal* lv = new ListVal(TYPE_ADDR);
|
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();
|
auto result = lv->ToSetVal();
|
||||||
trigger->Cache(call, result.get());
|
trigger->Cache(call, result.get());
|
||||||
Unref(lv);
|
Unref(lv);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue