mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-17 11:21:39 -10:00
Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1253cefc5a | ||
|
|
44d208fb47 | ||
|
|
eae2290bab | ||
|
|
ae0ba45006 | ||
|
|
467ad88de7 | ||
|
|
21703ef409 | ||
|
|
e303d4d6a6 | ||
|
|
cc2b8bab1c | ||
|
|
6bc64ef07f | ||
|
|
e94dd8dcd9 | ||
|
|
36955e7225 | ||
|
|
9b339f0bce | ||
|
|
f7f723ea1f | ||
|
|
8f1f8507fd | ||
|
|
bce9c3a881 | ||
|
|
a10b4b7574 | ||
|
|
c1bcb2ef03 |
No files matched your search
@@ -37,32 +37,6 @@ using Mono.Security;
|
||||
using Mono.Security.X509;
|
||||
|
||||
namespace Mono.Security.X509.Extensions {
|
||||
// definition found @ http://groups.yahoo.com/group/ssl-talk/message/1964
|
||||
//
|
||||
// keyAttributes EXTENSION ::= {
|
||||
// SYNTAX KeyAttributes
|
||||
// IDENTIFIED BY { id-ce 2 } }
|
||||
//
|
||||
// KeyAttributes ::= SEQUENCE {
|
||||
// keyIdentifier KeyIdentifier OPTIONAL,
|
||||
// intendedKeyUsage KeyUsage OPTIONAL,
|
||||
// privateKeyUsagePeriod PrivateKeyValidity OPTIONAL
|
||||
// }
|
||||
// KeyUsage ::= BIT STRING {
|
||||
// digitalSignature (0),
|
||||
// nonRepudiation (1),
|
||||
// keyEncipherment (2),
|
||||
// dataEncipherment (3),
|
||||
// keyAgreement (4),
|
||||
// keyCertSign (5),
|
||||
// offLineCRLSign (6)
|
||||
// }
|
||||
// PrivateKeyValidity ::= SEQUENCE {
|
||||
// notBefore [0] GeneralizedTime OPTIONAL,
|
||||
// notAfter [1] GeneralizedTime OPTIONAL
|
||||
// }
|
||||
// ( CONSTRAINED BY { -- at least one component shall be present -- })
|
||||
|
||||
public class KeyAttributesExtension : X509Extension {
|
||||
|
||||
private byte[] keyId;
|
||||
|
||||
@@ -52,11 +52,11 @@ namespace System.Linq.Expressions {
|
||||
internal const BindingFlags AllStatic = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy;
|
||||
internal const BindingFlags All = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.FlattenHierarchy;
|
||||
|
||||
public ExpressionType NodeType {
|
||||
public virtual ExpressionType NodeType {
|
||||
get { return node_type; }
|
||||
}
|
||||
|
||||
public Type Type {
|
||||
public virtual Type Type {
|
||||
get { return type; }
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace System.Net.Http.Headers
|
||||
HeaderInfo.CreateMulti<string> ("Trailer", Parser.Token.TryParse, HttpHeaderKind.Request | HttpHeaderKind.Response),
|
||||
HeaderInfo.CreateMulti<TransferCodingHeaderValue> ("Transfer-Encoding", TransferCodingHeaderValue.TryParse, HttpHeaderKind.Request | HttpHeaderKind.Response),
|
||||
HeaderInfo.CreateMulti<ProductHeaderValue> ("Upgrade", ProductHeaderValue.TryParse, HttpHeaderKind.Request | HttpHeaderKind.Response),
|
||||
HeaderInfo.CreateMulti<ProductInfoHeaderValue> ("User-Agent", ProductInfoHeaderValue.TryParse, HttpHeaderKind.Request),
|
||||
HeaderInfo.CreateMultiList<ProductInfoHeaderValue> ("User-Agent", ProductInfoHeaderValue.TryParse, HttpHeaderKind.Request),
|
||||
HeaderInfo.CreateMulti<string> ("Vary", Parser.Token.TryParse, HttpHeaderKind.Response),
|
||||
HeaderInfo.CreateMulti<ViaHeaderValue> ("Via", ViaHeaderValue.TryParse, HttpHeaderKind.Request | HttpHeaderKind.Response),
|
||||
HeaderInfo.CreateMulti<WarningHeaderValue> ("Warning", WarningHeaderValue.TryParse, HttpHeaderKind.Request | HttpHeaderKind.Response),
|
||||
|
||||
@@ -201,17 +201,26 @@ namespace System.Net.Http.Headers
|
||||
|
||||
public bool ScanCommentOptional (out string value)
|
||||
{
|
||||
var t = Scan ();
|
||||
if (t != Token.Type.OpenParens) {
|
||||
Token t;
|
||||
if (ScanCommentOptional (out value, out t))
|
||||
return true;
|
||||
|
||||
return t == Token.Type.End;
|
||||
}
|
||||
|
||||
public bool ScanCommentOptional (out string value, out Token readToken)
|
||||
{
|
||||
readToken = Scan ();
|
||||
if (readToken != Token.Type.OpenParens) {
|
||||
value = null;
|
||||
return t == Token.Type.End;
|
||||
return false;
|
||||
}
|
||||
|
||||
while (pos < s.Length) {
|
||||
var ch = s[pos];
|
||||
if (ch == ')') {
|
||||
++pos;
|
||||
var start = t.StartPosition;
|
||||
var start = readToken.StartPosition;
|
||||
value = s.Substring (start, pos - start);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -45,12 +45,12 @@ namespace System.Net.Http.Headers
|
||||
Version = version;
|
||||
}
|
||||
|
||||
private ProductHeaderValue ()
|
||||
internal ProductHeaderValue ()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name { get; private set; }
|
||||
public string Version { get; private set; }
|
||||
public string Name { get; internal set; }
|
||||
public string Version { get; internal set; }
|
||||
|
||||
object ICloneable.Clone ()
|
||||
{
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace System.Net.Http.Headers
|
||||
{
|
||||
public class ProductInfoHeaderValue : ICloneable
|
||||
@@ -93,9 +95,44 @@ namespace System.Net.Http.Headers
|
||||
parsedValue = null;
|
||||
|
||||
var lexer = new Lexer (input);
|
||||
string comment;
|
||||
if (!TryParseElement (lexer, out parsedValue) || parsedValue == null)
|
||||
return false;
|
||||
|
||||
if (lexer.ScanCommentOptional (out comment)) {
|
||||
if (lexer.Scan () != Token.Type.End) {
|
||||
parsedValue = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static bool TryParse (string input, out List<ProductInfoHeaderValue> result)
|
||||
{
|
||||
var list = new List<ProductInfoHeaderValue> ();
|
||||
var lexer = new Lexer (input);
|
||||
result = null;
|
||||
|
||||
while (true) {
|
||||
ProductInfoHeaderValue element;
|
||||
if (!TryParseElement (lexer, out element))
|
||||
return false;
|
||||
|
||||
if (element == null) {
|
||||
result = list;
|
||||
return true;
|
||||
}
|
||||
|
||||
list.Add (element);
|
||||
}
|
||||
}
|
||||
|
||||
static bool TryParseElement (Lexer lexer, out ProductInfoHeaderValue parsedValue)
|
||||
{
|
||||
string comment;
|
||||
parsedValue = null;
|
||||
Token t;
|
||||
|
||||
if (lexer.ScanCommentOptional (out comment, out t)) {
|
||||
if (comment == null)
|
||||
return false;
|
||||
|
||||
@@ -104,11 +141,25 @@ namespace System.Net.Http.Headers
|
||||
return true;
|
||||
}
|
||||
|
||||
ProductHeaderValue res;
|
||||
if (!ProductHeaderValue.TryParse (input, out res))
|
||||
if (t == Token.Type.End)
|
||||
return true;
|
||||
|
||||
if (t != Token.Type.Token)
|
||||
return false;
|
||||
|
||||
parsedValue = new ProductInfoHeaderValue (res);
|
||||
var value = new ProductHeaderValue ();
|
||||
value.Name = lexer.GetStringValue (t);
|
||||
|
||||
t = lexer.Scan ();
|
||||
if (t == Token.Type.SeparatorSlash) {
|
||||
t = lexer.Scan ();
|
||||
if (t != Token.Type.Token)
|
||||
return false;
|
||||
|
||||
value.Version = lexer.GetStringValue (t);
|
||||
}
|
||||
|
||||
parsedValue = new ProductInfoHeaderValue (value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -360,6 +360,29 @@ namespace MonoTests.System.Net.Http
|
||||
));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Headers_Complex ()
|
||||
{
|
||||
HttpRequestMessage message = new HttpRequestMessage ();
|
||||
HttpRequestHeaders headers = message.Headers;
|
||||
|
||||
headers.Add ("user-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36");
|
||||
|
||||
|
||||
Assert.AreEqual (6, headers.UserAgent.Count);
|
||||
|
||||
Assert.IsTrue (headers.UserAgent.SequenceEqual (
|
||||
new[] {
|
||||
new ProductInfoHeaderValue ("Mozilla", "5.0"),
|
||||
new ProductInfoHeaderValue ("(Macintosh; Intel Mac OS X 10_8_4)"),
|
||||
new ProductInfoHeaderValue ("AppleWebKit", "537.36"),
|
||||
new ProductInfoHeaderValue ("(KHTML, like Gecko)"),
|
||||
new ProductInfoHeaderValue ("Chrome", "29.0.1547.62"),
|
||||
new ProductInfoHeaderValue ("Safari", "537.36")
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Header_BaseImplementation ()
|
||||
{
|
||||
|
||||
@@ -59,6 +59,10 @@ using System.Runtime.InteropServices;
|
||||
[assembly: InternalsVisibleTo ("System.Windows, PublicKey=00240000048000009400000006020000002400005253413100040000010001008D56C76F9E8649383049F383C44BE0EC204181822A6C31CF5EB7EF486944D032188EA1D3920763712CCB12D75FB77E9811149E6148E5D32FBAAB37611C1878DDC19E20EF135D0CB2CFF2BFEC3D115810C3D9069638FE4BE215DBF795861920E5AB6F7DB2E2CEEF136AC23D5DD2BF031700AEC232F6C6B1C785B4305C123B37AB")]
|
||||
[assembly: InternalsVisibleTo ("System.Windows.Browser, PublicKey=00240000048000009400000006020000002400005253413100040000010001008D56C76F9E8649383049F383C44BE0EC204181822A6C31CF5EB7EF486944D032188EA1D3920763712CCB12D75FB77E9811149E6148E5D32FBAAB37611C1878DDC19E20EF135D0CB2CFF2BFEC3D115810C3D9069638FE4BE215DBF795861920E5AB6F7DB2E2CEEF136AC23D5DD2BF031700AEC232F6C6B1C785B4305C123B37AB")]
|
||||
[assembly: InternalsVisibleTo ("System.Xml, PublicKey=00240000048000009400000006020000002400005253413100040000010001008D56C76F9E8649383049F383C44BE0EC204181822A6C31CF5EB7EF486944D032188EA1D3920763712CCB12D75FB77E9811149E6148E5D32FBAAB37611C1878DDC19E20EF135D0CB2CFF2BFEC3D115810C3D9069638FE4BE215DBF795861920E5AB6F7DB2E2CEEF136AC23D5DD2BF031700AEC232F6C6B1C785B4305C123B37AB")]
|
||||
#elif NET_4_0
|
||||
[assembly: AssemblyKeyFile ("../msfinal.pub")]
|
||||
[assembly: AllowPartiallyTrustedCallers]
|
||||
[assembly: SecurityCritical]
|
||||
#else
|
||||
[assembly: AssemblyKeyFile ("../ecma.pub")]
|
||||
[assembly: AllowPartiallyTrustedCallers]
|
||||
|
||||
@@ -39,6 +39,6 @@ using System.Runtime.CompilerServices;
|
||||
[assembly: AssemblyInformationalVersion (Consts.FxFileVersion)]
|
||||
[assembly: AssemblyFileVersion (Consts.FxFileVersion)]
|
||||
[assembly: AssemblyDelaySign (true)]
|
||||
[assembly: AssemblyKeyFile ("../msfinal.pub")]
|
||||
[assembly: AssemblyKeyFile ("../ecma.pub")]
|
||||
|
||||
[assembly: ReferenceAssembly]
|
||||
@@ -1051,16 +1051,21 @@ namespace MonoTests.System.Net.Sockets {
|
||||
[Test]
|
||||
public void Available ()
|
||||
{
|
||||
UdpClient client = new UdpClient (1238);
|
||||
IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 1238);
|
||||
byte[] bytes = new byte[] {10, 11, 12, 13};
|
||||
|
||||
client.Send (bytes, bytes.Length, ep);
|
||||
int avail = client.Available;
|
||||
|
||||
Assert.AreEqual (bytes.Length, avail, "Available #1");
|
||||
using (UdpClient client = new UdpClient (1238)) {
|
||||
IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 1238);
|
||||
byte[] bytes = new byte[] {10, 11, 12, 13};
|
||||
|
||||
int res = client.Send (bytes, bytes.Length, ep);
|
||||
Assert.AreEqual (bytes.Length, res, "Send");
|
||||
|
||||
client.Close ();
|
||||
// that might happen too quickly, data sent and not yet received/available
|
||||
Thread.Sleep (100);
|
||||
int avail = client.Available;
|
||||
|
||||
Assert.AreEqual (bytes.Length, avail, "Available #1");
|
||||
|
||||
client.Close ();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
// Authors:
|
||||
// Bob Smith ([email protected])
|
||||
// Ben Maurer ([email protected])
|
||||
// Sebastien Pouliot <[email protected]>
|
||||
//
|
||||
// (C) 2001 Bob Smith. http://www.thestuff.net
|
||||
// (C) 2003 Ben Maurer
|
||||
//
|
||||
|
||||
//
|
||||
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
|
||||
// Copyright 2013 Xamarin Inc. (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
@@ -39,12 +38,11 @@ namespace System
|
||||
[ComVisible (true)]
|
||||
public class Random
|
||||
{
|
||||
const int MBIG = int.MaxValue;
|
||||
const int MSEED = 161803398;
|
||||
uint x;
|
||||
uint y;
|
||||
uint z;
|
||||
uint c;
|
||||
|
||||
int inext, inextp;
|
||||
int [] SeedArray = new int [56];
|
||||
|
||||
public Random ()
|
||||
: this (Environment.TickCount)
|
||||
{
|
||||
@@ -52,75 +50,28 @@ namespace System
|
||||
|
||||
public Random (int Seed)
|
||||
{
|
||||
int ii;
|
||||
int mj, mk;
|
||||
|
||||
// Numerical Recipes in C online @ http://www.library.cornell.edu/nr/bookcpdf/c7-1.pdf
|
||||
|
||||
// Math.Abs throws on Int32.MinValue, so we need to work around that case.
|
||||
// Fixes: 605797
|
||||
if (Seed == Int32.MinValue)
|
||||
mj = MSEED - Math.Abs (Int32.MinValue + 1);
|
||||
else
|
||||
mj = MSEED - Math.Abs (Seed);
|
||||
|
||||
SeedArray [55] = mj;
|
||||
mk = 1;
|
||||
for (int i = 1; i < 55; i++) { // [1, 55] is special (Knuth)
|
||||
ii = (21 * i) % 55;
|
||||
SeedArray [ii] = mk;
|
||||
mk = mj - mk;
|
||||
if (mk < 0)
|
||||
mk += MBIG;
|
||||
mj = SeedArray [ii];
|
||||
}
|
||||
for (int k = 1; k < 5; k++) {
|
||||
for (int i = 1; i < 56; i++) {
|
||||
SeedArray [i] -= SeedArray [1 + (i + 30) % 55];
|
||||
if (SeedArray [i] < 0)
|
||||
SeedArray [i] += MBIG;
|
||||
}
|
||||
}
|
||||
inext = 0;
|
||||
inextp = 31;
|
||||
x = (uint) Seed;
|
||||
y = (uint) 987654321;
|
||||
z = (uint) 43219876;
|
||||
c = (uint) 6543217;
|
||||
}
|
||||
|
||||
protected virtual double Sample ()
|
||||
uint JKiss ()
|
||||
{
|
||||
int retVal;
|
||||
|
||||
if (++inext >= 56) inext = 1;
|
||||
if (++inextp >= 56) inextp = 1;
|
||||
|
||||
retVal = SeedArray [inext] - SeedArray [inextp];
|
||||
|
||||
if (retVal < 0)
|
||||
retVal += MBIG;
|
||||
|
||||
SeedArray [inext] = retVal;
|
||||
|
||||
return retVal * (1.0 / MBIG);
|
||||
}
|
||||
|
||||
public virtual int Next ()
|
||||
{
|
||||
return (int)(Sample () * int.MaxValue);
|
||||
}
|
||||
|
||||
public virtual int Next (int maxValue)
|
||||
{
|
||||
if (maxValue < 0)
|
||||
throw new ArgumentOutOfRangeException(Locale.GetText (
|
||||
"Max value is less than min value."));
|
||||
|
||||
return (int)(Sample () * maxValue);
|
||||
x = 314527869 * x + 1234567;
|
||||
y ^= y << 5;
|
||||
y ^= y >> 7;
|
||||
y ^= y << 22;
|
||||
ulong t = ((ulong) 4294584393 * z + c);
|
||||
c = (uint) (t >> 32);
|
||||
z = (uint) t;
|
||||
return (x + y + z);
|
||||
}
|
||||
|
||||
public virtual int Next (int minValue, int maxValue)
|
||||
{
|
||||
if (minValue > maxValue)
|
||||
throw new ArgumentOutOfRangeException (Locale.GetText (
|
||||
"Min value is greater than max value."));
|
||||
throw new ArgumentOutOfRangeException ("Maximum value is less than minimal value.");
|
||||
|
||||
// special case: a difference of one (or less) will always return the minimum
|
||||
// e.g. -1,-1 or -1,0 will always return -1
|
||||
@@ -128,7 +79,28 @@ namespace System
|
||||
if (diff <= 1)
|
||||
return minValue;
|
||||
|
||||
return (int)((uint)(Sample () * diff) + minValue);
|
||||
return minValue + ((int) (JKiss () % diff));
|
||||
}
|
||||
|
||||
public virtual int Next (int maxValue)
|
||||
{
|
||||
if (maxValue < 0)
|
||||
throw new ArgumentOutOfRangeException ("Maximum value is less than minimal value.");
|
||||
|
||||
return (int) (JKiss () % maxValue);
|
||||
}
|
||||
|
||||
public virtual int Next ()
|
||||
{
|
||||
// returns a non-negative, [0 - Int32.MacValue], random number
|
||||
// but we want to avoid calls to Math.Abs (call cost and branching cost it requires)
|
||||
// and the fact it would throw for Int32.MinValue (so roughly 1 time out of 2^32)
|
||||
int random = (int) JKiss ();
|
||||
while (random == Int32.MinValue)
|
||||
random = (int) JKiss ();
|
||||
int mask = random >> 31;
|
||||
random ^= mask;
|
||||
return random + (mask & 1);
|
||||
}
|
||||
|
||||
public virtual void NextBytes (byte [] buffer)
|
||||
@@ -136,14 +108,39 @@ namespace System
|
||||
if (buffer == null)
|
||||
throw new ArgumentNullException ("buffer");
|
||||
|
||||
for (int i = 0; i < buffer.Length; i++) {
|
||||
buffer [i] = (byte)(Sample () * (byte.MaxValue + 1));
|
||||
// each random `int` can fill 4 bytes
|
||||
int p = 0;
|
||||
uint random;
|
||||
for (int i = 0; i < (buffer.Length >> 2); i++) {
|
||||
random = JKiss ();
|
||||
buffer [p++] = (byte) (random >> 24);
|
||||
buffer [p++] = (byte) (random >> 16);
|
||||
buffer [p++] = (byte) (random >> 8);
|
||||
buffer [p++] = (byte) random;
|
||||
}
|
||||
if (p == buffer.Length)
|
||||
return;
|
||||
|
||||
// complete the array
|
||||
random = JKiss ();
|
||||
while (p < buffer.Length) {
|
||||
buffer [p++] = (byte) random;
|
||||
random >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual double NextDouble ()
|
||||
{
|
||||
return this.Sample ();
|
||||
// return a double value between [0,1]
|
||||
return Sample ();
|
||||
}
|
||||
|
||||
protected virtual double Sample ()
|
||||
{
|
||||
// a single 32 bits random value is not enough to create a random double value
|
||||
uint a = JKiss () >> 6; // Upper 26 bits
|
||||
uint b = JKiss () >> 5; // Upper 27 bits
|
||||
return (a * 134217728.0 + b) / 9007199254740992.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,10 @@
|
||||
//
|
||||
// Authors:
|
||||
// Bob Smith <[email protected]>
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
// Sebastien Pouliot <sebastien@xamarin.com>
|
||||
//
|
||||
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
|
||||
// Copyright 2013 Xamarin Inc. (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
@@ -29,44 +30,21 @@
|
||||
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MonoTests.System {
|
||||
|
||||
[TestFixture]
|
||||
public class RandomTest {
|
||||
|
||||
#if false
|
||||
//
|
||||
// This test will fail, given enough runs.
|
||||
//
|
||||
// It is an ad-hoc test for distribution, and does not work
|
||||
// 100% of the time.
|
||||
//
|
||||
[Test]
|
||||
public void NextDouble ()
|
||||
{
|
||||
Random r = new Random ();
|
||||
int i;
|
||||
double c=0;
|
||||
for (i=0; i<20; i++)
|
||||
c += r.NextDouble ();
|
||||
c/=i;
|
||||
Assert.IsTrue (c.ToString () + " is out of range.", c < .7 && c > .3);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void CompareStreamWithSameSeed ()
|
||||
{
|
||||
Random r = new Random (42);
|
||||
Random r2 = new Random (42);
|
||||
double c=0, c2=0;
|
||||
for (int i=0; i<20; i++) {
|
||||
c += r.NextDouble ();
|
||||
c2 += r2.NextDouble ();
|
||||
Assert.AreEqual (r.NextDouble (), r2.NextDouble (), i.ToString ());
|
||||
}
|
||||
Assert.AreEqual (c, c2, "Compare");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -109,23 +87,124 @@ namespace MonoTests.System {
|
||||
}
|
||||
}
|
||||
|
||||
/* Mono implementation is now compatible with Knuth (not MS) implementation (choice of constants)
|
||||
[Test]
|
||||
public void CompareWithMS ()
|
||||
{
|
||||
string[] r = new string [4];
|
||||
byte[] buffer = new byte [8];
|
||||
int x = 4;
|
||||
while (x-- > 0) {
|
||||
int seed = (x << x);
|
||||
Random random = new Random (seed);
|
||||
random.NextBytes (buffer);
|
||||
r [x] = BitConverter.ToString (buffer);
|
||||
class RandomSampleOverride : Random {
|
||||
|
||||
protected override double Sample ()
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
Assert.AreEqual ("43-DB-8B-AE-0A-88-A8-7B", r [3], "Seed(24)");
|
||||
Assert.AreEqual ("E7-2A-5C-44-D1-8C-7D-74", r [2], "Seed(8)");
|
||||
Assert.AreEqual ("C5-67-2A-FC-1B-4E-CD-72", r [1], "Seed(2)");
|
||||
Assert.AreEqual ("B9-D1-C4-8E-34-8F-E7-71", r [0], "Seed(0)");
|
||||
}*/
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Base_Int ()
|
||||
{
|
||||
var random = new RandomSampleOverride ();
|
||||
// from 2.0+ Next(), Next(int,int) and NextBytes(byte[]) do not call Sample
|
||||
// see MSDN's Notes to Inheritors
|
||||
random.Next ();
|
||||
random.Next (Int32.MinValue, Int32.MaxValue);
|
||||
random.NextBytes (new byte[1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException (typeof (NotImplementedException))]
|
||||
public void Base_Double ()
|
||||
{
|
||||
var random = new RandomSampleOverride ();
|
||||
random.NextDouble ();
|
||||
}
|
||||
|
||||
// generate values (one for each 1024 returned values) from the original C implementation
|
||||
static uint[] jkiss_values = {
|
||||
560241513, /* 0 */
|
||||
1281708802, /* 1024 */
|
||||
1571324528, /* 2048 */
|
||||
1565809406, /* 3072 */
|
||||
1010890569, /* 4096 */
|
||||
1778803435, /* 5120 */
|
||||
903613637, /* 6144 */
|
||||
3496059008, /* 7168 */
|
||||
108603163, /* 8192 */
|
||||
1854081276, /* 9216 */
|
||||
3703232459, /* 10240 */
|
||||
2191562138, /* 11264 */
|
||||
337995793, /* 12288 */
|
||||
1340840062, /* 13312 */
|
||||
2364148985, /* 14336 */
|
||||
2549812361, /* 15360 */
|
||||
563432369, /* 16384 */
|
||||
229365487, /* 17408 */
|
||||
1821397325, /* 18432 */
|
||||
3246092454, /* 19456 */
|
||||
691032417, /* 20480 */
|
||||
86951316, /* 21504 */
|
||||
3029975455, /* 22528 */
|
||||
1261370163, /* 23552 */
|
||||
2539815382, /* 24576 */
|
||||
3017891647, /* 25600 */
|
||||
3877215120, /* 26624 */
|
||||
3142958765, /* 27648 */
|
||||
1080903191, /* 28672 */
|
||||
2837464745, /* 29696 */
|
||||
614275602, /* 30720 */
|
||||
2250626199, /* 31744 */
|
||||
729001311, /* 32768 */
|
||||
3313769017, /* 33792 */
|
||||
2408398670, /* 34816 */
|
||||
3123583383, /* 35840 */
|
||||
3346590423, /* 36864 */
|
||||
1629546563, /* 37888 */
|
||||
251343753, /* 38912 */
|
||||
2695793631, /* 39936 */
|
||||
2768993787, /* 40960 */
|
||||
3688573224, /* 41984 */
|
||||
2897218561, /* 43008 */
|
||||
2725058810, /* 44032 */
|
||||
2142061914, /* 45056 */
|
||||
3983217096, /* 46080 */
|
||||
3609758190, /* 47104 */
|
||||
842060935, /* 48128 */
|
||||
2893482035, /* 49152 */
|
||||
2290461665, /* 50176 */
|
||||
1709481476, /* 51200 */
|
||||
3633857838, /* 52224 */
|
||||
332645044, /* 53248 */
|
||||
3522654497, /* 54272 */
|
||||
2501348469, /* 55296 */
|
||||
1644344287, /* 56320 */
|
||||
3081428084, /* 57344 */
|
||||
3114560766, /* 58368 */
|
||||
489030597, /* 59392 */
|
||||
367291591, /* 60416 */
|
||||
106358682, /* 61440 */
|
||||
3020781303, /* 62464 */
|
||||
1209590375, /* 63488 */
|
||||
1833282169, /* 64512 */
|
||||
61543407, /* 65536 */
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void JKISS ()
|
||||
{
|
||||
// Random.Next() returns a non-negative *signed* integer value - so it can't be used for testing
|
||||
var next = typeof(Random).GetMethod ("JKiss", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
||||
// if the method is not present, e.g. on MS.NET, skip this test
|
||||
if (next == null)
|
||||
return;
|
||||
|
||||
// ensure we match the original JKISS random stream
|
||||
// first 64KB but without checking every value (one each KB)
|
||||
Random r = new Random (123456789);
|
||||
int n = 0;
|
||||
int j = 0;
|
||||
while (j < 64 * 1024) {
|
||||
uint random = (uint) next.Invoke (r, null);
|
||||
if (j++ % 1024 == 0) {
|
||||
Assert.AreEqual (random, jkiss_values [n], n.ToString ());
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -862,7 +862,7 @@ static KeyRemapEntry key_remap_table[] = {
|
||||
{ "System.ComponentModel.DataAnnotations", "ddd0da4d3e678217", WINFX_KEY },
|
||||
{ "System.Core", SILVERLIGHT_KEY, ECMA_KEY },
|
||||
// FIXME: MS uses MSFINAL_KEY for .NET 4.5
|
||||
{ "System.Net", SILVERLIGHT_KEY, ECMA_KEY },
|
||||
{ "System.Net", SILVERLIGHT_KEY, MSFINAL_KEY },
|
||||
{ "System.Numerics", WINFX_KEY, ECMA_KEY },
|
||||
{ "System.Runtime.Serialization", SILVERLIGHT_KEY, ECMA_KEY },
|
||||
{ "System.ServiceModel", WINFX_KEY, ECMA_KEY },
|
||||
@@ -870,7 +870,7 @@ static KeyRemapEntry key_remap_table[] = {
|
||||
{ "System.Windows", SILVERLIGHT_KEY, MSFINAL_KEY },
|
||||
{ "System.Xml", SILVERLIGHT_KEY, ECMA_KEY },
|
||||
{ "System.Xml.Linq", WINFX_KEY, ECMA_KEY },
|
||||
{ "System.Xml.Serialization", WINFX_KEY, MSFINAL_KEY }
|
||||
{ "System.Xml.Serialization", WINFX_KEY, ECMA_KEY }
|
||||
};
|
||||
|
||||
static void
|
||||
|
||||
+37
-80
@@ -356,40 +356,6 @@ region_info_entry_from_lcid (int lcid)
|
||||
return entry;
|
||||
}
|
||||
|
||||
/*
|
||||
* The following two methods are modified from the ICU source code. (http://oss.software.ibm.com/icu)
|
||||
* Copyright (c) 1995-2003 International Business Machines Corporation and others
|
||||
* All rights reserved.
|
||||
*/
|
||||
static gchar*
|
||||
get_posix_locale (void)
|
||||
{
|
||||
const gchar* posix_locale = NULL;
|
||||
|
||||
posix_locale = g_getenv("LC_ALL");
|
||||
if (posix_locale == 0) {
|
||||
posix_locale = g_getenv("LANG");
|
||||
if (posix_locale == 0) {
|
||||
posix_locale = setlocale(LC_ALL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (posix_locale == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((strcmp ("C", posix_locale) == 0) || (strchr (posix_locale, ' ') != NULL)
|
||||
|| (strchr (posix_locale, '/') != NULL)) {
|
||||
/*
|
||||
* HPUX returns 'C C C C C C C'
|
||||
* Solaris can return /en_US/C/C/C/C/C on the second try.
|
||||
* Maybe we got some garbage.
|
||||
*/
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g_strdup (posix_locale);
|
||||
}
|
||||
|
||||
#if defined (__APPLE__)
|
||||
static gchar*
|
||||
get_darwin_locale (void)
|
||||
@@ -430,14 +396,34 @@ get_darwin_locale (void)
|
||||
}
|
||||
#endif
|
||||
|
||||
static gchar*
|
||||
static char *
|
||||
get_posix_locale ()
|
||||
{
|
||||
const char *locale;
|
||||
|
||||
locale = g_getenv ("LC_ALL");
|
||||
if (locale != NULL){
|
||||
locale = g_getenv ("LANG");
|
||||
if (locale == NULL)
|
||||
locale = setlocale (LC_ALL, NULL);
|
||||
}
|
||||
if (locale == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Skip English-only locale 'C' */
|
||||
if (strcmp (locale, "C") == 0)
|
||||
return NULL;
|
||||
|
||||
return g_strdup (locale);
|
||||
}
|
||||
|
||||
|
||||
static gchar *
|
||||
get_current_locale_name (void)
|
||||
{
|
||||
gchar *locale;
|
||||
gchar *corrected = NULL;
|
||||
const gchar *p;
|
||||
gchar *c;
|
||||
|
||||
char *locale;
|
||||
char *p, *ret;
|
||||
|
||||
#ifdef HOST_WIN32
|
||||
locale = g_win32_getlocale ();
|
||||
#elif defined (__APPLE__)
|
||||
@@ -446,52 +432,23 @@ get_current_locale_name (void)
|
||||
locale = get_posix_locale ();
|
||||
#else
|
||||
locale = get_posix_locale ();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (locale == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((p = strchr (locale, '.')) != NULL) {
|
||||
/* assume new locale can't be larger than old one? */
|
||||
corrected = g_malloc (strlen (locale));
|
||||
strncpy (corrected, locale, p - locale);
|
||||
corrected [p - locale] = 0;
|
||||
p = strchr (locale, '.');
|
||||
if (p != NULL)
|
||||
*p = 0;
|
||||
p = strchr (locale, '@');
|
||||
if (p != NULL)
|
||||
*p = 0;
|
||||
|
||||
/* do not copy after the @ */
|
||||
if ((p = strchr (corrected, '@')) != NULL)
|
||||
corrected [p - corrected] = 0;
|
||||
}
|
||||
ret = g_ascii_strdown (locale, -1);
|
||||
g_free (locale);
|
||||
|
||||
/* Note that we scan the *uncorrected* ID. */
|
||||
if ((p = strrchr (locale, '@')) != NULL) {
|
||||
|
||||
/*
|
||||
* In Mono we dont handle the '@' modifier because we do
|
||||
* not have any cultures that use it. We just trim it
|
||||
* off of the end of the name.
|
||||
*/
|
||||
|
||||
if (corrected == NULL) {
|
||||
corrected = g_malloc (strlen (locale));
|
||||
strncpy (corrected, locale, p - locale);
|
||||
corrected [p - locale] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (corrected == NULL)
|
||||
corrected = locale;
|
||||
else
|
||||
g_free (locale);
|
||||
|
||||
if ((c = strchr (corrected, '_')) != NULL)
|
||||
*c = '-';
|
||||
|
||||
c = corrected;
|
||||
corrected = g_ascii_strdown (c, -1);
|
||||
g_free (c);
|
||||
|
||||
return corrected;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
MonoBoolean
|
||||
ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_current_locale (MonoCultureInfo *ci)
|
||||
|
||||
+26
-89
@@ -1,48 +1,17 @@
|
||||
/* GLIB - Library of useful routines for C programming
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GLib Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
* mono-hash.c: GC-aware hashtable, based on Eglib's Hashtable
|
||||
*
|
||||
* Authors:
|
||||
* Paolo Molaro ([email protected])
|
||||
*
|
||||
* Copyright 2013 Xamarin Inc (http://www.xamarin.com)
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <mono/utils/mono-publib.h>
|
||||
#ifndef __MONO_G_HASH_H__
|
||||
#define __MONO_G_HASH_H__
|
||||
|
||||
/*
|
||||
* Imported in mono cvs from version 1.7 of gnome cvs.
|
||||
* This hash table is GC friendly and the pointers stored in it
|
||||
* are tracked by the garbage collector.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <mono/utils/mono-publib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _MonoGHashTable MonoGHashTable;
|
||||
|
||||
typedef gpointer (*MonoGRemapperFunc) (gpointer key, gpointer value,
|
||||
gpointer user_data);
|
||||
|
||||
MONO_BEGIN_DECLS
|
||||
/* do not change the values of this enum */
|
||||
typedef enum {
|
||||
MONO_HASH_CONSERVATIVE_GC,
|
||||
@@ -51,55 +20,23 @@ typedef enum {
|
||||
MONO_HASH_KEY_VALUE_GC /* note this is the OR of the other two values */
|
||||
} MonoGHashGCType;
|
||||
|
||||
/* Hash tables
|
||||
*/
|
||||
MONO_API MonoGHashTable* mono_g_hash_table_new (GHashFunc hash_func,
|
||||
GEqualFunc key_equal_func);
|
||||
MONO_API MonoGHashTable* mono_g_hash_table_new_type (GHashFunc hash_func,
|
||||
GEqualFunc key_equal_func,
|
||||
MonoGHashGCType type);
|
||||
MONO_API MonoGHashTable* mono_g_hash_table_new_full (GHashFunc hash_func,
|
||||
GEqualFunc key_equal_func,
|
||||
GDestroyNotify key_destroy_func,
|
||||
GDestroyNotify value_destroy_func);
|
||||
MONO_API void mono_g_hash_table_destroy (MonoGHashTable *hash_table);
|
||||
MONO_API void mono_g_hash_table_insert (MonoGHashTable *hash_table,
|
||||
gpointer key,
|
||||
gpointer value);
|
||||
MONO_API void mono_g_hash_table_replace (MonoGHashTable *hash_table,
|
||||
gpointer key,
|
||||
gpointer value);
|
||||
MONO_API gboolean mono_g_hash_table_remove (MonoGHashTable *hash_table,
|
||||
gconstpointer key);
|
||||
MONO_API gboolean mono_g_hash_table_steal (MonoGHashTable *hash_table,
|
||||
gconstpointer key);
|
||||
MONO_API gpointer mono_g_hash_table_lookup (MonoGHashTable *hash_table,
|
||||
gconstpointer key);
|
||||
MONO_API gboolean mono_g_hash_table_lookup_extended (MonoGHashTable *hash_table,
|
||||
gconstpointer lookup_key,
|
||||
gpointer *orig_key,
|
||||
gpointer *value);
|
||||
MONO_API void mono_g_hash_table_foreach (MonoGHashTable *hash_table,
|
||||
GHFunc func,
|
||||
gpointer user_data);
|
||||
MONO_API guint mono_g_hash_table_foreach_remove (MonoGHashTable *hash_table,
|
||||
GHRFunc func,
|
||||
gpointer user_data);
|
||||
MONO_API guint mono_g_hash_table_foreach_steal (MonoGHashTable *hash_table,
|
||||
GHRFunc func,
|
||||
gpointer user_data);
|
||||
MONO_API gpointer mono_g_hash_table_find (MonoGHashTable *hash_table,
|
||||
GHRFunc predicate,
|
||||
gpointer user_data);
|
||||
MONO_API guint mono_g_hash_table_size (MonoGHashTable *hash_table);
|
||||
typedef struct _MonoGHashTable MonoGHashTable;
|
||||
|
||||
MONO_API void mono_g_hash_table_remap (MonoGHashTable *hash_table,
|
||||
MonoGRemapperFunc func,
|
||||
gpointer user_data);
|
||||
|
||||
MONO_API void mono_g_hash_table_print_stats (MonoGHashTable *table);
|
||||
|
||||
G_END_DECLS
|
||||
MONO_API MonoGHashTable *mono_g_hash_table_new_type (GHashFunc hash_func, GEqualFunc key_equal_func, MonoGHashGCType type);
|
||||
MONO_API MonoGHashTable *mono_g_hash_table_new (GHashFunc hash_func, GEqualFunc key_equal_func);
|
||||
MONO_API MonoGHashTable *mono_g_hash_table_new_full (GHashFunc hash_func, GEqualFunc key_equal_func,
|
||||
GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func);
|
||||
MONO_API guint mono_g_hash_table_size (MonoGHashTable *hash);
|
||||
MONO_API gpointer mono_g_hash_table_lookup (MonoGHashTable *hash, gconstpointer key);
|
||||
MONO_API gboolean mono_g_hash_table_lookup_extended (MonoGHashTable *hash, gconstpointer key, gpointer *orig_key, gpointer *value);
|
||||
MONO_API void mono_g_hash_table_foreach (MonoGHashTable *hash, GHFunc func, gpointer user_data);
|
||||
MONO_API gpointer mono_g_hash_table_find (MonoGHashTable *hash, GHRFunc predicate, gpointer user_data);
|
||||
MONO_API gboolean mono_g_hash_table_remove (MonoGHashTable *hash, gconstpointer key);
|
||||
MONO_API guint mono_g_hash_table_foreach_remove (MonoGHashTable *hash, GHRFunc func, gpointer user_data);
|
||||
MONO_API void mono_g_hash_table_destroy (MonoGHashTable *hash);
|
||||
MONO_API void mono_g_hash_table_insert (MonoGHashTable *h, gpointer k, gpointer v);
|
||||
MONO_API void mono_g_hash_table_replace (MonoGHashTable *h, gpointer k, gpointer v);
|
||||
MONO_API void mono_g_hash_table_print_stats (MonoGHashTable *table);
|
||||
|
||||
MONO_END_DECLS
|
||||
#endif /* __MONO_G_HASH_H__ */
|
||||
|
||||
+16
-13
@@ -106,6 +106,15 @@
|
||||
#define AI_ADDRCONFIG 0
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
/*
|
||||
* We remove this until we have a Darwin implementation
|
||||
* that can walk the result of struct ifconf. The current
|
||||
* implementation only works for Linux
|
||||
*/
|
||||
#undef HAVE_SIOCGIFCONF
|
||||
#endif
|
||||
|
||||
static gint32 convert_family(MonoAddressFamily mono_family)
|
||||
{
|
||||
gint32 family=-1;
|
||||
@@ -1405,19 +1414,13 @@ extern void ves_icall_System_Net_Sockets_Socket_Disconnect_internal(SOCKET sock,
|
||||
*/
|
||||
_wapi_disconnectex = NULL;
|
||||
|
||||
/* Look up the TransmitFile extension function pointer
|
||||
* instead of calling TransmitFile() directly, because
|
||||
* apparently "Several of the extension functions have
|
||||
* been available since WinSock 1.1 and are exported
|
||||
* from MSWsock.dll, however it's not advisable to
|
||||
* link directly to this dll as this ties you to the
|
||||
* Microsoft WinSock provider. A provider neutral way
|
||||
* of accessing these extension functions is to load
|
||||
* them dynamically via WSAIoctl using the
|
||||
* SIO_GET_EXTENSION_FUNCTION_POINTER op code. This
|
||||
* should, theoretically, allow you to access these
|
||||
* functions from any provider that supports them..."
|
||||
* (http://www.codeproject.com/internet/jbsocketserver3.asp)
|
||||
/*
|
||||
* Use the SIO_GET_EXTENSION_FUNCTION_POINTER to
|
||||
* determine the address of the disconnect method without
|
||||
* taking a hard dependency on a single provider
|
||||
*
|
||||
* For an explanation of why this is done, you can read
|
||||
* the article at http://www.codeproject.com/internet/jbsocketserver3.asp
|
||||
*/
|
||||
ret = WSAIoctl (sock, SIO_GET_EXTENSION_FUNCTION_POINTER,
|
||||
(void *)&trans_guid, sizeof(GUID),
|
||||
|
||||
@@ -2533,6 +2533,13 @@ ves_icall_System_Threading_Thread_VolatileRead8 (void *ptr)
|
||||
#if SIZEOF_VOID_P == 8
|
||||
return *((volatile gint64 *) (ptr));
|
||||
#else
|
||||
if ((size_t)ptr & 0x7) {
|
||||
gint64 value;
|
||||
mono_interlocked_lock ();
|
||||
value = *(gint64 *)ptr;
|
||||
mono_interlocked_unlock ();
|
||||
return value;
|
||||
}
|
||||
return InterlockedCompareExchange64 (ptr, 0, 0); /*Must ensure atomicity of the operation. */
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -3339,14 +3339,23 @@ emit_seq_point (MonoCompile *cfg, MonoMethod *method, guint8* ip, gboolean intr_
|
||||
}
|
||||
|
||||
static void
|
||||
save_cast_details (MonoCompile *cfg, MonoClass *klass, int obj_reg)
|
||||
save_cast_details (MonoCompile *cfg, MonoClass *klass, int obj_reg, gboolean null_check, MonoBasicBlock **out_bblock)
|
||||
{
|
||||
if (mini_get_debug_options ()->better_cast_details) {
|
||||
int to_klass_reg = alloc_preg (cfg);
|
||||
int vtable_reg = alloc_preg (cfg);
|
||||
int klass_reg = alloc_preg (cfg);
|
||||
MonoInst *tls_get = mono_get_jit_tls_intrinsic (cfg);
|
||||
MonoBasicBlock *is_null_bb = NULL;
|
||||
MonoInst *tls_get;
|
||||
|
||||
if (null_check) {
|
||||
NEW_BBLOCK (cfg, is_null_bb);
|
||||
|
||||
MONO_EMIT_NEW_BIALU_IMM (cfg, OP_COMPARE_IMM, -1, obj_reg, 0);
|
||||
MONO_EMIT_NEW_BRANCH_BLOCK (cfg, OP_PBEQ, is_null_bb);
|
||||
}
|
||||
|
||||
tls_get = mono_get_jit_tls_intrinsic (cfg);
|
||||
if (!tls_get) {
|
||||
fprintf (stderr, "error: --debug=casts not supported on this platform.\n.");
|
||||
exit (1);
|
||||
@@ -3359,6 +3368,12 @@ save_cast_details (MonoCompile *cfg, MonoClass *klass, int obj_reg)
|
||||
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, tls_get->dreg, G_STRUCT_OFFSET (MonoJitTlsData, class_cast_from), klass_reg);
|
||||
MONO_EMIT_NEW_PCONST (cfg, to_klass_reg, klass);
|
||||
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, tls_get->dreg, G_STRUCT_OFFSET (MonoJitTlsData, class_cast_to), to_klass_reg);
|
||||
|
||||
if (null_check) {
|
||||
MONO_START_BB (cfg, is_null_bb);
|
||||
if (out_bblock)
|
||||
*out_bblock = cfg->cbb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3386,7 +3401,7 @@ mini_emit_check_array_type (MonoCompile *cfg, MonoInst *obj, MonoClass *array_cl
|
||||
|
||||
context_used = mini_class_check_context_used (cfg, array_class);
|
||||
|
||||
save_cast_details (cfg, array_class, obj->dreg);
|
||||
save_cast_details (cfg, array_class, obj->dreg, FALSE, NULL);
|
||||
|
||||
MONO_EMIT_NEW_LOAD_MEMBASE_FAULT (cfg, vtable_reg, obj->dreg, G_STRUCT_OFFSET (MonoObject, vtable));
|
||||
|
||||
@@ -3503,7 +3518,7 @@ handle_unbox (MonoCompile *cfg, MonoClass *klass, MonoInst **sp, int context_use
|
||||
MONO_EMIT_NEW_BIALU (cfg, OP_COMPARE, -1, eclass_reg, element_class->dreg);
|
||||
MONO_EMIT_NEW_COND_EXC (cfg, NE_UN, "InvalidCastException");
|
||||
} else {
|
||||
save_cast_details (cfg, klass->element_class, obj_reg);
|
||||
save_cast_details (cfg, klass->element_class, obj_reg, FALSE, NULL);
|
||||
mini_emit_class_check (cfg, eclass_reg, klass->element_class);
|
||||
reset_cast_details (cfg);
|
||||
}
|
||||
@@ -3872,7 +3887,7 @@ handle_castclass (MonoCompile *cfg, MonoClass *klass, MonoInst *src, int context
|
||||
MONO_EMIT_NEW_BIALU_IMM (cfg, OP_COMPARE_IMM, -1, obj_reg, 0);
|
||||
MONO_EMIT_NEW_BRANCH_BLOCK (cfg, OP_PBEQ, is_null_bb);
|
||||
|
||||
save_cast_details (cfg, klass, obj_reg);
|
||||
save_cast_details (cfg, klass, obj_reg, FALSE, NULL);
|
||||
|
||||
if (klass->flags & TYPE_ATTRIBUTE_INTERFACE) {
|
||||
MONO_EMIT_NEW_LOAD_MEMBASE (cfg, vtable_reg, obj_reg, G_STRUCT_OFFSET (MonoObject, vtable));
|
||||
@@ -4182,7 +4197,7 @@ handle_ccastclass (MonoCompile *cfg, MonoClass *klass, MonoInst *src)
|
||||
MONO_EMIT_NEW_BIALU_IMM (cfg, OP_COMPARE_IMM, -1, obj_reg, 0);
|
||||
MONO_EMIT_NEW_BRANCH_BLOCK (cfg, OP_PBEQ, ok_result_bb);
|
||||
|
||||
save_cast_details (cfg, klass, obj_reg);
|
||||
save_cast_details (cfg, klass, obj_reg, FALSE, NULL);
|
||||
|
||||
if (klass->flags & TYPE_ATTRIBUTE_INTERFACE) {
|
||||
#ifndef DISABLE_REMOTING
|
||||
@@ -9344,7 +9359,8 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
|
||||
EMIT_NEW_PCONST (cfg, args [2], mono_domain_alloc0 (cfg->domain, sizeof (gpointer)));
|
||||
|
||||
/*The wrapper doesn't inline well so the bloat of inlining doesn't pay off.*/
|
||||
save_cast_details (cfg, klass, sp [0]->dreg);
|
||||
|
||||
save_cast_details (cfg, klass, sp [0]->dreg, TRUE, &bblock);
|
||||
*sp++ = mono_emit_method_call (cfg, mono_castclass, args, NULL);
|
||||
reset_cast_details (cfg);
|
||||
ip += 5;
|
||||
@@ -9357,7 +9373,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
|
||||
mono_castclass = mono_marshal_get_castclass (klass);
|
||||
iargs [0] = sp [0];
|
||||
|
||||
save_cast_details (cfg, klass, sp [0]->dreg);
|
||||
save_cast_details (cfg, klass, sp [0]->dreg, TRUE, &bblock);
|
||||
costs = inline_method (cfg, mono_castclass, mono_method_signature (mono_castclass),
|
||||
iargs, ip, cfg->real_offset, dont_inline, TRUE);
|
||||
reset_cast_details (cfg);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
public class Tests
|
||||
{
|
||||
@@ -30,4 +31,15 @@ public class Tests
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
[MethodImplAttribute (MethodImplOptions.NoInlining)]
|
||||
public static object return_null () {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int test_0_complex_1_null () {
|
||||
object o = return_null ();
|
||||
IEnumerable<object> ie = (IEnumerable<object>)o;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+9
-17
@@ -210,25 +210,17 @@ mono_bitset_count (const MonoBitSet *set) {
|
||||
count = 0;
|
||||
for (i = 0; i < set->size / BITS_PER_CHUNK; ++i) {
|
||||
d = set->data [i];
|
||||
/* there is probably some asm code that can do this much faster */
|
||||
if (d) {
|
||||
#if SIZEOF_VOID_P == 8
|
||||
/* http://www.jjj.de/bitwizardry/bitwizardrypage.html */
|
||||
d -= (d>>1) & 0x5555555555555555;
|
||||
d = ((d>>2) & 0x3333333333333333) + (d & 0x3333333333333333);
|
||||
d = ((d>>4) + d) & 0x0f0f0f0f0f0f0f0f;
|
||||
d *= 0x0101010101010101;
|
||||
count += d >> 56;
|
||||
#ifdef __GNUC__
|
||||
if (sizeof (gsize) == sizeof (unsigned long))
|
||||
count += __builtin_popcountl (d);
|
||||
else
|
||||
count += __builtin_popcount (d);
|
||||
#else
|
||||
/* http://aggregate.org/MAGIC/ */
|
||||
d -= ((d >> 1) & 0x55555555);
|
||||
d = (((d >> 2) & 0x33333333) + (d & 0x33333333));
|
||||
d = (((d >> 4) + d) & 0x0f0f0f0f);
|
||||
d += (d >> 8);
|
||||
d += (d >> 16);
|
||||
count += (d & 0x0000003f);
|
||||
#endif
|
||||
while (d) {
|
||||
count ++;
|
||||
d &= (d - 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user