[gnome-builder/wip/gtk4-port: 1235/1774] libide/core: cleanup string handling macros/inlines
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 1235/1774] libide/core: cleanup string handling macros/inlines
- Date: Mon, 11 Jul 2022 22:31:39 +0000 (UTC)
commit 0be02dd83bbaeb76e6c705f04540e4c45eafd54e
Author: Christian Hergert <chergert redhat com>
Date: Tue May 31 11:23:10 2022 -0700
libide/core: cleanup string handling macros/inlines
We can do this a bit better so it makes more sense to use them across
the API for string properties.
src/libide/core/ide-macros.h | 32 +++++++++++++++++++++-----------
1 file changed, 21 insertions(+), 11 deletions(-)
---
diff --git a/src/libide/core/ide-macros.h b/src/libide/core/ide-macros.h
index 0a456b060..ae3043ba0 100644
--- a/src/libide/core/ide-macros.h
+++ b/src/libide/core/ide-macros.h
@@ -38,7 +38,6 @@ G_BEGIN_DECLS
#define ide_str_equal(str1,str2) (strcmp((char*)str1,(char*)str2)==0)
#define ide_str_equal0(str1,str2) (g_strcmp0((char*)str1,(char*)str2)==0)
#define ide_strv_empty0(strv) (((strv) == NULL) || ((strv)[0] == NULL))
-#define ide_set_string(ptr,str) (ide_take_string((ptr), g_strdup(str)))
#define ide_clear_param(pptr, pval) \
G_STMT_START { if (pptr) { *(pptr) = pval; }; } G_STMT_END
@@ -89,24 +88,35 @@ _g_object_unref0 (gpointer instance)
}
static inline gboolean
-ide_take_string (gchar **ptr,
- gchar *str)
+ide_set_string (char **ptr,
+ const char *str)
{
- if (*ptr != str)
+ if (*ptr == str || g_strcmp0 (*ptr, str) == 0)
+ return FALSE;
+
+ g_clear_pointer (ptr, g_free);
+ *ptr = g_strdup (str);
+ return TRUE;
+}
+
+static inline void
+ide_take_string (char **ptr,
+ char *str)
+{
+ if (*ptr == str || g_strcmp0 (*ptr, str) == 0)
{
- g_free (*ptr);
- *ptr = str;
- return TRUE;
+ g_free (str);
+ return;
}
- return FALSE;
+ g_clear_pointer (ptr, g_free);
+ *ptr = g_steal_pointer (&str);
}
static inline void
-ide_clear_string (gchar **ptr)
+ide_clear_string (char **ptr)
{
- g_free (*ptr);
- *ptr = NULL;
+ g_clear_pointer (ptr, g_free);
}
static inline GList *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]