[vala/0.54] girparser: Avoid possibily creating duplicated attributes
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.54] girparser: Avoid possibily creating duplicated attributes
- Date: Thu, 16 Dec 2021 07:23:40 +0000 (UTC)
commit d493b7759b58a551c2f8123315c968f2f6f76a01
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Wed Dec 15 21:42:53 2021 +0100
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.
vala/valacodenode.vala | 17 +++++++++++++++++
vala/valagirparser.vala | 4 ++--
2 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala
index 05ba53a0a..4ca44c8d9 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 6a4b572af..3babf7424 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -3959,7 +3959,7 @@ public class Vala.GirParser : CodeVisitor {
}
foreach (var attribute in orig.attributes) {
- deleg.attributes.append (attribute);
+ deleg.add_attribute (attribute);
}
alias.symbol = deleg;
@@ -4419,7 +4419,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 ());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]