소스 검색

Added ASSERT() macro

tags/v0.9.3
Michael Brown 19 년 전
부모
커밋
f0d048bf91
2개의 변경된 파일19개의 추가작업 그리고 4개의 파일을 삭제
  1. 2
    4
      src/core/heap.c
  2. 17
    0
      src/include/compiler.h

+ 2
- 4
src/core/heap.c 파일 보기

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

+ 17
- 0
src/include/compiler.h 파일 보기

@@ -67,6 +67,23 @@ __asm__ ( ".equ\tDEBUG_LEVEL, " DEBUG_SYMBOL_STR );
67 67
 #define DBG2 DBG_PRINT
68 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 87
 #define PACKED __attribute__((packed))
71 88
 #define __unused __attribute__((unused))
72 89
 #define __used __attribute__((used))

Loading…
취소
저장