Make BIFs just return ValPtr directly instead of BifReturnVal

This commit is contained in:
Tim Wojtulewicz 2024-01-16 17:17:47 -07:00
parent 5602546f2e
commit 2aaaab4dad
11 changed files with 12 additions and 55 deletions

4
NEWS
View file

@ -51,6 +51,10 @@ Breaking Changes
values as well as the LDAP message identifier. The value within the LDAP logs values as well as the LDAP message identifier. The value within the LDAP logs
will be the most recently observed one. will be the most recently observed one.
- BIF methods now return a ``ValPtr`` directly instead of a ``BifReturnVal`` object
which was just a thin wrapper around ``ValPtr``. This may cause compilation errors
in C++ code that was calling BIF methods directly.
New Functionality New Functionality
----------------- -----------------

@ -1 +1 @@
Subproject commit cfbd7e905eae6d84542b7b5f761a9e67c20e50c5 Subproject commit 22c031762832b72c2f7b4ac8bbe8102d66b09ccc

View file

@ -1,11 +0,0 @@
// See the file "COPYING" in the main distribution directory for copyright.
#include "zeek/BifReturnVal.h"
#include "zeek/Val.h"
namespace zeek::detail {
BifReturnVal::BifReturnVal(std::nullptr_t) noexcept {}
} // namespace zeek::detail

View file

@ -1,32 +0,0 @@
// See the file "COPYING" in the main distribution directory for copyright.
#pragma once
#include "zeek/zeek-config.h"
#include "zeek/IntrusivePtr.h"
namespace zeek {
class Val;
using ValPtr = IntrusivePtr<Val>;
namespace detail {
/**
* 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(std::nullptr_t) noexcept;
ValPtr rval;
};
} // namespace detail
} // namespace zeek

View file

@ -295,7 +295,6 @@ set(MAIN_SRCS
Anon.cc Anon.cc
Attr.cc Attr.cc
Base64.cc Base64.cc
BifReturnVal.cc
CCL.cc CCL.cc
CompHash.cc CompHash.cc
Conn.cc Conn.cc

View file

@ -729,7 +729,7 @@ ValPtr BuiltinFunc::Invoke(Args* args, Frame* parent) const {
const CallExpr* call_expr = parent ? parent->GetCall() : nullptr; const CallExpr* call_expr = parent ? parent->GetCall() : nullptr;
call_stack.emplace_back(CallInfo{call_expr, this, *args}); call_stack.emplace_back(CallInfo{call_expr, this, *args});
auto result = std::move(func(parent, args).rval); auto result = func(parent, args);
call_stack.pop_back(); call_stack.pop_back();
if ( result && g_trace_state.DoTrace() ) { if ( result && g_trace_state.DoTrace() ) {

View file

@ -9,7 +9,6 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "zeek/BifReturnVal.h"
#include "zeek/Obj.h" #include "zeek/Obj.h"
#include "zeek/Scope.h" #include "zeek/Scope.h"
#include "zeek/Stmt.h" #include "zeek/Stmt.h"
@ -314,7 +313,7 @@ private:
int current_priority = 0; int current_priority = 0;
}; };
using built_in_func = BifReturnVal (*)(Frame* frame, const Args* args); using built_in_func = ValPtr (*)(Frame* frame, const Args* args);
class BuiltinFunc final : public Func { class BuiltinFunc final : public Func {
public: public:

View file

@ -37,12 +37,11 @@ class ODesc;
namespace zeek::detail { namespace zeek::detail {
class Frame; class Frame;
class BifReturnVal;
} // namespace zeek::detail } // namespace zeek::detail
namespace zeek::BifFunc { namespace zeek::BifFunc {
extern zeek::detail::BifReturnVal md5_hmac_bif(zeek::detail::Frame* frame, const zeek::Args*); zeek::ValPtr md5_hmac_bif(zeek::detail::Frame* frame, const zeek::Args*);
} }
namespace zeek::detail { namespace zeek::detail {
@ -211,7 +210,7 @@ private:
inline static bool seeds_initialized = false; inline static bool seeds_initialized = false;
friend void util::detail::hmac_md5(size_t size, const unsigned char* bytes, unsigned char digest[16]); friend void util::detail::hmac_md5(size_t size, const unsigned char* bytes, unsigned char digest[16]);
friend BifReturnVal BifFunc::md5_hmac_bif(zeek::detail::Frame* frame, const Args*); friend ValPtr BifFunc::md5_hmac_bif(zeek::detail::Frame* frame, const Args*);
}; };
enum HashKeyTag { HASH_KEY_INT, HASH_KEY_DOUBLE, HASH_KEY_STRING }; enum HashKeyTag { HASH_KEY_INT, HASH_KEY_DOUBLE, HASH_KEY_STRING };

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
// Headers to include by generated BiF code. // Headers to include by generated BiF code.
#include "zeek/BifReturnVal.h"
#include "zeek/Conn.h" #include "zeek/Conn.h"
#include "zeek/Event.h" #include "zeek/Event.h"
#include "zeek/EventRegistry.h" #include "zeek/EventRegistry.h"

View file

@ -747,7 +747,7 @@ SetupResult setup(int argc, char** argv, Options* zopts) {
auto ipbft = auto ipbft =
make_intrusive<FuncType>(make_intrusive<RecordType>(nullptr), base_type(TYPE_BOOL), FUNC_FLAVOR_FUNCTION); make_intrusive<FuncType>(make_intrusive<RecordType>(nullptr), base_type(TYPE_BOOL), FUNC_FLAVOR_FUNCTION);
ipbid->SetType(std::move(ipbft)); ipbid->SetType(std::move(ipbft));
auto init_bifs = [](Frame* frame, const Args* args) -> BifReturnVal { auto init_bifs = [](Frame* frame, const Args* args) -> ValPtr {
init_primary_bifs(); init_primary_bifs();
return val_mgr->True(); return val_mgr->True();
}; };

View file

@ -1461,7 +1461,7 @@ function sort%(v: any, ...%) : any
auto vv = v->As<zeek::VectorVal*>(); auto vv = v->As<zeek::VectorVal*>();
vv->Sort(comp); vv->Sort(comp);
return std::move(rval); return rval;
%} %}
## Returns the order of the elements in a vector according to some ## Returns the order of the elements in a vector according to some
@ -2721,7 +2721,7 @@ function to_addr%(ip: string%): addr
} }
delete [] s; delete [] s;
return std::move(ret); return ret;
%} %}
## Checks if a string is a valid IPv4 or IPv6 address. ## Checks if a string is a valid IPv4 or IPv6 address.