src/SDL_assert.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 24 Jan 2011 21:20:30 -0800
changeset 5090 327f181542f1
parent 5086 c2539ff054c8
child 5262 b530ef003506
permissions -rw-r--r--
Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.

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