refactor: Small style fixups in src/kernel/bitcoinkernel.cpp

* Use type alias TranslateFn:
  https://github.com/bitcoin/bitcoin/pull/30595#discussion_r2653828562
* Use std::span::data:
  https://github.com/bitcoin/bitcoin/pull/30595#discussion_r2653829743
* Use the ref helper:
  https://github.com/bitcoin/bitcoin/pull/30595#discussion_r2653829991
* Reword error handling section:
  https://github.com/bitcoin/bitcoin/pull/30595#discussion_r2653843805
This commit is contained in:
MarcoFalke committed 2026-02-03 20:07:17 +01:00
1 parent b58eebf152
commit fa51594c5c
2 files changed
+7 -8

No files matched your search

+4 -5
View File
@@ -41,7 +41,6 @@
#include <cstring> #include <cstring>
#include <exception> #include <exception>
#include <functional> #include <functional>
#include <iterator>
#include <list> #include <list>
#include <memory> #include <memory>
#include <span> #include <span>
@@ -56,7 +55,7 @@ using util::ImmediateTaskRunner;
// Define G_TRANSLATION_FUN symbol in libbitcoinkernel library so users of the // Define G_TRANSLATION_FUN symbol in libbitcoinkernel library so users of the
// library aren't required to export this symbol // library aren't required to export this symbol
extern const std::function<std::string(const char*)> G_TRANSLATION_FUN{nullptr}; extern const TranslateFn G_TRANSLATION_FUN{nullptr};
static const kernel::Context btck_context_static{}; static const kernel::Context btck_context_static{};
@@ -84,7 +83,7 @@ public:
// //
void write(std::span<const std::byte> src) void write(std::span<const std::byte> src)
{ {
if (m_writer(std::data(src), src.size(), m_user_data) != 0) { if (m_writer(src.data(), src.size(), m_user_data) != 0) {
throw std::runtime_error("Failed to write serialization data"); throw std::runtime_error("Failed to write serialization data");
} }
} }
@@ -113,13 +112,13 @@ struct Handle {
static C* create(Args&&... args) static C* create(Args&&... args)
{ {
auto cpp_obj{std::make_unique<CPP>(std::forward<Args>(args)...)}; auto cpp_obj{std::make_unique<CPP>(std::forward<Args>(args)...)};
return reinterpret_cast<C*>(cpp_obj.release()); return ref(cpp_obj.release());
} }
static C* copy(const C* ptr) static C* copy(const C* ptr)
{ {
auto cpp_obj{std::make_unique<CPP>(get(ptr))}; auto cpp_obj{std::make_unique<CPP>(get(ptr))};
return reinterpret_cast<C*>(cpp_obj.release()); return ref(cpp_obj.release());
} }
static const CPP& get(const C* ptr) static const CPP& get(const C* ptr)
+3 -3
View File
@@ -82,9 +82,9 @@ extern "C" {
* @section error Error handling * @section error Error handling
* *
* Functions communicate an error through their return types, usually returning * Functions communicate an error through their return types, usually returning
* a nullptr, 0, or false if an error is encountered. Additionally, verification * a nullptr or a status code as documented by the returning function.
* functions, e.g. for scripts, may communicate more detailed error information * Additionally, verification functions, e.g. for scripts, may communicate more
* through status code out parameters. * detailed error information through status code out parameters.
* *
* Fine-grained validation information is communicated through the validation * Fine-grained validation information is communicated through the validation
* interface. * interface.