]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/propname.cpp
ICU-461.12.tar.gz
[apple/icu.git] / icuSources / common / propname.cpp
index 789a610aca27684a60e7127d6eece158c3109e6c..1721f83ebd41ec5f63d7d4746103aea77da24c9e 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-* Copyright (c) 2002-2004, International Business Machines
+* Copyright (c) 2002-2009, International Business Machines
 * Corporation and others.  All Rights Reserved.
 **********************************************************************
 * Author: Alan Liu
@@ -204,6 +204,7 @@ PropertyAliases::getPropertyValueEnum(EnumValue prop,
 }
 
 U_NAMESPACE_END
+U_NAMESPACE_USE
 
 //----------------------------------------------------------------------
 // UDataMemory structures
@@ -233,7 +234,7 @@ isPNameAcceptable(void* /*context*/,
         info->formatVersion[0] == PNAME_FORMAT_VERSION;
 }
 
-static UBool U_CALLCONV pname_cleanup() {
+static UBool U_CALLCONV pname_cleanup(void) {
     if (UDATA) {
         udata_close(UDATA);
         UDATA = NULL;
@@ -276,9 +277,8 @@ static UBool _load() {
  * to load it, and return TRUE if the load succeeds.
  */
 static inline UBool load() {
-    umtx_lock(NULL);
-    UBool f = (PNAME!=NULL);
-    umtx_unlock(NULL);
+    UBool f;
+    UMTX_CHECK(NULL, (PNAME!=NULL), f);
     return f || _load();
 }
 
@@ -520,16 +520,18 @@ NameToEnum::swap(const UDataSwapper *ds,
          * which makes testing harder
          */
         cmp.chars=(const char *)outBytes;
-        cmp.propCompare=
-            ds->outCharset==U_ASCII_FAMILY ?
-                uprv_compareASCIIPropertyNames :
-                uprv_compareEBCDICPropertyNames;
+        if (ds->outCharset==U_ASCII_FAMILY) {
+            cmp.propCompare=uprv_compareASCIIPropertyNames;
+        }
+        else {
+            cmp.propCompare=uprv_compareEBCDICPropertyNames;
+        }
         uprv_sortArray(sortArray, tempMap->count, sizeof(NameAndIndex),
                        upname_compareRows, &cmp,
                        TRUE, pErrorCode);
         if(U_FAILURE(*pErrorCode)) {
-            udata_printError(ds, "upname_swap(NameToEnum).uprv_sortArray(%d items) failed - %s\n",
-                             tempMap->count, u_errorName(*pErrorCode));
+            udata_printError(ds, "upname_swap(NameToEnum).uprv_sortArray(%d items) failed\n",
+                             tempMap->count);
             return 0;
         }
 
@@ -596,8 +598,6 @@ PropertyAliases::swap(const UDataSwapper *ds,
     ValueMap *outValueMaps;
     ValueMap valueMap;
 
-    uint8_t *temp;
-
     int32_t i;
 
     inAliases=(const PropertyAliases *)inBytes;
@@ -645,26 +645,25 @@ PropertyAliases::swap(const UDataSwapper *ds,
          *     resort strings in name->enum maps
          * swap value maps
          */
-        temp=(uint8_t *)uprv_malloc(aliases.total_size);
-        if(temp==NULL) {
+        LocalMemory<uint8_t> temp;
+        if(temp.allocateInsteadAndReset(aliases.total_size)==NULL) {
             udata_printError(ds, "upname_swap(): unable to allocate temp memory (%d bytes)\n",
                              aliases.total_size);
             *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
             return 0;
         }
-        uprv_memset(temp, 0, aliases.total_size);
 
         /* swap properties->name groups map */
         NonContiguousEnumToOffset::swap(ds, inBytes, length, outBytes,
-                                        temp, aliases.enumToName_offset, pErrorCode);
+                                        temp.getAlias(), aliases.enumToName_offset, pErrorCode);
 
         /* swap name->properties map */
         NameToEnum::swap(ds, inBytes, length, outBytes,
-                         temp, aliases.nameToEnum_offset, pErrorCode);
+                         temp.getAlias(), aliases.nameToEnum_offset, pErrorCode);
 
         /* swap properties->value maps map */
         NonContiguousEnumToOffset::swap(ds, inBytes, length, outBytes,
-                                        temp, aliases.enumToValue_offset, pErrorCode);
+                                        temp.getAlias(), aliases.enumToValue_offset, pErrorCode);
 
         /* enumerate all ValueMaps and swap them */
         inValueMaps=(const ValueMap *)(inBytes+aliases.valueMap_offset);
@@ -677,16 +676,16 @@ PropertyAliases::swap(const UDataSwapper *ds,
 
             if(valueMap.enumToName_offset!=0) {
                 EnumToOffset::swap(ds, inBytes, length, outBytes,
-                                   temp, valueMap.enumToName_offset,
+                                   temp.getAlias(), valueMap.enumToName_offset,
                                    pErrorCode);
             } else if(valueMap.ncEnumToName_offset!=0) {
                 NonContiguousEnumToOffset::swap(ds, inBytes, length, outBytes,
-                                                temp, valueMap.ncEnumToName_offset,
+                                                temp.getAlias(), valueMap.ncEnumToName_offset,
                                                 pErrorCode);
             }
             if(valueMap.nameToEnum_offset!=0) {
                 NameToEnum::swap(ds, inBytes, length, outBytes,
-                                 temp, valueMap.nameToEnum_offset,
+                                 temp.getAlias(), valueMap.nameToEnum_offset,
                                  pErrorCode);
             }
         }
@@ -696,9 +695,6 @@ PropertyAliases::swap(const UDataSwapper *ds,
                            outValueMaps, pErrorCode);
 
         /* name groups and strings were swapped above */
-
-        /* release temp */
-        uprv_free(temp);
     }
 
     return aliases.total_size;