Browse Source

Moved iobuf.h assertions outside the static inline functions, so that

the assert message's file and line number gives some clue as to the
real location of the problem.

Added similar assertions to list.h.
tags/v0.9.3
Michael Brown 17 years ago
parent
commit
2c56ede6f8
2 changed files with 42 additions and 4 deletions
  1. 24
    4
      src/include/gpxe/iobuf.h
  2. 18
    0
      src/include/gpxe/list.h

+ 24
- 4
src/include/gpxe/iobuf.h View File

@@ -67,9 +67,13 @@ struct io_buffer {
67 67
 static inline void * iob_reserve ( struct io_buffer *iobuf, size_t len ) {
68 68
 	iobuf->data += len;
69 69
 	iobuf->tail += len;
70
-	assert ( iobuf->tail <= iobuf->end );
71 70
 	return iobuf->data;
72 71
 }
72
+#define iob_reserve( iobuf, len ) ( {			\
73
+	void *__result;					\
74
+	__result = iob_reserve ( (iobuf), (len) );	\
75
+	assert ( (iobuf)->tail <= (iobuf)->end );	\
76
+	__result; } )
73 77
 
74 78
 /**
75 79
  * Add data to start of I/O buffer
@@ -80,9 +84,13 @@ static inline void * iob_reserve ( struct io_buffer *iobuf, size_t len ) {
80 84
  */
81 85
 static inline void * iob_push ( struct io_buffer *iobuf, size_t len ) {
82 86
 	iobuf->data -= len;
83
-	assert ( iobuf->data >= iobuf->head );
84 87
 	return iobuf->data;
85 88
 }
89
+#define iob_push( iobuf, len ) ( {			\
90
+	void *__result;					\
91
+	__result = iob_push ( (iobuf), (len) );		\
92
+	assert ( (iobuf)->data >= (iobuf)->head );	\
93
+	__result; } )
86 94
 
87 95
 /**
88 96
  * Remove data from start of I/O buffer
@@ -96,6 +104,11 @@ static inline void * iob_pull ( struct io_buffer *iobuf, size_t len ) {
96 104
 	assert ( iobuf->data <= iobuf->tail );
97 105
 	return iobuf->data;
98 106
 }
107
+#define iob_pull( iobuf, len ) ( {			\
108
+	void *__result;					\
109
+	__result = iob_pull ( (iobuf), (len) );		\
110
+	assert ( (iobuf)->data <= (iobuf)->tail );	\
111
+	__result; } )
99 112
 
100 113
 /**
101 114
  * Add data to end of I/O buffer
@@ -107,9 +120,13 @@ static inline void * iob_pull ( struct io_buffer *iobuf, size_t len ) {
107 120
 static inline void * iob_put ( struct io_buffer *iobuf, size_t len ) {
108 121
 	void *old_tail = iobuf->tail;
109 122
 	iobuf->tail += len;
110
-	assert ( iobuf->tail <= iobuf->end );
111 123
 	return old_tail;
112 124
 }
125
+#define iob_put( iobuf, len ) ( {			\
126
+	void *__result;					\
127
+	__result = iob_put ( (iobuf), (len) );		\
128
+	assert ( (iobuf)->tail <= (iobuf)->end );	\
129
+	__result; } )
113 130
 
114 131
 /**
115 132
  * Remove data from end of I/O buffer
@@ -119,8 +136,11 @@ static inline void * iob_put ( struct io_buffer *iobuf, size_t len ) {
119 136
  */
120 137
 static inline void iob_unput ( struct io_buffer *iobuf, size_t len ) {
121 138
 	iobuf->tail -= len;
122
-	assert ( iobuf->tail >= iobuf->data );
123 139
 }
140
+#define iob_unput( iobuf, len ) do {			\
141
+	iob_unput ( (iobuf), (len) );			\
142
+	assert ( (iobuf)->tail >= (iobuf)->data );	\
143
+	} while ( 0 )
124 144
 
125 145
 /**
126 146
  * Empty an I/O buffer

+ 18
- 0
src/include/gpxe/list.h View File

@@ -10,6 +10,7 @@
10 10
  */
11 11
 
12 12
 #include <stddef.h>
13
+#include <assert.h>
13 14
 
14 15
 /*
15 16
  * Simple doubly linked list implementation.
@@ -62,6 +63,11 @@ static inline void __list_add ( struct list_head *new,
62 63
 static inline void list_add ( struct list_head *new, struct list_head *head ) {
63 64
 	__list_add ( new, head, head->next );
64 65
 }
66
+#define list_add( new, head ) do {			\
67
+	assert ( (head)->next->prev == (head) );	\
68
+	assert ( (head)->prev->next == (head) );	\
69
+	list_add ( (new), (head) );			\
70
+	} while ( 0 )
65 71
 
66 72
 /**
67 73
  * Add a new entry to the tail of a list
@@ -76,6 +82,11 @@ static inline void list_add_tail ( struct list_head *new,
76 82
 				   struct list_head *head ) {
77 83
 	__list_add ( new, head->prev, head );
78 84
 }
85
+#define list_add_tail( new, head ) do {			\
86
+	assert ( (head)->next->prev == (head) );	\
87
+	assert ( (head)->prev->next == (head) );	\
88
+	list_add_tail ( (new), (head) );		\
89
+	} while ( 0 )
79 90
 
80 91
 /*
81 92
  * Delete a list entry by making the prev/next entries
@@ -101,6 +112,13 @@ static inline void __list_del ( struct list_head * prev,
101 112
 static inline void list_del ( struct list_head *entry ) {
102 113
 	__list_del ( entry->prev, entry->next );
103 114
 }
115
+#define list_del( entry ) do {				\
116
+	assert ( (entry)->prev != NULL );		\
117
+	assert ( (entry)->next != NULL );		\
118
+	assert ( (entry)->next->prev == (entry) );	\
119
+	assert ( (entry)->prev->next == (entry) );	\
120
+	list_del ( (entry) );				\
121
+	} while ( 0 )
104 122
 
105 123
 /**
106 124
  * Test whether a list is empty

Loading…
Cancel
Save