From af23ff8a24a9de9b725335527529e5cc743311eb Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 23 Mar 2006 19:33:57 +0000 Subject: [PATCH] Assertions are now handled via the POSIX-like . --- src/core/buffer.c | 5 +++-- src/core/heap.c | 11 ++++++----- src/include/compiler.h | 23 +++-------------------- src/include/dev.h | 11 +++-------- 4 files changed, 15 insertions(+), 35 deletions(-) diff --git a/src/core/buffer.c b/src/core/buffer.c index b1a0464e..5c31ff8d 100644 --- a/src/core/buffer.c +++ b/src/core/buffer.c @@ -42,6 +42,7 @@ #include "string.h" #include "io.h" #include "errno.h" +#include #include "buffer.h" /** @@ -208,7 +209,7 @@ int fill_buffer ( struct buffer *buffer, const void *data, /* Write back 'before' block, if any */ if ( before.start ) { before.tail = 0; - ASSERT ( ( before.end - before.start ) >= + assert ( ( before.end - before.start ) >= sizeof ( struct buffer_free_block ) ); store_free_block ( &before ); } else { @@ -217,7 +218,7 @@ int fill_buffer ( struct buffer *buffer, const void *data, /* Write back 'after' block, if any */ if ( after.start < buffer->end ) { - ASSERT ( after.tail || + assert ( after.tail || ( ( after.end - after.start ) >= sizeof ( struct buffer_free_block ) ) ); store_free_block ( &after ); diff --git a/src/core/heap.c b/src/core/heap.c index d9a7efec..d70aa2d9 100644 --- a/src/core/heap.c +++ b/src/core/heap.c @@ -1,6 +1,7 @@ #include "etherboot.h" #include "init.h" #include "memsizes.h" +#include #include "heap.h" struct heap_block { @@ -76,7 +77,7 @@ static void init_heap ( void ) { } } - ASSERT ( size != 0 ); + assert ( size != 0 ); DBG ( "HEAP using region [%x,%x)\n", heap_start, heap_end ); heap_ptr = heap_end; } @@ -95,7 +96,7 @@ void * emalloc ( size_t size, unsigned int align ) { struct heap_block *block; physaddr_t addr; - ASSERT ( ( align & ( align - 1 ) ) == 0 ); + assert ( ( align & ( align - 1 ) ) == 0 ); addr = block_alloc_addr ( heap_ptr, size, align ); if ( addr < heap_start ) { @@ -133,7 +134,7 @@ static inline physaddr_t block_free_addr ( size_t size ) { void efree ( void *ptr ) { struct heap_block *block; - ASSERT ( ptr == phys_to_virt ( heap_ptr + sizeof ( size_t ) ) ); + assert ( ptr == phys_to_virt ( heap_ptr + sizeof ( size_t ) ) ); block = ( struct heap_block * ) ( ptr - offsetof ( struct heap_block, data ) ); @@ -142,7 +143,7 @@ void efree ( void *ptr ) { DBG ( "HEAP freed %x [%x,%x)\n", virt_to_phys ( ptr ), virt_to_phys ( block ), heap_ptr ); - ASSERT ( heap_ptr <= heap_end ); + assert ( heap_ptr <= heap_end ); } /* @@ -199,7 +200,7 @@ void * erealloc ( void *ptr, size_t size ) { * already checked that there was sufficient space. */ ptr = emalloc ( size, old_align ); - ASSERT ( ptr != NULL ); + assert ( ptr != NULL ); return ptr; } diff --git a/src/include/compiler.h b/src/include/compiler.h index 79781bc7..08a2d364 100644 --- a/src/include/compiler.h +++ b/src/include/compiler.h @@ -15,7 +15,7 @@ * Global compiler definitions. * * This file is implicitly included by every @c .c file in Etherboot. - * It defines global macros such as DBG() and ASSERT(). + * It defines global macros such as DBG(). * * We arrange for each object to export the symbol @c obj_OBJECT * (where @c OBJECT is the object name, e.g. @c rtl8139) as a global @@ -138,25 +138,8 @@ __asm__ ( ".equ\tDEBUG_LEVEL, " DEBUG_SYMBOL_STR ); #define DBG2 DBG_PRINT #endif -/** - * Assert a condition. - * - * If the condition is not true, a debug message will be printed. - * Assertions only take effect if the debug level is non-zero (see - * DBG()). - * - */ -#define ASSERT(x) - -#if DEBUG_SYMBOL >= 1 -#undef ASSERT -#define ASSERT(x) \ - do { \ - if ( ! (x) ) { \ - DBG ( "ASSERT(%s) failed at %s line %d [%s]\n", #x, \ - __FILE__, __LINE__, __FUNCTION__ ); \ - } \ - } while (0) +#if DEBUG_SYMBOL == 0 +#define NDEBUG #endif /** Declare a data structure as packed. */ diff --git a/src/include/dev.h b/src/include/dev.h index d6e31dab..fa549deb 100644 --- a/src/include/dev.h +++ b/src/include/dev.h @@ -6,6 +6,7 @@ #include "buffer.h" #include "dhcp.h" /* for dhcp_dev_id */ #include "tables.h" +#include /* * Forward declarations @@ -100,17 +101,11 @@ struct bus_dev { * */ -#define LINKER_ASSERT(test,error_symbol) \ - if ( ! (test) ) { \ - extern void error_symbol ( void ); \ - error_symbol(); \ - } - #define BUS_LOC_CHECK(datatype) \ - LINKER_ASSERT( ( sizeof (datatype) <= sizeof (struct bus_loc) ), \ + linker_assert( ( sizeof (datatype) <= sizeof (struct bus_loc) ), \ __BUS_LOC_SIZE_is_too_small__see_dev_h ) #define BUS_DEV_CHECK(datatype) \ - LINKER_ASSERT( ( sizeof (datatype) <= sizeof (struct bus_dev) ), \ + linker_assert( ( sizeof (datatype) <= sizeof (struct bus_dev) ), \ __BUS_DEV_SIZE_is_too_small__see_dev_h ) /*