Merge remote-tracking branch 'origin/topic/bbannier/fix-spicy-main'

* origin/topic/bbannier/fix-spicy-main:
  Fix clang-tidy `bugprone-inc-dec-in-conditions` report in Spicy plugins glue compiler
  Fix clang-tidy `performance-enum-size` reports in Spicy plugin's glue compiler
  Remove unneeded copies in Spicy plugin glue compiler
  Adjust for renamed function flavor in Spicy development version
This commit is contained in:
Tim Wojtulewicz 2025-05-12 11:33:38 -07:00
commit 912356deac
4 changed files with 28 additions and 14 deletions

14
CHANGES
View file

@ -1,3 +1,17 @@
8.0.0-dev.87 | 2025-05-12 11:33:38 -0700
* Fix clang-tidy `bugprone-inc-dec-in-conditions` report in Spicy plugins glue compiler (Benjamin Bannier, Corelight)
* Fix clang-tidy `performance-enum-size` reports in Spicy plugin's glue compiler (Benjamin Bannier, Corelight)
* Remove unneeded copies in Spicy plugin glue compiler (Benjamin Bannier, Corelight)
* Adjust for renamed function flavor in Spicy development version (Benjamin Bannier, Corelight)
With zeek/spicy#2048 the flavor for functions was renamed from
`Standard` to `Function`. This patch adapts the code for that while
still allowing using earlier Spicy versions.
8.0.0-dev.82 | 2025-05-09 17:25:38 +0200 8.0.0-dev.82 | 2025-05-09 17:25:38 +0200
* speed up file analysis, remove IncrementByteCount (Justin Azoff) * speed up file analysis, remove IncrementByteCount (Justin Azoff)

View file

@ -1 +1 @@
8.0.0-dev.82 8.0.0-dev.87

@ -1 +1 @@
Subproject commit ceb058a517e1feb042ebbaf6fb80facf4b15a23d Subproject commit abd484926df173d8351bc1269a5ac0ad848b3d6e

View file

@ -38,12 +38,8 @@ static std::string::size_type looking_at(const std::string& chunk, std::string::
const std::string_view& token) { const std::string_view& token) {
eat_spaces(chunk, &i); eat_spaces(chunk, &i);
for ( char j : token ) { bool token_at_position = i < chunk.size() && token == std::string_view(chunk).substr(i, token.size());
if ( i >= chunk.size() || chunk[i++] != j ) return token_at_position ? i + token.size() : 0;
return 0;
}
return i;
} }
static void eat_token(const std::string& chunk, std::string::size_type* i, const std::string_view& token) { static void eat_token(const std::string& chunk, std::string::size_type* i, const std::string_view& token) {
@ -343,7 +339,7 @@ hilti::Result<std::string> GlueCompiler::getNextEvtBlock(std::istream& in, int*
std::string chunk; std::string chunk;
// Parser need to track whether we are inside a string or a comment. // Parser need to track whether we are inside a string or a comment.
enum State { Default, InComment, InString } state = Default; enum State : char { Default, InComment, InString } state = Default;
char prev = '\0'; char prev = '\0';
while ( true ) { while ( true ) {
@ -666,7 +662,7 @@ glue::ProtocolAnalyzer GlueCompiler::parseProtocolAnalyzer(const std::string& ch
eat_token(chunk, &i, ":"); eat_token(chunk, &i, ":");
enum { orig, resp, both } dir; enum Dir : char { orig, resp, both } dir;
while ( true ) { while ( true ) {
if ( looking_at(chunk, i, "parse") ) { if ( looking_at(chunk, i, "parse") ) {
@ -1046,7 +1042,7 @@ bool GlueCompiler::compile() {
preinit_body.addCall("zeek_rt::register_file_analyzer", preinit_body.addCall("zeek_rt::register_file_analyzer",
{builder()->stringMutable(a.name.str()), {builder()->stringMutable(a.name.str()),
builder()->vector(hilti::util::transform(a.mime_types, builder()->vector(hilti::util::transform(a.mime_types,
[&](auto m) { [&](const auto& m) {
return builder() return builder()
->stringMutable(m) ->stringMutable(m)
->template as<hilti::Expression>(); ->template as<hilti::Expression>();
@ -1100,7 +1096,7 @@ bool GlueCompiler::compile() {
m->spicy_module->add(context(), import_); m->spicy_module->add(context(), import_);
// Create a vector of unique parent paths from all EVTs files going into this module. // Create a vector of unique parent paths from all EVTs files going into this module.
auto search_dirs = hilti::util::transform(m->evts, [](auto p) { return p.parent_path(); }); auto search_dirs = hilti::util::transform(m->evts, [](const auto& p) { return p.parent_path(); });
auto search_dirs_vec = std::vector<hilti::rt::filesystem::path>(search_dirs.begin(), search_dirs.end()); auto search_dirs_vec = std::vector<hilti::rt::filesystem::path>(search_dirs.begin(), search_dirs.end());
// Import any dependencies. // Import any dependencies.
@ -1120,11 +1116,15 @@ bool GlueCompiler::compile() {
preinit_body.addCall("zeek_rt::register_spicy_module_end", {}); preinit_body.addCall("zeek_rt::register_spicy_module_end", {});
if ( ! preinit_body.empty() ) { if ( ! preinit_body.empty() ) {
#if SPICY_VERSION_NUMBER >= 11400
constexpr auto zeek_preinit_flavor = hilti::type::function::Flavor::Function;
#else
constexpr auto zeek_preinit_flavor = hilti::type::function::Flavor::Standard;
#endif
auto preinit_function = auto preinit_function =
builder()->function(hilti::ID("zeek_preinit"), builder()->function(hilti::ID("zeek_preinit"),
builder()->qualifiedType(builder()->typeVoid(), hilti::Constness::Const), {}, builder()->qualifiedType(builder()->typeVoid(), hilti::Constness::Const), {},
preinit_body.block(), hilti::type::function::Flavor::Standard, preinit_body.block(), zeek_preinit_flavor, hilti::declaration::Linkage::PreInit);
hilti::declaration::Linkage::PreInit);
init_module->add(context(), preinit_function); init_module->add(context(), preinit_function);
} }