Skip to content

Commit

Permalink
[metadata] Make type dup used by inflate_generic_type be cmod aware. F…
Browse files Browse the repository at this point in the history
…ixes mono#10834

We didn't include cmods when inflating var/mvar cuz we'd mono_metadata_type_dup' the inflated type
and not the (m)var MonoType.

The solution is to add a variant of mono_metadata_type_dup that takes the source of cmods to use.
  • Loading branch information
kumpera authored and monojenkins committed Feb 5, 2019
1 parent 18a4294 commit 17696af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 3 additions & 3 deletions mono/metadata/class.c
Expand Up @@ -644,7 +644,7 @@ inflate_generic_type (MonoImage *image, MonoType *type, MonoGenericContext *cont
* while the VAR/MVAR duplicates a type from the context. So, we need to ensure that the
* ->byref and ->attrs from @type are propagated to the returned type.
*/
nt = mono_metadata_type_dup (image, inst->type_argv [num]);
nt = mono_metadata_type_dup_with_cmods (image, inst->type_argv [num], type);
nt->byref = type->byref;
nt->attrs = type->attrs;
return nt;
Expand All @@ -667,7 +667,7 @@ inflate_generic_type (MonoImage *image, MonoType *type, MonoGenericContext *cont
num, pname ? pname : "", inst->type_argv [num]->type);
return NULL;
}
nt = mono_metadata_type_dup (image, inst->type_argv [num]);
nt = mono_metadata_type_dup_with_cmods (image, inst->type_argv [num], type);
nt->byref = type->byref;
nt->attrs = type->attrs;
return nt;
Expand Down Expand Up @@ -790,7 +790,7 @@ mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type,
if (!inflated) {
MonoType *shared = mono_metadata_get_shared_type (type);

if (shared) {
if (shared && !type->has_cmods) {
return shared;
} else {
return mono_metadata_type_dup (image, type);
Expand Down
2 changes: 2 additions & 0 deletions mono/metadata/metadata-internals.h
Expand Up @@ -893,6 +893,8 @@ void mono_unload_interface_ids (MonoBitSet *bitset);


MonoType *mono_metadata_type_dup (MonoImage *image, const MonoType *original);
MonoType *mono_metadata_type_dup_with_cmods (MonoImage *image, const MonoType *original, const MonoType *cmods_source);

MonoMethodSignature *mono_metadata_signature_dup_full (MonoImage *image,MonoMethodSignature *sig);
MonoMethodSignature *mono_metadata_signature_dup_mempool (MonoMemPool *mp, MonoMethodSignature *sig);
MonoMethodSignature *mono_metadata_signature_dup_add_this (MonoImage *image, MonoMethodSignature *sig, MonoClass *klass);
Expand Down
19 changes: 17 additions & 2 deletions mono/metadata/metadata.c
Expand Up @@ -5694,13 +5694,28 @@ mono_metadata_signature_equal (MonoMethodSignature *sig1, MonoMethodSignature *s
*/
MonoType *
mono_metadata_type_dup (MonoImage *image, const MonoType *o)
{
return mono_metadata_type_dup_with_cmods (image, o, o);
}

/**
* Works the same way as mono_metadata_type_dup but pick cmods from @cmods_source
*/
MonoType *
mono_metadata_type_dup_with_cmods (MonoImage *image, const MonoType *o, const MonoType *cmods_source)
{
MonoType *r = NULL;
size_t sizeof_o = mono_sizeof_type (o);
size_t sizeof_o = mono_sizeof_type (cmods_source);

r = image ? (MonoType *)mono_image_alloc0 (image, sizeof_o) : (MonoType *)g_malloc (sizeof_o);

memcpy (r, o, sizeof_o);
if (cmods_source->has_cmods) {
g_assert (!image || image == mono_type_get_cmods (cmods_source)->image);
memcpy (r, cmods_source, sizeof_o);
}

memcpy (r, o, sizeof (MonoType));
r->has_cmods = cmods_source->has_cmods;

if (o->type == MONO_TYPE_PTR) {
r->data.type = mono_metadata_type_dup (image, o->data.type);
Expand Down

0 comments on commit 17696af

Please sign in to comment.