Browse Source

Added ASSERT() macro

tags/v0.9.3
Michael Brown 19 years ago
parent
commit
f0d048bf91
2 changed files with 19 additions and 4 deletions
  1. 2
    4
      src/core/heap.c
  2. 17
    0
      src/include/compiler.h

+ 2
- 4
src/core/heap.c View File

3
 #include "memsizes.h"
3
 #include "memsizes.h"
4
 #include "heap.h"
4
 #include "heap.h"
5
 
5
 
6
-#define ASSERT(...)
7
-
8
 struct heap_block {
6
 struct heap_block {
9
 	size_t size;
7
 	size_t size;
10
 	char data[0];
8
 	char data[0];
102
 	physaddr_t addr;
100
 	physaddr_t addr;
103
 	struct heap_block *block;
101
 	struct heap_block *block;
104
 	
102
 	
105
-	ASSERT ( ! ( align & ( align - 1 ) ) );
103
+	ASSERT ( ( align & ( align - 1 ) ) == 0 );
106
 	
104
 	
107
 	addr = ( ( ( heap_ptr - size ) & ~( align - 1 ) )
105
 	addr = ( ( ( heap_ptr - size ) & ~( align - 1 ) )
108
 		 - sizeof ( struct heap_block ) );
106
 		 - sizeof ( struct heap_block ) );
132
 void efree ( void *ptr ) {
130
 void efree ( void *ptr ) {
133
 	struct heap_block *block;
131
 	struct heap_block *block;
134
 
132
 
135
-	ASSERT ( ptr == ( heap_ptr + sizeof ( size_t ) ) );
133
+	ASSERT ( ptr == phys_to_virt ( heap_ptr + sizeof ( size_t ) ) );
136
 	
134
 	
137
 	block = ( struct heap_block * )
135
 	block = ( struct heap_block * )
138
 		( ptr - offsetof ( struct heap_block, data ) );
136
 		( ptr - offsetof ( struct heap_block, data ) );

+ 17
- 0
src/include/compiler.h View File

67
 #define DBG2 DBG_PRINT
67
 #define DBG2 DBG_PRINT
68
 #endif
68
 #endif
69
 
69
 
70
+/*
71
+ * ASSERT() macros
72
+ *
73
+ */
74
+#define ASSERT(x)
75
+
76
+#if DEBUG_SYMBOL >= 1
77
+#undef ASSERT
78
+#define ASSERT(x) 							      \
79
+	do { 								      \
80
+		if ( ! (x) ) { 						      \
81
+			DBG ( "ASSERT(%s) failed at %s line %d [%s]\n", #x,   \
82
+			      __FILE__, __LINE__, __FUNCTION__ );	      \
83
+		} 							      \
84
+	} while (0)
85
+#endif
86
+
70
 #define PACKED __attribute__((packed))
87
 #define PACKED __attribute__((packed))
71
 #define __unused __attribute__((unused))
88
 #define __unused __attribute__((unused))
72
 #define __used __attribute__((used))
89
 #define __used __attribute__((used))

Loading…
Cancel
Save