[gobject-introspection] girepository: Add GI_VFUNC_THROWS



commit 39a70b7b108ed1a262de0b9dc3ffca944d9eee0f
Author: Colin Walters <walters verbum org>
Date:   Fri Feb 3 13:20:00 2012 -0500

    girepository: Add GI_VFUNC_THROWS
    
    Virtual functions can definitely throw an error.  Right now the
    scanner omits the GError parameter for them and adds throws="1", but
    g-ir-compiler ignores this.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=669332

 girepository/girnode.c            |    1 +
 girepository/girnode.h            |    1 +
 girepository/girparser.c          |    7 +++++++
 girepository/girwriter.c          |    3 +++
 girepository/gitypelib-internal.h |    3 ++-
 girepository/gitypes.h            |    4 +++-
 girepository/givfuncinfo.c        |    3 +++
 tests/gimarshallingtests.c        |   12 +++++++++++-
 tests/gimarshallingtests.h        |    7 +++++++
 9 files changed, 38 insertions(+), 3 deletions(-)
---
diff --git a/girepository/girnode.c b/girepository/girnode.c
index fcc8ce5..c5a7048 100644
--- a/girepository/girnode.c
+++ b/girepository/girnode.c
@@ -1784,6 +1784,7 @@ _g_ir_node_build_typelib (GIrNode         *node,
 	blob->must_be_implemented = 0; /* FIXME */
 	blob->must_not_be_implemented = 0; /* FIXME */
 	blob->class_closure = 0; /* FIXME */
+        blob->throws = vfunc->throws;
 	blob->reserved = 0;
 
 	if (vfunc->invoker)
diff --git a/girepository/girnode.h b/girepository/girnode.h
index 3286345..018261a 100644
--- a/girepository/girnode.h
+++ b/girepository/girnode.h
@@ -206,6 +206,7 @@ struct _GIrNodeVFunc
   gboolean must_be_implemented;
   gboolean must_not_be_implemented;
   gboolean is_class_closure;
+  gboolean throws;
 
   char *invoker;
 
diff --git a/girepository/girparser.c b/girepository/girparser.c
index fd742f9..b5c4ee3 100644
--- a/girepository/girparser.c
+++ b/girepository/girparser.c
@@ -2345,6 +2345,7 @@ start_vfunc (GMarkupParseContext *context,
   const gchar *is_class_closure;
   const gchar *offset;
   const gchar *invoker;
+  const gchar *throws;
   GIrNodeInterface *iface;
   GIrNodeVFunc *vfunc;
 
@@ -2362,6 +2363,7 @@ start_vfunc (GMarkupParseContext *context,
   is_class_closure = find_attribute ("is-class-closure", attribute_names, attribute_values);
   offset = find_attribute ("offset", attribute_names, attribute_values);
   invoker = find_attribute ("invoker", attribute_names, attribute_values);
+  throws = find_attribute ("throws", attribute_names, attribute_values);
 
   if (name == NULL)
     {
@@ -2400,6 +2402,11 @@ start_vfunc (GMarkupParseContext *context,
   else
     vfunc->is_class_closure = FALSE;
 
+  if (throws && strcmp (throws, "1") == 0)
+    vfunc->throws = TRUE;
+  else
+    vfunc->throws = FALSE;
+
   if (offset)
     vfunc->offset = atoi (offset);
   else
diff --git a/girepository/girwriter.c b/girepository/girwriter.c
index d9f916c..7f5f7e8 100644
--- a/girepository/girwriter.c
+++ b/girepository/girwriter.c
@@ -916,6 +916,9 @@ write_vfunc_info (const gchar *namespace,
   else if (flags & GI_VFUNC_MUST_NOT_OVERRIDE)
     xml_printf (file, " override=\"never\"");
 
+  if (flags & GI_VFUNC_THROWS)
+    xml_printf (file, " throws=\"1\"");
+
   xml_printf (file, " offset=\"%d\"", offset);
 
   if (invoker)
diff --git a/girepository/gitypelib-internal.h b/girepository/gitypelib-internal.h
index f450a2f..c6575d6 100644
--- a/girepository/gitypelib-internal.h
+++ b/girepository/gitypelib-internal.h
@@ -925,7 +925,8 @@ typedef struct {
   guint16 must_be_implemented     : 1;
   guint16 must_not_be_implemented : 1;
   guint16 class_closure           : 1;
-  guint16 reserved                :12;
+  guint16 throws                  : 1;
+  guint16 reserved                :11;
   guint16 signal;
 
   guint16 struct_offset;
diff --git a/girepository/gitypes.h b/girepository/gitypes.h
index cbe4316..f83ea8b 100644
--- a/girepository/gitypes.h
+++ b/girepository/gitypes.h
@@ -403,6 +403,7 @@ typedef enum
  * @GI_VFUNC_MUST_CHAIN_UP: chains up to the parent type
  * @GI_VFUNC_MUST_OVERRIDE: overrides
  * @GI_VFUNC_MUST_NOT_OVERRIDE: does not override
+ * @GI_VFUNC_THROWS: Includes a #GError
  *
  * Flags of a #GIVFuncInfo struct.
  */
@@ -410,7 +411,8 @@ typedef enum
 {
   GI_VFUNC_MUST_CHAIN_UP     = 1 << 0,
   GI_VFUNC_MUST_OVERRIDE     = 1 << 1,
-  GI_VFUNC_MUST_NOT_OVERRIDE = 1 << 2
+  GI_VFUNC_MUST_NOT_OVERRIDE = 1 << 2,
+  GI_VFUNC_THROWS =            1 << 3
 } GIVFuncInfoFlags;
 
 /**
diff --git a/girepository/givfuncinfo.c b/girepository/givfuncinfo.c
index 332655a..c55c28d 100644
--- a/girepository/givfuncinfo.c
+++ b/girepository/givfuncinfo.c
@@ -104,6 +104,9 @@ g_vfunc_info_get_flags (GIVFuncInfo *info)
   if (blob->must_not_be_implemented)
     flags = flags | GI_VFUNC_MUST_NOT_OVERRIDE;
 
+  if (blob->throws)
+    flags = flags | GI_VFUNC_THROWS;
+
   return flags;
 }
 
diff --git a/tests/gimarshallingtests.c b/tests/gimarshallingtests.c
index 66a6dad..8734a90 100644
--- a/tests/gimarshallingtests.c
+++ b/tests/gimarshallingtests.c
@@ -3946,6 +3946,17 @@ gi_marshalling_tests_object_vfunc_return_value_and_multiple_out_parameters (GIMa
     return return_value;
 }
 
+gboolean
+gi_marshalling_tests_object_vfunc_meth_with_error (GIMarshallingTestsObject *self,
+                                                   gint                      x,
+                                                   GError                  **error)
+{
+  gulong local = 0x12345678;
+  gboolean ret = GI_MARSHALLING_TESTS_OBJECT_GET_CLASS (self)->vfunc_meth_with_err (self, x, error);
+  g_assert_cmpint(local, ==, 0x12345678);
+  return ret;
+}
+
 G_DEFINE_TYPE (GIMarshallingTestsSubObject, gi_marshalling_tests_sub_object, GI_MARSHALLING_TESTS_TYPE_OBJECT);
 
 static void
@@ -4280,7 +4291,6 @@ gi_marshalling_tests_overrides_object_method (GIMarshallingTestsOverridesObject
     return 42;
 }
 
-
 /**
  * gi_marshalling_tests_overrides_object_returnv:
  *
diff --git a/tests/gimarshallingtests.h b/tests/gimarshallingtests.h
index e4f5cb9..1d66991 100644
--- a/tests/gimarshallingtests.h
+++ b/tests/gimarshallingtests.h
@@ -737,6 +737,12 @@ struct _GIMarshallingTestsObjectClass
      */
     glong (* vfunc_return_value_and_multiple_out_parameters) (GIMarshallingTestsObject *self, glong *a, glong *b);
 
+    /**
+     * GIMarshallingTestsObjectClass::vfunc_meth_with_err:
+     * @x:
+     * @error: A #GError
+     */
+    gboolean (*vfunc_meth_with_err) (GIMarshallingTestsObject *object, gint x, GError **error);
 };
 
 struct _GIMarshallingTestsObject
@@ -766,6 +772,7 @@ void gi_marshalling_tests_object_vfunc_one_out_parameter (GIMarshallingTestsObje
 void gi_marshalling_tests_object_vfunc_multiple_out_parameters (GIMarshallingTestsObject *self, gfloat *a, gfloat *b);
 glong gi_marshalling_tests_object_vfunc_return_value_and_one_out_parameter (GIMarshallingTestsObject *self, glong *a);
 glong gi_marshalling_tests_object_vfunc_return_value_and_multiple_out_parameters (GIMarshallingTestsObject *self, glong *a, glong *b);
+gboolean gi_marshalling_tests_object_vfunc_meth_with_error (GIMarshallingTestsObject *object, gint x, GError **error);
 
 GIMarshallingTestsObject *gi_marshalling_tests_object_none_return (void);
 GIMarshallingTestsObject *gi_marshalling_tests_object_full_return (void);



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