Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJb Evain <jbevain@gmail.com>2015-08-28 11:06:19 +0300
committerJb Evain <jbevain@gmail.com>2015-08-28 11:06:19 +0300
commit67a2569688a13a6cb487f9af5c3418f7a8f43e3c (patch)
tree35013abf36d900d7543ce90381ad7d1efcca1ab7
parent12f981e0b482d7dce21c2efa935c9f4d5cbed8b3 (diff)
parent0c0de8bfe6eb234b210764cb09742ab18d4fb4fb (diff)
Merge pull request #237 from jbevain/fix-roundtrip-resolve
Do not force the resolution of attributes when writing a deferred Image as we can write them unresolved
-rw-r--r--Mono.Cecil/AssemblyReader.cs44
-rw-r--r--Mono.Cecil/AssemblyWriter.cs6
-rw-r--r--Test/Mono.Cecil.Tests/CustomAttributesTests.cs4
-rw-r--r--Test/Resources/il/ca-empty-blob.il21
-rw-r--r--Test/Resources/il/types.il12
5 files changed, 53 insertions, 34 deletions
diff --git a/Mono.Cecil/AssemblyReader.cs b/Mono.Cecil/AssemblyReader.cs
index 451ec56..ff53e4c 100644
--- a/Mono.Cecil/AssemblyReader.cs
+++ b/Mono.Cecil/AssemblyReader.cs
@@ -120,6 +120,8 @@ namespace Mono.Cecil {
sealed class ImmediateModuleReader : ModuleReader {
+ private bool resolve;
+
public ImmediateModuleReader (Image image)
: base (image, ReadingMode.Immediate)
{
@@ -129,13 +131,15 @@ namespace Mono.Cecil {
{
this.module.Read (this.module, (module, reader) => {
ReadModuleManifest (reader);
- ReadModule (module);
+ ReadModule (module, resolve: true);
return module;
});
}
- public static void ReadModule (ModuleDefinition module)
+ public void ReadModule (ModuleDefinition module, bool resolve)
{
+ this.resolve = resolve;
+
if (module.HasAssemblyReferences)
Read (module.AssemblyReferences);
if (module.HasResources)
@@ -146,26 +150,24 @@ namespace Mono.Cecil {
ReadTypes (module.Types);
if (module.HasExportedTypes)
Read (module.ExportedTypes);
- if (module.HasCustomAttributes)
- Read (module.CustomAttributes);
+
+ ReadCustomAttributes (module);
var assembly = module.Assembly;
if (assembly == null)
return;
- if (assembly.HasCustomAttributes)
- ReadCustomAttributes (assembly);
- if (assembly.HasSecurityDeclarations)
- Read (assembly.SecurityDeclarations);
+ ReadCustomAttributes (assembly);
+ ReadSecurityDeclarations (assembly);
}
- static void ReadTypes (Collection<TypeDefinition> types)
+ void ReadTypes (Collection<TypeDefinition> types)
{
for (int i = 0; i < types.Count; i++)
ReadType (types [i]);
}
- static void ReadType (TypeDefinition type)
+ void ReadType (TypeDefinition type)
{
ReadGenericParameters (type);
@@ -194,7 +196,7 @@ namespace Mono.Cecil {
ReadCustomAttributes (type);
}
- static void ReadGenericParameters (IGenericParameterProvider provider)
+ void ReadGenericParameters (IGenericParameterProvider provider)
{
if (!provider.HasGenericParameters)
return;
@@ -211,13 +213,16 @@ namespace Mono.Cecil {
}
}
- static void ReadSecurityDeclarations (ISecurityDeclarationProvider provider)
+ void ReadSecurityDeclarations (ISecurityDeclarationProvider provider)
{
if (!provider.HasSecurityDeclarations)
return;
var security_declarations = provider.SecurityDeclarations;
+ if (!resolve)
+ return;
+
for (int i = 0; i < security_declarations.Count; i++) {
var security_declaration = security_declarations [i];
@@ -225,13 +230,16 @@ namespace Mono.Cecil {
}
}
- static void ReadCustomAttributes (ICustomAttributeProvider provider)
+ void ReadCustomAttributes (ICustomAttributeProvider provider)
{
if (!provider.HasCustomAttributes)
return;
var custom_attributes = provider.CustomAttributes;
+ if (!resolve)
+ return;
+
for (int i = 0; i < custom_attributes.Count; i++) {
var custom_attribute = custom_attributes [i];
@@ -239,7 +247,7 @@ namespace Mono.Cecil {
}
}
- static void ReadFields (TypeDefinition type)
+ void ReadFields (TypeDefinition type)
{
var fields = type.Fields;
@@ -262,7 +270,7 @@ namespace Mono.Cecil {
}
}
- static void ReadMethods (TypeDefinition type)
+ void ReadMethods (TypeDefinition type)
{
var methods = type.Methods;
@@ -294,7 +302,7 @@ namespace Mono.Cecil {
}
}
- static void ReadParameters (MethodDefinition method)
+ void ReadParameters (MethodDefinition method)
{
var parameters = method.Parameters;
@@ -311,7 +319,7 @@ namespace Mono.Cecil {
}
}
- static void ReadProperties (TypeDefinition type)
+ void ReadProperties (TypeDefinition type)
{
var properties = type.Properties;
@@ -327,7 +335,7 @@ namespace Mono.Cecil {
}
}
- static void ReadEvents (TypeDefinition type)
+ void ReadEvents (TypeDefinition type)
{
var events = type.Events;
diff --git a/Mono.Cecil/AssemblyWriter.cs b/Mono.Cecil/AssemblyWriter.cs
index b96d42d..2fd8e2c 100644
--- a/Mono.Cecil/AssemblyWriter.cs
+++ b/Mono.Cecil/AssemblyWriter.cs
@@ -66,8 +66,10 @@ namespace Mono.Cecil {
if ((module.Attributes & ModuleAttributes.ILOnly) == 0)
throw new NotSupportedException ("Writing mixed-mode assemblies is not supported");
- if (module.HasImage && module.ReadingMode == ReadingMode.Deferred)
- ImmediateModuleReader.ReadModule (module);
+ if (module.HasImage && module.ReadingMode == ReadingMode.Deferred) {
+ var immediate_reader = new ImmediateModuleReader (module.Image);
+ immediate_reader.ReadModule (module, resolve: false);
+ }
module.MetadataSystem.Clear ();
diff --git a/Test/Mono.Cecil.Tests/CustomAttributesTests.cs b/Test/Mono.Cecil.Tests/CustomAttributesTests.cs
index 5a1d4b6..5af0467 100644
--- a/Test/Mono.Cecil.Tests/CustomAttributesTests.cs
+++ b/Test/Mono.Cecil.Tests/CustomAttributesTests.cs
@@ -404,11 +404,11 @@ namespace Mono.Cecil.Tests {
[Test]
public void EmptyBlob ()
{
- TestIL ("types.il", module => {
+ TestIL ("ca-empty-blob.il", module => {
var attribute = module.GetType ("CustomAttribute");
Assert.AreEqual (1, attribute.CustomAttributes.Count);
Assert.AreEqual (0, attribute.CustomAttributes [0].ConstructorArguments.Count);
- });
+ }, verify: !Platform.OnMono);
}
[Test]
diff --git a/Test/Resources/il/ca-empty-blob.il b/Test/Resources/il/ca-empty-blob.il
new file mode 100644
index 0000000..2d3d780
--- /dev/null
+++ b/Test/Resources/il/ca-empty-blob.il
@@ -0,0 +1,21 @@
+.assembly extern mscorlib
+{
+ .publickeytoken = (B7 7A 5C 56 19 34 E0 89)
+ .ver 2:0:0:0
+}
+
+.assembly CaEmptyBlob {}
+
+.module CaEmptyBlob.dll
+
+.class public auto ansi CustomAttribute extends [mscorlib]System.Attribute
+{
+ .custom instance void CustomAttribute::.ctor() = ()
+
+ .method public hidebysig specialname rtspecialname instance void .ctor()
+ {
+ ldarg.0
+ call instance void [mscorlib]System.Attribute::.ctor()
+ ret
+ }
+}
diff --git a/Test/Resources/il/types.il b/Test/Resources/il/types.il
index b230c21..4c9acaf 100644
--- a/Test/Resources/il/types.il
+++ b/Test/Resources/il/types.il
@@ -44,15 +44,3 @@
.field private static literal int16 int16_char = char(0x0073)
.field private static literal int32 int32_nullref = nullref
}
-
-.class public auto ansi CustomAttribute extends [mscorlib]System.Attribute
-{
- .custom instance void CustomAttribute::.ctor() = ()
-
- .method public hidebysig specialname rtspecialname instance void .ctor()
- {
- ldarg.0
- call instance void [mscorlib]System.Attribute::.ctor()
- ret
- }
-}