Do TLS using pthreads if __thread keyword not supported.
[mono.git] / mono / metadata / locales.c
index 74279f5a2898bb50490fb3eea4eb2e492b056f34..9d977d1e85e2b00979fc9584366cae42c9a18527 100644 (file)
@@ -5,7 +5,8 @@
  *     Dick Porter (dick@ximian.com)
  *     Mohammad DAMT (mdamt@cdl2000.com)
  *
- * (C) 2003 Ximian, Inc.
+ * Copyright 2003 Ximian, Inc (http://www.ximian.com)
+ * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
  * (C) 2003 PT Cakram Datalingga Duaribu  http://www.cdl2000.com
  */
 
@@ -21,6 +22,7 @@
 #include <mono/metadata/locales.h>
 #include <mono/metadata/culture-info.h>
 #include <mono/metadata/culture-info-tables.h>
+#include <mono/metadata/normalization-tables.h>
 
 
 #include <locale.h>
@@ -101,7 +103,7 @@ create_group_sizes_array (const gint *gs, gint ml)
                len++;
        }
        
-       ret = mono_array_new (mono_domain_get (),
+       ret = mono_array_new_cached (mono_domain_get (),
                        mono_get_int32_class (), len);
 
        for(i = 0; i < len; i++)
@@ -128,7 +130,7 @@ create_names_array_idx (const guint16 *names, int ml)
                len++;
        }
 
-       ret = mono_array_new (mono_domain_get (), mono_get_string_class (), len);
+       ret = mono_array_new_cached (mono_domain_get (), mono_get_string_class (), len);
 
        for(i = 0; i < len; i++)
                mono_array_setref (ret, i, mono_string_new (domain, idx2string (names [i])));
@@ -152,6 +154,7 @@ ves_icall_System_Globalization_CultureInfo_construct_datetime_format (MonoCultur
 
        domain = mono_domain_get ();
 
+       datetime->readOnly = this->is_read_only;
        MONO_OBJECT_SETREF (datetime, AbbreviatedDayNames, create_names_array_idx (dfe->abbreviated_day_names,
                        NUM_DAYS));
        MONO_OBJECT_SETREF (datetime, AbbreviatedMonthNames, create_names_array_idx (dfe->abbreviated_month_names,
@@ -198,6 +201,7 @@ ves_icall_System_Globalization_CultureInfo_construct_number_format (MonoCultureI
 
        domain = mono_domain_get ();
 
+       number->readOnly = this->is_read_only;
        number->currencyDecimalDigits = nfe->currency_decimal_digits;
        MONO_OBJECT_SETREF (number, currencyDecimalSeparator, mono_string_new (domain,
                        idx2string (nfe->currency_decimal_separator)));
@@ -249,6 +253,7 @@ construct_culture (MonoCultureInfo *this, const CultureInfoEntry *ci)
        MONO_OBJECT_SETREF (this, win3lang, mono_string_new (domain, idx2string (ci->win3lang)));
        MONO_OBJECT_SETREF (this, iso3lang, mono_string_new (domain, idx2string (ci->iso3lang)));
        MONO_OBJECT_SETREF (this, iso2lang, mono_string_new (domain, idx2string (ci->iso2lang)));
+       MONO_OBJECT_SETREF (this, territory, mono_string_new (domain, idx2string (ci->territory)));
        this->parent_lcid = ci->parent_lcid;
        this->specific_lcid = ci->specific_lcid;
        this->datetime_index = ci->datetime_format_index;
@@ -299,25 +304,6 @@ construct_culture_from_specific_name (MonoCultureInfo *ci, gchar *name)
        return construct_culture (ci, entry);
 }
 
-static gboolean
-construct_region_from_specific_name (MonoRegionInfo *ri, gchar *name)
-{
-       const RegionInfoEntry *entry;
-       const RegionInfoNameEntry *ne;
-
-       MONO_ARCH_SAVE_REGS;
-
-       ne = bsearch (name, region_name_entries, NUM_REGION_ENTRIES,
-                       sizeof (RegionInfoNameEntry), region_name_locator);
-
-       if (ne == NULL)
-               return FALSE;
-
-       entry = &region_entries [ne->region_entry_index];
-
-       return construct_region (ri, entry);
-}
-
 static const CultureInfoEntry*
 culture_info_entry_from_lcid (int lcid)
 {
@@ -402,7 +388,7 @@ get_current_locale_name (void)
 
        if ((p = strchr (locale, '.')) != NULL) {
                /* assume new locale can't be larger than old one? */
-               corrected = malloc (strlen (locale));
+               corrected = g_malloc (strlen (locale));
                strncpy (corrected, locale, p - locale);
                corrected [p - locale] = 0;
 
@@ -421,7 +407,7 @@ get_current_locale_name (void)
                 */
 
                if (corrected == NULL) {
-                       corrected = malloc (strlen (locale));
+                       corrected = g_malloc (strlen (locale));
                        strncpy (corrected, locale, p - locale);
                        corrected [p - locale] = 0;
                }
@@ -435,7 +421,9 @@ get_current_locale_name (void)
        if ((c = strchr (corrected, '_')) != NULL)
                *c = '-';
 
-       g_strdown (corrected);
+       c = corrected;
+       corrected = g_ascii_strdown (c, -1);
+       g_free (c);
 
        return corrected;
 }       
@@ -454,6 +442,8 @@ ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_curren
 
        ret = construct_culture_from_specific_name (ci, locale);
        g_free (locale);
+       ci->is_read_only = TRUE;
+       ci->use_user_override = TRUE;
 
        return ret;
 }
@@ -598,6 +588,7 @@ ves_icall_System_Globalization_CultureInfo_internal_get_cultures (MonoBoolean ne
                        culture = (MonoCultureInfo *) mono_object_new (domain, class);
                        mono_runtime_object_init ((MonoObject *) culture);
                        construct_culture (culture, ci);
+                       culture->use_user_override = TRUE;
                        mono_array_setref (ret, len++, culture);
                }
        }
@@ -627,16 +618,6 @@ ves_icall_System_Globalization_CultureInfo_internal_is_lcid_neutral (gint lcid,
        return TRUE;
 }
 
-void ves_icall_System_Globalization_CultureInfo_construct_internal_locale (MonoCultureInfo *this, MonoString *locale)
-{
-       MONO_ARCH_SAVE_REGS;
-       
-       /* Always claim "unknown locale" if we don't have ICU (only
-        * called for non-invariant locales)
-        */
-       mono_raise_exception((MonoException *)mono_exception_from_name(mono_get_corlib (), "System", "ArgumentException"));
-}
-
 void ves_icall_System_Globalization_CompareInfo_construct_compareinfo (MonoCompareInfo *comp, MonoString *locale)
 {
        /* Nothing to do here */
@@ -713,16 +694,17 @@ static gint32 string_invariant_compare_char (gunichar2 c1, gunichar2 c2,
                                             gint32 options)
 {
        gint32 result;
-       GUnicodeType c1type, c2type;
 
        /* Ordinal can not be mixed with other options, and must return the difference, not only -1, 0, 1 */
        if (options & CompareOptions_Ordinal) 
                return (gint32) c1 - c2;
        
-       c1type = g_unichar_type (c1);
-       c2type = g_unichar_type (c2);
-       
        if (options & CompareOptions_IgnoreCase) {
+               GUnicodeType c1type, c2type;
+
+               c1type = g_unichar_type (c1);
+               c2type = g_unichar_type (c2);
+       
                result = (gint32) (c1type != G_UNICODE_LOWERCASE_LETTER ? g_unichar_tolower(c1) : c1) -
                        (c2type != G_UNICODE_LOWERCASE_LETTER ? g_unichar_tolower(c2) : c2);
        } else {
@@ -938,3 +920,19 @@ static gint32 string_invariant_indexof_char (MonoString *source, gint32 sindex,
        }
 }
 
+void load_normalization_resource (guint8 **argProps,
+                                 guint8 **argMappedChars,
+                                 guint8 **argCharMapIndex,
+                                 guint8 **argHelperIndex,
+                                 guint8 **argMapIdxToComposite,
+                                 guint8 **argCombiningClass)
+{
+       *argProps = (guint8*)props;
+       *argMappedChars = (guint8*) mappedChars;
+       *argCharMapIndex = (guint8*) charMapIndex;
+       *argHelperIndex = (guint8*) helperIndex;
+       *argMapIdxToComposite = (guint8*) mapIdxToComposite;
+       *argCombiningClass = (guint8*)combiningClass;
+}
+
+