diff options
author | Thomas Haller <thaller@redhat.com> | 2017-08-30 17:39:40 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-08-30 18:59:36 +0200 |
commit | 6e9aa9402a67bab563320fb0b37df242df15214c (patch) | |
tree | cca614812afc61474f691e01ab169f22a0467f47 | |
parent | abcc74e0b52cb080e5fa23b9113b017217015428 (diff) | |
download | NetworkManager-6e9aa9402a67bab563320fb0b37df242df15214c.tar.gz |
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.
-rw-r--r-- | src/nm-ip4-config.h | 12 | ||||
-rw-r--r-- | 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 ab8fa51d4d..4d42cee35a 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 eb2aae170d..9f798041a4 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)); \ ) |