mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-01 04:27:59 +02:00
Use g_ptr_array_new_with_free_func() in more places to make client applications easier
This commit is contained in:
parent
b8dd8ffe1e
commit
59357d79f3
8 changed files with 20 additions and 23 deletions
|
|
@ -55,6 +55,10 @@ libdevkit_power_gobject_la_LDFLAGS = \
|
|||
-no-undefined \
|
||||
-export-symbols-regex '^dkp_.*'
|
||||
|
||||
libdevkit_power_gobject_la_CFLAGS = \
|
||||
$(WARNINGFLAGS_C) \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DIST = \
|
||||
dkp-version.h.in
|
||||
|
||||
|
|
|
|||
|
|
@ -336,8 +336,7 @@ dkp_device_print_history (const DkpDevice *device, const gchar *type)
|
|||
obj = (const DkpHistoryObj *) g_ptr_array_index (array, i);
|
||||
g_print (" %i\t%.3f\t%s\n", obj->time, obj->value, dkp_device_state_to_text (obj->state));
|
||||
}
|
||||
g_ptr_array_foreach (array, (GFunc) dkp_history_obj_free, NULL);
|
||||
g_ptr_array_free (array, TRUE);
|
||||
g_ptr_array_unref (array);
|
||||
ret = TRUE;
|
||||
out:
|
||||
return ret;
|
||||
|
|
@ -506,7 +505,7 @@ out:
|
|||
/**
|
||||
* dkp_device_get_history:
|
||||
*
|
||||
* Returns an array of %DkpHistoryObj's
|
||||
* Returns an array of %DkpHistoryObj's, free with g_ptr_array_unref()
|
||||
**/
|
||||
GPtrArray *
|
||||
dkp_device_get_history (const DkpDevice *device, const gchar *type, guint timespec, guint resolution, GError **error)
|
||||
|
|
@ -555,7 +554,7 @@ dkp_device_get_history (const DkpDevice *device, const gchar *type, guint timesp
|
|||
}
|
||||
|
||||
/* convert */
|
||||
array = g_ptr_array_new ();
|
||||
array = g_ptr_array_new_with_free_func ((GDestroyNotify) dkp_history_obj_free);
|
||||
|
||||
for (i=0; i<gvalue_ptr_array->len; i++) {
|
||||
gva = (GValueArray *) g_ptr_array_index (gvalue_ptr_array, i);
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ dkp_wakeups_get_data (DkpWakeups *wakeups, GError **error)
|
|||
}
|
||||
out:
|
||||
if (gvalue_ptr_array != NULL)
|
||||
g_ptr_array_free (gvalue_ptr_array, TRUE);
|
||||
g_ptr_array_unref (gvalue_ptr_array);
|
||||
return array;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -354,7 +354,7 @@ dkp_daemon_enumerate_devices (DkpDaemon *daemon, DBusGMethodInvocation *context)
|
|||
DkpDevice *device;
|
||||
|
||||
/* build a pointer array of the object paths */
|
||||
object_paths = g_ptr_array_new ();
|
||||
object_paths = g_ptr_array_new_with_free_func (g_free);
|
||||
array = dkp_device_list_get_array (daemon->priv->power_devices);
|
||||
for (i=0; i<array->len; i++) {
|
||||
device = (DkpDevice *) g_ptr_array_index (array, i);
|
||||
|
|
@ -366,8 +366,7 @@ dkp_daemon_enumerate_devices (DkpDaemon *daemon, DBusGMethodInvocation *context)
|
|||
dbus_g_method_return (context, object_paths);
|
||||
|
||||
/* free */
|
||||
g_ptr_array_foreach (object_paths, (GFunc) g_free, NULL);
|
||||
g_ptr_array_free (object_paths, TRUE);
|
||||
g_ptr_array_unref (object_paths);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ dkp_device_list_finalize (GObject *object)
|
|||
|
||||
list = DKP_DEVICE_LIST (object);
|
||||
|
||||
g_ptr_array_free (list->priv->array, TRUE);
|
||||
g_ptr_array_unref (list->priv->array);
|
||||
g_hash_table_unref (list->priv->map_native_path_to_device);
|
||||
|
||||
G_OBJECT_CLASS (dkp_device_list_parent_class)->finalize (object);
|
||||
|
|
|
|||
|
|
@ -711,8 +711,7 @@ dkp_device_get_history (DkpDevice *device, const gchar *type_string, guint times
|
|||
dbus_g_method_return (context, complex);
|
||||
out:
|
||||
if (array != NULL) {
|
||||
g_ptr_array_foreach (array, (GFunc) dkp_history_obj_free, NULL);
|
||||
g_ptr_array_free (array, TRUE);
|
||||
g_ptr_array_unref (array);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -479,7 +479,7 @@ dkp_qos_get_latency_requests (DkpQos *qos, GPtrArray **requests, GError **error)
|
|||
|
||||
// dbus_g_method_return (context, requests);
|
||||
// g_ptr_array_foreach (*requests, (GFunc) g_value_array_free, NULL);
|
||||
// g_ptr_array_free (*requests, TRUE);
|
||||
// g_ptr_array_unref (*requests);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ dkp_wakeups_get_data (DkpWakeups *wakeups, GPtrArray **data, GError **error)
|
|||
|
||||
// dbus_g_method_return (context, data);
|
||||
// g_ptr_array_foreach (*data, (GFunc) g_value_array_free, NULL);
|
||||
// g_ptr_array_free (*data, TRUE);
|
||||
// g_ptr_array_unref (*data);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -267,7 +267,7 @@ dkp_strsplit_complete_set (const gchar *string, const gchar *delimiters, guint m
|
|||
GPtrArray *array;
|
||||
|
||||
/* find sections not delimited by space */
|
||||
array = g_ptr_array_new ();
|
||||
array = g_ptr_array_new_with_free_func (g_free);
|
||||
for (i=0; string[i] != '\0'; i++) {
|
||||
ret = dkp_is_in (string[i], delimiters);
|
||||
if (ret) {
|
||||
|
|
@ -366,8 +366,7 @@ dkp_wakeups_poll_kernel_cb (DkpWakeups *wakeups)
|
|||
/* find out how many processors we have */
|
||||
sections = dkp_strsplit_complete_set (lines[0], " ", 0);
|
||||
cpus = sections->len;
|
||||
g_ptr_array_foreach (sections, (GFunc) g_free, NULL);
|
||||
g_ptr_array_free (sections, TRUE);
|
||||
g_ptr_array_unref (sections);
|
||||
|
||||
/* get the data from " 9: 29730 365 IO-APIC-fasteoi acpi" */
|
||||
for (i=1; lines[i] != NULL; i++) {
|
||||
|
|
@ -440,8 +439,7 @@ dkp_wakeups_poll_kernel_cb (DkpWakeups *wakeups)
|
|||
obj->value = (interrupts - obj->old) / (gfloat) DKP_WAKEUPS_POLL_INTERVAL_KERNEL;
|
||||
obj->old = interrupts;
|
||||
skip:
|
||||
g_ptr_array_foreach (sections, (GFunc) g_free, NULL);
|
||||
g_ptr_array_free (sections, TRUE);
|
||||
g_ptr_array_unref (sections);
|
||||
}
|
||||
|
||||
/* tell GUI we've changed */
|
||||
|
|
@ -557,8 +555,7 @@ dkp_wakeups_poll_userspace_cb (DkpWakeups *wakeups)
|
|||
/* we report this in minutes, not seconds */
|
||||
obj->value = (gfloat) interrupts / interval;
|
||||
skip:
|
||||
g_ptr_array_foreach (sections, (GFunc) g_free, NULL);
|
||||
g_ptr_array_free (sections, TRUE);
|
||||
g_ptr_array_unref (sections);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -720,7 +717,7 @@ dkp_wakeups_init (DkpWakeups *wakeups)
|
|||
GError *error = NULL;
|
||||
|
||||
wakeups->priv = DKP_WAKEUPS_GET_PRIVATE (wakeups);
|
||||
wakeups->priv->data = g_ptr_array_new ();
|
||||
wakeups->priv->data = g_ptr_array_new_with_free_func ((GDestroyNotify) dkp_wakeups_obj_free);
|
||||
wakeups->priv->total_old = 0;
|
||||
wakeups->priv->total_ave = 0;
|
||||
wakeups->priv->poll_userspace_id = 0;
|
||||
|
|
@ -762,8 +759,7 @@ dkp_wakeups_finalize (GObject *object)
|
|||
/* stop timerstats */
|
||||
dkp_wakeups_timerstats_disable (wakeups);
|
||||
|
||||
g_ptr_array_foreach (wakeups->priv->data, (GFunc) dkp_wakeups_obj_free, NULL);
|
||||
g_ptr_array_free (wakeups->priv->data, TRUE);
|
||||
g_ptr_array_unref (wakeups->priv->data);
|
||||
|
||||
G_OBJECT_CLASS (dkp_wakeups_parent_class)->finalize (object);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue