Bug 563469 – Arrays not treated correctly in struct offset calculation

Arrays are currently not handled specially, and hence treated as pointers in
giroffsets.c:get_field_size_alignment(), which is (obviously) wrong.

svn path=/trunk/; revision=1078
This commit is contained in:
Colin Walters 2009-02-02 16:31:02 +00:00
parent 3353523d11
commit 4e5037e0f3

View File

@ -144,21 +144,19 @@ get_enum_size_alignment (GIrNodeEnum *enum_node,
} }
static gboolean static gboolean
get_interface_size_alignment (GIrNodeField *field, get_interface_size_alignment (GIrNodeType *type,
GIrNode *parent_node,
GIrModule *module, GIrModule *module,
GList *modules, GList *modules,
gint *size, gint *size,
gint *alignment) gint *alignment,
const char *who)
{ {
GIrNodeType *type = field->type;
GIrNode *iface; GIrNode *iface;
GIrModule *iface_module; GIrModule *iface_module;
if (!g_ir_find_node (module, modules, type->interface, &iface, &iface_module)) if (!g_ir_find_node (module, modules, type->interface, &iface, &iface_module))
{ {
g_warning ("Can't resolve type '%s' for field %s.%s.%s", g_warning ("Can't resolve type '%s' for %s", type->interface, who);
type->interface, module->name, parent_node->name, ((GIrNode *)field)->name);
*size = -1; *size = -1;
*alignment = -1; *alignment = -1;
return FALSE; return FALSE;
@ -212,8 +210,8 @@ get_interface_size_alignment (GIrNodeField *field,
} }
default: default:
{ {
g_warning ("Field %s.%s.%s has is not a pointer and is of type %s", g_warning ("%s has is not a pointer and is of type %s",
module->name, parent_node->name, ((GIrNode *)field)->name, who,
g_ir_node_type_to_string (iface->type)); g_ir_node_type_to_string (iface->type));
*size = -1; *size = -1;
*alignment = -1; *alignment = -1;
@ -225,17 +223,34 @@ get_interface_size_alignment (GIrNodeField *field,
} }
static gboolean static gboolean
get_field_size_alignment (GIrNodeField *field, get_type_size_alignment (GIrNodeType *type,
GIrNode *parent_node,
GIrModule *module, GIrModule *module,
GList *modules, GList *modules,
gint *size, gint *size,
gint *alignment) gint *alignment,
const char *who)
{ {
GIrNodeType *type = field->type;
ffi_type *type_ffi; ffi_type *type_ffi;
if (type->is_pointer) if (type->tag == GI_TYPE_TAG_ARRAY)
{
gint elt_size, elt_alignment;
if (!type->has_size
|| !get_type_size_alignment(type->parameter_type1, module, modules,
&elt_size, &elt_alignment, who))
{
*size = -1;
*alignment = -1;
return FALSE;
}
*size = type->size * elt_size;
*alignment = elt_alignment;
return TRUE;
}
else if (type->is_pointer)
{ {
type_ffi = &ffi_type_pointer; type_ffi = &ffi_type_pointer;
} }
@ -243,9 +258,7 @@ get_field_size_alignment (GIrNodeField *field,
{ {
if (type->tag == GI_TYPE_TAG_INTERFACE) if (type->tag == GI_TYPE_TAG_INTERFACE)
{ {
return get_interface_size_alignment (field, parent_node, return get_interface_size_alignment (type, module, modules, size, alignment, who);
module, modules,
size, alignment);
} }
else else
{ {
@ -253,16 +266,15 @@ get_field_size_alignment (GIrNodeField *field,
if (type_ffi == &ffi_type_void) if (type_ffi == &ffi_type_void)
{ {
g_warning ("Field %s.%s.%s has void type", g_warning ("%s has void type", who);
module->name, parent_node->name, ((GIrNode *)field)->name);
*size = -1; *size = -1;
*alignment = -1; *alignment = -1;
return FALSE; return FALSE;
} }
else if (type_ffi == &ffi_type_pointer) else if (type_ffi == &ffi_type_pointer)
{ {
g_warning ("Field %s.%s.%s has is not a pointer and is of type %s", g_warning ("%s has is not a pointer and is of type %s",
module->name, parent_node->name, ((GIrNode *)field)->name, who,
g_type_tag_to_string (type->tag)); g_type_tag_to_string (type->tag));
*size = -1; *size = -1;
*alignment = -1; *alignment = -1;
@ -278,6 +290,25 @@ get_field_size_alignment (GIrNodeField *field,
return TRUE; return TRUE;
} }
static gboolean
get_field_size_alignment (GIrNodeField *field,
GIrNode *parent_node,
GIrModule *module,
GList *modules,
gint *size,
gint *alignment)
{
gchar *who;
gboolean success;
who = g_strdup_printf ("field %s.%s.%s", module->name, parent_node->name, ((GIrNode *)field)->name);
success = get_type_size_alignment (field->type, module, modules, size, alignment, who);
g_free (who);
return success;
}
#define ALIGN(n, align) (((n) + (align) - 1) & ~((align) - 1)) #define ALIGN(n, align) (((n) + (align) - 1) & ~((align) - 1))
static gboolean static gboolean