Browse Source

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

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

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

1
 #include "etherboot.h"
1
 #include "etherboot.h"
2
 #include "init.h"
2
 #include "init.h"
3
 #include "memsizes.h"
3
 #include "memsizes.h"
4
+#include <assert.h>
4
 #include "heap.h"
5
 #include "heap.h"
5
 
6
 
6
 struct heap_block {
7
 struct heap_block {
76
 		}
77
 		}
77
 	}
78
 	}
78
 
79
 
79
-	ASSERT ( size != 0 );
80
+	assert ( size != 0 );
80
 	DBG ( "HEAP using region [%x,%x)\n", heap_start, heap_end );
81
 	DBG ( "HEAP using region [%x,%x)\n", heap_start, heap_end );
81
 	heap_ptr = heap_end;
82
 	heap_ptr = heap_end;
82
 }
83
 }
95
 	struct heap_block *block;
96
 	struct heap_block *block;
96
 	physaddr_t addr;
97
 	physaddr_t addr;
97
 	
98
 	
98
-	ASSERT ( ( align & ( align - 1 ) ) == 0 );
99
+	assert ( ( align & ( align - 1 ) ) == 0 );
99
 
100
 
100
 	addr = block_alloc_addr ( heap_ptr, size, align );
101
 	addr = block_alloc_addr ( heap_ptr, size, align );
101
 	if ( addr < heap_start ) {
102
 	if ( addr < heap_start ) {
133
 void efree ( void *ptr ) {
134
 void efree ( void *ptr ) {
134
 	struct heap_block *block;
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
 	block = ( struct heap_block * )
139
 	block = ( struct heap_block * )
139
 		( ptr - offsetof ( struct heap_block, data ) );
140
 		( ptr - offsetof ( struct heap_block, data ) );
142
 	DBG ( "HEAP freed %x [%x,%x)\n", virt_to_phys ( ptr ),
143
 	DBG ( "HEAP freed %x [%x,%x)\n", virt_to_phys ( ptr ),
143
 	      virt_to_phys ( block ), heap_ptr );
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
 	 * already checked that there was sufficient space.
200
 	 * already checked that there was sufficient space.
200
 	 */
201
 	 */
201
 	ptr = emalloc ( size, old_align );
202
 	ptr = emalloc ( size, old_align );
202
-	ASSERT ( ptr != NULL );
203
+	assert ( ptr != NULL );
203
 
204
 
204
 	return ptr;
205
 	return ptr;
205
 }
206
 }

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

15
  * Global compiler definitions.
15
  * Global compiler definitions.
16
  *
16
  *
17
  * This file is implicitly included by every @c .c file in Etherboot.
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
  * We arrange for each object to export the symbol @c obj_OBJECT
20
  * We arrange for each object to export the symbol @c obj_OBJECT
21
  * (where @c OBJECT is the object name, e.g. @c rtl8139) as a global
21
  * (where @c OBJECT is the object name, e.g. @c rtl8139) as a global
138
 #define DBG2 DBG_PRINT
138
 #define DBG2 DBG_PRINT
139
 #endif
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
 #endif
143
 #endif
161
 
144
 
162
 /** Declare a data structure as packed. */
145
 /** Declare a data structure as packed. */

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

6
 #include "buffer.h"
6
 #include "buffer.h"
7
 #include "dhcp.h" /* for dhcp_dev_id */
7
 #include "dhcp.h" /* for dhcp_dev_id */
8
 #include "tables.h"
8
 #include "tables.h"
9
+#include <assert.h>
9
 
10
 
10
 /*
11
 /*
11
  * Forward declarations
12
  * Forward declarations
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
 #define BUS_LOC_CHECK(datatype)					      \
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
 		       __BUS_LOC_SIZE_is_too_small__see_dev_h )
106
 		       __BUS_LOC_SIZE_is_too_small__see_dev_h )
112
 #define BUS_DEV_CHECK(datatype)					      \
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
 		       __BUS_DEV_SIZE_is_too_small__see_dev_h )
109
 		       __BUS_DEV_SIZE_is_too_small__see_dev_h )
115
 
110
 
116
 /*
111
 /*

Loading…
Cancel
Save