diff --git a/src/File.h b/src/File.h index 8ed5d0a13e..78524826b2 100644 --- a/src/File.h +++ b/src/File.h @@ -12,8 +12,7 @@ #include #endif // NEED_KRB5_H -#include "zeek/Obj.h" -#include "zeek/IntrusivePtr.h" +#include "zeek/Val.h" #include "zeek/util.h" namespace zeek { @@ -23,6 +22,8 @@ namespace detail { class PrintStmt; class Attributes; +extern void do_print_stmt(const std::vector& vals); + } // namespace detail; class RecordVal; @@ -84,7 +85,7 @@ public: protected: - friend class detail::PrintStmt; + friend void detail::do_print_stmt(const std::vector& vals); File() { Init(); } void Init(); diff --git a/src/Stmt.cc b/src/Stmt.cc index fed57f9496..77beb1c9e9 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -306,18 +306,23 @@ ValPtr PrintStmt::DoExec(std::vector vals, StmtFlowType& /* flow */) { RegisterAccess(); + do_print_stmt(vals); + return nullptr; + } +void do_print_stmt(const std::vector& vals) + { if ( ! print_stdout ) print_stdout = new File(stdout); File* f = print_stdout; int offset = 0; - if ( vals.size() > 0 && (vals)[0]->GetType()->Tag() == TYPE_FILE ) + if ( vals.size() > 0 && vals[0] && vals[0]->GetType()->Tag() == TYPE_FILE ) { f = (vals)[0]->AsFile(); if ( ! f->IsOpen() ) - return nullptr; + return; ++offset; } @@ -331,7 +336,7 @@ ValPtr PrintStmt::DoExec(std::vector vals, case BifEnum::Log::REDIRECT_ALL: { print_log(vals); - return nullptr; + return; } case BifEnum::Log::REDIRECT_STDOUT: if ( f->FileHandle() == stdout ) @@ -339,7 +344,7 @@ ValPtr PrintStmt::DoExec(std::vector vals, // Should catch even printing to a "manually opened" stdout file, // like "/dev/stdout" or "-". print_log(vals); - return nullptr; + return; } break; default: @@ -368,8 +373,6 @@ ValPtr PrintStmt::DoExec(std::vector vals, describe_vals(vals, &d, offset); f->Write("\n", 1); } - - return nullptr; } ExprStmt::ExprStmt(ExprPtr arg_e) : Stmt(STMT_EXPR), e(std::move(arg_e)) diff --git a/src/Stmt.h b/src/Stmt.h index bd26492afe..9bf13d9c9a 100644 --- a/src/Stmt.h +++ b/src/Stmt.h @@ -62,6 +62,8 @@ protected: StmtPtr DoSubclassReduce(ListExprPtr singletons, Reducer* c) override; }; +extern void do_print_stmt(const std::vector& vals); + class ExprStmt : public Stmt { public: explicit ExprStmt(ExprPtr e);