Add support to build build with Mono.
authorMiguel de Icaza <miguel@gnome.org>
Sat, 22 Nov 2014 20:42:36 +0000 (15:42 -0500)
committerMarek Safar <marek.safar@gmail.com>
Mon, 2 May 2016 22:07:38 +0000 (00:07 +0200)
This patch does the following things:

* Adds support to build without Code Access Security, by using the new
  define DISABLE_CAS_USE.  The reason is that this is both slow, and
  Mono does not actually offer a Code Access Secured environment.  So
  avoid paying the price.

* Removes some warnings from the build for unused variables.

* Allows the code to be bootstrapped with a 2.0 compiler (which Mono
  does during the bootstrap phase currently).

mcs/class/referencesource/System/regex/system/text/regularexpressions/Regex.cs
mcs/class/referencesource/System/regex/system/text/regularexpressions/RegexCompiler.cs
mcs/class/referencesource/System/regex/system/text/regularexpressions/RegexGroup.cs
mcs/class/referencesource/System/regex/system/text/regularexpressions/RegexMatch.cs
mcs/class/referencesource/System/regex/system/text/regularexpressions/compiledregexrunnerfactory.cs

index 59c93a47a0a6049f747002dee6e8b7eadeec1722..84d2654ff2340975b7458a24ee8c00d6581c7a4a 100644 (file)
@@ -74,7 +74,12 @@ namespace System.Text.RegularExpressions {
         #if !FEATURE_NETCORE
         [NonSerialized()]
         #endif
-        public static readonly TimeSpan InfiniteMatchTimeout = Timeout.InfiniteTimeSpan;
+        public static readonly TimeSpan InfiniteMatchTimeout =
+#if BOOTSTRAP_BASIC
+               new TimeSpan (0, 0, 0, 0, Timeout.Infinite);    
+#else
+               Timeout.InfiniteTimeSpan;
+#endif
         #else
         internal static readonly TimeSpan InfiniteMatchTimeout = new TimeSpan(0, 0, 0, 0, Timeout.Infinite);
         #endif                              
@@ -398,7 +403,9 @@ namespace System.Text.RegularExpressions {
         * This method is internal virtual so the jit does not inline it.
         */
         [
+#if !DISABLE_CAS_USE
             HostProtection(MayLeakOnAbort=true),
+#endif
             MethodImplAttribute(MethodImplOptions.NoInlining)
         ]
         internal RegexRunnerFactory Compile(RegexCode code, RegexOptions roptions) {
@@ -1186,7 +1193,9 @@ namespace System.Text.RegularExpressions {
 #if !SILVERLIGHT
         /// <devdoc>
         /// </devdoc>
+#if !DISABLE_CAS_USE
         [HostProtection(MayLeakOnAbort=true)]
+#endif
         [ResourceExposure(ResourceScope.Machine)] // The AssemblyName is interesting.
         [ResourceConsumption(ResourceScope.Machine)]
         [SuppressMessage("Microsoft.Naming","CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId="assemblyname", Justification="[....]: already shipped since v1 - can't fix without causing a breaking change")]
@@ -1197,7 +1206,9 @@ namespace System.Text.RegularExpressions {
 
         /// <devdoc>
         /// </devdoc>
+#if !DISABLE_CAS_USE
         [HostProtection(MayLeakOnAbort=true)]
+#endif
         [ResourceExposure(ResourceScope.Machine)] // The AssemblyName is interesting.
         [ResourceConsumption(ResourceScope.Machine)]
         [SuppressMessage("Microsoft.Naming","CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId="assemblyname", Justification="[....]: already shipped since v1 - can't fix without causing a breaking change")]
@@ -1205,7 +1216,9 @@ namespace System.Text.RegularExpressions {
             CompileToAssemblyInternal(regexinfos, assemblyname, attributes, null);
         }
 
+#if !DISABLE_CAS_USE
         [HostProtection(MayLeakOnAbort=true)]
+#endif
         [ResourceExposure(ResourceScope.Machine)]
         [ResourceConsumption(ResourceScope.Machine)]
         [SuppressMessage("Microsoft.Naming","CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId="assemblyname", Justification="[....]: already shipped since v1 - can't fix without causing a breaking change")]
index 20be01664334aae88de846ba1f5aeec460ff114e..63e77fa7d0442c829b1a39c6dbf2640a074d68c6 100644 (file)
@@ -130,8 +130,10 @@ namespace System.Text.RegularExpressions {
         static RegexCompiler() {
             // <SECREVIEW> Regex only generates string manipulation, so this is ok.
             // </SECREVIEW>      
-           
+
+#if !DISABLE_CAS_USE
             new ReflectionPermission(PermissionState.Unrestricted).Assert();
+#endif
             try {
                 // note some fields
                 _textbegF       = RegexRunnerField("runtextbeg");
@@ -193,7 +195,9 @@ namespace System.Text.RegularExpressions {
 
             // <SECREVIEW> Regex only generates string manipulation, so this is ok.
             // </SECREVIEW>         
+#if !DISABLE_CAS_USE
             new ReflectionPermission(PermissionState.Unrestricted).Assert();
+#endif
             try {
                 factory = c.FactoryInstanceFromCode(code, options);
             }
@@ -231,7 +235,9 @@ namespace System.Text.RegularExpressions {
         
                 Type factory;
         
+#if !DISABLE_CAS_USE
                 new ReflectionPermission(PermissionState.Unrestricted).Assert();
+#endif
                 try {
                     factory = c.FactoryTypeFromCode(code, options, fullname);
                     c.GenerateRegexType(pattern, options, fullname, regexes[i].IsPublic, code, tree, factory, mTimeout);
@@ -1015,7 +1021,9 @@ namespace System.Text.RegularExpressions {
          * grouping stack when they get too full.
          */
         internal void GenerateMiddleSection() {
+#pragma warning disable 219
             Label l1 = DefineLabel();
+#pragma warning restore 219
             Label[] table;
             int i;
 
@@ -1211,7 +1219,9 @@ namespace System.Text.RegularExpressions {
                 Label      lAdvance         = DefineLabel();
                 Label      lFail            = DefineLabel();
                 Label      lStart           = DefineLabel();
+#pragma warning disable 219
                 Label      lOutOfRange      = DefineLabel();
+#pragma warning restore 219
                 Label      lPartialMatch    = DefineLabel();
 
 
@@ -1372,7 +1382,9 @@ namespace System.Text.RegularExpressions {
             }
             else {
                 LocalBuilder cV   = _temp2V;
+#pragma warning disable 219
                 LocalBuilder chV  = _tempV;
+#pragma warning restore 219
                 Label      l1   = DefineLabel();
                 Label      l2   = DefineLabel();
                 Label      l3   = DefineLabel();
@@ -2087,8 +2099,10 @@ namespace System.Text.RegularExpressions {
                         LocalBuilder count = _tempV;
                         LocalBuilder mark  = _temp2V;
                         Label      l1    = DefineLabel();
+#pragma warning disable 219
                         Label      l2    = DefineLabel();
                         Label      l3    = _labels[NextCodepos()];
+#pragma warning restore 219
 
                         PopStack();
                         Stloc(count);                           // count -> temp
@@ -3029,7 +3043,9 @@ namespace System.Text.RegularExpressions {
             // SECREVIEW : Regex only generates string manipulation, so this is
             //           : ok.
             //
+#if !DISABLE_CAS_USE
             new ReflectionPermission(PermissionState.Unrestricted).Assert();
+#endif
             try {
                 Debug.Assert(an != null, "AssemblyName should not be null");
 
@@ -3039,11 +3055,13 @@ namespace System.Text.RegularExpressions {
                 CustomAttributeBuilder transparencyAttribute = new CustomAttributeBuilder(transparencyCtor, new object[0]);
                 assemblyAttributes.Add(transparencyAttribute);
 
+#if !DISABLE_CAS_USE
                 ConstructorInfo securityRulesCtor = typeof(SecurityRulesAttribute).GetConstructor(new Type[] { typeof(SecurityRuleSet) });
                 CustomAttributeBuilder securityRulesAttribute =
                     new CustomAttributeBuilder(securityRulesCtor, new object[] { SecurityRuleSet.Level2 });
                 assemblyAttributes.Add(securityRulesAttribute);
-
+#endif
+       
                 _assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave, assemblyAttributes);
                 _module = _assembly.DefineDynamicModule(an.Name + ".dll");
 
index 3f5b1d37ed97767f5d68d5feac36edb08396cf94..97f33d958530c1218c21a0de68e5c610aeba16f6 100644 (file)
@@ -77,7 +77,9 @@ namespace System.Text.RegularExpressions {
         ///       multiple threads.</para>
         /// </devdoc>
 #if !SILVERLIGHT
+#if !DISABLE_CAS_USE
         [HostProtection(Synchronization=true)]
+#endif
         static public Group Synchronized(Group inner) {
 #else
         static internal Group Synchronized(Group inner) {
index 5dfd3e8041f59733c125c079edbc32cea8b75a34..6c0ff3850a410dfdd38f0df3425b975520db41f6 100644 (file)
@@ -201,7 +201,9 @@ namespace System.Text.RegularExpressions {
         /// </devdoc>
 
 #if !SILVERLIGHT
+#if !DISABLE_CAS_USE
         [HostProtection(Synchronization=true)]
+#endif
         static public Match Synchronized(Match inner) {
 #else
         static internal Match Synchronized(Match inner) {
index 48a4e4cc065507a6cdbd593f10faf784b66d9028..56545405b208cb730ecd072b9dfb4753aedea365 100644 (file)
@@ -28,7 +28,9 @@ namespace System.Text.RegularExpressions {
         protected internal override RegexRunner CreateInstance() {
             CompiledRegexRunner runner = new CompiledRegexRunner();
 
+#if !DISABLE_CAS_USE
             new ReflectionPermission(PermissionState.Unrestricted).Assert();
+#endif
             runner.SetDelegates((NoParamDelegate)       goMethod.CreateDelegate(typeof(NoParamDelegate)),
                                 (FindFirstCharDelegate) findFirstCharMethod.CreateDelegate(typeof(FindFirstCharDelegate)),
                                 (NoParamDelegate)       initTrackCountMethod.CreateDelegate(typeof(NoParamDelegate)));