Removed assertion list terminator (just do it like a normal linked list).
authorRyan C. Gordon <icculus@icculus.org>
Tue, 19 Apr 2011 14:12:56 -0400
changeset 5541b63f1383f8c9
parent 5540 918efbff8259
child 5542 882871b2db1a
Removed assertion list terminator (just do it like a normal linked list).
include/SDL_assert.h
src/SDL_assert.c
     1.1 --- a/include/SDL_assert.h	Tue Apr 19 09:53:01 2011 -0700
     1.2 +++ b/include/SDL_assert.h	Tue Apr 19 14:12:56 2011 -0400
     1.3 @@ -205,7 +205,7 @@
     1.4   *
     1.5   *  <code>
     1.6   *  const SDL_assert_data *item = SDL_GetAssertionReport();
     1.7 - *  while (item->condition) {
     1.8 + *  while (item) {
     1.9   *      printf("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n",
    1.10   *             item->condition, item->function, item->filename,
    1.11   *             item->linenum, item->trigger_count,
    1.12 @@ -214,8 +214,7 @@
    1.13   *  }
    1.14   *  </code>
    1.15   *
    1.16 - *  \return List of all assertions. This never returns NULL,
    1.17 - *          even if there are no items.
    1.18 + *  \return List of all assertions.
    1.19   *  \sa SDL_ResetAssertionReport
    1.20   */
    1.21  extern DECLSPEC const SDL_assert_data * SDLCALL SDL_GetAssertionReport(void);
     2.1 --- a/src/SDL_assert.c	Tue Apr 19 09:53:01 2011 -0700
     2.2 +++ b/src/SDL_assert.c	Tue Apr 19 14:12:56 2011 -0400
     2.3 @@ -44,8 +44,7 @@
     2.4   * We keep all triggered assertions in a singly-linked list so we can
     2.5   *  generate a report later.
     2.6   */
     2.7 -static SDL_assert_data assertion_list_terminator = { 0, 0, 0, 0, 0, 0, 0 };
     2.8 -static SDL_assert_data *triggered_assertions = &assertion_list_terminator;
     2.9 +static SDL_assert_data *triggered_assertions = NULL;
    2.10  
    2.11  static SDL_mutex *assertion_mutex = NULL;
    2.12  static SDL_AssertionHandler assertion_handler = SDL_PromptAssertion;
    2.13 @@ -217,7 +216,8 @@
    2.14  {
    2.15      /* (data) is always a static struct defined with the assert macros, so
    2.16         we don't have to worry about copying or allocating them. */
    2.17 -    if (data->next == NULL) {  /* not yet added? */
    2.18 +    data->trigger_count++;
    2.19 +    if (data->trigger_count == 1) {  /* not yet added? */
    2.20          data->next = triggered_assertions;
    2.21          triggered_assertions = data;
    2.22      }
    2.23 @@ -226,19 +226,14 @@
    2.24  
    2.25  static void SDL_GenerateAssertionReport(void)
    2.26  {
    2.27 -    const SDL_assert_data *item;
    2.28 +    const SDL_assert_data *item = triggered_assertions;
    2.29  
    2.30      /* only do this if the app hasn't assigned an assertion handler. */
    2.31 -    if (assertion_handler != SDL_PromptAssertion)
    2.32 -        return;
    2.33 -
    2.34 -    item = SDL_GetAssertionReport();
    2.35 -    if (item->condition)
    2.36 -    {
    2.37 +    if ((item != NULL) && (assertion_handler != SDL_PromptAssertion)) {
    2.38          debug_print("\n\nSDL assertion report.\n");
    2.39          debug_print("All SDL assertions between last init/quit:\n\n");
    2.40  
    2.41 -        while (item->condition) {
    2.42 +        while (item != NULL) {
    2.43              debug_print(
    2.44                  "'%s'\n"
    2.45                  "    * %s (%s:%d)\n"
    2.46 @@ -398,8 +393,6 @@
    2.47  
    2.48      SDL_AddAssertionToReport(data);
    2.49  
    2.50 -    data->trigger_count++;
    2.51 -
    2.52      assertion_running++;
    2.53      if (assertion_running > 1) {   /* assert during assert! Abort. */
    2.54          if (assertion_running == 2) {
    2.55 @@ -472,16 +465,16 @@
    2.56  
    2.57  void SDL_ResetAssertionReport(void)
    2.58  {
    2.59 -    SDL_assert_data *item = triggered_assertions;
    2.60      SDL_assert_data *next = NULL;
    2.61 -    for (item = triggered_assertions; item->condition; item = next) {
    2.62 +    SDL_assert_data *item;
    2.63 +    for (item = triggered_assertions; item != NULL; item = next) {
    2.64          next = (SDL_assert_data *) item->next;
    2.65          item->always_ignore = SDL_FALSE;
    2.66          item->trigger_count = 0;
    2.67          item->next = NULL;
    2.68      }
    2.69  
    2.70 -    triggered_assertions = &assertion_list_terminator;
    2.71 +    triggered_assertions = NULL;
    2.72  }
    2.73  
    2.74  /* vi: set ts=4 sw=4 expandtab: */