diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index 739e0d709d..5234ef6e35 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -173,9 +173,9 @@ void DNS_Mgr_mapping_delete_func(void* v) static TableVal* empty_addr_set() { - BroType* addr_t = base_type(TYPE_ADDR); + IntrusivePtr addr_t{AdoptRef{}, base_type(TYPE_ADDR)}; auto set_index = make_intrusive(addr_t); - set_index->Append(addr_t); + set_index->Append(std::move(addr_t)); auto s = make_intrusive(std::move(set_index), nullptr); return new TableVal(std::move(s)); } diff --git a/src/Expr.cc b/src/Expr.cc index 4f9da75168..3c954ee5bb 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -3109,7 +3109,7 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr constructor_li else { if ( op->AsListExpr()->Exprs().empty() ) - SetType(make_intrusive(make_intrusive(base_type(TYPE_ANY)), nullptr)); + SetType(make_intrusive(make_intrusive(IntrusivePtr{AdoptRef{}, base_type(TYPE_ANY)}), nullptr)); else { SetType({AdoptRef{}, init_type(op.get())}); @@ -3223,7 +3223,7 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr constructor_list, else { if ( op->AsListExpr()->Exprs().empty() ) - SetType(make_intrusive<::SetType>(make_intrusive(base_type(TYPE_ANY)), nullptr)); + SetType(make_intrusive<::SetType>(make_intrusive(IntrusivePtr{AdoptRef{}, base_type(TYPE_ANY)}), nullptr)); else SetType({AdoptRef{}, init_type(op.get())}); } @@ -3841,7 +3841,7 @@ FlattenExpr::FlattenExpr(IntrusivePtr arg_op) auto tl = make_intrusive(); for ( int i = 0; i < num_fields; ++i ) - tl->Append(rt->FieldType(i)->Ref()); + tl->Append({NewRef{}, rt->FieldType(i)}); Unref(rt); SetType(std::move(tl)); @@ -4481,7 +4481,7 @@ ListExpr::~ListExpr() void ListExpr::Append(IntrusivePtr e) { exprs.push_back(e.release()); - ((TypeList*) type.get())->Append(exprs.back()->Type()->Ref()); + ((TypeList*) type.get())->Append({NewRef{}, exprs.back()->Type()}); } bool ListExpr::IsPure() const @@ -4568,12 +4568,12 @@ IntrusivePtr ListExpr::InitType() const if ( ! til->IsPure() || ! til->AllMatch(til->PureType(), 1) ) - tl->Append(til->Ref()); + tl->Append({NewRef{}, til}); else - tl->Append(til->PureType()->Ref()); + tl->Append({NewRef{}, til->PureType()}); } else - tl->Append(ti->Ref()); + tl->Append({NewRef{}, ti}); } return tl; @@ -5121,7 +5121,7 @@ int check_and_promote_args(ListExpr* const args, RecordType* types) TypeList* tl = new TypeList(); for ( int i = 0; i < types->NumFields(); ++i ) - tl->Append(types->FieldType(i)->Ref()); + tl->Append({NewRef{}, types->FieldType(i)}); int rval = check_and_promote_exprs(args, tl); Unref(tl); diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 8674f428d8..b0ed446e6f 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -793,8 +793,8 @@ bool BloomFilterVal::Typify(BroType* arg_type) type = arg_type; type->Ref(); - auto tl = make_intrusive(type); - tl->Append(type->Ref()); + auto tl = make_intrusive(IntrusivePtr{NewRef{}, type}); + tl->Append({NewRef{}, type}); hash = new CompositeHash(std::move(tl)); return true; @@ -963,8 +963,8 @@ bool CardinalityVal::Typify(BroType* arg_type) type = arg_type; type->Ref(); - auto tl = make_intrusive(type); - tl->Append(type->Ref()); + auto tl = make_intrusive(IntrusivePtr{NewRef{}, type}); + tl->Append({NewRef{}, type}); hash = new CompositeHash(std::move(tl)); return true; diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index e52861295a..35a25b201c 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -145,8 +145,8 @@ RuleConditionEval::RuleConditionEval(const char* func) rules_error("eval function type must yield a 'bool'", func); TypeList tl; - tl.Append(internal_type("signature_state")->Ref()); - tl.Append(base_type(TYPE_STRING)); + tl.Append({NewRef{}, internal_type("signature_state")}); + tl.Append({AdoptRef{}, base_type(TYPE_STRING)}); if ( ! f->CheckArgs(tl.Types()) ) rules_error("eval function parameters must be a 'signature_state' " diff --git a/src/Stmt.cc b/src/Stmt.cc index 2691487602..76dd181b6b 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -587,7 +587,7 @@ static void int_del_func(void* v) void SwitchStmt::Init() { auto t = make_intrusive(); - t->Append(e->Type()->Ref()); + t->Append({NewRef{}, e->Type()}); comp_hash = new CompositeHash(std::move(t)); case_label_value_map.SetDeleteFunc(int_del_func); diff --git a/src/Type.cc b/src/Type.cc index 274aa9c468..9a245511c0 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -155,8 +155,6 @@ TypeList::~TypeList() { for ( const auto& type : types ) Unref(type); - - Unref(pure_type); } int TypeList::AllMatch(const BroType* t, int is_init) const @@ -167,23 +165,20 @@ int TypeList::AllMatch(const BroType* t, int is_init) const return 1; } -void TypeList::Append(BroType* t) +void TypeList::Append(IntrusivePtr t) { - if ( pure_type && ! same_type(t, pure_type) ) + if ( pure_type && ! same_type(t.get(), pure_type.get()) ) reporter->InternalError("pure type-list violation"); - types.push_back(t); + types.push_back(t.release()); } -void TypeList::AppendEvenIfNotPure(BroType* t) +void TypeList::AppendEvenIfNotPure(IntrusivePtr t) { - if ( pure_type && ! same_type(t, pure_type) ) - { - Unref(pure_type); + if ( pure_type && ! same_type(t.get(), pure_type.get()) ) pure_type = 0; - } - types.push_back(t); + types.push_back(t.release()); } void TypeList::Describe(ODesc* d) const @@ -368,7 +363,7 @@ TypeList* TableType::ExpandRecordIndex(RecordType* rt) const for ( int i = 0; i < n; ++i ) { TypeDecl* td = rt->FieldDecl(i); - tl->Append(td->type->Ref()); + tl->Append({NewRef{}, td->type}); } return tl; @@ -396,21 +391,17 @@ SetType::SetType(IntrusivePtr ind, IntrusivePtr arg_elements else if ( tl->length() == 1 ) { - BroType* t = flatten_type((*tl)[0]->Ref()); + IntrusivePtr t{AdoptRef{}, flatten_type((*tl)[0]->Ref())}; indices = make_intrusive(t); - indices->Append(t->Ref()); + indices->Append(std::move(t)); } else { - BroType* t = merge_types((*tl)[0], (*tl)[1]); + IntrusivePtr t{AdoptRef{}, merge_types((*tl)[0], (*tl)[1])}; for ( int i = 2; t && i < tl->length(); ++i ) - { - BroType* t_new = merge_types(t, (*tl)[i]); - Unref(t); - t = t_new; - } + t = {AdoptRef{}, merge_types(t.get(), (*tl)[i])}; if ( ! t ) { @@ -419,7 +410,7 @@ SetType::SetType(IntrusivePtr ind, IntrusivePtr arg_elements } indices = make_intrusive(t); - indices->Append(t); + indices->Append(std::move(t)); } } } @@ -457,7 +448,7 @@ FuncType::FuncType(RecordType* arg_args, BroType* arg_yield, function_flavor arg args->Error(err_str); } - arg_types->Append(args->FieldType(i)->Ref()); + arg_types->Append({NewRef{}, args->FieldType(i)}); } } @@ -1832,11 +1823,11 @@ BroType* merge_types(const BroType* t1, const BroType* t2) loop_over_list(*tl1, i) { - BroType* tl3_i = merge_types((*tl1)[i], (*tl2)[i]); + IntrusivePtr tl3_i{AdoptRef{}, merge_types((*tl1)[i], (*tl2)[i])}; if ( ! tl3_i ) return 0; - tl3->Append(tl3_i); + tl3->Append(std::move(tl3_i)); } } @@ -1952,7 +1943,7 @@ BroType* merge_types(const BroType* t1, const BroType* t2) TypeList* tl3 = new TypeList(); loop_over_list(*l1, i) - tl3->Append(merge_types((*l1)[i], (*l2)[i])); + tl3->Append({AdoptRef{}, merge_types((*l1)[i], (*l2)[i])}); return tl3; } @@ -2105,8 +2096,8 @@ BroType* init_type(Expr* init) // it one, as that's what's required for creating a set type. if ( t->Tag() != TYPE_LIST ) { - auto tl = make_intrusive(t.get()->Ref()); - tl->Append(t.release()); + auto tl = make_intrusive(t); + tl->Append(std::move(t)); t = std::move(tl); } diff --git a/src/Type.h b/src/Type.h index 0acc1da850..c63962c95d 100644 --- a/src/Type.h +++ b/src/Type.h @@ -347,11 +347,8 @@ private: class TypeList : public BroType { public: - explicit TypeList(BroType* arg_pure_type = 0) : BroType(TYPE_LIST) + explicit TypeList(IntrusivePtr arg_pure_type = nullptr) : BroType(TYPE_LIST), pure_type(std::move(arg_pure_type)) { - pure_type = arg_pure_type; - if ( pure_type ) - pure_type->Ref(); } ~TypeList() override; @@ -362,23 +359,23 @@ public: // Returns the underlying pure type, or nil if the list // is not pure or is empty. - BroType* PureType() { return pure_type; } - const BroType* PureType() const { return pure_type; } + BroType* PureType() { return pure_type.get(); } + const BroType* PureType() const { return pure_type.get(); } // True if all of the types match t, false otherwise. If // is_init is true, then the matching is done in the context // of an initialization. int AllMatch(const BroType* t, int is_init) const; - void Append(BroType* t); - void AppendEvenIfNotPure(BroType* t); + void Append(IntrusivePtr t); + void AppendEvenIfNotPure(IntrusivePtr t); void Describe(ODesc* d) const override; unsigned int MemoryAllocation() const override; protected: - BroType* pure_type; + IntrusivePtr pure_type; type_list types; }; diff --git a/src/Val.cc b/src/Val.cc index 7b82051d9c..f053836c52 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1185,7 +1185,7 @@ IntrusivePtr PatternVal::DoClone(CloneState* state) } ListVal::ListVal(TypeTag t) -: Val(new TypeList(t == TYPE_ANY ? 0 : base_type_no_ref(t))) +: Val(new TypeList({NewRef{}, t == TYPE_ANY ? 0 : base_type_no_ref(t)})) { tag = t; } @@ -1226,7 +1226,7 @@ void ListVal::Append(Val* v) } vals.push_back(v); - type->AsTypeList()->Append(v->Type()->Ref()); + type->AsTypeList()->Append({NewRef{}, v->Type()}); } TableVal* ListVal::ConvertToSet() const @@ -1234,8 +1234,8 @@ TableVal* ListVal::ConvertToSet() const if ( tag == TYPE_ANY ) Internal("conversion of heterogeneous list to set"); - auto set_index = make_intrusive(type->AsTypeList()->PureType()); - set_index->Append(base_type(tag)); + auto set_index = make_intrusive(IntrusivePtr{NewRef{}, type->AsTypeList()->PureType()}); + set_index->Append({AdoptRef{}, base_type(tag)}); auto s = make_intrusive(std::move(set_index), nullptr); TableVal* t = new TableVal(std::move(s)); diff --git a/src/file_analysis/AnalyzerSet.cc b/src/file_analysis/AnalyzerSet.cc index 53c677eff3..e2eed8e4ac 100644 --- a/src/file_analysis/AnalyzerSet.cc +++ b/src/file_analysis/AnalyzerSet.cc @@ -21,8 +21,8 @@ static void analyzer_del_func(void* v) AnalyzerSet::AnalyzerSet(File* arg_file) : file(arg_file) { auto t = make_intrusive(); - t->Append(file_mgr->GetTagEnumType()->Ref()); - t->Append(BifType::Record::Files::AnalyzerArgs->Ref()); + t->Append({NewRef{}, file_mgr->GetTagEnumType()}); + t->Append({NewRef{}, BifType::Record::Files::AnalyzerArgs}); analyzer_hash = new CompositeHash(std::move(t)); analyzer_map.SetDeleteFunc(analyzer_del_func); } diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index f982080d5a..569dcaca32 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -23,8 +23,8 @@ using namespace file_analysis; static Val* empty_connection_table() { - auto tbl_index = make_intrusive(conn_id); - tbl_index->Append(conn_id->Ref()); + auto tbl_index = make_intrusive(IntrusivePtr{NewRef{}, conn_id}); + tbl_index->Append({NewRef{}, conn_id}); auto tbl_type = make_intrusive(std::move(tbl_index), IntrusivePtr{NewRef{}, connection_type}); return new TableVal(std::move(tbl_type)); } diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 18d13fff17..0e4d2af186 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -2377,8 +2377,8 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ { // all entries have to have the same type... BroType* type = request_type->AsTableType()->Indices()->PureType(); - auto set_index = make_intrusive(type->Ref()); - set_index->Append(type->Ref()); + auto set_index = make_intrusive(IntrusivePtr{NewRef{}, type}); + set_index->Append({NewRef{}, type}); auto s = make_intrusive(std::move(set_index), nullptr); TableVal* t = new TableVal(std::move(s)); for ( int j = 0; j < val->val.set_val.size; j++ ) @@ -2534,7 +2534,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co if ( stag == TYPE_VOID ) TypeTag stag = val->val.set_val.vals[0]->type; - BroType* index_type; + IntrusivePtr index_type; if ( stag == TYPE_ENUM ) { @@ -2552,13 +2552,13 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co return nullptr; } - index_type = enum_id->Type()->AsEnumType(); + index_type = {NewRef{}, enum_id->Type()->AsEnumType()}; } else - index_type = base_type_no_ref(stag); + index_type = {NewRef{}, base_type_no_ref(stag)}; set_index = make_intrusive(index_type); - set_index->Append(index_type->Ref()); + set_index->Append(std::move(index_type)); } auto s = make_intrusive(std::move(set_index), nullptr); diff --git a/src/parse.y b/src/parse.y index 621ec377af..6a52961152 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1027,11 +1027,11 @@ type: type_list: type_list ',' type - { $1->AppendEvenIfNotPure($3); } + { $1->AppendEvenIfNotPure({AdoptRef{}, $3}); } | type { - $$ = new TypeList($1); - $$->Append($1); + $$ = new TypeList({NewRef{}, $1}); + $$->Append({AdoptRef{}, $1}); } ; diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index d369e2b6c5..de9c530689 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -27,8 +27,8 @@ void TopkVal::Typify(BroType* t) { assert(!hash && !type); type = t->Ref(); - auto tl = make_intrusive(t); - tl->Append(t->Ref()); + auto tl = make_intrusive(IntrusivePtr{NewRef{}, t}); + tl->Append({NewRef{}, t}); hash = new CompositeHash(std::move(tl)); } @@ -199,8 +199,8 @@ VectorVal* TopkVal::GetTopK(int k) const // returns vector return 0; } - TypeList* vector_index = new TypeList(type); - vector_index->Append(type->Ref()); + TypeList* vector_index = new TypeList({NewRef{}, type}); + vector_index->Append({NewRef{}, type}); VectorType* v = new VectorType(vector_index); VectorVal* t = new VectorVal(v);