change functions for ZVal type management to static members

This commit is contained in:
Vern Paxson 2021-03-18 11:31:31 -07:00
parent 1e316c05c9
commit efe40204e0
5 changed files with 58 additions and 59 deletions

View file

@ -79,6 +79,24 @@ union ZVal {
Obj* ManagedVal() const { return managed_val; }
// True if a given type is one for which we manage the associated
// memory internally.
static bool IsManagedType(const TypePtr& t);
// Deletes a managed value. Caller needs to ensure that the ZVal
// indeed holds such.
static void DeleteManagedType(ZVal& v)
{
Unref(v.ManagedVal());
}
// Deletes a possibly-managed value.
static void DeleteIfManaged(ZVal& v, const TypePtr& t)
{
if ( IsManagedType(t) )
DeleteManagedType(v);
}
private:
friend class RecordVal;
friend class VectorVal;
@ -124,22 +142,4 @@ private:
static bool zval_was_nil;
};
// True if a given type is one for which we manage the associated
// memory internally.
bool IsManagedType(const TypePtr& t);
// Deletes a managed value. Caller needs to ensure that the ZVal
// indeed holds such.
inline void DeleteManagedType(ZVal& v)
{
Unref(v.ManagedVal());
}
// Deletes a possibly-managed value.
inline void DeleteIfManaged(ZVal& v, const TypePtr& t)
{
if ( IsManagedType(t) )
DeleteManagedType(v);
}
} // zeek