From 8ee4058f62f48d27081e18a7ef2caff271130b6a Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Tue, 7 Apr 2009 18:31:32 +0000 Subject: [PATCH] ICU-6441 bug fix in ucnv_bld.c: don't ucnv_close() if onlyTestIsLoadable; and simplify code by dropping isLoadable result and using UErrorCode instead X-SVN-Rev: 25741 --- icu4c/source/common/ucnv2022.c | 9 ++------- icu4c/source/common/ucnv_bld.c | 9 ++++----- icu4c/source/common/ucnv_cnv.h | 2 +- icu4c/source/common/ucnv_lmb.c | 7 +------ icu4c/source/common/ucnv_u16.c | 27 +++++++++------------------ icu4c/source/common/ucnv_u32.c | 6 +----- icu4c/source/common/ucnv_u7.c | 7 +++---- icu4c/source/common/ucnvhz.c | 3 +-- icu4c/source/common/ucnvisci.c | 1 - icu4c/source/common/ucnvmbcs.c | 2 -- icu4c/source/common/ucnvscsu.c | 1 - 11 files changed, 22 insertions(+), 52 deletions(-) diff --git a/icu4c/source/common/ucnv2022.c b/icu4c/source/common/ucnv2022.c index ea22880f543..41334d9e902 100644 --- a/icu4c/source/common/ucnv2022.c +++ b/icu4c/source/common/ucnv2022.c @@ -518,8 +518,7 @@ _ISO2022Open(UConverter *cnv, UConverterLoadArgs *pArgs, UErrorCode *errorCode){ myConverterData->version=version=0; } if(pArgs->onlyTestIsLoadable) { - UErrorCode localStatus=U_ZERO_ERROR; - pArgs->isLoadable=ucnv_canCreateConverter(cnvName, &localStatus); + ucnv_canCreateConverter(cnvName, errorCode); /* errorCode carries result */ uprv_free(cnv->extraInfo); cnv->extraInfo=NULL; return; @@ -594,13 +593,9 @@ _ISO2022Open(UConverter *cnv, UConverterLoadArgs *pArgs, UErrorCode *errorCode){ cnv->maxBytesPerUChar=cnv->sharedData->staticData->maxBytesPerChar; - if(U_FAILURE(*errorCode)) { + if(U_FAILURE(*errorCode) || pArgs->onlyTestIsLoadable) { _ISO2022Close(cnv); } - if(pArgs->onlyTestIsLoadable) { - _ISO2022Close(cnv); - pArgs->isLoadable=TRUE; - } } else { *errorCode = U_MEMORY_ALLOCATION_ERROR; } diff --git a/icu4c/source/common/ucnv_bld.c b/icu4c/source/common/ucnv_bld.c index 05c4b6966b3..d0ed7d3ece2 100644 --- a/icu4c/source/common/ucnv_bld.c +++ b/icu4c/source/common/ucnv_bld.c @@ -874,7 +874,7 @@ ucnv_canCreateConverter(const char *converterName, UErrorCode *err) { } UTRACE_EXIT_STATUS(*err); - return U_SUCCESS(*err) && stackArgs.isLoadable; + return U_SUCCESS(*err); } UConverter * @@ -1016,11 +1016,10 @@ ucnv_createConverterFromSharedData(UConverter *myUConverter, myUConverter->toUCallbackReason = UCNV_ILLEGAL; /* default reason to invoke (*fromCharErrorBehaviour) */ } - if(mySharedConverterData->impl->open == NULL) { - pArgs->isLoadable = pArgs->onlyTestIsLoadable; - } else { + if(mySharedConverterData->impl->open != NULL) { mySharedConverterData->impl->open(myUConverter, pArgs, err); - if(U_FAILURE(*err)) { + if(U_FAILURE(*err) && !pArgs->onlyTestIsLoadable) { + /* don't ucnv_close() if onlyTestIsLoadable because not fully initialized */ ucnv_close(myUConverter); return NULL; } diff --git a/icu4c/source/common/ucnv_cnv.h b/icu4c/source/common/ucnv_cnv.h index 0163f5eab4f..cba24d06c51 100644 --- a/icu4c/source/common/ucnv_cnv.h +++ b/icu4c/source/common/ucnv_cnv.h @@ -50,7 +50,7 @@ typedef struct { int32_t size; /* sizeof(UConverterLoadArgs) */ int32_t nestedLoads; /* count nested ucnv_load() calls */ UBool onlyTestIsLoadable; /* input: don't actually load */ - UBool isLoadable; /* output, if onlyTestIsLoadable is set */ + UBool reserved0; /* reserved - for good alignment of the pointers */ int16_t reserved; /* reserved - for good alignment of the pointers */ uint32_t options; const char *pkg, *name, *locale; diff --git a/icu4c/source/common/ucnv_lmb.c b/icu4c/source/common/ucnv_lmb.c index ecdd376ac06..db9aa808a85 100644 --- a/icu4c/source/common/ucnv_lmb.c +++ b/icu4c/source/common/ucnv_lmb.c @@ -588,15 +588,10 @@ _LMBCSOpenWorker(UConverter* _this, } } - if(U_FAILURE(*err)) { + if(U_FAILURE(*err) || pArgs->onlyTestIsLoadable) { _LMBCSClose(_this); return; } - if(pArgs->onlyTestIsLoadable) { - _LMBCSClose(_this); - pArgs->isLoadable=TRUE; - return; - } extraInfo->OptGroup = OptGroup; extraInfo->localeConverterIndex = FindLMBCSLocale(pArgs->locale); } diff --git a/icu4c/source/common/ucnv_u16.c b/icu4c/source/common/ucnv_u16.c index 1c3c1f79595..b54b07d7770 100644 --- a/icu4c/source/common/ucnv_u16.c +++ b/icu4c/source/common/ucnv_u16.c @@ -585,13 +585,10 @@ static void _UTF16BEOpen(UConverter *cnv, UConverterLoadArgs *pArgs, UErrorCode *pErrorCode) { - if(pArgs->onlyTestIsLoadable) { - pArgs->isLoadable=TRUE; - } else { - if(UCNV_GET_VERSION(cnv)>1) { - cnv->options=0; - } + if(UCNV_GET_VERSION(cnv)<=1) { _UTF16BEReset(cnv, UCNV_RESET_BOTH); + } else { + *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; } } @@ -1187,13 +1184,10 @@ static void _UTF16LEOpen(UConverter *cnv, UConverterLoadArgs *pArgs, UErrorCode *pErrorCode) { - if(pArgs->onlyTestIsLoadable) { - pArgs->isLoadable=TRUE; - } else { - if(UCNV_GET_VERSION(cnv)>1) { - cnv->options=0; - } + if(UCNV_GET_VERSION(cnv)<=1) { _UTF16LEReset(cnv, UCNV_RESET_BOTH); + } else { + *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; } } @@ -1289,13 +1283,10 @@ static void _UTF16Open(UConverter *cnv, UConverterLoadArgs *pArgs, UErrorCode *pErrorCode) { - if(pArgs->onlyTestIsLoadable) { - pArgs->isLoadable=TRUE; - } else { - if(UCNV_GET_VERSION(cnv)>1) { - cnv->options=0; - } + if(UCNV_GET_VERSION(cnv)<=1) { _UTF16Reset(cnv, UCNV_RESET_BOTH); + } else { + *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; } } diff --git a/icu4c/source/common/ucnv_u32.c b/icu4c/source/common/ucnv_u32.c index 654990ff7a9..f76b9b04eda 100644 --- a/icu4c/source/common/ucnv_u32.c +++ b/icu4c/source/common/ucnv_u32.c @@ -1035,11 +1035,7 @@ static void _UTF32Open(UConverter *cnv, UConverterLoadArgs *pArgs, UErrorCode *pErrorCode) { - if(pArgs->onlyTestIsLoadable) { - pArgs->isLoadable=TRUE; - } else { - _UTF32Reset(cnv, UCNV_RESET_BOTH); - } + _UTF32Reset(cnv, UCNV_RESET_BOTH); } static const char utf32BOM[8]={ 0, 0, (char)0xfe, (char)0xff, (char)0xff, (char)0xfe, 0, 0 }; diff --git a/icu4c/source/common/ucnv_u7.c b/icu4c/source/common/ucnv_u7.c index a540f8f0688..8ef36050ddf 100644 --- a/icu4c/source/common/ucnv_u7.c +++ b/icu4c/source/common/ucnv_u7.c @@ -192,10 +192,9 @@ static void _UTF7Open(UConverter *cnv, UConverterLoadArgs *pArgs, UErrorCode *pErrorCode) { - if(pArgs->onlyTestIsLoadable) { - pArgs->isLoadable=TRUE; - } else if((pArgs->options&0xf)<=1) { - cnv->fromUnicodeStatus=(pArgs->options&0xf)<<28; + if(UCNV_GET_VERSION(cnv)<=1) { + /* TODO(markus): Should just use cnv->options rather than copying the version number. */ + cnv->fromUnicodeStatus=UCNV_GET_VERSION(cnv)<<28; _UTF7Reset(cnv, UCNV_RESET_BOTH); } else { *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; diff --git a/icu4c/source/common/ucnvhz.c b/icu4c/source/common/ucnvhz.c index 16e3fb24ced..074b4f4a5f3 100644 --- a/icu4c/source/common/ucnvhz.c +++ b/icu4c/source/common/ucnvhz.c @@ -69,8 +69,7 @@ static void _HZOpen(UConverter *cnv, UConverterLoadArgs *pArgs, UErrorCode *errorCode){ UConverter *gbConverter; if(pArgs->onlyTestIsLoadable) { - UErrorCode localStatus = U_ZERO_ERROR; - pArgs->isLoadable = ucnv_canCreateConverter("GBK", &localStatus); + ucnv_canCreateConverter("GBK", errorCode); /* errorCode carries result */ return; } gbConverter = ucnv_open("GBK", errorCode); diff --git a/icu4c/source/common/ucnvisci.c b/icu4c/source/common/ucnvisci.c index 1784c8eb823..ece3b5d964b 100644 --- a/icu4c/source/common/ucnvisci.c +++ b/icu4c/source/common/ucnvisci.c @@ -173,7 +173,6 @@ static void initializeSets() { static void _ISCIIOpen(UConverter *cnv, UConverterLoadArgs *pArgs, UErrorCode *errorCode) { if(pArgs->onlyTestIsLoadable) { - pArgs->isLoadable=TRUE; return; } diff --git a/icu4c/source/common/ucnvmbcs.c b/icu4c/source/common/ucnvmbcs.c index a1736fec6a8..068f9e29442 100644 --- a/icu4c/source/common/ucnvmbcs.c +++ b/icu4c/source/common/ucnvmbcs.c @@ -1401,7 +1401,6 @@ ucnv_MBCSLoad(UConverterSharedData *sharedData, args.size=sizeof(UConverterLoadArgs); args.nestedLoads=2; args.onlyTestIsLoadable=pArgs->onlyTestIsLoadable; - args.isLoadable=pArgs->isLoadable; args.reserved=pArgs->reserved; args.options=pArgs->options; args.pkg=pArgs->pkg; @@ -1688,7 +1687,6 @@ ucnv_MBCSOpen(UConverter *cnv, int8_t maxBytesPerUChar; if(pArgs->onlyTestIsLoadable) { - pArgs->isLoadable=TRUE; return; } diff --git a/icu4c/source/common/ucnvscsu.c b/icu4c/source/common/ucnvscsu.c index ac98637f29d..76e973d0598 100644 --- a/icu4c/source/common/ucnvscsu.c +++ b/icu4c/source/common/ucnvscsu.c @@ -194,7 +194,6 @@ _SCSUOpen(UConverter *cnv, UErrorCode *pErrorCode) { const char *locale=pArgs->locale; if(pArgs->onlyTestIsLoadable) { - pArgs->isLoadable=TRUE; return; } cnv->extraInfo=uprv_malloc(sizeof(SCSUData));