Compare commits

...
Author SHA1 Message Date
Jonathan Pryor 0ba10a0d6e Define the MONO_API & related symbols.
Fixes a build break:

	.../mono/mono/metadata/mono-hash.h:24: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'MonoGHashTable'
2013-09-23 15:04:14 -04:00
Miguel de Icaza 4637a49d3f Rewrite the header file, based on the internal mono-hash.c contents
Conflicts:
	mono/metadata/mono-hash.h
2013-09-23 12:39:56 -04:00
Miguel de Icaza f0670279f0 Remove text from article 2013-09-23 12:39:09 -04:00
Miguel de Icaza 378190cc06 Simplify locale fetching, we have very simple needs 2013-09-23 12:38:57 -04:00
Sebastien Pouliot 63e9680b83 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-09-23 12:38:52 -04:00
Miguel de Icaza 51da73b27e Remove comment, refer to the spec instead 2013-09-23 12:38:46 -04:00
Zoltan Varga 1b67e5118c [runtime] Fix a regression introduced by 5503991372. Use __builtin_popcountl () on 64 bit machines. 2013-09-23 12:38:41 -04:00
Zoltan Varga bc6fb04b29 Use __builtin_popcount () in mono_bitset_count (). 2013-09-23 12:38:35 -04:00
Marek Safar 27fa78fa6d Remove CultureInfo.CurrentCulture dependency from ordinal based string::EndsWith. Fixes #13509 2013-07-29 15:30:35 -04:00
Zoltan Varga ec40cb0d68 Avoid an assert on android where seq points are not generated for wrappers. 2013-07-26 16:03:13 -04:00
Alex Rønne Petersen c10b255509 Revert the use of mono_binary_search () in support/supportw.c.
This code can't depend on mono/utils and doesn't need the 'fixed'
implementation of bsearch () anyway since keys are never null.
2013-07-26 16:03:12 -04:00
Alex Rønne Petersen 08e0f0446e Add a mono_binary_search () function.
This is a replacement for bsearch () because some platforms
have bogus asserts in their implementations.

Conflicts:
	mono/utils/Makefile.am
	msvc/libmonoutils.vcxproj
2013-07-26 16:03:06 -04:00
22 changed files with 441 additions and 392 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;
+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;
}
}
}
}
+2 -2
View File
@@ -1694,9 +1694,9 @@ namespace System
case StringComparison.InvariantCultureIgnoreCase:
return CultureInfo.InvariantCulture.CompareInfo.IsSuffix (this, value, CompareOptions.IgnoreCase);
case StringComparison.Ordinal:
return CultureInfo.CurrentCulture.CompareInfo.IsSuffix (this, value, CompareOptions.Ordinal);
return CultureInfo.InvariantCulture.CompareInfo.IsSuffix (this, value, CompareOptions.Ordinal);
case StringComparison.OrdinalIgnoreCase:
return CultureInfo.CurrentCulture.CompareInfo.IsSuffix (this, value, CompareOptions.OrdinalIgnoreCase);
return CultureInfo.InvariantCulture.CompareInfo.IsSuffix (this, value, CompareOptions.OrdinalIgnoreCase);
default:
string msg = Locale.GetText ("Invalid value '{0}' for StringComparison", comparisonType);
throw new ArgumentException (msg, "comparisonType");
+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++;
}
}
}
}
}
}
+3 -2
View File
@@ -30,6 +30,7 @@
#include <mono/metadata/loader.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/appdomain.h>
#include <mono/utils/bsearch.h>
static void setup_filter (MonoImage *image);
static gboolean should_include_type (int idx);
@@ -1109,7 +1110,7 @@ dis_interfaces (MonoImage *m, guint32 typedef_row, MonoGenericContainer *contain
loc.col_idx = MONO_INTERFACEIMPL_CLASS;
loc.idx = typedef_row;
if (!bsearch (&loc, table->base, table->rows, table->row_size, table_locator))
if (!mono_binary_search (&loc, table->base, table->rows, table->row_size, table_locator))
return;
start = loc.result;
@@ -1680,7 +1681,7 @@ table_includes (TableFilter *tf, int idx)
{
if (!tf->count)
return FALSE;
return bsearch (&idx, tf->elems, tf->count, sizeof (int), int_cmp) != NULL;
return mono_binary_search (&idx, tf->elems, tf->count, sizeof (int), int_cmp) != NULL;
}
static gboolean
+2 -1
View File
@@ -17,6 +17,7 @@
#include <mono/io-layer/wapi-private.h>
#include <mono/io-layer/misc-private.h>
#include <mono/io-layer/messages.h>
#include <mono/utils/bsearch.h>
#undef DEBUG
@@ -1830,7 +1831,7 @@ find_msg (guint32 id, ErrorDesc *base, int n)
ErrorDesc d, *result;
d.id = id;
result = bsearch (&d, base, n, sizeof (ErrorDesc), msg_compare);
result = mono_binary_search (&d, base, n, sizeof (ErrorDesc), msg_compare);
if (result == NULL)
return NULL;
return result->txt;
+3 -1
View File
@@ -42,6 +42,8 @@
#include <mono/utils/mono-logger-internal.h>
#include <mono/utils/mono-memory-model.h>
#include <mono/utils/atomic.h>
#include <mono/utils/bsearch.h>
MonoStats mono_stats;
gboolean mono_print_vtable = FALSE;
@@ -2645,7 +2647,7 @@ compare_interface_ids (const void *p_key, const void *p_element) {
/*FIXME verify all callers if they should switch to mono_class_interface_offset_with_variance*/
int
mono_class_interface_offset (MonoClass *klass, MonoClass *itf) {
MonoClass **result = bsearch (
MonoClass **result = mono_binary_search (
itf,
klass->interfaces_packed,
klass->interface_offsets_count,
+2 -1
View File
@@ -30,6 +30,7 @@
#include <mono/metadata/metadata-internals.h>
#include <mono/metadata/class-internals.h>
#include <mono/utils/mono-mmap.h>
#include <mono/utils/bsearch.h>
#include <fcntl.h>
#ifdef HAVE_UNISTD_H
@@ -731,7 +732,7 @@ mono_debug_symfile_lookup_method (MonoDebugHandle *handle, MonoMethod *method)
first_ie = (MonoSymbolFileMethodEntry *)
(symfile->raw_contents + read32(&(symfile->offset_table->_method_table_offset)));
ie = bsearch (GUINT_TO_POINTER (mono_method_get_token (method)), first_ie,
ie = mono_binary_search (GUINT_TO_POINTER (mono_method_get_token (method)), first_ie,
read32(&(symfile->offset_table->_method_count)),
sizeof (MonoSymbolFileMethodEntry), compare_method);
+6 -5
View File
@@ -84,6 +84,7 @@
#include <mono/utils/mono-mmap.h>
#include <mono/utils/mono-io-portability.h>
#include <mono/utils/mono-digest.h>
#include <mono/utils/bsearch.h>
#if defined (HOST_WIN32)
#include <windows.h>
@@ -7947,7 +7948,7 @@ compare_method_imap (const void *key, const void *elem)
static gpointer
find_method_icall (const IcallTypeDesc *imap, const char *name)
{
const guint16 *nameslot = bsearch (name, icall_names_idx + imap->first_icall, icall_desc_num_icalls (imap), sizeof (icall_names_idx [0]), compare_method_imap);
const guint16 *nameslot = mono_binary_search (name, icall_names_idx + imap->first_icall, icall_desc_num_icalls (imap), sizeof (icall_names_idx [0]), compare_method_imap);
if (!nameslot)
return NULL;
return (gpointer)icall_functions [(nameslot - &icall_names_idx [0])];
@@ -7963,7 +7964,7 @@ compare_class_imap (const void *key, const void *elem)
static const IcallTypeDesc*
find_class_icalls (const char *name)
{
const guint16 *nameslot = bsearch (name, icall_type_names_idx, Icall_type_num, sizeof (icall_type_names_idx [0]), compare_class_imap);
const guint16 *nameslot = mono_binary_search (name, icall_type_names_idx, Icall_type_num, sizeof (icall_type_names_idx [0]), compare_class_imap);
if (!nameslot)
return NULL;
return &icall_type_descs [nameslot - &icall_type_names_idx [0]];
@@ -7981,7 +7982,7 @@ compare_method_imap (const void *key, const void *elem)
static gpointer
find_method_icall (const IcallTypeDesc *imap, const char *name)
{
const char **nameslot = bsearch (name, icall_names + imap->first_icall, icall_desc_num_icalls (imap), sizeof (icall_names [0]), compare_method_imap);
const char **nameslot = mono_binary_search (name, icall_names + imap->first_icall, icall_desc_num_icalls (imap), sizeof (icall_names [0]), compare_method_imap);
if (!nameslot)
return NULL;
return (gpointer)icall_functions [(nameslot - icall_names)];
@@ -7997,7 +7998,7 @@ compare_class_imap (const void *key, const void *elem)
static const IcallTypeDesc*
find_class_icalls (const char *name)
{
const char **nameslot = bsearch (name, icall_type_names, Icall_type_num, sizeof (icall_type_names [0]), compare_class_imap);
const char **nameslot = mono_binary_search (name, icall_type_names, Icall_type_num, sizeof (icall_type_names [0]), compare_class_imap);
if (!nameslot)
return NULL;
return &icall_type_descs [nameslot - icall_type_names];
@@ -8208,7 +8209,7 @@ mono_lookup_icall_symbol (MonoMethod *m)
func = mono_lookup_internal_call (m);
if (!func)
return NULL;
slot = bsearch (func, functions_sorted, G_N_ELEMENTS (icall_functions), sizeof (gpointer), func_cmp);
slot = mono_binary_search (func, functions_sorted, G_N_ELEMENTS (icall_functions), sizeof (gpointer), func_cmp);
if (!slot)
return NULL;
g_assert (slot);
+43 -85
View File
@@ -24,6 +24,7 @@
#include <mono/metadata/locales.h>
#include <mono/metadata/culture-info.h>
#include <mono/metadata/culture-info-tables.h>
#include <mono/utils/bsearch.h>
#ifndef DISABLE_NORMALIZATION
#include <mono/metadata/normalization-tables.h>
@@ -313,7 +314,7 @@ construct_culture_from_specific_name (MonoCultureInfo *ci, gchar *name)
MONO_ARCH_SAVE_REGS;
ne = bsearch (name, culture_name_entries, NUM_CULTURE_ENTRIES,
ne = mono_binary_search (name, culture_name_entries, NUM_CULTURE_ENTRIES,
sizeof (CultureInfoNameEntry), culture_name_locator);
if (ne == NULL)
@@ -332,7 +333,7 @@ culture_info_entry_from_lcid (int lcid)
{
const CultureInfoEntry *ci;
ci = bsearch (&lcid, culture_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoEntry), culture_lcid_locator);
ci = mono_binary_search (&lcid, culture_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoEntry), culture_lcid_locator);
return ci;
}
@@ -345,7 +346,7 @@ region_info_entry_from_lcid (int lcid)
MONO_ARCH_SAVE_REGS;
ne = bsearch (&lcid, culture_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoEntry), culture_lcid_locator);
ne = mono_binary_search (&lcid, culture_entries, NUM_CULTURE_ENTRIES, sizeof (CultureInfoEntry), culture_lcid_locator);
if (ne == NULL)
return FALSE;
@@ -355,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)
@@ -429,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__)
@@ -445,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)
@@ -537,7 +495,7 @@ ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name (
MONO_ARCH_SAVE_REGS;
n = mono_string_to_utf8 (name);
ne = bsearch (n, culture_name_entries, NUM_CULTURE_ENTRIES,
ne = mono_binary_search (n, culture_name_entries, NUM_CULTURE_ENTRIES,
sizeof (CultureInfoNameEntry), culture_name_locator);
if (ne == NULL) {
@@ -591,7 +549,7 @@ ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_name (M
MONO_ARCH_SAVE_REGS;
n = mono_string_to_utf8 (name);
ne = bsearch (n, region_name_entries, NUM_REGION_ENTRIES,
ne = mono_binary_search (n, region_name_entries, NUM_REGION_ENTRIES,
sizeof (RegionInfoNameEntry), region_name_locator);
if (ne == NULL) {
+2 -1
View File
@@ -24,6 +24,7 @@
#include <mono/metadata/attrdefs.h>
#include <mono/utils/strenc.h>
#include <mono/utils/mono-error-internals.h>
#include <mono/utils/bsearch.h>
#include <string.h>
//#include <signal.h>
#include <ctype.h>
@@ -1069,7 +1070,7 @@ search_sorted_table (VerifyContext *ctx, int table, int column, guint32 coded_to
base = tinfo->base;
VERIFIER_DEBUG ( printf ("looking token %x table %d col %d rsize %d roff %d\n", coded_token, table, column, locator.col_size, locator.col_offset) );
res = bsearch (&locator, base, tinfo->rows, tinfo->row_size, token_locator);
res = mono_binary_search (&locator, base, tinfo->rows, tinfo->row_size, token_locator);
if (!res)
return -1;
+20 -19
View File
@@ -26,7 +26,8 @@
#include "marshal.h"
#include "debug-helpers.h"
#include <mono/utils/mono-error-internals.h>
#include <mono/utils/bsearch.h>
/* Auxiliary structure used for caching inflated signatures */
typedef struct {
MonoMethodSignature *sig;
@@ -3917,7 +3918,7 @@ mono_metadata_typedef_from_field (MonoImage *meta, guint32 index)
if (meta->uncompressed_metadata)
loc.idx = search_ptr_table (meta, MONO_TABLE_FIELD_POINTER, loc.idx);
if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, typedef_locator))
if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, typedef_locator))
return 0;
/* loc_result is 0..1, needs to be mapped to table index (that is +1) */
@@ -3948,7 +3949,7 @@ mono_metadata_typedef_from_method (MonoImage *meta, guint32 index)
if (meta->uncompressed_metadata)
loc.idx = search_ptr_table (meta, MONO_TABLE_METHOD_POINTER, loc.idx);
if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, typedef_locator))
if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, typedef_locator))
return 0;
/* loc_result is 0..1, needs to be mapped to table index (that is +1) */
@@ -3990,7 +3991,7 @@ mono_metadata_interfaces_from_typedef_full (MonoImage *meta, guint32 index, Mono
loc.col_idx = MONO_INTERFACEIMPL_CLASS;
loc.t = tdef;
if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
return TRUE;
start = loc.result;
@@ -4086,7 +4087,7 @@ mono_metadata_nested_in_typedef (MonoImage *meta, guint32 index)
loc.col_idx = MONO_NESTED_CLASS_NESTED;
loc.t = tdef;
if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
return 0;
/* loc_result is 0..1, needs to be mapped to table index (that is +1) */
@@ -4150,7 +4151,7 @@ mono_metadata_packing_from_typedef (MonoImage *meta, guint32 index, guint32 *pac
loc.col_idx = MONO_CLASS_LAYOUT_PARENT;
loc.t = tdef;
if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
return 0;
mono_metadata_decode_row (tdef, loc.result, cols, MONO_CLASS_LAYOUT_SIZE);
@@ -4187,7 +4188,7 @@ mono_metadata_custom_attrs_from_index (MonoImage *meta, guint32 index)
/* FIXME: Index translation */
if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
return 0;
/* Find the first entry by searching backwards */
@@ -4220,7 +4221,7 @@ mono_metadata_declsec_from_index (MonoImage *meta, guint32 index)
loc.col_idx = MONO_DECL_SECURITY_PARENT;
loc.t = tdef;
if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, declsec_locator))
if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, declsec_locator))
return -1;
/* Find the first entry by searching backwards */
@@ -4934,7 +4935,7 @@ mono_metadata_field_info_full (MonoImage *meta, guint32 index, guint32 *offset,
loc.col_idx = MONO_FIELD_LAYOUT_FIELD;
loc.t = tdef;
if (tdef->base && bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) {
if (tdef->base && mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) {
*offset = mono_metadata_decode_row_col (tdef, loc.result, MONO_FIELD_LAYOUT_OFFSET);
} else {
*offset = (guint32)-1;
@@ -4946,7 +4947,7 @@ mono_metadata_field_info_full (MonoImage *meta, guint32 index, guint32 *offset,
loc.col_idx = MONO_FIELD_RVA_FIELD;
loc.t = tdef;
if (tdef->base && bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) {
if (tdef->base && mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) {
/*
* LAMESPEC: There is no signature, no nothing, just the raw data.
*/
@@ -5007,7 +5008,7 @@ mono_metadata_get_constant_index (MonoImage *meta, guint32 token, guint32 hint)
if ((hint > 0) && (hint < tdef->rows) && (mono_metadata_decode_row_col (tdef, hint - 1, MONO_CONSTANT_PARENT) == index))
return hint;
if (tdef->base && bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) {
if (tdef->base && mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator)) {
return loc.result + 1;
}
return 0;
@@ -5038,7 +5039,7 @@ mono_metadata_events_from_typedef (MonoImage *meta, guint32 index, guint *end_id
loc.col_idx = MONO_EVENT_MAP_PARENT;
loc.idx = index + 1;
if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
return 0;
start = mono_metadata_decode_row_col (tdef, loc.result, MONO_EVENT_MAP_EVENTLIST);
@@ -5080,7 +5081,7 @@ mono_metadata_methods_from_event (MonoImage *meta, guint32 index, guint *end_i
loc.col_idx = MONO_METHOD_SEMA_ASSOCIATION;
loc.idx = ((index + 1) << MONO_HAS_SEMANTICS_BITS) | MONO_HAS_SEMANTICS_EVENT; /* Method association coded index */
if (!bsearch (&loc, msemt->base, msemt->rows, msemt->row_size, table_locator))
if (!mono_binary_search (&loc, msemt->base, msemt->rows, msemt->row_size, table_locator))
return 0;
start = loc.result;
@@ -5129,7 +5130,7 @@ mono_metadata_properties_from_typedef (MonoImage *meta, guint32 index, guint *en
loc.col_idx = MONO_PROPERTY_MAP_PARENT;
loc.idx = index + 1;
if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
return 0;
start = mono_metadata_decode_row_col (tdef, loc.result, MONO_PROPERTY_MAP_PROPERTY_LIST);
@@ -5171,7 +5172,7 @@ mono_metadata_methods_from_property (MonoImage *meta, guint32 index, guint *en
loc.col_idx = MONO_METHOD_SEMA_ASSOCIATION;
loc.idx = ((index + 1) << MONO_HAS_SEMANTICS_BITS) | MONO_HAS_SEMANTICS_PROPERTY; /* Method association coded index */
if (!bsearch (&loc, msemt->base, msemt->rows, msemt->row_size, table_locator))
if (!mono_binary_search (&loc, msemt->base, msemt->rows, msemt->row_size, table_locator))
return 0;
start = loc.result;
@@ -5210,7 +5211,7 @@ mono_metadata_implmap_from_method (MonoImage *meta, guint32 method_idx)
loc.col_idx = MONO_IMPLMAP_MEMBER;
loc.idx = ((method_idx + 1) << MONO_MEMBERFORWD_BITS) | MONO_MEMBERFORWD_METHODDEF;
if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
return 0;
return loc.result + 1;
@@ -5594,7 +5595,7 @@ mono_metadata_get_marshal_info (MonoImage *meta, guint32 idx, gboolean is_field)
/* FIXME: Index translation */
if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
return NULL;
return mono_metadata_blob_heap (meta, mono_metadata_decode_row_col (tdef, loc.result, MONO_FIELD_MARSHAL_NATIVE_TYPE));
@@ -5647,7 +5648,7 @@ mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod
loc.col_idx = MONO_METHODIMPL_CLASS;
loc.idx = mono_metadata_token_index (type_token);
if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
return TRUE;
start = loc.result;
@@ -5787,7 +5788,7 @@ mono_metadata_get_generic_param_row (MonoImage *image, guint32 token, guint32 *o
loc.col_idx = MONO_GENERICPARAM_OWNER;
loc.t = tdef;
if (!bsearch (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
if (!mono_binary_search (&loc, tdef->base, tdef->rows, tdef->row_size, table_locator))
return 0;
/* Find the first entry by searching backwards */
+24 -88
View File
@@ -1,47 +1,16 @@
/* 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 (lupus@xamarin.com)
*
* 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>
G_BEGIN_DECLS
typedef struct _MonoGHashTable MonoGHashTable;
typedef gpointer (*MonoGRemapperFunc) (gpointer key, gpointer value,
gpointer user_data);
/* do not change the values of this enum */
typedef enum {
MONO_HASH_CONSERVATIVE_GC,
@@ -50,55 +19,22 @@ typedef enum {
MONO_HASH_KEY_VALUE_GC /* note this is the OR of the other two values */
} MonoGHashGCType;
/* Hash tables
*/
MonoGHashTable* mono_g_hash_table_new (GHashFunc hash_func,
GEqualFunc key_equal_func);
MonoGHashTable* mono_g_hash_table_new_type (GHashFunc hash_func,
GEqualFunc key_equal_func,
MonoGHashGCType type);
MonoGHashTable* mono_g_hash_table_new_full (GHashFunc hash_func,
GEqualFunc key_equal_func,
GDestroyNotify key_destroy_func,
GDestroyNotify value_destroy_func);
void mono_g_hash_table_destroy (MonoGHashTable *hash_table);
void mono_g_hash_table_insert (MonoGHashTable *hash_table,
gpointer key,
gpointer value);
void mono_g_hash_table_replace (MonoGHashTable *hash_table,
gpointer key,
gpointer value);
gboolean mono_g_hash_table_remove (MonoGHashTable *hash_table,
gconstpointer key);
gboolean mono_g_hash_table_steal (MonoGHashTable *hash_table,
gconstpointer key);
gpointer mono_g_hash_table_lookup (MonoGHashTable *hash_table,
gconstpointer key);
gboolean mono_g_hash_table_lookup_extended (MonoGHashTable *hash_table,
gconstpointer lookup_key,
gpointer *orig_key,
gpointer *value);
void mono_g_hash_table_foreach (MonoGHashTable *hash_table,
GHFunc func,
gpointer user_data);
guint mono_g_hash_table_foreach_remove (MonoGHashTable *hash_table,
GHRFunc func,
gpointer user_data);
guint mono_g_hash_table_foreach_steal (MonoGHashTable *hash_table,
GHRFunc func,
gpointer user_data);
gpointer mono_g_hash_table_find (MonoGHashTable *hash_table,
GHRFunc predicate,
gpointer user_data);
guint mono_g_hash_table_size (MonoGHashTable *hash_table);
typedef struct _MonoGHashTable MonoGHashTable;
void mono_g_hash_table_remap (MonoGHashTable *hash_table,
MonoGRemapperFunc func,
gpointer user_data);
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);
#endif /* __MONO_G_HASH_H__ */
+7 -13
View File
@@ -1402,19 +1402,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),
+9 -8
View File
@@ -3803,17 +3803,18 @@ mono_save_seq_point_info (MonoCompile *cfg)
* The ENDFINALLY branches are not represented in the cfg, so link it with all seq points starting bbs.
*/
l = g_slist_last (bb->seq_points);
g_assert (l);
endfinally_seq_point = l->data;
if (l) {
endfinally_seq_point = l->data;
for (bb2 = cfg->bb_entry; bb2; bb2 = bb2->next_bb) {
GSList *l = g_slist_last (bb2->seq_points);
for (bb2 = cfg->bb_entry; bb2; bb2 = bb2->next_bb) {
GSList *l = g_slist_last (bb2->seq_points);
if (l) {
MonoInst *ins = l->data;
if (l) {
MonoInst *ins = l->data;
if (!(ins->inst_imm == METHOD_ENTRY_IL_OFFSET || ins->inst_imm == METHOD_EXIT_IL_OFFSET) && ins != endfinally_seq_point)
next [endfinally_seq_point->backend.size] = g_slist_append (next [endfinally_seq_point->backend.size], GUINT_TO_POINTER (ins->backend.size));
if (!(ins->inst_imm == METHOD_ENTRY_IL_OFFSET || ins->inst_imm == METHOD_EXIT_IL_OFFSET) && ins != endfinally_seq_point)
next [endfinally_seq_point->backend.size] = g_slist_append (next [endfinally_seq_point->backend.size], GUINT_TO_POINTER (ins->backend.size));
}
}
}
}
+2 -1
View File
@@ -12,6 +12,7 @@
#include "mini.h"
#include "ir-emit.h"
#include "mono/utils/bsearch.h"
/*
General notes on SIMD intrinsics
@@ -1477,7 +1478,7 @@ simd_version_name (guint32 version)
static MonoInst*
emit_intrinsics (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args, const SimdIntrinsc *intrinsics, guint32 size)
{
const SimdIntrinsc * result = bsearch (cmethod->name, intrinsics, size, sizeof (SimdIntrinsc), &simd_intrinsic_compare_by_name);
const SimdIntrinsc * result = mono_binary_search (cmethod->name, intrinsics, size, sizeof (SimdIntrinsc), &simd_intrinsic_compare_by_name);
if (!result) {
DEBUG (printf ("function doesn't have a simd intrinsic %s::%s/%d\n", cmethod->klass->name, cmethod->name, fsig->param_count));
return NULL;
+3 -1
View File
@@ -103,7 +103,9 @@ monoutils_sources = \
linux_magic.h \
mono-memory-model.h \
atomic.h \
atomic.c
atomic.c \
bsearch.h \
bsearch.c
arch_sources =
+63
View File
@@ -0,0 +1,63 @@
/*
* bsearch () implementation. Needed because some broken platforms
* have implementations that have unreasonable, non-standard
* requirements (e.g. "key must not be null"). Taken from NetBSD
* with some minor modifications.
*
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "mono/utils/bsearch.h"
void *
mono_binary_search (
const void *key,
const void *array,
size_t array_length,
size_t member_size,
BinarySearchComparer comparer)
{
const char *base = array;
size_t lim;
int cmp;
const void *p;
for (lim = array_length; lim; lim >>= 1) {
p = base + (lim >> 1) * member_size;
cmp = (* comparer) (key, p);
if (!cmp)
return (void *) p;
else if (cmp > 0) {
base = (const char *) p + member_size;
lim--;
}
}
return NULL;
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef __MONO_BSEARCH_H__
#define __MONO_BSEARCH_H__
#include <stdlib.h>
#include "mono/utils/mono-compiler.h"
typedef int (* BinarySearchComparer) (const void *key, const void *member);
void *
mono_binary_search (
const void *key,
const void *array,
size_t array_length,
size_t member_size,
BinarySearchComparer comparer);
#endif
+24 -2
View File
@@ -18,7 +18,9 @@
MONO_BEGIN_DECLS
/* VS 2010 and later have stdint.h */
#if defined(_MSC_VER) && _MSC_VER < 1600
#if defined(_MSC_VER)
#if _MSC_VER < 1600
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
@@ -33,8 +35,28 @@ typedef unsigned __int64 uint64_t;
#include <stdint.h>
#endif
#define MONO_API_EXPORT __declspec(dllexport)
#define MONO_API_IMPORT __declspec(dllimport)
#else
#include <stdint.h>
#define MONO_API_EXPORT
#define MONO_API_IMPORT
#endif /* end of compiler-specific stuff */
#if !defined(MONO_STATIC_BUILD) && defined(MONO_DLL_EXPORT)
#define MONO_API MONO_API_EXPORT
#elif !defined(MONO_STATIC_BUILD)
#define MONO_API MONO_API_IMPORT
#else
#define MONO_API
#endif
typedef int32_t mono_bool;
typedef uint8_t mono_byte;
typedef uint16_t mono_unichar2;
@@ -42,7 +64,7 @@ typedef uint16_t mono_unichar2;
typedef void (*MonoFunc) (void* data, void* user_data);
typedef void (*MonoHFunc) (void* key, void* value, void* user_data);
void mono_free (void *);
MONO_API void mono_free (void *);
#define MONO_CONST_RETURN const
+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;
}
+5 -1
View File
@@ -61,6 +61,8 @@
<ClCompile Include="..\mono\utils\monobitset.c" />
<ClCompile Include="..\mono\utils\strenc.c" />
<ClCompile Include="..\mono\utils\strtod.c" />
<ClCompile Include="..\mono\utils\atomic.c" />
<ClCompile Include="..\mono\utils\bsearch.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\mono\utils\dlmalloc.h" />
@@ -116,6 +118,8 @@
<ClInclude Include="..\mono\utils\strenc.h" />
<ClInclude Include="..\mono\utils\strtod.h" />
<ClInclude Include="..\mono\utils\valgrind.h" />
<ClInclude Include="..\mono\utils\atomic.h" />
<ClInclude Include="..\mono\utils\bsearch.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8FC2B0C8-51AD-49DF-851F-5D01A77A75E4}</ProjectGuid>
@@ -254,4 +258,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>