Skip to content

Commit

Permalink
WIP wont compile
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Jul 9, 2024
1 parent 0aae39d commit 6f634cd
Show file tree
Hide file tree
Showing 66 changed files with 237 additions and 235 deletions.
2 changes: 1 addition & 1 deletion include/xrpl/basics/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Buffer
operator=(Slice s)
{
// Ensure the slice isn't a subset of the buffer.
XRPL_ASSERT(
XRPL_ASSERT("Buffer assignment from Slice",
s.size() == 0 || size_ == 0 || s.data() < p_.get() ||
s.data() >= p_.get() + size_);

Expand Down
6 changes: 3 additions & 3 deletions include/xrpl/basics/FeeUnits.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ mulDivU(Source1 value, Dest mul, Source2 div)
{
// split the asserts so if one hits, the user can tell which
// without a debugger.
XRPL_ASSERT(value.value() >= 0);
XRPL_ASSERT(mul.value() >= 0);
XRPL_ASSERT(div.value() >= 0);
XRPL_ASSERT("feeunit::mulDivU value check", value.value() >= 0);
XRPL_ASSERT("feeunit::mulDivU mul check", mul.value() >= 0);
XRPL_ASSERT("feeunit::mulDivU div check", div.value() >= 0);
return std::nullopt;
}

Expand Down
8 changes: 5 additions & 3 deletions include/xrpl/basics/SlabAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef RIPPLE_BASICS_SLABALLOCATOR_H_INCLUDED
#define RIPPLE_BASICS_SLABALLOCATOR_H_INCLUDED

#include <xrpl/basics/ByteUtilities.h>
#include <xrpl/beast/type_name.h>
#include <xrpl/beast/utility/instrumentation.h>

Expand All @@ -32,6 +33,7 @@
#include <cstdint>
#include <cstring>
#include <mutex>
#include <vector>

#if BOOST_OS_LINUX
#include <sys/mman.h>
Expand Down Expand Up @@ -141,7 +143,7 @@ class SlabAllocator
void
deallocate(std::uint8_t* ptr) noexcept
{
XRPL_ASSERT(own(ptr));
XRPL_ASSERT("SlabAllocator::SlabBlock::deallocate", own(ptr));

std::lock_guard l(m_);

Expand Down Expand Up @@ -184,7 +186,7 @@ class SlabAllocator
boost::alignment::align_up(sizeof(Type) + extra, itemAlignment_))
, slabSize_(alloc)
{
XRPL_ASSERT((itemAlignment_ & (itemAlignment_ - 1)) == 0);
XRPL_ASSERT("SlabAllocator constructor", (itemAlignment_ & (itemAlignment_ - 1)) == 0);
}

SlabAllocator(SlabAllocator const& other) = delete;
Expand Down Expand Up @@ -294,7 +296,7 @@ class SlabAllocator
bool
deallocate(std::uint8_t* ptr) noexcept
{
XRPL_ASSERT(ptr);
XRPL_ASSERT("SlabAllocator::deallocate", ptr);

for (auto slab = slabs_.load(); slab != nullptr; slab = slab->next_)
{
Expand Down
2 changes: 1 addition & 1 deletion include/xrpl/basics/Slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Slice
std::uint8_t
operator[](std::size_t i) const noexcept
{
XRPL_ASSERT(i < size_);
XRPL_ASSERT("Slice const indexing", i < size_);
return data_[i];
}

Expand Down
4 changes: 2 additions & 2 deletions include/xrpl/basics/base_uint.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class base_uint
std::is_trivially_copyable<typename Container::value_type>::value>>
explicit base_uint(Container const& c)
{
XRPL_ASSERT(
XRPL_ASSERT("base_uint constructor from a container",
c.size() * sizeof(typename Container::value_type) == size());
std::memcpy(data_.data(), c.data(), size());
}
Expand All @@ -302,7 +302,7 @@ class base_uint
base_uint&>
operator=(Container const& c)
{
XRPL_ASSERT(
XRPL_ASSERT("base_uint assignment from a container",
c.size() * sizeof(typename Container::value_type) == size());
std::memcpy(data_.data(), c.data(), size());
return *this;
Expand Down
2 changes: 1 addition & 1 deletion include/xrpl/basics/partitioned_unordered_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class partitioned_unordered_map
? *partitions
: std::thread::hardware_concurrency();
map_.resize(partitions_);
XRPL_ASSERT(partitions_);
XRPL_ASSERT("partitioned_unordered_map constructor from an optional", partitions_);
}

std::size_t
Expand Down
2 changes: 1 addition & 1 deletion include/xrpl/basics/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ std::enable_if_t<
Integral>
rand_int(Engine& engine, Integral min, Integral max)
{
XRPL_ASSERT(max > min);
XRPL_ASSERT("rand_int", max > min);

// This should have no state and constructing it should
// be very cheap. If that turns out not to be the case
Expand Down
2 changes: 1 addition & 1 deletion include/xrpl/basics/spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class packed_spinlock
packed_spinlock(std::atomic<T>& lock, int index)
: bits_(lock), mask_(static_cast<T>(1) << index)
{
XRPL_ASSERT(index >= 0 && (mask_ != 0));
XRPL_ASSERT("packed_spinlock constructor", index >= 0 && (mask_ != 0));
}

[[nodiscard]] bool
Expand Down
4 changes: 2 additions & 2 deletions include/xrpl/beast/asio/io_latency_probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class io_latency_probe
, m_repeat(repeat)
, m_probe(probe)
{
XRPL_ASSERT(m_probe);
XRPL_ASSERT("beast::io_latency_probe::sample_op constructor", m_probe);
m_probe->addref();
}

Expand All @@ -184,7 +184,7 @@ class io_latency_probe
, m_repeat(from.m_repeat)
, m_probe(from.m_probe)
{
XRPL_ASSERT(m_probe);
XRPL_ASSERT("beast::io_latency_probe::sample_op move constructor",m_probe);
from.m_probe = nullptr;
}

Expand Down
4 changes: 2 additions & 2 deletions include/xrpl/beast/clock/manual_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class manual_clock : public abstract_clock<Clock>
void
set(time_point const& when)
{
XRPL_ASSERT(!Clock::is_steady || when >= now_);
XRPL_ASSERT("beast::manual_clock::set from time_point", !Clock::is_steady || when >= now_);
now_ = when;
}

Expand All @@ -78,7 +78,7 @@ class manual_clock : public abstract_clock<Clock>
void
advance(std::chrono::duration<Rep, Period> const& elapsed)
{
XRPL_ASSERT(!Clock::is_steady || (now_ + elapsed) >= now_);
XRPL_ASSERT("beast::manual_clock::advance duration",!Clock::is_steady || (now_ + elapsed) >= now_);
now_ += elapsed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ class aged_unordered_container
size_type
bucket(Key const& k) const
{
XRPL_ASSERT(bucket_count() != 0);
XRPL_ASSERT("beast::detail::aged_unordered_container::bucket", bucket_count() != 0);
return m_cont.bucket(k, std::cref(m_config.hash_function()));
}

Expand Down Expand Up @@ -1470,7 +1470,7 @@ class aged_unordered_container
{
if (would_exceed(additional))
m_buck.resize(size() + additional, m_cont);
XRPL_ASSERT(load_factor() <= max_load_factor());
XRPL_ASSERT("beast::detail::aged_unordered_container::maybe_rehash",load_factor() <= max_load_factor());
}

// map, set
Expand Down
4 changes: 2 additions & 2 deletions include/xrpl/beast/core/LexicalCast.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ struct LexicalCast<Out, char const*>
bool
operator()(Out& out, char const* in) const
{
XRPL_ASSERT(in);
XRPL_ASSERT("beast::detail::LexicalCast from char const*", in);
return LexicalCast<Out, std::string_view>()(out, in);
}
};
Expand All @@ -175,7 +175,7 @@ struct LexicalCast<Out, char*>
bool
operator()(Out& out, char* in) const
{
XRPL_ASSERT(in);
XRPL_ASSERT("beast::detail::LexicalCast from char*", in);
return LexicalCast<Out, std::string_view>()(out, in);
}
};
Expand Down
2 changes: 1 addition & 1 deletion include/xrpl/beast/net/IPAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ hash_append(Hasher& h, beast::IP::Address const& addr) noexcept
else if (addr.is_v6())
hash_append(h, addr.to_v6().to_bytes());
else
XRPL_UNREACHABLE();
XRPL_UNREACHABLE("beast::hash_append invalid address type");
}
} // namespace beast

Expand Down
2 changes: 1 addition & 1 deletion include/xrpl/beast/utility/Journal.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class Journal
*/
Stream(Sink& sink, Severity level) : m_sink(sink), m_level(level)
{
XRPL_ASSERT(m_level < severities::kDisabled);
XRPL_ASSERT("beast::Journal::Stream constructor", m_level < severities::kDisabled);
}

/** Construct or copy another Stream. */
Expand Down
6 changes: 3 additions & 3 deletions include/xrpl/beast/utility/instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#endif

#ifndef NDEBUG
#define XRPL_ASSERT(...) ALWAYS_OR_UNREACHABLE(((bool)(__VA_ARGS__)), "", {})
#define XRPL_UNREACHABLE() UNREACHABLE("", {})
#define XRPL_ASSERT(M, ...) ALWAYS_OR_UNREACHABLE(((bool)(__VA_ARGS__)), M, {})
#define XRPL_UNREACHABLE(M) UNREACHABLE(M, {})
#else
#define XRPL_ASSERT(...)
#define XRPL_UNREACHABLE()
#define XRPL_UNREACHABLE(M)
#endif

#endif
2 changes: 1 addition & 1 deletion include/xrpl/beast/utility/rngfill.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ rngfill(void* buffer, std::size_t bytes, Generator& g)
bytes -= sizeof(v);
}

XRPL_ASSERT(bytes < sizeof(result_type));
XRPL_ASSERT("beast::rngfill from void*", bytes < sizeof(result_type));

#ifdef __GNUC__
// gcc 11.1 (falsely) warns about an array-bounds overflow in release mode.
Expand Down
3 changes: 0 additions & 3 deletions include/xrpl/json/detail/json_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

#include <xrpl/json/json_errors.h>

#define JSON_ASSERT_UNREACHABLE XRPL_UNREACHABLE()
#define JSON_ASSERT(condition) \
XRPL_ASSERT(condition); // @todo <= change this into an exception throw
#define JSON_ASSERT_MESSAGE(condition, message) \
if (!(condition)) \
ripple::Throw<Json::error>(message);
Expand Down
10 changes: 5 additions & 5 deletions include/xrpl/protocol/AmountConversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ toSTAmount(XRPAmount const& xrp)
inline STAmount
toSTAmount(XRPAmount const& xrp, Issue const& iss)
{
XRPL_ASSERT(isXRP(iss.account) && isXRP(iss.currency));
XRPL_ASSERT("toSTAmount", isXRP(iss.account) && isXRP(iss.currency));
return toSTAmount(xrp);
}

Expand All @@ -78,25 +78,25 @@ template <>
inline IOUAmount
toAmount<IOUAmount>(STAmount const& amt)
{
XRPL_ASSERT(amt.mantissa() < std::numeric_limits<std::int64_t>::max());
XRPL_ASSERT("toAmount for IOUAmount mantissa", amt.mantissa() < std::numeric_limits<std::int64_t>::max());
bool const isNeg = amt.negative();
std::int64_t const sMant =
isNeg ? -std::int64_t(amt.mantissa()) : amt.mantissa();

XRPL_ASSERT(!isXRP(amt));
XRPL_ASSERT("toAmount for IOUAmount is not XRP", !isXRP(amt));
return IOUAmount(sMant, amt.exponent());
}

template <>
inline XRPAmount
toAmount<XRPAmount>(STAmount const& amt)
{
XRPL_ASSERT(amt.mantissa() < std::numeric_limits<std::int64_t>::max());
XRPL_ASSERT("toAmount for XRPAmount mantissa", amt.mantissa() < std::numeric_limits<std::int64_t>::max());
bool const isNeg = amt.negative();
std::int64_t const sMant =
isNeg ? -std::int64_t(amt.mantissa()) : amt.mantissa();

XRPL_ASSERT(isXRP(amt));
XRPL_ASSERT("toAmount for XRPAmount is XRP", isXRP(amt));
return XRPAmount(sMant);
}

Expand Down
6 changes: 3 additions & 3 deletions include/xrpl/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,22 @@ class FeatureBitset : private std::bitset<detail::numFeatures>

explicit FeatureBitset(base const& b) : base(b)
{
XRPL_ASSERT(b.count() == count());
XRPL_ASSERT("FeatureBitset constructor from base", b.count() == count());
}

template <class... Fs>
explicit FeatureBitset(uint256 const& f, Fs&&... fs)
{
initFromFeatures(f, std::forward<Fs>(fs)...);
XRPL_ASSERT(count() == (sizeof...(fs) + 1));
XRPL_ASSERT("FeatureBitset constructor from uint256", count() == (sizeof...(fs) + 1));
}

template <class Col>
explicit FeatureBitset(Col const& fs)
{
for (auto const& f : fs)
set(featureToBitsetIndex(f));
XRPL_ASSERT(fs.size() == count());
XRPL_ASSERT("FeatureBitset constructor from a container",fs.size() == count());
}

auto
Expand Down
2 changes: 1 addition & 1 deletion include/xrpl/protocol/Indexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ page(uint256 const& root, std::uint64_t index = 0) noexcept;
inline Keylet
page(Keylet const& root, std::uint64_t index = 0) noexcept
{
XRPL_ASSERT(root.type == ltDIR_NODE);
XRPL_ASSERT("keylet::page", root.type == ltDIR_NODE);
return page(root.key, index);
}
/** @} */
Expand Down
4 changes: 2 additions & 2 deletions include/xrpl/protocol/MultiApiJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ struct MultiApiJson
-> std::
invoke_result_t<Fn, decltype(json.val[0]), Version, Args&&...>
{
XRPL_ASSERT(
XRPL_ASSERT("detail::MultiApiJson functor with extra arguments version check",
valid(version) && index(version) >= 0 && index(version) < size);
return std::invoke(
fn,
Expand All @@ -175,7 +175,7 @@ struct MultiApiJson
operator()(Json& json, Version version, Fn fn) const
-> std::invoke_result_t<Fn, decltype(json.val[0])>
{
XRPL_ASSERT(
XRPL_ASSERT("detail::MultiApiJson functor Json only version check",
valid(version) && index(version) >= 0 && index(version) < size);
return std::invoke(fn, json.val[index(version)]);
}
Expand Down
2 changes: 1 addition & 1 deletion include/xrpl/protocol/Quality.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class Quality
friend double
relativeDistance(Quality const& q1, Quality const& q2)
{
XRPL_ASSERT(q1.m_value > 0 && q2.m_value > 0);
XRPL_ASSERT("Quality::relativeDistance positive qualities", q1.m_value > 0 && q2.m_value > 0);

if (q1.m_value == q2.m_value) // make expected common case fast
return 0;
Expand Down
4 changes: 2 additions & 2 deletions include/xrpl/protocol/STBitString.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ template <int Bits>
void
STBitString<Bits>::add(Serializer& s) const
{
XRPL_ASSERT(getFName().isBinary());
XRPL_ASSERT(getFName().fieldType == getSType());
XRPL_ASSERT("STBitString::add binary field", getFName().isBinary());
XRPL_ASSERT("STBitString::add field type check", getFName().fieldType == getSType());
s.addBitString<Bits>(value_);
}

Expand Down
4 changes: 2 additions & 2 deletions include/xrpl/protocol/STInteger.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ template <typename Integer>
inline void
STInteger<Integer>::add(Serializer& s) const
{
XRPL_ASSERT(getFName().isBinary());
XRPL_ASSERT(getFName().fieldType == getSType());
XRPL_ASSERT("STInteger::add binary field", getFName().isBinary());
XRPL_ASSERT("STInteger::add field type check", getFName().fieldType == getSType());
s.addInteger(value_);
}

Expand Down
Loading

0 comments on commit 6f634cd

Please sign in to comment.