TableVal: Propagate &ordered through copy()

Copying an &ordered table or set would result in a copy that is not ordered.
This seems rather surprising behavior, so propagate the &ordered attribute.

Closes #2793
This commit is contained in:
Arne Welzel 2023-02-17 12:54:39 +01:00
parent 3de785114b
commit 754831d7b0
4 changed files with 71 additions and 1 deletions

View file

@ -2619,7 +2619,19 @@ double TableVal::CallExpireFunc(ListValPtr idx)
ValPtr TableVal::DoClone(CloneState* state)
{
auto tv = make_intrusive<TableVal>(table_type);
// Propagate the &ordered attribute when cloning.
//
// Some of the attributes are dealt with later, but this one needs to be
// passed explicitly to the TableVal constructor so the underlying PDict
// is initialized ordered.
detail::AttributesPtr init_attrs = nullptr;
if ( auto ordered_attr = GetAttr(detail::ATTR_ORDERED) )
{
init_attrs = zeek::make_intrusive<detail::Attributes>(table_type, false, false);
init_attrs->AddAttr(ordered_attr);
}
auto tv = make_intrusive<TableVal>(table_type, init_attrs);
state->NewClone(this, tv);
const PDict<TableEntryVal>* tbl = AsTable();