Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2009-02-12 04:36:31 (GMT)
committer Colin Walters <walters@verbum.org>2009-02-19 02:54:03 (GMT)
commitfdeaf8e51dbcb5ed909249d74c0d711d6dfb6e2d (patch)
treea2e301725a33ef7ec67ae438637017f74f3ff9bd
parent5b613e587adbd1c69eb9c568e5966c32bdc30258 (diff)
Bug 571373 - Consistently use sizeof () inside gtypelib and girmodule
This not only makes it easier to change these structures, it becomes clearer exactly what each magic number is just for reference.
-rw-r--r--girepository/girmodule.c34
-rw-r--r--girepository/gtypelib.c40
2 files changed, 37 insertions, 37 deletions
diff --git a/girepository/girmodule.c b/girepository/girmodule.c
index 63d42cc..5f5ae09 100644
--- a/girepository/girmodule.c
+++ b/girepository/girmodule.c
@@ -163,7 +163,7 @@ g_ir_module_build_typelib (GIrModule *module,
g_message ("%d entries (%d local), %d dependencies\n", n_entries, n_local_entries,
g_list_length (module->dependencies));
- dir_size = n_entries * 12;
+ dir_size = n_entries * sizeof (DirEntry);
size = header_size + dir_size;
size += ALIGN_VALUE (strlen (module->name) + 1, 4);
@@ -208,24 +208,24 @@ g_ir_module_build_typelib (GIrModule *module,
write_string (module->shared_library, strings, data, &header_size)
: 0);
header->directory = ALIGN_VALUE (header_size, 4);
- header->entry_blob_size = 12;
+ header->entry_blob_size = sizeof (DirEntry);
header->function_blob_size = sizeof (FunctionBlob);
- header->callback_blob_size = 12;
- header->signal_blob_size = 12;
- header->vfunc_blob_size = 16;
- header->arg_blob_size = 16;
- 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 = 24;
+ header->callback_blob_size = sizeof (CallbackBlob);
+ header->signal_blob_size = sizeof (SignalBlob);
+ header->vfunc_blob_size = sizeof (VFuncBlob);
+ header->arg_blob_size = sizeof (ArgBlob);
+ header->property_blob_size = sizeof (PropertyBlob);
+ header->field_blob_size = sizeof (FieldBlob);
+ header->value_blob_size = sizeof (ValueBlob);
+ header->constant_blob_size = sizeof (ConstantBlob);
+ header->error_domain_blob_size = sizeof (ErrorDomainBlob);
+ header->annotation_blob_size = sizeof (AnnotationBlob);
+ header->signature_blob_size = sizeof (SignatureBlob);
+ header->enum_blob_size = sizeof (EnumBlob);
+ header->struct_blob_size = sizeof (StructBlob);
header->object_blob_size = sizeof(ObjectBlob);
- header->interface_blob_size = 28;
- header->union_blob_size = 32;
+ header->interface_blob_size = sizeof (InterfaceBlob);
+ header->union_blob_size = sizeof (UnionBlob);
/* fill in directory and content */
entry = (DirEntry *)&data[header->directory];
diff --git a/girepository/gtypelib.c b/girepository/gtypelib.c
index b228a23..6de6217 100644
--- a/girepository/gtypelib.c
+++ b/girepository/gtypelib.c
@@ -168,6 +168,7 @@ g_typelib_check_sanity (void)
CHECK_SIZE (SignatureBlob, 8);
CHECK_SIZE (CommonBlob, 8);
CHECK_SIZE (FunctionBlob, 20);
+ CHECK_SIZE (CallbackBlob, 12);
CHECK_SIZE (InterfaceTypeBlob, 4);
CHECK_SIZE (ArrayTypeBlob, 8);
CHECK_SIZE (ParamTypeBlob, 4);
@@ -315,32 +316,31 @@ validate_header (ValidateContext *ctx,
}
/* This is a sanity check for a specific typelib; it
- * prevents us from loading an incompatible typelib. It's OK to change
- * these hardcoded constants to sizeof() as you see fit.
+ * prevents us from loading an incompatible typelib.
*
- * We want to keep the hardcoded checks in g_typelib_check_sanity to
+ * The hardcoded checks in g_typelib_check_sanity to
* protect against inadvertent or buggy changes to the typelib format
* itself.
*/
- if (header->entry_blob_size != 12 ||
- header->function_blob_size != 20 ||
- header->callback_blob_size != 12 ||
- header->signal_blob_size != 12 ||
- header->vfunc_blob_size != 16 ||
- header->arg_blob_size != 16 ||
- 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 != 24 ||
+ if (header->entry_blob_size != sizeof (DirEntry) ||
+ header->function_blob_size != sizeof (FunctionBlob) ||
+ header->callback_blob_size != sizeof (CallbackBlob) ||
+ header->signal_blob_size != sizeof (SignalBlob) ||
+ header->vfunc_blob_size != sizeof (VFuncBlob) ||
+ header->arg_blob_size != sizeof (ArgBlob) ||
+ header->property_blob_size != sizeof (PropertyBlob) ||
+ header->field_blob_size != sizeof (FieldBlob) ||
+ header->value_blob_size != sizeof (ValueBlob) ||
+ header->constant_blob_size != sizeof (ConstantBlob) ||
+ header->error_domain_blob_size != sizeof (ErrorDomainBlob) ||
+ header->annotation_blob_size != sizeof (AnnotationBlob) ||
+ header->signature_blob_size != sizeof (SignatureBlob) ||
+ header->enum_blob_size != sizeof (EnumBlob) ||
+ header->struct_blob_size != sizeof (StructBlob) ||
header->object_blob_size != sizeof(ObjectBlob) ||
- header->interface_blob_size != 28 ||
- header->union_blob_size != 32)
+ header->interface_blob_size != sizeof (InterfaceBlob) ||
+ header->union_blob_size != sizeof (UnionBlob))
{
g_set_error (error,
G_TYPELIB_ERROR,