Browse Source

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

tags/v0.9.3
Michael Brown 19 years ago
parent
commit
af23ff8a24
4 changed files with 15 additions and 35 deletions
  1. 3
    2
      src/core/buffer.c
  2. 6
    5
      src/core/heap.c
  3. 3
    20
      src/include/compiler.h
  4. 3
    8
      src/include/dev.h

+ 3
- 2
src/core/buffer.c View File

@@ -42,6 +42,7 @@
42 42
 #include "string.h"
43 43
 #include "io.h"
44 44
 #include "errno.h"
45
+#include <assert.h>
45 46
 #include "buffer.h"
46 47
 
47 48
 /**
@@ -208,7 +209,7 @@ int fill_buffer ( struct buffer *buffer, const void *data,
208 209
 	/* Write back 'before' block, if any */
209 210
 	if ( before.start ) {
210 211
 		before.tail = 0;
211
-		ASSERT ( ( before.end - before.start ) >=
212
+		assert ( ( before.end - before.start ) >=
212 213
 			 sizeof ( struct buffer_free_block ) );
213 214
 		store_free_block ( &before );
214 215
 	} else {
@@ -217,7 +218,7 @@ int fill_buffer ( struct buffer *buffer, const void *data,
217 218
 
218 219
 	/* Write back 'after' block, if any */
219 220
 	if ( after.start < buffer->end ) {
220
-		ASSERT ( after.tail ||
221
+		assert ( after.tail ||
221 222
 			 ( ( after.end - after.start ) >=
222 223
 			   sizeof ( struct buffer_free_block ) ) );
223 224
 		store_free_block ( &after );

+ 6
- 5
src/core/heap.c View File

@@ -1,6 +1,7 @@
1 1
 #include "etherboot.h"
2 2
 #include "init.h"
3 3
 #include "memsizes.h"
4
+#include <assert.h>
4 5
 #include "heap.h"
5 6
 
6 7
 struct heap_block {
@@ -76,7 +77,7 @@ static void init_heap ( void ) {
76 77
 		}
77 78
 	}
78 79
 
79
-	ASSERT ( size != 0 );
80
+	assert ( size != 0 );
80 81
 	DBG ( "HEAP using region [%x,%x)\n", heap_start, heap_end );
81 82
 	heap_ptr = heap_end;
82 83
 }
@@ -95,7 +96,7 @@ void * emalloc ( size_t size, unsigned int align ) {
95 96
 	struct heap_block *block;
96 97
 	physaddr_t addr;
97 98
 	
98
-	ASSERT ( ( align & ( align - 1 ) ) == 0 );
99
+	assert ( ( align & ( align - 1 ) ) == 0 );
99 100
 
100 101
 	addr = block_alloc_addr ( heap_ptr, size, align );
101 102
 	if ( addr < heap_start ) {
@@ -133,7 +134,7 @@ static inline physaddr_t block_free_addr ( size_t size ) {
133 134
 void efree ( void *ptr ) {
134 135
 	struct heap_block *block;
135 136
 
136
-	ASSERT ( ptr == phys_to_virt ( heap_ptr + sizeof ( size_t ) ) );
137
+	assert ( ptr == phys_to_virt ( heap_ptr + sizeof ( size_t ) ) );
137 138
 	
138 139
 	block = ( struct heap_block * )
139 140
 		( ptr - offsetof ( struct heap_block, data ) );
@@ -142,7 +143,7 @@ void efree ( void *ptr ) {
142 143
 	DBG ( "HEAP freed %x [%x,%x)\n", virt_to_phys ( ptr ),
143 144
 	      virt_to_phys ( block ), heap_ptr );
144 145
 
145
-	ASSERT ( heap_ptr <= heap_end );
146
+	assert ( heap_ptr <= heap_end );
146 147
 }
147 148
 
148 149
 /*
@@ -199,7 +200,7 @@ void * erealloc ( void *ptr, size_t size ) {
199 200
 	 * already checked that there was sufficient space.
200 201
 	 */
201 202
 	ptr = emalloc ( size, old_align );
202
-	ASSERT ( ptr != NULL );
203
+	assert ( ptr != NULL );
203 204
 
204 205
 	return ptr;
205 206
 }

+ 3
- 20
src/include/compiler.h View File

@@ -15,7 +15,7 @@
15 15
  * Global compiler definitions.
16 16
  *
17 17
  * This file is implicitly included by every @c .c file in Etherboot.
18
- * It defines global macros such as DBG() and ASSERT().
18
+ * It defines global macros such as DBG().
19 19
  *
20 20
  * We arrange for each object to export the symbol @c obj_OBJECT
21 21
  * (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 );
138 138
 #define DBG2 DBG_PRINT
139 139
 #endif
140 140
 
141
-/**
142
- * Assert a condition.
143
- *
144
- * If the condition is not true, a debug message will be printed.
145
- * Assertions only take effect if the debug level is non-zero (see
146
- * DBG()).
147
- *
148
- */
149
-#define ASSERT(x)
150
-
151
-#if DEBUG_SYMBOL >= 1
152
-#undef ASSERT
153
-#define ASSERT(x) 							      \
154
-	do { 								      \
155
-		if ( ! (x) ) { 						      \
156
-			DBG ( "ASSERT(%s) failed at %s line %d [%s]\n", #x,   \
157
-			      __FILE__, __LINE__, __FUNCTION__ );	      \
158
-		} 							      \
159
-	} while (0)
141
+#if DEBUG_SYMBOL == 0
142
+#define NDEBUG
160 143
 #endif
161 144
 
162 145
 /** Declare a data structure as packed. */

+ 3
- 8
src/include/dev.h View File

@@ -6,6 +6,7 @@
6 6
 #include "buffer.h"
7 7
 #include "dhcp.h" /* for dhcp_dev_id */
8 8
 #include "tables.h"
9
+#include <assert.h>
9 10
 
10 11
 /*
11 12
  * Forward declarations
@@ -100,17 +101,11 @@ struct bus_dev {
100 101
  *
101 102
  */
102 103
 
103
-#define LINKER_ASSERT(test,error_symbol)		\
104
-	if ( ! (test) ) {				\
105
-		extern void error_symbol ( void );	\
106
-		error_symbol();				\
107
-	}
108
-
109 104
 #define BUS_LOC_CHECK(datatype)					      \
110
-	LINKER_ASSERT( ( sizeof (datatype) <= sizeof (struct bus_loc) ),  \
105
+	linker_assert( ( sizeof (datatype) <= sizeof (struct bus_loc) ),  \
111 106
 		       __BUS_LOC_SIZE_is_too_small__see_dev_h )
112 107
 #define BUS_DEV_CHECK(datatype)					      \
113
-	LINKER_ASSERT( ( sizeof (datatype) <= sizeof (struct bus_dev) ),    \
108
+	linker_assert( ( sizeof (datatype) <= sizeof (struct bus_dev) ),    \
114 109
 		       __BUS_DEV_SIZE_is_too_small__see_dev_h )
115 110
 
116 111
 /*

Loading…
Cancel
Save