2
0
mirror of https://github.com/xcat2/xNBA.git synced 2024-11-23 10:01:47 +00:00

Assertions are now handled via the POSIX-like <assert.h>.

This commit is contained in:
Michael Brown 2006-03-23 19:33:57 +00:00
parent 55497b3402
commit af23ff8a24
4 changed files with 15 additions and 35 deletions

View File

@ -42,6 +42,7 @@
#include "string.h"
#include "io.h"
#include "errno.h"
#include <assert.h>
#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 );

View File

@ -1,6 +1,7 @@
#include "etherboot.h"
#include "init.h"
#include "memsizes.h"
#include <assert.h>
#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;
}

View File

@ -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. */

View File

@ -6,6 +6,7 @@
#include "buffer.h"
#include "dhcp.h" /* for dhcp_dev_id */
#include "tables.h"
#include <assert.h>
/*
* 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 )
/*