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:
Jon Siwek 2020-04-03 16:32:17 -07:00
parent 8843f69002
commit eb77411dbf
3 changed files with 29 additions and 3 deletions

View file

@ -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: