[gnome-builder] gui: Make IdeSession pre API rework migration use a definite GVariantBuilder type



commit 06741c521ed73f6d4990e602853e5e31bda08852
Author: vanadiae <vanadiae35 gmail com>
Date:   Thu Jul 8 17:43:43 2021 +0200

    gui: Make IdeSession pre API rework migration use a definite GVariantBuilder type
    
    Currently if opening a project which used the old session.state format (pre API
    rework) that doesn't contain any page (just an empty workspace basically), the code
    would spew
    sys:1: Warning: g_variant_builder_end: assertion '!GVSB(builder)->uniform_item_types
    || GVSB(builder)->prev_item_type != NULL || g_variant_type_is_definite
    (GVSB(builder)->type)' failed
    with a few other related warnings that followed.
    
    This is due to the current code that initialized the array of pages' states with
    an indefinite (i.e. not known fully) array type. Usually the GVariantBuilder
    infers the type of the elements in the array by looking at the type of the first
    added item, with g_variant_builder_add(_value) function. But since no item
    is added, the GVariantBuilder doesn't know what's the definite type of the array
    when g_variant_builder_end() is called, it returns NULL and emits a warning,
    because there's no way it can build the (empty) array in that case.
    
    So this commit initializes the GVariantBuilder to the full definite type aa{sv},
    since we know what's supposed to be in the GVariant at the end.

 src/libide/gui/ide-session.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/src/libide/gui/ide-session.c b/src/libide/gui/ide-session.c
index 6bad3f6f9..05e9e8590 100644
--- a/src/libide/gui/ide-session.c
+++ b/src/libide/gui/ide-session.c
@@ -313,7 +313,7 @@ migrate_pre_api_rework (GVariant *pages_variant)
   /* Migrate old format to first version of the new format. */
   g_variant_dict_insert (&version_wrapper_dict, "version", "u", (guint32) 1);
 
-  g_variant_builder_init (&addins_states, G_VARIANT_TYPE_ARRAY);
+  g_variant_builder_init (&addins_states, G_VARIANT_TYPE ("aa{sv}"));
 
   g_debug ("Handling migration of the project's session.gvariant, from prior to the Session API rework…");
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]