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.
This commit is contained in:
Colin Walters 2009-02-11 23:36:31 -05:00
parent ff6c10e53c
commit 83c0d9b93b
2 changed files with 37 additions and 37 deletions

View File

@ -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];

View File

@ -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,