Alexandre Julliard : widl: Take into account structure field alignment when computing offsets.
Alexandre Julliard
julliard at winehq.org
Fri Jul 3 09:31:09 CDT 2009
Module: wine
Branch: master
Commit: f6d2b49145e16cacc694f08b5b4442358c7c6718
URL: http://source.winehq.org/git/wine.git/?a=commit;h=f6d2b49145e16cacc694f08b5b4442358c7c6718
Author: Alexandre Julliard <julliard at winehq.org>
Date: Fri Jul 3 12:02:30 2009 +0200
widl: Take into account structure field alignment when computing offsets.
---
tools/widl/typegen.c | 22 +++++++++++++++-------
1 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/tools/widl/typegen.c b/tools/widl/typegen.c
index 5abf575..9b39c63 100644
--- a/tools/widl/typegen.c
+++ b/tools/widl/typegen.c
@@ -59,6 +59,7 @@ struct expr_eval_routine
const expr_t *expr;
};
+static unsigned int field_memsize(const type_t *type, unsigned int *offset);
static unsigned int fields_memsize(const var_list_t *fields, unsigned int *align);
static unsigned int write_struct_tfs(FILE *file, type_t *type, const char *name, unsigned int *tfsoff);
static int write_embedded_types(FILE *file, const attr_list_t *attrs, type_t *type,
@@ -978,14 +979,13 @@ static unsigned int write_conf_or_var_desc(FILE *file, const type_t *structure,
if (fields) LIST_FOR_EACH_ENTRY( var, fields, const var_t, entry )
{
- unsigned int align = 0;
- /* FIXME: take alignment into account */
+ unsigned int size = field_memsize( var->type, &offset );
if (var->name && !strcmp(var->name, subexpr->u.sval))
{
correlation_variable = var->type;
break;
}
- offset += type_memsize(var->type, &align);
+ offset += size;
}
if (!correlation_variable)
error("write_conf_or_var_desc: couldn't find variable %s in structure\n",
@@ -1081,6 +1081,16 @@ static unsigned int write_conf_or_var_desc(FILE *file, const type_t *structure,
return 4;
}
+/* return size and start offset of a data field based on current offset */
+static unsigned int field_memsize(const type_t *type, unsigned int *offset)
+{
+ unsigned int align = 0;
+ unsigned int size = type_memsize( type, &align );
+
+ *offset = ROUND_SIZE( *offset, align );
+ return size;
+}
+
static unsigned int fields_memsize(const var_list_t *fields, unsigned int *align)
{
unsigned int size = 0;
@@ -1511,8 +1521,8 @@ static void write_descriptors(FILE *file, type_t *type, unsigned int *tfsoff)
if (fs) LIST_FOR_EACH_ENTRY(f, fs, var_t, entry)
{
- unsigned int align = 0;
type_t *ft = f->type;
+ unsigned int size = field_memsize( ft, &offset );
if (type_get_type(ft) == TYPE_UNION && is_attr(f->attrs, ATTR_SWITCHIS))
{
short reloff;
@@ -1529,9 +1539,7 @@ static void write_descriptors(FILE *file, type_t *type, unsigned int *tfsoff)
reloff, reloff, absoff);
*tfsoff += 8;
}
-
- /* FIXME: take alignment into account */
- offset += type_memsize(ft, &align);
+ offset += size;
}
}
More information about the wine-cvs
mailing list