summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-08-23 16:00:11 +0200
committerThomas Haller <thaller@redhat.com>2017-08-23 18:37:21 +0200
commit2f693fb68c0b71cc77e7a722c5d3b8bebea01e35 (patch)
tree964c79c7a951cece6663b8edc99ee979494b5b93
parent3fc501e83320c3e6ddc1826ea1ef37289a644ccd (diff)
downloadNetworkManager-2f693fb68c0b71cc77e7a722c5d3b8bebea01e35.tar.gz
shared: return deleted object from nm_dedup_multi_index_remove_obj()
For completeness of the API. remove_obj() is basically a shortcut of nm_dedup_multi_index_lookup_obj() combined with nm_dedup_multi_index_remove_entry(). As such, it is useful to return the actually deleted object. Note that the lookup needle @obj is not necessarily the same instance as the one that will be removed, it's only an instance that compares equal according to the index's equality operator.
-rw-r--r--shared/nm-utils/nm-dedup-multi.c13
-rw-r--r--shared/nm-utils/nm-dedup-multi.h3
-rw-r--r--src/nm-ip4-config.c12
-rw-r--r--src/nm-ip6-config.c12
4 files changed, 29 insertions, 11 deletions
diff --git a/shared/nm-utils/nm-dedup-multi.c b/shared/nm-utils/nm-dedup-multi.c
index 8942ba36fb..383e40fd72 100644
--- a/shared/nm-utils/nm-dedup-multi.c
+++ b/shared/nm-utils/nm-dedup-multi.c
@@ -626,13 +626,22 @@ nm_dedup_multi_index_remove_entry (NMDedupMultiIndex *self,
guint
nm_dedup_multi_index_remove_obj (NMDedupMultiIndex *self,
NMDedupMultiIdxType *idx_type,
- /*const NMDedupMultiObj * */ gconstpointer obj)
+ /*const NMDedupMultiObj * */ gconstpointer obj,
+ /*const NMDedupMultiObj ** */ gconstpointer *out_obj)
{
const NMDedupMultiEntry *entry;
entry = nm_dedup_multi_index_lookup_obj (self, idx_type, obj);
- if (!entry)
+ if (!entry) {
+ NM_SET_OUT (out_obj, NULL);
return 0;
+ }
+
+ /* since we are about to remove the object, we obviously pass
+ * a reference to @out_obj, the caller MUST unref the object,
+ * if he chooses to provide @out_obj. */
+ NM_SET_OUT (out_obj, nm_dedup_multi_obj_ref (entry->obj));
+
_remove_entry (self, (NMDedupMultiEntry *) entry, NULL);
return 1;
}
diff --git a/shared/nm-utils/nm-dedup-multi.h b/shared/nm-utils/nm-dedup-multi.h
index b6cfc43209..c99d6d11e1 100644
--- a/shared/nm-utils/nm-dedup-multi.h
+++ b/shared/nm-utils/nm-dedup-multi.h
@@ -291,7 +291,8 @@ guint nm_dedup_multi_index_remove_entry (NMDedupMultiIndex *self,
guint nm_dedup_multi_index_remove_obj (NMDedupMultiIndex *self,
NMDedupMultiIdxType *idx_type,
- /*const NMDedupMultiObj * */ gconstpointer obj);
+ /*const NMDedupMultiObj * */ gconstpointer obj,
+ /*const NMDedupMultiObj ** */ gconstpointer *out_obj);
guint nm_dedup_multi_index_remove_head (NMDedupMultiIndex *self,
NMDedupMultiIdxType *idx_type,
diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c
index b47f478fb9..5e4cd7f59d 100644
--- a/src/nm-ip4-config.c
+++ b/src/nm-ip4-config.c
@@ -1228,7 +1228,8 @@ nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src)
nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, src, &a) {
if (nm_dedup_multi_index_remove_obj (priv_dst->multi_idx,
&priv_dst->idx_ip4_addresses,
- NMP_OBJECT_UP_CAST (a)))
+ NMP_OBJECT_UP_CAST (a),
+ NULL))
changed = TRUE;
}
if (changed)
@@ -1256,7 +1257,8 @@ nm_ip4_config_subtract (NMIP4Config *dst, const NMIP4Config *src)
nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, src, &r) {
if (nm_dedup_multi_index_remove_obj (priv_dst->multi_idx,
&priv_dst->idx_ip4_routes,
- NMP_OBJECT_UP_CAST (r)))
+ NMP_OBJECT_UP_CAST (r),
+ NULL))
changed = TRUE;
}
if (changed)
@@ -1921,7 +1923,8 @@ _nmtst_nm_ip4_config_del_address (NMIP4Config *self, guint i)
if (nm_dedup_multi_index_remove_obj (priv->multi_idx,
&priv->idx_ip4_addresses,
- NMP_OBJECT_UP_CAST (a)) != 1)
+ NMP_OBJECT_UP_CAST (a),
+ NULL) != 1)
g_return_if_reached ();
_notify_addresses (self);
}
@@ -2040,7 +2043,8 @@ _nmtst_nm_ip4_config_del_route (NMIP4Config *self, guint i)
if (nm_dedup_multi_index_remove_obj (priv->multi_idx,
&priv->idx_ip4_routes,
- NMP_OBJECT_UP_CAST (r)) != 1)
+ NMP_OBJECT_UP_CAST (r),
+ NULL) != 1)
g_return_if_reached ();
_notify_routes (self);
}
diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c
index dc45acc18d..a3d958a616 100644
--- a/src/nm-ip6-config.c
+++ b/src/nm-ip6-config.c
@@ -1025,7 +1025,8 @@ nm_ip6_config_subtract (NMIP6Config *dst, const NMIP6Config *src)
nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, src, &a) {
if (nm_dedup_multi_index_remove_obj (priv_dst->multi_idx,
&priv_dst->idx_ip6_addresses,
- NMP_OBJECT_UP_CAST (a)))
+ NMP_OBJECT_UP_CAST (a),
+ NULL))
changed = TRUE;
}
if (changed)
@@ -1054,7 +1055,8 @@ nm_ip6_config_subtract (NMIP6Config *dst, const NMIP6Config *src)
nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, src, &r) {
if (nm_dedup_multi_index_remove_obj (priv_dst->multi_idx,
&priv_dst->idx_ip6_routes,
- NMP_OBJECT_UP_CAST (r)))
+ NMP_OBJECT_UP_CAST (r),
+ NULL))
changed = TRUE;
}
if (changed)
@@ -1586,7 +1588,8 @@ _nmtst_nm_ip6_config_del_address (NMIP6Config *self, guint i)
if (nm_dedup_multi_index_remove_obj (priv->multi_idx,
&priv->idx_ip6_addresses,
- NMP_OBJECT_UP_CAST (a)) != 1)
+ NMP_OBJECT_UP_CAST (a),
+ NULL) != 1)
g_return_if_reached ();
_notify_addresses (self);
}
@@ -1763,7 +1766,8 @@ _nmtst_ip6_config_del_route (NMIP6Config *self, guint i)
if (nm_dedup_multi_index_remove_obj (priv->multi_idx,
&priv->idx_ip6_routes,
- NMP_OBJECT_UP_CAST (r)) != 1)
+ NMP_OBJECT_UP_CAST (r),
+ NULL) != 1)
g_return_if_reached ();
_notify_routes (self);
}