[california] Don't pass non-null Value messages holding null
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california] Don't pass non-null Value messages holding null
- Date: Fri, 27 Jun 2014 20:48:44 +0000 (UTC)
commit e9c5a195d6fe80c9a0a5065495f0aaa95073ad9a
Author: Jim Nelson <jim yorba org>
Date: Fri Jun 27 13:46:49 2014 -0700
Don't pass non-null Value messages holding null
It's a pain for the Toolkit.Cards to have to check for non-null
Value messages holding null references, so Toolkit.Deck will "strip"
those messages out and simply pass null to the Card.
This occurred because apparently either GSignal or some Vala-generated
code was turning a null Value into a non-null Value holding null and
the code on the other end of the signal wasn't expecting that.
src/toolkit/toolkit-card.vala | 8 ++++++++
src/toolkit/toolkit-deck.vala | 20 ++++++++++++++++++--
2 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/src/toolkit/toolkit-card.vala b/src/toolkit/toolkit-card.vala
index 158a8a3..ed7ef81 100644
--- a/src/toolkit/toolkit-card.vala
+++ b/src/toolkit/toolkit-card.vala
@@ -126,6 +126,14 @@ public interface Card : Gtk.Widget {
* message may be null even if the Card expects one; generally this means { link jump_back}
* or { link jump_home} was invoked, resulting in this Card being activated.
*
+ * Due to some mechanism inside of GSignal or Vala, it's possible for a caller to pass null
+ * that gets translated into a Value object holding a null pointer. Deck will watch for this
+ * situation and convert those Values into a null reference. This means passing Value(null)
+ * as a message is impossible.
+ *
+ * In order for this null-checking to work, the message must be holding a pointer, Object, or
+ * a string. Other types (including Vala-generated fundamental types!) are not safe-guarded.
+ *
* This is called before dealing with { link default_widget} and { link initial_focus}, so
* changes to those properties in this call, if need be.
*/
diff --git a/src/toolkit/toolkit-deck.vala b/src/toolkit/toolkit-deck.vala
index e5f8acc..c738acf 100644
--- a/src/toolkit/toolkit-deck.vala
+++ b/src/toolkit/toolkit-deck.vala
@@ -191,6 +191,22 @@ public class Deck : Gtk.Stack {
}
}
+ private Value? strip_null_value(Value? message) {
+ if (message == null)
+ return null;
+
+ if (message.holds(typeof(string)))
+ return message.get_string() != null ? message : null;
+
+ if (message.holds(typeof(Object)))
+ return message.get_object() != null ? message : null;
+
+ if (message.holds(typeof(void*)))
+ return message.get_pointer() != null ? message : null;
+
+ return message;
+ }
+
/**
* Force the { link Deck} to jump to the { link home} { link Card}.
*
@@ -207,7 +223,7 @@ public class Deck : Gtk.Stack {
navigation_stack.clear();
set_visible_child(home);
- home.jumped_to(null, message);
+ home.jumped_to(null, strip_null_value(message));
}
private void on_jump_to_card(Card card, Card next, Value? message) {
@@ -226,7 +242,7 @@ public class Deck : Gtk.Stack {
}
set_visible_child(next);
- next.jumped_to(card, message);
+ next.jumped_to(card, strip_null_value(message));
}
private void on_jump_to_card_by_name(Card card, string name, Value? message) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]