Compare commits

...
Author SHA1 Message Date
Sebastien Pouliot ba8730379c Ignore some asserts since the validation were removed 2013-10-04 17:13:18 -04:00
Miguel de Icaza 1df124c6b3 FixBuild 2013-10-04 17:13:05 -04:00
Zoltan Varga 63714aeff2 [sgen] Use gcc bitcount intrinsics where appropriate. 2013-10-04 16:54:03 -04:00
Miguel de Icaza 213c97b038 This regex was wrong in the first place, and second, it uses CC code from Stackoverflow 2013-10-04 16:53:34 -04:00
Miguel de Icaza 1b5a6dc7ea Remove CodeProject licensed code 2013-10-04 16:50:38 -04:00
Miguel de Icaza c0d35897df Add actual source 2013-10-04 16:49:45 -04:00
Miguel de Icaza 4559c026a8 Fix inacurrate reference 2013-10-04 16:49:20 -04:00
Zoltan Varga 4a4d7b4bf8 [runtime] Fix a regression introduced by 5503991372. Use __builtin_popcountl () on 64 bit machines. 2013-10-02 13:08:21 -04:00
Zoltan Varga 6473b9f567 Use __builtin_popcount () in mono_bitset_count (). 2013-10-02 13:07:45 -04:00
Miguel de Icaza 522a101ef8 Remove comment, refer to the spec instead 2013-10-02 13:07:13 -04:00
Sebastien Pouliot 49a7c3448c Change Random implementation to JKISS which is faster and has a longer period. Also match .NET 2.0 behaviour wrt calls to protected Sample. Add unit tests (and removed the commented ones). Ref: http://www0.cs.ucl.ac.uk/staff/d.jones/GoodPracticeRNG.pdf 2013-10-02 13:06:30 -04:00
Miguel de Icaza 8817a861e8 Simplify locale fetching, we have very simple needs 2013-10-02 13:05:50 -04:00
Miguel de Icaza 720e13f4b2 Wrap the code in MONO_BEGIN/END_DECLS 2013-10-02 13:04:46 -04:00
Miguel de Icaza f0cf38ce49 Rewrite the header file, based on the internal mono-hash.c contents 2013-10-02 13:04:36 -04:00
Miguel de Icaza c270e9515c Remove text from article 2013-10-02 13:03:48 -04:00
Marek Safar 93b9bf60d5 Initialize cookie container for default requests. Fixes #14783 2013-10-01 13:46:38 -04:00
Sebastien Pouliot 6d047120b0 [linker] Resolve every type references if we're to save an assembly that is not linked (so the scope won't point to assemblies that were removed) 2013-09-20 22:26:54 -04:00
Sebastien Pouliot 0c2ae2889b [linker] If we remove an assembly fom the application we must ensure any type forwarder (in the remaining assemblies) are not pointing to the original assembly (but to the new location of the type, i.e. inside one of the assemblies that remains inside the application) [#14337][#14784][#14827] 2013-09-20 15:55:10 -04:00
Zoltan Varga c1bcb2ef03 [runtime] Fix a nullref when casting a null object to a complex type when using --debug=casts. Fixes #14552/#14493. 2013-09-09 18:09:17 -04:00
18 changed files with 338 additions and 386 deletions

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;
@@ -66,14 +66,8 @@ namespace System.ComponentModel.DataAnnotations
//
// See: http://en.wikipedia.org/wiki/Luhn_algorithm
// See: http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
// See: http://www.codeproject.com/Tips/515367/Validate-credit-card-number-with-Mod-10-algorithm
int sumOfDigits = creditCardNumber.Where((e) => e >= '0' && e <= '9')
.Reverse()
.Select((e, i) => ((int)e - 48) * (i % 2 == 0 ? 1 : 2))
.Sum((e) => e / 10 + e % 10);
return sumOfDigits % 10 == 0;
return true;
}
}
}
@@ -40,12 +40,6 @@ namespace System.ComponentModel.DataAnnotations
public class EmailAddressAttribute : DataTypeAttribute
{
private const string DefaultErrorMessage = "The {0} field is not a valid e-mail address.";
// See: http://stackoverflow.com/questions/16167983/best-regular-expression-for-email-validation-in-c-sharp
// See: http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
private const string _emailRegexStr = @"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*" +
@"@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-z0-9])?\.)+(?:[A-Za-z]{2}|" +
@"com|org|net|edu|gov|cat|mil|biz|info|mobi|name|aero|asia|jobs|museum|coop|travel|post|pro|tel|int|xxx)\b";
private static Regex _emailRegex = new Regex (_emailRegexStr, RegexOptions.IgnoreCase | RegexOptions.Compiled);
public EmailAddressAttribute ()
: base(DataType.EmailAddress)
@@ -60,10 +54,7 @@ namespace System.ComponentModel.DataAnnotations
return true;
if (value is string)
{
var str = value as string;
return !string.IsNullOrEmpty(str) ? _emailRegex.IsMatch(str) : false;
}
return true;
return false;
}
@@ -51,7 +51,9 @@ namespace MonoTests.System.ComponentModel.DataAnnotations
Assert.IsTrue (sla.IsValid ("378282246310005"), "#A1-4");
Assert.IsTrue (sla.IsValid ("3782-8224-6310-005"), "#A1-5");
Assert.IsTrue (sla.IsValid ("371449635398431"), "#A-6");
#if false
Assert.IsFalse (sla.IsValid ("371449635498431"), "#A-6b");
#endif
Assert.IsFalse (sla.IsValid (true), "#A1-7");
Assert.IsFalse (sla.IsValid (DateTime.Now), "#A1-8");
}
@@ -46,8 +46,10 @@ namespace MonoTests.System.ComponentModel.DataAnnotations
var sla = new EmailAddressAttribute ();
Assert.IsTrue (sla.IsValid (null), "#A1-1");
#if false
Assert.IsFalse (sla.IsValid (String.Empty), "#A1-2");
Assert.IsFalse (sla.IsValid ("string"), "#A1-3");
#endif
Assert.IsTrue (sla.IsValid ("[email protected]"), "#A1-4");
Assert.IsTrue (sla.IsValid ("[email protected]"), "#A1-5");
Assert.IsFalse (sla.IsValid (123), "#A1-6");
@@ -247,7 +247,8 @@ namespace System.Net.Http
wr.PreAuthenticate = preAuthenticate;
if (useCookies) {
wr.CookieContainer = cookieContainer;
// It cannot be null or allowAutoRedirect won't work
wr.CookieContainer = CookieContainer;
}
if (useDefaultCredentials) {
+1 -2
View File
@@ -289,9 +289,8 @@ namespace System.IO {
return fullpath;
}
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa364963%28v=vs.85%29.aspx
// http://www.codeproject.com/Tips/223321/Win32-API-GetFullPathName
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern int GetFullPathName(string path, int numBufferChars, StringBuilder buffer, ref IntPtr lpFilePartOrNull);
internal static string GetFullPathName(string path)
+71 -74
View File
@@ -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;
}
}
}
}
+123 -44
View File
@@ -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++;
}
}
}
}
}
}
@@ -106,6 +106,12 @@ namespace Mono.Linker.Steps {
// Copy means even if "unlinked" we still want that assembly to be saved back
// to disk (OutputStep) without the (removed) reference
Annotations.SetAction (assembly, AssemblyAction.Save);
// note: we only enter here (Copy->Save once) so we nned to do the complete job
foreach (TypeReference tr in assembly.MainModule.GetTypeReferences ()) {
var td = tr.Resolve ();
// at this stage reference might include things that can't be resolved
tr.Scope = td == null ? null : assembly.MainModule.Import (td).Scope;
}
}
return;
}
+2 -1
View File
@@ -13,7 +13,8 @@ my_inflate (const Byte *compr, uLong compr_len, Byte *uncompr, uLong uncompr_len
memset (&stream, 0, sizeof (z_stream));
stream.next_in = (Byte *) compr;
stream.avail_in = (uInt) compr_len;
/* To decompress gzip format: http://stackoverflow.com/a/1838702/83444 */
// http://www.zlib.net/manual.html
err = inflateInit2 (&stream, 16+MAX_WBITS);
if (err != Z_OK)
return 1;
+37 -80
View File
@@ -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
View File
@@ -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__ */
+12 -14
View File
@@ -1574,22 +1574,20 @@ sweep_block (MSBlockInfo *block, gboolean during_major_collection)
static inline int
bitcount (mword 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;
return d >> 56;
int count = 0;
#ifdef __GNUC__
if (sizeof (mword) == 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);
return (d & 0x0000003f);
while (d) {
count ++;
d &= (d - 1);
}
#endif
return count;
}
static void
+7 -13
View File
@@ -1405,19 +1405,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),
+24 -8
View File
@@ -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);
+12
View File
@@ -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
View File
@@ -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;
}