From 530bad0b79e2cef910b466ac4033d0bf05f421bd Mon Sep 17 00:00:00 2001 From: Shane Carr Date: Thu, 3 May 2018 06:50:50 +0000 Subject: [PATCH] ICU-13676 Enabling cleanup of default converter whenever the default converter is put back into the global singleton cache. X-SVN-Rev: 41314 --- icu4c/source/common/ucnv_bld.cpp | 11 ++++++++--- icu4c/source/common/ucnv_bld.h | 3 +++ icu4c/source/common/ustr_cnv.cpp | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/icu4c/source/common/ucnv_bld.cpp b/icu4c/source/common/ucnv_bld.cpp index 14de21bd739..7596687435d 100644 --- a/icu4c/source/common/ucnv_bld.cpp +++ b/icu4c/source/common/ucnv_bld.cpp @@ -261,6 +261,11 @@ static UBool U_CALLCONV ucnv_cleanup(void) { return (SHARED_DATA_HASHTABLE == NULL); } +U_CAPI void U_EXPORT2 +ucnv_enableCleanup() { + ucln_common_registerCleanup(UCLN_COMMON_UCNV, ucnv_cleanup); +} + static UBool U_CALLCONV isCnvAcceptable(void * /*context*/, const char * /*type*/, const char * /*name*/, @@ -439,7 +444,7 @@ ucnv_shareConverterData(UConverterSharedData * data) SHARED_DATA_HASHTABLE = uhash_openSize(uhash_hashChars, uhash_compareChars, NULL, ucnv_io_countKnownConverters(&err)*UCNV_CACHE_LOAD_FACTOR, &err); - ucln_common_registerCleanup(UCLN_COMMON_UCNV, ucnv_cleanup); + ucnv_enableCleanup(); if (U_FAILURE(err)) return; @@ -1099,7 +1104,7 @@ static void U_CALLCONV initAvailableConvertersList(UErrorCode &errCode) { U_ASSERT(gAvailableConverterCount == 0); U_ASSERT(gAvailableConverters == NULL); - ucln_common_registerCleanup(UCLN_COMMON_UCNV, ucnv_cleanup); + ucnv_enableCleanup(); UEnumeration *allConvEnum = ucnv_openAllNames(&errCode); int32_t allConverterCount = uenum_count(allConvEnum, &errCode); if (U_FAILURE(errCode)) { @@ -1205,7 +1210,7 @@ internalSetName(const char *name, UErrorCode *status) { // -- Andy gDefaultConverterName = gDefaultConverterNameBuffer; - ucln_common_registerCleanup(UCLN_COMMON_UCNV, ucnv_cleanup); + ucnv_enableCleanup(); umtx_unlock(&cnvCacheMutex); } diff --git a/icu4c/source/common/ucnv_bld.h b/icu4c/source/common/ucnv_bld.h index a1e2df6730c..18b3795e4d8 100644 --- a/icu4c/source/common/ucnv_bld.h +++ b/icu4c/source/common/ucnv_bld.h @@ -288,6 +288,9 @@ ucnv_swap(const UDataSwapper *ds, const void *inData, int32_t length, void *outData, UErrorCode *pErrorCode); +U_CAPI void U_EXPORT2 +ucnv_enableCleanup(); + #endif #endif /* _UCNV_BLD */ diff --git a/icu4c/source/common/ustr_cnv.cpp b/icu4c/source/common/ustr_cnv.cpp index 38f4d82105c..97c78bfaca9 100644 --- a/icu4c/source/common/ustr_cnv.cpp +++ b/icu4c/source/common/ustr_cnv.cpp @@ -28,6 +28,7 @@ #include "cmemory.h" #include "umutex.h" #include "ustr_cnv.h" +#include "ucnv_bld.h" /* mutexed access to a shared default converter ----------------------------- */ @@ -68,8 +69,8 @@ u_releaseDefaultConverter(UConverter *converter) if (converter != NULL) { ucnv_reset(converter); } + ucnv_enableCleanup(); umtx_lock(NULL); - if(gDefaultConverter == NULL) { gDefaultConverter = converter; converter = NULL; -- 2.40.0