Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_assert.h File Reference
#include <QtGlobal>
#include <kritaglobal_export.h>

Go to the source code of this file.

Macros

#define KIS_ASSERT(cond)   ((!(cond)) ? kis_assert_exception(#cond,__FILE__,__LINE__) : qt_noop())
 
#define KIS_ASSERT_RECOVER(cond)   if (!(cond) && (kis_assert_recoverable(#cond,__FILE__,__LINE__), true))
 
#define KIS_ASSERT_RECOVER_BREAK(cond)   KIS_ASSERT_RECOVER(cond) { break; }
 
#define KIS_ASSERT_RECOVER_NOOP(cond)   do { KIS_ASSERT_RECOVER(cond) { qt_noop(); } } while (0)
 
#define KIS_ASSERT_RECOVER_RETURN(cond)   do { KIS_ASSERT_RECOVER(cond) { return; } } while (0)
 
#define KIS_ASSERT_RECOVER_RETURN_VALUE(cond, val)   do { KIS_ASSERT_RECOVER(cond) { return (val); } } while (0)
 
#define KIS_ASSERT_X(cond, where, what)   ((!(cond)) ? kis_assert_x_exception(#cond,where, what,__FILE__,__LINE__) : qt_noop())
 
#define KIS_SAFE_ASSERT_RECOVER(cond)   if (!(cond) && (kis_safe_assert_recoverable(#cond,__FILE__,__LINE__), true))
 
#define KIS_SAFE_ASSERT_RECOVER_BREAK(cond)   KIS_SAFE_ASSERT_RECOVER(cond) { break; }
 
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)   do { KIS_SAFE_ASSERT_RECOVER(cond) { qt_noop(); } } while (0)
 
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)   do { KIS_SAFE_ASSERT_RECOVER(cond) { return; } } while (0)
 
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)   do { KIS_SAFE_ASSERT_RECOVER(cond) { return (val); } } while (0)
 

Functions

KRITAGLOBAL_EXPORT void kis_assert_exception (const char *assertion, const char *file, int line)
 
KRITAGLOBAL_EXPORT void kis_assert_recoverable (const char *assertion, const char *file, int line)
 
KRITAGLOBAL_EXPORT void kis_assert_x_exception (const char *assertion, const char *where, const char *what, const char *file, int line)
 
KRITAGLOBAL_EXPORT void kis_safe_assert_recoverable (const char *assertion, const char *file, int line)
 

Macro Definition Documentation

◆ KIS_ASSERT

#define KIS_ASSERT ( cond)    ((!(cond)) ? kis_assert_exception(#cond,__FILE__,__LINE__) : qt_noop())

KIS_ASSERT family of macros allows the user to choose whether to try to continue working in Krita or to abort an application and see a backtrace.

Note, the macro are present in Release mode by default! Checks the condition and depending on the user action either aborts the program or throws an exception, which restarts event loop.

Definition at line 33 of file kis_assert.h.

◆ KIS_ASSERT_RECOVER

#define KIS_ASSERT_RECOVER ( cond)    if (!(cond) && (kis_assert_recoverable(#cond,__FILE__,__LINE__), true))

This is a recoverable variant of KIS_ASSERT. It doesn't throw any exceptions. It checks the condition, and either aborts the application, or executes user-supplied code. The typical usecase is the following:

int fooBar = ...; KIS_ASSERT_RECOVER (fooBar > 0) { // the code which is executed in a case of emergency }

Definition at line 55 of file kis_assert.h.

◆ KIS_ASSERT_RECOVER_BREAK

#define KIS_ASSERT_RECOVER_BREAK ( cond)    KIS_ASSERT_RECOVER(cond) { break; }

Equivalent of the following:

KIS_ASSERT_RECOVER(cond) { break; }

Definition at line 65 of file kis_assert.h.

◆ KIS_ASSERT_RECOVER_NOOP

#define KIS_ASSERT_RECOVER_NOOP ( cond)    do { KIS_ASSERT_RECOVER(cond) { qt_noop(); } } while (0)

Does nothing in case of a failure. Just continues execution.

Equivalent of the following:

KIS_ASSERT_RECOVER(cond) { qt_noop(); }

Definition at line 97 of file kis_assert.h.

◆ KIS_ASSERT_RECOVER_RETURN

#define KIS_ASSERT_RECOVER_RETURN ( cond)    do { KIS_ASSERT_RECOVER(cond) { return; } } while (0)

Equivalent of the following:

KIS_ASSERT_RECOVER(cond) { return; }

Definition at line 75 of file kis_assert.h.

◆ KIS_ASSERT_RECOVER_RETURN_VALUE

#define KIS_ASSERT_RECOVER_RETURN_VALUE ( cond,
val )   do { KIS_ASSERT_RECOVER(cond) { return (val); } } while (0)

Equivalent of the following:

KIS_ASSERT_RECOVER(cond) { return val; }

Definition at line 85 of file kis_assert.h.

◆ KIS_ASSERT_X

#define KIS_ASSERT_X ( cond,
where,
what )   ((!(cond)) ? kis_assert_x_exception(#cond,where, what,__FILE__,__LINE__) : qt_noop())

Same as KIS_ASSERT, but allows to show more text to the user.

See also
KIS_ASSERT

Definition at line 40 of file kis_assert.h.

◆ KIS_SAFE_ASSERT_RECOVER

#define KIS_SAFE_ASSERT_RECOVER ( cond)    if (!(cond) && (kis_safe_assert_recoverable(#cond,__FILE__,__LINE__), true))

This set of macros work in exactly the same way as their non-safe counterparts, but they are automatically converted into console warnings in release builds. That is the user will not see any message box, just a warning message will be printed in a terminal and a recovery branch will be taken automatically.

Rules when to use "safe" asserts. Use them if the following conditions are met:

1) The condition in the assert shows that a real bug has happened. It is not just a warning. It is a bug that should be fixed.

2) The recovery branch will workaround the bug and the user will be able to continue his work as if nothing has happened. Again, please mark the assert "safe" if and only if you are 100% sure Krita will not crash in a minute after you faced that bug. The user is not notified about this bug, so he is not going to take any emergency steps like saving his work and restarting Krita!

3) If you think that Krita should be better restarted after this bug, please use a usual KIS_ASSERT_RECOVER.

Definition at line 126 of file kis_assert.h.

◆ KIS_SAFE_ASSERT_RECOVER_BREAK

#define KIS_SAFE_ASSERT_RECOVER_BREAK ( cond)    KIS_SAFE_ASSERT_RECOVER(cond) { break; }

Definition at line 127 of file kis_assert.h.

◆ KIS_SAFE_ASSERT_RECOVER_NOOP

#define KIS_SAFE_ASSERT_RECOVER_NOOP ( cond)    do { KIS_SAFE_ASSERT_RECOVER(cond) { qt_noop(); } } while (0)

Definition at line 130 of file kis_assert.h.

◆ KIS_SAFE_ASSERT_RECOVER_RETURN

#define KIS_SAFE_ASSERT_RECOVER_RETURN ( cond)    do { KIS_SAFE_ASSERT_RECOVER(cond) { return; } } while (0)

Definition at line 128 of file kis_assert.h.

◆ KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE

#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE ( cond,
val )   do { KIS_SAFE_ASSERT_RECOVER(cond) { return (val); } } while (0)

Definition at line 129 of file kis_assert.h.

Function Documentation

◆ kis_assert_exception()

KRITAGLOBAL_EXPORT void kis_assert_exception ( const char * assertion,
const char * file,
int line )

Definition at line 108 of file kis_assert.cpp.

109{
110 kis_assert_common(assertion, file, line, true, false);
111}
void kis_assert_common(const char *assertion, const char *file, int line, bool abort, bool isIgnorable)

References kis_assert_common().

◆ kis_assert_recoverable()

KRITAGLOBAL_EXPORT void kis_assert_recoverable ( const char * assertion,
const char * file,
int line )

Definition at line 98 of file kis_assert.cpp.

99{
100 kis_assert_common(assertion, file, line, false, false);
101}

References kis_assert_common().

◆ kis_assert_x_exception()

KRITAGLOBAL_EXPORT void kis_assert_x_exception ( const char * assertion,
const char * where,
const char * what,
const char * file,
int line )

Definition at line 113 of file kis_assert.cpp.

117{
118 QString res =
119 QString("ASSERT failure in %1: \"%2\" (%3)")
120 .arg(where, what, assertion);
121
122 kis_assert_common(res.toLatin1().data(), file, line, true, false);
123}

References kis_assert_common().

◆ kis_safe_assert_recoverable()

KRITAGLOBAL_EXPORT void kis_safe_assert_recoverable ( const char * assertion,
const char * file,
int line )

Definition at line 103 of file kis_assert.cpp.

104{
105 kis_assert_common(assertion, file, line, false, true);
106}

References kis_assert_common().