ICU-3491 remove extra calls to u_init(), and simplify the API comments for u_init().

X-SVN-Rev: 26279
This commit is contained in:
Andy Heninger 2009-07-09 22:50:01 +00:00
parent 6bcaf05997
commit 49db0e1ead
10 changed files with 43 additions and 54 deletions

View file

@ -1,6 +1,6 @@
/*
*******************************************************************************
* Copyright (C) 1997-2008, International Business Machines Corporation and *
* Copyright (C) 1997-2009, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*
@ -378,7 +378,6 @@ BreakIterator::createInstance(const Locale& loc, int32_t kind, UErrorCode& statu
return NULL;
}
u_init(&status);
#if !UCONFIG_NO_SERVICE
if (hasService()) {
Locale actualLoc("");

View file

@ -1523,6 +1523,10 @@ getCaseProps() {
* do not have a service object and also do not have an error code parameter.
* Other API implementations get the singleton themselves
* (with mutexing), store it in the service object, and report errors.
*
* TODO: Remove this support for non-hardcoded data. u_init() is publicly
* advertised as not being required for thread safety, we cannot
* revert to unsafe data loading.
*/
#if !UCASE_HARDCODE_DATA
#define GET_CASE_PROPS() (gCsp!=NULL ? gCsp : getCaseProps())

View file

@ -92,6 +92,11 @@ u_init(UErrorCode *status) {
* initialization had occurred).
*/
/* TODO: Completely remove this section. u_init() is now publicly being
* advertised as never being required for thread safety, and we cannot
* bring back this requirement.
*/
/* Char Properties */
uprv_haveProperties(status);

View file

@ -1,7 +1,7 @@
/*
******************************************************************************
*
* Copyright (C) 1997-2008, International Business Machines
* Copyright (C) 1997-2009, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
@ -504,8 +504,8 @@ u_setMutexFunctions(const void *context, UMtxInitFn *i, UMtxFn *d, UMtxFn *l, UM
pMutexUnlockFn = u;
gMutexContext = context;
gGlobalMutex = NULL; /* For POSIX, the global mutex will be pre-initialized */
/* Undo that, force re-initialization when u_init() */
/* happens. */
/* Undo that, force re-initialization on first use */
/* of the global mutex. */
}

View file

@ -1,7 +1,7 @@
/*
******************************************************************************
* *
* Copyright (C) 2001-2005, International Business Machines *
* Copyright (C) 2001-2009, International Business Machines *
* Corporation and others. All Rights Reserved. *
* *
******************************************************************************
@ -24,38 +24,22 @@
*/
/**
* Initialize ICU. The description further below applies to ICU 2.6 to ICU 3.4.
* Starting with ICU 3.4, u_init() needs not be called any more for
* ensuring thread safety, but it can give an indication for whether ICU
* can load its data. In ICU 3.4, it will try to load the converter alias table
* (cnvalias.icu) and give an error code if that fails.
* This may change in the future.
* <p>
* For ensuring the availability of necessary data, an application should
* open the service objects (converters, collators, etc.) that it will use
* and check for error codes there.
* <p>
* Documentation for ICU 2.6 to ICU 3.4:
* <p>
* This function loads and initializes data items
* that are required internally by various ICU functions. Use of this explicit
* initialization is required in multi-threaded applications; in
* single threaded apps, use is optional, but incurs little additional
* cost, and is thus recommended.
* <p>
* In multi-threaded applications, u_init() should be called in the
* main thread before starting additional threads, or, alternatively
* it can be called in each individual thread once, before other ICU
* functions are called in that thread. In this second scenario, the
* application must guarantee that the first call to u_init() happen
* without contention, in a single thread only.
* <p>
* If <code>u_setMemoryFunctions()</code> or
* <code>u_setMutexFunctions</code> are needed (uncommon), they must be
* called _before_ <code>u_init()</code>.
* <p>
* Extra, repeated, or otherwise unneeded calls to u_init() do no harm,
* other than taking a small amount of time.
* Initialize ICU.
*
* Use of this function is optional. It is OK to simply use ICU
* services and functions without first having initialized
* ICU by calling u_init().
*
* u_init() will attempt to load some part of ICU's data, and is
* useful as a test for configuration or installation problems that
* leave the ICU data inaccessible. A successful invocation of u_init()
* does not, however, guarantee that all ICU data is accessible.
*
* Multiple calls to u_init() cause no harm, aside from the small amount
* of time required.
*
* In old versions of ICU, u_init() was required in multi-threaded applications
* to ensure the thread safety of ICU. u_init() is no longer needed for this purpose.
*
* @param status An ICU UErrorCode parameter. It must not be <code>NULL</code>.
* An Error will be returned if some required part of ICU data can not

View file

@ -1,7 +1,7 @@
/*
******************************************************************************
*
* Copyright (C) 1999-2008, International Business Machines
* Copyright (C) 1999-2009, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
@ -373,8 +373,8 @@ typedef enum UDataFileAccess {
/**
* This function may be called to control how ICU loads data. It must be called
* before any ICU data is loaded, including application data loaded with ures/ResourceBundle or
* udata APIs. It should be called before u_init. This function is not multithread safe.
* before any ICU data is loaded, including application data loaded with
* ures/ResourceBundle or udata APIs. This function is not multithread safe.
* The results of calling it while other threads are loading data are undefined.
* @param access The type of file access to be used
* @param status Error code.

View file

@ -1,6 +1,6 @@
/*
******************************************************************************
* Copyright (c) 1996-2008, International Business Machines
* Copyright (c) 1996-2009, International Business Machines
* Corporation and others. All Rights Reserved.
******************************************************************************
* File unorm.cpp
@ -290,6 +290,10 @@ loadNormData(UErrorCode &errorCode) {
* - they are not usually used in execution paths that are
* as performance-sensitive as others
* (e.g., IDNA takes more time than unorm_quickCheck() anyway)
*
* TODO: Remove code in support for non-hardcoded data. u_init() is now advertised
* as not being required for thread safety, and we can't reasonably
* revert to requiring it.
*/
if(haveNormData==0) {
UTrie _normTrie={ 0,0,0,0,0,0,0 }, _fcdTrie={ 0,0,0,0,0,0,0 }, _auxTrie={ 0,0,0,0,0,0,0 };

View file

@ -1,6 +1,6 @@
/*
**********************************************************************
* Copyright (C) 1999-2008, International Business Machines
* Copyright (C) 1999-2009, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* file name: ustr_imp.h
@ -53,8 +53,7 @@ u_strcmpFold(const UChar *s1, int32_t length1,
* Are the Unicode properties loaded?
* This must be used before internal functions are called that do
* not perform this check.
* Generate a debug assertion failure if data is not loaded, to flag the fact
* that u_init() wasn't called first, before trying to access character properties.
* Generate a debug assertion failure if data is not loaded.
* @internal
*/
U_CFUNC UBool

View file

@ -3,7 +3,7 @@
//
/*
***************************************************************************
* Copyright (C) 2002-2008 International Business Machines Corporation *
* Copyright (C) 2002-2009 International Business Machines Corporation *
* and others. All rights reserved. *
***************************************************************************
*/
@ -30,8 +30,8 @@ U_NAMESPACE_BEGIN
//--------------------------------------------------------------------------
RegexPattern::RegexPattern() {
UErrorCode status = U_ZERO_ERROR;
u_init(&status);
// Init all of this instances data.
// Init all of this instance's data.
init();
// Lazy init of all shared global sets.

View file

@ -329,7 +329,6 @@ ucol_open(const char *loc,
UTRACE_DATA1(UTRACE_INFO, "locale = \"%s\"", loc);
UCollator *result = NULL;
u_init(status);
#if !UCONFIG_NO_SERVICE
result = Collator::createUCollator(loc, status);
if (result == NULL)
@ -357,11 +356,6 @@ ucol_openRules( const UChar *rules,
return 0;
}
u_init(status);
if (U_FAILURE(*status)) {
return NULL;
}
if(rules == NULL || rulesLength < -1) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
return 0;