Bug 572965 – Allow generic marshaller to be called without parameters
authorJohan Bilien <jobi@litl.com>
Tue, 24 Feb 2009 15:19:07 +0000 (15:19 +0000)
committerJohan Bilien <jobi@litl.com>
Tue, 24 Feb 2009 15:22:59 +0000 (15:22 +0000)
girepository/ginvoke.c: handle the case where n_param_values == 0.
tests/invoke/genericmarshaller.c: add a test case for this.

girepository/ginvoke.c
tests/invoke/genericmarshaller.c

index e83a820..70d81f8 100644 (file)
@@ -407,18 +407,26 @@ gi_cclosure_marshal_generic (GClosure *closure,
   atypes = g_alloca (sizeof (ffi_type *) * n_args);
   args =  g_alloca (sizeof (gpointer) * n_args);
 
-  if (G_CCLOSURE_SWAP_DATA (closure))
+  if (n_param_values > 0)
     {
-      atypes[n_args-1] = value_to_ffi_type (param_values + 0,  
-                                            &args[n_args-1]);
-      atypes[0] = &ffi_type_pointer;
-      args[0] = &closure->data;
+      if (G_CCLOSURE_SWAP_DATA (closure))
+        {
+          atypes[n_args-1] = value_to_ffi_type (param_values + 0,  
+                                                &args[n_args-1]);
+          atypes[0] = &ffi_type_pointer;
+          args[0] = &closure->data;
+        }
+      else
+        {
+          atypes[0] = value_to_ffi_type (param_values + 0, &args[0]);
+          atypes[n_args-1] = &ffi_type_pointer;
+          args[n_args-1] = &closure->data;
+        }
     }
   else
     {
-      atypes[0] = value_to_ffi_type (param_values + 0, &args[0]);
-      atypes[n_args-1] = &ffi_type_pointer;
-      args[n_args-1] = &closure->data;
+      atypes[0] = &ffi_type_pointer;
+      args[0] = &closure->data;
     }
 
   for (i = 1; i < n_args - 1; i++)
index dd2509c..d023399 100644 (file)
@@ -150,12 +150,20 @@ test4_callback (TestObject *object,
   g_return_if_fail (ulong == 30L);
 }
 
+/* this callback has no "this" */
+static void
+test5_callback (gpointer user_data)
+{
+  g_return_if_fail (!strcmp (user_data, "user-data"));
+}
+
 static void
 test_cclosure_marshal (void)
 {
   TestObject *object;
   gchar *data = "user-data";
   int i;
+  GClosure *closure;
   
   g_type_init ();
   
@@ -189,7 +197,17 @@ test_cclosure_marshal (void)
   g_assert (i == 20);
 
   g_object_unref (object);
+
+  closure = g_cclosure_new (G_CALLBACK (test5_callback),
+                            data,
+                            NULL);
+  g_closure_ref (closure);
+  g_closure_sink (closure);
+  g_closure_set_marshal (closure, gi_cclosure_marshal_generic);
+  g_closure_invoke (closure, NULL, 0, NULL, NULL);
+  g_closure_unref (closure);
 }
+
   
 int main(void)
 {