Deprecate all ValManager "Get" methods

Alternate methods that return IntrusivePtr are available in similarly
named methods that omit the "Get" prefix.
This commit is contained in:
Jon Siwek 2020-04-03 16:36:01 -07:00
parent eb77411dbf
commit 202b3f877d
3 changed files with 86 additions and 59 deletions

3
NEWS
View file

@ -104,6 +104,9 @@ Deprecated Functionality
``analyzer::Analyzer::ConectionEventFast()`` methods are deprecated, use ``analyzer::Analyzer::ConectionEventFast()`` methods are deprecated, use
``analyzer::Analyzer::EnqueueConnEvent()`` instead. ``analyzer::Analyzer::EnqueueConnEvent()`` instead.
- All ``val_mgr`` methods starting with "Get" are deprecated, use the new
``val_mgr`` methods that return ``IntrusivePtr``.
Zeek 3.1.0 Zeek 3.1.0
========== ==========

View file

@ -3398,13 +3398,26 @@ bool can_cast_value_to_type(const BroType* s, BroType* t)
return false; return false;
} }
IntrusivePtr<Val> Val::MakeBool(bool b)
{
return IntrusivePtr{AdoptRef{}, new Val(bro_int_t(b), TYPE_BOOL)};
}
IntrusivePtr<Val> Val::MakeInt(bro_int_t i)
{
return IntrusivePtr{AdoptRef{}, new Val(i, TYPE_INT)};
}
IntrusivePtr<Val> Val::MakeCount(bro_uint_t u)
{
return IntrusivePtr{AdoptRef{}, new Val(u, TYPE_COUNT)};
}
ValManager::ValManager() ValManager::ValManager()
{ {
empty_string = new StringVal(""); empty_string = make_intrusive<StringVal>("");
b_false = Val::MakeBool(false); b_false = Val::MakeBool(false);
b_true = Val::MakeBool(true); b_true = Val::MakeBool(true);
counts = new Val*[PREALLOCATED_COUNTS];
ints = new Val*[PREALLOCATED_INTS];
for ( auto i = 0u; i < PREALLOCATED_COUNTS; ++i ) for ( auto i = 0u; i < PREALLOCATED_COUNTS; ++i )
counts[i] = Val::MakeCount(i); counts[i] = Val::MakeCount(i);
@ -3418,37 +3431,16 @@ ValManager::ValManager()
auto port_type = (TransportProto)i; auto port_type = (TransportProto)i;
for ( auto j = 0u; j < arr.size(); ++j ) for ( auto j = 0u; j < arr.size(); ++j )
arr[j] = new PortVal(PortVal::Mask(j, port_type)); arr[j] = IntrusivePtr{AdoptRef{}, new PortVal(PortVal::Mask(j, port_type))};
} }
} }
ValManager::~ValManager()
{
Unref(empty_string);
Unref(b_true);
Unref(b_false);
for ( auto i = 0u; i < PREALLOCATED_COUNTS; ++i )
Unref(counts[i]);
for ( auto i = 0u; i < PREALLOCATED_INTS; ++i )
Unref(ints[i]);
delete [] counts;
delete [] ints;
for ( auto& arr : ports )
for ( auto& pv : arr )
Unref(pv);
}
StringVal* ValManager::GetEmptyString() const StringVal* ValManager::GetEmptyString() const
{ {
::Ref(empty_string); return empty_string->Ref()->AsStringVal();
return empty_string;
} }
PortVal* ValManager::GetPort(uint32_t port_num, TransportProto port_type) const const IntrusivePtr<PortVal>& ValManager::Port(uint32_t port_num, TransportProto port_type) const
{ {
if ( port_num >= 65536 ) if ( port_num >= 65536 )
{ {
@ -3456,22 +3448,30 @@ PortVal* ValManager::GetPort(uint32_t port_num, TransportProto port_type) const
port_num = 0; port_num = 0;
} }
auto rval = ports[port_type][port_num]; return ports[port_type][port_num];
::Ref(rval);
return rval;
} }
PortVal* ValManager::GetPort(uint32_t port_num) const PortVal* ValManager::GetPort(uint32_t port_num, TransportProto port_type) const
{
return Port(port_num, port_type)->Ref()->AsPortVal();
}
const IntrusivePtr<PortVal>& ValManager::Port(uint32_t port_num) const
{ {
auto mask = port_num & PORT_SPACE_MASK; auto mask = port_num & PORT_SPACE_MASK;
port_num &= ~PORT_SPACE_MASK; port_num &= ~PORT_SPACE_MASK;
if ( mask == TCP_PORT_MASK ) if ( mask == TCP_PORT_MASK )
return GetPort(port_num, TRANSPORT_TCP); return Port(port_num, TRANSPORT_TCP);
else if ( mask == UDP_PORT_MASK ) else if ( mask == UDP_PORT_MASK )
return GetPort(port_num, TRANSPORT_UDP); return Port(port_num, TRANSPORT_UDP);
else if ( mask == ICMP_PORT_MASK ) else if ( mask == ICMP_PORT_MASK )
return GetPort(port_num, TRANSPORT_ICMP); return Port(port_num, TRANSPORT_ICMP);
else else
return GetPort(port_num, TRANSPORT_UNKNOWN); return Port(port_num, TRANSPORT_UNKNOWN);
}
PortVal* ValManager::GetPort(uint32_t port_num) const
{
return Port(port_num)->Ref()->AsPortVal();
} }

View file

@ -335,20 +335,9 @@ protected:
virtual void ValDescribe(ODesc* d) const; virtual void ValDescribe(ODesc* d) const;
virtual void ValDescribeReST(ODesc* d) const; virtual void ValDescribeReST(ODesc* d) const;
static Val* MakeBool(bool b) static IntrusivePtr<Val> MakeBool(bool b);
{ static IntrusivePtr<Val> MakeInt(bro_int_t i);
return new Val(bro_int_t(b), TYPE_BOOL); static IntrusivePtr<Val> MakeCount(bro_uint_t u);
}
static Val* MakeInt(bro_int_t i)
{
return new Val(i, TYPE_INT);
}
static Val* MakeCount(bro_uint_t u)
{
return new Val(u, TYPE_COUNT);
}
template<typename V> template<typename V>
Val(V &&v, TypeTag t) noexcept Val(V &&v, TypeTag t) noexcept
@ -406,44 +395,79 @@ public:
ValManager(); ValManager();
~ValManager(); [[deprecated("Remove in v4.1. Use val_mgr->True() instead.")]]
inline Val* GetTrue() const inline Val* GetTrue() const
{ return b_true->Ref(); } { return b_true->Ref(); }
inline const IntrusivePtr<Val>& True() const
{ return b_true; }
[[deprecated("Remove in v4.1. Use val_mgr->False() instead.")]]
inline Val* GetFalse() const inline Val* GetFalse() const
{ return b_false->Ref(); } { return b_false->Ref(); }
inline const IntrusivePtr<Val>& False() const
{ return b_false; }
[[deprecated("Remove in v4.1. Use val_mgr->Bool() instead.")]]
inline Val* GetBool(bool b) const inline Val* GetBool(bool b) const
{ return b ? b_true->Ref() : b_false->Ref(); } { return b ? b_true->Ref() : b_false->Ref(); }
inline const IntrusivePtr<Val>& Bool(bool b) const
{ return b ? b_true : b_false; }
[[deprecated("Remove in v4.1. Use val_mgr->Int() instead.")]]
inline Val* GetInt(int64_t i) const inline Val* GetInt(int64_t i) const
{ {
return i < PREALLOCATED_INT_LOWEST || i > PREALLOCATED_INT_HIGHEST ? return i < PREALLOCATED_INT_LOWEST || i > PREALLOCATED_INT_HIGHEST ?
Val::MakeInt(i) : ints[i - PREALLOCATED_INT_LOWEST]->Ref(); Val::MakeInt(i).release() : ints[i - PREALLOCATED_INT_LOWEST]->Ref();
} }
inline IntrusivePtr<Val> Int(int64_t i) const
{
return i < PREALLOCATED_INT_LOWEST || i > PREALLOCATED_INT_HIGHEST ?
Val::MakeInt(i) : ints[i - PREALLOCATED_INT_LOWEST];
}
[[deprecated("Remove in v4.1. Use val_mgr->Count() instead.")]]
inline Val* GetCount(uint64_t i) const inline Val* GetCount(uint64_t i) const
{ {
return i >= PREALLOCATED_COUNTS ? Val::MakeCount(i) : counts[i]->Ref(); return i >= PREALLOCATED_COUNTS ? Val::MakeCount(i).release() : counts[i]->Ref();
} }
inline IntrusivePtr<Val> Count(uint64_t i) const
{
return i >= PREALLOCATED_COUNTS ? Val::MakeCount(i) : counts[i];
}
[[deprecated("Remove in v4.1. Use val_mgr->EmptyString() instead.")]]
StringVal* GetEmptyString() const; StringVal* GetEmptyString() const;
inline const IntrusivePtr<StringVal>& EmptyString() const
{ return empty_string; }
// Port number given in host order. // Port number given in host order.
[[deprecated("Remove in v4.1. Use val_mgr->Port() instead.")]]
PortVal* GetPort(uint32_t port_num, TransportProto port_type) const; PortVal* GetPort(uint32_t port_num, TransportProto port_type) const;
// Port number given in host order.
const IntrusivePtr<PortVal>& Port(uint32_t port_num, TransportProto port_type) const;
// Host-order port number already masked with port space protocol mask. // Host-order port number already masked with port space protocol mask.
[[deprecated("Remove in v4.1. Use val_mgr->Port() instead.")]]
PortVal* GetPort(uint32_t port_num) const; PortVal* GetPort(uint32_t port_num) const;
// Host-order port number already masked with port space protocol mask.
const IntrusivePtr<PortVal>& Port(uint32_t port_num) const;
private: private:
std::array<std::array<PortVal*, 65536>, NUM_PORT_SPACES> ports; std::array<std::array<IntrusivePtr<PortVal>, 65536>, NUM_PORT_SPACES> ports;
StringVal* empty_string; std::array<IntrusivePtr<Val>, PREALLOCATED_COUNTS> counts;
Val* b_true; std::array<IntrusivePtr<Val>, PREALLOCATED_INTS> ints;
Val* b_false; IntrusivePtr<StringVal> empty_string;
Val** counts; IntrusivePtr<Val> b_true;
Val** ints; IntrusivePtr<Val> b_false;
}; };
extern ValManager* val_mgr; extern ValManager* val_mgr;