Only one instance of base_type() getting a NewRef instead of AdoptRef
fixed in merge.  All other changes are superficial formatting and
factoring.

* 'leaks' of https://github.com/MaxKellermann/zeek: (22 commits)
  Stmt: use class IntrusivePtr
  Stmt: remove unused default constructors and `friend` declarations
  Val: remove unimplemented prototype recover_val()
  Val: cast_value_to_type() returns IntrusivePtr
  Val: use IntrusivePtr in check_and_promote()
  Val: use nullptr instead of 0
  zeekygen: use class IntrusivePtr
  ID: use class IntrusivePtr
  Expr: use class IntrusivePtr
  Var: copy Location to stack, to fix use-after-free crash bug
  Scope: lookup_ID() and install_ID() return IntrusivePtr<ID>
  Scope: delete duplicate locals
  EventRegistry: automatically delete EventHandlers
  main: destroy event_registry after iosource_mgr
  zeekygen/IdentifierInfo: delete duplicate fields
  main: free the global scope in terminate_bro()
  Scope: pop_scope() returns IntrusivePtr<>
  Scope: unref all inits in destructor
  Var: pass IntrusivePtr to add_global(), add_local() etc.
  plugin/ComponentManager: hold a reference to the EnumType
  ...
This commit is contained in:
Jon Siwek 2020-02-28 00:42:17 -08:00
commit cf196bb148
41 changed files with 1864 additions and 2095 deletions

View file

@ -2,6 +2,7 @@
#pragma once
#include "IntrusivePtr.h"
#include "Obj.h"
#include "Attr.h"
#include "Notifier.h"
@ -35,9 +36,9 @@ public:
std::string ModuleName() const;
void SetType(BroType* t);
BroType* Type() { return type; }
const BroType* Type() const { return type; }
void SetType(IntrusivePtr<BroType> t);
BroType* Type() { return type.get(); }
const BroType* Type() const { return type.get(); }
void MakeType() { is_type = true; }
BroType* AsType() { return is_type ? Type() : 0; }
@ -51,10 +52,10 @@ public:
// reference to the Val, the Val will be destroyed (naturally,
// you have to take care that it will not be accessed via
// the ID afterwards).
void SetVal(Val* v, bool weak_ref = false);
void SetVal(IntrusivePtr<Val> v, bool weak_ref = false);
void SetVal(Val* v, init_class c);
void SetVal(Expr* ev, init_class c);
void SetVal(IntrusivePtr<Val> v, init_class c);
void SetVal(IntrusivePtr<Expr> ev, init_class c);
bool HasVal() const { return val != 0; }
Val* ID_Val() { return val; }
@ -75,11 +76,11 @@ public:
bool IsRedefinable() const;
void SetAttrs(Attributes* attr);
void AddAttrs(Attributes* attr);
void SetAttrs(IntrusivePtr<Attributes> attr);
void AddAttrs(IntrusivePtr<Attributes> attr);
void RemoveAttr(attr_tag a);
void UpdateValAttrs();
Attributes* Attrs() const { return attrs; }
Attributes* Attrs() const { return attrs.get(); }
Attr* FindAttr(attr_tag t) const;
@ -108,12 +109,11 @@ public:
bool HasOptionHandlers() const
{ return !option_handlers.empty(); }
// Takes ownership of callback.
void AddOptionHandler(Func* callback, int priority);
void AddOptionHandler(IntrusivePtr<Func> callback, int priority);
std::vector<Func*> GetOptionHandlers() const;
protected:
void EvalFunc(Expr* ef, Expr* ev);
void EvalFunc(IntrusivePtr<Expr> ef, IntrusivePtr<Expr> ev);
#ifdef DEBUG
void UpdateValID();
@ -122,13 +122,13 @@ protected:
const char* name;
IDScope scope;
bool is_export;
BroType* type;
IntrusivePtr<BroType> type;
bool is_const, is_enum_const, is_type, is_option;
int offset;
Val* val;
Attributes* attrs;
IntrusivePtr<Attributes> attrs;
// contains list of functions that are called when an option changes
std::multimap<int, Func*> option_handlers;
std::multimap<int, IntrusivePtr<Func>> option_handlers;
bool infer_return_type;
bool weak_ref;