mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:47:34 +00:00
LibC: Simplify ASSERT() to reduce code size
Instead of pushing the message, file name, line# and function name separately, we now mash the message, file name and line# into a string constant and pass that. This means that the failure path only has to push a single address onto the stack, reducing the code size and causing the compiler to inline many more functions containing an assertions (e.g RefPtr::operator*()) Obviously if you wanted minimal size, you could turn assertions off entirely, but I really like running with assertions, so let's make a little effort to reduce their impact. :^)
This commit is contained in:
parent
8ebee4bce6
commit
038fdc2017
2 changed files with 7 additions and 5 deletions
|
@ -32,10 +32,10 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func)
|
void __assertion_failed(const char* msg)
|
||||||
{
|
{
|
||||||
dbgprintf("USERSPACE(%d) ASSERTION FAILED: %s\n%s:%u in %s\n", getpid(), msg, file, line, func);
|
dbgprintf("USERSPACE(%d) ASSERTION FAILED: %s\n", getpid(), msg);
|
||||||
fprintf(stderr, "ASSERTION FAILED: %s\n%s:%u in %s\n", msg, file, line, func);
|
fprintf(stderr, "ASSERTION FAILED: %s\n", msg);
|
||||||
abort();
|
abort();
|
||||||
for (;;)
|
for (;;)
|
||||||
;
|
;
|
||||||
|
|
|
@ -31,8 +31,10 @@
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
__attribute__((noreturn)) void __assertion_failed(const char* msg, const char* file, unsigned line, const char* func);
|
__attribute__((noreturn)) void __assertion_failed(const char* msg);
|
||||||
# define assert(expr) ((expr) ? (void)0 : __assertion_failed(# expr, __FILE__, __LINE__, __PRETTY_FUNCTION__))
|
# define __stringify_helper(x) # x
|
||||||
|
# define __stringify(x) __stringify_helper(x)
|
||||||
|
# define assert(expr) ((expr) ? (void)0 : __assertion_failed(# expr "\n" __FILE__ ":" __stringify(__LINE__)));
|
||||||
# define ASSERT_NOT_REACHED() assert(false)
|
# define ASSERT_NOT_REACHED() assert(false)
|
||||||
#else
|
#else
|
||||||
# define assert(expr)
|
# define assert(expr)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue