From 6e9aa9402a67bab563320fb0b37df242df15214c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Aug 2017 17:39:40 +0200 Subject: [PATCH] core: allow NULL argument to nm-ip-config's for-each macros Allow omitting the platform output argument. One can use the iterator to access the current entry. --- src/nm-ip4-config.h | 12 ++++-------- src/nm-ip6-config.h | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h index ab8fa51d4..4d42cee35 100644 --- a/src/nm-ip4-config.h +++ b/src/nm-ip4-config.h @@ -46,10 +46,8 @@ nm_ip_config_iter_ip4_address_next (NMDedupMultiIter *ipconf_iter, const NMPlatf { gboolean has_next; - g_return_val_if_fail (out_address, FALSE); - has_next = nm_dedup_multi_iter_next (ipconf_iter); - if (has_next) + if (has_next && out_address) *out_address = NMP_OBJECT_CAST_IP4_ADDRESS (ipconf_iter->current->obj); return has_next; } @@ -59,21 +57,19 @@ nm_ip_config_iter_ip4_route_next (NMDedupMultiIter *ipconf_iter, const NMPlatfor { gboolean has_next; - g_return_val_if_fail (out_route, FALSE); - has_next = nm_dedup_multi_iter_next (ipconf_iter); - if (has_next) + if (has_next && out_route) *out_route = NMP_OBJECT_CAST_IP4_ROUTE (ipconf_iter->current->obj); return has_next; } #define nm_ip_config_iter_ip4_address_for_each(iter, self, address) \ - for (*(address) = NULL, nm_ip_config_iter_ip4_address_init ((iter), (self)); \ + for (({ if (address) { *((const NMPlatformIP4Address **) (address)) = NULL; } }), nm_ip_config_iter_ip4_address_init ((iter), (self)); \ nm_ip_config_iter_ip4_address_next ((iter), (address)); \ ) #define nm_ip_config_iter_ip4_route_for_each(iter, self, route) \ - for (*(route) = NULL, nm_ip_config_iter_ip4_route_init ((iter), (self)); \ + for (({ if (route) { *((const NMPlatformIP4Route **) (route)) = NULL; } }), nm_ip_config_iter_ip4_route_init ((iter), (self)); \ nm_ip_config_iter_ip4_route_next ((iter), (route)); \ ) diff --git a/src/nm-ip6-config.h b/src/nm-ip6-config.h index eb2aae170..9f798041a 100644 --- a/src/nm-ip6-config.h +++ b/src/nm-ip6-config.h @@ -39,10 +39,8 @@ nm_ip_config_iter_ip6_address_next (NMDedupMultiIter *ipconf_iter, const NMPlatf { gboolean has_next; - g_return_val_if_fail (out_address, FALSE); - has_next = nm_dedup_multi_iter_next (ipconf_iter); - if (has_next) + if (has_next && out_address) *out_address = NMP_OBJECT_CAST_IP6_ADDRESS (ipconf_iter->current->obj); return has_next; } @@ -52,21 +50,19 @@ nm_ip_config_iter_ip6_route_next (NMDedupMultiIter *ipconf_iter, const NMPlatfor { gboolean has_next; - g_return_val_if_fail (out_route, FALSE); - has_next = nm_dedup_multi_iter_next (ipconf_iter); - if (has_next) + if (has_next && out_route) *out_route = NMP_OBJECT_CAST_IP6_ROUTE (ipconf_iter->current->obj); return has_next; } #define nm_ip_config_iter_ip6_address_for_each(iter, self, address) \ - for (*(address) = NULL, nm_ip_config_iter_ip6_address_init ((iter), (self)); \ + for (({ if (address) { *(((const NMPlatformIP6Address **) address)) = NULL; } }), nm_ip_config_iter_ip6_address_init ((iter), (self)); \ nm_ip_config_iter_ip6_address_next ((iter), (address)); \ ) #define nm_ip_config_iter_ip6_route_for_each(iter, self, route) \ - for (*(route) = NULL, nm_ip_config_iter_ip6_route_init ((iter), (self)); \ + for (({ if (route) { *((const NMPlatformIP6Route **) (route)) = NULL; } }), nm_ip_config_iter_ip6_route_init ((iter), (self)); \ nm_ip_config_iter_ip6_route_next ((iter), (route)); \ )