Skip to contentSkip to conversation

vhost-user-test: fix crash with glib < 2.36

PATCH In review Michael S. Tsirkin 2 participants 2 messages Nov 30, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost-user-test: fix crash with glib < 2.36

glib manual says this about the prepare callback:
Since 2.36 this may be NULL, in which case the effect is as if the function always returns FALSE with a timeout of -1.

Fix code to work for older glib - simply implement a stub prepare callback.

While we are at it, switch to named initializers for readability.

---
 tests/vhost-user-test.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
tests/vhost-user-test.c +9 -4
index 29205ed..b67ca56 100644
@@ -506,11 +506,16 @@ test_migrate_source_check(GSource *source)
     return FALSE;
 }
 
+static gboolean
+test_migrate_source_prepare(GSource *source, gint *timeout)
+{
+    *timeout = -1;
+    return FALSE;
+}
+
 GSourceFuncs test_migrate_source_funcs = {
-    NULL,
-    test_migrate_source_check,
-    NULL,
-    NULL
+    .prepare = test_migrate_source_prepare,
+    .check = test_migrate_source_check,
 };
 
 static void test_migrate(void)
Signature · 1 line
MST
#1 lore raw

Hi

Quoted 6 lines · Michael S. Tsirkin

glib manual says this about the prepare callback:
Since 2.36 this may be NULL, in which case the effect is as if the function always returns FALSE with a timeout of -1.

Fix code to work for older glib - simply implement a stub prepare callback.

That's what I did in my patch. However, I explained why I'd prefer to keep the #ifdef to avoid the stub/dumb callback in the future.

Quoted 4 lines

While we are at it, switch to named initializers for readability.

That's readability, not strictly required to fix the issue.

Quoted 34 lines
---
 tests/vhost-user-test.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
tests/vhost-user-test.c +9 -5
index 29205ed..b67ca56 100644
@@ -506,11 +506,16 @@ test_migrate_source_check(GSource *source)
     return FALSE;
 }
 
+static gboolean
+test_migrate_source_prepare(GSource *source, gint *timeout)
+{
+    *timeout = -1;
+    return FALSE;
+}
+
 GSourceFuncs test_migrate_source_funcs = {
-    NULL,
-    test_migrate_source_check,
-    NULL,
-    NULL
+    .prepare = test_migrate_source_prepare,
+    .check = test_migrate_source_check,
 };
 
 static void test_migrate(void)
--

MST

Signature · 1 line
Marc-André Lureau