Migrate Tag classes to use IntrusivePtr

Deprecates various methods that previously took raw pointers
This commit is contained in:
Jon Siwek 2020-05-05 17:10:34 -07:00
parent b096e552d3
commit 1abed4fd4c
20 changed files with 174 additions and 85 deletions

View file

@ -21,7 +21,7 @@ static void analyzer_del_func(void* v)
AnalyzerSet::AnalyzerSet(File* arg_file) : file(arg_file)
{
auto t = make_intrusive<TypeList>();
t->Append({NewRef{}, file_mgr->GetTagEnumType()});
t->Append(file_mgr->GetTagType());
t->Append({NewRef{}, BifType::Record::Files::AnalyzerArgs});
analyzer_hash = new CompositeHash(std::move(t));
analyzer_map.SetDeleteFunc(analyzer_del_func);
@ -164,7 +164,7 @@ bool AnalyzerSet::RemoveMod::Perform(AnalyzerSet* set)
HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const
{
ListVal* lv = new ListVal(TYPE_ANY);
lv->Append({NewRef{}, t.AsEnumVal()});
lv->Append(t.AsVal());
lv->Append({NewRef{}, args});
HashKey* key = analyzer_hash->ComputeHash(lv, true);
Unref(lv);

View file

@ -422,13 +422,9 @@ string Manager::GetFileID(const analyzer::Tag& tag, Connection* c, bool is_orig)
DBG_LOG(DBG_FILE_ANALYSIS, "Raise get_file_handle() for protocol analyzer %s",
analyzer_mgr->GetComponentName(tag).c_str());
EnumVal* tagval = tag.AsEnumVal();
const auto& tagval = tag.AsVal();
mgr.Enqueue(get_file_handle,
IntrusivePtr{NewRef{}, tagval},
c->ConnVal(),
val_mgr->Bool(is_orig)
);
mgr.Enqueue(get_file_handle, tagval, c->ConnVal(), val_mgr->Bool(is_orig));
mgr.Drain(); // need file handle immediately so we don't have to buffer data
return current_file_id;
}

View file

@ -8,7 +8,7 @@ using namespace file_analysis;
const file_analysis::Tag file_analysis::Tag::Error;
file_analysis::Tag::Tag(type_t type, subtype_t subtype)
: ::Tag(file_mgr->GetTagEnumType(), type, subtype)
: ::Tag(file_mgr->GetTagType(), type, subtype)
{
}
@ -18,7 +18,20 @@ file_analysis::Tag& file_analysis::Tag::operator=(const file_analysis::Tag& othe
return *this;
}
const IntrusivePtr<EnumVal>& file_analysis::Tag::AsVal() const
{
return ::Tag::AsVal(file_mgr->GetTagType());
}
EnumVal* file_analysis::Tag::AsEnumVal() const
{
return ::Tag::AsEnumVal(file_mgr->GetTagEnumType());
return AsVal().get();
}
file_analysis::Tag::Tag(IntrusivePtr<EnumVal> val)
: ::Tag(std::move(val))
{ }
file_analysis::Tag::Tag(EnumVal* val)
: ::Tag({NewRef{}, val})
{ }

View file

@ -82,6 +82,9 @@ public:
*
* @param etype the script-layer enum type associated with the tag.
*/
const IntrusivePtr<EnumVal>& AsVal() const;
[[deprecated("Remove in v4.1. Use AsVal() instead.")]]
EnumVal* AsEnumVal() const;
static const Tag Error;
@ -107,7 +110,10 @@ protected:
*
* @param val An enum value of script type \c Files::Tag.
*/
explicit Tag(EnumVal* val) : ::Tag(val) {}
explicit Tag(IntrusivePtr<EnumVal> val);
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
explicit Tag(EnumVal* val);
};
}

View file

@ -68,7 +68,8 @@ function Files::__stop%(file_id: string%): bool
## :zeek:see:`Files::analyzer_name`.
function Files::__analyzer_name%(tag: Files::Tag%) : string
%{
return make_intrusive<StringVal>(file_mgr->GetComponentName(tag));
const auto& n = file_mgr->GetComponentName(IntrusivePtr{NewRef{}, tag->AsEnumVal()});
return make_intrusive<StringVal>(n);
%}
## :zeek:see:`Files::file_exists`.