X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/57a6839dcb3bba09e8228b822b290604668416fe..277af7082f210d5fa7e37ce63392ac8568371616:/icuSources/common/ucnv_bld.cpp diff --git a/icuSources/common/ucnv_bld.cpp b/icuSources/common/ucnv_bld.cpp index 4940310f..fe9684d9 100644 --- a/icuSources/common/ucnv_bld.cpp +++ b/icuSources/common/ucnv_bld.cpp @@ -1,11 +1,11 @@ /* ******************************************************************** * COPYRIGHT: - * Copyright (c) 1996-2013, International Business Machines Corporation and + * Copyright (c) 1996-2016, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************** * - * uconv_bld.cpp: + * ucnv_bld.cpp: * * Defines functions that are used in the creation/initialization/deletion * of converters and related structures. @@ -64,33 +64,51 @@ converterData[UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES]={ #endif &_Latin1Data, - &_UTF8Data, &_UTF16BEData, &_UTF16LEData, &_UTF32BEData, &_UTF32LEData, + &_UTF8Data, &_UTF16BEData, &_UTF16LEData, +#if UCONFIG_ONLY_HTML_CONVERSION + NULL, NULL, +#else + &_UTF32BEData, &_UTF32LEData, +#endif NULL, #if UCONFIG_NO_LEGACY_CONVERSION NULL, +#else + &_ISO2022Data, +#endif + +#if UCONFIG_NO_LEGACY_CONVERSION || UCONFIG_ONLY_HTML_CONVERSION NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, #else - &_ISO2022Data, &_LMBCSData1,&_LMBCSData2, &_LMBCSData3, &_LMBCSData4, &_LMBCSData5, &_LMBCSData6, &_LMBCSData8,&_LMBCSData11,&_LMBCSData16,&_LMBCSData17,&_LMBCSData18,&_LMBCSData19, &_HZData, #endif +#if UCONFIG_ONLY_HTML_CONVERSION + NULL, +#else &_SCSUData, +#endif -#if UCONFIG_NO_LEGACY_CONVERSION + +#if UCONFIG_NO_LEGACY_CONVERSION || UCONFIG_ONLY_HTML_CONVERSION NULL, #else &_ISCIIData, #endif &_ASCIIData, +#if UCONFIG_ONLY_HTML_CONVERSION + NULL, NULL, &_UTF16Data, NULL, NULL, NULL, +#else &_UTF7Data, &_Bocu1Data, &_UTF16Data, &_UTF32Data, &_CESU8Data, &_IMAPData, +#endif -#if UCONFIG_NO_LEGACY_CONVERSION +#if UCONFIG_NO_LEGACY_CONVERSION || UCONFIG_ONLY_HTML_CONVERSION NULL, #else &_CompoundTextData @@ -105,18 +123,24 @@ static struct { const char *name; const UConverterType type; } const cnvNameType[] = { +#if !UCONFIG_ONLY_HTML_CONVERSION { "bocu1", UCNV_BOCU1 }, { "cesu8", UCNV_CESU8 }, -#if !UCONFIG_NO_LEGACY_CONVERSION +#endif +#if !UCONFIG_NO_LEGACY_CONVERSION && !UCONFIG_ONLY_HTML_CONVERSION { "hz",UCNV_HZ }, #endif +#if !UCONFIG_ONLY_HTML_CONVERSION { "imapmailboxname", UCNV_IMAP_MAILBOX }, -#if !UCONFIG_NO_LEGACY_CONVERSION +#endif +#if !UCONFIG_NO_LEGACY_CONVERSION && !UCONFIG_ONLY_HTML_CONVERSION { "iscii", UCNV_ISCII }, +#endif +#if !UCONFIG_NO_LEGACY_CONVERSION { "iso2022", UCNV_ISO_2022 }, #endif { "iso88591", UCNV_LATIN_1 }, -#if !UCONFIG_NO_LEGACY_CONVERSION +#if !UCONFIG_NO_LEGACY_CONVERSION && !UCONFIG_ONLY_HTML_CONVERSION { "lmbcs1", UCNV_LMBCS_1 }, { "lmbcs11",UCNV_LMBCS_11 }, { "lmbcs16",UCNV_LMBCS_16 }, @@ -130,7 +154,9 @@ static struct { { "lmbcs6", UCNV_LMBCS_6 }, { "lmbcs8", UCNV_LMBCS_8 }, #endif +#if !UCONFIG_ONLY_HTML_CONVERSION { "scsu", UCNV_SCSU }, +#endif { "usascii", UCNV_US_ASCII }, { "utf16", UCNV_UTF16 }, { "utf16be", UCNV_UTF16_BigEndian }, @@ -142,6 +168,7 @@ static struct { { "utf16oppositeendian", UCNV_UTF16_BigEndian}, { "utf16platformendian", UCNV_UTF16_LittleEndian }, #endif +#if !UCONFIG_ONLY_HTML_CONVERSION { "utf32", UCNV_UTF32 }, { "utf32be", UCNV_UTF32_BigEndian }, { "utf32le", UCNV_UTF32_LittleEndian }, @@ -152,9 +179,14 @@ static struct { { "utf32oppositeendian", UCNV_UTF32_BigEndian }, { "utf32platformendian", UCNV_UTF32_LittleEndian }, #endif +#endif +#if !UCONFIG_ONLY_HTML_CONVERSION { "utf7", UCNV_UTF7 }, +#endif { "utf8", UCNV_UTF8 }, +#if !UCONFIG_ONLY_HTML_CONVERSION { "x11compoundtext", UCNV_COMPOUND_TEXT} +#endif }; @@ -260,6 +292,7 @@ ucnv_data_unFlattenClone(UConverterLoadArgs *pArgs, UDataMemory *pData, UErrorCo if( (uint16_t)type >= UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES || converterData[type] == NULL || + !converterData[type]->isReferenceCounted || converterData[type]->referenceCounter != 1 || source->structSize != sizeof(UConverterStaticData)) { @@ -276,26 +309,6 @@ ucnv_data_unFlattenClone(UConverterLoadArgs *pArgs, UDataMemory *pData, UErrorCo /* copy initial values from the static structure for this type */ uprv_memcpy(data, converterData[type], sizeof(UConverterSharedData)); -#if 0 /* made UConverterMBCSTable part of UConverterSharedData -- markus 20031107 */ - /* - * It would be much more efficient if the table were a direct member, not a pointer. - * However, that would add to the size of all UConverterSharedData objects - * even if they do not use this table (especially algorithmic ones). - * If this changes, then the static templates from converterData[type] - * need more entries. - * - * In principle, it would be cleaner if the load() function below - * allocated the table. - */ - data->table = (UConverterTable *)uprv_malloc(sizeof(UConverterTable)); - if(data->table == NULL) { - uprv_free(data); - *status = U_MEMORY_ALLOCATION_ERROR; - return NULL; - } - uprv_memset(data->table, 0, sizeof(UConverterTable)); -#endif - data->staticData = source; data->sharedDataCached = FALSE; @@ -306,7 +319,6 @@ ucnv_data_unFlattenClone(UConverterLoadArgs *pArgs, UDataMemory *pData, UErrorCo if(data->impl->load != NULL) { data->impl->load(data, pArgs, raw + source->structSize, status); if(U_FAILURE(*status)) { - uprv_free(data->table); uprv_free(data); return NULL; } @@ -373,7 +385,7 @@ getAlgorithmicTypeFromName(const char *realName) /* do a binary search for the alias */ start = 0; - limit = sizeof(cnvNameType)/sizeof(cnvNameType[0]); + limit = UPRV_LENGTHOF(cnvNameType); mid = limit; lastMid = UINT32_MAX; @@ -510,25 +522,6 @@ ucnv_deleteSharedConverterData(UConverterSharedData * deadSharedData) udata_close(data); } - if(deadSharedData->table != NULL) - { - uprv_free(deadSharedData->table); - } - -#if 0 - /* if the static data is actually owned by the shared data */ - /* enable if we ever have this situation. */ - if(deadSharedData->staticDataOwned == TRUE) /* see ucnv_bld.h */ - { - uprv_free((void*)deadSharedData->staticData); - } -#endif - -#if 0 - /* Zap it ! */ - uprv_memset(deadSharedData->0, sizeof(*deadSharedData)); -#endif - uprv_free(deadSharedData); UTRACE_EXIT_VALUE((int32_t)TRUE); @@ -579,7 +572,7 @@ ucnv_load(UConverterLoadArgs *pArgs, UErrorCode *err) { /** * Unload a non-algorithmic converter. - * It must be sharedData->referenceCounter != ~0 + * It must be sharedData->isReferenceCounted * and this function must be called inside umtx_lock(&cnvCacheMutex). */ U_CAPI void @@ -598,12 +591,7 @@ ucnv_unload(UConverterSharedData *sharedData) { U_CFUNC void ucnv_unloadSharedDataIfReady(UConverterSharedData *sharedData) { - /* - Checking whether it's an algorithic converter is okay - in multithreaded applications because the value never changes. - Don't check referenceCounter for any other value. - */ - if(sharedData != NULL && sharedData->referenceCounter != (uint32_t)~0) { + if(sharedData != NULL && sharedData->isReferenceCounted) { umtx_lock(&cnvCacheMutex); ucnv_unload(sharedData); umtx_unlock(&cnvCacheMutex); @@ -613,12 +601,7 @@ ucnv_unloadSharedDataIfReady(UConverterSharedData *sharedData) U_CFUNC void ucnv_incrementRefCount(UConverterSharedData *sharedData) { - /* - Checking whether it's an algorithic converter is okay - in multithreaded applications because the value never changes. - Don't check referenceCounter for any other value. - */ - if(sharedData != NULL && sharedData->referenceCounter != (uint32_t)~0) { + if(sharedData != NULL && sharedData->isReferenceCounted) { umtx_lock(&cnvCacheMutex); sharedData->referenceCounter++; umtx_unlock(&cnvCacheMutex); @@ -908,12 +891,7 @@ ucnv_createAlgorithmicConverter(UConverter *myUConverter, } sharedData = converterData[type]; - /* - Checking whether it's an algorithic converter is okay - in multithreaded applications because the value never changes. - Don't check referenceCounter for any other value. - */ - if(sharedData == NULL || sharedData->referenceCounter != (uint32_t)~0) { + if(sharedData == NULL || sharedData->isReferenceCounted) { /* not a valid type, or not an algorithmic converter */ *err = U_ILLEGAL_ARGUMENT_ERROR; UTRACE_EXIT_STATUS(U_ILLEGAL_ARGUMENT_ERROR); @@ -1086,7 +1064,7 @@ ucnv_flushCache () i = 0; do { remaining = 0; - pos = -1; + pos = UHASH_FIRST; while ((e = uhash_nextElement (SHARED_DATA_HASHTABLE, &pos)) != NULL) { mySharedData = (UConverterSharedData *) e->value.pointer;