[glibmm/wip/dboles/Binding-2.62] Binding: no point to set target value if got false



commit 15f06466ff622bb3dc9ea6ddf0259d269deb9a6e
Author: Daniel Boles <dboles src gmail com>
Date:   Sat Nov 9 19:43:39 2019 +0000

    Binding: no point to set target value if got false
    
    If we return false, GBinding ignores target GValue, so there’s no point
    setting it. Besides, if the transform function returned false, that says
    they couldn't calculate a target value, so they shouldn’t assign to `to`
    
    I default-construct primitive `T_to`s in case anyone *was* reading those
    for some daft reason, so they get a zero-initialised value instead of UB

 glib/src/binding.hg | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/glib/src/binding.hg b/glib/src/binding.hg
index 221554aa..cd219fcb 100644
--- a/glib/src/binding.hg
+++ b/glib/src/binding.hg
@@ -414,14 +414,16 @@ private:
     {
       Glib::Value<T_from> from_glib_value;
       from_glib_value.init(from_value);
+      T_to to{};
+
+      if (!typed_transform(from_glib_value.get(), to))
+        return false;
+
       Glib::Value<T_to> to_glib_value;
       to_glib_value.init(to_value);
-      T_to to = to_glib_value.get();
-
-      const bool result = typed_transform(from_glib_value.get(), to);
       to_glib_value.set(to);
       g_value_copy(to_glib_value.gobj(), to_value);
-      return result;
+      return true;
     }
 
   private:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]