[gobject-introspection] Add "c:identifier" attribute to GIrNodeValue (for flags and enum values).



commit ed94a687d874c655386bcef662eb659aaca83ac5
Author: Laszlo Pandy <lpandy src gnome org>
Date:   Tue Feb 22 16:02:12 2011 +0100

    Add "c:identifier" attribute to GIrNodeValue (for flags and enum values).
    
    Flags and enums with a GType have a value_nick and value_name
    strings available in the class struct. But for flags and enums
    without GType, we need to get this information from introspection.
    
    g_base_info_get_name() gives the string for value_nick. In the GIR,
    the attribute "c:identifier" is the string neede for value_name.
    
    This patch adds the "c:identifier" from GIR to the typelib for all
    flags and enum values. It can be retireved using
    g_base_info_get_attribute(info, "c:identifier").
    
    https://bugzilla.gnome.org/show_bug.cgi?id=642757

 girepository/girparser.c         |    6 +++
 tests/repository/Makefile.am     |   10 ++++--
 tests/repository/gitypelibtest.c |   70 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 3 deletions(-)
---
diff --git a/girepository/girparser.c b/girepository/girparser.c
index be74e0b..e32acc0 100644
--- a/girepository/girparser.c
+++ b/girepository/girparser.c
@@ -1480,6 +1480,7 @@ start_member (GMarkupParseContext *context,
   const gchar *name;
   const gchar *value;
   const gchar *deprecated;
+  const gchar *c_identifier;
   GIrNodeEnum *enum_;
   GIrNodeValue *value_;
 
@@ -1490,6 +1491,7 @@ start_member (GMarkupParseContext *context,
   name = find_attribute ("name", attribute_names, attribute_values);
   value = find_attribute ("value", attribute_names, attribute_values);
   deprecated = find_attribute ("deprecated", attribute_names, attribute_values);
+  c_identifier = find_attribute ("c:identifier", attribute_names, attribute_values);
 
   if (name == NULL)
     {
@@ -1509,6 +1511,10 @@ start_member (GMarkupParseContext *context,
   else
     value_->deprecated = FALSE;
 
+  g_hash_table_insert (((GIrNode *)value_)->attributes,
+                       g_strdup ("c:identifier"),
+                       g_strdup (c_identifier));
+
   enum_ = (GIrNodeEnum *)CURRENT_NODE (ctx);
   enum_->values = g_list_append (enum_->values, value_);
 
diff --git a/tests/repository/Makefile.am b/tests/repository/Makefile.am
index a4557a9..268d9f9 100644
--- a/tests/repository/Makefile.am
+++ b/tests/repository/Makefile.am
@@ -2,7 +2,7 @@ AM_CFLAGS = $(GOBJECT_CFLAGS)
 AM_LDFLAGS = -module -avoid-version
 LIBS = $(GOBJECT_LIBS)
 
-noinst_PROGRAMS = gitestrepo gitestthrows
+noinst_PROGRAMS = gitestrepo gitestthrows gitypelibtest
 
 gitestrepo_SOURCES = $(srcdir)/gitestrepo.c
 gitestrepo_CPPFLAGS = $(GIREPO_CFLAGS) -I$(top_srcdir)/girepository
@@ -12,6 +12,10 @@ gitestthrows_SOURCES = $(srcdir)/gitestthrows.c
 gitestthrows_CPPFLAGS = $(GIREPO_CFLAGS) -I$(top_srcdir)/girepository
 gitestthrows_LDADD = $(top_builddir)/libgirepository-1.0.la $(GIREPO_LIBS)
 
-TESTS = gitestrepo gitestthrows
-TESTS_ENVIRONMENT=env GI_TYPELIB_PATH=$(top_builddir) \
+gitypelibtest_SOURCES = $(srcdir)/gitypelibtest.c
+gitypelibtest_CPPFLAGS = $(GIREPO_CFLAGS) -I$(top_srcdir)/girepository
+gitypelibtest_LDADD = $(top_builddir)/libgirepository-1.0.la $(GIREPO_LIBS)
+
+TESTS = gitestrepo gitestthrows gitypelibtest
+TESTS_ENVIRONMENT=env GI_TYPELIB_PATH=$(top_builddir):$(top_builddir)/tests \
    XDG_DATA_DIRS="$(top_srcdir)/gir:$(XDG_DATA_DIRS)" $(DEBUG)
diff --git a/tests/repository/gitypelibtest.c b/tests/repository/gitypelibtest.c
new file mode 100644
index 0000000..9e9b8d2
--- /dev/null
+++ b/tests/repository/gitypelibtest.c
@@ -0,0 +1,70 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * vim: tabstop=4 shiftwidth=4 expandtab
+ */
+
+#include "girepository.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static void
+test_enum_and_flags_cidentifier(GIRepository *repo)
+{
+    GITypelib *ret;
+    GError *error = NULL;
+    gint n_infos, i;
+
+    ret = g_irepository_require (repo, "GIMarshallingTests", NULL, 0, &error);
+    if (!ret)
+        g_error ("%s", error->message);
+
+    n_infos = g_irepository_get_n_infos (repo, "GIMarshallingTests");
+
+    for (i = 0; i < n_infos; i++) {
+        GIBaseInfo *info;
+        GIInfoType type;
+
+        info = g_irepository_get_info (repo, "GIMarshallingTests", i);
+        type = g_base_info_get_type (info);
+
+        /* both GI_INFO_TYPE_ENUM and GI_INFO_TYPE_FLAGS use GIEnumInfo */
+        if (GI_IS_ENUM_INFO (info)) {
+            gint n_values, j;
+
+            n_values = g_enum_info_get_n_values ((GIEnumInfo *) info);
+            for (j = 0; j < n_values; j++) {
+                GIValueInfo *value_info;
+                const gchar *c_identifier = NULL;
+
+                value_info = g_enum_info_get_value ((GIEnumInfo *) info, j);
+                c_identifier = g_base_info_get_attribute ((GIBaseInfo *) value_info, "c:identifier");
+
+                if (c_identifier == NULL) {
+                    g_error ("Error: no 'c:identifier' attribute on GIMarshallingTests.%s.%s\n",
+                             g_base_info_get_name (info),
+                             g_base_info_get_name ((GIBaseInfo *) value_info));
+                }
+
+                g_base_info_unref ((GIBaseInfo *) value_info);
+            }
+        }
+
+        g_base_info_unref (info);
+    }
+}
+
+int
+main(int argc, char **argv)
+{
+    GIRepository *repo;
+
+    g_type_init ();
+
+    repo = g_irepository_get_default ();
+
+    /* do tests */
+    test_enum_and_flags_cidentifier (repo);
+
+    exit(0);
+}



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