From: Rico Tzschichholz Date: Wed, 15 Dec 2021 20:42:53 +0000 (+0100) Subject: girparser: Avoid possibily creating duplicated attributes X-Git-Tag: 0.48.22~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8e86a57d44cee2c1bd789eb49e6ea05dbf1e98d0;p=thirdparty%2Fvala.git girparser: Avoid possibily creating duplicated attributes 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. --- diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala index 88d283896..0d2a9e5a3 100644 --- a/vala/valacodenode.vala +++ b/vala/valacodenode.vala @@ -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) { diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index c8dde53db..ed1c18b51 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -3907,7 +3907,7 @@ public class Vala.GirParser : CodeVisitor { } foreach (var attribute in orig.attributes) { - deleg.attributes.append (attribute); + deleg.add_attribute (attribute); } alias.symbol = deleg; @@ -4347,7 +4347,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 ());