* nih/list.h (NIH_LIST_FOREACH_SAFE): Mark the cursor to be
automatically cleaned up should we exit the loop; this somewhat
simplifies the definition and allows returning from within the loop.
diff --git a/ChangeLog b/ChangeLog
index 4d56183..78b0385 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2008-10-24 Scott James Remnant <scott@netsplit.com>
+ * nih/list.h (NIH_LIST_FOREACH_SAFE): Mark the cursor to be
+ automatically cleaned up should we exit the loop; this somewhat
+ simplifies the definition and allows returning from within the loop.
+
* nih/list.h (NIH_LIST_FOREACH_SAFE): Fix a typo that caused only
once cursor variable to be used, rather than one per iteration.
diff --git a/nih/list.h b/nih/list.h
index 57a2fa4..71f4abc 100644
--- a/nih/list.h
+++ b/nih/list.h
@@ -106,13 +106,11 @@
* would be placed before the cursor and thus skipped.
**/
#define NIH_LIST_FOREACH_SAFE(list, iter) \
- for (NihList _##iter##_cursor = { &_##iter##_cursor, &_##iter##_cursor }, \
- *_##iter = &_##iter##_cursor; \
- _##iter; \
- nih_list_destroy (_##iter), _##iter = NULL) \
- for (NihList *iter = nih_list_add_after ((list)->next, _##iter)->prev; \
- iter != (list) && iter != _##iter; \
- iter = nih_list_add_after (_##iter->next, _##iter)->prev)
+ for (NihList _##iter __attribute__((cleanup(nih_list_destroy))) = \
+ { &_##iter, &_##iter }, \
+ *iter = nih_list_add_after ((list)->next, &_##iter)->prev; \
+ iter != (list) && iter != &_##iter; \
+ iter = nih_list_add_after (_##iter.next, &_##iter)->prev)
NIH_BEGIN_EXTERN