[perl-Glib-Object-Introspection] Refactor the vfunc offset code into a function



commit 6a44a6a12f4739b8122c34baeca59279e19cd81e
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date:   Thu Feb 14 23:05:51 2013 +0100

    Refactor the vfunc offset code into a function

 GObjectIntrospection.xs      |   19 ++-----------------
 gperl-i11n-vfunc-interface.c |    4 +++-
 gperl-i11n-vfunc-object.c    |   28 +++++++++++++++++++++++++++-
 3 files changed, 32 insertions(+), 19 deletions(-)
---
diff --git a/GObjectIntrospection.xs b/GObjectIntrospection.xs
index 40e064e..c8d79fe 100644
--- a/GObjectIntrospection.xs
+++ b/GObjectIntrospection.xs
@@ -762,7 +762,6 @@ _find_vfuncs_with_implementation (class, object_package, target_package)
        GType object_gtype, target_gtype;
        gpointer object_klass, target_klass;
        GIObjectInfo *object_info;
-       GIStructInfo *struct_info;
        gint n_vfuncs, i;
     PPCODE:
        repository = g_irepository_get_default ();
@@ -774,27 +773,20 @@ _find_vfuncs_with_implementation (class, object_package, target_package)
        g_assert (target_klass && object_klass);
        object_info = g_irepository_find_by_gtype (repository, object_gtype);
        g_assert (object_info && GI_IS_OBJECT_INFO (object_info));
-       struct_info = g_object_info_get_class_struct (object_info);
-       g_assert (struct_info);
        n_vfuncs = g_object_info_get_n_vfuncs (object_info);
        for (i = 0; i < n_vfuncs; i++) {
                GIVFuncInfo *vfunc_info;
                const gchar *vfunc_name;
-               GIFieldInfo *field_info;
                gint field_offset;
                vfunc_info = g_object_info_get_vfunc (object_info, i);
                vfunc_name = g_base_info_get_name (vfunc_info);
                /* FIXME: g_vfunc_info_get_offset does not seem to work here. */
-               field_info = get_field_info (struct_info, vfunc_name);
-               g_assert (field_info);
-               field_offset = g_field_info_get_offset (field_info);
+               field_offset = get_vfunc_offset (object_info, vfunc_name);
                if (G_STRUCT_MEMBER (gpointer, target_klass, field_offset)) {
                        XPUSHs (sv_2mortal (newSVpv (vfunc_name, PL_na)));
                }
-               g_base_info_unref (field_info);
                g_base_info_unref (vfunc_info);
        }
-       g_base_info_unref (struct_info);
        g_base_info_unref (object_info);
 
 void
@@ -808,9 +800,7 @@ _invoke_fallback_vfunc (class, vfunc_package, vfunc_name, target_package, ...)
        GIObjectInfo *info;
        GType gtype;
        gpointer klass;
-       GIStructInfo *struct_info;
        GIVFuncInfo *vfunc_info;
-       GIFieldInfo *field_info;
        gint field_offset;
        gpointer func_pointer;
     PPCODE:
@@ -823,14 +813,10 @@ _invoke_fallback_vfunc (class, vfunc_package, vfunc_name, target_package, ...)
        info = g_irepository_find_by_gtype (
                repository, gperl_object_type_from_package (vfunc_package));
        g_assert (info && GI_IS_OBJECT_INFO (info));
-       struct_info = g_object_info_get_class_struct (info);
-       g_assert (struct_info);
        vfunc_info = g_object_info_find_vfunc (info, vfunc_name);
        g_assert (vfunc_info);
        /* FIXME: g_vfunc_info_get_offset does not seem to work here. */
-       field_info = get_field_info (struct_info, vfunc_name);
-       g_assert (field_info);
-       field_offset = g_field_info_get_offset (field_info);
+       field_offset = get_vfunc_offset (info, vfunc_name);
        func_pointer = G_STRUCT_MEMBER (gpointer, klass, field_offset);
        g_assert (func_pointer);
        invoke_c_code (vfunc_info, func_pointer,
@@ -841,7 +827,6 @@ _invoke_fallback_vfunc (class, vfunc_package, vfunc_name, target_package, ...)
         * pointer.  so we need to make sure that our local variable
         * 'sp' is correct before the implicit PUTBACK happens. */
        SPAGAIN;
-       g_base_info_unref (field_info);
        g_base_info_unref (vfunc_info);
        g_base_info_unref (info);
 
diff --git a/gperl-i11n-vfunc-interface.c b/gperl-i11n-vfunc-interface.c
index f67d89c..d66aa5d 100644
--- a/gperl-i11n-vfunc-interface.c
+++ b/gperl-i11n-vfunc-interface.c
@@ -30,7 +30,9 @@ generic_interface_init (gpointer iface, gpointer data)
                        perl_method_name = replacement;
                }
 
-               /* FIXME: g_vfunc_info_get_offset does not seem to work here. */
+               /* We use the field information here rather than the vfunc
+                * information so that the Perl invoker does not have to deal
+                * with an implicit invocant. */
                field_info = get_field_info (struct_info, vfunc_name);
                g_assert (field_info);
                field_offset = g_field_info_get_offset (field_info);
diff --git a/gperl-i11n-vfunc-object.c b/gperl-i11n-vfunc-object.c
index ea35d8c..b2b5282 100644
--- a/gperl-i11n-vfunc-object.c
+++ b/gperl-i11n-vfunc-object.c
@@ -56,7 +56,9 @@ generic_class_init (GIObjectInfo *info, const gchar *target_package, gpointer cl
                        }
                }
 
-               /* FIXME: g_vfunc_info_get_offset does not seem to work here. */
+               /* We use the field information here rather than the vfunc
+                * information so that the Perl invoker does not have to deal
+                * with an implicit invocant. */
                field_info = get_field_info (struct_info, vfunc_name);
                g_assert (field_info);
                field_offset = g_field_info_get_offset (field_info);
@@ -79,3 +81,27 @@ generic_class_init (GIObjectInfo *info, const gchar *target_package, gpointer cl
        }
        g_base_info_unref (struct_info);
 }
+
+/* ------------------------------------------------------------------------- */
+
+static gint
+get_vfunc_offset (GIObjectInfo *info, const gchar *vfunc_name)
+{
+       GIStructInfo *struct_info;
+       GIFieldInfo *field_info;
+       gint field_offset;
+
+       struct_info = g_object_info_get_class_struct (info);
+       g_assert (struct_info);
+
+       field_info = get_field_info (struct_info, vfunc_name);
+       g_assert (field_info);
+       field_offset = g_field_info_get_offset (field_info);
+
+       g_base_info_unref (field_info);
+       g_base_info_unref (struct_info);
+
+       return field_offset;
+}
+
+


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