diff options
author | Dan Winship <danw@gnome.org> | 2012-06-18 15:31:47 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2012-06-20 08:20:50 -0400 |
commit | 7d0db042234165678f5dfafef3dd96d3af97b56c (patch) | |
tree | 7dae0f813325e96c264cc13fc9f4179f50929ade | |
parent | 599d1a430e787f7cda929b8b0188a01f39453e66 (diff) | |
download | glib-7d0db042234165678f5dfafef3dd96d3af97b56c.tar.gz |
gdbus: fix generated code to not warn under -Wfloat-equal
https://bugzilla.gnome.org/show_bug.cgi?id=678333
-rw-r--r-- | gio/gdbus-2.0/codegen/codegen.py | 11 | ||||
-rw-r--r-- | gio/tests/gdbus-test-codegen.c | 31 |
2 files changed, 40 insertions, 2 deletions
diff --git a/gio/gdbus-2.0/codegen/codegen.py b/gio/gdbus-2.0/codegen/codegen.py index 4960f5625..41ea8fa76 100644 --- a/gio/gdbus-2.0/codegen/codegen.py +++ b/gio/gdbus-2.0/codegen/codegen.py @@ -66,7 +66,9 @@ class CodeGenerator: '#endif\n' '\n' '#include "%s"\n' - '\n'%(self.h.name)) + '\n' + '#include <string.h>\n' + %(self.h.name)) self.c.write('#ifdef G_OS_UNIX\n' '# include <gio/gunixfdlist.h>\n' @@ -192,7 +194,12 @@ class CodeGenerator: ' ret = (g_value_get_uint64 (a) == g_value_get_uint64 (b));\n' ' break;\n' ' case G_TYPE_DOUBLE:\n' - ' ret = (g_value_get_double (a) == g_value_get_double (b));\n' + ' {\n' + ' /* Avoid -Wfloat-equal warnings by doing a direct bit compare */\n' + ' gdouble da = g_value_get_double (a);\n' + ' gdouble db = g_value_get_double (b);\n' + ' ret = memcmp (&da, &db, sizeof (gdouble)) == 0;\n' + ' }\n' ' break;\n' ' case G_TYPE_STRING:\n' ' ret = (g_strcmp0 (g_value_get_string (a), g_value_get_string (b)) == 0);\n' diff --git a/gio/tests/gdbus-test-codegen.c b/gio/tests/gdbus-test-codegen.c index 5eb175f7c..9cf73675e 100644 --- a/gio/tests/gdbus-test-codegen.c +++ b/gio/tests/gdbus-test-codegen.c @@ -1730,10 +1730,23 @@ on_object_proxy_removed (GDBusObjectManagerClient *manager, } static void +property_d_changed (GObject *object, + GParamSpec *pspec, + gpointer user_data) +{ + gboolean *changed = user_data; + + *changed = TRUE; +} + +static void om_check_property_and_signal_emission (GMainLoop *loop, FooiGenBar *skeleton, FooiGenBar *proxy) { + gboolean d_changed = FALSE; + guint handler; + /* First PropertiesChanged */ g_assert_cmpint (foo_igen_bar_get_i (skeleton), ==, 0); g_assert_cmpint (foo_igen_bar_get_i (proxy), ==, 0); @@ -1742,6 +1755,24 @@ om_check_property_and_signal_emission (GMainLoop *loop, g_assert_cmpint (foo_igen_bar_get_i (skeleton), ==, 1); g_assert_cmpint (foo_igen_bar_get_i (proxy), ==, 1); + /* Double-check the gdouble case */ + g_assert_cmpfloat (foo_igen_bar_get_d (skeleton), ==, 0.0); + g_assert_cmpfloat (foo_igen_bar_get_d (proxy), ==, 0.0); + foo_igen_bar_set_d (skeleton, 1.0); + _g_assert_property_notify (proxy, "d"); + + /* Verify that re-setting it to the same value doesn't cause a + * notify on the proxy, by taking advantage of the fact that + * notifications are serialized. + */ + handler = g_signal_connect (proxy, "notify::d", + G_CALLBACK (property_d_changed), &d_changed); + foo_igen_bar_set_d (skeleton, 1.0); + foo_igen_bar_set_i (skeleton, 2); + _g_assert_property_notify (proxy, "i"); + g_assert (d_changed == FALSE); + g_signal_handler_disconnect (proxy, handler); + /* Then just a regular signal */ foo_igen_bar_emit_another_signal (skeleton, "word"); _g_assert_signal_received (proxy, "another-signal"); |