Move Dictionary/PDict, List/PList, and Queue/PQueue to zeek namespace

This commit is contained in:
Tim Wojtulewicz 2020-06-23 13:25:43 -07:00
parent 4a1e17f4e0
commit 464efbe66a
30 changed files with 172 additions and 138 deletions

View file

@ -5,23 +5,23 @@
#include "List.h"
ZEEK_FORWARD_DECLARE_NAMESPACED(Val, zeek);
using val_list = PList<zeek::Val>;
using val_list = zeek::PList<zeek::Val>;
ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
using expr_list = PList<zeek::detail::Expr>;
using expr_list = zeek::PList<zeek::detail::Expr>;
ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail);
using id_list = PList<zeek::detail::ID>;
using id_list = zeek::PList<zeek::detail::ID>;
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
using stmt_list = PList<zeek::detail::Stmt>;
using stmt_list = zeek::PList<zeek::detail::Stmt>;
namespace zeek { class Type; }
using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type;
using type_list = PList<zeek::Type>;
using type_list = zeek::PList<zeek::Type>;
ZEEK_FORWARD_DECLARE_NAMESPACED(Attr, zeek::detail);
using attr_list = PList<zeek::detail::Attr>;
using attr_list = zeek::PList<zeek::detail::Attr>;
class Timer;
using timer_list = PList<Timer, ListOrder::UNORDERED>;
using timer_list = zeek::PList<Timer, zeek::ListOrder::UNORDERED>;

View file

@ -49,7 +49,6 @@ private:
int current_level;
int suspend_level;
typedef PList<void> voidp_list;
using voidp_list = zeek::PList<void>;
voidp_list states;
};

View file

@ -29,8 +29,7 @@ using ListValPtr = zeek::IntrusivePtr<ListVal>;
using TableValPtr = zeek::IntrusivePtr<TableVal>;
}
typedef PList<DNS_Mgr_Request> DNS_mgr_request_list;
using DNS_mgr_request_list = zeek::PList<DNS_Mgr_Request>;
struct nb_dns_info;
struct nb_dns_result;

View file

@ -30,7 +30,7 @@ struct ParseLocationRec {
};
class StmtLocMapping;
typedef PQueue<StmtLocMapping> Filemap; // mapping for a single file
typedef zeek::PQueue<StmtLocMapping> Filemap; // mapping for a single file
class DbgBreakpoint;
class DbgWatch;

View file

@ -123,7 +123,7 @@ static void choose_global_symbols_regex(const string& regex, vector<zeek::detail
// DebugCmdInfo implementation
//
PQueue<DebugCmdInfo> g_DebugCmdInfos;
zeek::PQueue<DebugCmdInfo> g_DebugCmdInfos;
DebugCmdInfo::DebugCmdInfo(const DebugCmdInfo& info)
: cmd(info.cmd), helpstring(nullptr)

View file

@ -41,7 +41,7 @@ protected:
bool repeatable;
};
extern PQueue<DebugCmdInfo> g_DebugCmdInfos;
extern zeek::PQueue<DebugCmdInfo> g_DebugCmdInfos;
void init_global_dbg_constants ();

View file

@ -13,17 +13,18 @@
// If the mean bucket length exceeds the following then Insert() will
// increase the size of the hash table.
#define DEFAULT_DENSITY_THRESH 3.0
constexpr double DEFAULT_DENSITY_THRESH = 3.0;
// Threshold above which we do not try to ensure that the hash size
// is prime.
#define PRIME_THRESH 1000
constexpr int PRIME_THRESH = 1000;
// Default number of hash buckets in dictionary. The dictionary will
// increase the size of the hash table as needed.
#define DEFAULT_DICT_SIZE 16
constexpr int DEFAULT_DICT_SIZE = 16;
TEST_SUITE_BEGIN("Dict");
namespace zeek {
namespace detail {
class DictEntry {
public:
@ -40,6 +41,8 @@ public:
void* value;
};
} //namespace detail
// The value of an iteration cookie is the bucket and offset within the
// bucket at which to start looking for the next value to return.
class IterCookie {
@ -47,25 +50,29 @@ public:
IterCookie(int b, int o) : bucket(b), offset(o) {}
int bucket, offset;
PList<DictEntry>** ttbl = nullptr;
zeek::PList<detail::DictEntry>** ttbl = nullptr;
const int* num_buckets_p = nullptr;
PList<DictEntry> inserted; // inserted while iterating
zeek::PList<detail::DictEntry> inserted; // inserted while iterating
};
} // namespace zeek
TEST_SUITE_BEGIN("Dict");
TEST_CASE("dict construction")
{
PDict<int> dict;
zeek::PDict<int> dict;
CHECK(dict.IsOrdered() == false);
CHECK(dict.Length() == 0);
PDict<int> dict2(ORDERED);
zeek::PDict<int> dict2(zeek::ORDERED);
CHECK(dict2.IsOrdered() == true);
CHECK(dict2.Length() == 0);
}
TEST_CASE("dict operation")
{
PDict<uint32_t> dict;
zeek::PDict<uint32_t> dict;
uint32_t val = 10;
uint32_t key_val = 5;
@ -111,8 +118,8 @@ TEST_CASE("dict operation")
TEST_CASE("dict nthentry")
{
PDict<uint32_t> unordered(UNORDERED);
PDict<uint32_t> ordered(ORDERED);
zeek::PDict<uint32_t> unordered(zeek::UNORDERED);
zeek::PDict<uint32_t> ordered(zeek::ORDERED);
uint32_t val = 15;
uint32_t key_val = 5;
@ -147,7 +154,7 @@ TEST_CASE("dict nthentry")
TEST_CASE("dict iteration")
{
PDict<uint32_t> dict;
zeek::PDict<uint32_t> dict;
uint32_t val = 15;
uint32_t key_val = 5;
@ -161,7 +168,7 @@ TEST_CASE("dict iteration")
dict.Insert(key2, &val2);
HashKey* it_key;
IterCookie* it = dict.InitForIteration();
zeek::IterCookie* it = dict.InitForIteration();
CHECK(it != nullptr);
int count = 0;
@ -186,10 +193,14 @@ TEST_CASE("dict iteration")
delete key2;
}
Dictionary::Dictionary(dict_order ordering, int initial_size)
TEST_SUITE_END();
namespace zeek {
Dictionary::Dictionary(DictOrder ordering, int initial_size)
{
if ( ordering == ORDERED )
order = new PList<DictEntry>;
order = new zeek::PList<detail::DictEntry>;
if ( initial_size > 0 )
Init(initial_size);
@ -218,7 +229,7 @@ void Dictionary::DeInit()
for ( int i = 0; i < num_buckets; ++i )
if ( tbl[i] )
{
PList<DictEntry>* chain = tbl[i];
zeek::PList<detail::DictEntry>* chain = tbl[i];
for ( const auto& e : *chain )
{
if ( delete_func )
@ -238,7 +249,7 @@ void Dictionary::DeInit()
for ( int i = 0; i < num_buckets2; ++i )
if ( tbl2[i] )
{
PList<DictEntry>* chain = tbl2[i];
zeek::PList<detail::DictEntry>* chain = tbl2[i];
for ( const auto& e : *chain )
{
if ( delete_func )
@ -259,7 +270,7 @@ void* Dictionary::Lookup(const void* key, int key_size, hash_t hash) const
return nullptr;
hash_t h;
PList<DictEntry>* chain;
zeek::PList<detail::DictEntry>* chain;
// Figure out which hash table to look in.
h = hash % num_buckets;
@ -287,12 +298,12 @@ void* Dictionary::Insert(void* key, int key_size, hash_t hash, void* val,
if ( ! tbl )
Init(DEFAULT_DICT_SIZE);
DictEntry* new_entry = new DictEntry(key, key_size, hash, val);
detail::DictEntry* new_entry = new detail::DictEntry(key, key_size, hash, val);
void* old_val = Insert(new_entry, copy_key);
if ( old_val )
{
// We didn't need the new DictEntry, the key was already
// We didn't need the new detail::DictEntry, the key was already
// present.
delete new_entry;
}
@ -315,7 +326,7 @@ void* Dictionary::Remove(const void* key, int key_size, hash_t hash,
return nullptr;
hash_t h;
PList<DictEntry>* chain;
zeek::PList<detail::DictEntry>* chain;
int* num_entries_ptr;
// Figure out which hash table to look in
@ -338,7 +349,7 @@ void* Dictionary::Remove(const void* key, int key_size, hash_t hash,
for ( auto i = 0u; i < chain_length; ++i )
{
DictEntry* entry = (*chain)[i];
detail::DictEntry* entry = (*chain)[i];
if ( entry->hash == hash && entry->len == key_size &&
! memcmp(key, entry->key, key_size) )
@ -357,8 +368,8 @@ void* Dictionary::Remove(const void* key, int key_size, hash_t hash,
return nullptr;
}
void* Dictionary::DoRemove(DictEntry* entry, hash_t h,
PList<DictEntry>* chain, int chain_offset)
void* Dictionary::DoRemove(detail::DictEntry* entry, hash_t h,
zeek::PList<detail::DictEntry>* chain, int chain_offset)
{
void* entry_value = entry->value;
@ -397,7 +408,7 @@ void* Dictionary::NthEntry(int n, const void*& key, int& key_len) const
if ( ! order || n < 0 || n >= Length() )
return nullptr;
DictEntry* entry = (*order)[n];
detail::DictEntry* entry = (*order)[n];
key = entry->key;
key_len = entry->len;
return entry->value;
@ -417,7 +428,7 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c
{
if ( ! tbl && ! tbl2 )
{
const_cast<PList<IterCookie>*>(&cookies)->remove(cookie);
const_cast<zeek::PList<IterCookie>*>(&cookies)->remove(cookie);
delete cookie;
cookie = nullptr;
return nullptr;
@ -427,7 +438,7 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c
// That keeps the list small and helps avoiding searching
// a large list when deleting an entry.
DictEntry* entry;
detail::DictEntry* entry;
if ( cookie->inserted.length() )
{
@ -442,7 +453,7 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c
int b = cookie->bucket;
int o = cookie->offset;
PList<DictEntry>** ttbl;
zeek::PList<detail::DictEntry>** ttbl;
const int* num_buckets_p;
if ( ! cookie->ttbl )
@ -484,7 +495,7 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c
// FIXME: I don't like removing the const here. But is there
// a better way?
const_cast<PList<IterCookie>*>(&cookies)->remove(cookie);
const_cast<zeek::PList<IterCookie>*>(&cookies)->remove(cookie);
delete cookie;
cookie = nullptr;
return nullptr;
@ -503,7 +514,7 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c
void Dictionary::Init(int size)
{
num_buckets = NextPrime(size);
tbl = new PList<DictEntry>*[num_buckets];
tbl = new zeek::PList<detail::DictEntry>*[num_buckets];
for ( int i = 0; i < num_buckets; ++i )
tbl[i] = nullptr;
@ -515,7 +526,7 @@ void Dictionary::Init(int size)
void Dictionary::Init2(int size)
{
num_buckets2 = NextPrime(size);
tbl2 = new PList<DictEntry>*[num_buckets2];
tbl2 = new zeek::PList<detail::DictEntry>*[num_buckets2];
for ( int i = 0; i < num_buckets2; ++i )
tbl2[i] = nullptr;
@ -524,12 +535,12 @@ void Dictionary::Init2(int size)
}
// private
void* Dictionary::Insert(DictEntry* new_entry, bool copy_key)
void* Dictionary::Insert(detail::DictEntry* new_entry, bool copy_key)
{
if ( ! tbl )
Init(DEFAULT_DICT_SIZE);
PList<DictEntry>** ttbl;
zeek::PList<detail::DictEntry>** ttbl;
int* num_entries_ptr;
int* max_num_entries_ptr;
hash_t h = new_entry->hash % num_buckets;
@ -554,7 +565,7 @@ void* Dictionary::Insert(DictEntry* new_entry, bool copy_key)
max_num_entries_ptr = &max_num_entries2;
}
PList<DictEntry>* chain = ttbl[h];
zeek::PList<detail::DictEntry>* chain = ttbl[h];
int n = new_entry->len;
@ -562,7 +573,7 @@ void* Dictionary::Insert(DictEntry* new_entry, bool copy_key)
{
for ( int i = 0; i < chain->length(); ++i )
{
DictEntry* entry = (*chain)[i];
detail::DictEntry* entry = (*chain)[i];
if ( entry->hash == new_entry->hash &&
entry->len == n &&
@ -576,7 +587,7 @@ void* Dictionary::Insert(DictEntry* new_entry, bool copy_key)
}
else
// Create new chain.
chain = ttbl[h] = new PList<DictEntry>;
chain = ttbl[h] = new zeek::PList<detail::DictEntry>;
// If we got this far, then we couldn't use an existing copy
// of the key, so make a new one if necessary.
@ -660,7 +671,7 @@ void Dictionary::MoveChains()
do
{
PList<DictEntry>* chain = tbl[tbl_next_ind++];
zeek::PList<detail::DictEntry>* chain = tbl[tbl_next_ind++];
if ( ! chain )
continue;
@ -720,13 +731,13 @@ unsigned int Dictionary::MemoryAllocation() const
for ( int i = 0; i < num_buckets; ++i )
if ( tbl[i] )
{
PList<DictEntry>* chain = tbl[i];
zeek::PList<detail::DictEntry>* chain = tbl[i];
for ( const auto& c : *chain )
size += padded_sizeof(DictEntry) + pad_size(c->len);
size += padded_sizeof(detail::DictEntry) + pad_size(c->len);
size += chain->MemoryAllocation();
}
size += pad_size(num_buckets * sizeof(PList<DictEntry>*));
size += pad_size(num_buckets * sizeof(zeek::PList<detail::DictEntry>*));
if ( order )
size += order->MemoryAllocation();
@ -736,13 +747,13 @@ unsigned int Dictionary::MemoryAllocation() const
for ( int i = 0; i < num_buckets2; ++i )
if ( tbl2[i] )
{
PList<DictEntry>* chain = tbl2[i];
zeek::PList<detail::DictEntry>* chain = tbl2[i];
for ( const auto& c : *chain )
size += padded_sizeof(DictEntry) + pad_size(c->len);
size += padded_sizeof(detail::DictEntry) + pad_size(c->len);
size += chain->MemoryAllocation();
}
size += pad_size(num_buckets2 * sizeof(PList<DictEntry>*));
size += pad_size(num_buckets2 * sizeof(zeek::PList<detail::DictEntry>*));
}
return size;
@ -753,4 +764,4 @@ void generic_delete_func(void* v)
free(v);
}
TEST_SUITE_END();
} // namespace zeek

View file

@ -2,27 +2,31 @@
#pragma once
#include "zeek-config.h"
#include "List.h"
#include "Hash.h"
class Dictionary;
class DictEntry;
class IterCookie;
// Type indicating whether the dictionary should keep track of the order
// of insertions.
enum dict_order { ORDERED, UNORDERED };
ZEEK_FORWARD_DECLARE_NAMESPACED(DictEntry, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(IterCookie, zeek);
// Type for function to be called when deleting elements.
typedef void (*dict_delete_func)(void*);
namespace zeek {
// Type indicating whether the dictionary should keep track of the order
// of insertions.
enum DictOrder { ORDERED, UNORDERED };
// A dict_delete_func that just calls delete.
extern void generic_delete_func(void*);
class Dictionary {
public:
explicit Dictionary(dict_order ordering = UNORDERED,
int initial_size = 0);
explicit Dictionary(DictOrder ordering = UNORDERED,
int initial_size = 0);
~Dictionary();
// Member functions for looking up a key, inserting/changing its
@ -125,10 +129,10 @@ private:
void DeInit();
// Internal version of Insert().
void* Insert(DictEntry* entry, bool copy_key);
void* Insert(zeek::detail::DictEntry* entry, bool copy_key);
void* DoRemove(DictEntry* entry, hash_t h,
PList<DictEntry>* chain, int chain_offset);
void* DoRemove(zeek::detail::DictEntry* entry, hash_t h,
zeek::PList<zeek::detail::DictEntry>* chain, int chain_offset);
int NextPrime(int n) const;
bool IsPrime(int n) const;
@ -158,7 +162,7 @@ private:
// When we're resizing, we'll have tbl (old) and tbl2 (new)
// tbl_next_ind keeps track of how much we've moved to tbl2
// (it's the next index we're going to move).
PList<DictEntry>** tbl = nullptr;
zeek::PList<zeek::detail::DictEntry>** tbl = nullptr;
int num_buckets = 0;
int num_entries = 0;
int max_num_entries = 0;
@ -167,7 +171,7 @@ private:
double den_thresh = 0.0;
// Resizing table (replicates tbl above).
PList<DictEntry>** tbl2 = nullptr;
zeek::PList<zeek::detail::DictEntry>** tbl2 = nullptr;
int num_buckets2 = 0;
int num_entries2 = 0;
int max_num_entries2 = 0;
@ -177,16 +181,16 @@ private:
hash_t tbl_next_ind = 0;
PList<DictEntry>* order = nullptr;
zeek::PList<zeek::detail::DictEntry>* order = nullptr;
dict_delete_func delete_func = nullptr;
PList<IterCookie> cookies;
zeek::PList<IterCookie> cookies;
};
template<typename T>
class PDict : public Dictionary {
public:
explicit PDict(dict_order ordering = UNORDERED, int initial_size = 0) :
explicit PDict(DictOrder ordering = UNORDERED, int initial_size = 0) :
Dictionary(ordering, initial_size) {}
T* Lookup(const char* key) const
{
@ -221,3 +225,8 @@ public:
T* RemoveEntry(const HashKey& key)
{ return (T*) Remove(key.Key(), key.Size(), key.Hash()); }
};
} //namespace zeek
using Dictionary [[deprecated("Remove in v4.1. Use zeek::Dictionary instead.")]] = zeek::Dictionary;
template<typename T> using PDict [[deprecated("Remove in v4.1. Use zeek::PDict instead.")]] = zeek::PDict<T>;

View file

@ -3,17 +3,17 @@
TEST_CASE("list construction")
{
List<int> list;
zeek::List<int> list;
CHECK(list.empty());
List<int> list2(10);
zeek::List<int> list2(10);
CHECK(list2.empty());
CHECK(list2.max() == 10);
}
TEST_CASE("list operation")
{
List<int> list({ 1, 2, 3 });
zeek::List<int> list({ 1, 2, 3 });
CHECK(list.size() == 3);
CHECK(list.max() == 3);
CHECK(list[0] == 1);
@ -85,7 +85,7 @@ TEST_CASE("list operation")
TEST_CASE("list iteration")
{
List<int> list({ 1, 2, 3, 4});
zeek::List<int> list({ 1, 2, 3, 4});
int index = 1;
for ( int v : list )
@ -98,7 +98,7 @@ TEST_CASE("list iteration")
TEST_CASE("plists")
{
PList<int> list;
zeek::PList<int> list;
list.push_back(new int(1));
list.push_back(new int(2));
list.push_back(new int(3));
@ -117,7 +117,7 @@ TEST_CASE("plists")
TEST_CASE("unordered list operation")
{
List<int, ListOrder::UNORDERED> list({1, 2, 3, 4});
zeek::List<int, zeek::ListOrder::UNORDERED> list({1, 2, 3, 4});
CHECK(list.size() == 4);
// An unordered list doesn't maintain the ordering of the elements when

View file

@ -26,6 +26,10 @@
#include <cassert>
#include "util.h"
//enum class [[deprecated("Remove in v4.1. Use zeek::ListOrder instead.")]] ListOrder : int { ORDERED, UNORDERED };
namespace zeek {
enum class ListOrder : int { ORDERED, UNORDERED };
template<typename T, ListOrder Order = ListOrder::ORDERED>
@ -331,7 +335,11 @@ template<typename T, ListOrder Order = ListOrder::ORDERED>
using PList = List<T*, Order>;
// Popular type of list: list of strings.
typedef PList<char> name_list;
using name_list = PList<char>;
} // namespace zeek
using ListOrder [[deprecated("Remove in v4.1. Use zeek::ListOrder instead.")]] = zeek::ListOrder;
// Macro to visit each list element in turn.
#define loop_over_list(list, iterator) \

View file

@ -11,7 +11,7 @@ class EquivClass;
ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek::detail);
typedef PList<NFA_State> NFA_state_list;
using NFA_state_list = zeek::PList<NFA_State>;
#define NO_ACCEPT 0

View file

@ -22,6 +22,7 @@
// Entries must be either a pointer to the data or nonzero data with
// sizeof(data) <= sizeof(void*).
namespace zeek {
template<typename T>
class Queue {
@ -196,3 +197,8 @@ protected:
template<typename T>
using PQueue = Queue<T*>;
} // namespace zeek
template<typename T> using Queue [[deprecated("Remove in v4.1. Use zeek::Queue instead.")]] = zeek::Queue<T>;
template<typename T> using PQueue [[deprecated("Remove in v4.1. Use zeek::Queue instead.")]] = zeek::PQueue<T>;

View file

@ -36,7 +36,7 @@ typedef int AcceptIdx;
typedef std::set<AcceptIdx> AcceptingSet;
typedef uint64_t MatchPos;
typedef std::map<AcceptIdx, MatchPos> AcceptingMatchSet;
typedef name_list string_list;
typedef zeek::name_list string_list;
typedef enum { MATCH_ANYWHERE, MATCH_EXACTLY, } match_type;
@ -128,7 +128,7 @@ protected:
std::map<std::string, std::string> defs;
std::map<std::string, CCL*> ccl_dict;
PList<CCL> ccl_list;
zeek::PList<CCL> ccl_list;
EquivClass equiv_class;
int* ecs;
DFA_Machine* dfa;

View file

@ -73,7 +73,7 @@ void Reporter::InitOptions()
auto wl_table = wl_val->AsTable();
HashKey* k;
IterCookie* c = wl_table->InitForIteration();
zeek::IterCookie* c = wl_table->InitForIteration();
zeek::TableEntryVal* v;
while ( (v = wl_table->NextEntry(k, c)) )

View file

@ -14,8 +14,8 @@ class RuleAction;
class RuleHdrTest;
class Rule;
typedef PList<Rule> rule_list;
typedef std::map<std::string, Rule*> rule_dict;
using rule_list = zeek::PList<Rule>;
using rule_dict = std::map<std::string, Rule*>;
class Rule {
public:
@ -58,9 +58,9 @@ private:
void SortHdrTests();
typedef PList<RuleAction> rule_action_list;
typedef PList<RuleCondition> rule_condition_list;
typedef PList<RuleHdrTest> rule_hdr_test_list;
using rule_action_list = zeek::PList<RuleAction>;
using rule_condition_list = zeek::PList<RuleCondition>;
using rule_hdr_test_list = zeek::PList<RuleHdrTest>;
rule_hdr_test_list hdr_tests;
rule_condition_list conditions;
@ -74,7 +74,7 @@ private:
bool negate; // negate test
};
typedef PList<Precond> precond_list;
using precond_list = zeek::PList<Precond>;
precond_list preconds;
rule_list dependents; // rules w/ us as a precondition
@ -92,7 +92,7 @@ private:
uint32_t depth;
};
typedef PList<Pattern> pattern_list;
using pattern_list = zeek::PList<Pattern>;
pattern_list patterns;
Rule* next; // Linkage within RuleHdrTest tree:

View file

@ -57,9 +57,9 @@ struct MaskedValue {
uint32_t mask;
};
typedef PList<MaskedValue> maskedvalue_list;
typedef PList<char> string_list;
typedef PList<BroString> bstr_list;
using maskedvalue_list = zeek::PList<MaskedValue>;
using string_list = zeek::PList<char>;
using bstr_list = zeek::PList<BroString>;
// Get values from Bro's script-level variables.
extern void id_to_maskedvallist(const char* id, maskedvalue_list* append_to,
@ -117,7 +117,7 @@ private:
int_list ids; // (only needed for debugging)
};
typedef PList<PatternSet> pattern_set_list;
using pattern_set_list = zeek::PList<PatternSet>;
pattern_set_list psets[Rule::TYPES];
// List of rules belonging to this node.
@ -131,7 +131,7 @@ private:
RuleHdrTest* child;
};
typedef PList<RuleHdrTest> rule_hdr_test_list;
using rule_hdr_test_list = zeek::PList<RuleHdrTest>;
// RuleEndpointState keeps the per-stream matching state of one
// connection endpoint.
@ -166,7 +166,7 @@ private:
Rule::PatternType type;
};
typedef PList<Matcher> matcher_list;
using matcher_list = zeek::PList<Matcher>;
analyzer::Analyzer* analyzer;
RuleEndpointState* opposite;
@ -205,8 +205,7 @@ private:
RE_Match_State* state;
};
typedef PList<Matcher> matcher_list;
using matcher_list = zeek::PList<Matcher>;
matcher_list matchers;
};

View file

@ -12,7 +12,7 @@
namespace zeek::detail {
using scope_list = PList<Scope>;
using scope_list = zeek::PList<Scope>;
static scope_list scopes;
static Scope* top_scope;

View file

@ -190,7 +190,7 @@ protected:
StmtPtr s;
};
using case_list = PList<Case>;
using case_list = zeek::PList<Case>;
class SwitchStmt final : public ExprStmt {
public:
@ -229,7 +229,7 @@ protected:
case_list* cases;
int default_case_idx;
CompositeHash* comp_hash;
PDict<int> case_label_value_map;
zeek::PDict<int> case_label_value_map;
std::vector<std::pair<ID*, int>> case_label_type_list;
};

View file

@ -620,7 +620,7 @@ public:
const char* id = nullptr;
};
using type_decl_list = PList<TypeDecl>;
using type_decl_list = zeek::PList<TypeDecl>;
class RecordType final : public Type {
public:

View file

@ -25,9 +25,12 @@
#define UDP_PORT_MASK 0x20000
#define ICMP_PORT_MASK 0x30000
namespace zeek {
template<typename T> class PDict;
};
template<typename T> using PDict [[deprecated("Remove in v4.1. Use zeek::PDict instead.")]] = zeek::PDict<T>;
class IterCookie;
ZEEK_FORWARD_DECLARE_NAMESPACED(IterCookie, zeek);
class BroString;
class BroFile;
@ -99,7 +102,7 @@ union BroValUnion {
zeek::detail::Func* func_val;
BroFile* file_val;
RE_Matcher* re_val;
PDict<TableEntryVal>* table_val;
zeek::PDict<TableEntryVal>* table_val;
std::vector<ValPtr>* record_val;
std::vector<ValPtr>* vector_val;
@ -132,7 +135,7 @@ union BroValUnion {
constexpr BroValUnion(RE_Matcher* value) noexcept
: re_val(value) {}
constexpr BroValUnion(PDict<TableEntryVal>* value) noexcept
constexpr BroValUnion(zeek::PDict<TableEntryVal>* value) noexcept
: table_val(value) {}
};
@ -237,7 +240,7 @@ public:
CONST_ACCESSOR2(zeek::TYPE_ENUM, int, int_val, AsEnum)
CONST_ACCESSOR(zeek::TYPE_STRING, BroString*, string_val, AsString)
CONST_ACCESSOR(zeek::TYPE_FUNC, zeek::detail::Func*, func_val, AsFunc)
CONST_ACCESSOR(zeek::TYPE_TABLE, PDict<TableEntryVal>*, table_val, AsTable)
CONST_ACCESSOR(zeek::TYPE_TABLE, zeek::PDict<TableEntryVal>*, table_val, AsTable)
CONST_ACCESSOR(zeek::TYPE_RECORD, std::vector<ValPtr>*, record_val, AsRecord)
CONST_ACCESSOR(zeek::TYPE_FILE, BroFile*, file_val, AsFile)
CONST_ACCESSOR(zeek::TYPE_PATTERN, RE_Matcher*, re_val, AsPattern)
@ -385,7 +388,7 @@ protected:
: type(std::move(t))
{}
ACCESSOR(zeek::TYPE_TABLE, PDict<TableEntryVal>*, table_val, AsNonConstTable)
ACCESSOR(zeek::TYPE_TABLE, zeek::PDict<TableEntryVal>*, table_val, AsNonConstTable)
ACCESSOR(zeek::TYPE_RECORD, std::vector<ValPtr>*, record_val, AsNonConstRecord)
// For internal use by the Val::Clone() methods.

View file

@ -70,14 +70,14 @@ protected:
class SteppingStoneManager {
public:
PQueue<SteppingStoneEndpoint>& OrderedEndpoints()
zeek::PQueue<SteppingStoneEndpoint>& OrderedEndpoints()
{ return ordered_endps; }
// Use postfix ++, since the first ID needs to be even.
int NextID() { return endp_cnt++; }
protected:
PQueue<SteppingStoneEndpoint> ordered_endps;
zeek::PQueue<SteppingStoneEndpoint> ordered_endps;
int endp_cnt = 0;
};

View file

@ -28,12 +28,12 @@ std::set<std::string> val_to_topic_set(zeek::Val* val)
rval.emplace(val->AsString()->CheckString());
else
{
const PDict<zeek::TableEntryVal>* tbl = val->AsTable();
const zeek::PDict<zeek::TableEntryVal>* tbl = val->AsTable();
if ( tbl->Length() == 0 )
return rval;
IterCookie* c = tbl->InitForIteration();
zeek::IterCookie* c = tbl->InitForIteration();
HashKey* k;
while ( tbl->NextEntry(k, c) )

View file

@ -93,7 +93,7 @@ public:
* @see Dictionary#InitForIteration
* @return an iterator that may be used to loop over analyzers in the set.
*/
IterCookie* InitForIteration() const
zeek::IterCookie* InitForIteration() const
{ return analyzer_map.InitForIteration(); }
/**
@ -103,7 +103,7 @@ public:
* @return the next analyzer in the set or a null pointer if there is no
* more left (in that case the cookie is also deleted).
*/
file_analysis::Analyzer* NextEntry(IterCookie* c)
file_analysis::Analyzer* NextEntry(zeek::IterCookie* c)
{ return analyzer_map.NextEntry(c); }
protected:
@ -145,7 +145,7 @@ private:
File* file; /**< File which owns the set */
CompositeHash* analyzer_hash; /**< AnalyzerArgs hashes. */
PDict<file_analysis::Analyzer> analyzer_map; /**< Indexed by AnalyzerArgs. */
zeek::PDict<file_analysis::Analyzer> analyzer_map; /**< Indexed by AnalyzerArgs. */
/**
* Abstract base class for analyzer set modifications.

View file

@ -394,7 +394,7 @@ void File::DeliverStream(const u_char* data, uint64_t len)
len > 40 ? "..." : "");
file_analysis::Analyzer* a = nullptr;
IterCookie* c = analyzers.InitForIteration();
zeek::IterCookie* c = analyzers.InitForIteration();
while ( (a = analyzers.NextEntry(c)) )
{
@ -498,7 +498,7 @@ void File::DeliverChunk(const u_char* data, uint64_t len, uint64_t offset)
len > 40 ? "..." : "");
file_analysis::Analyzer* a = nullptr;
IterCookie* c = analyzers.InitForIteration();
zeek::IterCookie* c = analyzers.InitForIteration();
while ( (a = analyzers.NextEntry(c)) )
{
@ -562,7 +562,7 @@ void File::EndOfFile()
done = true;
file_analysis::Analyzer* a = nullptr;
IterCookie* c = analyzers.InitForIteration();
zeek::IterCookie* c = analyzers.InitForIteration();
while ( (a = analyzers.NextEntry(c)) )
{
@ -595,7 +595,7 @@ void File::Gap(uint64_t offset, uint64_t len)
}
file_analysis::Analyzer* a = nullptr;
IterCookie* c = analyzers.InitForIteration();
zeek::IterCookie* c = analyzers.InitForIteration();
while ( (a = analyzers.NextEntry(c)) )
{

View file

@ -18,7 +18,7 @@ extern void add_input_file_at_front(const char* file);
// Adds the substrings (using the given delimiter) in a string to the
// given namelist.
extern void add_to_name_list(char* s, char delim, name_list& nl);
extern void add_to_name_list(char* s, char delim, zeek::name_list& nl);
extern void begin_RE();

View file

@ -99,8 +99,8 @@ public:
zeek::RecordType* rtype;
zeek::RecordType* itype;
PDict<InputHash>* currDict;
PDict<InputHash>* lastDict;
zeek::PDict<InputHash>* currDict;
zeek::PDict<InputHash>* lastDict;
zeek::detail::Func* pred;
@ -273,7 +273,7 @@ bool Manager::CreateStream(Stream* info, zeek::RecordVal* description)
{
// create config mapping in ReaderInfo. Has to be done before the construction of reader_obj.
HashKey* k;
IterCookie* c = info->config->AsTable()->InitForIteration();
zeek::IterCookie* c = info->config->AsTable()->InitForIteration();
zeek::TableEntryVal* v;
while ( (v = info->config->AsTable()->NextEntry(k, c)) )
@ -674,9 +674,9 @@ bool Manager::CreateTableStream(zeek::RecordVal* fval)
stream->itype = idx->Ref()->AsRecordType();
stream->event = event ? event_registry->Lookup(event->Name()) : nullptr;
stream->error_event = error_event ? event_registry->Lookup(error_event->Name()) : nullptr;
stream->currDict = new PDict<InputHash>;
stream->currDict = new zeek::PDict<InputHash>;
stream->currDict->SetDeleteFunc(input_hash_delete_func);
stream->lastDict = new PDict<InputHash>;
stream->lastDict = new zeek::PDict<InputHash>;
stream->lastDict->SetDeleteFunc(input_hash_delete_func);
stream->want_record = ( want_record->InternalInt() == 1 );
@ -1319,7 +1319,7 @@ void Manager::EndCurrentSend(ReaderFrontend* reader)
TableStream* stream = (TableStream*) i;
// lastdict contains all deleted entries and should be empty apart from that
IterCookie *c = stream->lastDict->InitForIteration();
zeek::IterCookie *c = stream->lastDict->InitForIteration();
stream->lastDict->MakeRobustCookie(c);
InputHash* ih;
HashKey *lastDictIdxKey;
@ -1372,7 +1372,7 @@ void Manager::EndCurrentSend(ReaderFrontend* reader)
delete(stream->lastDict);
stream->lastDict = stream->currDict;
stream->currDict = new PDict<InputHash>;
stream->currDict = new zeek::PDict<InputHash>;
stream->currDict->SetDeleteFunc(input_hash_delete_func);
#ifdef DEBUG

View file

@ -859,7 +859,7 @@ bool Manager::Write(zeek::EnumVal* id, zeek::RecordVal* columns_arg)
info->network_time = network_time;
HashKey* k;
IterCookie* c = filter->config->AsTable()->InitForIteration();
zeek::IterCookie* c = filter->config->AsTable()->InitForIteration();
zeek::TableEntryVal* v;
while ( (v = filter->config->AsTable()->NextEntry(k, c)) )

View file

@ -35,7 +35,7 @@ HashKey* TopkVal::GetHash(Val* v) const
TopkVal::TopkVal(uint64_t arg_size) : OpaqueVal(topk_type)
{
elementDict = new PDict<Element>;
elementDict = new zeek::PDict<Element>;
elementDict->SetDeleteFunc(topk_element_hash_delete_func);
size = arg_size;
numElements = 0;
@ -45,7 +45,7 @@ TopkVal::TopkVal(uint64_t arg_size) : OpaqueVal(topk_type)
TopkVal::TopkVal() : OpaqueVal(topk_type)
{
elementDict = new PDict<Element>;
elementDict = new zeek::PDict<Element>;
elementDict->SetDeleteFunc(topk_element_hash_delete_func);
size = 0;
numElements = 0;

View file

@ -166,7 +166,7 @@ private:
zeek::TypePtr type;
CompositeHash* hash;
std::list<Bucket*> buckets;
PDict<Element>* elementDict;
zeek::PDict<Element>* elementDict;
uint64_t size; // how many elements are we tracking?
uint64_t numElements; // how many elements do we have at the moment
bool pruned; // was this data structure pruned?

View file

@ -139,7 +139,7 @@ public:
// A stack of input buffers we're scanning. file_stack[len-1] is the
// top of the stack.
static PList<FileInfo> file_stack;
static zeek::PList<FileInfo> file_stack;
#define RET_CONST(v) \
{ \
@ -835,8 +835,8 @@ void do_atendif()
// Be careful to never delete things from this list, as the strings
// are referred to (in order to save the locations of tokens and statements,
// for error reporting and debugging).
static name_list input_files;
static name_list essential_input_files;
static zeek::name_list input_files;
static zeek::name_list essential_input_files;
void add_essential_input_file(const char* file)
{
@ -871,7 +871,7 @@ void add_input_file_at_front(const char* file)
input_files.push_front(copy_string(file));
}
void add_to_name_list(char* s, char delim, name_list& nl)
void add_to_name_list(char* s, char delim, zeek::name_list& nl)
{
while ( s )
{
@ -917,7 +917,7 @@ int yywrap()
// Stack is now empty.
while ( essential_input_files.length() > 0 || input_files.length() > 0 )
{
name_list& files = essential_input_files.length() > 0 ?
zeek::name_list& files = essential_input_files.length() > 0 ?
essential_input_files : input_files;
if ( load_files(files[0]) )