[gnome-builder] configuration: copy internal values when duplicating a configuration
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] configuration: copy internal values when duplicating a configuration
- Date: Wed, 2 Nov 2016 23:57:23 +0000 (UTC)
commit 9cb7d8444c112f172c99a6bfd7741862412fccde
Author: Christian Hergert <chergert redhat com>
Date: Wed Nov 2 16:52:27 2016 -0700
configuration: copy internal values when duplicating a configuration
libide/buildsystem/ide-configuration.c | 21 +++++++++++++++++++++
tests/test-ide-configuration.c | 9 +++++++++
2 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/libide/buildsystem/ide-configuration.c b/libide/buildsystem/ide-configuration.c
index 6cf000f..08645da 100644
--- a/libide/buildsystem/ide-configuration.c
+++ b/libide/buildsystem/ide-configuration.c
@@ -107,6 +107,20 @@ _value_new (GType type)
return value;
}
+static GValue *
+_value_copy (const GValue *value)
+{
+ GValue *dst;
+
+ g_assert (value != NULL);
+
+ dst = g_slice_new0 (GValue);
+ g_value_init (dst, G_VALUE_TYPE (value));
+ g_value_copy (value, dst);
+
+ return dst;
+}
+
static void
ide_configuration_emit_changed (IdeConfiguration *self)
{
@@ -857,10 +871,13 @@ IdeConfiguration *
ide_configuration_duplicate (IdeConfiguration *self)
{
static gint next_counter = 2;
+ GHashTableIter iter;
IdeConfiguration *copy;
IdeContext *context;
g_autofree gchar *id = NULL;
g_autofree gchar *name = NULL;
+ const gchar *key;
+ const GValue *value;
g_return_val_if_fail (IDE_IS_CONFIGURATION (self), NULL);
@@ -886,6 +903,10 @@ ide_configuration_duplicate (IdeConfiguration *self)
if (self->postbuild)
copy->postbuild = ide_build_command_queue_copy (self->postbuild);
+ g_hash_table_iter_init (&iter, self->internal);
+ while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *)&value))
+ g_hash_table_insert (copy->internal, g_strdup (key), _value_copy (value));
+
return copy;
}
diff --git a/tests/test-ide-configuration.c b/tests/test-ide-configuration.c
index f9cd713..4517ee8 100644
--- a/tests/test-ide-configuration.c
+++ b/tests/test-ide-configuration.c
@@ -22,6 +22,7 @@ static void
test_internal (void)
{
g_autoptr(IdeConfiguration) configuration = NULL;
+ g_autoptr(IdeConfiguration) copy = NULL;
configuration = g_object_new (IDE_TYPE_CONFIGURATION,
"id", "my-configuration",
@@ -57,6 +58,14 @@ test_internal (void)
g_assert_cmpint (ide_configuration_get_internal_int64 (configuration, "foo-string"), ==, 0);
g_assert_cmpint (ide_configuration_get_internal_boolean (configuration, "foo-string"), ==, TRUE);
+ copy = ide_configuration_duplicate (configuration);
+ g_assert (copy != NULL);
+ g_assert_cmpint (ide_configuration_get_internal_boolean (copy, "foo-string"), ==, TRUE);
+
+ g_object_add_weak_pointer (G_OBJECT (copy), (gpointer *)©);
+ g_object_unref (copy);
+ g_assert (copy == NULL);
+
g_object_add_weak_pointer (G_OBJECT (configuration), (gpointer *)&configuration);
g_object_unref (configuration);
g_assert (configuration == NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]