diff options
author | Richard Hughes <richard@hughsie.com> | 2015-10-13 16:34:45 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2015-10-13 16:34:45 +0100 |
commit | d1c8abfd482310fdb3bdbb7464216f7f61e221b7 (patch) | |
tree | ed187e90bf829b8190fd312f53ede2b6a2d852aa | |
parent | 67ba1c8ec83cbc8f9776cbbf6f0dc7c50897e565 (diff) | |
download | colord-d1c8abfd482310fdb3bdbb7464216f7f61e221b7.tar.gz |
Add g_autoptr() defines for cd_color*
-rw-r--r-- | client/cd-util.c | 3 | ||||
-rw-r--r-- | contrib/session-helper/cd-main.c | 3 | ||||
-rw-r--r-- | lib/colord/cd-color.h | 7 | ||||
-rw-r--r-- | lib/colord/cd-test-private.c | 4 | ||||
-rw-r--r-- | src/cd-sensor.c | 17 |
5 files changed, 14 insertions, 20 deletions
diff --git a/client/cd-util.c b/client/cd-util.c index e9e31b0..e3c46e1 100644 --- a/client/cd-util.c +++ b/client/cd-util.c @@ -1066,7 +1066,6 @@ cd_util_sensor_lock (CdUtilPrivate *priv, gchar **values, GError **error) static gboolean cd_util_get_sensor_reading (CdUtilPrivate *priv, gchar **values, GError **error) { - CdColorXYZ *xyz; CdSensorCap cap; CdSensorCap cap_tmp = CD_SENSOR_CAP_UNKNOWN; CdSensor *sensor; @@ -1097,6 +1096,7 @@ cd_util_get_sensor_reading (CdUtilPrivate *priv, gchar **values, GError **error) } cap = cd_sensor_cap_from_string (values[0]); for (i = 0; i < array->len; i++) { + g_autoptr(CdColorXYZ) xyz = NULL; sensor = g_ptr_array_index (array, i); if (!cd_sensor_connect_sync (sensor, NULL, error)) @@ -1164,7 +1164,6 @@ cd_util_get_sensor_reading (CdUtilPrivate *priv, gchar **values, GError **error) g_print ("%s XYZ : %f, %f, %f\n", _("Color"), xyz->X, xyz->Y, xyz->Z); - cd_color_xyz_free (xyz); } /* unlock */ diff --git a/contrib/session-helper/cd-main.c b/contrib/session-helper/cd-main.c index 5c8ed07..141efb6 100644 --- a/contrib/session-helper/cd-main.c +++ b/contrib/session-helper/cd-main.c @@ -355,7 +355,7 @@ cd_main_calib_get_sample (CdMainPrivate *priv, CdColorXYZ *xyz, GError **error) { - CdColorXYZ *xyz_tmp; + g_autoptr(CdColorXYZ) xyz_tmp = NULL; xyz_tmp = cd_sensor_get_sample_sync (priv->sensor, priv->device_kind, @@ -364,7 +364,6 @@ cd_main_calib_get_sample (CdMainPrivate *priv, if (xyz_tmp == NULL) return FALSE; cd_color_xyz_copy (xyz_tmp, xyz); - cd_color_xyz_free (xyz_tmp); return TRUE; } diff --git a/lib/colord/cd-color.h b/lib/colord/cd-color.h index 8d2cc61..45179dd 100644 --- a/lib/colord/cd-color.h +++ b/lib/colord/cd-color.h @@ -100,6 +100,13 @@ void cd_color_yxy_free (CdColorYxy *src); void cd_color_uvw_free (CdColorUVW *src); void cd_color_swatch_free (CdColorSwatch *src); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(CdColorXYZ, cd_color_xyz_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(CdColorRGB, cd_color_rgb_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(CdColorLab, cd_color_lab_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(CdColorYxy, cd_color_yxy_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(CdColorUVW, cd_color_uvw_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(CdColorSwatch, cd_color_swatch_free) + CdColorXYZ *cd_color_xyz_dup (const CdColorXYZ *src); CdColorLab *cd_color_lab_dup (const CdColorLab *src); CdColorRGB *cd_color_rgb_dup (const CdColorRGB *src); diff --git a/lib/colord/cd-test-private.c b/lib/colord/cd-test-private.c index ff709d0..d4db6ef 100644 --- a/lib/colord/cd-test-private.c +++ b/lib/colord/cd-test-private.c @@ -966,7 +966,7 @@ static void colord_color_func (void) { CdColorUVW uvw; - CdColorXYZ *xyz; + g_autoptr(CdColorXYZ) xyz = NULL; CdColorXYZ xyz_src; CdColorYxy yxy; @@ -996,8 +996,6 @@ colord_color_func (void) g_assert_cmpfloat (ABS (xyz->X - 2.0), <, 0.01); g_assert_cmpfloat (ABS (xyz->Y - 1.0), <, 0.01); g_assert_cmpfloat (ABS (xyz->Z - 0.5), <, 0.01); - - cd_color_xyz_free (xyz); } diff --git a/src/cd-sensor.c b/src/cd-sensor.c index 34a0745..9fbf428 100644 --- a/src/cd-sensor.c +++ b/src/cd-sensor.c @@ -535,7 +535,7 @@ cd_sensor_get_sample_cb (GObject *source_object, gpointer user_data) { GVariant *result = NULL; - CdColorXYZ *sample; + g_autoptr(CdColorXYZ) sample = NULL; CdSensor *sensor = CD_SENSOR (source_object); CdSensorPrivate *priv = GET_PRIVATE (sensor); GDBusMethodInvocation *invocation = (GDBusMethodInvocation *) user_data; @@ -546,22 +546,13 @@ cd_sensor_get_sample_cb (GObject *source_object, if (sample == NULL) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); - goto out; + return; } /* return value */ - g_debug ("returning value %f, %f, %f", - sample->X, - sample->Y, - sample->Z); - result = g_variant_new ("(ddd)", - sample->X, - sample->Y, - sample->Z); + g_debug ("returning value %f, %f, %f", sample->X, sample->Y, sample->Z); + result = g_variant_new ("(ddd)", sample->X, sample->Y, sample->Z); g_dbus_method_invocation_return_value (invocation, result); -out: - if (sample != NULL) - cd_color_xyz_free (sample); } /** |