* 'intrusive_ptr' of https://github.com/MaxKellermann/zeek: (32 commits)
  Scope: store IntrusivePtr in `local`
  Scope: pass IntrusivePtr to AddInit()
  DNS_Mgr: use class IntrusivePtr
  Scope: use class IntrusivePtr
  Attr: use class IntrusivePtr
  Expr: check_and_promote_expr() returns IntrusivePtr
  Frame: use class IntrusivePtr
  Val: RecordVal::LookupWithDefault() returns IntrusivePtr
  Type: RecordType::FieldDefault() returns IntrusivePtr
  Val: TableVal::Delete() returns IntrusivePtr
  Type: base_type() returns IntrusivePtr
  Type: init_type() returns IntrusivePtr
  Type: merge_types() returns IntrusivePtr
  Type: use class IntrusivePtr in VectorType
  Type: use class IntrusivePtr in EnumType
  Type: use class IntrusivePtr in FileType
  Type: use class IntrusivePtr in TypeDecl
  Type: make TypeDecl `final` and the dtor non-`virtual`
  Type: use class IntrusivePtr in TypeType
  Type: use class IntrusivePtr in FuncType
  ...
This commit is contained in:
Jon Siwek 2020-03-17 22:51:46 -07:00
commit b62727a7fa
108 changed files with 1737 additions and 2067 deletions

View file

@ -180,9 +180,9 @@ char* CompositeHash::SingleValHash(int type_check, char* kp0,
for ( int i = 0; i < num_fields; ++i )
{
Val* rv_i = rv->Lookup(i);
auto rv_i = rv->Lookup(i);
Attributes* a = rt->FieldDecl(i)->attrs;
Attributes* a = rt->FieldDecl(i)->attrs.get();
bool optional = (a && a->FindAttr(ATTR_OPTIONAL));
if ( ! (rv_i || optional) )
@ -249,9 +249,10 @@ char* CompositeHash::SingleValHash(int type_check, char* kp0,
if ( ! v->Type()->IsSet() )
{
Val* val = tv->Lookup(key);
auto val = tv->Lookup(key);
if ( ! (kp1 = SingleValHash(type_check, kp1, val->Type(),
val, false)) )
val.get(), false)) )
{
Unref(lv);
return 0;
@ -519,7 +520,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v,
for ( int i = 0; i < num_fields; ++i )
{
Attributes* a = rt->FieldDecl(i)->attrs;
Attributes* a = rt->FieldDecl(i)->attrs.get();
bool optional = (a && a->FindAttr(ATTR_OPTIONAL));
sz = SingleTypeKeySize(rt->FieldType(i),
@ -554,8 +555,8 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v,
if ( ! bt->IsSet() )
{
Val* val = tv->Lookup(key);
sz = SingleTypeKeySize(val->Type(), val, type_check, sz,
auto val = tv->Lookup(key);
sz = SingleTypeKeySize(val->Type(), val.get(), type_check, sz,
false, calc_static_size);
if ( ! sz )
{
@ -720,19 +721,19 @@ int CompositeHash::SizeAlign(int offset, unsigned int size) const
return offset;
}
ListVal* CompositeHash::RecoverVals(const HashKey* k) const
IntrusivePtr<ListVal> CompositeHash::RecoverVals(const HashKey* k) const
{
ListVal* l = new ListVal(TYPE_ANY);
auto l = make_intrusive<ListVal>(TYPE_ANY);
const type_list* tl = type->Types();
const char* kp = (const char*) k->Key();
const char* const k_end = kp + k->Size();
for ( const auto& type : *tl )
{
Val* v = nullptr;
kp = RecoverOneVal(k, kp, k_end, type, v, false);
IntrusivePtr<Val> v;
kp = RecoverOneVal(k, kp, k_end, type, &v, false);
ASSERT(v);
l->Append(v);
l->Append(v.release());
}
if ( kp != k_end )
@ -743,7 +744,7 @@ ListVal* CompositeHash::RecoverVals(const HashKey* k) const
const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
const char* const k_end, BroType* t,
Val*& pval, bool optional) const
IntrusivePtr<Val>* pval, bool optional) const
{
// k->Size() == 0 for a single empty string.
if ( kp0 >= k_end && k->Size() > 0 )
@ -760,7 +761,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
if ( ! *kp )
{
pval = 0;
*pval = nullptr;
return kp0;
}
}
@ -772,15 +773,15 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
kp1 = reinterpret_cast<const char*>(kp+1);
if ( tag == TYPE_ENUM )
pval = t->AsEnumType()->GetVal(*kp);
*pval = t->AsEnumType()->GetVal(*kp);
else if ( tag == TYPE_BOOL )
pval = val_mgr->GetBool(*kp);
*pval = {AdoptRef{}, val_mgr->GetBool(*kp)};
else if ( tag == TYPE_INT )
pval = val_mgr->GetInt(*kp);
*pval = {AdoptRef{}, val_mgr->GetInt(*kp)};
else
{
reporter->InternalError("bad internal unsigned int in CompositeHash::RecoverOneVal()");
pval = 0;
*pval = nullptr;
}
}
break;
@ -793,16 +794,16 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
switch ( tag ) {
case TYPE_COUNT:
case TYPE_COUNTER:
pval = val_mgr->GetCount(*kp);
*pval = {AdoptRef{}, val_mgr->GetCount(*kp)};
break;
case TYPE_PORT:
pval = val_mgr->GetPort(*kp);
*pval = {AdoptRef{}, val_mgr->GetPort(*kp)};
break;
default:
reporter->InternalError("bad internal unsigned int in CompositeHash::RecoverOneVal()");
pval = 0;
*pval = nullptr;
break;
}
}
@ -814,9 +815,9 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
kp1 = reinterpret_cast<const char*>(kp+1);
if ( tag == TYPE_INTERVAL )
pval = new IntervalVal(*kp, 1.0);
*pval = make_intrusive<IntervalVal>(*kp, 1.0);
else
pval = new Val(*kp, tag);
*pval = make_intrusive<Val>(*kp, tag);
}
break;
@ -829,12 +830,12 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
switch ( tag ) {
case TYPE_ADDR:
pval = new AddrVal(addr);
*pval = make_intrusive<AddrVal>(addr);
break;
default:
reporter->InternalError("bad internal address in CompositeHash::RecoverOneVal()");
pval = 0;
*pval = nullptr;
break;
}
}
@ -844,7 +845,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
{
const uint32_t* const kp = AlignType<uint32_t>(kp0);
kp1 = reinterpret_cast<const char*>(kp+5);
pval = new SubNetVal(kp, kp[4]);
*pval = make_intrusive<SubNetVal>(kp, kp[4]);
}
break;
@ -862,20 +863,19 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
if ( ! f )
reporter->InternalError("failed to look up unique function id %" PRIu32 " in CompositeHash::RecoverOneVal()", *kp);
pval = new Val(f);
*pval = make_intrusive<Val>(f);
auto pvt = (*pval)->Type();
if ( ! pval->Type() )
if ( ! pvt )
reporter->InternalError("bad aggregate Val in CompositeHash::RecoverOneVal()");
else if ( t->Tag() != TYPE_FUNC &&
! same_type(pval->Type(), t) )
else if ( t->Tag() != TYPE_FUNC && ! same_type(pvt, t) )
// ### Maybe fix later, but may be fundamentally
// un-checkable --US
reporter->InternalError("inconsistent aggregate Val in CompositeHash::RecoverOneVal()");
// ### A crude approximation for now.
else if ( t->Tag() == TYPE_FUNC &&
pval->Type()->Tag() != TYPE_FUNC )
else if ( t->Tag() == TYPE_FUNC && pvt->Tag() != TYPE_FUNC )
reporter->InternalError("inconsistent aggregate Val in CompositeHash::RecoverOneVal()");
}
break;
@ -898,7 +898,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
re = new RE_Matcher(kp1, kp1 + len[0]);
kp1 += len[0] + len[1];
}
pval = new PatternVal(re);
*pval = make_intrusive<PatternVal>(re);
}
break;
@ -912,13 +912,13 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
int i;
for ( i = 0; i < num_fields; ++i )
{
Val* v;
IntrusivePtr<Val> v;
Attributes* a = rt->FieldDecl(i)->attrs;
Attributes* a = rt->FieldDecl(i)->attrs.get();
bool optional = (a && a->FindAttr(ATTR_OPTIONAL));
kp = RecoverOneVal(k, kp, k_end,
rt->FieldType(i), v, optional);
rt->FieldType(i), &v, optional);
// An earlier call to reporter->InternalError would have called abort() and broken the
// call tree that clang-tidy is relying on to get the error described.
@ -926,21 +926,21 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
if ( ! (v || optional) )
{
reporter->InternalError("didn't recover expected number of fields from HashKey");
pval = 0;
pval = nullptr;
break;
}
values.push_back(v);
values.push_back(v.release());
}
ASSERT(int(values.size()) == num_fields);
RecordVal* rv = new RecordVal(rt);
auto rv = make_intrusive<RecordVal>(rt);
for ( int i = 0; i < num_fields; ++i )
rv->Assign(i, values[i]);
pval = rv;
*pval = std::move(rv);
kp1 = kp;
}
break;
@ -952,29 +952,25 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
n = *kp;
kp1 = reinterpret_cast<const char*>(kp+1);
TableType* tt = t->AsTableType();
TableVal* tv = new TableVal(tt);
vector<Val*> keys, values;
auto tv = make_intrusive<TableVal>(IntrusivePtr{NewRef{}, tt});
for ( int i = 0; i < n; ++i )
{
Val* key;
kp1 = RecoverOneVal(k, kp1, k_end, tt->Indices(), key, false);
keys.push_back(key);
if ( ! t->IsSet() )
IntrusivePtr<Val> key;
kp1 = RecoverOneVal(k, kp1, k_end, tt->Indices(), &key, false);
if ( t->IsSet() )
tv->Assign(key.get(), nullptr);
else
{
Val* value;
kp1 = RecoverOneVal(k, kp1, k_end, tt->YieldType(), value,
IntrusivePtr<Val> value;
kp1 = RecoverOneVal(k, kp1, k_end, tt->YieldType(), &value,
false);
values.push_back(value);
tv->Assign(key.get(), std::move(value));
}
}
for ( int i = 0; i < n; ++i )
{
tv->Assign(keys[i], t->IsSet() ? 0 : values[i]);
Unref(keys[i]);
}
pval = tv;
*pval = std::move(tv);
}
break;
@ -985,7 +981,8 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
n = *kp;
kp1 = reinterpret_cast<const char*>(kp+1);
VectorType* vt = t->AsVectorType();
VectorVal* vv = new VectorVal(vt);
auto vv = make_intrusive<VectorVal>(vt);
for ( unsigned int i = 0; i < n; ++i )
{
kp = AlignType<unsigned int>(kp1);
@ -994,14 +991,16 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
kp = AlignType<unsigned int>(kp1);
unsigned int have_val = *kp;
kp1 = reinterpret_cast<const char*>(kp+1);
Val* value = 0;
IntrusivePtr<Val> value;
if ( have_val )
kp1 = RecoverOneVal(k, kp1, k_end, vt->YieldType(), value,
kp1 = RecoverOneVal(k, kp1, k_end, vt->YieldType(), &value,
false);
vv->Assign(index, value);
vv->Assign(index, std::move(value));
}
pval = vv;
*pval = std::move(vv);
}
break;
@ -1012,16 +1011,17 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
n = *kp;
kp1 = reinterpret_cast<const char*>(kp+1);
TypeList* tl = t->AsTypeList();
ListVal* lv = new ListVal(TYPE_ANY);
auto lv = make_intrusive<ListVal>(TYPE_ANY);
for ( int i = 0; i < n; ++i )
{
Val* v;
IntrusivePtr<Val> v;
BroType* it = (*tl->Types())[i];
kp1 = RecoverOneVal(k, kp1, k_end, it, v, false);
lv->Append(v);
kp1 = RecoverOneVal(k, kp1, k_end, it, &v, false);
lv->Append(v.release());
}
pval = lv;
*pval = std::move(lv);
}
break;
@ -1051,7 +1051,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0,
kp1 = reinterpret_cast<const char*>(kp+1);
}
pval = new StringVal(new BroString((const byte_vec) kp1, n, 1));
*pval = make_intrusive<StringVal>(new BroString((const byte_vec) kp1, n, 1));
kp1 += n;
}
break;