Changeset d8de5d3 in mainline for uspace/lib/c/generic/assert.c


Ignore:
Timestamp:
2011-05-23T13:31:54Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
540cb1b, 773f188
Parents:
207533f
Message:

do not reinvent the wheel in assert_abort(), use the services of printf_core() to implement a more elegant klog output
(printf_core should be safe w.r.t. nested assertions and memory allocation)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/assert.c

    r207533f rd8de5d3  
    3939#include <stdint.h>
    4040
    41 #define MSG_START       "Assertion failed ("
    42 #define MSG_FILE        ") in file \""
    43 #define MSG_LINE        "\", line "
    44 #define MSG_END         ".\n"
    45 
    46 static atomic_t failed_asserts;
     41static atomic_t failed_asserts = {0};
    4742
    4843void assert_abort(const char *cond, const char *file, unsigned int line)
    4944{
    50         char lstr[11];
    51         char *pd = &lstr[10];
    52         uint32_t ln = (uint32_t) line;
    53 
    54         /*
    55          * Convert ln to a zero-terminated string.
    56          */
    57         *pd-- = 0;
    58         for (; ln; ln /= 10)
    59                 *pd-- = '0' + ln % 10;
    60         pd++;
    61 
    6245        /*
    6346         * Send the message safely to klog. Nested asserts should not occur.
    6447         */
    65         klog_write(MSG_START, str_size(MSG_START));
    66         klog_write(cond, str_size(cond));
    67         klog_write(MSG_FILE, str_size(MSG_FILE));
    68         klog_write(file, str_size(file));
    69         klog_write(MSG_LINE, str_size(MSG_LINE));
    70         klog_write(pd, str_size(pd));
    71         klog_write(MSG_END, str_size(MSG_END));
    72 
     48        klog_printf("Assertion failed (%s) in file \"%s\", line %u.\n",
     49            cond, file, line);
     50       
    7351        /*
    7452         * Check if this is a nested or parallel assert.
     
    8260         * assertions.
    8361         */
    84         printf(MSG_START "%s" MSG_FILE "%s" MSG_LINE "%u" MSG_END,
     62        printf("Assertion failed (%s) in file \"%s\", line %u.\n",
    8563            cond, file, line);
    8664        stacktrace_print();
    87 
     65       
    8866        abort();
    8967}
Note: See TracChangeset for help on using the changeset viewer.