浏览代码

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 年前
父节点
当前提交
2c56ede6f8
共有 2 个文件被更改,包括 42 次插入4 次删除
  1. 24
    4
      src/include/gpxe/iobuf.h
  2. 18
    0
      src/include/gpxe/list.h

+ 24
- 4
src/include/gpxe/iobuf.h 查看文件

67
 static inline void * iob_reserve ( struct io_buffer *iobuf, size_t len ) {
67
 static inline void * iob_reserve ( struct io_buffer *iobuf, size_t len ) {
68
 	iobuf->data += len;
68
 	iobuf->data += len;
69
 	iobuf->tail += len;
69
 	iobuf->tail += len;
70
-	assert ( iobuf->tail <= iobuf->end );
71
 	return iobuf->data;
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
  * Add data to start of I/O buffer
79
  * Add data to start of I/O buffer
80
  */
84
  */
81
 static inline void * iob_push ( struct io_buffer *iobuf, size_t len ) {
85
 static inline void * iob_push ( struct io_buffer *iobuf, size_t len ) {
82
 	iobuf->data -= len;
86
 	iobuf->data -= len;
83
-	assert ( iobuf->data >= iobuf->head );
84
 	return iobuf->data;
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
  * Remove data from start of I/O buffer
96
  * Remove data from start of I/O buffer
96
 	assert ( iobuf->data <= iobuf->tail );
104
 	assert ( iobuf->data <= iobuf->tail );
97
 	return iobuf->data;
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
  * Add data to end of I/O buffer
114
  * Add data to end of I/O buffer
107
 static inline void * iob_put ( struct io_buffer *iobuf, size_t len ) {
120
 static inline void * iob_put ( struct io_buffer *iobuf, size_t len ) {
108
 	void *old_tail = iobuf->tail;
121
 	void *old_tail = iobuf->tail;
109
 	iobuf->tail += len;
122
 	iobuf->tail += len;
110
-	assert ( iobuf->tail <= iobuf->end );
111
 	return old_tail;
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
  * Remove data from end of I/O buffer
132
  * Remove data from end of I/O buffer
119
  */
136
  */
120
 static inline void iob_unput ( struct io_buffer *iobuf, size_t len ) {
137
 static inline void iob_unput ( struct io_buffer *iobuf, size_t len ) {
121
 	iobuf->tail -= len;
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
  * Empty an I/O buffer
146
  * Empty an I/O buffer

+ 18
- 0
src/include/gpxe/list.h 查看文件

10
  */
10
  */
11
 
11
 
12
 #include <stddef.h>
12
 #include <stddef.h>
13
+#include <assert.h>
13
 
14
 
14
 /*
15
 /*
15
  * Simple doubly linked list implementation.
16
  * Simple doubly linked list implementation.
62
 static inline void list_add ( struct list_head *new, struct list_head *head ) {
63
 static inline void list_add ( struct list_head *new, struct list_head *head ) {
63
 	__list_add ( new, head, head->next );
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
  * Add a new entry to the tail of a list
73
  * Add a new entry to the tail of a list
76
 				   struct list_head *head ) {
82
 				   struct list_head *head ) {
77
 	__list_add ( new, head->prev, head );
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
  * Delete a list entry by making the prev/next entries
92
  * Delete a list entry by making the prev/next entries
101
 static inline void list_del ( struct list_head *entry ) {
112
 static inline void list_del ( struct list_head *entry ) {
102
 	__list_del ( entry->prev, entry->next );
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
  * Test whether a list is empty
124
  * Test whether a list is empty

正在加载...
取消
保存