]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girparser: Add required copy/free attributes for gtype-boxed structs
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 8 Oct 2019 12:04:35 +0000 (14:04 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 8 Oct 2019 14:51:55 +0000 (16:51 +0200)
See https://gitlab.gnome.org/GNOME/vala/issues/863

vala/valagirparser.vala

index efe4399817826ebe4eab40e1615670bfccd0c5d6..9a47de56cb4b9c958a151b8ada46ff410f2c7fb3 100644 (file)
@@ -2784,6 +2784,7 @@ public class Vala.GirParser : CodeVisitor {
                push_node (element_get_name (), true);
 
                Struct st;
+               bool require_copy_free = false;
                if (current.new_symbol) {
                        st = new Struct (element_get_name (), current.source_reference);
                        current.symbol = st;
@@ -2792,6 +2793,7 @@ public class Vala.GirParser : CodeVisitor {
                }
 
                set_type_id_ccode (st);
+               require_copy_free = st.has_attribute_argument ("CCode", "type_id");
 
                st.external = true;
                st.access = SymbolAccessibility.PUBLIC;
@@ -2842,6 +2844,12 @@ public class Vala.GirParser : CodeVisitor {
                        pop_metadata ();
                }
 
+               // Add default g_boxed_copy/free ccode-attributes
+               if (require_copy_free) {
+                       st.set_attribute_string ("CCode", "copy_function", "g_boxed_copy");
+                       st.set_attribute_string ("CCode", "free_function", "g_boxed_free");
+               }
+
                pop_node ();
                end_element ("record");
        }