Skip to content

Commit 549b431

Browse files
authored
[mono] Support array parameter types of custom attributes in Mono AOT compiler (#69759)
- mono_reflection_create_custom_attr_data_args_noalloc now supports decoding array type parameters of custom attributes - mono_reflection_create_custom_attr_data_args_noalloc is refactored to use MonoDecodeCustomAttr - MonoDecodeCustomAttr encapsulates all the information of the decoded custom attribute parameters - initial support for UnmanagedCallConvAttribute: native-to-managed wrapper generation now takes into account applied custom attributes by updating the method's signature Fixes [#52977](#52977)
1 parent 874f7aa commit 549b431

14 files changed

+594
-170
lines changed

src/mono/mono/component/debugger-agent.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,21 +2944,14 @@ static gint32 isFixedSizeArray (MonoClassField *f)
29442944
MonoClass *fixed_size_class = mono_class_try_get_fixed_buffer_class ();
29452945
if (fixed_size_class != NULL && mono_class_has_parent (ctor_class, fixed_size_class)) {
29462946
attr = &cinfo->attrs [aindex];
2947-
gpointer *typed_args, *named_args;
2948-
CattrNamedArg *arginfo;
2949-
int num_named_args;
2950-
2951-
mono_reflection_create_custom_attr_data_args_noalloc (mono_get_corlib (), attr->ctor, attr->data, attr->data_size,
2952-
&typed_args, &named_args, &num_named_args, &arginfo, error);
2947+
MonoDecodeCustomAttr *decoded_args = mono_reflection_create_custom_attr_data_args_noalloc (mono_get_corlib (), attr->ctor, attr->data, attr->data_size, error);
29532948
if (!is_ok (error)) {
29542949
ret = 0;
29552950
goto leave;
29562951
}
2957-
ret = *(gint32*)typed_args [1];
2958-
g_free (typed_args [1]);
2959-
g_free (typed_args);
2960-
g_free (named_args);
2961-
g_free (arginfo);
2952+
2953+
ret = *(gint32*)decoded_args->typed_args[1]->value.primitive;
2954+
mono_reflection_free_custom_attr_data_args_noalloc (decoded_args);
29622955
return ret;
29632956
}
29642957
}

src/mono/mono/metadata/custom-attrs-internals.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,29 @@
99
#include <mono/metadata/object-internals.h>
1010
#include <mono/metadata/reflection.h>
1111

12+
typedef struct _MonoCustomAttrValueArray MonoCustomAttrValueArray;
13+
14+
typedef struct _MonoCustomAttrValue {
15+
union {
16+
gpointer primitive; /* int/enum/MonoType/string */
17+
MonoCustomAttrValueArray *array;
18+
} value;
19+
MonoTypeEnum type : 8;
20+
} MonoCustomAttrValue;
21+
22+
struct _MonoCustomAttrValueArray {
23+
int len;
24+
MonoCustomAttrValue values[MONO_ZERO_LEN_ARRAY];
25+
};
26+
27+
typedef struct _MonoDecodeCustomAttr {
28+
int typed_args_num;
29+
int named_args_num;
30+
MonoCustomAttrValue **typed_args;
31+
MonoCustomAttrValue **named_args;
32+
CattrNamedArg *named_args_info;
33+
} MonoDecodeCustomAttr;
34+
1235
MonoCustomAttrInfo*
1336
mono_custom_attrs_from_builders (MonoImage *alloc_img, MonoImage *image, MonoArray *cattrs);
1437

@@ -33,8 +56,9 @@ MONO_COMPONENT_API void
3356
mono_reflection_create_custom_attr_data_args (MonoImage *image, MonoMethod *method, const guchar *data, guint32 len, MonoArrayHandleOut typed_args_out, MonoArrayHandleOut named_args_out, CattrNamedArg **named_arg_info, MonoError *error);
3457

3558
MONO_COMPONENT_API void
36-
mono_reflection_create_custom_attr_data_args_noalloc (MonoImage *image, MonoMethod *method, const guchar *data, guint32 len,
37-
gpointer **typed_args_out, gpointer **named_args_out, int *num_named_args,
38-
CattrNamedArg **named_arg_info, MonoError *error);
59+
mono_reflection_free_custom_attr_data_args_noalloc(MonoDecodeCustomAttr* decoded_args);
60+
61+
MONO_COMPONENT_API MonoDecodeCustomAttr*
62+
mono_reflection_create_custom_attr_data_args_noalloc (MonoImage *image, MonoMethod *method, const guchar *data, guint32 len, MonoError *error);
3963

4064
#endif /* __MONO_METADATA_REFLECTION_CUSTOM_ATTRS_INTERNALS_H__ */

0 commit comments

Comments
 (0)