Files
palladiumcore/src/support/events.h
Davide Grilli 21ae070217 Fix compilation with modern GCC (Ubuntu 24.04+)
Add missing C++ standard library includes required by GCC 13+ and newer
toolchains. These headers were previously included implicitly through
other headers in older GCC versions (e.g., GCC 9 on Ubuntu 20.04), but
modern compilers require explicit includes per C++ standard compliance.

Changes:
- Add <cstdint> to util/bip32.h for uint32_t type definitions
- Add <array> to net_processing.cpp for std::array
- Add <stdexcept> to multiple headers for exception types:
  * support/events.h (std::runtime_error)
  * dbwrapper.h (std::runtime_error base class)
  * streams.h (std::out_of_range, std::ios_base::failure)
  * coins.h (std::logic_error)
  * wallet/coinselection.h (std::invalid_argument, std::out_of_range)
  * rpc/util.h (std::runtime_error)
  * support/lockedpool.h (std::runtime_error)
  * support/lockedpool.cpp (std::runtime_error)
  * wallet/scriptpubkeyman.h (std::runtime_error)

This ensures compatibility across different compiler versions and
architectures (ARM64/x86_64) while maintaining backward compatibility
with older toolchains.

Tested on Ubuntu 24.04 with GCC 13.
2026-01-26 17:30:11 +01:00

58 lines
1.7 KiB
C++

// Copyright (c) 2016-2018 The Palladium Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef PALLADIUM_SUPPORT_EVENTS_H
#define PALLADIUM_SUPPORT_EVENTS_H
#include <ios>
#include <memory>
#include <stdexcept>
#include <event2/event.h>
#include <event2/http.h>
#define MAKE_RAII(type) \
/* deleter */\
struct type##_deleter {\
void operator()(struct type* ob) {\
type##_free(ob);\
}\
};\
/* unique ptr typedef */\
typedef std::unique_ptr<struct type, type##_deleter> raii_##type
MAKE_RAII(event_base);
MAKE_RAII(event);
MAKE_RAII(evhttp);
MAKE_RAII(evhttp_request);
MAKE_RAII(evhttp_connection);
inline raii_event_base obtain_event_base() {
auto result = raii_event_base(event_base_new());
if (!result.get())
throw std::runtime_error("cannot create event_base");
return result;
}
inline raii_event obtain_event(struct event_base* base, evutil_socket_t s, short events, event_callback_fn cb, void* arg) {
return raii_event(event_new(base, s, events, cb, arg));
}
inline raii_evhttp obtain_evhttp(struct event_base* base) {
return raii_evhttp(evhttp_new(base));
}
inline raii_evhttp_request obtain_evhttp_request(void(*cb)(struct evhttp_request *, void *), void *arg) {
return raii_evhttp_request(evhttp_request_new(cb, arg));
}
inline raii_evhttp_connection obtain_evhttp_connection_base(struct event_base* base, std::string host, uint16_t port) {
auto result = raii_evhttp_connection(evhttp_connection_base_new(base, nullptr, host.c_str(), port));
if (!result.get())
throw std::runtime_error("create connection failed");
return result;
}
#endif // PALLADIUM_SUPPORT_EVENTS_H