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

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.

svn path=/trunk/; revision=132
This commit is contained in:
Mark Doffman 2008-03-10 17:47:20 +00:00 committed by Johan Dahlin
parent 0f2b1089ad
commit 4ab667b160
4 changed files with 12 additions and 85 deletions

11
ginfo.c
View File

@ -1,4 +1,4 @@
</* GObject introspection: Repository implementation
/* GObject introspection: Repository implementation
*
* Copyright (C) 2005 Matthias Clasen
*
@ -1045,6 +1045,15 @@ g_enum_info_get_n_values (GIEnumInfo *info)
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)

View File

@ -355,6 +355,7 @@ const gchar * g_registered_type_info_get_type_init (GIRegisteredTypeInf
/* 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);

View File

@ -42,41 +42,9 @@ g_metadata_get_dir_entry (GMetadata *metadata,
{
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 @@ validate_header (GMetadata *metadata,
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 @@ validate_struct_blob (GMetadata *metadata,
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 @@ validate_enum_blob (GMetadata *metadata,
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))
{

View File

@ -507,11 +507,8 @@ struct _GMetadata {
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,