Hey,
Comments below:
El vie, 14-10-2005 a las 09:08 +0100, Marek Safar escribió:
> Hello,
>
> >The attached patch checks the validity of InternalsVisibleToAttribute,
> >and reports and warnings depending on the contents.
> >
> >May I commit?
> >
> >
> - no test for CS1700.
Sorry, since it is a warning I didn't take the time for it. The test is
attached.
> - please use syntax `blabla' for error/warning arguments.
Ok.
>
> + if (a.Type == TypeManager.internals_visible_attr_type)
> + if (!CheckInternalsVisibleAttribute (a))
> + return;
> +
>
> Please use, &&.
Ok.
>
> But I am not sure whether we should commit this to mcs and then
> integrate or to gmcs only.
> Any ideas ?
>
Well, I think we should keep it in gmcs only by now, since it requires
InternalsVisibleToAttribute, which is 2.0 only.
I was trying to figure out a way to commit it to mcs, but they would be
hacks, so I would prefer to keep this in gmcs.
The patch with the changes is attached. Here it's 4 a.m, so I think I
will write the test tomorrow.
Carlos.
Index: typemanager.cs
===================================================================
--- typemanager.cs (revisión: 51640)
+++ typemanager.cs (copia de trabajo)
@@ -107,6 +107,7 @@
static internal Type compiler_generated_attr_type;
static internal Type fixed_buffer_attr_type;
static internal Type default_charset_type;
+ static internal Type internals_visible_attr_type;
//
// An empty array of types
@@ -1143,6 +1144,7 @@
compiler_generated_attr_type = CoreLookupType ("System.Runtime.CompilerServices", "CompilerGeneratedAttribute");
fixed_buffer_attr_type = CoreLookupType ("System.Runtime.CompilerServices", "FixedBufferAttribute");
default_charset_type = CoreLookupType ("System.Runtime.InteropServices", "DefaultCharSetAttribute");
+ internals_visible_attr_type = CoreLookupType ("System.Runtime.CompilerServices", "InternalsVisibleToAttribute");
//
// When compiling corlib, store the "real" types here.
//
Index: codegen.cs
===================================================================
--- codegen.cs (revisión: 51690)
+++ codegen.cs (copia de trabajo)
@@ -144,6 +144,10 @@
return false;
}
+ // Get the complete AssemblyName from the builder
+ // (We need to get the public key and token)
+ Assembly.Name = Assembly.Builder.GetName ();
+
//
// Pass a path-less name to DefineDynamicModule. Wonder how
// this copes with output in different directories then.
@@ -1006,6 +1010,7 @@
public class AssemblyClass: CommonAssemblyModulClass {
// TODO: make it private and move all builder based methods here
public AssemblyBuilder Builder;
+ public AssemblyName Name;
bool is_cls_compliant;
public Attribute ClsCompliantAttribute;
@@ -1196,6 +1201,35 @@
Report.Error (1548, "Error during assembly signing. " + text);
}
+ bool CheckInternalsVisibleAttribute (Attribute a)
+ {
+ string assembly_name = a.GetString ();
+ if (assembly_name.Length == 0)
+ return false;
+
+ AssemblyName aname = null;
+ try {
+ aname = new AssemblyName (assembly_name);
+ } catch (FileLoadException) {
+ } catch (ArgumentException) {
+ }
+
+ // Bad assembly name format
+ if (aname == null)
+ Report.Warning (1700, 3, a.Location, "Assembly reference '" + assembly_name + "' is invalid and cannot be resolved");
+ // Report error if we have defined Version or Culture
+ else if (aname.Version != null || aname.CultureInfo != null)
+ throw new Exception ("Friend assembly `" + a.GetString () +
+ "' is invalid. InternalsVisibleTo cannot have version or culture specified.");
+ else if (aname.GetPublicKeyToken () == null && Name.GetPublicKeyToken () != null) {
+ Report.Error (1726, a.Location, "Friend assembly reference '" + aname.Name + "' is invalid." +
+ " Strong named assemblies must specify a public key token in their InternalsVisibleTo declarations");
+ return false;
+ }
+
+ return true;
+ }
+
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
{
if (a.Type.IsSubclassOf (TypeManager.security_attr_type) && a.CheckSecurityActionValidity (true)) {
@@ -1217,6 +1251,9 @@
}
}
+ if (a.Type == TypeManager.internals_visible_attr_type && !CheckInternalsVisibleAttribute (a))
+ return;
+
Builder.SetCustomAttribute (customBuilder);
}
_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-devel-list