summaryrefslogtreecommitdiff
path: root/libnm
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-08-25 10:33:53 -0400
committerDan Winship <danw@gnome.org>2014-09-04 09:21:05 -0400
commit3e5b3833aa4964f6d2224560f3ad8c7ffa1e8027 (patch)
tree411d50040fa8997bcd912e1f4eebd83c364a0e4a /libnm
parent074c2093b6a733c3d5712a7c58386e1e652a8903 (diff)
downloadNetworkManager-3e5b3833aa4964f6d2224560f3ad8c7ffa1e8027.tar.gz
libnm: change empty-GPtrArray-return semantics
libnm functions that return GPtrArrays of objects had a rule that if the array was empty, they would return NULL rather than a 0-length array. As it turns out, this is just a nuisance to clients, since in most places the code for the non-empty case would end up doing the right thing for the empty case as well (and where it doesn't, we can check "array->len == 0" just as easily as "array == NULL"). So just return the 0-length array instead.
Diffstat (limited to 'libnm')
-rw-r--r--libnm/nm-active-connection.c2
-rw-r--r--libnm/nm-client.c6
-rw-r--r--libnm/nm-device-bond.c2
-rw-r--r--libnm/nm-device-bridge.c2
-rw-r--r--libnm/nm-device-team.c2
-rw-r--r--libnm/nm-device-wifi.c2
-rw-r--r--libnm/nm-device-wimax.c2
-rw-r--r--libnm/nm-device.c2
-rw-r--r--libnm/nm-object-private.h9
-rw-r--r--libnm/tests/test-nm-client.c6
10 files changed, 13 insertions, 22 deletions
diff --git a/libnm/nm-active-connection.c b/libnm/nm-active-connection.c
index 659b820d82..7088e496a4 100644
--- a/libnm/nm-active-connection.c
+++ b/libnm/nm-active-connection.c
@@ -284,7 +284,7 @@ nm_active_connection_get_devices (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
- return handle_ptr_array_return (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->devices);
+ return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->devices;
}
/**
diff --git a/libnm/nm-client.c b/libnm/nm-client.c
index fdbaed38b7..70c9c813ab 100644
--- a/libnm/nm-client.c
+++ b/libnm/nm-client.c
@@ -380,7 +380,7 @@ nm_client_get_devices (NMClient *client)
{
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
- return handle_ptr_array_return (NM_CLIENT_GET_PRIVATE (client)->devices);
+ return NM_CLIENT_GET_PRIVATE (client)->devices;
}
/**
@@ -522,7 +522,7 @@ recheck_pending_activations (NMClient *self, const char *failed_path, GError *er
ainfo = info;
}
- for (i = 0; active_connections && i < active_connections->len; i++) {
+ for (i = 0; i < active_connections->len; i++) {
NMActiveConnection *active = g_ptr_array_index (active_connections, i);
const char *active_path = nm_object_get_path (NM_OBJECT (active));
@@ -803,7 +803,7 @@ nm_client_get_active_connections (NMClient *client)
if (!nm_client_get_nm_running (client))
return NULL;
- return handle_ptr_array_return (priv->active_connections);
+ return priv->active_connections;
}
/**
diff --git a/libnm/nm-device-bond.c b/libnm/nm-device-bond.c
index d0a3e94a82..e378c9cc31 100644
--- a/libnm/nm-device-bond.c
+++ b/libnm/nm-device-bond.c
@@ -118,7 +118,7 @@ nm_device_bond_get_slaves (NMDeviceBond *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BOND (device), FALSE);
- return handle_ptr_array_return (NM_DEVICE_BOND_GET_PRIVATE (device)->slaves);
+ return NM_DEVICE_BOND_GET_PRIVATE (device)->slaves;
}
static gboolean
diff --git a/libnm/nm-device-bridge.c b/libnm/nm-device-bridge.c
index 1a17196656..cb9cb2ad46 100644
--- a/libnm/nm-device-bridge.c
+++ b/libnm/nm-device-bridge.c
@@ -118,7 +118,7 @@ nm_device_bridge_get_slaves (NMDeviceBridge *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), FALSE);
- return handle_ptr_array_return (NM_DEVICE_BRIDGE_GET_PRIVATE (device)->slaves);
+ return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->slaves;
}
static gboolean
diff --git a/libnm/nm-device-team.c b/libnm/nm-device-team.c
index 0aeda17039..27deda8a5a 100644
--- a/libnm/nm-device-team.c
+++ b/libnm/nm-device-team.c
@@ -118,7 +118,7 @@ nm_device_team_get_slaves (NMDeviceTeam *device)
{
g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), FALSE);
- return handle_ptr_array_return (NM_DEVICE_TEAM_GET_PRIVATE (device)->slaves);
+ return NM_DEVICE_TEAM_GET_PRIVATE (device)->slaves;
}
static const char *
diff --git a/libnm/nm-device-wifi.c b/libnm/nm-device-wifi.c
index 6a41ccc218..7252672f2d 100644
--- a/libnm/nm-device-wifi.c
+++ b/libnm/nm-device-wifi.c
@@ -247,7 +247,7 @@ nm_device_wifi_get_access_points (NMDeviceWifi *device)
{
g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL);
- return handle_ptr_array_return (NM_DEVICE_WIFI_GET_PRIVATE (device)->aps);
+ return NM_DEVICE_WIFI_GET_PRIVATE (device)->aps;
}
/**
diff --git a/libnm/nm-device-wimax.c b/libnm/nm-device-wimax.c
index 5f190ea3f0..fc5793acb2 100644
--- a/libnm/nm-device-wimax.c
+++ b/libnm/nm-device-wimax.c
@@ -161,7 +161,7 @@ nm_device_wimax_get_nsps (NMDeviceWimax *wimax)
{
g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL);
- return handle_ptr_array_return (NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->nsps);
+ return NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->nsps;
}
/**
diff --git a/libnm/nm-device.c b/libnm/nm-device.c
index 3e67f09472..1eff7386d6 100644
--- a/libnm/nm-device.c
+++ b/libnm/nm-device.c
@@ -1364,7 +1364,7 @@ nm_device_get_available_connections (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
- return handle_ptr_array_return (NM_DEVICE_GET_PRIVATE (device)->available_connections);
+ return NM_DEVICE_GET_PRIVATE (device)->available_connections;
}
static char *
diff --git a/libnm/nm-object-private.h b/libnm/nm-object-private.h
index 4422883f8d..78764c8611 100644
--- a/libnm/nm-object-private.h
+++ b/libnm/nm-object-private.h
@@ -70,15 +70,6 @@ void _nm_object_set_property (NMObject *object,
const char *prop_name,
GValue *value);
-static inline const GPtrArray *
-handle_ptr_array_return (GPtrArray *array)
-{
- /* zero-length is special-case; return NULL */
- if (!array || !array->len)
- return NULL;
- return array;
-}
-
/* object demarshalling support */
typedef GType (*NMObjectTypeFunc) (DBusGConnection *, const char *);
typedef void (*NMObjectTypeCallbackFunc) (GType, gpointer);
diff --git a/libnm/tests/test-nm-client.c b/libnm/tests/test-nm-client.c
index 5f0bcbffbf..5bf11e4aa7 100644
--- a/libnm/tests/test-nm-client.c
+++ b/libnm/tests/test-nm-client.c
@@ -156,7 +156,7 @@ test_device_added (void)
client = test_client_new ();
devices = nm_client_get_devices (client);
- g_assert (devices == NULL);
+ g_assert (devices->len == 0);
/* Tell the test service to add a new device */
add_device ("AddWiredDevice", "eth0", NULL);
@@ -293,7 +293,7 @@ wifi_ap_remove_notify_cb (NMDeviceWifi *w,
const GPtrArray *aps;
aps = nm_device_wifi_get_access_points (w);
- g_assert (aps == NULL);
+ g_assert (aps->len == 0);
info->notified = TRUE;
wifi_check_quit (info);
@@ -516,7 +516,7 @@ wimax_nsp_remove_notify_cb (NMDeviceWimax *w,
const GPtrArray *nsps;
nsps = nm_device_wimax_get_nsps (w);
- g_assert (nsps == NULL);
+ g_assert (nsps->len == 0);
info->notified = TRUE;
wimax_check_quit (info);