tests: shrink helper code
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 31 Jan 2023 18:29:16 +0000 (19:29 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 31 Jan 2023 18:30:29 +0000 (19:30 +0100)
Use g_autoptr() for GVariantBuilder objects and shrink the code by a few
lines.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
tests/gpiod-test-helpers.c

index 4801b151837fe4360bee35485572ec68992db36a..1669ee3ec4cae93a03d36ebea49b6a8c5ea281ae 100644 (file)
@@ -14,9 +14,8 @@
 GVariant *
 gpiod_test_package_line_names(const struct gpiod_test_line_name *names)
 {
+       g_autoptr(GVariantBuilder) builder = NULL;
        const struct gpiod_test_line_name *name;
-       GVariantBuilder *builder;
-       GVariant *ret;
 
        builder = g_variant_builder_new(G_VARIANT_TYPE("a(us)"));
 
@@ -24,17 +23,13 @@ gpiod_test_package_line_names(const struct gpiod_test_line_name *names)
                g_variant_builder_add(builder, "(us)",
                                      name->offset, name->name);
 
-       ret = g_variant_ref_sink(g_variant_new("a(us)", builder));
-       g_variant_builder_unref(builder);
-
-       return ret;
+       return g_variant_ref_sink(g_variant_new("a(us)", builder));
 }
 
 GVariant *gpiod_test_package_hogs(const struct gpiod_test_hog *hogs)
 {
+       g_autoptr(GVariantBuilder) builder = NULL;
        const struct gpiod_test_hog *hog;
-       GVariantBuilder *builder;
-       GVariant *ret;
 
        builder = g_variant_builder_new(G_VARIANT_TYPE("a(usi)"));
 
@@ -42,8 +37,5 @@ GVariant *gpiod_test_package_hogs(const struct gpiod_test_hog *hogs)
                g_variant_builder_add(builder, "(usi)",
                                      hog->offset, hog->name, hog->direction);
 
-       ret = g_variant_ref_sink(g_variant_new("a(usi)", builder));
-       g_variant_builder_unref(builder);
-
-       return ret;
+       return g_variant_ref_sink(g_variant_new("a(usi)", builder));
 }