Skip to content

Commit

Permalink
Everywhere: Rename ASSERT => VERIFY
Browse files Browse the repository at this point in the history
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
  • Loading branch information
awesomekling committed Feb 23, 2021
1 parent b33a6a4 commit 5d180d1
Show file tree
Hide file tree
Showing 725 changed files with 3,448 additions and 3,448 deletions.
4 changes: 2 additions & 2 deletions AK/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ struct Array {

constexpr const T& at(size_t index) const
{
ASSERT(index < size());
VERIFY(index < size());
return (*this)[index];
}
constexpr T& at(size_t index)
{
ASSERT(index < size());
VERIFY(index < size());
return (*this)[index];
}

Expand Down
6 changes: 3 additions & 3 deletions AK/Assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
#else
# include <assert.h>
# ifndef __serenity__
# define ASSERT assert
# define ASSERT_NOT_REACHED() assert(false)
# define VERIFY assert
# define VERIFY_NOT_REACHED() assert(false)
# define RELEASE_ASSERT assert
# define TODO ASSERT_NOT_REACHED
# define TODO VERIFY_NOT_REACHED
# endif
#endif
30 changes: 15 additions & 15 deletions AK/Bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ class Bitmap {
size_t size_in_bytes() const { return ceil_div(m_size, static_cast<size_t>(8)); }
bool get(size_t index) const
{
ASSERT(index < m_size);
VERIFY(index < m_size);
return 0 != (m_data[index / 8] & (1u << (index % 8)));
}
void set(size_t index, bool value) const
{
ASSERT(index < m_size);
VERIFY(index < m_size);
if (value)
m_data[index / 8] |= static_cast<u8>((1u << (index % 8)));
else
Expand All @@ -104,8 +104,8 @@ class Bitmap {

size_t count_in_range(size_t start, size_t len, bool value) const
{
ASSERT(start < m_size);
ASSERT(start + len <= m_size);
VERIFY(start < m_size);
VERIFY(start + len <= m_size);
if (len == 0)
return 0;

Expand Down Expand Up @@ -153,8 +153,8 @@ class Bitmap {

void grow(size_t size, bool default_value)
{
ASSERT(m_owned);
ASSERT(size > m_size);
VERIFY(m_owned);
VERIFY(size > m_size);

auto previous_size_bytes = size_in_bytes();
auto previous_size = m_size;
Expand All @@ -176,8 +176,8 @@ class Bitmap {
template<bool VALUE>
void set_range(size_t start, size_t len)
{
ASSERT(start < m_size);
ASSERT(start + len <= m_size);
VERIFY(start < m_size);
VERIFY(start + len <= m_size);
if (len == 0)
return;

Expand Down Expand Up @@ -228,7 +228,7 @@ class Bitmap {
template<bool VALUE>
Optional<size_t> find_one_anywhere(size_t hint = 0) const
{
ASSERT(hint < m_size);
VERIFY(hint < m_size);
const u8* end = &m_data[m_size / 8];

for (;;) {
Expand All @@ -249,7 +249,7 @@ class Bitmap {
byte = m_data[i];
if constexpr (!VALUE)
byte = ~byte;
ASSERT(byte != 0);
VERIFY(byte != 0);
return i * 8 + __builtin_ffs(byte) - 1;
}
}
Expand All @@ -264,7 +264,7 @@ class Bitmap {
u8 byte = VALUE ? 0x00 : 0xff;
size_t i = (const u8*)ptr32 - &m_data[0];
size_t byte_count = m_size / 8;
ASSERT(i <= byte_count);
VERIFY(i <= byte_count);
while (i < byte_count && m_data[i] == byte)
i++;
if (i == byte_count) {
Expand All @@ -279,7 +279,7 @@ class Bitmap {
byte = m_data[i];
if constexpr (!VALUE)
byte = ~byte;
ASSERT(byte != 0);
VERIFY(byte != 0);
return i * 8 + __builtin_ffs(byte) - 1;
}

Expand All @@ -288,7 +288,7 @@ class Bitmap {
val32 = *ptr32;
if constexpr (!VALUE)
val32 = ~val32;
ASSERT(val32 != 0);
VERIFY(val32 != 0);
return ((const u8*)ptr32 - &m_data[0]) * 8 + __builtin_ffsl(val32) - 1;
}
}
Expand Down Expand Up @@ -317,7 +317,7 @@ class Bitmap {
byte = m_data[i];
if constexpr (!VALUE)
byte = ~byte;
ASSERT(byte != 0);
VERIFY(byte != 0);
return i * 8 + __builtin_ffs(byte) - 1;
}

Expand Down Expand Up @@ -509,7 +509,7 @@ class Bitmap {
: m_size(size)
, m_owned(true)
{
ASSERT(m_size != 0);
VERIFY(m_size != 0);
m_data = reinterpret_cast<u8*>(kmalloc(size_in_bytes()));
fill(default_value);
}
Expand Down
18 changes: 9 additions & 9 deletions AK/ByteBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ class ByteBufferImpl : public RefCounted<ByteBufferImpl> {

u8& operator[](size_t i)
{
ASSERT(i < m_size);
VERIFY(i < m_size);
return m_data[i];
}
const u8& operator[](size_t i) const
{
ASSERT(i < m_size);
VERIFY(i < m_size);
return m_data[i];
}
bool is_empty() const { return !m_size; }
Expand All @@ -83,7 +83,7 @@ class ByteBufferImpl : public RefCounted<ByteBufferImpl> {
// NOTE: trim() does not reallocate.
void trim(size_t size)
{
ASSERT(size <= m_size);
VERIFY(size <= m_size);
m_size = size;
}

Expand Down Expand Up @@ -145,12 +145,12 @@ class ByteBuffer {

u8& operator[](size_t i)
{
ASSERT(m_impl);
VERIFY(m_impl);
return (*m_impl)[i];
}
u8 operator[](size_t i) const
{
ASSERT(m_impl);
VERIFY(m_impl);
return (*m_impl)[i];
}
bool is_empty() const { return !m_impl || m_impl->is_empty(); }
Expand Down Expand Up @@ -215,7 +215,7 @@ class ByteBuffer {
return {};

// I cannot hand you a slice I don't have
ASSERT(offset + size <= this->size());
VERIFY(offset + size <= this->size());

return copy(offset_pointer(offset), size);
}
Expand All @@ -232,7 +232,7 @@ class ByteBuffer {
{
if (data_size == 0)
return;
ASSERT(data != nullptr);
VERIFY(data != nullptr);
int old_size = size();
grow(size() + data_size);
__builtin_memcpy(this->data() + old_size, data, data_size);
Expand All @@ -246,7 +246,7 @@ class ByteBuffer {
void overwrite(size_t offset, const void* data, size_t data_size)
{
// make sure we're not told to write past the end
ASSERT(offset + data_size <= size());
VERIFY(offset + data_size <= size());
__builtin_memcpy(this->data() + offset, data, data_size);
}

Expand Down Expand Up @@ -285,7 +285,7 @@ inline ByteBufferImpl::ByteBufferImpl(const void* data, size_t size)

inline void ByteBufferImpl::grow(size_t size)
{
ASSERT(size > m_size);
VERIFY(size > m_size);
if (size == 0) {
if (m_data)
kfree(m_data);
Expand Down
4 changes: 2 additions & 2 deletions AK/Checked.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ class Checked {

ALWAYS_INLINE constexpr bool operator!() const
{
ASSERT(!m_overflow);
VERIFY(!m_overflow);
return !m_value;
}

ALWAYS_INLINE constexpr T value() const
{
ASSERT(!m_overflow);
VERIFY(!m_overflow);
return m_value;
}

Expand Down
2 changes: 1 addition & 1 deletion AK/CheckedFormatString.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#ifndef DBGLN_NO_COMPILETIME_FORMAT_CHECK
namespace AK::Format::Detail {

// We have to define a local "purely constexpr" Array that doesn't lead back to us (via e.g. ASSERT)
// We have to define a local "purely constexpr" Array that doesn't lead back to us (via e.g. VERIFY)
template<typename T, size_t Size>
struct Array {
constexpr static size_t size() { return Size; }
Expand Down
2 changes: 1 addition & 1 deletion AK/CircularDeque.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CircularDeque : public CircularQueue<T, Capacity> {

T dequeue_end()
{
ASSERT(!this->is_empty());
VERIFY(!this->is_empty());
auto& slot = this->elements()[(this->m_head + this->m_size - 1) % Capacity];
T value = move(slot);
slot.~T();
Expand Down
4 changes: 2 additions & 2 deletions AK/CircularDuplexStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CircularDuplexStream : public AK::DuplexStream {
}

const auto nwritten = write(bytes);
ASSERT(nwritten == bytes.size());
VERIFY(nwritten == bytes.size());
return true;
}

Expand Down Expand Up @@ -123,7 +123,7 @@ class CircularDuplexStream : public AK::DuplexStream {

Bytes reserve_contigous_space(size_t count)
{
ASSERT(count <= remaining_contigous_space());
VERIFY(count <= remaining_contigous_space());

Bytes bytes { m_queue.m_storage + (m_queue.head_index() + m_queue.size()) % Capacity, count };

Expand Down
2 changes: 1 addition & 1 deletion AK/CircularQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CircularQueue {

T dequeue()
{
ASSERT(!is_empty());
VERIFY(!is_empty());
auto& slot = elements()[m_head];
T value = move(slot);
slot.~T();
Expand Down
30 changes: 15 additions & 15 deletions AK/DoublyLinkedList.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,22 @@ class DoublyLinkedList {

T& first()
{
ASSERT(m_head);
VERIFY(m_head);
return m_head->value;
}
const T& first() const
{
ASSERT(m_head);
VERIFY(m_head);
return m_head->value;
}
T& last()
{
ASSERT(m_head);
VERIFY(m_head);
return m_tail->value;
}
const T& last() const
{
ASSERT(m_head);
VERIFY(m_head);
return m_tail->value;
}

Expand All @@ -117,13 +117,13 @@ class DoublyLinkedList {
requires { T(value); }, "Conversion operator is missing.");
auto* node = new Node(forward<U>(value));
if (!m_head) {
ASSERT(!m_tail);
VERIFY(!m_tail);
m_head = node;
m_tail = node;
return;
}
ASSERT(m_tail);
ASSERT(!node->next);
VERIFY(m_tail);
VERIFY(!node->next);
m_tail->next = node;
node->prev = m_tail;
m_tail = node;
Expand All @@ -135,13 +135,13 @@ class DoublyLinkedList {
static_assert(IsSame<T, U>::value);
auto* node = new Node(forward<U>(value));
if (!m_head) {
ASSERT(!m_tail);
VERIFY(!m_tail);
m_head = node;
m_tail = node;
return;
}
ASSERT(m_tail);
ASSERT(!node->prev);
VERIFY(m_tail);
VERIFY(!node->prev);
m_head->prev = node;
node->next = m_head;
m_head = node;
Expand Down Expand Up @@ -174,20 +174,20 @@ class DoublyLinkedList {

void remove(Iterator it)
{
ASSERT(it.m_node);
VERIFY(it.m_node);
auto* node = it.m_node;
if (node->prev) {
ASSERT(node != m_head);
VERIFY(node != m_head);
node->prev->next = node->next;
} else {
ASSERT(node == m_head);
VERIFY(node == m_head);
m_head = node->next;
}
if (node->next) {
ASSERT(node != m_tail);
VERIFY(node != m_tail);
node->next->prev = node->prev;
} else {
ASSERT(node == m_tail);
VERIFY(node == m_tail);
m_tail = node->prev;
}
delete node;
Expand Down
6 changes: 3 additions & 3 deletions AK/FlyString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ struct FlyStringImplTraits : public AK::Traits<StringImpl*> {
static unsigned hash(const StringImpl* s) { return s ? s->hash() : 0; }
static bool equals(const StringImpl* a, const StringImpl* b)
{
ASSERT(a);
ASSERT(b);
VERIFY(a);
VERIFY(b);
return *a == *b;
}
};
Expand Down Expand Up @@ -70,7 +70,7 @@ FlyString::FlyString(const String& string)
string.impl()->set_fly({}, true);
m_impl = string.impl();
} else {
ASSERT((*it)->is_fly());
VERIFY((*it)->is_fly());
m_impl = *it;
}
}
Expand Down
Loading

0 comments on commit 5d180d1

Please sign in to comment.