]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girparser: Avoid possibily creating duplicated attributes
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 15 Dec 2021 20:42:53 +0000 (21:42 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 9 Jan 2022 09:02:24 +0000 (10:02 +0100)
Don't append an attribute without checking if there is an existing one.
In case the attribute already exists append the new key/value pairs.

vala/valacodenode.vala
vala/valagirparser.vala

index 05ba53a0a13f3589be5e468ecc5be1f8f9de0677..4ca44c8d916168bf2bbf50ce1f0fbc8b656ff148 100644 (file)
@@ -120,6 +120,23 @@ public abstract class Vala.CodeNode {
                return null;
        }
 
+       /**
+        * Add attribute and append key/value pairs to an existing one.
+        *
+        * @param a  an attribute to add
+        */
+       public void add_attribute (Attribute a) {
+               unowned Attribute? old_a = get_attribute (a.name);
+               if (old_a == null) {
+                       attributes.append (a);
+               } else {
+                       var it = a.args.map_iterator ();
+                       while (it.next ()) {
+                               old_a.args.set (it.get_key (), it.get_value ());
+                       }
+               }
+       }
+
        unowned Attribute get_or_create_attribute (string name) {
                unowned Attribute? a = get_attribute (name);
                if (a == null) {
index d59114020595c5fa22c8201a468cd5f5f69f4019..3acef3ff65b879bf8a9f7836fec13ff935ba9827 100644 (file)
@@ -3933,7 +3933,7 @@ public class Vala.GirParser : CodeVisitor {
                        }
 
                        foreach (var attribute in orig.attributes) {
-                               deleg.attributes.append (attribute);
+                               deleg.add_attribute (attribute);
                        }
 
                        alias.symbol = deleg;
@@ -4373,7 +4373,7 @@ public class Vala.GirParser : CodeVisitor {
                                // cannot use List.copy()
                                // as it returns a list of unowned elements
                                foreach (Attribute a in m.attributes) {
-                                       method.attributes.append (a);
+                                       method.add_attribute (a);
                                }
 
                                method.set_attribute_string ("CCode", "cname", node.get_cname ());