diff mbox series

[libgpiod] tests: don't use g_value_set_static_string() for non-static strings

Message ID 20240813093025.94980-1-brgl@bgdev.pl
State New
Headers show
Series [libgpiod] tests: don't use g_value_set_static_string() for non-static strings | expand

Commit Message

Bartosz Golaszewski Aug. 13, 2024, 9:30 a.m. UTC
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

As pointed out by Philip Withnall, g_value_set_static_string() must only
be used with actual static strings and not with ones whose life-time is
tied to that of their owner. Use g_value_set_string() to get the gpiosim
properties and rework the existing getter functions returning const
gchar * to return the address provided by libgpiosim directly instead of
passing through the GObject property path.

Suggested-by: Philip Withnall <philip@tecnocode.co.uk>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 tests/gpiosim-glib/gpiosim-glib.c | 24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)

Comments

Bartosz Golaszewski Aug. 16, 2024, 7:56 a.m. UTC | #1
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


On Tue, 13 Aug 2024 11:30:25 +0200, Bartosz Golaszewski wrote:
> As pointed out by Philip Withnall, g_value_set_static_string() must only
> be used with actual static strings and not with ones whose life-time is
> tied to that of their owner. Use g_value_set_string() to get the gpiosim
> properties and rework the existing getter functions returning const
> gchar * to return the address provided by libgpiosim directly instead of
> passing through the GObject property path.
> 
> [...]

Applied, thanks!

[1/1] tests: don't use g_value_set_static_string() for non-static strings
      commit: 47e14b2cefb5a6d4ae6d7bffd76fa7bd129cd23b

Best regards,
diff mbox series

Patch

diff --git a/tests/gpiosim-glib/gpiosim-glib.c b/tests/gpiosim-glib/gpiosim-glib.c
index 4eaeace..27ce019 100644
--- a/tests/gpiosim-glib/gpiosim-glib.c
+++ b/tests/gpiosim-glib/gpiosim-glib.c
@@ -245,12 +245,11 @@  static void g_gpiosim_chip_get_property(GObject *obj, guint prop_id,
 
 	switch (prop_id) {
 	case G_GPIOSIM_CHIP_PROP_DEV_PATH:
-		g_value_set_static_string(val,
-				gpiosim_bank_get_dev_path(self->bank));
+		g_value_set_string(val, gpiosim_bank_get_dev_path(self->bank));
 		break;
 	case G_GPIOSIM_CHIP_PROP_NAME:
-		g_value_set_static_string(val,
-				gpiosim_bank_get_chip_name(self->bank));
+		g_value_set_string(val,
+				   gpiosim_bank_get_chip_name(self->bank));
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
@@ -396,27 +395,14 @@  static void g_gpiosim_chip_init(GPIOSimChip *self)
 	self->hogs = NULL;
 }
 
-static const gchar *
-g_gpiosim_chip_get_string_prop(GPIOSimChip *self, const gchar *prop)
-{
-	GValue val = G_VALUE_INIT;
-	const gchar *str;
-
-	g_object_get_property(G_OBJECT(self), prop, &val);
-	str = g_value_get_string(&val);
-	g_value_unset(&val);
-
-	return str;
-}
-
 const gchar *g_gpiosim_chip_get_dev_path(GPIOSimChip *self)
 {
-	return g_gpiosim_chip_get_string_prop(self, "dev-path");
+	return gpiosim_bank_get_dev_path(self->bank);
 }
 
 const gchar *g_gpiosim_chip_get_name(GPIOSimChip *self)
 {
-	return g_gpiosim_chip_get_string_prop(self, "name");
+	return gpiosim_bank_get_chip_name(self->bank);
 }
 
 GPIOSimValue