mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
Val: cast_value_to_type() returns IntrusivePtr
This commit is contained in:
parent
96951c1300
commit
3331abb4f2
4 changed files with 6 additions and 8 deletions
|
@ -4797,8 +4797,7 @@ IntrusivePtr<Val> CastExpr::Eval(Frame* f) const
|
|||
if ( ! v )
|
||||
return 0;
|
||||
|
||||
IntrusivePtr<Val> nv{AdoptRef{}, cast_value_to_type(v.get(), Type())};
|
||||
|
||||
auto nv = cast_value_to_type(v.get(), Type());
|
||||
if ( nv )
|
||||
return nv;
|
||||
|
||||
|
|
|
@ -834,7 +834,7 @@ Val* SwitchStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
|
|||
if ( matching_id )
|
||||
{
|
||||
auto cv = cast_value_to_type(v, matching_id->Type());
|
||||
f->SetElement(matching_id, cv);
|
||||
f->SetElement(matching_id, cv.release());
|
||||
}
|
||||
|
||||
flow = FLOW_NEXT;
|
||||
|
|
|
@ -3206,7 +3206,7 @@ void delete_vals(val_list* vals)
|
|||
}
|
||||
}
|
||||
|
||||
Val* cast_value_to_type(Val* v, BroType* t)
|
||||
IntrusivePtr<Val> cast_value_to_type(Val* v, BroType* t)
|
||||
{
|
||||
// Note: when changing this function, adapt all three of
|
||||
// cast_value_to_type()/can_cast_value_to_type()/can_cast_value_to_type().
|
||||
|
@ -3217,7 +3217,7 @@ Val* cast_value_to_type(Val* v, BroType* t)
|
|||
// Always allow casting to same type. This also covers casting 'any'
|
||||
// to the actual type.
|
||||
if ( same_type(v->Type(), t) )
|
||||
return v->Ref();
|
||||
return {NewRef{}, v};
|
||||
|
||||
if ( same_type(v->Type(), bro_broker::DataVal::ScriptDataType()) )
|
||||
{
|
||||
|
@ -3226,7 +3226,7 @@ Val* cast_value_to_type(Val* v, BroType* t)
|
|||
if ( ! dv )
|
||||
return nullptr;
|
||||
|
||||
return static_cast<bro_broker::DataVal *>(dv)->castTo(t).release();
|
||||
return static_cast<bro_broker::DataVal *>(dv)->castTo(t);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
|
|
@ -1037,10 +1037,9 @@ extern void delete_vals(val_list* vals);
|
|||
inline bool is_vector(Val* v) { return v->Type()->Tag() == TYPE_VECTOR; }
|
||||
|
||||
// Returns v casted to type T if the type supports that. Returns null if not.
|
||||
// The returned value will be ref'ed.
|
||||
//
|
||||
// Note: This implements the script-level cast operator.
|
||||
extern Val* cast_value_to_type(Val* v, BroType* t);
|
||||
extern IntrusivePtr<Val> cast_value_to_type(Val* v, BroType* t);
|
||||
|
||||
// Returns true if v can be casted to type T. If so, check_and_cast() will
|
||||
// succeed as well.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue