mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Use automatic allocation for assertion error messages
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
struct Assertion {
|
struct Assertion {
|
||||||
struct Patch patch; // Also used for its `.type`
|
struct Patch patch; // Also used for its `.type`
|
||||||
std::string *message;
|
std::string message;
|
||||||
// This would be redundant with `.section->fileSymbols`... but `section` is sometimes NULL!
|
// This would be redundant with `.section->fileSymbols`... but `section` is sometimes NULL!
|
||||||
std::vector<struct Symbol> *fileSymbols;
|
std::vector<struct Symbol> *fileSymbols;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -384,11 +384,14 @@ static void readAssertion(FILE *file, struct Assertion *assert, char const *file
|
|||||||
std::vector<struct FileStackNode> const &fileNodes)
|
std::vector<struct FileStackNode> const &fileNodes)
|
||||||
{
|
{
|
||||||
char assertName[sizeof("Assertion #4294967295")]; // UINT32_MAX
|
char assertName[sizeof("Assertion #4294967295")]; // UINT32_MAX
|
||||||
|
std::string *name;
|
||||||
|
|
||||||
snprintf(assertName, sizeof(assertName), "Assertion #%" PRIu32, i);
|
snprintf(assertName, sizeof(assertName), "Assertion #%" PRIu32, i);
|
||||||
|
|
||||||
readPatch(file, &assert->patch, fileName, assertName, 0, fileNodes);
|
readPatch(file, &assert->patch, fileName, assertName, 0, fileNodes);
|
||||||
tryReadstring(assert->message, file, "%s: Cannot read assertion's message: %s", fileName);
|
tryReadstring(name, file, "%s: Cannot read assertion's message: %s", fileName);
|
||||||
|
assert->message = *name;
|
||||||
|
delete name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct Section *getMainSection(struct Section *section)
|
static struct Section *getMainSection(struct Section *section)
|
||||||
@@ -587,7 +590,4 @@ void obj_Cleanup(void)
|
|||||||
|
|
||||||
sect_ForEach(freeSection);
|
sect_ForEach(freeSection);
|
||||||
sect_CleanupSections();
|
sect_CleanupSections();
|
||||||
|
|
||||||
for (struct Assertion &assert : assertions)
|
|
||||||
delete assert.message;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -422,24 +422,23 @@ void patch_CheckAssertions(std::deque<struct Assertion> &assertions)
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case ASSERT_FATAL:
|
case ASSERT_FATAL:
|
||||||
fatal(assert.patch.src, assert.patch.lineNo, "%s",
|
fatal(assert.patch.src, assert.patch.lineNo, "%s",
|
||||||
!assert.message->empty() ? assert.message->c_str()
|
!assert.message.empty() ? assert.message.c_str()
|
||||||
: "assert failure");
|
: "assert failure");
|
||||||
case ASSERT_ERROR:
|
case ASSERT_ERROR:
|
||||||
error(assert.patch.src, assert.patch.lineNo, "%s",
|
error(assert.patch.src, assert.patch.lineNo, "%s",
|
||||||
!assert.message->empty() ? assert.message->c_str()
|
!assert.message.empty() ? assert.message.c_str()
|
||||||
: "assert failure");
|
: "assert failure");
|
||||||
break;
|
break;
|
||||||
case ASSERT_WARN:
|
case ASSERT_WARN:
|
||||||
warning(assert.patch.src, assert.patch.lineNo, "%s",
|
warning(assert.patch.src, assert.patch.lineNo, "%s",
|
||||||
!assert.message->empty() ? assert.message->c_str()
|
!assert.message.empty() ? assert.message.c_str()
|
||||||
: "assert failure");
|
: "assert failure");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (isError && type == ASSERT_FATAL) {
|
} else if (isError && type == ASSERT_FATAL) {
|
||||||
fatal(assert.patch.src, assert.patch.lineNo,
|
fatal(assert.patch.src, assert.patch.lineNo,
|
||||||
"Failed to evaluate assertion%s%s",
|
"Failed to evaluate assertion%s%s",
|
||||||
!assert.message->empty() ? ": " : "",
|
!assert.message.empty() ? ": " : "", assert.message.c_str());
|
||||||
assert.message->c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user