ICU-2403 tracing, split header file in two, misc. review fixes. Work in process.

X-SVN-Rev: 13549
This commit is contained in:
Andy Heninger 2003-11-01 01:18:42 +00:00
parent 2875ab287f
commit 5fb5017307
4 changed files with 73 additions and 45 deletions

View File

@ -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<UCLN_COMMON; libType++) {
if (gCleanupFunctions[libType])
{
@ -109,13 +109,13 @@ u_cleanup(void)
U_CAPI void U_EXPORT2
u_init(UErrorCode *status) {
UTRACE_ENTRY(UTRACE_U_INIT);
UTRACE_ENTRY_OC(UTRACE_U_INIT);
/* Make sure the global mutexes are initialized. */
umtx_init(NULL);
umtx_lock(&gICUInitMutex);
if (gICUInitialized || U_FAILURE(*status)) {
umtx_unlock(&gICUInitMutex);
UTRACE_EXIT_S(*status);
UTRACE_EXIT_STATUS(*status);
return;
}
@ -134,7 +134,7 @@ u_init(UErrorCode *status) {
#endif
gICUInitialized = TRUE; /* TODO: don't set if U_FAILURE? */
umtx_unlock(&gICUInitMutex);
UTRACE_EXIT_S(*status);
UTRACE_EXIT_STATUS(*status);
}

View File

@ -303,7 +303,6 @@ utrace_format(char *outBuf, int32_t capacity, int32_t indent, const char *fmt, v
case 'S':
charsToOutput = 0;
//outputString(*ptrPtr, outBuf, &outIx, capacity, indent);
outputUString((const unsigned short *)*ptrPtr, -1, outBuf, &outIx, capacity, indent);
outputChar('\n', outBuf, &outIx, capacity, indent);
longArg = *ptrPtr==NULL? 0: 1; /* for test for null term. array. */

View File

@ -67,19 +67,24 @@ U_CFUNC U_IMPORT int32_t
#endif
utrace_level;
/**
* Boolean expression to see if ICU tracing is turned on.
* @draft ICU 2.8
*/
#define UTRACE_IS_ON (utrace_level>=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); \
}}

View File

@ -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 <pSrc && *pSrc==0)) && /* At end of src string, however it was specified. */
(pTarg==pTargEnd || (pTargEnd<pTarg && *pTarg==0))) { /* and also at end of dest string */
UTRACE_EXIT_D(UCOL_EQUAL);
UTRACE_EXIT_VALUE(UCOL_EQUAL);
return UCOL_EQUAL;
}
}
@ -8735,7 +8735,7 @@ ucol_strcoll( const UCollator *coll,
} else {
returnVal = ucol_strcollUseLatin1(coll, source, sourceLength, target, targetLength, &status);
}
UTRACE_EXIT_D(returnVal);
UTRACE_EXIT_VALUE(returnVal);
return returnVal;
}
@ -8810,7 +8810,7 @@ ucol_getLocale(const UCollator *coll, ULocDataLocaleType type, UErrorCode *statu
*status = U_ILLEGAL_ARGUMENT_ERROR;
}
UTRACE_DATA1(UTRACE_INFO, "result = %s", result);
UTRACE_EXIT_S(*status);
UTRACE_EXIT_STATUS(*status);
return result;
}