gobject-introspection r132 - in trunk: girepository tools



Author: johan
Date: Mon Mar 10 17:47:20 2008
New Revision: 132
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=132&view=rev

Log:
2008-02-21  Mark Doffman  <mark doffman codethink co uk>

    * girepository/ginfo.c
    * girepository/girepository.h
    * tools/generate.c

      Add a function to check if an enum is registered or not.
      Previously anything testing this relied on the g-type
      string offset having a value of 0.

    * girepository/gmetadata.c
    * girepository/gmetadata.h
    * tools/generate.c

      Remove unneccesary or erroneous checks. There were two
      metadata validation checks which made sure that the blob
      sizes were the same as some magic numbers compiled into the code.
      This is wrong as it breaks any forwards compatibility that may
      be possible.

      Checks were also present that made sure that unregistered type
      blobs had a value of 0 in the g-type offset field. This is
      unneccessary. If a type blob is unregistered then any value
      in its g-type field is simply invalid.

WARNING: This commit does not compile. It is a partial change.


Modified:
   trunk/girepository/ginfo.c
   trunk/girepository/girepository.h
   trunk/girepository/gmetadata.c
   trunk/girepository/gmetadata.h
   trunk/tools/generate.c

Modified: trunk/girepository/ginfo.c
==============================================================================
--- trunk/girepository/ginfo.c	(original)
+++ trunk/girepository/ginfo.c	Mon Mar 10 17:47:20 2008
@@ -1,4 +1,4 @@
-</* GObject introspection: Repository implementation
+/* GObject introspection: Repository implementation
  *
  * Copyright (C) 2005 Matthias Clasen
  *
@@ -1045,6 +1045,15 @@
   return blob->n_values;
 }
 
+gboolean
+g_enum_info_is_registered (GIEnumInfo *info)
+{
+  GIBaseInfo *base = (GIBaseInfo *)info;
+  EnumBlob *blob = (EnumBlob *)&base->metadata->data[base->offset];
+
+  return !blob->unregistered;
+}
+
 GIValueInfo *
 g_enum_info_get_value (GIEnumInfo *info,
 		       gint            n)

Modified: trunk/girepository/girepository.h
==============================================================================
--- trunk/girepository/girepository.h	(original)
+++ trunk/girepository/girepository.h	Mon Mar 10 17:47:20 2008
@@ -355,6 +355,7 @@
 /* GIEnumInfo */
 
 gint                   g_enum_info_get_n_values             (GIEnumInfo      *info);
+gboolean               g_enum_info_get_is_registered        (GIEnumInfo      *info);
 GIValueInfo  *         g_enum_info_get_value                (GIEnumInfo      *info,
 							     gint            n);
 

Modified: trunk/girepository/gmetadata.c
==============================================================================
--- trunk/girepository/gmetadata.c	(original)
+++ trunk/girepository/gmetadata.c	Mon Mar 10 17:47:20 2008
@@ -42,41 +42,9 @@
 {
   Header *header = (Header *)metadata->data;
 
-  return (DirEntry *)&metadata->data[header->directory + (index - 1) * header->entry_blob_size];
+  return (DirEntry *)&metadata->data[header->directory + ((index - 1) * header->entry_blob_size)];
 }
 
-void    
-g_metadata_check_sanity (void)
-{
-  /* Check that struct layout is as we expect */
-  g_assert (sizeof (Header) == 100);
-  g_assert (sizeof (DirEntry) == 12);
-  g_assert (sizeof (SimpleTypeBlob) == 4);
-  g_assert (sizeof (ArgBlob) == 12);
-  g_assert (sizeof (SignatureBlob) == 8);
-  g_assert (sizeof (CommonBlob) == 8);
-  g_assert (sizeof (FunctionBlob) == 16);
-  g_assert (sizeof (InterfaceTypeBlob) == 4);
-  g_assert (sizeof (ArrayTypeBlob) == 8);
-  g_assert (sizeof (ParamTypeBlob) == 4);
-  g_assert (sizeof (ErrorTypeBlob) == 4);
-  g_assert (sizeof (ErrorDomainBlob) == 16);
-  g_assert (sizeof (ValueBlob) == 12);
-  g_assert (sizeof (FieldBlob) == 12);
-  g_assert (sizeof (RegisteredTypeBlob) == 16);
-  g_assert (sizeof (StructBlob) == 20);
-  g_assert (sizeof (EnumBlob) == 20);
-  g_assert (sizeof (PropertyBlob) == 12);
-  g_assert (sizeof (SignalBlob) == 12);
-  g_assert (sizeof (VFuncBlob) == 16);
-  g_assert (sizeof (ObjectBlob) == 32);
-  g_assert (sizeof (InterfaceBlob) == 28);
-  g_assert (sizeof (ConstantBlob) == 20);
-  g_assert (sizeof (AnnotationBlob) == 12);
-  g_assert (sizeof (UnionBlob) == 28);
-}
-
-
 static gboolean
 is_aligned (guint32 offset)
 {
@@ -156,32 +124,6 @@
       return FALSE; 
     }
 
-  if (header->entry_blob_size != 12 ||
-      header->function_blob_size != 16 ||
-      header->callback_blob_size != 12 ||
-      header->signal_blob_size != 12 ||
-      header->vfunc_blob_size != 16 ||
-      header->arg_blob_size != 12 ||
-      header->property_blob_size != 12 ||
-      header->field_blob_size != 12 ||
-      header->value_blob_size != 12 ||
-      header->constant_blob_size != 20 ||
-      header->error_domain_blob_size != 16 ||
-      header->annotation_blob_size != 12 ||
-      header->signature_blob_size != 8 ||
-      header->enum_blob_size != 20 ||
-      header->struct_blob_size != 20 ||
-      header->object_blob_size != 32 ||
-      header->interface_blob_size != 28 ||
-      header->union_blob_size != 28)
-    {
-      g_set_error (error,
-		   G_METADATA_ERROR,
-		   G_METADATA_ERROR_INVALID_HEADER,
-		   "Blob size mismatch");
-      return FALSE; 
-    }
-
   if (!is_aligned (header->directory))
     {
       g_set_error (error,
@@ -1046,17 +988,6 @@
 	  return FALSE; 
 	}
     }
-  else
-    {
-      if (blob->gtype_name || blob->gtype_init)
-	{
-	  g_set_error (error,
-		       G_METADATA_ERROR,
-		       G_METADATA_ERROR_INVALID_BLOB,
-		       "Gtype data in struct");
-	  return FALSE; 
-	}
-    }
 
   if (metadata->len < offset + sizeof (StructBlob) + 
             blob->n_fields * sizeof (FieldBlob) +
@@ -1142,17 +1073,6 @@
 	  return FALSE; 
 	}
     }
-  else
-    {
-      if (blob->gtype_name || blob->gtype_init)
-	{
-	  g_set_error (error,
-		       G_METADATA_ERROR,
-		       G_METADATA_ERROR_INVALID_BLOB,
-		       "Gtype data in unregistered enum");
-	  return FALSE; 
-	}
-    }
 
   if (!is_name (metadata->data, blob->name))
     {

Modified: trunk/girepository/gmetadata.h
==============================================================================
--- trunk/girepository/gmetadata.h	(original)
+++ trunk/girepository/gmetadata.h	Mon Mar 10 17:47:20 2008
@@ -507,11 +507,8 @@
 DirEntry *g_metadata_get_dir_entry (GMetadata *metadata,
 				    guint16            index);
 
-void      g_metadata_check_sanity (void);
-
 #define   g_metadata_get_string(metadata,offset) ((const gchar*)&(metadata->data)[(offset)])
 
-
 typedef enum
 {
   G_METADATA_ERROR_INVALID,

Modified: trunk/tools/generate.c
==============================================================================
--- trunk/tools/generate.c	(original)
+++ trunk/tools/generate.c	Mon Mar 10 17:47:20 2008
@@ -574,16 +574,22 @@
 		 FILE        *file)
 {
   const gchar *name;
-  const gchar *type_name;
-  const gchar *type_init;
+  const gchar *type_name = NULL;
+  const gchar *type_init = NULL;
   gboolean deprecated;
   gint i;
 
   name = g_base_info_get_name ((GIBaseInfo *)info);
   deprecated = g_base_info_is_deprecated ((GIBaseInfo *)info);
 
-  type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info);
-  type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info);
+  /* Make sure this is a registered enum before filling out the
+   * GType information
+   */
+  if (g_enum_info_is_registered ((GIEnumInfo *)info))
+    {
+      type_name = g_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info);
+      type_init = g_registered_type_info_get_type_init ((GIRegisteredTypeInfo*)info);
+    }
 
   if (g_base_info_get_type ((GIBaseInfo *)info) == GI_INFO_TYPE_ENUM)
     g_fprintf (file, "    <enum ");
@@ -1148,8 +1154,6 @@
 
   g_type_init ();
 
-  g_metadata_check_sanity ();
-
   context = g_option_context_new ("");
   g_option_context_add_main_entries (context, options, NULL);
   g_option_context_parse (context, &argc, &argv, &error);



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