VirtualBox

Changeset 55945 in vbox for trunk


Ignore:
Timestamp:
May 19, 2015 11:20:24 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
100444
Message:

VirtualBoxBase.h: Made the ComAssertXXX macros always setError and let assert.h decided when the AssertXXX macros are no-ops and not. The macros used to not call setError in debug builds, just do AssertXXX, leading to different error reporting for no reason.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/VirtualBoxBase.h

    r55944 r55945  
    156156 *  @param   expr    Expression which should be true.
    157157 */
    158 #if defined(DEBUG)
    159 # define ComAssert(expr)    Assert(expr)
    160 #else
    161 # define ComAssert(expr) \
     158#define ComAssert(expr) \
    162159    do { \
    163160        if (RT_LIKELY(!!(expr))) \
    164161        { /* likely */ } \
    165162        else \
     163        { \
     164            AssertMsgFailed(("%s\n", #expr)); \
    166165            setError(E_FAIL, \
    167166                     "Assertion failed: [%s] at '%s' (%d) in %s.\nPlease contact the product vendor!", \
    168167                     #expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
    169     } while (0)
    170 #endif
     168        } \
     169    } while (0)
    171170
    172171/**
     
    181180 *
    182181 */
    183 #if defined(DEBUG)
    184 # define ComAssertFailed()  AssertFailed()
    185 #else
    186 # define ComAssertFailed() \
    187     do { \
     182#define ComAssertFailed() \
     183    do { \
     184        AssertFailed(); \
    188185        setError(E_FAIL, \
    189186                 "Assertion failed: at '%s' (%d) in %s.\nPlease contact the product vendor!", \
    190187                 __FILE__, __LINE__, __PRETTY_FUNCTION__); \
    191188    } while (0)
    192 #endif
    193189
    194190/**
     
    201197 *  @param   a       printf argument list (in parenthesis).
    202198 */
    203 #if defined(DEBUG)
    204 # define ComAssertMsg(expr, a) AssertMsg(expr, a)
    205 #else
    206 # define ComAssertMsg(expr, a) \
     199#define ComAssertMsg(expr, a) \
    207200    do { \
    208201        if (RT_LIKELY(!!(expr))) \
    209202        { /* likely */ } \
    210203        else \
     204        { \
     205            Utf8StrFmt MyAssertMsg a; /* may throw bad_alloc */ \
     206            AssertMsgFailed(("%s\n", MyAssertMsg.c_str())); \
    211207            setError(E_FAIL, \
    212208                     "Assertion failed: [%s] at '%s' (%d) in %s.\n%s.\nPlease contact the product vendor!", \
    213                      #expr, __FILE__, __LINE__, __PRETTY_FUNCTION__, Utf8StrFmt a .c_str()); \
    214     } while (0)
    215 #endif
     209                     #expr, __FILE__, __LINE__, __PRETTY_FUNCTION__, MyAssertMsg.c_str()); \
     210        } \
     211    } while (0)
    216212
    217213/**
     
    223219 *  @param   a       printf argument list (in parenthesis).
    224220 */
    225 #if defined(DEBUG)
    226 # define ComAssertMsgFailed(a)  AssertMsgFailed(a)
    227 #else
    228 # define ComAssertMsgFailed(a) \
    229     do { \
     221#define ComAssertMsgFailed(a) \
     222    do { \
     223        Utf8StrFmt MyAssertMsg a; /* may throw bad_alloc */ \
     224        AssertMsgFailed(("%s\n", MyAssertMsg.c_str())); \
    230225        setError(E_FAIL, \
    231226                 "Assertion failed: at '%s' (%d) in %s.\n%s.\nPlease contact the product vendor!", \
    232                  __FILE__, __LINE__, __PRETTY_FUNCTION__, Utf8StrFmt a .c_str()); \
    233     } while (0)
    234 #endif
     227                 __FILE__, __LINE__, __PRETTY_FUNCTION__, MyAssertMsg.c_str()); \
     228    } while (0)
    235229
    236230/**
     
    242236 * @param   vrc     VBox status code.
    243237 */
    244 #if defined(DEBUG)
    245 # define ComAssertRC(vrc)   AssertRC(vrc)
    246 #else
    247 # define ComAssertRC(vrc)   ComAssertMsgRC(vrc, ("%Rra", vrc))
    248 #endif
     238#define ComAssertRC(vrc)            ComAssertMsgRC(vrc, ("%Rra", vrc))
    249239
    250240/**
     
    257247 *  @param   msg    printf argument list (in parenthesis).
    258248 */
    259 #if defined(DEBUG)
    260 # define ComAssertMsgRC(vrc, msg)   AssertMsgRC(vrc, msg)
    261 #else
    262 # define ComAssertMsgRC(vrc, msg)   ComAssertMsg(RT_SUCCESS(vrc), msg)
    263 #endif
     249#define ComAssertMsgRC(vrc, msg)    ComAssertMsg(RT_SUCCESS(vrc), msg)
    264250
    265251/**
     
    269255 *  See ComAssert for more info.
    270256 *
    271  *  @param rc   COM result code
    272  */
    273 #if defined(DEBUG)
    274 # define ComAssertComRC(rc) AssertComRC(rc)
    275 #else
    276 # define ComAssertComRC(rc) ComAssertMsg(SUCCEEDED(rc), ("COM RC = %Rhrc (0x%08X)", (rc), (rc)))
    277 #endif
     257 *  @param hrc  COM result code
     258 */
     259#define ComAssertComRC(hrc)         ComAssertMsg(SUCCEEDED(hrc), ("COM RC=%Rhrc (0x%08X)", (hrc), (hrc)))
    278260
    279261
     
    565547        RTAssertDebugBreak(); \
    566548        throw (a); \
    567 } while (0)
     549    } while (0)
    568550#else
    569551# define DebugBreakThrow(a) throw (a)
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette