src/SDL_assert.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 31 Dec 2011 09:28:07 -0500
changeset 6138 4c64952a58fb
parent 6051 cb1f941ce38e
child 6217 6952b11b7f46
permissions -rwxr-xr-x
Happy New Year!
slouken@3647
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6138
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
slouken@3647
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@3647
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@3647
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@3647
    20
*/
slouken@3647
    21
slouken@3651
    22
#include "SDL.h"
slouken@5006
    23
#include "SDL_atomic.h"
slouken@3647
    24
#include "SDL_assert.h"
slouken@4472
    25
#include "SDL_assert_c.h"
slouken@3671
    26
#include "video/SDL_sysvideo.h"
slouken@3647
    27
slouken@5086
    28
#ifdef __WIN32__
slouken@5090
    29
#include "core/windows/SDL_windows.h"
slouken@5086
    30
slouken@5086
    31
#ifndef WS_OVERLAPPEDWINDOW
slouken@5086
    32
#define WS_OVERLAPPEDWINDOW 0
slouken@5086
    33
#endif
slouken@3647
    34
#else  /* fprintf, _exit(), etc. */
slouken@3647
    35
#include <stdio.h>
slouken@3647
    36
#include <stdlib.h>
icculus@3648
    37
#include <unistd.h>
slouken@3647
    38
#endif
slouken@3647
    39
icculus@3670
    40
static SDL_assert_state
icculus@3670
    41
SDL_PromptAssertion(const SDL_assert_data *data, void *userdata);
icculus@3670
    42
icculus@3670
    43
/*
icculus@3670
    44
 * We keep all triggered assertions in a singly-linked list so we can
slouken@3647
    45
 *  generate a report later.
slouken@3647
    46
 */
icculus@5541
    47
static SDL_assert_data *triggered_assertions = NULL;
icculus@3670
    48
icculus@3670
    49
static SDL_mutex *assertion_mutex = NULL;
icculus@3670
    50
static SDL_AssertionHandler assertion_handler = SDL_PromptAssertion;
icculus@3670
    51
static void *assertion_userdata = NULL;
slouken@3647
    52
icculus@3648
    53
#ifdef __GNUC__
icculus@3661
    54
static void
icculus@3661
    55
debug_print(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
icculus@3648
    56
#endif
icculus@3648
    57
icculus@3648
    58
static void
icculus@3648
    59
debug_print(const char *fmt, ...)
slouken@3647
    60
{
slouken@5086
    61
#ifdef __WIN32__
slouken@3647
    62
    /* Format into a buffer for OutputDebugStringA(). */
slouken@3647
    63
    char buf[1024];
slouken@3647
    64
    char *startptr;
slouken@3647
    65
    char *ptr;
slouken@5086
    66
    LPTSTR tstr;
slouken@3647
    67
    int len;
slouken@3647
    68
    va_list ap;
slouken@3647
    69
    va_start(ap, fmt);
slouken@3647
    70
    len = (int) SDL_vsnprintf(buf, sizeof (buf), fmt, ap);
slouken@3647
    71
    va_end(ap);
slouken@3647
    72
slouken@3647
    73
    /* Visual C's vsnprintf() may not null-terminate the buffer. */
slouken@3647
    74
    if ((len >= sizeof (buf)) || (len < 0)) {
slouken@3647
    75
        buf[sizeof (buf) - 1] = '\0';
slouken@3647
    76
    }
slouken@3647
    77
slouken@3647
    78
    /* Write it, sorting out the Unix newlines... */
slouken@3647
    79
    startptr = buf;
slouken@3647
    80
    for (ptr = startptr; *ptr; ptr++) {
slouken@3647
    81
        if (*ptr == '\n') {
slouken@3647
    82
            *ptr = '\0';
slouken@5086
    83
            tstr = WIN_UTF8ToString(startptr);
slouken@5086
    84
            OutputDebugString(tstr);
slouken@5086
    85
            SDL_free(tstr);
slouken@5086
    86
            OutputDebugString(TEXT("\r\n"));
slouken@3647
    87
            startptr = ptr+1;
slouken@3647
    88
        }
slouken@3647
    89
    }
slouken@3647
    90
slouken@3647
    91
    /* catch that last piece if it didn't have a newline... */
slouken@3647
    92
    if (startptr != ptr) {
slouken@5086
    93
        tstr = WIN_UTF8ToString(startptr);
slouken@5086
    94
        OutputDebugString(tstr);
slouken@5086
    95
        SDL_free(tstr);
slouken@3647
    96
    }
slouken@3647
    97
#else
slouken@3647
    98
    /* Unix has it easy. Just dump it to stderr. */
slouken@3647
    99
    va_list ap;
slouken@3647
   100
    va_start(ap, fmt);
icculus@3669
   101
    vfprintf(stderr, fmt, ap);
slouken@3647
   102
    va_end(ap);
slouken@3647
   103
    fflush(stderr);
slouken@3647
   104
#endif
slouken@3647
   105
}
slouken@3647
   106
slouken@3647
   107
slouken@5086
   108
#ifdef __WIN32__
slouken@3647
   109
static SDL_assert_state SDL_Windows_AssertChoice = SDL_ASSERTION_ABORT;
slouken@3647
   110
static const SDL_assert_data *SDL_Windows_AssertData = NULL;
slouken@3647
   111
slouken@3647
   112
static LRESULT CALLBACK
slouken@3647
   113
SDL_Assertion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
slouken@3647
   114
{
slouken@3647
   115
    switch (msg)
slouken@3647
   116
    {
slouken@3647
   117
        case WM_CREATE:
slouken@3647
   118
        {
slouken@3647
   119
            /* !!! FIXME: all this code stinks. */
slouken@3647
   120
            const SDL_assert_data *data = SDL_Windows_AssertData;
slouken@3647
   121
            char buf[1024];
slouken@5086
   122
            LPTSTR tstr;
slouken@3647
   123
            const int w = 100;
slouken@3647
   124
            const int h = 25;
slouken@3647
   125
            const int gap = 10;
slouken@3647
   126
            int x = gap;
slouken@3647
   127
            int y = 50;
slouken@3647
   128
            int len;
slouken@3647
   129
            int i;
slouken@3647
   130
            static const struct { 
slouken@5086
   131
                LPCTSTR name;
slouken@3647
   132
                SDL_assert_state state;
slouken@3647
   133
            } buttons[] = {
slouken@5086
   134
                {TEXT("Abort"), SDL_ASSERTION_ABORT },
slouken@5086
   135
                {TEXT("Break"), SDL_ASSERTION_BREAK },
slouken@5086
   136
                {TEXT("Retry"), SDL_ASSERTION_RETRY },
slouken@5086
   137
                {TEXT("Ignore"), SDL_ASSERTION_IGNORE },
slouken@5086
   138
                {TEXT("Always Ignore"), SDL_ASSERTION_ALWAYS_IGNORE },
slouken@3647
   139
            };
slouken@3647
   140
slouken@3647
   141
            len = (int) SDL_snprintf(buf, sizeof (buf), 
slouken@3647
   142
                         "Assertion failure at %s (%s:%d), triggered %u time%s:\r\n  '%s'",
slouken@3647
   143
                         data->function, data->filename, data->linenum,
slouken@3647
   144
                         data->trigger_count, (data->trigger_count == 1) ? "" : "s",
slouken@3647
   145
                         data->condition);
slouken@3647
   146
            if ((len < 0) || (len >= sizeof (buf))) {
slouken@3647
   147
                buf[sizeof (buf) - 1] = '\0';
slouken@3647
   148
            }
slouken@3647
   149
slouken@5086
   150
            tstr = WIN_UTF8ToString(buf);
slouken@5086
   151
            CreateWindow(TEXT("STATIC"), tstr,
slouken@3647
   152
                         WS_VISIBLE | WS_CHILD | SS_LEFT,
slouken@3647
   153
                         x, y, 550, 100,
slouken@3647
   154
                         hwnd, (HMENU) 1, NULL, NULL);
slouken@5086
   155
            SDL_free(tstr);
slouken@3647
   156
            y += 110;
slouken@3647
   157
slouken@3647
   158
            for (i = 0; i < (sizeof (buttons) / sizeof (buttons[0])); i++) {
slouken@5086
   159
                CreateWindow(TEXT("BUTTON"), buttons[i].name,
slouken@3647
   160
                         WS_VISIBLE | WS_CHILD,
slouken@3647
   161
                         x, y, w, h,
slouken@3647
   162
                         hwnd, (HMENU) buttons[i].state, NULL, NULL);
slouken@3647
   163
                x += w + gap;
slouken@3647
   164
            }
slouken@3647
   165
            break;
slouken@3647
   166
        }
slouken@3647
   167
slouken@3647
   168
        case WM_COMMAND:
slouken@3647
   169
            SDL_Windows_AssertChoice = ((SDL_assert_state) (LOWORD(wParam)));
slouken@3647
   170
            SDL_Windows_AssertData = NULL;
slouken@3647
   171
            break;
slouken@3647
   172
slouken@3647
   173
        case WM_DESTROY:
slouken@3647
   174
            SDL_Windows_AssertData = NULL;
slouken@3647
   175
            break;
slouken@3647
   176
    }
slouken@3647
   177
slouken@3647
   178
    return DefWindowProc(hwnd, msg, wParam, lParam);
slouken@3647
   179
}
slouken@3647
   180
slouken@3647
   181
static SDL_assert_state
slouken@3647
   182
SDL_PromptAssertion_windows(const SDL_assert_data *data)
slouken@3647
   183
{
slouken@3647
   184
    HINSTANCE hInstance = 0;  /* !!! FIXME? */
slouken@3647
   185
    HWND hwnd;
slouken@3647
   186
    MSG msg;
slouken@3647
   187
    WNDCLASS wc = {0};
slouken@3647
   188
slouken@3647
   189
    SDL_Windows_AssertChoice = SDL_ASSERTION_ABORT;
slouken@3647
   190
    SDL_Windows_AssertData = data;
slouken@3647
   191
slouken@3647
   192
    wc.lpszClassName = TEXT("SDL_assert");
slouken@3647
   193
    wc.hInstance = hInstance ;
slouken@3647
   194
    wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
slouken@3647
   195
    wc.lpfnWndProc = SDL_Assertion_WndProc;
slouken@3647
   196
    wc.hCursor = LoadCursor(0, IDC_ARROW);
slouken@3647
   197
  
slouken@3647
   198
    RegisterClass(&wc);
slouken@3647
   199
    hwnd = CreateWindow(wc.lpszClassName, TEXT("SDL assertion failure"),
slouken@3647
   200
                 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
slouken@3647
   201
                 150, 150, 570, 260, 0, 0, hInstance, 0);  
slouken@3647
   202
slouken@3647
   203
    while (GetMessage(&msg, NULL, 0, 0) && (SDL_Windows_AssertData != NULL)) {
slouken@3647
   204
        TranslateMessage(&msg);
slouken@3647
   205
        DispatchMessage(&msg);
slouken@3647
   206
    }
slouken@3647
   207
slouken@3647
   208
    DestroyWindow(hwnd);
slouken@3647
   209
    UnregisterClass(wc.lpszClassName, hInstance);
slouken@3647
   210
    return SDL_Windows_AssertChoice;
slouken@3647
   211
}
slouken@3647
   212
#endif
slouken@3647
   213
slouken@3647
   214
slouken@3647
   215
static void SDL_AddAssertionToReport(SDL_assert_data *data)
slouken@3647
   216
{
slouken@3647
   217
    /* (data) is always a static struct defined with the assert macros, so
slouken@3647
   218
       we don't have to worry about copying or allocating them. */
icculus@5541
   219
    data->trigger_count++;
icculus@5541
   220
    if (data->trigger_count == 1) {  /* not yet added? */
slouken@3647
   221
        data->next = triggered_assertions;
slouken@3647
   222
        triggered_assertions = data;
slouken@3647
   223
    }
slouken@3647
   224
}
slouken@3647
   225
icculus@3670
   226
slouken@3647
   227
static void SDL_GenerateAssertionReport(void)
slouken@3647
   228
{
icculus@5541
   229
    const SDL_assert_data *item = triggered_assertions;
icculus@3670
   230
icculus@3670
   231
    /* only do this if the app hasn't assigned an assertion handler. */
icculus@5541
   232
    if ((item != NULL) && (assertion_handler != SDL_PromptAssertion)) {
slouken@3647
   233
        debug_print("\n\nSDL assertion report.\n");
slouken@3647
   234
        debug_print("All SDL assertions between last init/quit:\n\n");
slouken@3647
   235
icculus@5541
   236
        while (item != NULL) {
slouken@3647
   237
            debug_print(
slouken@3647
   238
                "'%s'\n"
slouken@3647
   239
                "    * %s (%s:%d)\n"
slouken@3647
   240
                "    * triggered %u time%s.\n"
slouken@3647
   241
                "    * always ignore: %s.\n",
slouken@3647
   242
                item->condition, item->function, item->filename,
slouken@3647
   243
                item->linenum, item->trigger_count,
slouken@3647
   244
                (item->trigger_count == 1) ? "" : "s",
slouken@3647
   245
                item->always_ignore ? "yes" : "no");
slouken@3647
   246
            item = item->next;
slouken@3647
   247
        }
slouken@3647
   248
        debug_print("\n");
slouken@3647
   249
icculus@3670
   250
        SDL_ResetAssertionReport();
slouken@3647
   251
    }
slouken@3647
   252
}
slouken@3647
   253
icculus@3661
   254
static void SDL_ExitProcess(int exitcode)
slouken@3647
   255
{
slouken@5086
   256
#ifdef __WIN32__
slouken@3647
   257
    ExitProcess(42);
slouken@3656
   258
#else
slouken@3647
   259
    _exit(42);
slouken@3647
   260
#endif
slouken@3647
   261
}
icculus@3661
   262
icculus@3661
   263
static void SDL_AbortAssertion(void)
icculus@3661
   264
{
icculus@3661
   265
    SDL_Quit();
icculus@3661
   266
    SDL_ExitProcess(42);
icculus@3661
   267
}
icculus@3661
   268
slouken@3647
   269
icculus@3670
   270
static SDL_assert_state
icculus@3670
   271
SDL_PromptAssertion(const SDL_assert_data *data, void *userdata)
slouken@3647
   272
{
slouken@3647
   273
    const char *envr;
slouken@3657
   274
    SDL_assert_state state = SDL_ASSERTION_ABORT;
slouken@3685
   275
    SDL_Window *window;
slouken@3647
   276
icculus@3670
   277
    (void) userdata;  /* unused in default handler. */
icculus@3670
   278
slouken@3647
   279
    debug_print("\n\n"
slouken@3647
   280
                "Assertion failure at %s (%s:%d), triggered %u time%s:\n"
slouken@3647
   281
                "  '%s'\n"
slouken@3647
   282
                "\n",
slouken@3647
   283
                data->function, data->filename, data->linenum,
slouken@3647
   284
                data->trigger_count, (data->trigger_count == 1) ? "" : "s",
slouken@3647
   285
                data->condition);
slouken@3647
   286
slouken@3655
   287
    /* let env. variable override, so unit tests won't block in a GUI. */
slouken@3647
   288
    envr = SDL_getenv("SDL_ASSERT");
slouken@3647
   289
    if (envr != NULL) {
slouken@3647
   290
        if (SDL_strcmp(envr, "abort") == 0) {
slouken@3647
   291
            return SDL_ASSERTION_ABORT;
slouken@3647
   292
        } else if (SDL_strcmp(envr, "break") == 0) {
slouken@3647
   293
            return SDL_ASSERTION_BREAK;
slouken@3647
   294
        } else if (SDL_strcmp(envr, "retry") == 0) {
slouken@3647
   295
            return SDL_ASSERTION_RETRY;
slouken@3647
   296
        } else if (SDL_strcmp(envr, "ignore") == 0) {
slouken@3647
   297
            return SDL_ASSERTION_IGNORE;
slouken@3647
   298
        } else if (SDL_strcmp(envr, "always_ignore") == 0) {
slouken@3647
   299
            return SDL_ASSERTION_ALWAYS_IGNORE;
slouken@3647
   300
        } else {
slouken@3647
   301
            return SDL_ASSERTION_ABORT;  /* oh well. */
slouken@3647
   302
        }
slouken@3647
   303
    }
slouken@3647
   304
slouken@3657
   305
    /* Leave fullscreen mode, if possible (scary!) */
slouken@3657
   306
    window = SDL_GetFocusWindow();
slouken@3657
   307
    if (window) {
slouken@3657
   308
        if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) {
slouken@3657
   309
            SDL_MinimizeWindow(window);
slouken@3657
   310
        } else {
icculus@3670
   311
            /* !!! FIXME: ungrab the input if we're not fullscreen? */
slouken@3657
   312
            /* No need to mess with the window */
slouken@3657
   313
            window = 0;
slouken@3657
   314
        }
slouken@3657
   315
    }
slouken@3657
   316
slouken@3647
   317
    /* platform-specific UI... */
slouken@3647
   318
slouken@5086
   319
#ifdef __WIN32__
slouken@3657
   320
    state = SDL_PromptAssertion_windows(data);
slouken@3647
   321
icculus@6051
   322
#elif defined __MACOSX__ && defined SDL_VIDEO_DRIVER_COCOA
slouken@3647
   323
    /* This has to be done in an Objective-C (*.m) file, so we call out. */
slouken@3647
   324
    extern SDL_assert_state SDL_PromptAssertion_cocoa(const SDL_assert_data *);
slouken@3657
   325
    state = SDL_PromptAssertion_cocoa(data);
slouken@3647
   326
slouken@3657
   327
#else
slouken@3647
   328
    /* this is a little hacky. */
slouken@3647
   329
    for ( ; ; ) {
slouken@3647
   330
        char buf[32];
slouken@3647
   331
        fprintf(stderr, "Abort/Break/Retry/Ignore/AlwaysIgnore? [abriA] : ");
slouken@3647
   332
        fflush(stderr);
slouken@3647
   333
        if (fgets(buf, sizeof (buf), stdin) == NULL) {
slouken@3657
   334
            break;
slouken@3647
   335
        }
slouken@3647
   336
slouken@3647
   337
        if (SDL_strcmp(buf, "a") == 0) {
slouken@3657
   338
            state = SDL_ASSERTION_ABORT;
slouken@3657
   339
            break;
icculus@5547
   340
        } else if (SDL_strcmp(buf, "b") == 0) {
slouken@3657
   341
            state = SDL_ASSERTION_BREAK;
slouken@3657
   342
            break;
icculus@5547
   343
        } else if (SDL_strcmp(buf, "r") == 0) {
slouken@3657
   344
            state = SDL_ASSERTION_RETRY;
slouken@3657
   345
            break;
icculus@5547
   346
        } else if (SDL_strcmp(buf, "i") == 0) {
slouken@3657
   347
            state = SDL_ASSERTION_IGNORE;
slouken@3657
   348
            break;
icculus@5547
   349
        } else if (SDL_strcmp(buf, "A") == 0) {
slouken@3657
   350
            state = SDL_ASSERTION_ALWAYS_IGNORE;
slouken@3657
   351
            break;
slouken@3647
   352
        }
slouken@3647
   353
    }
slouken@3647
   354
#endif
slouken@3647
   355
slouken@3657
   356
    /* Re-enter fullscreen mode */
slouken@3657
   357
    if (window) {
slouken@3657
   358
        SDL_RestoreWindow(window);
slouken@3657
   359
    }
slouken@3657
   360
slouken@3657
   361
    return state;
slouken@3647
   362
}
slouken@3647
   363
slouken@3647
   364
slouken@3647
   365
SDL_assert_state
slouken@3655
   366
SDL_ReportAssertion(SDL_assert_data *data, const char *func, const char *file,
slouken@3655
   367
                    int line)
slouken@3647
   368
{
icculus@3661
   369
    static int assertion_running = 0;
icculus@3662
   370
    static SDL_SpinLock spinlock = 0;
icculus@3661
   371
    SDL_assert_state state = SDL_ASSERTION_IGNORE;
slouken@3647
   372
icculus@3662
   373
    SDL_AtomicLock(&spinlock);
icculus@3662
   374
    if (assertion_mutex == NULL) { /* never called SDL_Init()? */
icculus@3662
   375
        assertion_mutex = SDL_CreateMutex();
icculus@3662
   376
        if (assertion_mutex == NULL) {
icculus@3662
   377
            SDL_AtomicUnlock(&spinlock);
icculus@3662
   378
            return SDL_ASSERTION_IGNORE;   /* oh well, I guess. */
icculus@3662
   379
        }
icculus@3662
   380
    }
icculus@3662
   381
    SDL_AtomicUnlock(&spinlock);
icculus@3662
   382
slouken@3647
   383
    if (SDL_LockMutex(assertion_mutex) < 0) {
slouken@3647
   384
        return SDL_ASSERTION_IGNORE;   /* oh well, I guess. */
slouken@3647
   385
    }
slouken@3647
   386
slouken@3647
   387
    /* doing this because Visual C is upset over assigning in the macro. */
slouken@3647
   388
    if (data->trigger_count == 0) {
slouken@3647
   389
        data->function = func;
slouken@3655
   390
        data->filename = file;
slouken@3655
   391
        data->linenum = line;
slouken@3647
   392
    }
slouken@3647
   393
slouken@3647
   394
    SDL_AddAssertionToReport(data);
slouken@3647
   395
icculus@3661
   396
    assertion_running++;
icculus@3661
   397
    if (assertion_running > 1) {   /* assert during assert! Abort. */
icculus@3661
   398
        if (assertion_running == 2) {
icculus@3661
   399
            SDL_AbortAssertion();
icculus@3661
   400
        } else if (assertion_running == 3) {  /* Abort asserted! */
icculus@3661
   401
            SDL_ExitProcess(42);
icculus@3661
   402
        } else {
icculus@3661
   403
            while (1) { /* do nothing but spin; what else can you do?! */ }
icculus@3661
   404
        }
slouken@3647
   405
    }
slouken@3647
   406
icculus@3661
   407
    if (!data->always_ignore) {
icculus@3670
   408
        state = assertion_handler(data, assertion_userdata);
icculus@3661
   409
    }
slouken@3647
   410
slouken@3647
   411
    switch (state)
slouken@3647
   412
    {
slouken@3647
   413
        case SDL_ASSERTION_ABORT:
slouken@3647
   414
            SDL_AbortAssertion();
slouken@3647
   415
            return SDL_ASSERTION_IGNORE;  /* shouldn't return, but oh well. */
slouken@3647
   416
slouken@3647
   417
        case SDL_ASSERTION_ALWAYS_IGNORE:
slouken@3647
   418
            state = SDL_ASSERTION_IGNORE;
slouken@3647
   419
            data->always_ignore = 1;
slouken@3647
   420
            break;
slouken@3647
   421
slouken@3647
   422
        case SDL_ASSERTION_IGNORE:
slouken@3647
   423
        case SDL_ASSERTION_RETRY:
slouken@3647
   424
        case SDL_ASSERTION_BREAK:
slouken@3647
   425
            break;  /* macro handles these. */
slouken@3647
   426
    }
slouken@3647
   427
icculus@3661
   428
    assertion_running--;
slouken@3647
   429
    SDL_UnlockMutex(assertion_mutex);
slouken@3647
   430
slouken@3647
   431
    return state;
slouken@3647
   432
}
slouken@3647
   433
slouken@3647
   434
slouken@3647
   435
int SDL_AssertionsInit(void)
slouken@3647
   436
{
icculus@3664
   437
    /* this is a no-op at the moment. */
slouken@3647
   438
    return 0;
slouken@3647
   439
}
slouken@3647
   440
slouken@3647
   441
void SDL_AssertionsQuit(void)
slouken@3647
   442
{
slouken@3647
   443
    SDL_GenerateAssertionReport();
icculus@3664
   444
    if (assertion_mutex != NULL) {
icculus@3664
   445
        SDL_DestroyMutex(assertion_mutex);
icculus@3664
   446
        assertion_mutex = NULL;
icculus@3664
   447
    }
icculus@3670
   448
}
icculus@3670
   449
icculus@3670
   450
void SDL_SetAssertionHandler(SDL_AssertionHandler handler, void *userdata)
icculus@3670
   451
{
icculus@3670
   452
    if (handler != NULL) {
icculus@3670
   453
        assertion_handler = handler;
icculus@3670
   454
        assertion_userdata = userdata;
icculus@3670
   455
    } else {
icculus@3670
   456
        assertion_handler = SDL_PromptAssertion;
icculus@3670
   457
        assertion_userdata = NULL;
icculus@3670
   458
    }
icculus@3670
   459
}
icculus@3670
   460
icculus@3670
   461
const SDL_assert_data *SDL_GetAssertionReport(void)
icculus@3670
   462
{
icculus@3670
   463
    return triggered_assertions;
icculus@3670
   464
}
icculus@3670
   465
icculus@3670
   466
void SDL_ResetAssertionReport(void)
icculus@3670
   467
{
icculus@3670
   468
    SDL_assert_data *next = NULL;
icculus@5541
   469
    SDL_assert_data *item;
icculus@5541
   470
    for (item = triggered_assertions; item != NULL; item = next) {
icculus@3670
   471
        next = (SDL_assert_data *) item->next;
icculus@3670
   472
        item->always_ignore = SDL_FALSE;
icculus@3670
   473
        item->trigger_count = 0;
icculus@3670
   474
        item->next = NULL;
icculus@3670
   475
    }
icculus@3670
   476
icculus@5541
   477
    triggered_assertions = NULL;
slouken@3647
   478
}
slouken@3647
   479
slouken@3647
   480
/* vi: set ts=4 sw=4 expandtab: */