[Mono-bugs] [Bug 68126][Nor] New - CSharpCodeProvider does not recognize /unsafe

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 12 Oct 2004 15:30:20 -0400 (EDT)


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 karl@waclawek.net.

http://bugzilla.ximian.com/show_bug.cgi?id=68126

--- shadow/68126	2004-10-12 15:30:20.000000000 -0400
+++ shadow/68126.tmp.24263	2004-10-12 15:30:20.000000000 -0400
@@ -0,0 +1,144 @@
+Bug#: 68126
+Product: Mono: Class Libraries
+Version: unspecified
+OS: Red Hat 9.0
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: karl@waclawek.net               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: CSharpCodeProvider does not recognize /unsafe
+
+Description of Problem:
+=======================
+
+It is not possible to compile files with unsafe code since 
+ICodeCompiler instances created by CSharpCodeProvider do not
+recognize the /unsafe option.
+
+Steps to reproduce the problem:
+===============================
+
+Two files are needed, one for compiling with CSharpCodeProvider,
+the other as a test target file that has unsafe code.
+
+
+1) Executable for compiling with CSharCodeProvider
+
+Build MonoCompile.exe with
+  mcs /out:MonoCompile.exe /t:exe CompileFile.cs
+
+--- CompileFile.cs ---
+using System;
+using System.IO;
+using System.Collections.Specialized;
+using System.CodeDom.Compiler;
+using Microsoft.CSharp;
+
+namespace MonoCompile
+{
+  /// <summary>
+  /// Main application class.
+  /// </summary>
+  class CompileFile
+  {
+    /// <summary>
+    /// The main entry point for the application.
+    /// Usage: MonoCompile <filename.cs>
+    /// </summary>
+    [STAThread]
+    static void Main(string[] args)
+    {
+      CompilerParameters parameters = new CompilerParameters();
+      parameters.GenerateExecutable = true;
+      parameters.IncludeDebugInformation = false;
+      parameters.OutputAssembly = Path.ChangeExtension(args[0], ".exe");
+      parameters.ReferencedAssemblies.Add("System.dll");  // always added
+      parameters.CompilerOptions = "/unsafe";
+
+      CSharpCodeProvider provider = new CSharpCodeProvider();
+      ICodeCompiler compiler = provider.CreateCompiler();
+      CompilerResults results = 
+        compiler.CompileAssemblyFromFileBatch(parameters, new string[]{args
+[0]});
+      StringCollection messages = results.Output;
+      foreach (string msg in messages)
+        Console.WriteLine(msg);
+      if (!results.Errors.HasErrors)
+        Console.WriteLine(parameters.OutputAssembly + " built 
+successfully");
+      else {
+        foreach (CompilerError error in results.Errors)
+          Console.WriteLine(error.ToString());
+      }
+    }
+  }
+}
+--- end of file --- 
+
+2) This file is used as target for MonoCompile.exe
+
+--- UnsafeTest.cs ---
+using System;
+
+namespace UnsafeTest
+{
+  /// <summary>
+  /// Main application class.
+  /// </summary>
+  unsafe class Test
+  {
+    /// <summary>
+    /// The main entry point for the application.
+    /// </summary>
+    [STAThread]
+    static void Main(string[] args)
+    {
+      if (args.Length == 0) {
+        Console.WriteLine("No argument");
+        return;
+      }
+
+      string str = args[0];
+      int charCount = 0;
+      fixed (char* c = str) {
+        char* p = c;
+        while (*p != '\0') {
+          charCount++;
+          p++;
+        }
+      }
+      Console.WriteLine("{0} characters.", charCount);
+    }
+  }
+}
+--- end of file ---
+
+To test the issue, run 
+
+  mono MonoCompile.exe UnsafeTest.cs
+
+
+Actual Results:
+===============
+
+UnsafeTest.cs(8,0) : error CS0227: Unsafe code requires the -unsafe 
+command line option to be specified
+(0,0) : error failed: 1 error(s), 0 warnings
+
+
+
+Expected Results:
+=================
+
+Successful compile, as on MS.NET 1.1.
+
+
+Karl