Bug 558068 – when invoking a method, offset the in arguments by one, not
authorJohan Bilien <jobi@via.ecp.fr>
Mon, 27 Oct 2008 15:03:18 +0000 (15:03 +0000)
committerJohan Bilien <jobi@src.gnome.org>
Mon, 27 Oct 2008 15:03:18 +0000 (15:03 +0000)
2008-10-27  Johan Bilien  <jobi@via.ecp.fr>

Bug 558068 – when invoking a method, offset the in arguments by one,
not the out

* tests/invoke/invoke.c, tests/invoke/testfns.c,
tests/invoke/testfns-1.0.gir: Add testing of method and constructor.
* girepository/ginvoke.c: do not offset the index of given out
arguments by one for methods, "this" is provided as in argument only.

svn path=/trunk/; revision=820

ChangeLog
girepository/ginvoke.c
tests/invoke/invoke.c
tests/invoke/testfns-1.0.gir
tests/invoke/testfns.c

index 8fede08..961d4c0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2008-10-27  Johan Bilien  <jobi@via.ecp.fr>
+
+       Bug 558068 – when invoking a method, offset the in arguments by one,
+       not the out
+
+       * tests/invoke/invoke.c, tests/invoke/testfns.c,
+       tests/invoke/testfns-1.0.gir: Add testing of method and constructor.
+       * girepository/ginvoke.c: do not offset the index of given out
+       arguments by one for methods, "this" is provided as in argument only.
+
 2008-10-27  Johan Bilien  <jobi@via.ecp.fr>
 
        * gir/gio-2.0.c: add annotation for g_file_delete
index 2626a95..204c547 100644 (file)
@@ -254,7 +254,7 @@ g_function_info_invoke (GIFunctionInfo *info,
              goto out;
            }
 
-         args[i+offset] = (gpointer)&out_args[out_pos+offset];
+         args[i+offset] = (gpointer)&out_args[out_pos];
          out_pos++;      
          break;
        case GI_DIRECTION_INOUT:
index 27337e7..a41a025 100644 (file)
@@ -4,6 +4,12 @@
 #include <glib.h>
 #include <girepository.h>
 
+typedef struct
+{
+  int foo;
+} TestStruct;
+
+
 int
 main (int argc, char *argv[])
 {
@@ -12,6 +18,7 @@ main (int argc, char *argv[])
   GIRepository *rep;
   GIBaseInfo *info;
   GIFunctionInfo *function;
+  GIStructInfo *record;
   GArgument in_args[3];
   GArgument out_args[3];
   GArgument retval;
@@ -20,6 +27,7 @@ main (int argc, char *argv[])
   gint len;
   GError *error = NULL;
   const gchar *name;
+  TestStruct *s;
   
   g_type_init ();
 
@@ -185,6 +193,59 @@ main (int argc, char *argv[])
   g_base_info_unref (info);
   g_clear_error (&error);
 
+  g_print("Test 8\n");
+  info = g_irepository_find_by_name (rep, "test", "TestStruct");
+  g_assert (g_base_info_get_type (info) == GI_INFO_TYPE_STRUCT);
+  record = (GIStructInfo *)info;
+  info = g_struct_info_find_method (record, "test8");
+  g_assert (g_base_info_get_type (info) == GI_INFO_TYPE_FUNCTION);
+  function = (GIFunctionInfo *)info;
+  g_assert (g_function_info_get_flags (info) & GI_FUNCTION_IS_CONSTRUCTOR);
+
+  {
+    in_args[0].v_int = 42;
+    retval.v_pointer = NULL;
+
+    if (!g_function_info_invoke (function, in_args, 1, NULL, 0, &retval, &error))
+      g_print ("Invocation of %s failed: %s\n",
+               g_base_info_get_name (info),
+               error->message);
+
+    s = (TestStruct *)retval.v_pointer;
+
+    g_assert(s->foo == 42);
+
+  }
+
+  g_base_info_unref (info);
+  g_clear_error (&error);
+
+  g_print("Test 9\n");
+  info = g_struct_info_find_method (record, "test9");
+  g_assert (g_base_info_get_type (info) == GI_INFO_TYPE_FUNCTION);
+  function = (GIFunctionInfo *)info;
+  g_assert (g_function_info_get_flags (info) & GI_FUNCTION_IS_METHOD);
+
+  {
+    TestStruct s = { 42 };
+    int out_i;
+
+    retval.v_pointer = NULL;
+    in_args[0].v_pointer = &s;
+    out_args[0].v_pointer = &out_i;
+    if (!g_function_info_invoke (function, in_args, 1, out_args, 1, &retval, &error))
+      g_print ("Invocation of %s failed: %s\n",
+               g_base_info_get_name (info),
+               error->message);
+
+    g_assert(out_i == 42);
+  }
+
+  g_base_info_unref (info);
+  g_base_info_unref (record);
+  g_clear_error (&error);
+
+
   /* test error handling */
 
 #if 0
index 5218fa8..0398236 100644 (file)
       </parameters>
     </function>
 
+    <record name="TestStruct" c:type="TestStruct">
+      <constructor name="test8" c:identifier="test8">
+        <return-value transfer-ownership="full">
+          <type name="TestStruct" c:type="TestStruct*"/>
+        </return-value>
+        <parameters>
+          <parameter name="foo" direction="in" transfer-ownership="full">
+            <type name="int" c:type="int"/>
+          </parameter>
+        </parameters>
+      </constructor>
+      <method name="test9" c:identifier="test9">
+        <return-value transfer-ownership="full">
+          <type name="none" c:type="void"/>
+        </return-value>
+        <parameters>
+          <parameter name="out" direction="out" transfer-ownership="full">
+            <type name="int" c:type="int*"/>
+          </parameter>
+        </parameters>
+      </method>
+    </record>
+
     <function name="broken" c:identifier="broken">
       <return-value transfer-ownership="none">
          <type name="none" c:type="void"/>
index 06aa3de..c5e47ce 100644 (file)
@@ -3,6 +3,10 @@
 #include <glib.h>
 #include <glib/gprintf.h>
 
+typedef struct {
+    int foo;
+} TestStruct;
+
 gint test1 (gint in)
 {
   return in + 4;
@@ -45,3 +49,18 @@ char *test7 (GList *list)
     }
   return g_string_free (string, FALSE);
 }
+
+/* constructor */
+TestStruct * test8 (int foo)
+{
+  TestStruct *ret;
+
+  ret = g_new(TestStruct, 1);
+  ret->foo = foo;
+  return ret;
+}
+
+void test9 (TestStruct *test_struct, int *out)
+{
+  *out = test_struct->foo;
+}