Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup System.Reflection.Emit code. #47945

Merged
merged 3 commits into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,39 +178,18 @@ public sealed class AssemblyBuilder : Assembly
//
#region Sync with RuntimeAssembly.cs and ReflectionAssembly in object-internals.h
internal IntPtr _mono_assembly;
private object? _evidence;

private UIntPtr dynamic_assembly; /* GC-tracked */
private MethodInfo? entry_point;
private ModuleBuilder[] modules;
private string? name;
private string? dir;
private CustomAttributeBuilder[]? cattrs;
private object? resources;
private byte[]? public_key;
private string? version;
private string? culture;
private uint algid;
private uint flags;
private PEFileKinds pekind = PEFileKinds.Dll;
private bool delay_sign;
private uint access;
private Module[]? loaded_modules;
private object? win32_resources;
private object? permissions_minimum;
private object? permissions_optional;
private object? permissions_refused;
private int peKind;
private int machine;
private bool corlib_internal;
private Type[]? type_forwarders;
private byte[]? pktoken;
private uint access;
#endregion

private AssemblyName aname;
private string? assemblyName;
private bool created;
private string? versioninfo_culture;
private ModuleBuilder manifest_module;
private bool manifest_module_used;

Expand All @@ -221,8 +200,8 @@ public sealed class AssemblyBuilder : Assembly
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void UpdateNativeCustomAttributes(AssemblyBuilder ab);

[DynamicDependency(nameof(pktoken))] // Automatically keeps all previous fields too due to StructLayout
private AssemblyBuilder(AssemblyName n, string? directory, AssemblyBuilderAccess access, bool corlib_internal)
[DynamicDependency(nameof(access))] // Automatically keeps all previous fields too due to StructLayout
private AssemblyBuilder(AssemblyName n, AssemblyBuilderAccess access)
{
aname = (AssemblyName)n.Clone();

Expand All @@ -233,16 +212,10 @@ private AssemblyBuilder(AssemblyName n, string? directory, AssemblyBuilderAccess

name = n.Name;
this.access = (uint)access;
flags = (uint)n.Flags;

dir = directory;

/* Set defaults from n */
if (n.CultureInfo != null)
{
culture = n.CultureInfo.Name;
versioninfo_culture = n.CultureInfo.Name;
}
Version? v = n.Version;
if (v != null)
{
Expand All @@ -265,7 +238,7 @@ public override MethodInfo? EntryPoint
{
get
{
return entry_point;
return null;
}
}

Expand All @@ -287,7 +260,7 @@ public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyB
if (name == null)
throw new ArgumentNullException(nameof(name));

return new AssemblyBuilder(name, null, access, false);
return new AssemblyBuilder(name, access);
}

public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder>? assemblyAttributes)
Expand Down Expand Up @@ -366,6 +339,7 @@ public override string[] GetManifestResourceNames()
{
throw not_supported();
}

public override Stream? GetManifestResourceStream(Type type, string name)
{
throw not_supported();
Expand All @@ -379,14 +353,6 @@ public override bool IsCollectible
}
}

internal string? AssemblyDir
{
get
{
return dir;
}
}

public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
{
if (customBuilder == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ public sealed partial class ConstructorBuilder : ConstructorInfo
private bool init_locals = true;
private Type[][]? paramModReq;
private Type[][]? paramModOpt;
private object? permissions;
#endregion

internal bool finished;

[DynamicDependency(nameof(permissions))] // Automatically keeps all previous fields too due to StructLayout
[DynamicDependency(nameof(paramModOpt))] // Automatically keeps all previous fields too due to StructLayout
internal ConstructorBuilder(TypeBuilder tb, MethodAttributes attributes, CallingConventions callingConvention, Type[]? parameterTypes, Type[][]? paramModReq, Type[][]? paramModOpt)
{
attrs = attributes | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ public sealed partial class MethodBuilder : MethodInfo
private Type[]? returnModOpt;
private Type[][]? paramModReq;
private Type[][]? paramModOpt;
private object? permissions;
#endregion

private RuntimeMethodInfo? created;

[DynamicDependency(nameof(permissions))] // Automatically keeps all previous fields too due to StructLayout
[DynamicDependency(nameof(paramModOpt))] // Automatically keeps all previous fields too due to StructLayout
internal MethodBuilder(TypeBuilder tb, string name, MethodAttributes attributes, CallingConventions callingConvention, Type? returnType, Type[]? returnModReq, Type[]? returnModOpt, Type[]? parameterTypes, Type[][]? paramModReq, Type[][]? paramModOpt)
{
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public partial class ModuleBuilder : Module
private int num_types;
private TypeBuilder[]? types;
private CustomAttributeBuilder[]? cattrs;
private byte[] guid;
private int table_idx;
internal AssemblyBuilder assemblyb;
private object[]? global_methods;
Expand All @@ -73,6 +72,7 @@ public partial class ModuleBuilder : Module
private int[]? table_indexes;
#endregion

private byte[] guid;
private TypeBuilder? global_type;
private Type? global_type_created;
// name_cache keys are display names
Expand Down Expand Up @@ -113,11 +113,6 @@ public override string FullyQualifiedName
string fullyQualifiedName = fqname;
if (fullyQualifiedName == null)
return null!; // FIXME: this should not return null
if (assemblyb.AssemblyDir != null)
{
fullyQualifiedName = Path.Combine(assemblyb.AssemblyDir, fullyQualifiedName);
fullyQualifiedName = Path.GetFullPath(fullyQualifiedName);
}

return fullyQualifiedName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public sealed partial class TypeBuilder : TypeInfo
private PackingSize packing_size;
private IntPtr generic_container;
private GenericTypeParameterBuilder[]? generic_params;
private object? permissions;

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
private TypeInfo? created;
Expand Down
5 changes: 0 additions & 5 deletions src/mono/mono/metadata/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -5981,9 +5981,6 @@ can_access_type (MonoClass *access_klass, MonoClass *member_klass)
MonoAssembly *access_klass_assembly = m_class_get_image (access_klass)->assembly;
MonoAssembly *member_klass_assembly = m_class_get_image (member_klass)->assembly;

if (access_klass_assembly && m_class_get_image (access_klass)->assembly->corlib_internal)
return TRUE;

if (m_class_get_element_class (access_klass) && !m_class_is_enumtype (access_klass)) {
access_klass = m_class_get_element_class (access_klass);
access_klass_assembly = m_class_get_image (access_klass)->assembly;
Expand Down Expand Up @@ -6046,8 +6043,6 @@ can_access_member (MonoClass *access_klass, MonoClass *member_klass, MonoClass*
{
MonoClass *member_generic_def;
MonoAssembly *access_klass_assembly = m_class_get_image (access_klass)->assembly;
if (access_klass_assembly && access_klass_assembly->corlib_internal)
return TRUE;

MonoGenericClass *access_gklass = mono_class_try_get_generic_class (access_klass);
if (((access_gklass && access_gklass->container_class) ||
Expand Down
2 changes: 0 additions & 2 deletions src/mono/mono/metadata/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1699,8 +1699,6 @@ mono_domain_get_assemblies (MonoDomain *domain, gboolean refonly)
gboolean ass_ref_only = mono_asmctx_get_kind (&ass->context) == MONO_ASMCTX_REFONLY;
if (refonly != ass_ref_only)
continue;
if (ass->corlib_internal)
continue;
g_ptr_array_add (assemblies, ass);
}
mono_domain_assemblies_unlock (domain);
Expand Down
2 changes: 0 additions & 2 deletions src/mono/mono/metadata/dynamic-image.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,6 @@ mono_dynamic_image_create (MonoDynamicAssembly *assembly, char *assembly_name, c
}

image->image.assembly = (MonoAssembly*)assembly;
image->run = assembly->run;
image->save = assembly->save;
image->pe_kind = 0x1; /* ILOnly */
image->machine = 0x14c; /* I386 */

Expand Down
5 changes: 0 additions & 5 deletions src/mono/mono/metadata/icall.c
Original file line number Diff line number Diff line change
Expand Up @@ -3564,11 +3564,6 @@ ves_icall_InternalInvoke (MonoReflectionMethodHandle method_handle, MonoObjectHa
exception = mono_get_exception_invalid_operation ("It is illegal to invoke a method on a type loaded using the ReflectionOnly api.");
goto return_null;
}

if (image_is_dynamic (image) && !((MonoDynamicImage*)image)->run) {
exception = mono_get_exception_not_supported ("Cannot invoke a method in a dynamic assembly without run access.");
goto return_null;
}

if (m_class_get_rank (m->klass) && !strcmp (m->name, ".ctor")) {
int i;
Expand Down
5 changes: 0 additions & 5 deletions src/mono/mono/metadata/metadata-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ struct _MonoAssembly {
guint8 friend_assembly_names_inited;
guint8 in_gac;
guint8 dynamic;
guint8 corlib_internal;
MonoAssemblyContext context;
guint8 wrap_non_exception_throws;
guint8 wrap_non_exception_throws_inited;
Expand Down Expand Up @@ -669,8 +668,6 @@ struct _MonoDynamicAssembly {
MonoAssembly assembly;
char *strong_name;
guint32 strong_name_size;
guint8 run;
guint8 save;
MonoDomain *domain;
};

Expand Down Expand Up @@ -709,8 +706,6 @@ struct _MonoDynamicImage {
* Maps final token values to the object they describe.
*/
MonoGHashTable *remapped_tokens;
gboolean run;
gboolean save;
gboolean initial_image;
guint32 pe_kind, machine;
char *strong_name;
Expand Down
49 changes: 1 addition & 48 deletions src/mono/mono/metadata/object-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,6 @@ TYPED_HANDLE_DECL (MonoReflectionMethodBody);
struct _MonoReflectionAssembly {
MonoObject object;
MonoAssembly *assembly;
/* CAS related */
MonoObject *evidence; /* Evidence */
};

typedef struct {
Expand Down Expand Up @@ -1050,7 +1048,6 @@ typedef struct {
MonoBoolean init_locals;
MonoArray *param_modreq;
MonoArray *param_modopt;
MonoArray *permissions;
} MonoReflectionCtorBuilder;

/* Safely access System.Reflection.Emit.ConstructorBuilder from native code */
Expand Down Expand Up @@ -1084,7 +1081,6 @@ typedef struct {
MonoArray *return_modopt;
MonoArray *param_modreq;
MonoArray *param_modopt;
MonoArray *permissions;
} MonoReflectionMethodBuilder;

/* Safely access System.Reflection.Emit.MethodBuilder from native code */
Expand All @@ -1104,55 +1100,16 @@ typedef struct {
/* Safely access System.Reflection.Emit.MonoArrayMethod from native code */
TYPED_HANDLE_DECL (MonoReflectionArrayMethod);

typedef struct {
MonoArray *data;
MonoString *name;
MonoString *filename;
guint32 attrs;
guint32 offset;
MonoObject *stream;
} MonoReflectionResource;

typedef struct {
guint32 res_type;
guint32 res_id;
guint32 lang_id;
MonoArray *res_data;
} MonoReflectionWin32Resource;

typedef struct {
guint32 action;
MonoString *pset;
} MonoReflectionPermissionSet;

typedef struct {
MonoReflectionAssembly assembly;
MonoDynamicAssembly *dynamic_assembly;
MonoReflectionMethod *entry_point;
MonoArray *modules;
MonoString *name;
MonoString *dir;
MonoArray *cattrs;
MonoArray *resources;
MonoArray *public_key;
MonoString *version;
MonoString *culture;
guint32 algid;
guint32 flags;
guint32 pekind;
MonoBoolean delay_sign;
guint32 access;
MonoArray *loaded_modules;
MonoArray *win32_resources;
/* CAS related */
MonoArray *permissions_minimum;
MonoArray *permissions_optional;
MonoArray *permissions_refused;
gint32 pe_kind;
gint32 machine;
MonoBoolean corlib_internal;
MonoArray *type_forwarders;
MonoArray *pktoken; /* as hexadecimal byte[] */
guint32 access;
} MonoReflectionAssemblyBuilder;

/* Safely access System.Reflection.Emit.AssemblyBuilder from native code */
Expand Down Expand Up @@ -1217,11 +1174,8 @@ typedef struct {
gint32 num_types;
MonoArray *types;
MonoArray *cattrs;
MonoArray *guid;
guint32 table_idx;
MonoReflectionAssemblyBuilder *assemblyb;
MonoArray *global_methods;
MonoArray *global_fields;
gboolean is_main;
MonoArray *resources;
GHashTable *unparented_classes;
Expand Down Expand Up @@ -1260,7 +1214,6 @@ struct _MonoReflectionTypeBuilder {
gint32 packing_size;
MonoGenericContainer *generic_container;
MonoArray *generic_params;
MonoArray *permissions;
MonoReflectionType *created;
gint32 state;
};
Expand Down
Loading