mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 10:08:20 +00:00
Deprecate VectorVal::Insert() taking raw Val*, use IntrusivePtr
This commit is contained in:
parent
de1e3d7d6d
commit
40db09ccbf
4 changed files with 18 additions and 8 deletions
4
NEWS
4
NEWS
|
@ -211,8 +211,8 @@ Deprecated Functionality
|
||||||
- ``TableVal::Lookup()`` is deprecated, use ``TableVal::Find()`` or
|
- ``TableVal::Lookup()`` is deprecated, use ``TableVal::Find()`` or
|
||||||
``TableVal::FindOrDefault()``.
|
``TableVal::FindOrDefault()``.
|
||||||
|
|
||||||
- ``VectorVal::Assign`` methods taking raw ``Val*`` are deprecated, use the
|
- ``VectorVal::Assign`` and ``Insert`` methods taking raw ``Val*`` are
|
||||||
methods that take ``IntrusivePtr``.
|
deprecated, use the methods that take ``IntrusivePtr``.
|
||||||
|
|
||||||
Zeek 3.1.0
|
Zeek 3.1.0
|
||||||
==========
|
==========
|
||||||
|
|
|
@ -2756,7 +2756,7 @@ void IndexExpr::Assign(Frame* f, IntrusivePtr<Val> v)
|
||||||
VectorVal* v_vect = v->AsVectorVal();
|
VectorVal* v_vect = v->AsVectorVal();
|
||||||
|
|
||||||
for ( auto idx = 0u; idx < v_vect->Size(); idx++, first++ )
|
for ( auto idx = 0u; idx < v_vect->Size(); idx++, first++ )
|
||||||
v1_vect->Insert(first, v_vect->Lookup(idx)->Ref());
|
v1_vect->Insert(first, {NewRef{}, v_vect->Lookup(idx)});
|
||||||
}
|
}
|
||||||
else if ( ! v1_vect->Assign(lv->Idx(0)->CoerceToUnsigned(), std::move(v)) )
|
else if ( ! v1_vect->Assign(lv->Idx(0)->CoerceToUnsigned(), std::move(v)) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -3092,12 +3092,11 @@ bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VectorVal::Insert(unsigned int index, Val* element)
|
bool VectorVal::Insert(unsigned int index, IntrusivePtr<Val> element)
|
||||||
{
|
{
|
||||||
if ( element &&
|
if ( element &&
|
||||||
! same_type(element->GetType().get(), GetType()->AsVectorType()->Yield().get(), false) )
|
! same_type(element->GetType().get(), GetType()->AsVectorType()->Yield().get(), false) )
|
||||||
{
|
{
|
||||||
Unref(element);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3111,7 +3110,7 @@ bool VectorVal::Insert(unsigned int index, Val* element)
|
||||||
// Note: we do *not* Ref() the element, if any, at this point.
|
// Note: we do *not* Ref() the element, if any, at this point.
|
||||||
// AssignExpr::Eval() already does this; other callers must remember
|
// AssignExpr::Eval() already does this; other callers must remember
|
||||||
// to do it similarly.
|
// to do it similarly.
|
||||||
val.vector_val->insert(it, element);
|
val.vector_val->insert(it, element.release());
|
||||||
|
|
||||||
Modified();
|
Modified();
|
||||||
return true;
|
return true;
|
||||||
|
|
15
src/Val.h
15
src/Val.h
|
@ -1309,8 +1309,19 @@ public:
|
||||||
|
|
||||||
notifier::Modifiable* Modifiable() override { return this; }
|
notifier::Modifiable* Modifiable() override { return this; }
|
||||||
|
|
||||||
// Insert an element at a specific position into the underlying vector.
|
/**
|
||||||
bool Insert(unsigned int index, Val* element);
|
* Inserts an element at the given position in the vector. All elements
|
||||||
|
* at that original position and higher are shifted up by one.
|
||||||
|
* @param index The index to insert the element at.
|
||||||
|
* @param element The value to insert into the vector.
|
||||||
|
* @return True if the element was inserted or false if the element was
|
||||||
|
* the wrong type.
|
||||||
|
*/
|
||||||
|
bool Insert(unsigned int index, IntrusivePtr<Val> element);
|
||||||
|
|
||||||
|
[[deprecated("Remove in v4.1. Insert an IntrusivePtr instead.")]]
|
||||||
|
bool Insert(unsigned int index, Val* element)
|
||||||
|
{ return Insert(index, {AdoptRef{}, element}); }
|
||||||
|
|
||||||
// Removes an element at a specific position.
|
// Removes an element at a specific position.
|
||||||
bool Remove(unsigned int index);
|
bool Remove(unsigned int index);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue