diff --git a/aux/bifcl b/aux/bifcl index 66b4b30305..daf968b2fc 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit 66b4b30305237f48535276a00a52ca304659400b +Subproject commit daf968b2fc34c4316811adb1094f7ca1d68b92bf diff --git a/src/Func.cc b/src/Func.cc index 059d3807fd..e71e431904 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -633,7 +633,7 @@ IntrusivePtr BuiltinFunc::Call(const zeek::Args& args, Frame* parent) const const CallExpr* call_expr = parent ? parent->GetCall() : nullptr; call_stack.emplace_back(CallInfo{call_expr, this, args}); - IntrusivePtr result{AdoptRef{}, func(parent, &args)}; + auto result = std::move(func(parent, &args).rval); call_stack.pop_back(); if ( result && g_trace_state.DoTrace() ) @@ -890,3 +890,7 @@ function_ingredients::~function_ingredients() delete inits; } + +BifReturnVal::BifReturnVal(Val* v) noexcept + : rval(AdoptRef{}, v) + { } diff --git a/src/Func.h b/src/Func.h index ef22bb6aa1..a66bc5934f 100644 --- a/src/Func.h +++ b/src/Func.h @@ -188,7 +188,29 @@ private: bool weak_closure_ref = false; }; -using built_in_func = Val* (*)(Frame* frame, const zeek::Args* args); +/** + * A simple wrapper class to use for the return value of BIFs so that + * they may return either a Val* or IntrusivePtr (the former could + * potentially be deprecated). + */ +class BifReturnVal { +public: + + template + BifReturnVal(IntrusivePtr v) noexcept + : rval(AdoptRef{}, v.release()) + { } + + BifReturnVal(Val* v) noexcept; + +private: + + friend class BuiltinFunc; + + IntrusivePtr rval; +}; + +using built_in_func = BifReturnVal (*)(Frame* frame, const zeek::Args* args); class BuiltinFunc final : public Func { public: