[geary] Tighten up parent refs in ListParameters
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary] Tighten up parent refs in ListParameters
- Date: Fri, 19 Sep 2014 02:04:09 +0000 (UTC)
commit 513c6d8c0dfea6264a9f99242a686704e27b1500
Author: Jim Nelson <jim yorba org>
Date: Thu Sep 18 17:36:41 2014 -0700
Tighten up parent refs in ListParameters
While working on another bug, I discovered some issues with the
maintenance of parent references for IMAP Parameters being held in
ListParameters (of which every Parameter is held). This patch not
only tightens up references, it also verifies references are accurate
when the ListParameter is destroyed.
src/engine/imap/parameter/imap-list-parameter.vala | 37 ++++++++++++--------
1 files changed, 22 insertions(+), 15 deletions(-)
---
diff --git a/src/engine/imap/parameter/imap-list-parameter.vala
b/src/engine/imap/parameter/imap-list-parameter.vala
index 1df02be..e742752 100644
--- a/src/engine/imap/parameter/imap-list-parameter.vala
+++ b/src/engine/imap/parameter/imap-list-parameter.vala
@@ -43,14 +43,15 @@ public class Geary.Imap.ListParameter : Geary.Imap.Parameter {
}
~ListParameter() {
- // Although every attempt is made to make sure the parent-child relationship is maintained,
- // be lenient here and only drop it if coherent ... this is done because, although it's
- // a weak ref, sometimes ListParameters are temporarily made and current Vala doesn't
- // reset weak refs
+ // Drop back links because, although it's a weak ref, sometimes ListParameters are temporarily
+ // made and current Vala doesn't reset weak refs
foreach (Parameter param in list) {
ListParameter? listp = param as ListParameter;
- if (listp != null && listp.parent == this)
+ if (listp != null) {
+ assert(listp.parent == this);
+
listp.parent = null;
+ }
}
}
@@ -68,8 +69,12 @@ public class Geary.Imap.ListParameter : Geary.Imap.Parameter {
public bool add(Parameter param) {
// if adding a ListParameter, set its parent
ListParameter? listp = param as ListParameter;
- if (listp != null)
+ if (listp != null) {
+ if (listp.parent != null)
+ listp.parent.list.remove(listp);
+
listp.parent = this;
+ }
return list.add(param);
}
@@ -129,6 +134,8 @@ public class Geary.Imap.ListParameter : Geary.Imap.Parameter {
/**
* Clears the { link ListParameter} of all its children.
+ *
+ * This also clears (sets to null) the parents of all { link ListParamater} children.
*/
public void clear() {
// sever ties to ListParameter children
@@ -448,8 +455,12 @@ public class Geary.Imap.ListParameter : Geary.Imap.Parameter {
// add parent to new Parameter if a list
ListParameter? listp = parameter as ListParameter;
- if (listp != null)
+ if (listp != null) {
+ if (listp.parent != null)
+ listp.parent.list.remove(listp);
+
listp.parent = this;
+ }
// clear parent of old Parameter if a list
listp = old as ListParameter;
@@ -468,15 +479,11 @@ public class Geary.Imap.ListParameter : Geary.Imap.Parameter {
public void adopt_children(ListParameter src) {
clear();
- foreach (Parameter param in src.list) {
- ListParameter? listp = param as ListParameter;
- if (listp != null)
- listp.parent = this;
-
- list.add(param);
- }
-
+ Gee.List<Parameter> src_children = new Gee.ArrayList<Parameter>();
+ src_children.add_all(src.list);
src.clear();
+
+ add_all(src_children);
}
protected string stringize_list() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]