From 78ca2fdfc9a38545a827d1292adfce99ea5801e5 Mon Sep 17 00:00:00 2001 From: Andy Heninger Date: Thu, 14 Aug 2003 21:34:54 +0000 Subject: [PATCH] ICU-3014 Add explicit u_init() calls to tools and tests in anticipation of static init changes X-SVN-Rev: 12826 --- icu4c/source/common/cmemory.c | 10 +-- icu4c/source/common/umutex.c | 79 +++++++++++------------- icu4c/source/common/unicode/uclean.h | 18 +++--- icu4c/source/extra/uconv/uconv.cpp | 10 +++ icu4c/source/test/cintltst/cintltst.c | 55 ++++++++--------- icu4c/source/test/intltest/intltest.cpp | 18 +++--- icu4c/source/tools/genbrk/genbrk.cpp | 9 +++ icu4c/source/tools/genccode/genccode.c | 11 ++++ icu4c/source/tools/gencmn/gencmn.c | 10 +++ icu4c/source/tools/gencnval/gencnval.c | 10 +++ icu4c/source/tools/gennames/gennames.c | 15 +++++ icu4c/source/tools/gennorm/gennorm.c | 14 +++++ icu4c/source/tools/genpname/genpname.cpp | 19 +++++- icu4c/source/tools/genprops/genprops.c | 16 +++++ icu4c/source/tools/genrb/genrb.c | 13 ++++ icu4c/source/tools/gensprep/gensprep.c | 9 +++ icu4c/source/tools/gentest/gentest.c | 11 ++++ icu4c/source/tools/gentz/gentz.cpp | 10 +++ icu4c/source/tools/genuca/genuca.cpp | 10 +++ icu4c/source/tools/makeconv/makeconv.c | 10 +++ icu4c/source/tools/pkgdata/pkgdata.c | 9 +++ 21 files changed, 267 insertions(+), 99 deletions(-) diff --git a/icu4c/source/common/cmemory.c b/icu4c/source/common/cmemory.c index 5e914864474..c6d9125d002 100644 --- a/icu4c/source/common/cmemory.c +++ b/icu4c/source/common/cmemory.c @@ -25,10 +25,10 @@ static const int32_t zeroMem[] = {0, 0, 0, 0, 0, 0}; /* Function Pointers for user-supplied heap functions */ -static const void *pContext; -static UMemAlloc *pAlloc; -static UMemRealloc *pRealloc; -static UMemFree *pFree; +static const void *pContext; +static UMemAllocFn *pAlloc; +static UMemReallocFn *pRealloc; +static UMemFreeFn *pFree; /* Flag indicating whether any heap allocations have happened. * Used to prevent changing out the heap functions after allocations have been made */ @@ -81,7 +81,7 @@ uprv_free(void *buffer) { } U_CAPI void U_EXPORT2 -u_setMemoryFunctions(const void *context, UMemAlloc *a, UMemRealloc *r, UMemFree *f, UErrorCode *status) +u_setMemoryFunctions(const void *context, UMemAllocFn *a, UMemReallocFn *r, UMemFreeFn *f, UErrorCode *status) { if (U_FAILURE(*status)) { return; diff --git a/icu4c/source/common/umutex.c b/icu4c/source/common/umutex.c index fb3fcebd43d..724d4ab3adf 100644 --- a/icu4c/source/common/umutex.c +++ b/icu4c/source/common/umutex.c @@ -70,11 +70,11 @@ static int32_t gRecursionCount = 0; * directly using the system (Posix or Windows) APIs. * (declarations are in uclean.h) */ -static UMtxInit *pMutexInit = NULL; -static UMtxFunc *pMutexDestroy = NULL; -static UMtxFunc *pMutexLock = NULL; -static UMtxFunc *pMutexUnlock = NULL; -static const void *gMutexContext = NULL; +static UMtxInitFn *pMutexInitFn = NULL; +static UMtxFn *pMutexDestroyFn = NULL; +static UMtxFn *pMutexLockFn = NULL; +static UMtxFn *pMutexUnlockFn = NULL; +static const void *gMutexContext = NULL; @@ -97,8 +97,8 @@ umtx_lock(UMTX *mutex) * still do the lazy init to try to avoid a crash */ } - if (pMutexLock != NULL) { - (*pMutexLock)(gMutexContext, mutex); + if (pMutexLockFn != NULL) { + (*pMutexLockFn)(gMutexContext, mutex); } else { #if (ICU_USE_THREADS == 1) @@ -144,8 +144,8 @@ umtx_unlock(UMTX* mutex) } #endif - if (pMutexUnlock) { - (*pMutexUnlock)(gMutexContext, mutex); + if (pMutexUnlockFn) { + (*pMutexUnlockFn)(gMutexContext, mutex); } else { #if (ICU_USE_THREADS==1) #if defined (WIN32) @@ -163,9 +163,9 @@ umtx_unlock(UMTX* mutex) * umtx_raw_init Do the platform specific mutex allocation and initialization */ static void umtx_raw_init(UMTX *mutex) { - if (pMutexInit != NULL) { + if (pMutexInitFn != NULL) { UErrorCode status = U_ZERO_ERROR; - (*pMutexInit)(gMutexContext, mutex, &status); + (*pMutexInitFn)(gMutexContext, mutex, &status); if (U_FAILURE(status)) { /* TODO: how should errors here be handled? */ return; @@ -271,8 +271,8 @@ umtx_destroy(UMTX *mutex) { return; } - if (pMutexDestroy != NULL) { - (*pMutexDestroy)(gMutexContext, mutex); + if (pMutexDestroyFn != NULL) { + (*pMutexDestroyFn)(gMutexContext, mutex); } else { #if (ICU_USE_THREADS == 1) #if defined (WIN32) @@ -297,7 +297,7 @@ umtx_destroy(UMTX *mutex) { U_CAPI void U_EXPORT2 -u_setMutexFunctions(const void *context, UMtxInit *i, UMtxFunc *d, UMtxFunc *l, UMtxFunc *u, +u_setMutexFunctions(const void *context, UMtxInitFn *i, UMtxFn *d, UMtxFn *l, UMtxFn *u, UErrorCode *status) { if (U_FAILURE(*status)) { return; @@ -315,22 +315,13 @@ u_setMutexFunctions(const void *context, UMtxInit *i, UMtxFunc *d, UMtxFunc *l, return; } - /* Destroy the mutexes that C++ static initialization creates */ - u_ICUStaticUnInitFunc(); - /* Swap in the mutex function pointers. */ - pMutexInit = i; - pMutexDestroy = d; - pMutexLock = l; - pMutexUnlock = u; - gMutexContext = context; + pMutexInitFn = i; + pMutexDestroyFn = d; + pMutexLockFn = l; + pMutexUnlockFn = u; + gMutexContext = context; - /* - * Re-do the equivalent of ICU's static initialization, - * which will recreate the default, resource bundle and converter mutexes. - * TODO: remove this when remove all ICU static init. - */ - u_ICUStaticInitFunc(); } @@ -344,16 +335,16 @@ u_setMutexFunctions(const void *context, UMtxInit *i, UMtxFunc *d, UMtxFunc *l, *----------------------------------------------------------------*/ /* Pointers to user-supplied inc/dec functions. Null if not funcs have been set. */ -static UMtxAtomicF *pIncF = NULL; -static UMtxAtomicF *pDecF = NULL; +static UMtxAtomicFn *pIncFn = NULL; +static UMtxAtomicFn *pDecFn = NULL; static void *gIncDecContext; U_CAPI int32_t U_EXPORT2 umtx_atomic_inc(int32_t *p) { int32_t retVal; - if (pIncF) { - retVal = (*pIncF)(gIncDecContext, p); + if (pIncFn) { + retVal = (*pIncFn)(gIncDecContext, p); } else { #if defined (WIN32) && ICU_USE_THREADS == 1 retVal = InterlockedIncrement(p); @@ -373,8 +364,8 @@ umtx_atomic_inc(int32_t *p) { U_CAPI int32_t U_EXPORT2 umtx_atomic_dec(int32_t *p) { int32_t retVal; - if (pDecF) { - retVal = (*pDecF)(gIncDecContext, p); + if (pDecFn) { + retVal = (*pDecFn)(gIncDecContext, p); } else { #if defined (WIN32) && ICU_USE_THREADS == 1 retVal = InterlockedDecrement(p); @@ -398,7 +389,7 @@ umtx_atomic_dec(int32_t *p) { U_CAPI void U_EXPORT2 -u_setAtomicIncDecFunctions(const void *context, UMtxAtomicF *ip, UMtxAtomicF *dp, +u_setAtomicIncDecFunctions(const void *context, UMtxAtomicFn *ip, UMtxAtomicFn *dp, UErrorCode *status) { int32_t testInt; if (U_FAILURE(*status)) { @@ -415,8 +406,8 @@ u_setAtomicIncDecFunctions(const void *context, UMtxAtomicF *ip, UMtxAtomicF *dp return; } - pIncF = ip; - pDecF = dp; + pIncFn = ip; + pDecFn = dp; testInt = 0; U_ASSERT(umtx_atomic_inc(&testInt) == 1); /* Sanity Check. Do the functions work at all? */ @@ -434,14 +425,14 @@ u_setAtomicIncDecFunctions(const void *context, UMtxAtomicF *ip, UMtxAtomicF *dp */ U_CFUNC UBool umtx_cleanup(void) { umtx_destroy(NULL); - pMutexInit = NULL; - pMutexDestroy = NULL; - pMutexLock = NULL; - pMutexUnlock = NULL; - gMutexContext = NULL; + pMutexInitFn = NULL; + pMutexDestroyFn = NULL; + pMutexLockFn = NULL; + pMutexUnlockFn = NULL; + gMutexContext = NULL; - pIncF = NULL; - pDecF = NULL; + pIncFn = NULL; + pDecFn = NULL; return TRUE; } diff --git a/icu4c/source/common/unicode/uclean.h b/icu4c/source/common/unicode/uclean.h index 284b2ebaf69..d4440b94b3c 100644 --- a/icu4c/source/common/unicode/uclean.h +++ b/icu4c/source/common/unicode/uclean.h @@ -114,7 +114,7 @@ typedef void *UMTX; * @param status Error status. Report errors back to ICU by setting this variable * with an error code. */ -typedef void U_CALLCONV UMtxInit (const void *context, UMTX *mutex, UErrorCode* pError); +typedef void U_CALLCONV UMtxInitFn (const void *context, UMTX *mutex, UErrorCode* status); /** @@ -126,7 +126,7 @@ typedef void U_CALLCONV UMtxInit (const void *context, UMTX *mutex, UErrorCod * @draft ICU 2.8 * @system */ -typedef void U_CALLCONV UMtxFunc (const void *context, UMTX *mutex); +typedef void U_CALLCONV UMtxFn (const void *context, UMTX *mutex); /** @@ -147,7 +147,7 @@ typedef void U_CALLCONV UMtxFunc (const void *context, UMTX *mutex); * @system */ U_CAPI void U_EXPORT2 -u_setMutexFunctions(const void *context, UMtxInit *i, UMtxFunc *d, UMtxFunc *l, UMtxFunc *u, +u_setMutexFunctions(const void *context, UMtxInitFn *init, UMtxFn *destroy, UMtxFn *lock, UMtxFn *unlock, UErrorCode *status); @@ -159,7 +159,7 @@ u_setMutexFunctions(const void *context, UMtxInit *i, UMtxFunc *d, UMtxFunc *l, * @draft ICU 2.8 * @system */ -typedef int32_t U_CALLCONV UMtxAtomicF (const void *context, int32_t *p); +typedef int32_t U_CALLCONV UMtxAtomicFn(const void *context, int32_t *p); /** * Set the functions that ICU will use for atomic increment and decrement of int32_t values. @@ -177,7 +177,7 @@ typedef int32_t U_CALLCONV UMtxAtomicF (const void *context, int32_t *p); * @system */ U_CAPI void U_EXPORT2 -u_setAtomicIncDecFunctions(const void *context, UMtxAtomicF *inc, UMtxAtomicF *dec, +u_setAtomicIncDecFunctions(const void *context, UMtxAtomicFn *inc, UMtxAtomicFn *dec, UErrorCode *status); @@ -190,7 +190,7 @@ u_setAtomicIncDecFunctions(const void *context, UMtxAtomicF *inc, UMtxAtomicF *d * @draft ICU 2.8 * @system */ -typedef void *U_CALLCONV UMemAlloc (const void *context, size_t size); +typedef void *U_CALLCONV UMemAllocFn(const void *context, size_t size); /** * Pointer type for a user supplied memory re-allocation function. * @param context user supplied value, obtained from from u_setMemoryFunctions(). @@ -199,7 +199,7 @@ typedef void *U_CALLCONV UMemAlloc (const void *context, size_t size); * @draft ICU 2.8 * @system */ -typedef void *U_CALLCONV UMemRealloc(const void *context, void *mem, size_t size); +typedef void *U_CALLCONV UMemReallocFn(const void *context, void *mem, size_t size); /** * Pointer type for a user supplied memory free function. Behavior should be * similar the standard C library free(). @@ -210,7 +210,7 @@ typedef void *U_CALLCONV UMemRealloc(const void *context, void *mem, size_t size * @draft ICU 2.8 * @system */ -typedef void U_CALLCONV UMemFree (const void *context, void *mem); +typedef void U_CALLCONV UMemFreeFn (const void *context, void *mem); /** * Set the functions that ICU will use for memory allocation. @@ -229,7 +229,7 @@ typedef void U_CALLCONV UMemFree (const void *context, void *mem); * @system */ U_CAPI void U_EXPORT2 -u_setMemoryFunctions(const void *context, UMemAlloc *a, UMemRealloc *r, UMemFree *f, +u_setMemoryFunctions(const void *context, UMemAllocFn *a, UMemReallocFn *r, UMemFreeFn *f, UErrorCode *status); #endif diff --git a/icu4c/source/extra/uconv/uconv.cpp b/icu4c/source/extra/uconv/uconv.cpp index a265c4ff3ab..ccfaf565a42 100644 --- a/icu4c/source/extra/uconv/uconv.cpp +++ b/icu4c/source/extra/uconv/uconv.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -796,6 +797,15 @@ int main(int argc, char **argv) int printTranslits = 0; int verbose = 0; + UErrorCode status = U_ZERO_ERROR; + + /* Initialize ICU */ + u_init(&status); + if (U_FAILURE(status)) { + fprintf(stderr, "%s: can not initialize ICU. status = %s\n", + argv[0], u_errorName(status)); + exit(1); + } // Get and prettify pname. pname = uprv_strrchr(*argv, U_FILE_SEP_CHAR); diff --git a/icu4c/source/test/cintltst/cintltst.c b/icu4c/source/test/cintltst/cintltst.c index 296e96e9515..8f6651bc47f 100644 --- a/icu4c/source/test/cintltst/cintltst.c +++ b/icu4c/source/test/cintltst/cintltst.c @@ -70,6 +70,10 @@ int main(int argc, const char* const argv[]) UResourceBundle *rb; UConverter *cnv; +#ifdef XP_MAC_CONSOLE + argc = ccommand((char***)&argv); +#endif + /* Checkargs */ for(i=1;i #include "unicode/utypes.h" #include "unicode/putil.h" +#include "unicode/uclean.h" #include "unicode/udata.h" #include "unewdata.h" #include "cmemory.h" @@ -55,6 +56,16 @@ static UOption options[]={ extern int main(int argc, char* argv[]) { + UErrorCode errorCode = U_ZERO_ERROR; + /* Initialize ICU */ + u_init(&errorCode); + if (U_FAILURE(errorCode)) { + fprintf(stderr, "%s: can not initialize ICU. errorCode = %s\n", + argv[0], u_errorName(errorCode)); + exit(1); + } + errorCode = U_ZERO_ERROR; + /* preset then read command line options */ options[2].value=u_getDataDirectory(); argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options); diff --git a/icu4c/source/tools/gentz/gentz.cpp b/icu4c/source/tools/gentz/gentz.cpp index 159b3714299..805aaeefd28 100644 --- a/icu4c/source/tools/gentz/gentz.cpp +++ b/icu4c/source/tools/gentz/gentz.cpp @@ -29,6 +29,7 @@ #include #include "unicode/utypes.h" #include "unicode/putil.h" +#include "unicode/uclean.h" #include "cmemory.h" #include "cstring.h" #include "filestrm.h" @@ -167,6 +168,15 @@ private: }; int main(int argc, char *argv[]) { + UErrorCode errorCode = U_ZERO_ERROR; + /* Initialize ICU */ + u_init(&errorCode); + if (U_FAILURE(errorCode)) { + fprintf(stderr, "%s: can not initialize ICU. errorCode = %s\n", + argv[0], u_errorName(errorCode)); + exit(1); + } + gentz x; U_MAIN_INIT_ARGS(argc, argv); diff --git a/icu4c/source/tools/genuca/genuca.cpp b/icu4c/source/tools/genuca/genuca.cpp index a6a9a558f97..913e16a4de0 100644 --- a/icu4c/source/tools/genuca/genuca.cpp +++ b/icu4c/source/tools/genuca/genuca.cpp @@ -26,6 +26,7 @@ #include #include "unicode/utypes.h" #include "unicode/udata.h" +#include "unicode/uclean.h" #include "ucol_imp.h" #include "genuca.h" #include "uoptions.h" @@ -971,6 +972,15 @@ int main(int argc, char* argv[]) { const char *copyright = NULL; uprv_memset(&UCAVersion, 0, 4); + /* Initialize ICU */ + u_init(&status); + if (U_FAILURE(status)) { + fprintf(stderr, "%s: can not initialize ICU. status = %s\n", + argv[0], u_errorName(status)); + exit(1); + } + status = U_ZERO_ERROR; + U_MAIN_INIT_ARGS(argc, argv); /* preset then read command line options */ diff --git a/icu4c/source/tools/makeconv/makeconv.c b/icu4c/source/tools/makeconv/makeconv.c index 6f6cf0b4e98..39177a8eb0c 100644 --- a/icu4c/source/tools/makeconv/makeconv.c +++ b/icu4c/source/tools/makeconv/makeconv.c @@ -32,6 +32,7 @@ #include "ucmpwrit.h" #include "makeconv.h" #include "genmbcs.h" +#include "unicode/uclean.h" #define DEBUG 0 @@ -267,6 +268,15 @@ int main(int argc, char* argv[]) char cnvNameWithPkg[UCNV_MAX_FULL_FILE_NAME_LENGTH]; UVersionInfo icuVersion; + /* Initialize ICU */ + u_init(&err); + if (U_FAILURE(err)) { + fprintf(stderr, "%s: can not initialize ICU. err = %s\n", + argv[0], u_errorName(err)); + exit(1); + } + err = U_ZERO_ERROR; + U_MAIN_INIT_ARGS(argc, argv); /* Set up the ICU version number */ diff --git a/icu4c/source/tools/pkgdata/pkgdata.c b/icu4c/source/tools/pkgdata/pkgdata.c index 5a5ad1121aa..4a3b8e022fc 100644 --- a/icu4c/source/tools/pkgdata/pkgdata.c +++ b/icu4c/source/tools/pkgdata/pkgdata.c @@ -24,6 +24,7 @@ #include "cstring.h" #include "filestrm.h" #include "toolutil.h" +#include "unicode/uclean.h" #include "unewdata.h" #include "uoptions.h" @@ -126,6 +127,14 @@ main(int argc, char* argv[]) { char tmp[1024]; int32_t i; + /* Initialize ICU */ + u_init(&status); + if (U_FAILURE(status)) { + fprintf(stderr, "%s: can not initialize ICU. status = %s\n", + argv[0], u_errorName(status)); + exit(1); + } + status = U_ZERO_ERROR; U_MAIN_INIT_ARGS(argc, argv); progname = argv[0];