mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 14:08:20 +00:00
revert fix now integrated into Master
This commit is contained in:
parent
af8468623a
commit
6b79bb2359
4 changed files with 31 additions and 57 deletions
16
src/Type.cc
16
src/Type.cc
|
@ -10,7 +10,6 @@
|
|||
#include <unordered_set>
|
||||
|
||||
#include "zeek/Attr.h"
|
||||
#include "zeek/CompHash.h"
|
||||
#include "zeek/Desc.h"
|
||||
#include "zeek/Expr.h"
|
||||
#include "zeek/Reporter.h"
|
||||
|
@ -479,13 +478,8 @@ TableType::TableType(TypeListPtr ind, TypePtr yield) : IndexType(TYPE_TABLE, std
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( Tag() != TYPE_ERROR )
|
||||
RegenerateHash();
|
||||
}
|
||||
|
||||
TableType::~TableType() { delete table_hash; }
|
||||
|
||||
bool TableType::CheckExpireFuncCompatibility(const detail::AttrPtr& attr) {
|
||||
if ( reported_error )
|
||||
return false;
|
||||
|
@ -499,11 +493,6 @@ bool TableType::CheckExpireFuncCompatibility(const detail::AttrPtr& attr) {
|
|||
|
||||
TypePtr TableType::ShallowClone() { return make_intrusive<TableType>(indices, yield_type); }
|
||||
|
||||
void TableType::RegenerateHash() {
|
||||
delete table_hash;
|
||||
table_hash = new detail::CompositeHash(GetIndices());
|
||||
}
|
||||
|
||||
bool TableType::IsUnspecifiedTable() const {
|
||||
// Unspecified types have an empty list of indices.
|
||||
return indices->GetTypes().empty();
|
||||
|
@ -1235,13 +1224,10 @@ const char* RecordType::AddFields(const type_decl_list& others, bool add_log_att
|
|||
return "extension field must be &optional or have &default";
|
||||
}
|
||||
|
||||
auto affected_table_types = TableVal::SaveParseTimeTableState(this);
|
||||
TableVal::SaveParseTimeTableState(this);
|
||||
|
||||
AddFieldsDirectly(others, add_log_attr);
|
||||
|
||||
for ( auto tt : affected_table_types )
|
||||
tt->RegenerateHash();
|
||||
|
||||
RecordVal::ResizeParseTimeRecords(this);
|
||||
TableVal::RebuildParseTimeTables();
|
||||
|
||||
|
|
30
src/Type.h
30
src/Type.h
|
@ -29,7 +29,6 @@ using TableValPtr = IntrusivePtr<TableVal>;
|
|||
|
||||
namespace detail {
|
||||
|
||||
class CompositeHash;
|
||||
class Expr;
|
||||
class ListExpr;
|
||||
class Attributes;
|
||||
|
@ -355,20 +354,22 @@ public:
|
|||
void DescribeReST(ODesc* d, bool roles_only = false) const override;
|
||||
|
||||
// Returns true if this table is solely indexed by subnet.
|
||||
bool IsSubNetIndex() const { return is_subnet_index; }
|
||||
bool IsSubNetIndex() const {
|
||||
const auto& types = indices->GetTypes();
|
||||
return types.size() == 1 && types[0]->Tag() == TYPE_SUBNET;
|
||||
}
|
||||
|
||||
// Returns true if this table has a single index of type pattern.
|
||||
bool IsPatternIndex() const { return is_pattern_index; }
|
||||
bool IsPatternIndex() const {
|
||||
const auto& types = indices->GetTypes();
|
||||
return types.size() == 1 && types[0]->Tag() == TYPE_PATTERN;
|
||||
}
|
||||
|
||||
detail::TraversalCode Traverse(detail::TraversalCallback* cb) const override;
|
||||
|
||||
protected:
|
||||
IndexType(TypeTag t, TypeListPtr arg_indices, TypePtr arg_yield_type)
|
||||
: Type(t), indices(std::move(arg_indices)), yield_type(std::move(arg_yield_type)) {
|
||||
const auto& types = indices->GetTypes();
|
||||
is_subnet_index = types.size() == 1 && types[0]->Tag() == TYPE_SUBNET;
|
||||
is_pattern_index = types.size() == 1 && types[0]->Tag() == TYPE_PATTERN;
|
||||
}
|
||||
: Type(t), indices(std::move(arg_indices)), yield_type(std::move(arg_yield_type)) {}
|
||||
|
||||
~IndexType() override = default;
|
||||
|
||||
|
@ -376,17 +377,12 @@ protected:
|
|||
|
||||
TypeListPtr indices;
|
||||
TypePtr yield_type;
|
||||
|
||||
bool is_subnet_index;
|
||||
bool is_pattern_index;
|
||||
};
|
||||
|
||||
class TableType : public IndexType {
|
||||
public:
|
||||
TableType(TypeListPtr ind, TypePtr yield);
|
||||
|
||||
~TableType();
|
||||
|
||||
/**
|
||||
* Assesses whether an &expire_func attribute's function type is compatible
|
||||
* with this table type.
|
||||
|
@ -402,17 +398,9 @@ public:
|
|||
// what one gets using an empty "set()" or "table()" constructor.
|
||||
bool IsUnspecifiedTable() const;
|
||||
|
||||
const detail::CompositeHash* GetTableHash() const { return table_hash; }
|
||||
|
||||
// Called to rebuild the associated hash function when a record type
|
||||
// (that this table type depends on) gets redefined during parsing.
|
||||
void RegenerateHash();
|
||||
|
||||
private:
|
||||
bool DoExpireCheck(const detail::AttrPtr& attr);
|
||||
|
||||
detail::CompositeHash* table_hash = nullptr;
|
||||
|
||||
// Used to prevent repeated error messages.
|
||||
bool reported_error = false;
|
||||
};
|
||||
|
|
35
src/Val.cc
35
src/Val.cc
|
@ -1568,6 +1568,7 @@ void TableVal::Init(TableTypePtr t, bool ordered) {
|
|||
if ( table_type->IsPatternIndex() )
|
||||
pattern_matcher = std::make_unique<detail::TablePatternMatcher>(this, table_type->Yield());
|
||||
|
||||
table_hash = new detail::CompositeHash(table_type->GetIndices());
|
||||
if ( ordered )
|
||||
table_val = new PDict<TableEntryVal>(DictOrder::ORDERED);
|
||||
else
|
||||
|
@ -1580,6 +1581,7 @@ TableVal::~TableVal() {
|
|||
if ( timer )
|
||||
detail::timer_mgr->Cancel(timer);
|
||||
|
||||
delete table_hash;
|
||||
delete table_val;
|
||||
delete expire_iterator;
|
||||
}
|
||||
|
@ -1754,7 +1756,7 @@ bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const {
|
|||
auto* v = tble.value;
|
||||
|
||||
if ( is_first_init && t->AsTable()->Lookup(k.get()) ) {
|
||||
auto key = GetTableHash()->RecoverVals(*k);
|
||||
auto key = table_hash->RecoverVals(*k);
|
||||
// ### Shouldn't complain if their values are equal.
|
||||
key->Warn("multiple initializations for index");
|
||||
continue;
|
||||
|
@ -2079,7 +2081,7 @@ bool TableVal::UpdateTimestamp(Val* index) {
|
|||
return true;
|
||||
}
|
||||
|
||||
ListValPtr TableVal::RecreateIndex(const detail::HashKey& k) const { return GetTableHash()->RecoverVals(k); }
|
||||
ListValPtr TableVal::RecreateIndex(const detail::HashKey& k) const { return table_hash->RecoverVals(k); }
|
||||
|
||||
void TableVal::CallChangeFunc(const ValPtr& index, const ValPtr& old_value, OnChangeType tpe) {
|
||||
if ( ! change_func || ! index || in_change_func )
|
||||
|
@ -2268,7 +2270,7 @@ ValPtr TableVal::Remove(const detail::HashKey& k, bool* iterators_invalidated) {
|
|||
va = v->GetVal() ? v->GetVal() : IntrusivePtr{NewRef{}, this};
|
||||
|
||||
if ( subnets ) {
|
||||
auto index = GetTableHash()->RecoverVals(k);
|
||||
auto index = table_hash->RecoverVals(k);
|
||||
|
||||
if ( ! subnets->Remove(index.get()) )
|
||||
reporter->InternalWarning("index not in prefix table");
|
||||
|
@ -2279,7 +2281,7 @@ ValPtr TableVal::Remove(const detail::HashKey& k, bool* iterators_invalidated) {
|
|||
Modified();
|
||||
|
||||
if ( va && (change_func || ! broker_store.empty()) ) {
|
||||
auto index = GetTableHash()->RecoverVals(k);
|
||||
auto index = table_hash->RecoverVals(k);
|
||||
if ( ! broker_store.empty() )
|
||||
SendToStore(index.get(), nullptr, ELEMENT_REMOVED);
|
||||
|
||||
|
@ -2295,7 +2297,7 @@ ListValPtr TableVal::ToListVal(TypeTag t) const {
|
|||
|
||||
for ( const auto& tble : *table_val ) {
|
||||
auto k = tble.GetHashKey();
|
||||
auto index = GetTableHash()->RecoverVals(*k);
|
||||
auto index = table_hash->RecoverVals(*k);
|
||||
|
||||
if ( t == TYPE_ANY )
|
||||
l->Append(std::move(index));
|
||||
|
@ -2327,7 +2329,7 @@ std::unordered_map<ValPtr, ValPtr> TableVal::ToMap() const {
|
|||
for ( const auto& iter : *table_val ) {
|
||||
auto k = iter.GetHashKey();
|
||||
auto v = iter.value;
|
||||
auto vl = GetTableHash()->RecoverVals(*k);
|
||||
auto vl = table_hash->RecoverVals(*k);
|
||||
|
||||
res[std::move(vl)] = v->GetVal();
|
||||
}
|
||||
|
@ -2364,7 +2366,7 @@ void TableVal::Describe(ODesc* d) const {
|
|||
auto k = iter->GetHashKey();
|
||||
auto* v = iter->value;
|
||||
|
||||
auto vl = GetTableHash()->RecoverVals(*k);
|
||||
auto vl = table_hash->RecoverVals(*k);
|
||||
int dim = vl->Length();
|
||||
|
||||
ODesc intermediary_d;
|
||||
|
@ -2703,7 +2705,7 @@ unsigned int TableVal::ComputeFootprint(std::unordered_set<const Val*>* analyzed
|
|||
|
||||
for ( const auto& iter : *table_val ) {
|
||||
auto k = iter.GetHashKey();
|
||||
auto vl = GetTableHash()->RecoverVals(*k);
|
||||
auto vl = table_hash->RecoverVals(*k);
|
||||
auto v = iter.value->GetVal();
|
||||
|
||||
fp += vl->Footprint(analyzed_vals);
|
||||
|
@ -2715,25 +2717,19 @@ unsigned int TableVal::ComputeFootprint(std::unordered_set<const Val*>* analyzed
|
|||
}
|
||||
|
||||
std::unique_ptr<detail::HashKey> TableVal::MakeHashKey(const Val& index) const {
|
||||
return GetTableHash()->MakeHashKey(index, true);
|
||||
return table_hash->MakeHashKey(index, true);
|
||||
}
|
||||
|
||||
std::set<TableType*> TableVal::SaveParseTimeTableState(RecordType* rt) {
|
||||
std::set<TableType*> affected_table_types;
|
||||
|
||||
void TableVal::SaveParseTimeTableState(RecordType* rt) {
|
||||
auto it = parse_time_table_record_dependencies.find(rt);
|
||||
|
||||
if ( it == parse_time_table_record_dependencies.end() )
|
||||
return affected_table_types;
|
||||
return;
|
||||
|
||||
auto& table_vals = it->second;
|
||||
|
||||
for ( auto& tv : table_vals ) {
|
||||
for ( auto& tv : table_vals )
|
||||
parse_time_table_states[tv.get()] = tv->DumpTableState();
|
||||
affected_table_types.insert(tv->table_type.get());
|
||||
}
|
||||
|
||||
return affected_table_types;
|
||||
}
|
||||
|
||||
void TableVal::RebuildParseTimeTables() {
|
||||
|
@ -2759,6 +2755,9 @@ TableVal::ParseTimeTableState TableVal::DumpTableState() {
|
|||
}
|
||||
|
||||
void TableVal::RebuildTable(ParseTimeTableState ptts) {
|
||||
delete table_hash;
|
||||
table_hash = new detail::CompositeHash(table_type->GetIndices());
|
||||
|
||||
for ( auto& [key, val] : ptts )
|
||||
Assign(std::move(key), std::move(val));
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ namespace detail {
|
|||
class ScriptFunc;
|
||||
class Frame;
|
||||
class PrefixTable;
|
||||
class CompositeHash;
|
||||
class HashKey;
|
||||
class TablePatternMatcher;
|
||||
|
||||
|
@ -929,7 +930,7 @@ public:
|
|||
|
||||
const PDict<TableEntryVal>* Get() const { return table_val; }
|
||||
|
||||
const detail::CompositeHash* GetTableHash() const { return table_type->GetTableHash(); }
|
||||
const detail::CompositeHash* GetTableHash() const { return table_hash; }
|
||||
|
||||
// Returns the size of the table.
|
||||
int Size() const;
|
||||
|
@ -971,8 +972,7 @@ public:
|
|||
|
||||
// Retrieves and saves all table state (key-value pairs) for
|
||||
// tables whose index type depends on the given RecordType.
|
||||
// Returns the associated table types.
|
||||
static std::set<TableType*> SaveParseTimeTableState(RecordType* rt);
|
||||
static void SaveParseTimeTableState(RecordType* rt);
|
||||
|
||||
// Rebuilds all TableVals whose state was previously saved by
|
||||
// SaveParseTimeTableState(). This is used to re-recreate the tables
|
||||
|
@ -1043,6 +1043,7 @@ protected:
|
|||
ValPtr DoClone(CloneState* state) override;
|
||||
|
||||
TableTypePtr table_type;
|
||||
detail::CompositeHash* table_hash;
|
||||
detail::AttributesPtr attrs;
|
||||
detail::ExprPtr expire_time;
|
||||
detail::ExprPtr expire_func;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue