From 2c56ede6f80127b1a352f4bafc94821fa98f127e Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 17 Sep 2007 18:38:04 +0100 Subject: [PATCH] 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. --- src/include/gpxe/iobuf.h | 28 ++++++++++++++++++++++++---- src/include/gpxe/list.h | 18 ++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/include/gpxe/iobuf.h b/src/include/gpxe/iobuf.h index e3db01ac..ff787754 100644 --- a/src/include/gpxe/iobuf.h +++ b/src/include/gpxe/iobuf.h @@ -67,9 +67,13 @@ struct io_buffer { static inline void * iob_reserve ( struct io_buffer *iobuf, size_t len ) { iobuf->data += len; iobuf->tail += len; - assert ( iobuf->tail <= iobuf->end ); return iobuf->data; } +#define iob_reserve( iobuf, len ) ( { \ + void *__result; \ + __result = iob_reserve ( (iobuf), (len) ); \ + assert ( (iobuf)->tail <= (iobuf)->end ); \ + __result; } ) /** * Add data to start of I/O buffer @@ -80,9 +84,13 @@ static inline void * iob_reserve ( struct io_buffer *iobuf, size_t len ) { */ static inline void * iob_push ( struct io_buffer *iobuf, size_t len ) { iobuf->data -= len; - assert ( iobuf->data >= iobuf->head ); return iobuf->data; } +#define iob_push( iobuf, len ) ( { \ + void *__result; \ + __result = iob_push ( (iobuf), (len) ); \ + assert ( (iobuf)->data >= (iobuf)->head ); \ + __result; } ) /** * Remove data from start of I/O buffer @@ -96,6 +104,11 @@ static inline void * iob_pull ( struct io_buffer *iobuf, size_t len ) { assert ( iobuf->data <= iobuf->tail ); return iobuf->data; } +#define iob_pull( iobuf, len ) ( { \ + void *__result; \ + __result = iob_pull ( (iobuf), (len) ); \ + assert ( (iobuf)->data <= (iobuf)->tail ); \ + __result; } ) /** * Add data to end of I/O buffer @@ -107,9 +120,13 @@ static inline void * iob_pull ( struct io_buffer *iobuf, size_t len ) { static inline void * iob_put ( struct io_buffer *iobuf, size_t len ) { void *old_tail = iobuf->tail; iobuf->tail += len; - assert ( iobuf->tail <= iobuf->end ); return old_tail; } +#define iob_put( iobuf, len ) ( { \ + void *__result; \ + __result = iob_put ( (iobuf), (len) ); \ + assert ( (iobuf)->tail <= (iobuf)->end ); \ + __result; } ) /** * Remove data from end of I/O buffer @@ -119,8 +136,11 @@ static inline void * iob_put ( struct io_buffer *iobuf, size_t len ) { */ static inline void iob_unput ( struct io_buffer *iobuf, size_t len ) { iobuf->tail -= len; - assert ( iobuf->tail >= iobuf->data ); } +#define iob_unput( iobuf, len ) do { \ + iob_unput ( (iobuf), (len) ); \ + assert ( (iobuf)->tail >= (iobuf)->data ); \ + } while ( 0 ) /** * Empty an I/O buffer diff --git a/src/include/gpxe/list.h b/src/include/gpxe/list.h index 0e65901c..602382be 100644 --- a/src/include/gpxe/list.h +++ b/src/include/gpxe/list.h @@ -10,6 +10,7 @@ */ #include +#include /* * Simple doubly linked list implementation. @@ -62,6 +63,11 @@ static inline void __list_add ( struct list_head *new, static inline void list_add ( struct list_head *new, struct list_head *head ) { __list_add ( new, head, head->next ); } +#define list_add( new, head ) do { \ + assert ( (head)->next->prev == (head) ); \ + assert ( (head)->prev->next == (head) ); \ + list_add ( (new), (head) ); \ + } while ( 0 ) /** * Add a new entry to the tail of a list @@ -76,6 +82,11 @@ static inline void list_add_tail ( struct list_head *new, struct list_head *head ) { __list_add ( new, head->prev, head ); } +#define list_add_tail( new, head ) do { \ + assert ( (head)->next->prev == (head) ); \ + assert ( (head)->prev->next == (head) ); \ + list_add_tail ( (new), (head) ); \ + } while ( 0 ) /* * Delete a list entry by making the prev/next entries @@ -101,6 +112,13 @@ static inline void __list_del ( struct list_head * prev, static inline void list_del ( struct list_head *entry ) { __list_del ( entry->prev, entry->next ); } +#define list_del( entry ) do { \ + assert ( (entry)->prev != NULL ); \ + assert ( (entry)->next != NULL ); \ + assert ( (entry)->next->prev == (entry) ); \ + assert ( (entry)->prev->next == (entry) ); \ + list_del ( (entry) ); \ + } while ( 0 ) /** * Test whether a list is empty