mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-6132 Recover from allocation errors more gracefully.
X-SVN-Rev: 23398
This commit is contained in:
parent
f785553c68
commit
3daa4c96d4
7 changed files with 32 additions and 18 deletions
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2004-2007, International Business Machines
|
||||
* Copyright (C) 2004-2008, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
|
@ -17,6 +17,8 @@
|
|||
* Much code moved here (and modified) from uchar.c.
|
||||
*/
|
||||
|
||||
#define UCASE_HARDCODE_DATA 1
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/uset.h"
|
||||
#include "unicode/udata.h" /* UDataInfo */
|
||||
|
@ -41,8 +43,6 @@ struct UCaseProps {
|
|||
|
||||
/* data loading etc. -------------------------------------------------------- */
|
||||
|
||||
#define UCASE_HARDCODE_DATA 1
|
||||
|
||||
#if UCASE_HARDCODE_DATA
|
||||
|
||||
/* ucase_props_data.c is machine-generated by gencase --csource */
|
||||
|
@ -205,23 +205,24 @@ ucase_close(UCaseProps *csp) {
|
|||
|
||||
/* UCaseProps singleton ----------------------------------------------------- */
|
||||
|
||||
static UCaseProps *gCsp=NULL, *gCspDummy=NULL;
|
||||
#if !UCASE_HARDCODE_DATA
|
||||
static UCaseProps *gCsp=NULL;
|
||||
static UCaseProps *gCspDummy=NULL;
|
||||
static UErrorCode gErrorCode=U_ZERO_ERROR;
|
||||
static int8_t gHaveData=0;
|
||||
#endif
|
||||
|
||||
#if !UCASE_HARDCODE_DATA
|
||||
static UBool U_CALLCONV ucase_cleanup(void) {
|
||||
ucase_close(gCsp);
|
||||
gCsp=NULL;
|
||||
ucase_close(gCspDummy);
|
||||
gCspDummy=NULL;
|
||||
#if !UCASE_HARDCODE_DATA
|
||||
gErrorCode=U_ZERO_ERROR;
|
||||
gHaveData=0;
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
U_CAPI const UCaseProps * U_EXPORT2
|
||||
ucase_getSingleton(UErrorCode *pErrorCode) {
|
||||
|
@ -271,6 +272,7 @@ ucase_getSingleton(UErrorCode *pErrorCode) {
|
|||
#endif
|
||||
}
|
||||
|
||||
#if !UCASE_HARDCODE_DATA
|
||||
U_CAPI const UCaseProps * U_EXPORT2
|
||||
ucase_getDummy(UErrorCode *pErrorCode) {
|
||||
UCaseProps *csp;
|
||||
|
@ -322,6 +324,7 @@ ucase_getDummy(UErrorCode *pErrorCode) {
|
|||
return gCspDummy;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* set of property starts for UnicodeSet ------------------------------------ */
|
||||
|
||||
|
@ -1488,6 +1491,7 @@ ucase_toFullFolding(const UCaseProps *csp, UChar32 c,
|
|||
/* case mapping properties API ---------------------------------------------- */
|
||||
|
||||
/* get the UCaseProps singleton, or else its dummy, once and for all */
|
||||
#if !UCASE_HARDCODE_DATA
|
||||
static const UCaseProps *
|
||||
getCaseProps() {
|
||||
/*
|
||||
|
@ -1511,6 +1515,7 @@ getCaseProps() {
|
|||
|
||||
return csp;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* In ICU 3.0, most Unicode properties were loaded from uprops.icu.
|
||||
|
@ -1539,7 +1544,11 @@ getCaseProps() {
|
|||
* Other API implementations get the singleton themselves
|
||||
* (with mutexing), store it in the service object, and report errors.
|
||||
*/
|
||||
#if !UCASE_HARDCODE_DATA
|
||||
#define GET_CASE_PROPS() (gCsp!=NULL ? gCsp : getCaseProps())
|
||||
#else
|
||||
#define GET_CASE_PROPS() &ucase_props_singleton
|
||||
#endif
|
||||
|
||||
/* public API (see uchar.h) */
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2004-2007, International Business Machines
|
||||
* Copyright (C) 2004-2008, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
|
@ -44,6 +44,7 @@ ucase_close(UCaseProps *csp);
|
|||
U_CAPI const UCaseProps * U_EXPORT2
|
||||
ucase_getSingleton(UErrorCode *pErrorCode);
|
||||
|
||||
#if defined(UCASE_HARDCODE_DATA) && !UCASE_HARDCODE_DATA
|
||||
/**
|
||||
* Get a singleton dummy object, one that works with no real data.
|
||||
* This can be used when the real data is not available.
|
||||
|
@ -51,6 +52,7 @@ ucase_getSingleton(UErrorCode *pErrorCode);
|
|||
*/
|
||||
U_CAPI const UCaseProps * U_EXPORT2
|
||||
ucase_getDummy(UErrorCode *pErrorCode);
|
||||
#endif
|
||||
|
||||
|
||||
U_CAPI int32_t U_EXPORT2
|
||||
|
|
|
@ -977,6 +977,9 @@ ucnv_flushCache ()
|
|||
/* Close the default converter without creating a new one so that everything will be flushed. */
|
||||
ucnv_close(u_getDefaultConverter(&status));
|
||||
|
||||
/* Flush now because we may not have any shared data in the hash. */
|
||||
ucnv_flushAvailableConverterCache();
|
||||
|
||||
/*if shared data hasn't even been lazy evaluated yet
|
||||
* return 0
|
||||
*/
|
||||
|
@ -1029,8 +1032,6 @@ ucnv_flushCache ()
|
|||
|
||||
UTRACE_DATA1(UTRACE_INFO, "ucnv_flushCache() exits with %d converters remaining", remaining);
|
||||
|
||||
ucnv_flushAvailableConverterCache();
|
||||
|
||||
UTRACE_EXIT_VALUE(tableDeletedNum);
|
||||
return tableDeletedNum;
|
||||
}
|
||||
|
|
|
@ -1257,7 +1257,7 @@ Transliterator* TransliteratorRegistry::instantiateEntry(const UnicodeString& ID
|
|||
return t;
|
||||
case Entry::COMPOUND_RBT:
|
||||
{
|
||||
UVector* rbts = new UVector(status);
|
||||
UVector* rbts = new UVector(entry->u.dataVector->size(), status);
|
||||
// Check for null pointer
|
||||
if (rbts == NULL) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
|
@ -1272,8 +1272,10 @@ Transliterator* TransliteratorRegistry::instantiateEntry(const UnicodeString& ID
|
|||
else
|
||||
rbts->addElement(t, status);
|
||||
}
|
||||
if (U_FAILURE(status))
|
||||
if (U_FAILURE(status)) {
|
||||
delete rbts;
|
||||
return 0;
|
||||
}
|
||||
aliasReturn = new TransliteratorAlias(ID, entry->stringArg, rbts, entry->compoundFilter);
|
||||
}
|
||||
if (aliasReturn == 0) {
|
||||
|
|
|
@ -634,6 +634,7 @@ error_cleanup:
|
|||
if (metaToOlson != NULL) {
|
||||
delete metaToOlson;
|
||||
}
|
||||
metaToOlson = NULL;
|
||||
goto normal_cleanup;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2007, International Business Machines Corporation and
|
||||
* Copyright (c) 1997-2008, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
/*******************************************************************************
|
||||
|
@ -3054,11 +3054,9 @@ static void TestUCase() {
|
|||
#if !HARDCODED_DATA_4497
|
||||
UDataMemory *pData;
|
||||
UCaseProps *csp;
|
||||
#endif
|
||||
const UCaseProps *ccsp;
|
||||
UErrorCode errorCode;
|
||||
|
||||
#if !HARDCODED_DATA_4497
|
||||
/* coverage for ucase_openBinary() */
|
||||
errorCode=U_ZERO_ERROR;
|
||||
pData=udata_open(NULL, UCASE_DATA_TYPE, UCASE_DATA_NAME, &errorCode);
|
||||
|
@ -3082,7 +3080,6 @@ static void TestUCase() {
|
|||
|
||||
ucase_close(csp);
|
||||
udata_close(pData);
|
||||
#endif
|
||||
|
||||
/* coverage for ucase_getDummy() */
|
||||
errorCode=U_ZERO_ERROR;
|
||||
|
@ -3090,6 +3087,7 @@ static void TestUCase() {
|
|||
if(ucase_tolower(ccsp, 0x41)!=0x41) {
|
||||
log_err("ucase_tolower(dummy, A)!=A\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* API coverage for ubidi_props.c */
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2007, International Business Machines Corporation and
|
||||
* Copyright (c) 1997-2008, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
/*******************************************************************************
|
||||
|
@ -5214,12 +5214,13 @@ static void TestJitterbug981(){
|
|||
int numNeeded=0;
|
||||
utf8cnv = ucnv_open ("utf8", &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("Could not open UTF-8 converter. Error: %s", u_errorName(status));
|
||||
log_err("Could not open UTF-8 converter. Error: %s\n", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
myCollator = ucol_open("zh", &status);
|
||||
if(U_FAILURE(status)){
|
||||
log_err("Could not open collator for zh locale. Error: %s", u_errorName(status));
|
||||
log_err("Could not open collator for zh locale. Error: %s\n", u_errorName(status));
|
||||
ucnv_close(utf8cnv);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue