# The extra brackets are to foil regex-based scans.
m4_ifdef([_A][M_PROG_TAR],[_A][M_SET_OPTION([tar-ustar])])
-AM_INIT_AUTOMAKE([1.9 dist-bzip2 tar-ustar no-dist-gzip foreign subdir-objects])
+AM_INIT_AUTOMAKE([1.9 dist-bzip2 tar-ustar no-dist-gzip foreign subdir-objects]
+ m4_esyscmd([case `automake --version | head -n 1` in # parallel-tests is default in automake 1.13+, we need to explicitly enable it
+ *1.11*|*1.12*) echo parallel-tests;; # for 1.11 and 1.12 but not below as those versions don't recognize the flag
+ esac])) # TODO: remove this hack once we require automake 1.11+
+
AC_CONFIG_HEADERS([config.h])
AM_MAINTAINER_MODE
AC_SUBST(G_HAVE_ISO_VARARGS)
AC_CHECK_HEADERS(getopt.h sys/select.h sys/time.h sys/wait.h pwd.h langinfo.h iconv.h localcharset.h sys/types.h sys/resource.h)
+AC_CHECK_LIB([iconv], [locale_charset],[],[AC_CHECK_LIB([charset], [locale_charset],[LIBS+="-liconv -lcharset"])])
AC_CHECK_HEADER(alloca.h, [HAVE_ALLOCA_H=1], [HAVE_ALLOCA_H=0])
AC_SUBST(HAVE_ALLOCA_H)
LICENSE.txt \
c5.pub c5.snk c5.xml
+NO_INSTALL = yes
+
include ../../build/library.make
#if !SQLITE_STANDARD\r
int n = UnsafeNativeMethods.sqlite3_close_interop(db);\r
#else\r
- ResetConnection(db);\r
- int n = UnsafeNativeMethods.sqlite3_close(db);\r
+ ResetConnection(db);\r
+ int n;\r
+ try {\r
+ n = UnsafeNativeMethods.sqlite3_close_v2(db);\r
+ } catch (EntryPointNotFoundException) {\r
+ n = UnsafeNativeMethods.sqlite3_close(db);\r
+ }\r
#endif\r
if (n > 0) throw new SqliteException(n, SQLiteLastError(db));\r
}\r
[DllImport(SQLITE_DLL)]\r
#endif\r
internal static extern int sqlite3_close(IntPtr db);\r
+ \r
+#if !PLATFORM_COMPACTFRAMEWORK\r
+ [DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]\r
+#else\r
+ [DllImport(SQLITE_DLL)]\r
+#endif\r
+ internal static extern int sqlite3_close_v2(IntPtr db);\r
\r
#if !PLATFORM_COMPACTFRAMEWORK\r
[DllImport(SQLITE_DLL, CallingConvention = CallingConvention.Cdecl)]\r
readonly static string _connectionString = "URI=file://" + _uri + ", version=3";
SqliteConnection _conn = new SqliteConnection ();
+ [Test]
+ public void ReleaseDatabaseFileHandles ()
+ {
+ _conn.ConnectionString = _connectionString;
+ _conn.Open ();
+
+ SqliteCommand cmd = _conn.CreateCommand ();
+ cmd.CommandText = "PRAGMA legacy_file_format;";
+ cmd.ExecuteScalar ();
+
+ // close connection before the command
+ _conn.Dispose ();
+
+ // then close the command
+ cmd.Dispose ();
+
+ // the locks should be released, and we should be able to delete the database
+ File.Delete (_uri);
+ }
+
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConnectionStringTest_Null ()
// block size (which isn't their real internal block size)
public BlockProcessor (ICryptoTransform transform, int blockSize)
{
+ if (transform == null)
+ throw new ArgumentNullException ("transform");
+ if (blockSize <= 0)
+ throw new ArgumentOutOfRangeException ("blockSize");
this.transform = transform;
this.blockSize = blockSize;
block = new byte [blockSize];
if (!settings.PrintToFile) {
StringBuilder sb = new StringBuilder (1024);
int length = sb.Capacity;
- cupsTempFile (sb, length);
+ cupsTempFd (sb, length);
name = sb.ToString ();
tmpfile = name;
}
static extern void cupsFreeDests (int num_dests, IntPtr dests);
[DllImport("libcups", CharSet=CharSet.Ansi)]
- static extern IntPtr cupsTempFile (StringBuilder sb, int len);
+ static extern IntPtr cupsTempFd (StringBuilder sb, int len);
[DllImport("libcups", CharSet=CharSet.Ansi)]
static extern IntPtr cupsGetDefault ();
public Point (int dw)
{
y = dw >> 16;
- x = dw & 0xffff;
+ x = unchecked ((short) (dw & 0xffff));
}
/// <summary>
Assert.AreEqual (pt_i, pt1_1, "#2");
Assert.AreEqual (pt_sz, pt1_1, "#3");
}
+
+ [Test]
+ public void ConstructorNegativeLocationTest ()
+ {
+ var pt = new Point (unchecked ((int) 0xffe0fc00));
+
+ Assert.AreEqual (-32, pt.Y, "#1"); // (short) 0xffe0
+ Assert.AreEqual (-1024, pt.X, "#2"); // (short) 0xfc00
+ }
[Test]
public void PropertyTest ()
if (xel == null) {
// search an "undefined" ID
xel = (XmlElement) document.SelectSingleNode ("//*[@Id='" + idValue + "']");
+ if (xel == null) {
+ xel = (XmlElement) document.SelectSingleNode ("//*[@ID='" + idValue + "']");
+ if (xel == null) {
+ xel = (XmlElement) document.SelectSingleNode ("//*[@id='" + idValue + "']");
+ }
+ }
}
return xel;
}
serializer.WriteObject (ms, person2);
}
}
+
+ [Test]
+ public void Bug15028()
+ {
+ DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Bug15028));
+ using (MemoryStream memoryStream = new MemoryStream())
+ {
+ ser.WriteObject(memoryStream, new Bug15028());
+ string output = Encoding.Default.GetString(memoryStream.ToArray());
+ Assert.AreEqual(@"{""Int0"":1,""Int1"":1,""IntZero1"":0,""Str0"":"""",""Str1"":"""",""StrNull1"":null}", output);
+ }
+ }
}
+
+ [DataContract]
+ public class Bug15028
+ {
+ [DataMember(EmitDefaultValue = false)]
+ public string StrNull0 { get; private set; }
+
+ [DataMember(EmitDefaultValue = false)]
+ public string Str0 { get; private set; }
+
+ [DataMember(EmitDefaultValue = true)]
+ public string StrNull1 { get; private set; }
+
+ [DataMember(EmitDefaultValue = true)]
+ public string Str1 { get; private set; }
+
+ [DataMember(EmitDefaultValue = false)]
+ public int IntZero0 { get; private set; }
+
+ [DataMember(EmitDefaultValue = false)]
+ public int Int0 { get; private set; }
+
+ [DataMember(EmitDefaultValue = true)]
+ public int IntZero1 { get; private set; }
+
+ [DataMember(EmitDefaultValue = true)]
+ public int Int1 { get; private set; }
+
+ public Bug15028()
+ {
+ Str0 = string.Empty;
+ Str1 = string.Empty;
+ Int0 = 1;
+ Int1 = 1;
+ }
+ }
+
public class CharTest
{
public char Foo;
AbortConnections (timeout);
// FIXME: this wait is sort of hack (because it should not be required), but without it some tests are blocked.
// This hack even had better be moved to base.CancelAsync().
- if (CurrentAsyncResult != null)
- CurrentAsyncResult.AsyncWaitHandle.WaitOne (TimeSpan.FromMilliseconds (300));
+// if (CurrentAsyncResult != null)
+// CurrentAsyncResult.AsyncWaitHandle.WaitOne (TimeSpan.FromMilliseconds (300));
return base.CancelAsync (timeout);
}
protected override void OnClose (TimeSpan timeout)
{
- if (CurrentAsyncThread != null)
+ if (currentAsyncThreads.Count > 0)
if (!CancelAsync (timeout))
- CurrentAsyncThread.Abort ();
+ foreach (Thread asyncThread in currentAsyncThreads)
+ asyncThread.Abort ();
}
public virtual bool CancelAsync (TimeSpan timeout)
{
// FIXME: It should wait for the actual completion.
- return CurrentAsyncResult == null;
+ return currentAsyncResults.Count > 0;
//return CurrentAsyncResult == null || CurrentAsyncResult.AsyncWaitHandle.WaitOne (timeout);
}
TryReceiveDelegate try_recv_delegate;
object async_result_lock = new object ();
- protected Thread CurrentAsyncThread { get; private set; }
- protected IAsyncResult CurrentAsyncResult { get; private set; }
+ HashSet<Thread> currentAsyncThreads = new HashSet<Thread>();
+ HashSet<IAsyncResult> currentAsyncResults = new HashSet<IAsyncResult>();
public virtual IAsyncResult BeginTryReceiveRequest (TimeSpan timeout, AsyncCallback callback, object state)
{
- if (CurrentAsyncResult != null)
- throw new InvalidOperationException ("Another async TryReceiveRequest operation is in progress");
+ IAsyncResult result = null;
+
if (try_recv_delegate == null)
try_recv_delegate = new TryReceiveDelegate (delegate (TimeSpan tout, out RequestContext ctx) {
lock (async_result_lock) {
- if (CurrentAsyncResult != null)
- CurrentAsyncThread = Thread.CurrentThread;
+ if (currentAsyncResults.Contains (result))
+ currentAsyncThreads.Add (Thread.CurrentThread);
}
try {
return TryReceiveRequest (tout, out ctx);
//the whole app. Ignore for now
} finally {
lock (async_result_lock) {
- CurrentAsyncResult = null;
- CurrentAsyncThread = null;
+ currentAsyncResults.Remove (result);
+ currentAsyncThreads.Remove (Thread.CurrentThread);
}
}
ctx = null;
return false;
});
RequestContext dummy;
- IAsyncResult result;
lock (async_result_lock) {
- result = CurrentAsyncResult = try_recv_delegate.BeginInvoke (timeout, out dummy, callback, state);
+ result = try_recv_delegate.BeginInvoke (timeout, out dummy, callback, state);
+ currentAsyncResults.Add (result);
}
- // Note that at this point CurrentAsyncResult can be null here if delegate has run to completion
+ // Note that at this point result can be missing from currentAsyncResults here if delegate has run to completion
return result;
}
return ret;
}
+ internal static Type GetContractAssignableToInterfaces(Type given, Type [] givenInterfaces)
+ {
+ if ((given != null) && (givenInterfaces.Count() < 1))
+ return null;
+ Dictionary<Type,int> interfaceGraph = new Dictionary<Type,int> ();
+ foreach (var smaller in givenInterfaces) {
+ interfaceGraph [smaller] = 0;
+ foreach (var bigger in givenInterfaces) {
+ if (smaller.IsAssignableFrom (bigger)) {
+ interfaceGraph [smaller]++;
+ }
+ }
+ }
+
+ List<Type> possibleInterfaces = new List<Type> ();
+ foreach (var node in interfaceGraph) {
+ if (node.Value == 1) {
+ possibleInterfaces.Add(node.Key);
+ }
+ }
+ // For this purpose a contract is a set of interfaces. it is necessary to find the interface representative of rest of the set. It will be assignable to all of
+ // the others but can only be assigned to by itself. This will give it count of ! in its slot in the interfaceGraph. To be a valid set there can be only one with a count of one
+ // in its slot. More results in InvalidOperation exceptioni with ambigours error message, less means that the interface we want is the one passed in by the parameter given
+ // and by returning null we give the callign method permission to use it..
+ switch (possibleInterfaces.Count())
+ {
+ case 0:
+ break;
+ case 1:
+ return possibleInterfaces [0];
+ break;
+ default:
+ if (!given.IsInterface)
+ throw new InvalidOperationException ("The contract type of " + given + " is ambiguous: can be either " + possibleInterfaces[0] + " or " + possibleInterfaces[1]);
+ break;
+ }
+ return null;
+ }
+
internal static ContractDescription GetContractInternal (Type givenContractType, Type givenServiceType, Type serviceTypeForCallback)
{
if (givenContractType == null)
exactContractType = givenContractType;
sca = contracts [givenContractType];
} else {
- foreach (Type t in contracts.Keys)
- if (t.IsAssignableFrom(givenContractType)) {
- if (t.IsAssignableFrom (exactContractType)) // exact = IDerived, t = IBase
- continue;
- if (sca != null && (exactContractType == null || !exactContractType.IsAssignableFrom (t))) // t = IDerived, exact = IBase
- throw new InvalidOperationException ("The contract type of " + givenContractType + " is ambiguous: can be either " + exactContractType + " or " + t);
- exactContractType = t;
- sca = contracts [t];
- }
+ Type[] contractTypes = contracts.Keys.ToArray() as Type [];
+ exactContractType = GetContractAssignableToInterfaces(givenContractType, contractTypes);
+ if (exactContractType != null)
+ sca = contracts[exactContractType];
}
+
if (exactContractType == null)
exactContractType = givenContractType;
if (sca == null) {
else
return null; // no contract
}
+
string name = sca.Name ?? exactContractType.Name;
string ns = sca.Namespace ?? "http://tempuri.org/";
*/
var inherited = new Collection<ContractDescription> ();
- foreach (var it in cd.ContractType.GetInterfaces ()) {
+ var interfaces = cd.ContractType.GetInterfaces ();
+ foreach (var it in interfaces ) {
var icd = GetContractInternal (it, givenServiceType, null);
if (icd != null)
inherited.Add (icd);
}
foreach (var icd in inherited) {
- foreach (var od in icd.Operations)
- if (!cd.Operations.Any(o => o.Name == od.Name && o.SyncMethod == od.SyncMethod &&
- o.BeginMethod == od.BeginMethod && o.InCallbackContract == od.InCallbackContract))
+ foreach (var od in icd.Operations) {
+ if (!cd.Operations.Any (o => o.Name == od.Name && o.SyncMethod == od.SyncMethod && o.BeginMethod == od.BeginMethod && o.InCallbackContract == od.InCallbackContract))
cd.Operations.Add (od);
+ }
}
FillOperationsForInterface (cd, cd.ContractType, givenServiceType, false);
public void CloseInput ()
{
foreach (var ch in channels.ToArray ()) {
- if (ch.State == CommunicationState.Closed)
- RemoveChannel (ch);
+ if (ch.State == CommunicationState.Closed) {
+ lock (channels) {
+ RemoveChannel (ch);
+ }
+ }
else {
try {
ch.Close (close_timeout - (DateTime.Now - close_started));
ContractDescription cd = GetExistingContract (implementedContract);
if (cd == null) {
cd = ContractDescription.GetContract (implementedContract);
- contracts.Add (cd.ContractType.FullName, cd);
+ if (!contracts.ContainsKey (cd.ContractType.FullName)) {
+ contracts.Add (cd.ContractType.FullName, cd);
+ }
}
return AddServiceEndpointCore (cd, binding, ea, listenUri);
contracts = new Dictionary<string,ContractDescription> ();
implementedContracts = contracts;
ServiceDescription sd;
- foreach (ContractDescription cd in GetServiceContractDescriptions())
+ IEnumerable<ContractDescription> contractDescriptions = GetServiceContractDescriptions ();
+ foreach (ContractDescription cd in contractDescriptions)
contracts.Add (cd.ContractType.FullName, cd);
if (SingletonInstance != null) {
[MyWebGet]
string Get ();
}
+
+ public interface IA1 : IB1, IB2
+ {
+ void MethodA1 ();
+ }
+
+ public interface IA2 : IB1, IB2
+ {
+ void MethodA2 ();
+ }
+
+ [ServiceContract]
+ public interface IB1 : IC1, IC2
+ {
+ [OperationContract]
+ void MethodB1 ();
+ }
+
+ [ServiceContract]
+ public interface IB2 : IC1, IC2
+ {
+ [OperationContract]
+ void MethodB2 ();
+ }
+
+ public interface IC1 {}
+ public interface IC2 {}
+
+ [ServiceContract]
+ public interface IS : IA1, IA2
+ {
+ [OperationContract]
+ void MethodS() ;
+ }
+
+ public class S : IS
+ {
+ #region IS implementation
+ public void MethodS ()
+ {
+ throw new NotImplementedException ();
+ }
+ #endregion
+ #region IA2 implementation
+ public void MethodA2 ()
+ {
+ throw new NotImplementedException ();
+ }
+ #endregion
+ #region IA1 implementation
+ public void MethodA1 ()
+ {
+ throw new NotImplementedException ();
+ }
+ #endregion
+ #region IB2 implementation
+ public void MethodB2 ()
+ {
+ throw new NotImplementedException ();
+ }
+ #endregion
+ #region IB1 implementation
+ public void MethodB1 ()
+ {
+ throw new NotImplementedException ();
+ }
+ #endregion
+
+ }
+ [Test]
+ public void DualSpreadingInheritanceTest()
+ {
+ var cd = ContractDescription.GetContract (typeof(S));
+ Assert.IsNotNull(cd);
+ Assert.IsTrue (cd.Name == "IS");
+ }
+
}
}
Page page = Page;
string onclick = page != null ? page.ClientScript.GetPostBackEventReference (GetPostBackOptions (), true) : String.Empty;
onclick = String.Concat ("setTimeout('", onclick.Replace ("\\", "\\\\").Replace ("'", "\\'"), "', 0)");
- w.AddAttribute (HtmlTextWriterAttribute.Onclick, BuildScriptAttribute ("onclick", onclick));
+ if (common_attrs != null && common_attrs ["onclick"] != null) {
+ onclick = ClientScriptManager.EnsureEndsWithSemicolon (common_attrs ["onclick"]) + onclick;
+ common_attrs.Remove ("onclick");
+ }
+ w.AddAttribute (HtmlTextWriterAttribute.Onclick, onclick);
}
if (AccessKey.Length > 0)
if ((long)nitems > 0) {
if (property == (IntPtr)Atom.XA_STRING) {
// Xamarin-5116: PtrToStringAnsi expects to get UTF-8, but we might have
- // Latin-1 instead.
+ // Latin-1 instead, in which case it will return null.
var s = Marshal.PtrToStringAnsi (prop);
if (string.IsNullOrEmpty (s)) {
var sb = new StringBuilder ();
start = pos;
int length = 0;
- while (pos < value.Length) {
+ while (pos < value.Length && length < 4) {
if (!ValidHexDigit (value [pos]))
break;
length++;
if (!is_running)
return;
elapsed += GetTimestamp () - started;
+ if (elapsed < 0)
+ elapsed = 0;
is_running = false;
}
using System.Threading.Tasks;
namespace System.Net.Mail {
+ [Obsolete ("SmtpClient and its network of types are poorly designed, we strongly recommend you use https://github.com/jstedfast/MailKit and https://github.com/jstedfast/MimeKit instead")]
public class SmtpClient
: IDisposable
{
// FIXME: parse the list of extensions so we don't bother wasting
// our time trying commands if they aren't supported.
- status = SendCommand ("EHLO " + Dns.GetHostName ());
+
+ // Get the FQDN of the local machine
+ string fqdn = Dns.GetHostEntry (Dns.GetHostName ()).HostName;
+ status = SendCommand ("EHLO " + fqdn);
if (IsError (status)) {
- status = SendCommand ("HELO " + Dns.GetHostName ());
+ status = SendCommand ("HELO " + fqdn);
if (IsError (status))
throw new SmtpException (status.StatusCode, status.Description);
ResetExtensions();
writer = new StreamWriter (stream);
reader = new StreamReader (stream);
- status = SendCommand ("EHLO " + Dns.GetHostName ());
+ status = SendCommand ("EHLO " + fqdn);
if (IsError (status)) {
- status = SendCommand ("HELO " + Dns.GetHostName ());
+ status = SendCommand ("HELO " + fqdn);
if (IsError (status))
throw new SmtpException (status.StatusCode, status.Description);
static void SendMailAsyncCompletedHandler (TaskCompletionSource<object> source, AsyncCompletedEventArgs e, SendCompletedEventHandler handler, SmtpClient client)
{
- if ((object) handler != e.UserState)
+ if (source != e.UserState)
return;
client.SendCompleted -= handler;
if (i == (ips.Length - 1)) {
if (i != 0 && val >= (256 << ((3 - i) * 8)))
return null;
- else if (val > 0x3fffffffe) // this is the last number that parses correctly with MS
+ else if (val > 0xffffffff)
return null;
i = 3;
} else if (val >= 0x100)
return m_Family;
}
}
-
-
+
+#if NET_4_5
+
+ public IPAddress MapToIPv4 ()
+ {
+ if (AddressFamily == AddressFamily.InterNetwork)
+ return this;
+ if (AddressFamily != AddressFamily.InterNetworkV6)
+ throw new Exception ("Only AddressFamily.InterNetworkV6 can be converted to IPv4");
+
+ //Test for 0000 0000 0000 0000 0000 FFFF xxxx xxxx
+ for (int i = 0; i < 5; i++) {
+ if (m_Numbers [i] != 0x0000)
+ throw new Exception ("Address does not have the ::FFFF prefix");
+ }
+ if (m_Numbers [5] != 0xFFFF)
+ throw new Exception ("Address does not have the ::FFFF prefix");
+
+ //We've got an IPv4 address
+ byte [] ipv4Bytes = new byte [4];
+ Buffer.BlockCopy (m_Numbers, 12, ipv4Bytes, 0, 4);
+ return new IPAddress (ipv4Bytes);
+ }
+
+ public IPAddress MapToIPv6 ()
+ {
+ if (AddressFamily == AddressFamily.InterNetworkV6)
+ return this;
+ if (AddressFamily != AddressFamily.InterNetwork)
+ throw new Exception ("Only AddressFamily.InterNetworkV4 can be converted to IPv6");
+
+ byte [] ipv4Bytes = GetAddressBytes ();
+ byte [] ipv6Bytes = new byte [16] {
+ 0,0, 0,0, 0,0, 0,0, 0,0, 0xFF,0xFF,
+ ipv4Bytes [0], ipv4Bytes [1], ipv4Bytes [2], ipv4Bytes [3]
+ };
+ return new IPAddress (ipv6Bytes);
+ }
+
+#endif
+
/// <summary>
/// Used to tell whether an address is a loopback.
/// All IP addresses of the form 127.X.Y.Z, where X, Y, and Z are in
Assert.AreEqual ("<bar@example.com>", server.rcpt_to);
}
+ [Test]
+ public void Deliver_Async ()
+ {
+ var server = new SmtpServer ();
+ var client = new SmtpClient ("localhost", server.EndPoint.Port);
+ var msg = new MailMessage ("foo@example.com", "bar@example.com", "hello", "howdydoo\r\n");
+
+ Thread t = new Thread (server.Run);
+ t.Start ();
+ var task = client.SendMailAsync (msg);
+ t.Join ();
+
+ Assert.AreEqual ("<foo@example.com>", server.mail_from);
+ Assert.AreEqual ("<bar@example.com>", server.rcpt_to);
+
+ Assert.IsTrue (task.IsCompleted, "task");
+ }
+
}
}
"20.65535", "20.0.255.255",
"0313.027035210", "203.92.58.136", // bug #411920
"0313.0134.035210", "203.92.58.136", // too
- "7848198702", "211.202.2.46", // too
"1434328179", "85.126.28.115", // too
"3397943208", "202.136.127.168", // too
};
"12.",
"12.1.2.",
"12...",
- " "
+ " ",
+ "7848198702",
};
+ static byte [] ipv4MappedIPv6Prefix = new byte [] { 0,0, 0,0, 0,0, 0,0, 0,0, 0xFF,0xFF };
+
[Test]
public void PublicFields ()
{
}
}
}
+
+#if NET_4_5
+
+ [Test]
+ public void MapToIPv6 ()
+ {
+ for (int i = 0; i < ipv4ParseOk.Length / 2; i++) {
+ IPAddress v4 = IPAddress.Parse (ipv4ParseOk [i * 2]);
+ byte [] v4bytes = v4.GetAddressBytes ();
+ IPAddress v6 = v4.MapToIPv6 ();
+ byte [] v6bytes = v6.GetAddressBytes ();
+ IPAddress v4back = v6.MapToIPv4 ();
+
+ Assert.IsTrue (StartsWith (v6bytes, ipv4MappedIPv6Prefix), "MapToIPv6 #" + i + ".1");
+ Assert.IsTrue (v6bytes [12] == v4bytes [0], "MapToIPv6 #" + i + ".2");
+ Assert.IsTrue (v6bytes [13] == v4bytes [1], "MapToIPv6 #" + i + ".3");
+ Assert.IsTrue (v6bytes [14] == v4bytes [2], "MapToIPv6 #" + i + ".4");
+ Assert.IsTrue (v6bytes [15] == v4bytes [3], "MapToIPv6 #" + i + ".5");
+ Assert.IsTrue (v4.Equals (v4back), "MapToIPv4 #" + i);
+ }
+
+ //TODO: Test using MapToIPv4/6 with anything other than IPv4/6 addresses.
+ //Currently it is not possible to do with the IPAddress implementation.
+ }
+
+ static bool StartsWith (byte [] a, byte [] b)
+ {
+ if (a.Length < b.Length)
+ return false;
+ for (int i = 0; i < b.Length; i++)
+ {
+ if (a [i] != b [i])
+ return false;
+ }
+ return true;
+ }
+
+#endif
+
+ [Test]
+ public void EqualsFromBytes ()
+ {
+ for (int i = 0; i < ipv4ParseOk.Length / 2; i++) {
+ IPAddress ip = IPAddress.Parse (ipv4ParseOk [i * 2]);
+ IPAddress ipFromBytes = new IPAddress (ip.GetAddressBytes ());
+ Assert.IsTrue (ip.Equals (ipFromBytes), "EqualsFromBytes #" + i);
+ }
+
+ }
+
}
}
IList<LocalVariableInfo> locals = mb.LocalVariables;
- // This might break with different compilers etc.
- Assert.AreEqual (2, locals.Count, "#3");
-
- Assert.IsTrue ((locals [0].LocalType == typeof (byte[])) || (locals [1].LocalType == typeof (byte[])), "#4");
- if (locals [0].LocalType == typeof (byte[]))
- Assert.AreEqual (false, locals [0].IsPinned, "#5");
- else
- Assert.AreEqual (false, locals [1].IsPinned, "#6");
+ bool foundPinnedBytePointer = false;
+ unsafe {
+ foreach (LocalVariableInfo lvi in locals) {
+ if (lvi.LocalType == typeof (byte[]))
+ // This is optimized out by CSC in .NET 4.6
+ Assert.IsFalse (lvi.IsPinned, "#3-1");
+
+ if (/* mcs */ lvi.LocalType == typeof (byte*) || /* csc */ lvi.LocalType == typeof (byte).MakeByRefType ()) {
+ foundPinnedBytePointer = true;
+ Assert.IsTrue (lvi.IsPinned, "#3-2");
+ }
+ }
+ }
+ Assert.IsTrue (foundPinnedBytePointer, "#4");
}
public int return_parameter_test ()
var type = typeof (GenericClass<>).GetMethod("Method").GetMethodBody().LocalVariables[0].LocalType;
Assert.AreEqual (typeofT, type);
Assert.AreEqual (typeof (GenericClass<>), type.DeclaringType);
+
+ bool foundTypeOfK = false;
+ bool foundExpectedType = false;
+
+ MethodBody mb = typeof (GenericClass<>).GetMethod("Method2").GetMethodBody();
+ foreach (LocalVariableInfo lvi in mb.LocalVariables) {
+ if (lvi.LocalType == typeofK) {
+ foundTypeOfK = true;
+ Assert.AreEqual (typeof (GenericClass<>), lvi.LocalType.DeclaringType, "#1-1");
+ } else if (lvi.LocalType == typeofT) {
+ foundExpectedType = true;
+ Assert.AreEqual (typeof (GenericClass<>), lvi.LocalType.DeclaringType, "#1-2");
+ }
+ }
- type = typeof (GenericClass<>).GetMethod("Method2").GetMethodBody().LocalVariables[0].LocalType;
- Assert.AreEqual (typeofT, type);
- Assert.AreEqual (typeof (GenericClass<>), type.DeclaringType);
-
- type = typeof (GenericClass<>).GetMethod("Method2").GetMethodBody().LocalVariables[1].LocalType;
- Assert.AreEqual (typeofK, type);
- Assert.AreEqual (typeof (GenericClass<>), type.DeclaringType);
-
- type = typeof (GenericClass<int>).GetMethod("Method2").GetMethodBody().LocalVariables[0].LocalType;
- Assert.AreEqual (typeof (int), type);
-
- type = typeof (GenericClass<int>).GetMethod("Method2").GetMethodBody().LocalVariables[1].LocalType;
- Assert.AreEqual (typeofK, type);
- Assert.AreEqual (typeof (GenericClass<>), type.DeclaringType);
+ Assert.IsTrue (foundTypeOfK, "#1-3");
+ if (mb.LocalVariables.Count < 2)
+ Assert.Ignore ("Code built in release mode - 'T var0' optmized out");
+ else
+ Assert.IsTrue (foundExpectedType, "#1-4");
+
+ foundTypeOfK = false;
+ foundExpectedType = false;
+ mb = typeof (GenericClass<int>).GetMethod("Method2").GetMethodBody();
+ foreach (LocalVariableInfo lvi in mb.LocalVariables) {
+ if (lvi.LocalType == typeofK) {
+ foundTypeOfK = true;
+ Assert.AreEqual (typeof (GenericClass<>), lvi.LocalType.DeclaringType, "#2-1");
+ } else if (lvi.LocalType == typeof (int)) {
+ foundExpectedType = true;
+ }
+ }
+
+ Assert.IsTrue (foundTypeOfK, "#2-3");
+ if (mb.LocalVariables.Count < 2)
+ Assert.Ignore ("Code built in release mode - 'int var0' optmized out");
+ else
+ Assert.IsTrue (foundExpectedType, "#2-4");
}
#endif
}
RSA subjectKey = (RSA)RSA.Create ();
bool selfSigned = false;
- string hashName = "SHA1";
+ string hashName = "SHA512";
CspParameters subjectParams = new CspParameters ();
CspParameters issuerParams = new CspParameters ();
case "-a":
// hash algorithm
switch (args [i++].ToLower ()) {
+ case "sha512":
+ hashName = "SHA512";
+ break;
+ case "sha256":
+ hashName = "SHA256";
+ break;
case "sha1":
+ Console.WriteLine ("WARNING: SHA1 is not safe for this usage.");
hashName = "SHA1";
break;
case "md5":
- Console.WriteLine ("WARNING: MD5 is no more safe for this usage.");
+ Console.WriteLine ("WARNING: MD5 is not safe for this usage.");
hashName = "MD5";
break;
default:
p = encodings [0];
code = 0;
for (i = 0; p != 0; ){
- if ((gssize) p < 7){
+ if ((gsize) p < 7){
code = (gssize) p;
p = encodings [++i];
continue;
if (!array_fill_vtable) {
static MonoClass klass;
static char _vtable[sizeof(MonoVTable)+8];
- MonoVTable* vtable = (MonoVTable*) ALIGN_TO(_vtable, 8);
+ MonoVTable* vtable = (MonoVTable*) ALIGN_TO((mword)_vtable, 8);
gsize bmap;
MonoDomain *domain = mono_get_root_domain ();
FOREACH_THREAD (info) {
int skip_reason = 0;
+ void *aligned_stack_start = (void*)(mword) ALIGN_TO ((mword)info->client_info.stack_start, SIZEOF_VOID_P);
+
if (info->client_info.skip) {
SGEN_LOG (3, "Skipping dead thread %p, range: %p-%p, size: %zd", info, info->client_info.stack_start, info->client_info.stack_end, (char*)info->client_info.stack_end - (char*)info->client_info.stack_start);
skip_reason = 1;
g_assert (info->client_info.suspend_done);
SGEN_LOG (3, "Scanning thread %p, range: %p-%p, size: %zd, pinned=%zd", info, info->client_info.stack_start, info->client_info.stack_end, (char*)info->client_info.stack_end - (char*)info->client_info.stack_start, sgen_get_pinned_count ());
if (mono_gc_get_gc_callbacks ()->thread_mark_func && !conservative_stack_mark) {
- mono_gc_get_gc_callbacks ()->thread_mark_func (info->client_info.runtime_data, info->client_info.stack_start, info->client_info.stack_end, precise, &ctx);
+ mono_gc_get_gc_callbacks ()->thread_mark_func (info->client_info.runtime_data, aligned_stack_start, info->client_info.stack_end, precise, &ctx);
} else if (!precise) {
if (!conservative_stack_mark) {
fprintf (stderr, "Precise stack mark not supported - disabling.\n");
conservative_stack_mark = TRUE;
}
- sgen_conservatively_pin_objects_from (info->client_info.stack_start, info->client_info.stack_end, start_nursery, end_nursery, PIN_TYPE_STACK);
+ sgen_conservatively_pin_objects_from (aligned_stack_start, info->client_info.stack_end, start_nursery, end_nursery, PIN_TYPE_STACK);
}
if (!precise) {
#if defined(ENABLE_GSHAREDVT)
mono_aot_register_jit_icall ("mono_arm_start_gsharedvt_call", mono_arm_start_gsharedvt_call);
#endif
+ mono_aot_register_jit_icall ("mono_arm_unaligned_stack", mono_arm_unaligned_stack);
#if defined(__ARM_EABI__)
eabi_supported = TRUE;
/* The signature doesn't matter */
mono_register_jit_icall (mono_arm_throw_exception, "mono_arm_throw_exception", mono_create_icall_signature ("void"), TRUE);
mono_register_jit_icall (mono_arm_throw_exception_by_token, "mono_arm_throw_exception_by_token", mono_create_icall_signature ("void"), TRUE);
+ mono_register_jit_icall (mono_arm_unaligned_stack, "mono_arm_unaligned_stack", mono_create_icall_signature ("void"), TRUE);
#ifndef MONO_CROSS_COMPILE
if (mono_arm_have_tls_get ()) {
}
}
+void
+mono_arm_unaligned_stack (MonoMethod *method)
+{
+ g_assert_not_reached ();
+}
+
#ifndef DISABLE_JIT
/*
max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
}
+ /* stack alignment check */
+ /*
+ {
+ guint8 *buf [16];
+ ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_SP);
+ code = mono_arm_emit_load_imm (code, ARMREG_IP, MONO_ARCH_FRAME_ALIGNMENT -1);
+ ARM_AND_REG_REG (code, ARMREG_LR, ARMREG_LR, ARMREG_IP);
+ ARM_CMP_REG_IMM (code, ARMREG_LR, 0, 0);
+ buf [0] = code;
+ ARM_B_COND (code, ARMCOND_EQ, 0);
+ if (cfg->compile_aot)
+ ARM_MOV_REG_IMM8 (code, ARMREG_R0, 0);
+ else
+ code = mono_arm_emit_load_imm (code, ARMREG_R0, (guint32)cfg->method);
+ mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD, "mono_arm_unaligned_stack");
+ code = emit_call_seq (cfg, code);
+ code = emit_call_reg (code, ARMREG_LR);
+ arm_patch (buf [0], code);
+ }
+ */
+
/* store runtime generic context */
if (cfg->rgctx_var) {
MonoInst *ins = cfg->rgctx_var;
gboolean
mono_arm_have_tls_get (void);
+void
+mono_arm_unaligned_stack (MonoMethod *method);
+
#endif /* __MONO_MINI_ARM_H__ */
#define OBJ_ADDR(diff) ((obj_base + diff) << 3)
#define LOG_TIME(base,diff) /*fprintf("outfile, time %llu + %llu near offset %d\n", base, diff, p - ctx->buf)*/
+
+/* Stats */
+#define BUFFER_HEADER_SIZE 48
+
+typedef struct {
+ int count, min_size, max_size, bytes;
+} EventStat;
+
+static int buffer_count;
+static EventStat stats [256];
+
+static void
+record_event_stats (int type, int size)
+{
+ ++stats [type].count;
+ if (!stats [type].min_size)
+ stats [type].min_size = size;
+ stats [type].min_size = MIN (stats [type].min_size, size);
+ stats [type].max_size = MAX (stats [type].max_size, size);
+ stats [type].bytes += size;
+}
+
static int
decode_buffer (ProfContext *ctx)
{
thread = load_thread (ctx, thread_id);
if (!load_data (ctx, len))
return 0;
+
+ ++buffer_count;
+
if (!startup_time) {
startup_time = time_base;
if (use_time_filter) {
p = ctx->buf;
end = p + len;
while (p < end) {
+ unsigned char *start = p;
+ unsigned char event = *p;
switch (*p & 0xf) {
case TYPE_GC: {
int subtype = *p & 0xf0;
fprintf (outfile, "unhandled profiler event: 0x%x at file offset: %llu + %lld (len: %d\n)\n", *p, (unsigned long long) file_offset, (long long) (p - ctx->buf), len);
exit (1);
}
+ record_event_stats (event, p - start);
}
thread->last_time = time_base;
for (i = 0; i < thread->stack_id; ++i)
}
}
+#define DUMP_EVENT_STAT(EVENT,SUBTYPE) dump_event (#EVENT, #SUBTYPE, EVENT, SUBTYPE);
+
+static void
+dump_event (const char *event_name, const char *subtype_name, int event, int subtype)
+{
+ int idx = event | subtype;
+ EventStat evt = stats [idx];
+ if (!evt.count)
+ return;
+
+ fprintf (outfile, "\t%16s\t%26s\tcount %6d\tmin %3d\tmax %6d\tbytes %d\n", event_name, subtype_name, evt.count, evt.min_size, evt.max_size, evt.bytes);
+}
+
+static void
+dump_stats (void)
+{
+ fprintf (outfile, "\nMlpd statistics\n");
+ fprintf (outfile, "\tBuffer count %d\toverhead %d (%d bytes per header)\n", buffer_count, buffer_count * BUFFER_HEADER_SIZE, BUFFER_HEADER_SIZE);
+ fprintf (outfile, "\nEvent details:\n");
+
+ DUMP_EVENT_STAT (TYPE_ALLOC, TYPE_ALLOC_NO_BT);
+ DUMP_EVENT_STAT (TYPE_ALLOC, TYPE_ALLOC_BT);
+
+ DUMP_EVENT_STAT (TYPE_GC, TYPE_GC_EVENT);
+ DUMP_EVENT_STAT (TYPE_GC, TYPE_GC_RESIZE);
+ DUMP_EVENT_STAT (TYPE_GC, TYPE_GC_MOVE);
+ DUMP_EVENT_STAT (TYPE_GC, TYPE_GC_HANDLE_CREATED);
+ DUMP_EVENT_STAT (TYPE_GC, TYPE_GC_HANDLE_DESTROYED);
+ DUMP_EVENT_STAT (TYPE_GC, TYPE_GC_HANDLE_CREATED_BT);
+ DUMP_EVENT_STAT (TYPE_GC, TYPE_GC_HANDLE_DESTROYED_BT);
+
+ DUMP_EVENT_STAT (TYPE_METADATA, TYPE_END_LOAD);
+ DUMP_EVENT_STAT (TYPE_METADATA, TYPE_END_UNLOAD);
+
+ DUMP_EVENT_STAT (TYPE_METHOD, TYPE_LEAVE);
+ DUMP_EVENT_STAT (TYPE_METHOD, TYPE_ENTER);
+ DUMP_EVENT_STAT (TYPE_METHOD, TYPE_EXC_LEAVE);
+ DUMP_EVENT_STAT (TYPE_METHOD, TYPE_JIT);
+
+ DUMP_EVENT_STAT (TYPE_EXCEPTION, TYPE_THROW);
+ DUMP_EVENT_STAT (TYPE_EXCEPTION, TYPE_CLAUSE);
+ DUMP_EVENT_STAT (TYPE_EXCEPTION, TYPE_EXCEPTION_BT);
+
+ DUMP_EVENT_STAT (TYPE_MONITOR, TYPE_MONITOR_NO_BT);
+ DUMP_EVENT_STAT (TYPE_MONITOR, TYPE_MONITOR_BT);
+
+ DUMP_EVENT_STAT (TYPE_HEAP, TYPE_HEAP_START);
+ DUMP_EVENT_STAT (TYPE_HEAP, TYPE_HEAP_END);
+ DUMP_EVENT_STAT (TYPE_HEAP, TYPE_HEAP_OBJECT);
+ DUMP_EVENT_STAT (TYPE_HEAP, TYPE_HEAP_ROOT);
+
+ DUMP_EVENT_STAT (TYPE_SAMPLE, TYPE_SAMPLE_HIT);
+ DUMP_EVENT_STAT (TYPE_SAMPLE, TYPE_SAMPLE_USYM);
+ DUMP_EVENT_STAT (TYPE_SAMPLE, TYPE_SAMPLE_UBIN);
+ DUMP_EVENT_STAT (TYPE_SAMPLE, TYPE_SAMPLE_COUNTERS_DESC);
+ DUMP_EVENT_STAT (TYPE_SAMPLE, TYPE_SAMPLE_COUNTERS);
+
+ DUMP_EVENT_STAT (TYPE_RUNTIME, TYPE_JITHELPER);
+
+ DUMP_EVENT_STAT (TYPE_COVERAGE, TYPE_COVERAGE_ASSEMBLY);
+ DUMP_EVENT_STAT (TYPE_COVERAGE, TYPE_COVERAGE_METHOD);
+ DUMP_EVENT_STAT (TYPE_COVERAGE, TYPE_COVERAGE_STATEMENT);
+ DUMP_EVENT_STAT (TYPE_COVERAGE, TYPE_COVERAGE_CLASS);
+}
+
+
+
static void
flush_context (ProfContext *ctx)
{
dump_coverage ();
continue;
}
+ if ((opt = match_option (p, "stats")) != p) {
+ if (!parse_only)
+ dump_stats ();
+ continue;
+ }
return 0;
}
return 1;
TYPE_CLAUSE = 1 << 4,
TYPE_EXCEPTION_BT = 1 << 7,
/* extended type for TYPE_ALLOC */
- TYPE_ALLOC_BT = 1 << 4,
+ TYPE_ALLOC_NO_BT = 0 << 4,
+ TYPE_ALLOC_BT = 1 << 4,
/* extended type for TYPE_MONITOR */
- TYPE_MONITOR_BT = 1 << 7,
+ TYPE_MONITOR_NO_BT = 0 << 7,
+ TYPE_MONITOR_BT = 1 << 7,
/* extended type for TYPE_SAMPLE */
TYPE_SAMPLE_HIT = 0 << 4,
TYPE_SAMPLE_USYM = 1 << 4,
{
int count = 0;
+ SGEN_ASSERT (0, ((mword)start & (SIZEOF_VOID_P - 1)) == 0, "Why are we scanning for references in unaligned memory ?");
+
#if defined(VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE) && !defined(_WIN64)
VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE (start, (char*)end - (char*)start);
#endif
add_free_block (free_blocks, size_index, info);
/*
- * This is the only place where the `allocated_blocks` array can potentially grow.
- * We need to make sure concurrent sweep isn't running when that happens, so in that
- * specific case we just wait for sweep to finish.
+ * Adding to the allocated_blocks array is racy with the removal of nulls when
+ * sweeping. We wait for sweep to finish to avoid that.
*
* The memory barrier here and in `sweep_job_func()` are required because we need
* `allocated_blocks` synchronized between this and the sweep thread.
*/
- if (sgen_pointer_queue_will_grow (&allocated_blocks)) {
- major_finish_sweep_checking ();
- mono_memory_barrier ();
- }
+ major_finish_sweep_checking ();
+ mono_memory_barrier ();
sgen_pointer_queue_add (&allocated_blocks, BLOCK_TAG (info));
{
GCObject *obj;
- major_finish_sweep_checking ();
-
obj = alloc_obj (vtable, size, FALSE, SGEN_VTABLE_HAS_REFERENCES (vtable));
if (G_LIKELY (obj)) {
HEAVY_STAT (++stat_objects_alloced_degraded);
if (info[i].generation != -1)
sgen_client_log_timing (&info [i], last_major_num_sections, last_los_memory_usage);
}
+ last_major_num_sections = major_collector.get_num_major_sections ();
}
/*
test_ldflags = -framework CoreFoundation -framework Foundation
endif
-AUTOMAKE_OPTIONS = parallel-tests
-
if !CROSS_COMPILE
if !HOST_WIN32
if SUPPORT_BOEHM
.NOTPARALLEL:
check-local:
- if grep -q "# FAIL: 0\|tests passed" test-suite.log; then successbool=True && failures=0; else successbool=False && failures=1; fi; \
- echo "<?xml version='1.0' encoding='utf-8'?><test-results failures='$$failures' total='1' not-run='0' name='unit-tests.dummy' date='$$(date +%F)' time='$$(date +%T)'><test-suite name='MonoTests.unit-tests' success='$$successbool' time='0'><results><test-case name='MonoTests.unit-tests.100percentsuccess' executed='True' success='$$successbool' time='0'>" > TestResult-unit-tests.xml; \
- if [ $$failures -ne 0 ]; then echo "<failure><message>"'<![CDATA[' >> TestResult-unit-tests.xml && cat test-suite.log >> TestResult-unit-tests.xml && echo "]]></message><stack-trace></stack-trace></failure>" >> TestResult-unit-tests.xml; fi; \
- echo "</test-case></results></test-suite></test-results>" >> TestResult-unit-tests.xml
+ if [ -e test-suite.log ]; then \
+ if grep -q "# FAIL: 0\|tests passed" test-suite.log; then successbool=True && failures=0; else successbool=False && failures=1; fi; \
+ echo "<?xml version='1.0' encoding='utf-8'?><test-results failures='$$failures' total='1' not-run='0' name='unit-tests.dummy' date='$$(date +%F)' time='$$(date +%T)'><test-suite name='MonoTests.unit-tests' success='$$successbool' time='0'><results><test-case name='MonoTests.unit-tests.100percentsuccess' executed='True' success='$$successbool' time='0'>" > TestResult-unit-tests.xml; \
+ if [ $$failures -ne 0 ]; then echo "<failure><message>"'<![CDATA[' >> TestResult-unit-tests.xml && cat test-suite.log >> TestResult-unit-tests.xml && echo "]]></message><stack-trace></stack-trace></failure>" >> TestResult-unit-tests.xml; fi; \
+ echo "</test-case></results></test-suite></test-results>" >> TestResult-unit-tests.xml; \
+ fi;
endif SUPPORT_BOEHM
endif !HOST_WIN32
#include <signal.h>
#endif
-#if defined (HOST_WATCHOS) || defined (HOST_APPLETVOS)
-#include <libunwind.h>
-#endif
-
/*
* General notes about mono-context.
* Each arch defines a MonoContext struct with all GPR regs + IP/PC.
#if defined(HOST_WATCHOS)
#define MONO_CONTEXT_GET_CURRENT(ctx) do { \
- unw_context_t uctx; \
- unw_cursor_t c; \
- unw_word_t data; \
- g_assert (unw_getcontext (&uctx) == 0); \
- g_assert (unw_init_local (&c, &uctx) == 0); \
- for (int reg = 0; reg < 13; ++reg) { \
- unw_get_reg (&c, (unw_regnum_t) UNW_ARM_R0 + reg, &data); \
- ctx.regs[reg] = data; \
- } \
- unw_get_reg (&c, UNW_ARM_SP, &data); \
- ctx.regs[ARMREG_SP] = data; \
- unw_get_reg (&c, UNW_ARM_LR, &data); \
- ctx.regs[ARMREG_LR] = data; \
- unw_get_reg (&c, UNW_ARM_IP, &data); \
- ctx.regs[ARMREG_PC] = data; \
- ctx.pc = ctx.regs[ARMREG_PC]; \
- for (int reg = 0; reg < 16; ++reg) { \
- unw_get_reg (&c, (unw_regnum_t) UNW_ARM_D0 + reg, &data); \
- ctx.fregs[reg] = data; \
- } \
} while (0);
#else