mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
Change TableVal::RecoverIndex() to return IntrusivePtr
This commit is contained in:
parent
0b5a18495d
commit
b045ce4bb3
11 changed files with 45 additions and 90 deletions
|
@ -207,7 +207,7 @@ char* CompositeHash::SingleValHash(int type_check, char* kp0,
|
|||
|
||||
auto tbl = tv->AsTable();
|
||||
auto it = tbl->InitForIteration();
|
||||
ListVal* lv = new ListVal(TYPE_ANY);
|
||||
auto lv = make_intrusive<ListVal>(TYPE_ANY);
|
||||
|
||||
struct HashKeyComparer {
|
||||
bool operator()(const HashKey* a, const HashKey* b) const
|
||||
|
@ -229,7 +229,7 @@ char* CompositeHash::SingleValHash(int type_check, char* kp0,
|
|||
while ( tbl->NextEntry(k, it) )
|
||||
{
|
||||
hashkeys[k] = idx++;
|
||||
lv->Append(tv->RecoverIndex(k));
|
||||
lv->Append(tv->RecoverIndex(k).release());
|
||||
}
|
||||
|
||||
for ( auto& kv : hashkeys )
|
||||
|
@ -242,10 +242,7 @@ char* CompositeHash::SingleValHash(int type_check, char* kp0,
|
|||
|
||||
if ( ! (kp1 = SingleValHash(type_check, kp1, key->Type(), key,
|
||||
false)) )
|
||||
{
|
||||
Unref(lv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( ! v->Type()->IsSet() )
|
||||
{
|
||||
|
@ -253,14 +250,10 @@ char* CompositeHash::SingleValHash(int type_check, char* kp0,
|
|||
|
||||
if ( ! (kp1 = SingleValHash(type_check, kp1, val->Type(),
|
||||
val.get(), false)) )
|
||||
{
|
||||
Unref(lv);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Unref(lv);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -80,7 +80,6 @@ void Reporter::InitOptions()
|
|||
auto index = wl_val->RecoverIndex(k);
|
||||
string key = index->Index(0)->AsString()->CheckString();
|
||||
weird_sampling_whitelist.emplace(move(key));
|
||||
Unref(index);
|
||||
delete k;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1198,7 +1198,7 @@ IntrusivePtr<Val> ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
|
|||
IterCookie* c = loop_vals->InitForIteration();
|
||||
while ( (current_tev = loop_vals->NextEntry(k, c)) )
|
||||
{
|
||||
IntrusivePtr<ListVal> ind_lv{AdoptRef{}, tv->RecoverIndex(k)};
|
||||
auto ind_lv = tv->RecoverIndex(k);
|
||||
delete k;
|
||||
|
||||
if ( value_var )
|
||||
|
|
56
src/Val.cc
56
src/Val.cc
|
@ -532,12 +532,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val*
|
|||
{
|
||||
auto lv = tval->RecoverIndex(k);
|
||||
delete k;
|
||||
|
||||
Val* entry_key;
|
||||
if ( lv->Length() == 1 )
|
||||
entry_key = lv->Index(0)->Ref();
|
||||
else
|
||||
entry_key = lv->Ref();
|
||||
Val* entry_key = lv->Length() == 1 ? lv->Index(0) : lv.get();
|
||||
|
||||
if ( tval->Type()->IsSet() )
|
||||
BuildJSON(writer, entry_key, only_loggable, re);
|
||||
|
@ -556,9 +551,6 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val*
|
|||
|
||||
BuildJSON(writer, entry->Value(), only_loggable, re, key_str);
|
||||
}
|
||||
|
||||
Unref(entry_key);
|
||||
Unref(lv);
|
||||
}
|
||||
|
||||
if ( tval->Type()->IsSet() )
|
||||
|
@ -1537,9 +1529,8 @@ int TableVal::Assign(Val* index, HashKey* k, IntrusivePtr<Val> new_val)
|
|||
{
|
||||
if ( ! index )
|
||||
{
|
||||
Val* v = RecoverIndex(&k_copy);
|
||||
subnets->Insert(v, new_entry_val);
|
||||
Unref(v);
|
||||
auto v = RecoverIndex(&k_copy);
|
||||
subnets->Insert(v.get(), new_entry_val);
|
||||
}
|
||||
else
|
||||
subnets->Insert(index, new_entry_val);
|
||||
|
@ -1553,10 +1544,10 @@ int TableVal::Assign(Val* index, HashKey* k, IntrusivePtr<Val> new_val)
|
|||
|
||||
if ( change_func )
|
||||
{
|
||||
Val* change_index = index ? index->Ref() : RecoverIndex(&k_copy);
|
||||
auto change_index = index ? IntrusivePtr<Val>{NewRef{}, index}
|
||||
: RecoverIndex(&k_copy);
|
||||
Val* v = old_entry_val ? old_entry_val->Value() : new_val.get();
|
||||
CallChangeFunc(change_index, v, old_entry_val ? ELEMENT_CHANGED : ELEMENT_NEW);
|
||||
Unref(change_index);
|
||||
CallChangeFunc(change_index.get(), v, old_entry_val ? ELEMENT_CHANGED : ELEMENT_NEW);
|
||||
}
|
||||
|
||||
delete old_entry_val;
|
||||
|
@ -1991,9 +1982,9 @@ bool TableVal::UpdateTimestamp(Val* index)
|
|||
return true;
|
||||
}
|
||||
|
||||
ListVal* TableVal::RecoverIndex(const HashKey* k) const
|
||||
IntrusivePtr<ListVal> TableVal::RecoverIndex(const HashKey* k) const
|
||||
{
|
||||
return table_hash->RecoverVals(k).release();
|
||||
return table_hash->RecoverVals(k);
|
||||
}
|
||||
|
||||
void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe)
|
||||
|
@ -2344,11 +2335,12 @@ void TableVal::DoExpire(double t)
|
|||
|
||||
else if ( v->ExpireAccessTime() + timeout < t )
|
||||
{
|
||||
Val* idx = nullptr;
|
||||
IntrusivePtr<ListVal> idx = nullptr;
|
||||
|
||||
if ( expire_func )
|
||||
{
|
||||
idx = RecoverIndex(k);
|
||||
double secs = CallExpireFunc({NewRef{}, idx});
|
||||
double secs = CallExpireFunc(idx);
|
||||
|
||||
// It's possible that the user-provided
|
||||
// function modified or deleted the table
|
||||
|
@ -2359,7 +2351,6 @@ void TableVal::DoExpire(double t)
|
|||
if ( ! v )
|
||||
{ // user-provided function deleted it
|
||||
v = v_saved;
|
||||
Unref(idx);
|
||||
delete k;
|
||||
continue;
|
||||
}
|
||||
|
@ -2369,7 +2360,6 @@ void TableVal::DoExpire(double t)
|
|||
// User doesn't want us to expire
|
||||
// this now.
|
||||
v->SetExpireAccess(network_time - timeout + secs);
|
||||
Unref(idx);
|
||||
delete k;
|
||||
continue;
|
||||
}
|
||||
|
@ -2380,7 +2370,7 @@ void TableVal::DoExpire(double t)
|
|||
{
|
||||
if ( ! idx )
|
||||
idx = RecoverIndex(k);
|
||||
if ( ! subnets->Remove(idx) )
|
||||
if ( ! subnets->Remove(idx.get()) )
|
||||
reporter->InternalWarning("index not in prefix table");
|
||||
}
|
||||
|
||||
|
@ -2389,9 +2379,9 @@ void TableVal::DoExpire(double t)
|
|||
{
|
||||
if ( ! idx )
|
||||
idx = RecoverIndex(k);
|
||||
CallChangeFunc(idx, v->Value(), ELEMENT_EXPIRED);
|
||||
CallChangeFunc(idx.get(), v->Value(), ELEMENT_EXPIRED);
|
||||
}
|
||||
Unref(idx);
|
||||
|
||||
delete v;
|
||||
modified = true;
|
||||
}
|
||||
|
@ -2439,7 +2429,7 @@ double TableVal::GetExpireTime()
|
|||
return -1;
|
||||
}
|
||||
|
||||
double TableVal::CallExpireFunc(IntrusivePtr<Val> idx)
|
||||
double TableVal::CallExpireFunc(IntrusivePtr<ListVal> idx)
|
||||
{
|
||||
if ( ! expire_func )
|
||||
return 0;
|
||||
|
@ -2468,8 +2458,6 @@ double TableVal::CallExpireFunc(IntrusivePtr<Val> idx)
|
|||
// backwards compatibility with idx: any idiom
|
||||
bool any_idiom = func_args->length() == 2 && func_args->back()->Tag() == TYPE_ANY;
|
||||
|
||||
if ( idx->Type()->Tag() == TYPE_LIST )
|
||||
{
|
||||
if ( ! any_idiom )
|
||||
{
|
||||
for ( const auto& v : *idx->AsListVal()->Vals() )
|
||||
|
@ -2480,13 +2468,10 @@ double TableVal::CallExpireFunc(IntrusivePtr<Val> idx)
|
|||
ListVal* idx_list = idx->AsListVal();
|
||||
// Flatten if only one element
|
||||
if ( idx_list->Length() == 1 )
|
||||
idx = {NewRef{}, idx_list->Index(0)};
|
||||
|
||||
vl.append(idx.release());
|
||||
}
|
||||
}
|
||||
vl.append(idx_list->Index(0)->Ref());
|
||||
else
|
||||
vl.append(idx.release());
|
||||
}
|
||||
|
||||
auto result = f->Call(&vl);
|
||||
|
||||
|
@ -2518,9 +2503,8 @@ IntrusivePtr<Val> TableVal::DoClone(CloneState* state)
|
|||
|
||||
if ( subnets )
|
||||
{
|
||||
Val* idx = RecoverIndex(key);
|
||||
tv->subnets->Insert(idx, nval);
|
||||
Unref(idx);
|
||||
auto idx = RecoverIndex(key);
|
||||
tv->subnets->Insert(idx.get(), nval);
|
||||
}
|
||||
|
||||
delete key;
|
||||
|
@ -2609,7 +2593,7 @@ TableVal::ParseTimeTableState TableVal::DumpTableState()
|
|||
|
||||
while ( (val = tbl->NextEntry(key, cookie)) )
|
||||
{
|
||||
rval.emplace_back(IntrusivePtr<Val>{AdoptRef{}, RecoverIndex(key)},
|
||||
rval.emplace_back(RecoverIndex(key),
|
||||
IntrusivePtr<Val>{NewRef{}, val->Value()});
|
||||
|
||||
delete key;
|
||||
|
|
|
@ -766,7 +766,7 @@ public:
|
|||
bool UpdateTimestamp(Val* index);
|
||||
|
||||
// Returns the index corresponding to the given HashKey.
|
||||
ListVal* RecoverIndex(const HashKey* k) const;
|
||||
IntrusivePtr<ListVal> RecoverIndex(const HashKey* k) const;
|
||||
|
||||
// Returns the element if it was in the table, false otherwise.
|
||||
IntrusivePtr<Val> Delete(const Val* index);
|
||||
|
@ -851,7 +851,7 @@ protected:
|
|||
double GetExpireTime();
|
||||
|
||||
// Calls &expire_func and returns its return interval;
|
||||
double CallExpireFunc(IntrusivePtr<Val> idx);
|
||||
double CallExpireFunc(IntrusivePtr<ListVal> idx);
|
||||
|
||||
// Enum for the different kinds of changes an &on_change handler can see
|
||||
enum OnChangeType { ELEMENT_NEW, ELEMENT_CHANGED, ELEMENT_REMOVED, ELEMENT_EXPIRED };
|
||||
|
|
|
@ -898,29 +898,14 @@ broker::expected<broker::data> bro_broker::val_to_data(const Val* v)
|
|||
else
|
||||
rval = broker::table();
|
||||
|
||||
struct iter_guard {
|
||||
iter_guard(HashKey* arg_k, ListVal* arg_lv)
|
||||
: k(arg_k), lv(arg_lv)
|
||||
{}
|
||||
|
||||
~iter_guard()
|
||||
{
|
||||
delete k;
|
||||
Unref(lv);
|
||||
}
|
||||
|
||||
HashKey* k;
|
||||
ListVal* lv;
|
||||
};
|
||||
|
||||
HashKey* k;
|
||||
HashKey* hk;
|
||||
TableEntryVal* entry;
|
||||
auto c = table->InitForIteration();
|
||||
|
||||
while ( (entry = table->NextEntry(k, c)) )
|
||||
while ( (entry = table->NextEntry(hk, c)) )
|
||||
{
|
||||
auto vl = table_val->RecoverIndex(k);
|
||||
iter_guard ig(k, vl);
|
||||
auto vl = table_val->RecoverIndex(hk);
|
||||
delete hk;
|
||||
|
||||
broker::vector composite_key;
|
||||
composite_key.reserve(vl->Length());
|
||||
|
|
|
@ -40,7 +40,6 @@ std::set<std::string> val_to_topic_set(Val* val)
|
|||
{
|
||||
auto index = val->AsTableVal()->RecoverIndex(k);
|
||||
rval.emplace(index->Index(0)->AsString()->CheckString());
|
||||
Unref(index);
|
||||
delete k;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -283,11 +283,10 @@ bool Manager::CreateStream(Stream* info, RecordVal* description)
|
|||
TableEntryVal* v;
|
||||
while ( (v = info->config->AsTable()->NextEntry(k, c)) )
|
||||
{
|
||||
ListVal* index = info->config->RecoverIndex(k);
|
||||
auto index = info->config->RecoverIndex(k);
|
||||
string key = index->Index(0)->AsString()->CheckString();
|
||||
string value = v->Value()->AsString()->CheckString();
|
||||
rinfo.config.insert(std::make_pair(copy_string(key.c_str()), copy_string(value.c_str())));
|
||||
Unref(index);
|
||||
delete k;
|
||||
}
|
||||
}
|
||||
|
@ -1335,7 +1334,6 @@ void Manager::EndCurrentSend(ReaderFrontend* reader)
|
|||
|
||||
while ( ( ih = stream->lastDict->NextEntry(lastDictIdxKey, c) ) )
|
||||
{
|
||||
ListVal * idx = 0;
|
||||
IntrusivePtr<Val> val;
|
||||
|
||||
Val* predidx = 0;
|
||||
|
@ -1344,12 +1342,11 @@ void Manager::EndCurrentSend(ReaderFrontend* reader)
|
|||
|
||||
if ( stream->pred || stream->event )
|
||||
{
|
||||
idx = stream->tab->RecoverIndex(ih->idxkey);
|
||||
assert(idx != 0);
|
||||
val = stream->tab->Lookup(idx);
|
||||
auto idx = stream->tab->RecoverIndex(ih->idxkey);
|
||||
assert(idx != nullptr);
|
||||
val = stream->tab->Lookup(idx.get());
|
||||
assert(val != 0);
|
||||
predidx = ListValToRecordVal(idx, stream->itype, &startpos);
|
||||
Unref(idx);
|
||||
predidx = ListValToRecordVal(idx.get(), stream->itype, &startpos);
|
||||
ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release();
|
||||
}
|
||||
|
||||
|
|
|
@ -868,11 +868,10 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg)
|
|||
TableEntryVal* v;
|
||||
while ( (v = filter->config->AsTable()->NextEntry(k, c)) )
|
||||
{
|
||||
ListVal* index = filter->config->RecoverIndex(k);
|
||||
auto index = filter->config->RecoverIndex(k);
|
||||
string key = index->Index(0)->AsString()->CheckString();
|
||||
string value = v->Value()->AsString()->CheckString();
|
||||
info->config.insert(std::make_pair(copy_string(key.c_str()), copy_string(value.c_str())));
|
||||
Unref(index);
|
||||
delete k;
|
||||
}
|
||||
|
||||
|
|
|
@ -182,7 +182,6 @@ function Reporter::set_weird_sampling_whitelist%(weird_sampling_whitelist: strin
|
|||
auto index = wl_val->RecoverIndex(k);
|
||||
string key = index->Index(0)->AsString()->CheckString();
|
||||
whitelist_set.emplace(move(key));
|
||||
Unref(index);
|
||||
delete k;
|
||||
}
|
||||
reporter->SetWeirdSamplingWhitelist(whitelist_set);
|
||||
|
|
|
@ -1024,7 +1024,7 @@ Supervisor::NodeConfig Supervisor::NodeConfig::FromRecord(const RecordVal* node)
|
|||
|
||||
while ( (v = cluster_table->NextEntry(k, c)) )
|
||||
{
|
||||
IntrusivePtr<ListVal> key{AdoptRef{}, cluster_table_val->RecoverIndex(k)};
|
||||
auto key = cluster_table_val->RecoverIndex(k);
|
||||
delete k;
|
||||
auto name = key->Index(0)->AsStringVal()->ToStdString();
|
||||
auto rv = v->Value()->AsRecordVal();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue