Merge remote-tracking branch 'origin/topic/johanna/clone'

* origin/topic/johanna/clone:
  Add leak-checks for new copy operations
  Finish implementation of copy method.
  Checkpoint - all non-opaque-types can be cloned.
  Reimplement copy().

Fixed a couple leaks during merge.
This commit is contained in:
Jon Siwek 2019-05-22 23:56:23 -07:00
commit 0f2e778216
28 changed files with 1005 additions and 58 deletions

View file

@ -172,7 +172,7 @@ public:
~Val() override;
Val* Ref() { ::Ref(this); return this; }
virtual Val* Clone() const;
Val* Clone();
int IsZero() const;
int IsOne() const;
@ -370,6 +370,9 @@ public:
protected:
friend class EnumType;
friend class ListVal;
friend class RecordVal;
friend class VectorVal;
friend class ValManager;
virtual void ValDescribe(ODesc* d) const;
@ -419,6 +422,14 @@ protected:
static Val* Unserialize(UnserialInfo* info, TypeTag type,
const BroType* exact_type);
// For internal use by the Val::Clone() methods.
struct CloneState {
std::unordered_map<const Val*, Val*> clones;
};
Val* Clone(CloneState* state);
virtual Val* DoClone(CloneState* state);
BroValUnion val;
BroType* type;
@ -636,6 +647,7 @@ protected:
PortVal(uint32 p, bool unused);
void ValDescribe(ODesc* d) const override;
Val* DoClone(CloneState* state) override;
DECLARE_SERIAL(PortVal);
};
@ -661,6 +673,8 @@ protected:
explicit AddrVal(TypeTag t) : Val(t) { }
explicit AddrVal(BroType* t) : Val(t) { }
Val* DoClone(CloneState* state) override;
DECLARE_SERIAL(AddrVal);
};
@ -689,6 +703,7 @@ protected:
SubNetVal() {}
void ValDescribe(ODesc* d) const override;
Val* DoClone(CloneState* state) override;
DECLARE_SERIAL(SubNetVal);
};
@ -721,6 +736,7 @@ protected:
StringVal() {}
void ValDescribe(ODesc* d) const override;
Val* DoClone(CloneState* state) override;
DECLARE_SERIAL(StringVal);
};
@ -741,6 +757,7 @@ protected:
PatternVal() {}
void ValDescribe(ODesc* d) const override;
Val* DoClone(CloneState* state) override;
DECLARE_SERIAL(PatternVal);
};
@ -786,6 +803,8 @@ protected:
friend class Val;
ListVal() {}
Val* DoClone(CloneState* state) override;
DECLARE_SERIAL(ListVal);
val_list vals;
@ -803,6 +822,16 @@ public:
expire_access_time = last_read_update =
int(network_time - bro_start_network_time);
}
TableEntryVal* Clone()
{
auto rval = new TableEntryVal(val ? val->Clone() : nullptr);
rval->last_access_time = last_access_time;
rval->expire_access_time = expire_access_time;
rval->last_read_update = last_read_update;
return rval;
}
~TableEntryVal() { }
Val* Value() { return val; }
@ -994,6 +1023,8 @@ protected:
// Propagates a read operation if necessary.
void ReadOperation(Val* index, TableEntryVal *v);
Val* DoClone(CloneState* state) override;
DECLARE_SERIAL(TableVal);
TableType* table_type;
@ -1009,7 +1040,7 @@ protected:
class RecordVal : public MutableVal {
public:
explicit RecordVal(RecordType* t);
explicit RecordVal(RecordType* t, bool init_fields = true);
~RecordVal() override;
Val* SizeVal() const override
@ -1066,6 +1097,8 @@ protected:
bool AddProperties(Properties arg_state) override;
bool RemoveProperties(Properties arg_state) override;
Val* DoClone(CloneState* state) override;
DECLARE_SERIAL(RecordVal);
RecordType* record_type;
@ -1097,6 +1130,7 @@ protected:
EnumVal() {}
void ValDescribe(ODesc* d) const override;
Val* DoClone(CloneState* state) override;
DECLARE_SERIAL(EnumVal);
};
@ -1157,6 +1191,7 @@ protected:
bool AddProperties(Properties arg_state) override;
bool RemoveProperties(Properties arg_state) override;
void ValDescribe(ODesc* d) const override;
Val* DoClone(CloneState* state) override;
DECLARE_SERIAL(VectorVal);
@ -1175,6 +1210,8 @@ protected:
friend class Val;
OpaqueVal() { }
Val* DoClone(CloneState* state) override;
DECLARE_SERIAL(OpaqueVal);
};