From 4ab667b160f860870a05bc54079c73758dcae7db Mon Sep 17 00:00:00 2001 From: Mark Doffman Date: Mon, 10 Mar 2008 17:47:20 +0000 Subject: [PATCH] girepository/ginfo.c girepository/girepository.h tools/generate.c 2008-02-21 Mark Doffman * 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 --- ginfo.c | 11 ++++++- girepository.h | 1 + gmetadata.c | 82 +------------------------------------------------- gmetadata.h | 3 -- 4 files changed, 12 insertions(+), 85 deletions(-) diff --git a/ginfo.c b/ginfo.c index 0537654c1..67385c354 100644 --- a/ginfo.c +++ b/ginfo.c @@ -1,4 +1,4 @@ -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) diff --git a/girepository.h b/girepository.h index 179d85fcd..0c1ac6630 100644 --- a/girepository.h +++ b/girepository.h @@ -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); diff --git a/gmetadata.c b/gmetadata.c index 436969d00..8c9827023 100644 --- a/gmetadata.c +++ b/gmetadata.c @@ -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)) { diff --git a/gmetadata.h b/gmetadata.h index 8c0f2b04d..345749174 100644 --- a/gmetadata.h +++ b/gmetadata.h @@ -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,