Commit 50a7b239 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

widl: Generate correct size and alignment for all types.

Using type_memsize_and_alignment() directly instead of reimplementing it. Also fix the generated tests in oleaut32 to reflect correct sizes for 64-bit typelibs. Signed-off-by: 's avatarZebediah Figura <z.figura12@gmail.com> Signed-off-by: 's avatarHuw Davies <huw@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 70e5d5fd
......@@ -3951,8 +3951,46 @@ static char *print_size(BSTR name, TYPEATTR *attr)
sprintf(buf, "sizeof(union %s)", dump_string(name));
break;
case TKIND_ALIAS:
sprintf(buf, "sizeof(%s)", dump_string(name));
break;
case TKIND_ENUM:
sprintf(buf, "4");
break;
default:
assert(0);
return NULL;
}
return buf;
}
static char *print_align(BSTR name, TYPEATTR *attr)
{
static char buf[256];
switch (attr->typekind)
{
case TKIND_DISPATCH:
case TKIND_INTERFACE:
sprintf(buf, "TYPE_ALIGNMENT(%s*)", dump_string(name));
break;
case TKIND_RECORD:
sprintf(buf, "TYPE_ALIGNMENT(struct %s)", dump_string(name));
break;
case TKIND_UNION:
sprintf(buf, "TYPE_ALIGNMENT(union %s)", dump_string(name));
break;
case TKIND_ALIAS:
sprintf(buf, "TYPE_ALIGNMENT(%s)", dump_string(name));
break;
case TKIND_ENUM:
sprintf(buf, "4");
break;
......@@ -4072,10 +4110,10 @@ static void test_dump_typelib(const char *name)
printf(" \"%s\",\n", wine_dbgstr_guid(&attr->guid));
printf(" /*kind*/ %s, /*flags*/ %s, /*align*/ %d, /*size*/ %s,\n"
printf(" /*kind*/ %s, /*flags*/ %s, /*align*/ %s, /*size*/ %s,\n"
" /*helpctx*/ 0x%04x, /*version*/ 0x%08x, /*#vtbl*/ %d, /*#func*/ %d",
map_value(attr->typekind, tkind_map), dump_type_flags(attr->wTypeFlags),
attr->cbAlignment, print_size(name, attr),
print_align(name, attr), print_size(name, attr),
help_ctx, MAKELONG(attr->wMinorVerNum, attr->wMajorVerNum),
attr->cbSizeVft/sizeof(void*), attr->cFuncs);
......@@ -4175,13 +4213,13 @@ static const type_info info[] = {
{
"g",
"{b14b6bb5-904e-4ff9-b247-bd361f7a0001}",
/*kind*/ TKIND_RECORD, /*flags*/ 0, /*align*/ 4, /*size*/ sizeof(struct g),
/*kind*/ TKIND_RECORD, /*flags*/ 0, /*align*/ TYPE_ALIGNMENT(struct g), /*size*/ sizeof(struct g),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
"test_iface",
"{b14b6bb5-904e-4ff9-b247-bd361f7a0002}",
/*kind*/ TKIND_INTERFACE, /*flags*/ 0, /*align*/ 4, /*size*/ sizeof(test_iface*),
/*kind*/ TKIND_INTERFACE, /*flags*/ 0, /*align*/ TYPE_ALIGNMENT(test_iface*), /*size*/ sizeof(test_iface*),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 4, /*#func*/ 1,
{
{
......@@ -4203,7 +4241,7 @@ static const type_info info[] = {
{
"parent_iface",
"{b14b6bb5-904e-4ff9-b247-bd361f7aa001}",
/*kind*/ TKIND_INTERFACE, /*flags*/ 0, /*align*/ 4, /*size*/ sizeof(parent_iface*),
/*kind*/ TKIND_INTERFACE, /*flags*/ 0, /*align*/ TYPE_ALIGNMENT(parent_iface*), /*size*/ sizeof(parent_iface*),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 4, /*#func*/ 1,
{
{
......@@ -4225,7 +4263,7 @@ static const type_info info[] = {
{
"child_iface",
"{b14b6bb5-904e-4ff9-b247-bd361f7aa002}",
/*kind*/ TKIND_INTERFACE, /*flags*/ 0, /*align*/ 4, /*size*/ sizeof(child_iface*),
/*kind*/ TKIND_INTERFACE, /*flags*/ 0, /*align*/ TYPE_ALIGNMENT(child_iface*), /*size*/ sizeof(child_iface*),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 5, /*#func*/ 1,
{
{
......@@ -4245,43 +4283,43 @@ static const type_info info[] = {
{
"_n",
"{016fe2ec-b2c8-45f8-b23b-39e53a753903}",
/*kind*/ TKIND_RECORD, /*flags*/ 0, /*align*/ 4, /*size*/ sizeof(struct _n),
/*kind*/ TKIND_RECORD, /*flags*/ 0, /*align*/ TYPE_ALIGNMENT(struct _n), /*size*/ sizeof(struct _n),
/*helpctx*/ 0x0003, /*version*/ 0x00010002, /*#vtbl*/ 0, /*#func*/ 0
},
{
"n",
"{016fe2ec-b2c8-45f8-b23b-39e53a753902}",
/*kind*/ TKIND_ALIAS, /*flags*/ TYPEFLAG_FHIDDEN, /*align*/ 4, /*size*/ 4,
/*kind*/ TKIND_ALIAS, /*flags*/ TYPEFLAG_FHIDDEN, /*align*/ TYPE_ALIGNMENT(n), /*size*/ sizeof(n),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
"nn",
"{00000000-0000-0000-0000-000000000000}",
/*kind*/ TKIND_ALIAS, /*flags*/ 0, /*align*/ 4, /*size*/ 4,
/*kind*/ TKIND_ALIAS, /*flags*/ 0, /*align*/ TYPE_ALIGNMENT(nn), /*size*/ sizeof(nn),
/*helpctx*/ 0x0003, /*version*/ 0x00010002, /*#vtbl*/ 0, /*#func*/ 0
},
{
"_m",
"{016fe2ec-b2c8-45f8-b23b-39e53a753906}",
/*kind*/ TKIND_RECORD, /*flags*/ 0, /*align*/ 4, /*size*/ sizeof(struct _m),
/*kind*/ TKIND_RECORD, /*flags*/ 0, /*align*/ TYPE_ALIGNMENT(struct _m), /*size*/ sizeof(struct _m),
/*helpctx*/ 0x0003, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
"m",
"{016fe2ec-b2c8-45f8-b23b-39e53a753905}",
/*kind*/ TKIND_ALIAS, /*flags*/ TYPEFLAG_FHIDDEN, /*align*/ 4, /*size*/ 4,
/*kind*/ TKIND_ALIAS, /*flags*/ TYPEFLAG_FHIDDEN, /*align*/ TYPE_ALIGNMENT(m), /*size*/ sizeof(m),
/*helpctx*/ 0x0000, /*version*/ 0x00010002, /*#vtbl*/ 0, /*#func*/ 0
},
{
"mm",
"{00000000-0000-0000-0000-000000000000}",
/*kind*/ TKIND_ALIAS, /*flags*/ 0, /*align*/ 4, /*size*/ 4,
/*kind*/ TKIND_ALIAS, /*flags*/ 0, /*align*/ TYPE_ALIGNMENT(mm), /*size*/ sizeof(mm),
/*helpctx*/ 0x0003, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
"IDualIface",
"{b14b6bb5-904e-4ff9-b247-bd361f7aaedd}",
/*kind*/ TKIND_DISPATCH, /*flags*/ TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL, /*align*/ 4, /*size*/ sizeof(IDualIface*),
/*kind*/ TKIND_DISPATCH, /*flags*/ TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL, /*align*/ TYPE_ALIGNMENT(IDualIface*), /*size*/ sizeof(IDualIface*),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 7, /*#func*/ 8,
{
{
......@@ -4423,7 +4461,7 @@ static const type_info info[] = {
{
"ISimpleIface",
"{ec5dfcd6-eeb0-4cd6-b51e-8030e1dac009}",
/*kind*/ TKIND_INTERFACE, /*flags*/ TYPEFLAG_FDISPATCHABLE, /*align*/ 4, /*size*/ sizeof(ISimpleIface*),
/*kind*/ TKIND_INTERFACE, /*flags*/ TYPEFLAG_FDISPATCHABLE, /*align*/ TYPE_ALIGNMENT(ISimpleIface*), /*size*/ sizeof(ISimpleIface*),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 8, /*#func*/ 1,
{
{
......@@ -4443,25 +4481,25 @@ static const type_info info[] = {
{
"test_struct",
"{4029f190-ca4a-4611-aeb9-673983cb96dd}",
/*kind*/ TKIND_RECORD, /*flags*/ 0, /*align*/ 4, /*size*/ sizeof(struct test_struct),
/*kind*/ TKIND_RECORD, /*flags*/ 0, /*align*/ TYPE_ALIGNMENT(struct test_struct), /*size*/ sizeof(struct test_struct),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
"test_struct2",
"{4029f190-ca4a-4611-aeb9-673983cb96de}",
/*kind*/ TKIND_RECORD, /*flags*/ 0, /*align*/ 4, /*size*/ sizeof(struct test_struct2),
/*kind*/ TKIND_RECORD, /*flags*/ 0, /*align*/ TYPE_ALIGNMENT(struct test_struct2), /*size*/ sizeof(struct test_struct2),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
"t_INT",
"{016fe2ec-b2c8-45f8-b23b-39e53a75396a}",
/*kind*/ TKIND_ALIAS, /*flags*/ TYPEFLAG_FRESTRICTED, /*align*/ 4, /*size*/ 4,
/*kind*/ TKIND_ALIAS, /*flags*/ TYPEFLAG_FRESTRICTED, /*align*/ TYPE_ALIGNMENT(t_INT), /*size*/ sizeof(t_INT),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
"a",
"{00000000-0000-0000-0000-000000000000}",
/*kind*/ TKIND_ALIAS, /*flags*/ 0, /*align*/ 4, /*size*/ 4,
/*kind*/ TKIND_ALIAS, /*flags*/ 0, /*align*/ TYPE_ALIGNMENT(a), /*size*/ sizeof(a),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
......@@ -4491,7 +4529,7 @@ static const type_info info[] = {
{
"c",
"{016fe2ec-b2c8-45f8-b23b-39e53a75396b}",
/*kind*/ TKIND_ALIAS, /*flags*/ 0, /*align*/ 4, /*size*/ 4,
/*kind*/ TKIND_ALIAS, /*flags*/ 0, /*align*/ TYPE_ALIGNMENT(c), /*size*/ sizeof(c),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
......@@ -4509,7 +4547,7 @@ static const type_info info[] = {
{
"d",
"{016fe2ec-b2c8-45f8-b23b-39e53a75396d}",
/*kind*/ TKIND_ALIAS, /*flags*/ TYPEFLAG_FRESTRICTED|TYPEFLAG_FHIDDEN, /*align*/ 4, /*size*/ 4,
/*kind*/ TKIND_ALIAS, /*flags*/ TYPEFLAG_FRESTRICTED|TYPEFLAG_FHIDDEN, /*align*/ TYPE_ALIGNMENT(d), /*size*/ sizeof(d),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
......@@ -4527,43 +4565,43 @@ static const type_info info[] = {
{
"e",
"{016fe2ec-b2c8-45f8-b23b-39e53a753970}",
/*kind*/ TKIND_ALIAS, /*flags*/ TYPEFLAG_FRESTRICTED|TYPEFLAG_FHIDDEN, /*align*/ 4, /*size*/ 4,
/*kind*/ TKIND_ALIAS, /*flags*/ TYPEFLAG_FRESTRICTED|TYPEFLAG_FHIDDEN, /*align*/ TYPE_ALIGNMENT(e), /*size*/ sizeof(e),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
"_e",
"{00000000-0000-0000-0000-000000000000}",
/*kind*/ TKIND_RECORD, /*flags*/ TYPEFLAG_FRESTRICTED|TYPEFLAG_FHIDDEN, /*align*/ 4, /*size*/ sizeof(struct _e),
/*kind*/ TKIND_RECORD, /*flags*/ TYPEFLAG_FRESTRICTED|TYPEFLAG_FHIDDEN, /*align*/ TYPE_ALIGNMENT(struct _e), /*size*/ sizeof(struct _e),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
"ee",
"{016fe2ec-b2c8-45f8-b23b-39e53a753971}",
/*kind*/ TKIND_RECORD, /*flags*/ TYPEFLAG_FRESTRICTED|TYPEFLAG_FHIDDEN, /*align*/ 4, /*size*/ sizeof(struct ee),
/*kind*/ TKIND_RECORD, /*flags*/ TYPEFLAG_FRESTRICTED|TYPEFLAG_FHIDDEN, /*align*/ TYPE_ALIGNMENT(struct ee), /*size*/ sizeof(struct ee),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
"f",
"{016fe2ec-b2c8-45f8-b23b-39e53a753972}",
/*kind*/ TKIND_ALIAS, /*flags*/ TYPEFLAG_FRESTRICTED|TYPEFLAG_FHIDDEN, /*align*/ 4, /*size*/ 4,
/*kind*/ TKIND_ALIAS, /*flags*/ TYPEFLAG_FRESTRICTED|TYPEFLAG_FHIDDEN, /*align*/ TYPE_ALIGNMENT(f), /*size*/ sizeof(f),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
"_f",
"{00000000-0000-0000-0000-000000000000}",
/*kind*/ TKIND_UNION, /*flags*/ TYPEFLAG_FRESTRICTED|TYPEFLAG_FHIDDEN, /*align*/ 4, /*size*/ sizeof(union _f),
/*kind*/ TKIND_UNION, /*flags*/ TYPEFLAG_FRESTRICTED|TYPEFLAG_FHIDDEN, /*align*/ TYPE_ALIGNMENT(union _f), /*size*/ sizeof(union _f),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
"ff",
"{016fe2ec-b2c8-45f8-b23b-39e53a753973}",
/*kind*/ TKIND_UNION, /*flags*/ TYPEFLAG_FRESTRICTED|TYPEFLAG_FHIDDEN, /*align*/ 4, /*size*/ sizeof(union ff),
/*kind*/ TKIND_UNION, /*flags*/ TYPEFLAG_FRESTRICTED|TYPEFLAG_FHIDDEN, /*align*/ TYPE_ALIGNMENT(union ff), /*size*/ sizeof(union ff),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 0, /*#func*/ 0
},
{
"ITestIface",
"{ec5dfcd6-eeb0-4cd6-b51e-8030e1dac00a}",
/*kind*/ TKIND_INTERFACE, /*flags*/ TYPEFLAG_FDISPATCHABLE, /*align*/ 4, /*size*/ sizeof(ITestIface*),
/*kind*/ TKIND_INTERFACE, /*flags*/ TYPEFLAG_FDISPATCHABLE, /*align*/ TYPE_ALIGNMENT(ITestIface*), /*size*/ sizeof(ITestIface*),
/*helpctx*/ 0x0000, /*version*/ 0x00000000, /*#vtbl*/ 13, /*#func*/ 6,
{
{
......@@ -4686,21 +4724,8 @@ static void test_dump_typelib(const char *name)
ole_check(ITypeInfo_GetTypeAttr(typeinfo, &typeattr));
expect_int(typeattr->typekind, ti->type);
expect_hex(typeattr->wTypeFlags, ti->wTypeFlags);
/* FIXME: remove once widl is fixed */
if (typeattr->typekind == TKIND_ALIAS && typeattr->cbAlignment != ti->cbAlignment)
{
todo_wine /* widl generates broken typelib and typeattr just reflects that */
ok(typeattr->cbAlignment == ti->cbAlignment || broken(typeattr->cbAlignment == 1),
"expected %d, got %d\n", ti->cbAlignment, typeattr->cbAlignment);
todo_wine /* widl generates broken typelib and typeattr just reflects that */
ok(typeattr->cbSizeInstance == ti->cbSizeInstance || broken(typeattr->cbSizeInstance == 0),
"expected %d, got %d\n", ti->cbSizeInstance, typeattr->cbSizeInstance);
}
else
{
expect_int(typeattr->cbAlignment, ti->cbAlignment);
expect_int(typeattr->cbSizeInstance, ti->cbSizeInstance);
}
expect_int(help_ctx, ti->help_ctx);
expect_int(MAKELONG(typeattr->wMinorVerNum, typeattr->wMajorVerNum), ti->version);
expect_int(typeattr->cbSizeVft, ti->cbSizeVft * sizeof(void*));
......
......@@ -84,7 +84,6 @@ static const unsigned short IsSimpleRef = 0x0100;
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 type_memsize_and_alignment(const type_t *t, unsigned int *align);
static unsigned int write_array_tfs(FILE *file, const attr_list_t *attrs, type_t *type,
const char *name, unsigned int *typestring_offset);
static unsigned int write_struct_tfs(FILE *file, type_t *type, const char *name, unsigned int *tfsoff);
......@@ -1841,7 +1840,7 @@ static unsigned int union_memsize(const var_list_t *fields, unsigned int *pmaxa)
return maxs;
}
static unsigned int type_memsize_and_alignment(const type_t *t, unsigned int *align)
unsigned int type_memsize_and_alignment(const type_t *t, unsigned int *align)
{
unsigned int size = 0;
......@@ -1910,6 +1909,7 @@ static unsigned int type_memsize_and_alignment(const type_t *t, unsigned int *al
size = union_memsize(type_union_get_cases(t), align);
break;
case TYPE_POINTER:
case TYPE_INTERFACE:
assert( pointer_size );
size = pointer_size;
if (size > *align) *align = size;
......@@ -1933,7 +1933,6 @@ static unsigned int type_memsize_and_alignment(const type_t *t, unsigned int *al
if (size > *align) *align = size;
}
break;
case TYPE_INTERFACE:
case TYPE_ALIAS:
case TYPE_VOID:
case TYPE_COCLASS:
......
......@@ -100,3 +100,4 @@ unsigned char get_basic_fc(const type_t *type);
unsigned char get_pointer_fc(const type_t *type, const attr_list_t *attrs, int toplevel_param);
unsigned char get_struct_fc(const type_t *type);
enum typegen_type typegen_detect_type(const type_t *type, const attr_list_t *attrs, unsigned int flags);
unsigned int type_memsize_and_alignment(const type_t *t, unsigned int *align);
......@@ -52,6 +52,7 @@
#include "hash.h"
#include "typetree.h"
#include "parser.h"
#include "typegen.h"
enum MSFT_segment_index {
MSFT_SEG_TYPEINFO = 0, /* type information */
......@@ -780,8 +781,6 @@ static int encode_type(
int vt, /* [I] vt to encode */
type_t *type, /* [I] type */
int *encoded_type, /* [O] The encoded type description. */
int *width, /* [O] The width of the type, or NULL. */
int *alignment, /* [O] The alignment of the type, or NULL. */
int *decoded_size) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
{
int default_type;
......@@ -794,8 +793,6 @@ static int encode_type(
chat("encode_type vt %d type %p\n", vt, type);
default_type = 0x80000000 | (vt << 16) | vt;
if (!width) width = &scratch;
if (!alignment) alignment = &scratch;
if (!decoded_size) decoded_size = &scratch;
*decoded_size = 0;
......@@ -804,38 +801,20 @@ static int encode_type(
case VT_I1:
case VT_UI1:
*encoded_type = default_type;
*width = 1;
*alignment = 1;
break;
case VT_INT:
*encoded_type = 0x80000000 | (VT_I4 << 16) | VT_INT;
if ((typelib->typelib_header.varflags & 0x0f) == SYS_WIN16) {
*width = 2;
*alignment = 2;
} else {
*width = 4;
*alignment = 4;
}
break;
case VT_UINT:
*encoded_type = 0x80000000 | (VT_UI4 << 16) | VT_UINT;
if ((typelib->typelib_header.varflags & 0x0f) == SYS_WIN16) {
*width = 2;
*alignment = 2;
} else {
*width = 4;
*alignment = 4;
}
break;
case VT_UI2:
case VT_I2:
case VT_BOOL:
*encoded_type = default_type;
*width = 2;
*alignment = 2;
break;
case VT_I4:
......@@ -844,56 +823,40 @@ static int encode_type(
case VT_ERROR:
case VT_HRESULT:
*encoded_type = default_type;
*width = 4;
*alignment = 4;
break;
case VT_R8:
case VT_I8:
case VT_UI8:
*encoded_type = default_type;
*width = 8;
*alignment = 8;
break;
case VT_CY:
case VT_DATE:
*encoded_type = default_type;
*width = 8;
*alignment = 8;
break;
case VT_DECIMAL:
*encoded_type = default_type;
*width = 16;
*alignment = 8;
break;
case VT_VOID:
*encoded_type = 0x80000000 | (VT_EMPTY << 16) | vt;
*width = 0;
*alignment = 1;
break;
case VT_UNKNOWN:
case VT_DISPATCH:
case VT_BSTR:
*encoded_type = default_type;
*width = pointer_size;
*alignment = 4;
break;
case VT_VARIANT:
*encoded_type = default_type;
*width = 8 + 2 * pointer_size;
*alignment = 8;
break;
case VT_LPSTR:
case VT_LPWSTR:
*encoded_type = 0xfffe0000 | vt;
*width = pointer_size;
*alignment = 4;
break;
case VT_PTR:
......@@ -909,14 +872,12 @@ static int encode_type(
next_vt = VT_VOID;
encode_type(typelib, next_vt, type_pointer_get_ref(type),
&target_type, NULL, NULL, &child_size);
&target_type, &child_size);
/* these types already have an implicit pointer, so we don't need to
* add another */
if(next_vt == VT_DISPATCH || next_vt == VT_UNKNOWN) {
chat("encode_type: skipping ptr\n");
*encoded_type = target_type;
*width = pointer_size;
*alignment = 4;
*decoded_size = child_size;
break;
}
......@@ -945,8 +906,6 @@ static int encode_type(
*encoded_type = typeoffset;
*width = pointer_size;
*alignment = 4;
*decoded_size = 8 /*sizeof(TYPEDESC)*/ + child_size;
break;
}
......@@ -956,7 +915,8 @@ static int encode_type(
type_t *element_type = type_alias_get_aliasee(type_array_get_element(type));
int next_vt = get_type_vt(element_type);
encode_type(typelib, next_vt, type_alias_get_aliasee(type_array_get_element(type)), &target_type, NULL, NULL, &child_size);
encode_type(typelib, next_vt, type_alias_get_aliasee(type_array_get_element(type)),
&target_type, &child_size);
for (typeoffset = 0; typeoffset < typelib->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
typedata = (void *)&typelib->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
......@@ -982,8 +942,6 @@ static int encode_type(
*encoded_type = typeoffset;
*width = pointer_size;
*alignment = 4;
*decoded_size = 8 /*sizeof(TYPEDESC)*/ + child_size;
break;
}
......@@ -1053,16 +1011,12 @@ static int encode_type(
}
*encoded_type = typeoffset;
*width = 0;
*alignment = 1;
break;
}
default:
error("encode_type: unrecognized type %d.\n", vt);
*encoded_type = default_type;
*width = 0;
*alignment = 1;
break;
}
......@@ -1079,8 +1033,6 @@ static int encode_var(
type_t *type, /* [I] The type description to encode. */
var_t *var, /* [I] The var to encode. */
int *encoded_type, /* [O] The encoded type description. */
int *width, /* [O] The width of the type, or NULL. */
int *alignment, /* [O] The alignment of the type, or NULL. */
int *decoded_size) /* [O] The total size of the unencoded TYPEDESCs, including nested descs. */
{
int typeoffset;
......@@ -1090,8 +1042,6 @@ static int encode_var(
int vt;
int scratch;
if (!width) width = &scratch;
if (!alignment) alignment = &scratch;
if (!decoded_size) decoded_size = &scratch;
*decoded_size = 0;
......@@ -1110,7 +1060,7 @@ static int encode_var(
++num_dims;
chat("array with %d dimensions\n", num_dims);
encode_var(typelib, atype, var, &target_type, width, alignment, NULL);
encode_var(typelib, atype, var, &target_type, NULL);
arrayoffset = ctl2_alloc_segment(typelib, MSFT_SEG_ARRAYDESC, (2 + 2 * num_dims) * sizeof(int), 0);
arraydata = (void *)&typelib->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
......@@ -1136,7 +1086,6 @@ static int encode_var(
typedata[1] = arrayoffset;
*encoded_type = typeoffset;
*width = *width * elements;
*decoded_size = 20 /*sizeof(ARRAYDESC)*/ + (num_dims - 1) * 8 /*sizeof(SAFEARRAYBOUND)*/;
return 0;
}
......@@ -1145,15 +1094,12 @@ static int encode_var(
if (vt == VT_PTR) {
type_t *ref = is_ptr(type) ?
type_pointer_get_ref(type) : type_array_get_element(type);
int skip_ptr = encode_var(typelib, ref, var,
&target_type, NULL, NULL, &child_size);
int skip_ptr = encode_var(typelib, ref, var, &target_type, &child_size);
if(skip_ptr == 2) {
chat("encode_var: skipping ptr\n");
*encoded_type = target_type;
*decoded_size = child_size;
*width = pointer_size;
*alignment = 4;
return 0;
}
......@@ -1184,15 +1130,13 @@ static int encode_var(
*encoded_type = typeoffset;
*width = pointer_size;
*alignment = 4;
*decoded_size = 8 /*sizeof(TYPEDESC)*/ + child_size;
return 0;
}
dump_type(type);
encode_type(typelib, vt, type, encoded_type, width, alignment, decoded_size);
encode_type(typelib, vt, type, encoded_type, decoded_size);
/* these types already have an implicit pointer, so we don't need to
* add another */
if(vt == VT_DISPATCH || vt == VT_UNKNOWN) return 2;
......@@ -1504,7 +1448,8 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, var_t *func, int index)
/* fill out the basic type information */
typedata[0] = typedata_size | (index << 16);
encode_var(typeinfo->typelib, type_function_get_rettype(func->type), func, &typedata[1], NULL, NULL, &decoded_size);
encode_var(typeinfo->typelib, type_function_get_rettype(func->type), func,
&typedata[1], &decoded_size);
typedata[2] = funcflags;
typedata[3] = ((52 /*sizeof(FUNCDESC)*/ + decoded_size) << 16) | typeinfo->typeinfo->cbSizeVft;
typedata[4] = (next_idx << 16) | (callconv << 8) | (invokekind << 3) | funckind;
......@@ -1541,7 +1486,7 @@ static HRESULT add_func_desc(msft_typeinfo_t* typeinfo, var_t *func, int index)
if(defaultdata) *defaultdata = -1;
encode_var(typeinfo->typelib, arg->type, arg, paramdata, NULL, NULL, &decoded_size);
encode_var(typeinfo->typelib, arg->type, arg, paramdata, &decoded_size);
if (arg->attrs) LIST_FOR_EACH_ENTRY( attr, arg->attrs, const attr_t, entry ) {
switch(attr->type) {
case ATTR_DEFAULTVALUE:
......@@ -1667,8 +1612,7 @@ static HRESULT add_var_desc(msft_typeinfo_t *typeinfo, UINT index, var_t* var)
int offset, id;
unsigned int typedata_size;
INT *typedata;
int var_datawidth;
int var_alignment;
unsigned int var_datawidth, var_alignment = 0;
int var_type_size, var_kind = 0 /* VAR_PERINSTANCE */;
int alignment;
int varflags = 0;
......@@ -1770,8 +1714,8 @@ static HRESULT add_var_desc(msft_typeinfo_t *typeinfo, UINT index, var_t* var)
typeinfo->var_offsets[var_num] = offset;
/* figure out type widths and whatnot */
encode_var(typeinfo->typelib, var->type, var, &typedata[1], &var_datawidth,
&var_alignment, &var_type_size);
var_datawidth = type_memsize_and_alignment(var->type, &var_alignment);
encode_var(typeinfo->typelib, var->type, var, &typedata[1], &var_type_size);
/* pad out starting position to data width */
typeinfo->datawidth += var_alignment - 1;
......@@ -1795,7 +1739,6 @@ static HRESULT add_var_desc(msft_typeinfo_t *typeinfo, UINT index, var_t* var)
case TKIND_DISPATCH:
var_kind = 3; /* VAR_DISPATCH */
typeinfo->datawidth = pointer_size;
var_alignment = 4;
break;
default:
error("add_var_desc: unhandled type kind %d\n", typeinfo->typekind);
......@@ -2073,7 +2016,7 @@ static void add_dispinterface_typeinfo(msft_typelib_t *typelib, type_t *dispinte
dispinterface->attrs);
msft_typeinfo->typeinfo->size = pointer_size;
msft_typeinfo->typeinfo->typekind |= 0x2100;
msft_typeinfo->typeinfo->typekind |= pointer_size << 11 | pointer_size << 6;
msft_typeinfo->typeinfo->flags |= 0x1000; /* TYPEFLAG_FDISPATCHABLE */
add_dispatch(typelib);
......@@ -2162,7 +2105,8 @@ static void add_interface_typeinfo(msft_typelib_t *typelib, type_t *interface)
interface->typelib_idx = typelib->typelib_header.nrtypeinfos;
msft_typeinfo = create_msft_typeinfo(typelib, TKIND_INTERFACE, interface->name, interface->attrs);
msft_typeinfo->typeinfo->size = pointer_size;
msft_typeinfo->typeinfo->typekind |= 0x2200;
msft_typeinfo->typeinfo->typekind |= 0x0200;
msft_typeinfo->typeinfo->typekind |= pointer_size << 11;
for (derived = inherit; derived; derived = type_iface_get_inherit(derived))
if (derived->name && !strcmp(derived->name, "IDispatch"))
......@@ -2247,7 +2191,8 @@ static void add_union_typeinfo(msft_typelib_t *typelib, type_t *tunion)
static void add_typedef_typeinfo(msft_typelib_t *typelib, type_t *tdef)
{
msft_typeinfo_t *msft_typeinfo = NULL;
int alignment, datatype1, datatype2, size, duplicate = 0;
int datatype1, datatype2, duplicate = 0;
unsigned int size, alignment = 0;
type_t *type;
if (-1 < tdef->typelib_idx)
......@@ -2263,8 +2208,8 @@ static void add_typedef_typeinfo(msft_typelib_t *typelib, type_t *tdef)
else
duplicate = 1;
encode_type(typelib, get_type_vt(type), type,
&datatype1, &size, &alignment, &datatype2);
encode_type(typelib, get_type_vt(type), type, &datatype1, &datatype2);
size = type_memsize_and_alignment(type, &alignment);
if (msft_typeinfo)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment