src/SDL_assert.c
changeset 5541 b63f1383f8c9
parent 5535 96594ac5fd1a
child 5547 4ccecd0901e2
equal deleted inserted replaced
5540:918efbff8259 5541:b63f1383f8c9
    42 
    42 
    43 /*
    43 /*
    44  * We keep all triggered assertions in a singly-linked list so we can
    44  * We keep all triggered assertions in a singly-linked list so we can
    45  *  generate a report later.
    45  *  generate a report later.
    46  */
    46  */
    47 static SDL_assert_data assertion_list_terminator = { 0, 0, 0, 0, 0, 0, 0 };
    47 static SDL_assert_data *triggered_assertions = NULL;
    48 static SDL_assert_data *triggered_assertions = &assertion_list_terminator;
       
    49 
    48 
    50 static SDL_mutex *assertion_mutex = NULL;
    49 static SDL_mutex *assertion_mutex = NULL;
    51 static SDL_AssertionHandler assertion_handler = SDL_PromptAssertion;
    50 static SDL_AssertionHandler assertion_handler = SDL_PromptAssertion;
    52 static void *assertion_userdata = NULL;
    51 static void *assertion_userdata = NULL;
    53 
    52 
   215 
   214 
   216 static void SDL_AddAssertionToReport(SDL_assert_data *data)
   215 static void SDL_AddAssertionToReport(SDL_assert_data *data)
   217 {
   216 {
   218     /* (data) is always a static struct defined with the assert macros, so
   217     /* (data) is always a static struct defined with the assert macros, so
   219        we don't have to worry about copying or allocating them. */
   218        we don't have to worry about copying or allocating them. */
   220     if (data->next == NULL) {  /* not yet added? */
   219     data->trigger_count++;
       
   220     if (data->trigger_count == 1) {  /* not yet added? */
   221         data->next = triggered_assertions;
   221         data->next = triggered_assertions;
   222         triggered_assertions = data;
   222         triggered_assertions = data;
   223     }
   223     }
   224 }
   224 }
   225 
   225 
   226 
   226 
   227 static void SDL_GenerateAssertionReport(void)
   227 static void SDL_GenerateAssertionReport(void)
   228 {
   228 {
   229     const SDL_assert_data *item;
   229     const SDL_assert_data *item = triggered_assertions;
   230 
   230 
   231     /* only do this if the app hasn't assigned an assertion handler. */
   231     /* only do this if the app hasn't assigned an assertion handler. */
   232     if (assertion_handler != SDL_PromptAssertion)
   232     if ((item != NULL) && (assertion_handler != SDL_PromptAssertion)) {
   233         return;
       
   234 
       
   235     item = SDL_GetAssertionReport();
       
   236     if (item->condition)
       
   237     {
       
   238         debug_print("\n\nSDL assertion report.\n");
   233         debug_print("\n\nSDL assertion report.\n");
   239         debug_print("All SDL assertions between last init/quit:\n\n");
   234         debug_print("All SDL assertions between last init/quit:\n\n");
   240 
   235 
   241         while (item->condition) {
   236         while (item != NULL) {
   242             debug_print(
   237             debug_print(
   243                 "'%s'\n"
   238                 "'%s'\n"
   244                 "    * %s (%s:%d)\n"
   239                 "    * %s (%s:%d)\n"
   245                 "    * triggered %u time%s.\n"
   240                 "    * triggered %u time%s.\n"
   246                 "    * always ignore: %s.\n",
   241                 "    * always ignore: %s.\n",
   396         data->linenum = line;
   391         data->linenum = line;
   397     }
   392     }
   398 
   393 
   399     SDL_AddAssertionToReport(data);
   394     SDL_AddAssertionToReport(data);
   400 
   395 
   401     data->trigger_count++;
       
   402 
       
   403     assertion_running++;
   396     assertion_running++;
   404     if (assertion_running > 1) {   /* assert during assert! Abort. */
   397     if (assertion_running > 1) {   /* assert during assert! Abort. */
   405         if (assertion_running == 2) {
   398         if (assertion_running == 2) {
   406             SDL_AbortAssertion();
   399             SDL_AbortAssertion();
   407         } else if (assertion_running == 3) {  /* Abort asserted! */
   400         } else if (assertion_running == 3) {  /* Abort asserted! */
   470     return triggered_assertions;
   463     return triggered_assertions;
   471 }
   464 }
   472 
   465 
   473 void SDL_ResetAssertionReport(void)
   466 void SDL_ResetAssertionReport(void)
   474 {
   467 {
   475     SDL_assert_data *item = triggered_assertions;
       
   476     SDL_assert_data *next = NULL;
   468     SDL_assert_data *next = NULL;
   477     for (item = triggered_assertions; item->condition; item = next) {
   469     SDL_assert_data *item;
       
   470     for (item = triggered_assertions; item != NULL; item = next) {
   478         next = (SDL_assert_data *) item->next;
   471         next = (SDL_assert_data *) item->next;
   479         item->always_ignore = SDL_FALSE;
   472         item->always_ignore = SDL_FALSE;
   480         item->trigger_count = 0;
   473         item->trigger_count = 0;
   481         item->next = NULL;
   474         item->next = NULL;
   482     }
   475     }
   483 
   476 
   484     triggered_assertions = &assertion_list_terminator;
   477     triggered_assertions = NULL;
   485 }
   478 }
   486 
   479 
   487 /* vi: set ts=4 sw=4 expandtab: */
   480 /* vi: set ts=4 sw=4 expandtab: */