From: Hans Leidekker hans@codeweavers.com
--- tools/widl/metadata.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)
diff --git a/tools/widl/metadata.c b/tools/widl/metadata.c index cd4d3d68c45..342f861565e 100644 --- a/tools/widl/metadata.c +++ b/tools/widl/metadata.c @@ -2798,6 +2798,65 @@ static void add_activatable_attr_step2( type_t *type ) } }
+static UINT make_threading_value( const type_t *type, BYTE *buf ) +{ + UINT value, model = get_attrv( type->attrs, ATTR_THREADING ); + + switch (model) + { + case THREADING_SINGLE: + value = 1; + break; + case THREADING_FREE: + value = 2; + break; + case THREADING_BOTH: + value = 3; + break; + default: + fprintf( stderr, "Unhandled model %u.\n", model ); + return 0; + } + + buf[0] = 1; + buf[1] = 0; + memcpy( buf + 2, &value, sizeof(value) ); + buf[6] = buf[7] = 0; + return 8; +} + +static void add_threading_attr_step1( type_t *type ) +{ + UINT assemblyref, scope, typeref, typeref_attr, class, sig_size; + BYTE sig[32]; + + if (!is_attr( type->attrs, ATTR_THREADING )) return; + + assemblyref = add_assemblyref_row( 0x200, 0, add_string("Windows.Foundation") ); + scope = resolution_scope( TABLE_ASSEMBLYREF, assemblyref ); + typeref = add_typeref_row( scope, add_string("ThreadingModel"), add_string("Windows.Foundation.Metadata") ); + + scope = resolution_scope( TABLE_ASSEMBLYREF, assemblyref ); + typeref_attr = add_typeref_row( scope, add_string("ThreadingAttribute"), add_string("Windows.Foundation.Metadata") ); + + class = memberref_parent( TABLE_TYPEREF, typeref_attr ); + sig_size = make_member_sig2( ELEMENT_TYPE_VALUETYPE, typedef_or_ref(TABLE_TYPEREF, typeref), sig ); + type->md.member[MD_ATTR_THREADING] = add_memberref_row( class, add_string(".ctor"), add_blob(sig, sig_size) ); +} + +static void add_threading_attr_step2( type_t *type ) +{ + UINT parent, attr_type, value_size; + BYTE value[8]; + + if (!is_attr( type->attrs, ATTR_THREADING )) return; + + parent = has_customattribute( TABLE_TYPEDEF, type->md.def ); + attr_type = customattribute_type( TABLE_MEMBERREF, type->md.member[MD_ATTR_THREADING] ); + value_size = make_threading_value( type, value ); + add_customattribute_row( parent, attr_type, add_blob(value, value_size) ); +} + static void add_runtimeclass_type_step2( type_t *type ) { UINT name, namespace, scope, extends, typeref, interface, interfaceimpl_ref, flags; @@ -2845,10 +2904,12 @@ static void add_runtimeclass_type_step2( type_t *type ) add_contract_attr_step1( type ); add_static_attr_step1( type ); add_activatable_attr_step1( type ); + add_threading_attr_step1( type );
add_contract_attr_step2( type ); add_static_attr_step2( type ); add_activatable_attr_step2( type ); + add_threading_attr_step2( type ); }
static void add_delegate_type_step1( type_t *type )