ams: revamp assertion system
This commit is contained in:
@@ -66,7 +66,7 @@ namespace ams::kvdb {
|
||||
|
||||
Result Initialize(size_t size) {
|
||||
/* Check that we're not already initialized. */
|
||||
AMS_ASSERT(this->buffer == nullptr);
|
||||
AMS_ABORT_UNLESS(this->buffer == nullptr);
|
||||
|
||||
/* Allocate a buffer. */
|
||||
this->buffer = static_cast<u8 *>(std::malloc(size));
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace ams::kvdb {
|
||||
private:
|
||||
/* Utility. */
|
||||
static inline void CheckLength(size_t len) {
|
||||
AMS_ASSERT(len < N);
|
||||
AMS_ABORT_UNLESS(len < N);
|
||||
}
|
||||
public:
|
||||
/* Constructors. */
|
||||
@@ -109,8 +109,8 @@ namespace ams::kvdb {
|
||||
/* Substring utilities. */
|
||||
void GetSubstring(char *dst, size_t dst_size, size_t offset, size_t length) const {
|
||||
/* Make sure output buffer can hold the substring. */
|
||||
AMS_ASSERT(offset + length <= GetLength());
|
||||
AMS_ASSERT(dst_size > length);
|
||||
AMS_ABORT_UNLESS(offset + length <= GetLength());
|
||||
AMS_ABORT_UNLESS(dst_size > length);
|
||||
/* Copy substring to dst. */
|
||||
std::strncpy(dst, this->buffer + offset, length);
|
||||
dst[length] = 0;
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace ams::kvdb {
|
||||
}
|
||||
private:
|
||||
void RemoveIndex(size_t i) {
|
||||
AMS_ASSERT(i < this->GetCount());
|
||||
AMS_ABORT_UNLESS(i < this->GetCount());
|
||||
std::memmove(this->keys + i, this->keys + i + 1, sizeof(*this->keys) * (this->GetCount() - (i + 1)));
|
||||
this->DecrementCount();
|
||||
}
|
||||
@@ -71,8 +71,8 @@ namespace ams::kvdb {
|
||||
|
||||
Result Initialize(const char *path, void *buf, size_t size) {
|
||||
/* Only initialize once, and ensure we have sufficient memory. */
|
||||
AMS_ASSERT(this->keys == nullptr);
|
||||
AMS_ASSERT(size >= BufferSize);
|
||||
AMS_ABORT_UNLESS(this->keys == nullptr);
|
||||
AMS_ABORT_UNLESS(size >= BufferSize);
|
||||
|
||||
/* Setup member variables. */
|
||||
this->keys = static_cast<Key *>(buf);
|
||||
@@ -127,23 +127,23 @@ namespace ams::kvdb {
|
||||
}
|
||||
|
||||
Key Get(size_t i) const {
|
||||
AMS_ASSERT(i < this->GetCount());
|
||||
AMS_ABORT_UNLESS(i < this->GetCount());
|
||||
return this->keys[i];
|
||||
}
|
||||
|
||||
Key Peek() const {
|
||||
AMS_ASSERT(!this->IsEmpty());
|
||||
AMS_ABORT_UNLESS(!this->IsEmpty());
|
||||
return this->Get(0);
|
||||
}
|
||||
|
||||
void Push(const Key &key) {
|
||||
AMS_ASSERT(!this->IsFull());
|
||||
AMS_ABORT_UNLESS(!this->IsFull());
|
||||
this->keys[this->GetCount()] = key;
|
||||
this->IncrementCount();
|
||||
}
|
||||
|
||||
Key Pop() {
|
||||
AMS_ASSERT(!this->IsEmpty());
|
||||
AMS_ABORT_UNLESS(!this->IsEmpty());
|
||||
this->RemoveIndex(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace ams::kvdb {
|
||||
static_assert(std::is_pod<Value>::value && !std::is_pointer<Value>::value, "Invalid FileKeyValueStore Value!");
|
||||
size_t size = 0;
|
||||
R_TRY(this->Get(&size, out_value, sizeof(Value), key));
|
||||
AMS_ASSERT(size >= sizeof(Value));
|
||||
AMS_ABORT_UNLESS(size >= sizeof(Value));
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace ams::kvdb {
|
||||
Value *GetValuePointer() {
|
||||
/* Size check. Note: Nintendo does not size check. */
|
||||
if constexpr (!std::is_same<Value, void>::value) {
|
||||
AMS_ASSERT(sizeof(Value) <= this->value_size);
|
||||
AMS_ABORT_UNLESS(sizeof(Value) <= this->value_size);
|
||||
/* Ensure we only get pod. */
|
||||
static_assert(std::is_pod<Value>::value, "KeyValueStore Values must be pod");
|
||||
}
|
||||
@@ -56,7 +56,7 @@ namespace ams::kvdb {
|
||||
const Value *GetValuePointer() const {
|
||||
/* Size check. Note: Nintendo does not size check. */
|
||||
if constexpr (!std::is_same<Value, void>::value) {
|
||||
AMS_ASSERT(sizeof(Value) <= this->value_size);
|
||||
AMS_ABORT_UNLESS(sizeof(Value) <= this->value_size);
|
||||
/* Ensure we only get pod. */
|
||||
static_assert(std::is_pod<Value>::value, "KeyValueStore Values must be pod");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user