[Mono-bugs] [Bug 77959][Wis] New - Optional ParameterAttribute and
nullref in Cecil
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Thu Mar 30 05:22:27 EST 2006
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by armand at dotnet.org.za.
http://bugzilla.ximian.com/show_bug.cgi?id=77959
--- shadow/77959 2006-03-30 05:22:27.000000000 -0500
+++ shadow/77959.tmp.18787 2006-03-30 05:22:27.000000000 -0500
@@ -0,0 +1,100 @@
+Bug#: 77959
+Product: Mono: Class Libraries
+Version: 1.1
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: Mono.Cecil
+AssignedTo: mono at evain.net
+ReportedBy: armand at dotnet.org.za
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Optional ParameterAttribute and nullref in Cecil
+
+Description of Problem:
+Background:The Microsoft.VisualBasic assembly contains a special marker
+attribute used to mark parameters as optional as there's no support for
+optional parameters in C#.
+The assembly is then disassembled after compilatation and a perl script
+used to add the opt flag to the parameter etc and reassembled.
+
+I tried running this process through Mono.Cecil and the following issues
+came up:
+1) The ParamAttributes value for Opt is 0x0004 in Mono.Cecil and in the old
+CLI specifications. However running an assembly through Microsoft's ildasm
+it seems to pick up paramattributes optional if the value is 0x0010 which
+is consistent with the 0x0013 mask supplied in Serge Lidin's ".NET IL
+Assembler" book. I just checked the updated draft of Partition II of the
+CLI specs and the updated value is 0x0010 :-) Maybe a bug in the old CLI
+spec :P
+
+23.1.13 Flags for params [ParamAttributes]
+Flag Value Description
+In 0x0001 Param is [In]
+Out 0x0002 Param is [out]
+Optional 0x0010 Param is optional
+
+2) The second issue is the handling of nullref (p121) where parameter
+default values is set to null. According to the spec a nullref should be
+encoded as a "ELEMENT_TYPE_CLASS with a Value of zero" so I've modified
+WriteConstant in ReflectionWriter to check for a null Constant value and
+update the ElementType accordingly. I haven't spent enough time on it to
+determine whether this is actuallly the appropriate or only place to add
+such a modification but have included my diff below.
+
+
+Index: ParamAttributes.cs
+===================================================================
+--- ParamAttributes.cs (revision 58723)
++++ ParamAttributes.cs (working copy)
+@@ -34,7 +34,7 @@
+ public enum ParamAttributes : ushort {
+ In = 0x0001, // Param is [In]
+ Out = 0x0002, // Param is [Out]
+- Optional = 0x0004, // Param is optional
++ Optional = 0x0010, // Param is optional
+ HasDefault = 0x1000, // Param has default value
+ HasFieldMarshal = 0x2000, // Param has field marshal
+ Unused = 0xcfe0 // Reserved: shall be zero in a conforming
+implementation
+
+
+Index: ReflectionWriter.cs
+===================================================================
+--- ReflectionWriter.cs (revision 58723)
++++ ReflectionWriter.cs (working copy)
+@@ -617,15 +617,20 @@
+ {
+ ConstantTable cTable = m_tableWriter.GetConstantTable ();
+ ElementType et;
+- if (type is TypeDefinition && (type as TypeDefinition).IsEnum) {
+- Type t = hc.Constant.GetType ();
+- if (t.IsEnum)
+- t = Enum.GetUnderlyingType (t);
++ if (type is TypeDefinition && (type as TypeDefinition).IsEnum) {
++ Type t = hc.Constant.GetType();
++ if (t.IsEnum)
++ t = Enum.GetUnderlyingType(t);
+
+- et = GetCorrespondingType (string.Concat (t.Namespace, '.', t.Name));
+- } else
+- et = GetCorrespondingType (type.FullName);
+-
++ et = GetCorrespondingType(string.Concat(t.Namespace, '.',
+t.Name));
++ }
++ else {
++ if (hc.Constant == null)
++ et = ElementType.Class;
++ else
++ et = GetCorrespondingType(type.FullName);
++ }
++
+ ConstantRow cRow = m_rowWriter.CreateConstantRow (
+ et,
+ hc.MetadataToken,
More information about the mono-bugs
mailing list