Skip to content

Commit

Permalink
Address cppcoreguidelines-explicit-virtual-functions & no-malloc warn…
Browse files Browse the repository at this point in the history
…ings (#1765)
  • Loading branch information
yperbasis authored Jan 19, 2024
1 parent a998f34 commit df77e63
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
2 changes: 0 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ Checks: >
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-avoid-reference-coroutine-parameters,
-cppcoreguidelines-explicit-virtual-functions,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-no-malloc,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-prefer-member-initializer,
Expand Down
18 changes: 9 additions & 9 deletions silkworm/node/db/mdbx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class ROCursor {
//! \brief Read-only key-value cursor for multi-value tables
class ROCursorDupSort : public virtual ROCursor {
public:
virtual ~ROCursorDupSort() = default; // NOLINT(modernize-use-override)
~ROCursorDupSort() override = default;

virtual CursorResult to_previous_last_multi() = 0;
virtual CursorResult to_previous_last_multi(bool throw_notfound) = 0;
Expand All @@ -141,16 +141,16 @@ class ROCursorDupSort : public virtual ROCursor {
virtual CursorResult find_multivalue(const Slice& key, const Slice& value, bool throw_notfound) = 0;
virtual CursorResult lower_bound_multivalue(const Slice& key, const Slice& value) = 0;
virtual CursorResult lower_bound_multivalue(const Slice& key, const Slice& value, bool throw_notfound) = 0;
virtual MoveResult move(MoveOperation operation, bool throw_notfound) = 0; // NOLINT(modernize-use-override)
virtual MoveResult move(MoveOperation operation, const Slice& key, bool throw_notfound) = 0; // NOLINT(modernize-use-override)
MoveResult move(MoveOperation operation, bool throw_notfound) override = 0;
MoveResult move(MoveOperation operation, const Slice& key, bool throw_notfound) override = 0;
virtual MoveResult move(MoveOperation operation, const Slice& key, const Slice& value, bool throw_notfound) = 0;
[[nodiscard]] virtual std::size_t count_multivalue() const = 0;
};

//! \brief Read-write key-value cursor for single-value tables
class RWCursor : public virtual ROCursor {
public:
virtual ~RWCursor() = default; // NOLINT(modernize-use-override)
~RWCursor() override = default;

virtual MDBX_error_t put(const Slice& key, Slice* value, MDBX_put_flags_t flags) noexcept = 0;
virtual void insert(const Slice& key, Slice value) = 0;
Expand All @@ -170,16 +170,16 @@ class RWCursor : public virtual ROCursor {
//! \brief Read-write key-value cursor for multi-value tables
class RWCursorDupSort : public RWCursor, public ROCursorDupSort {
public:
virtual ~RWCursorDupSort() = default; // NOLINT(modernize-use-override)
~RWCursorDupSort() override = default;

//! \brief Remove all multi-values at the current cursor position.
virtual bool erase() = 0; // NOLINT(modernize-use-override)
virtual bool erase(bool whole_multivalue) = 0; // NOLINT(modernize-use-override)
bool erase() override = 0;
bool erase(bool whole_multivalue) override = 0;

//! \brief Seek and remove whole multi-value of the given key.
//! \return true if the key is found and a value(s) is removed.
virtual bool erase(const Slice& key) = 0; // NOLINT(modernize-use-override)
virtual bool erase(const Slice& key, bool whole_multivalue) = 0; // NOLINT(modernize-use-override)
bool erase(const Slice& key) override = 0;
bool erase(const Slice& key, bool whole_multivalue) override = 0;

//! \brief Seek and remove the particular multi-value entry of the key.
//! \return true if the given key-value pair is found and removed
Expand Down
3 changes: 2 additions & 1 deletion silkworm/node/stagedsync/stages/stage_senders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ Stage::Result Senders::parallel_recover(db::RWTxn& txn) {

secp256k1_context* context = secp256k1_context_create(SILKWORM_SECP256K1_CONTEXT_FLAGS);
if (!context) throw std::runtime_error("Could not create elliptic curve context");
[[maybe_unused]] auto _ = gsl::finally([&]() { if (context) std::free(context); });
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc)
[[maybe_unused]] auto _ = gsl::finally([&]() { std::free(context); });

BlockNum start_block_num{previous_progress + 1u};

Expand Down
9 changes: 2 additions & 7 deletions silkworm/rpc/ethdb/bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,16 @@ using roaring_bitmap_t = roaring::api::roaring_bitmap_t;
using Roaring = roaring::Roaring;

static Roaring fast_or(size_t n, const std::vector<std::unique_ptr<Roaring>>& inputs) {
const auto** x = static_cast<const roaring_bitmap_t**>(malloc(n * sizeof(roaring_bitmap_t*)));
if (x == nullptr) {
throw std::runtime_error("failed memory alloc in fast_or");
}
std::vector<const roaring_bitmap_t*> x(n);
for (size_t k = 0; k < n; ++k) {
x[k] = &inputs[k]->roaring;
}

roaring_bitmap_t* c_ans = roaring_bitmap_or_many(n, x);
roaring_bitmap_t* c_ans = roaring_bitmap_or_many(n, x.data());
if (c_ans == nullptr) {
free(x);
throw std::runtime_error("failed memory alloc in fast_or");
}
Roaring ans(c_ans);
free(x);
return ans;
}

Expand Down

0 comments on commit df77e63

Please sign in to comment.