From 5fb5017307628882d3fbac6a9f14ce0c5781c5a4 Mon Sep 17 00:00:00 2001 From: Andy Heninger Date: Sat, 1 Nov 2003 01:18:42 +0000 Subject: [PATCH] ICU-2403 tracing, split header file in two, misc. review fixes. Work in process. X-SVN-Rev: 13549 --- icu4c/source/common/ucln_cmn.c | 8 ++--- icu4c/source/common/utrace.c | 1 - icu4c/source/common/utracimp.h | 65 ++++++++++++++++++++++++---------- icu4c/source/i18n/ucol.cpp | 44 +++++++++++------------ 4 files changed, 73 insertions(+), 45 deletions(-) diff --git a/icu4c/source/common/ucln_cmn.c b/icu4c/source/common/ucln_cmn.c index b5658ef793c..9fd286c1329 100644 --- a/icu4c/source/common/ucln_cmn.c +++ b/icu4c/source/common/ucln_cmn.c @@ -57,7 +57,7 @@ u_cleanup(void) { ECleanupLibraryType libType; - UTRACE_ENTRY(UTRACE_U_CLEANUP); + UTRACE_ENTRY_OC(UTRACE_U_CLEANUP); for (libType = UCLN_START+1; libType=UTRACE_ERROR) /** * Boolean expression to see if ICU tracing is turned on * to at least the specified level. - * @draft ICU 2.8 + * @internal */ #define UTRACE_LEVEL(level) (utrace_level>=(level)) +/** + * Flag bit in utraceFnNumber, the local variable added to each function + * with tracing code to contains the function number. + * + * Set the flag if the function's entry is traced, which will cause the + * function's exit to also be traced. utraceFnNumber is uncoditionally + * set at entry, whether or not the entry is traced, so that it will + * always be available for error trace output. + */ +#define UTRACE_TRACED_ENTRY 0x80000000 /** * Trace statement for the entry point of a function. @@ -93,12 +98,36 @@ utrace_level; * consistent with ICU's error handling model. * * @param fnNumber The UTraceFunctionNumber for the current function. - * @draft ICU 2.8 + * @internal */ #define UTRACE_ENTRY(fnNumber) \ int32_t utraceFnNumber=(fnNumber); \ - if(UTRACE_IS_ON) { \ + if(utrace_level>=UTRACE_INFO) { \ utrace_entry(fnNumber); \ + utraceFnNumber |= UTRACE_TRACED_ENTRY; \ + } + + +/** + * Trace statement for the entry point of open and close functions. + * Produces trace output at a less verbose setting than plain UTRACE_ENTRY + * Stores the function number in a local variable. + * In C code, must be placed immediately after the last variable declaration. + * Must be matched with UTRACE_EXIT() at all function exit points. + * + * Tracing should start with UTRACE_ENTRY after checking for + * U_FAILURE at function entry, so that if a function returns immediately + * because of a pre-existing error condition, it does not show up in the trace, + * consistent with ICU's error handling model. + * + * @param fnNumber The UTraceFunctionNumber for the current function. + * @internal + */ +#define UTRACE_ENTRY_OC(fnNumber) \ + int32_t utraceFnNumber=(fnNumber); \ + if(utrace_level>=UTRACE_OPEN_CLOSE) { \ + utrace_entry(fnNumber); \ + utraceFnNumber |= UTRACE_TRACED_ENTRY; \ } @@ -112,11 +141,11 @@ utrace_level; * positive values an error (see u_errorName()), * negative values an informational status. * - * @draft ICU 2.8 + * @internal */ #define UTRACE_EXIT() \ - {if(UTRACE_IS_ON) { \ - utrace_exit(utraceFnNumber, UTRACE_EXITV_NONE); \ + {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \ + utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, UTRACE_EXITV_NONE); \ }} /** @@ -125,20 +154,20 @@ utrace_level; * * @param val The function's return value, int32_t or comatible type. * - * @draft ICU 2.8 + * @internal */ -#define UTRACE_EXIT_D(val) \ - {if(UTRACE_IS_ON) { \ +#define UTRACE_EXIT_VALUE(val) \ + {if(utrace_level>=UTRACE_INFO) { \ utrace_exit(utraceFnNumber, UTRACE_EXITV_I32, val); \ }} -#define UTRACE_EXIT_S(status) \ - {if(UTRACE_IS_ON) { \ +#define UTRACE_EXIT_STATUS(status) \ + {if(utrace_level>=UTRACE_INFO) { \ utrace_exit(utraceFnNumber, UTRACE_EXITV_STATUS, status); \ }} -#define UTRACE_EXIT_DS(val, status) \ - {if(UTRACE_IS_ON) { \ +#define UTRACE_EXIT_VALUE_STATUS(val, status) \ + {if(utrace_level>=UTRACE_INFO) { \ utrace_exit(utraceFnNumber, (UTRACE_EXITV_I32 | UTRACE_EXITV_STATUS), val, status); \ }} diff --git a/icu4c/source/i18n/ucol.cpp b/icu4c/source/i18n/ucol.cpp index 44ffed0f1bc..3aedf833f0e 100644 --- a/icu4c/source/i18n/ucol.cpp +++ b/icu4c/source/i18n/ucol.cpp @@ -345,7 +345,7 @@ U_CAPI UCollator* ucol_open(const char *loc, UErrorCode *status) { - UTRACE_ENTRY(UTRACE_UCOL_OPEN); + UTRACE_ENTRY_OC(UTRACE_UCOL_OPEN); UTRACE_DATA1(UTRACE_INFO, "locale = \"%s\"", loc); UCollator *result = NULL; @@ -355,7 +355,7 @@ ucol_open(const char *loc, result = ucol_open_internal(loc, status); } UTRACE_DATA1(UTRACE_INFO, "Returning %p", result); - UTRACE_EXIT_S(*status); + UTRACE_EXIT_STATUS(*status); return result; } @@ -474,7 +474,7 @@ ucol_setReqValidLocales(UCollator *coll, char *requestedLocaleToAdopt, char *val U_CAPI void U_EXPORT2 ucol_close(UCollator *coll) { - UTRACE_ENTRY(UTRACE_UCOL_CLOSE); + UTRACE_ENTRY_OC(UTRACE_UCOL_CLOSE); UTRACE_DATA1(UTRACE_INFO, "coll = %p", coll); if(coll != NULL) { // these are always owned by each UCollator struct, @@ -4305,7 +4305,7 @@ ucol_getSortKey(const UCollator *coll, //((UCollator *)coll)->errorCode = status; /*semantically const */ } UTRACE_DATA2(UTRACE_VERBOSE, "Sort Key = %vb", result, keySize); - UTRACE_EXIT_S(status); + UTRACE_EXIT_STATUS(status); return keySize; } @@ -5763,7 +5763,7 @@ ucol_nextSortKeyPart(const UCollator *coll, if(count==0) { /* nothing to do */ - UTRACE_EXIT_D(0); + UTRACE_EXIT_VALUE(0); return 0; } @@ -5840,7 +5840,7 @@ ucol_nextSortKeyPart(const UCollator *coll, s.iterator = unorm_setIter(normIter, iter, UNORM_FCD, status); s.flags &= ~UCOL_ITER_NORM; if(U_FAILURE(*status)) { - UTRACE_EXIT_S(*status); + UTRACE_EXIT_STATUS(*status); return 0; } } else if(level == UCOL_PSK_IDENTICAL) { @@ -5850,7 +5850,7 @@ ucol_nextSortKeyPart(const UCollator *coll, s.iterator = unorm_setIter(normIter, iter, UNORM_NFD, status); s.flags &= ~UCOL_ITER_NORM; if(U_FAILURE(*status)) { - UTRACE_EXIT_S(*status); + UTRACE_EXIT_STATUS(*status); return 0; } doingIdenticalFromStart = TRUE; @@ -5875,7 +5875,7 @@ ucol_nextSortKeyPart(const UCollator *coll, /* reset to previous state */ s.iterator->setState(s.iterator, iterState, status); if(U_FAILURE(*status)) { - UTRACE_EXIT_S(*status); + UTRACE_EXIT_STATUS(*status); return 0; } } @@ -5920,7 +5920,7 @@ ucol_nextSortKeyPart(const UCollator *coll, if(CE==UCOL_NO_MORE_CES) { /* should not happen */ *status=U_INTERNAL_PROGRAM_ERROR; - UTRACE_EXIT_S(*status); + UTRACE_EXIT_STATUS(*status); return 0; } } @@ -6401,7 +6401,7 @@ ucol_nextSortKeyPart(const UCollator *coll, // At this point we have a NFD iterator that is positioned // in the right place if(U_FAILURE(*status)) { - UTRACE_EXIT_S(*status); + UTRACE_EXIT_STATUS(*status); return 0; } first = uiter_previous32(s.iterator); @@ -6471,7 +6471,7 @@ ucol_nextSortKeyPart(const UCollator *coll, break; default: *status = U_INTERNAL_PROGRAM_ERROR; - UTRACE_EXIT_S(*status); + UTRACE_EXIT_STATUS(*status); return 0; } @@ -6547,7 +6547,7 @@ saveState: // Return number of meaningful sortkey bytes. UTRACE_DATA4(UTRACE_VERBOSE, "dest = %vb, state=%d %d", dest,i, state[0], state[1]); - UTRACE_EXIT_D(i); + UTRACE_EXIT_VALUE(i); return i; } @@ -8499,12 +8499,12 @@ ucol_strcollIter( const UCollator *coll, UTRACE_DATA3(UTRACE_VERBOSE, "coll=%p, sIter=%p, tIter=%p", coll, sIter, tIter); if (sIter == tIter) { - UTRACE_EXIT_DS(UCOL_EQUAL, *status) + UTRACE_EXIT_VALUE_STATUS(UCOL_EQUAL, *status) return UCOL_EQUAL; } if(sIter == NULL || tIter == NULL || coll == NULL) { *status = U_ILLEGAL_ARGUMENT_ERROR; - UTRACE_EXIT_DS(UCOL_EQUAL, *status) + UTRACE_EXIT_VALUE_STATUS(UCOL_EQUAL, *status) return UCOL_EQUAL; } @@ -8584,7 +8584,7 @@ end_compare: unorm_closeIter(tNormIter); } - UTRACE_EXIT_DS(result, *status) + UTRACE_EXIT_VALUE_STATUS(result, *status) return result; } @@ -8620,7 +8620,7 @@ ucol_strcoll( const UCollator *coll, if(source == NULL || target == NULL) { // do not crash, but return. Should have // status argument to return error. - UTRACE_EXIT_D(UTRACE_UCOL_STRCOLL); + UTRACE_EXIT_VALUE(UTRACE_UCOL_STRCOLL); return UCOL_EQUAL; } collIterate sColl, tColl; @@ -8637,7 +8637,7 @@ ucol_strcoll( const UCollator *coll, // Check for them being the same string, and scan through // any leading equal portion. if (source==target) { - UTRACE_EXIT_D(UCOL_EQUAL); + UTRACE_EXIT_VALUE(UCOL_EQUAL); return UCOL_EQUAL; } @@ -8652,7 +8652,7 @@ ucol_strcoll( const UCollator *coll, pTarg++; } if (*pSrc == 0 && *pTarg == 0) { - UTRACE_EXIT_D(UCOL_EQUAL); + UTRACE_EXIT_VALUE(UCOL_EQUAL); return UCOL_EQUAL; } equalLength = pSrc - source; @@ -8663,7 +8663,7 @@ ucol_strcoll( const UCollator *coll, /* check if source and target are same strings */ if (source==target && sourceLength==targetLength) { - UTRACE_EXIT_D(UCOL_EQUAL); + UTRACE_EXIT_VALUE(UCOL_EQUAL); return UCOL_EQUAL; } const UChar *pSrcEnd = source + sourceLength; @@ -8692,7 +8692,7 @@ ucol_strcoll( const UCollator *coll, // If we made it all the way through both strings, we are done. They are == if ((pSrc ==pSrcEnd || (pSrcEnd