widl: Add padding to the end of complex structures.

This commit is contained in:
Dan Hipschman 2007-09-13 18:04:32 -07:00 committed by Alexandre Julliard
parent 1ca7435754
commit 5e84eb9a47
5 changed files with 59 additions and 0 deletions

View File

@ -344,6 +344,12 @@ s_sum_aligns(aligns_t *a)
return a->c + a->i + a->s + a->d; return a->c + a->i + a->s + a->d;
} }
int
s_sum_padded(padded_t *p)
{
return p->i + p->c;
}
void void
s_stop(void) s_stop(void)
{ {
@ -392,6 +398,7 @@ basic_tests(void)
static aligns_t aligns = {3, 4, 5, 6.0}; static aligns_t aligns = {3, 4, 5, 6.0};
pints_t pints; pints_t pints;
ptypes_t ptypes; ptypes_t ptypes;
padded_t padded;
int i1, i2, i3, *pi2, *pi3, **ppi3; int i1, i2, i3, *pi2, *pi3, **ppi3;
double u, v; double u, v;
float s, t; float s, t;
@ -465,6 +472,10 @@ basic_tests(void)
ok(enum_ord(E4) == 4, "RPC enum_ord\n"); ok(enum_ord(E4) == 4, "RPC enum_ord\n");
ok(sum_aligns(&aligns) == 18.0, "RPC sum_aligns\n"); ok(sum_aligns(&aligns) == 18.0, "RPC sum_aligns\n");
padded.i = -3;
padded.c = 8;
ok(sum_padded(&padded) == 5, "RPC sum_padded\n");
} }
static void static void

View File

@ -200,5 +200,13 @@ interface IServer
double sum_aligns(aligns_t *a); double sum_aligns(aligns_t *a);
typedef struct
{
int i;
char c;
} padded_t;
int sum_padded(padded_t *p);
void stop(void); void stop(void);
} }

View File

@ -1679,6 +1679,9 @@ static int get_struct_type(var_list_t *fields)
int has_variance = 0; int has_variance = 0;
var_t *field; var_t *field;
if (get_padding(fields))
return RPC_FC_BOGUS_STRUCT;
if (fields) LIST_FOR_EACH_ENTRY( field, fields, var_t, entry ) if (fields) LIST_FOR_EACH_ENTRY( field, fields, var_t, entry )
{ {
type_t *t = field->type; type_t *t = field->type;

View File

@ -726,6 +726,29 @@ static size_t union_memsize(const var_list_t *fields, unsigned int *pmaxa)
return maxs; return maxs;
} }
int get_padding(const var_list_t *fields)
{
unsigned short offset = 0;
int salign = -1;
const var_t *f;
if (!fields)
return 0;
LIST_FOR_EACH_ENTRY(f, fields, const var_t, entry)
{
type_t *ft = f->type;
unsigned int align = 0;
size_t size = type_memsize(ft, &align);
if (salign == -1)
salign = align;
offset = (offset + (align - 1)) & ~(align - 1);
offset += size;
}
return ((offset + (salign - 1)) & ~(salign - 1)) - offset;
}
size_t type_memsize(const type_t *t, unsigned int *align) size_t type_memsize(const type_t *t, unsigned int *align)
{ {
size_t size = 0; size_t size = 0;
@ -1518,6 +1541,8 @@ static void write_struct_members(FILE *file, const type_t *type,
{ {
const var_t *field; const var_t *field;
unsigned short offset = 0; unsigned short offset = 0;
int salign = -1;
int padding;
if (type->fields) LIST_FOR_EACH_ENTRY( field, type->fields, const var_t, entry ) if (type->fields) LIST_FOR_EACH_ENTRY( field, type->fields, const var_t, entry )
{ {
@ -1526,6 +1551,8 @@ static void write_struct_members(FILE *file, const type_t *type,
{ {
unsigned int align = 0; unsigned int align = 0;
size_t size = type_memsize(ft, &align); size_t size = type_memsize(ft, &align);
if (salign == -1)
salign = align;
if ((align - 1) & offset) if ((align - 1) & offset)
{ {
unsigned char fc = 0; unsigned char fc = 0;
@ -1549,6 +1576,15 @@ static void write_struct_members(FILE *file, const type_t *type,
} }
} }
padding = ((offset + (salign - 1)) & ~(salign - 1)) - offset;
if (padding)
{
print_file(file, 2, "0x%x,\t/* FC_STRUCTPAD%d */\n",
RPC_FC_STRUCTPAD1 + padding - 1,
padding);
*typestring_offset += 1;
}
write_end(file, typestring_offset); write_end(file, typestring_offset);
} }

View File

@ -55,3 +55,4 @@ size_t type_memsize(const type_t *t, unsigned int *align);
int decl_indirect(const type_t *t); int decl_indirect(const type_t *t);
void write_parameters_init(FILE *file, int indent, const func_t *func); void write_parameters_init(FILE *file, int indent, const func_t *func);
void print(FILE *file, int indent, const char *format, va_list ap); void print(FILE *file, int indent, const char *format, va_list ap);
int get_padding(const var_list_t *fields);