mirror of
https://github.com/zeek/zeek.git
synced 2025-10-03 23:28:20 +00:00
Change BIFs to return a wrapper object
That allows returning either Val* or IntrusivePtr<T>. The former could eventually be deprecated, but it's used extensively at the moment.
This commit is contained in:
parent
8843f69002
commit
eb77411dbf
3 changed files with 29 additions and 3 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 66b4b30305237f48535276a00a52ca304659400b
|
||||
Subproject commit daf968b2fc34c4316811adb1094f7ca1d68b92bf
|
|
@ -633,7 +633,7 @@ IntrusivePtr<Val> 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<Val> 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)
|
||||
{ }
|
||||
|
|
24
src/Func.h
24
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<Val> (the former could
|
||||
* potentially be deprecated).
|
||||
*/
|
||||
class BifReturnVal {
|
||||
public:
|
||||
|
||||
template <typename T>
|
||||
BifReturnVal(IntrusivePtr<T> v) noexcept
|
||||
: rval(AdoptRef{}, v.release())
|
||||
{ }
|
||||
|
||||
BifReturnVal(Val* v) noexcept;
|
||||
|
||||
private:
|
||||
|
||||
friend class BuiltinFunc;
|
||||
|
||||
IntrusivePtr<Val> rval;
|
||||
};
|
||||
|
||||
using built_in_func = BifReturnVal (*)(Frame* frame, const zeek::Args* args);
|
||||
|
||||
class BuiltinFunc final : public Func {
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue