Browse Source

Make Cecil property getters thread-safe.

pull/37/head
Daniel Grunwald 15 years ago
parent
commit
32bd96922e
  1. 6
      Mono.Cecil/Mono.Cecil/AssemblyDefinition.cs
  2. 7
      Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs
  3. 3
      Mono.Cecil/Mono.Cecil/AssemblyReader.cs
  4. 33
      Mono.Cecil/Mono.Cecil/CustomAttribute.cs
  5. 20
      Mono.Cecil/Mono.Cecil/EventDefinition.cs
  6. 4
      Mono.Cecil/Mono.Cecil/FieldDefinition.cs
  7. 4
      Mono.Cecil/Mono.Cecil/GenericParameter.cs
  8. 7
      Mono.Cecil/Mono.Cecil/IConstantProvider.cs
  9. 6
      Mono.Cecil/Mono.Cecil/ICustomAttributeProvider.cs
  10. 5
      Mono.Cecil/Mono.Cecil/IGenericParameterProvider.cs
  11. 3
      Mono.Cecil/Mono.Cecil/IMarshalInfoProvider.cs
  12. 26
      Mono.Cecil/Mono.Cecil/MethodDefinition.cs
  13. 50
      Mono.Cecil/Mono.Cecil/ModuleDefinition.cs
  14. 4
      Mono.Cecil/Mono.Cecil/ParameterDefinition.cs
  15. 16
      Mono.Cecil/Mono.Cecil/PropertyDefinition.cs
  16. 7
      Mono.Cecil/Mono.Cecil/SecurityDeclaration.cs
  17. 18
      Mono.Cecil/Mono.Cecil/TypeDefinition.cs
  18. 61
      Mono.Cecil/Mono.Cecil/TypeSystem.cs

6
Mono.Cecil/Mono.Cecil/AssemblyDefinition.cs

@ -62,7 +62,7 @@ namespace Mono.Cecil { @@ -62,7 +62,7 @@ namespace Mono.Cecil {
return modules;
if (main_module.HasImage)
return modules = main_module.Read (this, (_, reader) => reader.ReadModules ());
return main_module.Read (ref modules, this, (_, reader) => reader.ReadModules ());
return modules = new Collection<ModuleDefinition> { main_module };
}
@ -87,7 +87,7 @@ namespace Mono.Cecil { @@ -87,7 +87,7 @@ namespace Mono.Cecil {
}
public Collection<CustomAttribute> CustomAttributes {
get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (main_module)); }
get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, main_module)); }
}
public bool HasSecurityDeclarations {
@ -100,7 +100,7 @@ namespace Mono.Cecil { @@ -100,7 +100,7 @@ namespace Mono.Cecil {
}
public Collection<SecurityDeclaration> SecurityDeclarations {
get { return security_declarations ?? (security_declarations = this.GetSecurityDeclarations (main_module)); }
get { return security_declarations ?? (this.GetSecurityDeclarations (ref security_declarations, main_module)); }
}
internal AssemblyDefinition ()

7
Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs

@ -107,9 +107,10 @@ namespace Mono.Cecil { @@ -107,9 +107,10 @@ namespace Mono.Cecil {
if (public_key_token.IsNullOrEmpty () && !public_key.IsNullOrEmpty ()) {
var hash = HashPublicKey ();
// we need the last 8 bytes in reverse order
public_key_token = new byte [8];
Array.Copy (hash, (hash.Length - 8), public_key_token, 0, 8);
Array.Reverse (public_key_token, 0, 8);
byte[] local_public_key_token = new byte [8];
Array.Copy (hash, (hash.Length - 8), local_public_key_token, 0, 8);
Array.Reverse (local_public_key_token, 0, 8);
public_key_token = local_public_key_token; // publish only once finished (required for thread-safety)
}
return public_key_token;
}

3
Mono.Cecil/Mono.Cecil/AssemblyReader.cs

@ -1558,10 +1558,11 @@ namespace Mono.Cecil { @@ -1558,10 +1558,11 @@ namespace Mono.Cecil {
var methods = type.Methods;
for (int i = 0; i < methods.Count; i++) {
var method = methods [i];
if (method.sem_attrs.HasValue)
if (method.sem_attrs_ready)
continue;
method.sem_attrs = ReadMethodSemantics (method);
method.sem_attrs_ready = true;
}
}

33
Mono.Cecil/Mono.Cecil/CustomAttribute.cs

@ -191,7 +191,7 @@ namespace Mono.Cecil { @@ -191,7 +191,7 @@ namespace Mono.Cecil {
if (!HasImage || signature == 0)
throw new NotSupportedException ();
return blob = Module.Read (this, (attribute, reader) => reader.ReadCustomAttributeBlob (attribute.signature));
return Module.Read (ref blob, this, (attribute, reader) => reader.ReadCustomAttributeBlob (attribute.signature));
}
void Resolve ()
@ -199,23 +199,22 @@ namespace Mono.Cecil { @@ -199,23 +199,22 @@ namespace Mono.Cecil {
if (resolved || !HasImage)
return;
try {
Module.Read (this, (attribute, reader) => {
Module.Read (this, (attribute, reader) => {
try {
reader.ReadCustomAttributeSignature (attribute);
return this;
});
resolved = true;
} catch (ResolutionException) {
if (arguments != null)
arguments.Clear ();
if (fields != null)
fields.Clear ();
if (properties != null)
properties.Clear ();
resolved = false;
}
resolved = true;
} catch (ResolutionException) {
if (arguments != null)
arguments.Clear ();
if (fields != null)
fields.Clear ();
if (properties != null)
properties.Clear ();
resolved = false;
}
return this;
});
}
}

20
Mono.Cecil/Mono.Cecil/EventDefinition.cs

@ -113,7 +113,7 @@ namespace Mono.Cecil { @@ -113,7 +113,7 @@ namespace Mono.Cecil {
}
public Collection<CustomAttribute> CustomAttributes {
get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); }
get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, Module)); }
}
#region EventAttributes
@ -148,16 +148,18 @@ namespace Mono.Cecil { @@ -148,16 +148,18 @@ namespace Mono.Cecil {
void InitializeMethods ()
{
if (add_method != null
|| invoke_method != null
|| remove_method != null)
return;
var module = this.Module;
if (!module.HasImage ())
return;
lock (module.SyncRoot) {
if (add_method != null
|| invoke_method != null
|| remove_method != null)
return;
if (!module.HasImage ())
return;
module.Read (this, (@event, reader) => reader.ReadMethods (@event));
module.Read (this, (@event, reader) => reader.ReadMethods (@event));
}
}
public override EventDefinition Resolve ()

4
Mono.Cecil/Mono.Cecil/FieldDefinition.cs

@ -154,7 +154,7 @@ namespace Mono.Cecil { @@ -154,7 +154,7 @@ namespace Mono.Cecil {
}
public Collection<CustomAttribute> CustomAttributes {
get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); }
get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, Module)); }
}
public bool HasMarshalInfo {
@ -167,7 +167,7 @@ namespace Mono.Cecil { @@ -167,7 +167,7 @@ namespace Mono.Cecil {
}
public MarshalInfo MarshalInfo {
get { return marshal_info ?? (marshal_info = this.GetMarshalInfo (Module)); }
get { return marshal_info ?? (this.GetMarshalInfo (ref marshal_info, Module)); }
set { marshal_info = value; }
}

4
Mono.Cecil/Mono.Cecil/GenericParameter.cs

@ -78,7 +78,7 @@ namespace Mono.Cecil { @@ -78,7 +78,7 @@ namespace Mono.Cecil {
return constraints;
if (HasImage)
return constraints = Module.Read (this, (generic_parameter, reader) => reader.ReadGenericConstraints (generic_parameter));
return Module.Read (ref constraints, this, (generic_parameter, reader) => reader.ReadGenericConstraints (generic_parameter));
return constraints = new Collection<TypeReference> ();
}
@ -94,7 +94,7 @@ namespace Mono.Cecil { @@ -94,7 +94,7 @@ namespace Mono.Cecil {
}
public Collection<CustomAttribute> CustomAttributes {
get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); }
get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, Module)); }
}
internal new bool HasImage {

7
Mono.Cecil/Mono.Cecil/IConstantProvider.cs

@ -44,9 +44,10 @@ namespace Mono.Cecil { @@ -44,9 +44,10 @@ namespace Mono.Cecil {
ref object constant,
ModuleDefinition module)
{
constant = module.HasImage ()
? module.Read (self, (provider, reader) => reader.ReadConstant (provider))
: Mixin.NoValue;
if (module.HasImage ())
module.Read (ref constant, self, (provider, reader) => reader.ReadConstant (provider));
else
constant = Mixin.NoValue;
}
}
}

6
Mono.Cecil/Mono.Cecil/ICustomAttributeProvider.cs

@ -27,7 +27,6 @@ @@ -27,7 +27,6 @@
//
using System;
using Mono.Collections.Generic;
namespace Mono.Cecil {
@ -52,11 +51,12 @@ namespace Mono.Cecil { @@ -52,11 +51,12 @@ namespace Mono.Cecil {
public static Collection<CustomAttribute> GetCustomAttributes (
this ICustomAttributeProvider self,
ref Collection<CustomAttribute> variable,
ModuleDefinition module)
{
return module.HasImage ()
? module.Read (self, (provider, reader) => reader.ReadCustomAttributes (provider))
: new Collection<CustomAttribute> ();
? module.Read (ref variable, self, (provider, reader) => reader.ReadCustomAttributes (provider))
: variable = new Collection<CustomAttribute>();
}
}
}

5
Mono.Cecil/Mono.Cecil/IGenericParameterProvider.cs

@ -65,11 +65,12 @@ namespace Mono.Cecil { @@ -65,11 +65,12 @@ namespace Mono.Cecil {
public static Collection<GenericParameter> GetGenericParameters (
this IGenericParameterProvider self,
ref Collection<GenericParameter> collection,
ModuleDefinition module)
{
return module.HasImage ()
? module.Read (self, (provider, reader) => reader.ReadGenericParameters (provider))
: new Collection<GenericParameter> ();
? module.Read (ref collection, self, (provider, reader) => reader.ReadGenericParameters (provider))
: collection = new Collection<GenericParameter> ();
}
}
}

3
Mono.Cecil/Mono.Cecil/IMarshalInfoProvider.cs

@ -47,10 +47,11 @@ namespace Mono.Cecil { @@ -47,10 +47,11 @@ namespace Mono.Cecil {
public static MarshalInfo GetMarshalInfo (
this IMarshalInfoProvider self,
ref MarshalInfo variable,
ModuleDefinition module)
{
return module.HasImage ()
? module.Read (self, (provider, reader) => reader.ReadMarshalInfo (provider))
? module.Read (ref variable, self, (provider, reader) => reader.ReadMarshalInfo (provider))
: null;
}
}

26
Mono.Cecil/Mono.Cecil/MethodDefinition.cs

@ -37,7 +37,8 @@ namespace Mono.Cecil { @@ -37,7 +37,8 @@ namespace Mono.Cecil {
ushort attributes;
ushort impl_attributes;
internal MethodSemanticsAttributes? sem_attrs;
internal volatile bool sem_attrs_ready;
internal MethodSemanticsAttributes sem_attrs;
Collection<CustomAttribute> custom_attributes;
Collection<SecurityDeclaration> security_declarations;
@ -59,23 +60,24 @@ namespace Mono.Cecil { @@ -59,23 +60,24 @@ namespace Mono.Cecil {
public MethodSemanticsAttributes SemanticsAttributes {
get {
if (sem_attrs.HasValue)
return sem_attrs.Value;
if (sem_attrs_ready)
return sem_attrs;
if (HasImage) {
ReadSemantics ();
return sem_attrs.Value;
return sem_attrs;
}
sem_attrs = MethodSemanticsAttributes.None;
return sem_attrs.Value;
sem_attrs_ready = true;
return sem_attrs;
}
set { sem_attrs = value; }
}
internal void ReadSemantics ()
{
if (sem_attrs.HasValue)
if (sem_attrs_ready)
return;
var module = this.Module;
@ -98,7 +100,7 @@ namespace Mono.Cecil { @@ -98,7 +100,7 @@ namespace Mono.Cecil {
}
public Collection<SecurityDeclaration> SecurityDeclarations {
get { return security_declarations ?? (security_declarations = this.GetSecurityDeclarations (Module)); }
get { return security_declarations ?? (this.GetSecurityDeclarations (ref security_declarations, Module)); }
}
public bool HasCustomAttributes {
@ -111,7 +113,7 @@ namespace Mono.Cecil { @@ -111,7 +113,7 @@ namespace Mono.Cecil {
}
public Collection<CustomAttribute> CustomAttributes {
get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); }
get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, Module)); }
}
public int RVA {
@ -138,7 +140,7 @@ namespace Mono.Cecil { @@ -138,7 +140,7 @@ namespace Mono.Cecil {
return null;
if (HasImage && rva != 0)
return body = Module.Read (this, (method, reader) => reader.ReadMethodBody (method));
return Module.Read (ref body, this, (method, reader) => reader.ReadMethodBody (method));
return body = new MethodBody (this);
}
@ -160,7 +162,7 @@ namespace Mono.Cecil { @@ -160,7 +162,7 @@ namespace Mono.Cecil {
return pinvoke;
if (HasImage && IsPInvokeImpl)
return pinvoke = Module.Read (this, (method, reader) => reader.ReadPInvokeInfo (method));
return Module.Read (ref pinvoke, this, (method, reader) => reader.ReadPInvokeInfo (method));
return null;
}
@ -188,7 +190,7 @@ namespace Mono.Cecil { @@ -188,7 +190,7 @@ namespace Mono.Cecil {
return overrides;
if (HasImage)
return overrides = Module.Read (this, (method, reader) => reader.ReadOverrides (method));
return Module.Read (ref overrides, this, (method, reader) => reader.ReadOverrides (method));
return overrides = new Collection<MethodReference> ();
}
@ -204,7 +206,7 @@ namespace Mono.Cecil { @@ -204,7 +206,7 @@ namespace Mono.Cecil {
}
public override Collection<GenericParameter> GenericParameters {
get { return generic_parameters ?? (generic_parameters = this.GetGenericParameters (Module)); }
get { return generic_parameters ?? (this.GetGenericParameters (ref generic_parameters, Module)); }
}
#region MethodAttributes

50
Mono.Cecil/Mono.Cecil/ModuleDefinition.cs

@ -29,8 +29,8 @@ @@ -29,8 +29,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using SR = System.Reflection;
using Mono.Cecil.Cil;
using Mono.Cecil.Metadata;
using Mono.Cecil.PE;
@ -261,7 +261,11 @@ namespace Mono.Cecil { @@ -261,7 +261,11 @@ namespace Mono.Cecil {
#if !READ_ONLY
internal MetadataImporter MetadataImporter {
get { return importer ?? (importer = new MetadataImporter (this)); }
get {
if (importer == null)
Interlocked.CompareExchange(ref importer, new MetadataImporter(this), null);
return importer;
}
}
#endif
@ -270,7 +274,11 @@ namespace Mono.Cecil { @@ -270,7 +274,11 @@ namespace Mono.Cecil {
}
public TypeSystem TypeSystem {
get { return type_system ?? (type_system = TypeSystem.CreateTypeSystem (this)); }
get {
if (type_system == null)
Interlocked.CompareExchange(ref type_system, TypeSystem.CreateTypeSystem (this), null);
return type_system;
}
}
public bool HasAssemblyReferences {
@ -288,7 +296,7 @@ namespace Mono.Cecil { @@ -288,7 +296,7 @@ namespace Mono.Cecil {
return references;
if (HasImage)
return references = Read (this, (_, reader) => reader.ReadAssemblyReferences ());
return Read (ref references, this, (_, reader) => reader.ReadAssemblyReferences ());
return references = new Collection<AssemblyNameReference> ();
}
@ -309,7 +317,7 @@ namespace Mono.Cecil { @@ -309,7 +317,7 @@ namespace Mono.Cecil {
return modules;
if (HasImage)
return modules = Read (this, (_, reader) => reader.ReadModuleReferences ());
return Read (ref modules, this, (_, reader) => reader.ReadModuleReferences ());
return modules = new Collection<ModuleReference> ();
}
@ -333,7 +341,7 @@ namespace Mono.Cecil { @@ -333,7 +341,7 @@ namespace Mono.Cecil {
return resources;
if (HasImage)
return resources = Read (this, (_, reader) => reader.ReadResources ());
return Read (ref resources, this, (_, reader) => reader.ReadResources ());
return resources = new Collection<Resource> ();
}
@ -349,7 +357,7 @@ namespace Mono.Cecil { @@ -349,7 +357,7 @@ namespace Mono.Cecil {
}
public Collection<CustomAttribute> CustomAttributes {
get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (this)); }
get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, this)); }
}
public bool HasTypes {
@ -367,7 +375,7 @@ namespace Mono.Cecil { @@ -367,7 +375,7 @@ namespace Mono.Cecil {
return types;
if (HasImage)
return types = Read (this, (_, reader) => reader.ReadTypes ());
return Read (ref types, this, (_, reader) => reader.ReadTypes ());
return types = new TypeDefinitionCollection (this);
}
@ -388,7 +396,7 @@ namespace Mono.Cecil { @@ -388,7 +396,7 @@ namespace Mono.Cecil {
return exported_types;
if (HasImage)
return exported_types = Read (this, (_, reader) => reader.ReadExportedTypes ());
return Read (ref exported_types, this, (_, reader) => reader.ReadExportedTypes ());
return exported_types = new Collection<ExportedType> ();
}
@ -400,7 +408,7 @@ namespace Mono.Cecil { @@ -400,7 +408,7 @@ namespace Mono.Cecil {
return entry_point;
if (HasImage)
return entry_point = Read (this, (_, reader) => reader.ReadEntryPoint ());
return Read (ref entry_point, this, (_, reader) => reader.ReadEntryPoint ());
return entry_point = null;
}
@ -760,6 +768,10 @@ namespace Mono.Cecil { @@ -760,6 +768,10 @@ namespace Mono.Cecil {
readonly object module_lock = new object();
internal object SyncRoot {
get { return module_lock; }
}
internal TRet Read<TItem, TRet> (TItem item, Func<TItem, MetadataReader, TRet> read)
{
lock (module_lock) {
@ -774,6 +786,24 @@ namespace Mono.Cecil { @@ -774,6 +786,24 @@ namespace Mono.Cecil {
return ret;
}
}
internal TRet Read<TItem, TRet> (ref TRet variable, TItem item, Func<TItem, MetadataReader, TRet> read) where TRet : class
{
lock (module_lock) {
if (variable != null)
return variable;
var position = reader.position;
var context = reader.context;
var ret = read (item, reader);
reader.position = position;
reader.context = context;
return variable = ret;
}
}
void ProcessDebugHeader ()
{

4
Mono.Cecil/Mono.Cecil/ParameterDefinition.cs

@ -81,7 +81,7 @@ namespace Mono.Cecil { @@ -81,7 +81,7 @@ namespace Mono.Cecil {
}
public Collection<CustomAttribute> CustomAttributes {
get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (parameter_type.Module)); }
get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, parameter_type.Module)); }
}
public bool HasMarshalInfo {
@ -94,7 +94,7 @@ namespace Mono.Cecil { @@ -94,7 +94,7 @@ namespace Mono.Cecil {
}
public MarshalInfo MarshalInfo {
get { return marshal_info ?? (marshal_info = this.GetMarshalInfo (parameter_type.Module)); }
get { return marshal_info ?? (this.GetMarshalInfo (ref marshal_info, parameter_type.Module)); }
set { marshal_info = value; }
}

16
Mono.Cecil/Mono.Cecil/PropertyDefinition.cs

@ -76,7 +76,7 @@ namespace Mono.Cecil { @@ -76,7 +76,7 @@ namespace Mono.Cecil {
}
public Collection<CustomAttribute> CustomAttributes {
get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); }
get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, Module)); }
}
public MethodDefinition GetMethod {
@ -245,14 +245,16 @@ namespace Mono.Cecil { @@ -245,14 +245,16 @@ namespace Mono.Cecil {
void InitializeMethods ()
{
if (get_method != null || set_method != null)
return;
var module = this.Module;
if (!module.HasImage ())
return;
lock (module.SyncRoot) {
if (get_method != null || set_method != null)
return;
module.Read (this, (property, reader) => reader.ReadMethods (property));
if (!module.HasImage ())
return;
module.Read (this, (property, reader) => reader.ReadMethods (property));
}
}
public override PropertyDefinition Resolve ()

7
Mono.Cecil/Mono.Cecil/SecurityDeclaration.cs

@ -27,7 +27,7 @@ @@ -27,7 +27,7 @@
//
using System;
using System.Threading;
using Mono.Collections.Generic;
namespace Mono.Cecil {
@ -172,11 +172,12 @@ namespace Mono.Cecil { @@ -172,11 +172,12 @@ namespace Mono.Cecil {
public static Collection<SecurityDeclaration> GetSecurityDeclarations (
this ISecurityDeclarationProvider self,
ref Collection<SecurityDeclaration> variable,
ModuleDefinition module)
{
return module.HasImage ()
? module.Read (self, (provider, reader) => reader.ReadSecurityDeclarations (provider))
: new Collection<SecurityDeclaration> ();
? module.Read (ref variable, self, (provider, reader) => reader.ReadSecurityDeclarations (provider))
: LazyInitializer.EnsureInitialized(ref variable);
}
}
}

18
Mono.Cecil/Mono.Cecil/TypeDefinition.cs

@ -131,7 +131,7 @@ namespace Mono.Cecil { @@ -131,7 +131,7 @@ namespace Mono.Cecil {
return interfaces;
if (HasImage)
return interfaces = Module.Read (this, (type, reader) => reader.ReadInterfaces (type));
return Module.Read (ref interfaces, this, (type, reader) => reader.ReadInterfaces (type));
return interfaces = new Collection<TypeReference> ();
}
@ -155,7 +155,7 @@ namespace Mono.Cecil { @@ -155,7 +155,7 @@ namespace Mono.Cecil {
return nested_types;
if (HasImage)
return nested_types = Module.Read (this, (type, reader) => reader.ReadNestedTypes (type));
return Module.Read (ref nested_types, this, (type, reader) => reader.ReadNestedTypes (type));
return nested_types = new MemberDefinitionCollection<TypeDefinition> (this);
}
@ -183,7 +183,7 @@ namespace Mono.Cecil { @@ -183,7 +183,7 @@ namespace Mono.Cecil {
return methods;
if (HasImage)
return methods = Module.Read (this, (type, reader) => reader.ReadMethods (type));
return Module.Read (ref methods, this, (type, reader) => reader.ReadMethods (type));
return methods = new MemberDefinitionCollection<MethodDefinition> (this);
}
@ -207,7 +207,7 @@ namespace Mono.Cecil { @@ -207,7 +207,7 @@ namespace Mono.Cecil {
return fields;
if (HasImage)
return fields = Module.Read (this, (type, reader) => reader.ReadFields (type));
return Module.Read (ref fields, this, (type, reader) => reader.ReadFields (type));
return fields = new MemberDefinitionCollection<FieldDefinition> (this);
}
@ -231,7 +231,7 @@ namespace Mono.Cecil { @@ -231,7 +231,7 @@ namespace Mono.Cecil {
return events;
if (HasImage)
return events = Module.Read (this, (type, reader) => reader.ReadEvents (type));
return Module.Read (ref events, this, (type, reader) => reader.ReadEvents (type));
return events = new MemberDefinitionCollection<EventDefinition> (this);
}
@ -255,7 +255,7 @@ namespace Mono.Cecil { @@ -255,7 +255,7 @@ namespace Mono.Cecil {
return properties;
if (HasImage)
return properties = Module.Read (this, (type, reader) => reader.ReadProperties (type));
return Module.Read (ref properties, this, (type, reader) => reader.ReadProperties (type));
return properties = new MemberDefinitionCollection<PropertyDefinition> (this);
}
@ -271,7 +271,7 @@ namespace Mono.Cecil { @@ -271,7 +271,7 @@ namespace Mono.Cecil {
}
public Collection<SecurityDeclaration> SecurityDeclarations {
get { return security_declarations ?? (security_declarations = this.GetSecurityDeclarations (Module)); }
get { return security_declarations ?? (this.GetSecurityDeclarations (ref security_declarations, Module)); }
}
public bool HasCustomAttributes {
@ -284,7 +284,7 @@ namespace Mono.Cecil { @@ -284,7 +284,7 @@ namespace Mono.Cecil {
}
public Collection<CustomAttribute> CustomAttributes {
get { return custom_attributes ?? (custom_attributes = this.GetCustomAttributes (Module)); }
get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, Module)); }
}
public override bool HasGenericParameters {
@ -297,7 +297,7 @@ namespace Mono.Cecil { @@ -297,7 +297,7 @@ namespace Mono.Cecil {
}
public override Collection<GenericParameter> GenericParameters {
get { return generic_parameters ?? (generic_parameters = this.GetGenericParameters (Module)); }
get { return generic_parameters ?? (this.GetGenericParameters (ref generic_parameters, Module)); }
}
#region TypeAttributes

61
Mono.Cecil/Mono.Cecil/TypeSystem.cs

@ -174,18 +174,27 @@ namespace Mono.Cecil { @@ -174,18 +174,27 @@ namespace Mono.Cecil {
internal abstract TypeReference LookupType (string @namespace, string name);
TypeReference LookupSystemType (string name, ElementType element_type)
TypeReference LookupSystemType (ref TypeReference typeRef, string name, ElementType element_type)
{
var type = LookupType ("System", name);
type.etype = element_type;
return type;
lock (module.SyncRoot) {
if (typeRef != null)
return typeRef;
var type = LookupType ("System", name);
type.etype = element_type;
return typeRef = type;
}
}
TypeReference LookupSystemValueType (string name, ElementType element_type)
TypeReference LookupSystemValueType (ref TypeReference typeRef, string name, ElementType element_type)
{
var type = LookupSystemType (name, element_type);
type.IsValueType = true;
return type;
lock (module.SyncRoot) {
if (typeRef != null)
return typeRef;
var type = LookupType ("System", name);
type.etype = element_type;
type.IsValueType = true;
return typeRef = type;
}
}
public IMetadataScope Corlib {
@ -199,75 +208,75 @@ namespace Mono.Cecil { @@ -199,75 +208,75 @@ namespace Mono.Cecil {
}
public TypeReference Object {
get { return type_object ?? (type_object = LookupSystemType ("Object", ElementType.Object)); }
get { return type_object ?? (LookupSystemType (ref type_object, "Object", ElementType.Object)); }
}
public TypeReference Void {
get { return type_void ?? (type_void = LookupSystemType ("Void", ElementType.Void)); }
get { return type_void ?? (LookupSystemType (ref type_void, "Void", ElementType.Void)); }
}
public TypeReference Boolean {
get { return type_bool ?? (type_bool = LookupSystemValueType ("Boolean", ElementType.Boolean)); }
get { return type_bool ?? (LookupSystemValueType (ref type_bool, "Boolean", ElementType.Boolean)); }
}
public TypeReference Char {
get { return type_char ?? (type_char = LookupSystemValueType ("Char", ElementType.Char)); }
get { return type_char ?? (LookupSystemValueType (ref type_char, "Char", ElementType.Char)); }
}
public TypeReference SByte {
get { return type_sbyte ?? (type_sbyte = LookupSystemValueType ("SByte", ElementType.I1)); }
get { return type_sbyte ?? (LookupSystemValueType (ref type_sbyte, "SByte", ElementType.I1)); }
}
public TypeReference Byte {
get { return type_byte ?? (type_byte = LookupSystemValueType ("Byte", ElementType.U1)); }
get { return type_byte ?? (LookupSystemValueType (ref type_byte, "Byte", ElementType.U1)); }
}
public TypeReference Int16 {
get { return type_int16 ?? (type_int16 = LookupSystemValueType ("Int16", ElementType.I2)); }
get { return type_int16 ?? (LookupSystemValueType (ref type_int16, "Int16", ElementType.I2)); }
}
public TypeReference UInt16 {
get { return type_uint16 ?? (type_uint16 = LookupSystemValueType ("UInt16", ElementType.U2)); }
get { return type_uint16 ?? (LookupSystemValueType (ref type_uint16, "UInt16", ElementType.U2)); }
}
public TypeReference Int32 {
get { return type_int32 ?? (type_int32 = LookupSystemValueType ("Int32", ElementType.I4)); }
get { return type_int32 ?? (LookupSystemValueType (ref type_int32, "Int32", ElementType.I4)); }
}
public TypeReference UInt32 {
get { return type_uint32 ?? (type_uint32 = LookupSystemValueType ("UInt32", ElementType.U4)); }
get { return type_uint32 ?? (LookupSystemValueType (ref type_uint32, "UInt32", ElementType.U4)); }
}
public TypeReference Int64 {
get { return type_int64 ?? (type_int64 = LookupSystemValueType ("Int64", ElementType.I8)); }
get { return type_int64 ?? (LookupSystemValueType (ref type_int64, "Int64", ElementType.I8)); }
}
public TypeReference UInt64 {
get { return type_uint64 ?? (type_uint64 = LookupSystemValueType ("UInt64", ElementType.U8)); }
get { return type_uint64 ?? (LookupSystemValueType (ref type_uint64, "UInt64", ElementType.U8)); }
}
public TypeReference Single {
get { return type_single ?? (type_single = LookupSystemValueType ("Single", ElementType.R4)); }
get { return type_single ?? (LookupSystemValueType (ref type_single, "Single", ElementType.R4)); }
}
public TypeReference Double {
get { return type_double ?? (type_double = LookupSystemValueType ("Double", ElementType.R8)); }
get { return type_double ?? (LookupSystemValueType (ref type_double, "Double", ElementType.R8)); }
}
public TypeReference IntPtr {
get { return type_intptr ?? (type_intptr = LookupSystemValueType ("IntPtr", ElementType.I)); }
get { return type_intptr ?? (LookupSystemValueType (ref type_intptr, "IntPtr", ElementType.I)); }
}
public TypeReference UIntPtr {
get { return type_uintptr ?? (type_uintptr = LookupSystemValueType ("UIntPtr", ElementType.U)); }
get { return type_uintptr ?? (LookupSystemValueType (ref type_uintptr, "UIntPtr", ElementType.U)); }
}
public TypeReference String {
get { return type_string ?? (type_string = LookupSystemType ("String", ElementType.String)); }
get { return type_string ?? (LookupSystemType (ref type_string, "String", ElementType.String)); }
}
public TypeReference TypedReference {
get { return type_typedref ?? (type_typedref = LookupSystemValueType ("TypedReference", ElementType.TypedByRef)); }
get { return type_typedref ?? (LookupSystemValueType (ref type_typedref, "TypedReference", ElementType.TypedByRef)); }
}
}
}

Loading…
Cancel
Save