mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 10:08:20 +00:00
Deprecate Val(BroFile*) ctor, replace with one using IntrusivePtr
This commit is contained in:
parent
a031f5b727
commit
65aad4922d
9 changed files with 25 additions and 19 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 2c7ded074fdea124fcae7845d1f8e77879925270
|
||||
Subproject commit 31f7e04b0da5cfa65211208c64ac62874a065fc6
|
|
@ -4,5 +4,6 @@
|
|||
#include "Event.h"
|
||||
#include "NetVar.h"
|
||||
#include "Conn.h"
|
||||
#include "File.h"
|
||||
|
||||
#include "event.bif.func_def"
|
||||
|
|
|
@ -328,8 +328,8 @@ void BroFile::RaiseOpenEvent()
|
|||
if ( ! ::file_opened )
|
||||
return;
|
||||
|
||||
Ref(this);
|
||||
Event* event = new ::Event(::file_opened, {make_intrusive<Val>(this)});
|
||||
IntrusivePtr<BroFile> bf{NewRef{}, this};
|
||||
Event* event = new ::Event(::file_opened, {make_intrusive<Val>(std::move(bf))});
|
||||
mgr.Dispatch(event, true);
|
||||
}
|
||||
|
||||
|
|
|
@ -311,9 +311,8 @@ void ProfileLogger::Log()
|
|||
// (and for consistency we dispatch it *now*)
|
||||
if ( profiling_update )
|
||||
{
|
||||
Ref(file);
|
||||
mgr.Dispatch(new Event(profiling_update, {
|
||||
make_intrusive<Val>(file),
|
||||
make_intrusive<Val>(IntrusivePtr{NewRef{}, file}),
|
||||
val_mgr->Bool(expensive),
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -57,10 +57,13 @@ static const IntrusivePtr<FileType>& GetStringFileType() noexcept
|
|||
return string_file_type;
|
||||
}
|
||||
|
||||
Val::Val(BroFile* f)
|
||||
: val(f), type(GetStringFileType())
|
||||
Val::Val(BroFile* f) : Val({AdoptRef{}, f})
|
||||
{}
|
||||
|
||||
Val::Val(IntrusivePtr<BroFile> f)
|
||||
: val(f.release()), type(GetStringFileType())
|
||||
{
|
||||
assert(f->FType()->Tag() == TYPE_STRING);
|
||||
assert(val.file_val->FType()->Tag() == TYPE_STRING);
|
||||
}
|
||||
|
||||
Val::~Val()
|
||||
|
|
|
@ -133,9 +133,11 @@ public:
|
|||
explicit Val(Func* f);
|
||||
explicit Val(IntrusivePtr<Func> f);
|
||||
|
||||
// Note, will unref 'f' when it's done, closing it unless
|
||||
// class has ref'd it.
|
||||
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
|
||||
explicit Val(BroFile* f);
|
||||
// Note, the file will be closed after this Val is destructed if there's
|
||||
// no other remaining references.
|
||||
explicit Val(IntrusivePtr<BroFile> f);
|
||||
|
||||
// Extra arg to differentiate from protected version.
|
||||
Val(IntrusivePtr<BroType> t, bool type_type)
|
||||
|
|
|
@ -121,12 +121,13 @@ function set_contents_file%(cid: conn_id, direction: count, f: file%): bool
|
|||
function get_contents_file%(cid: conn_id, direction: count%): file
|
||||
%{
|
||||
Connection* c = sessions->FindConnection(cid);
|
||||
BroFile* f = c ? c->GetRootAnalyzer()->GetContentsFile(direction) : nullptr;
|
||||
|
||||
if ( f )
|
||||
if ( c )
|
||||
{
|
||||
Ref(f);
|
||||
return make_intrusive<Val>(f);
|
||||
auto cf = c->GetRootAnalyzer()->GetContentsFile(direction);
|
||||
|
||||
if ( cf )
|
||||
return make_intrusive<Val>(IntrusivePtr{NewRef{}, cf});
|
||||
}
|
||||
|
||||
// Return some sort of error value.
|
||||
|
@ -135,5 +136,5 @@ function get_contents_file%(cid: conn_id, direction: count%): file
|
|||
else
|
||||
builtin_error("no contents file for given direction");
|
||||
|
||||
return make_intrusive<Val>(new BroFile(stderr, "-", "w"));
|
||||
return make_intrusive<Val>(make_intrusive<BroFile>(stderr, "-", "w"));
|
||||
%}
|
||||
|
|
|
@ -127,7 +127,7 @@ struct val_converter {
|
|||
auto file = BroFile::GetFile(a.data());
|
||||
|
||||
if ( file )
|
||||
return new Val(file);
|
||||
return new Val({AdoptRef{}, file});
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -4398,9 +4398,9 @@ function open%(f: string%): file
|
|||
const char* file = f->CheckString();
|
||||
|
||||
if ( streq(file, "-") )
|
||||
return make_intrusive<Val>(new BroFile(stdout, "-", "w"));
|
||||
return make_intrusive<Val>(make_intrusive<BroFile>(stdout, "-", "w"));
|
||||
else
|
||||
return make_intrusive<Val>(new BroFile(file, "w"));
|
||||
return make_intrusive<Val>(make_intrusive<BroFile>(file, "w"));
|
||||
%}
|
||||
|
||||
## Opens a file for writing or appending. If a file with the same name already
|
||||
|
@ -4415,7 +4415,7 @@ function open%(f: string%): file
|
|||
## rmdir unlink rename
|
||||
function open_for_append%(f: string%): file
|
||||
%{
|
||||
return make_intrusive<Val>(new BroFile(f->CheckString(), "a"));
|
||||
return make_intrusive<Val>(make_intrusive<BroFile>(f->CheckString(), "a"));
|
||||
%}
|
||||
|
||||
## Closes an open file and flushes any buffered content.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue