ICU-2011 U_ASSERT macro added

X-SVN-Rev: 9285
This commit is contained in:
Andy Heninger 2002-07-22 23:24:55 +00:00
parent e32993b2d8
commit 0e23352a30
10 changed files with 70 additions and 59 deletions

View File

@ -45,7 +45,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMMON_EXPORTS" /FD /c
# ADD CPP /nologo /G6 /MD /Za /W3 /GX /Zi /O2 /Ob2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMMON_EXPORTS" /D "U_COMMON_IMPLEMENTATION" /D "UDATA_STATIC_LIB" /FD /GF /c
# ADD CPP /nologo /G6 /MD /Za /W3 /GX /Zi /O2 /Ob2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMMON_EXPORTS" /D "U_COMMON_IMPLEMENTATION" /D "UDATA_STATIC_LIB" /FR /FD /GF /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
@ -1309,6 +1309,10 @@ SOURCE=.\symtable.h
# End Source File
# Begin Source File
SOURCE=.\uassert.h
# End Source File
# Begin Source File
SOURCE=.\unicode\ubidi.h
!IF "$(CFG)" == "common - Win32 Release"

View File

@ -20,7 +20,7 @@
#include "cmemory.h"
#include "stdio.h"
#include "assert.h"
#include "uassert.h"
U_NAMESPACE_BEGIN
@ -643,7 +643,7 @@ int32_t RuleBasedBreakIterator::handleNext(void) {
// Lookahead match is completed. Set the result accordingly, but only
// if no other rule has matched further in the mean time.
if (lookaheadResult > result) {
assert(row->fAccepting == lookaheadStatus); // TODO: handle this case
U_ASSERT(row->fAccepting == lookaheadStatus); // TODO: handle this case
// of overlapping lookahead matches.
result = lookaheadResult;
fLastBreakTag = lookaheadTag;
@ -782,7 +782,7 @@ int32_t RuleBasedBreakIterator::handlePrevious(void) {
// Lookahead match is completed. Set the result accordingly, but only
// if no other rule has matched further in the mean time.
if (lookaheadResult > result) {
assert(row->fAccepting == lookaheadStatus); // TODO: handle this case
U_ASSERT(row->fAccepting == lookaheadStatus); // TODO: handle this case
// of overlapping lookahead matches.
result = lookaheadResult;
fLastBreakTag = lookaheadTag;
@ -838,7 +838,7 @@ int32_t RuleBasedBreakIterator::getRuleStatus() const {
int32_t pa = current();
nonConstThis->previous();
int32_t pb = nonConstThis->next();
assert(pa == pb);
U_ASSERT(pa == pb);
}
}
return nonConstThis->fLastBreakTag;

View File

@ -11,7 +11,7 @@
#include "udatamem.h"
#include "cmemory.h"
#include <assert.h>
#include "uassert.h"
#include <stdio.h>
@ -105,7 +105,7 @@ void RBBIDataWrapper::init(const RBBIDataHeader *data, UErrorCode &status) {
//
//-----------------------------------------------------------------------------
RBBIDataWrapper::~RBBIDataWrapper() {
assert(fRefCount == 0);
U_ASSERT(fRefCount == 0);
if (fUDataMem) {
udata_close(fUDataMem);
} else {

View File

@ -24,7 +24,7 @@
#include "rbbirb.h"
#include "rbbinode.h"
#include "assert.h"
#include "uassert.h"
#include <stdio.h> // TODO - getrid of this.
@ -175,7 +175,7 @@ RBBINode *RBBINode::cloneTree() {
//
//-------------------------------------------------------------------------
void RBBINode::flattenVariables() {
assert(fType != varRef);
U_ASSERT(fType != varRef);
if (fLeftChild != NULL) {
if (fLeftChild->fType==varRef) {
@ -211,7 +211,7 @@ void RBBINode::flattenVariables() {
//
//-------------------------------------------------------------------------
void RBBINode::flattenSets() {
assert(fType != setRef);
U_ASSERT(fType != setRef);
if (fLeftChild != NULL) {
if (fLeftChild->fType==setRef) {

View File

@ -32,7 +32,6 @@
#include <stdio.h> // TODO - getrid of this.
#include <stdlib.h>
#include <string.h>
#include <assert.h>
U_NAMESPACE_BEGIN

View File

@ -33,7 +33,7 @@
#include <stdio.h> // TODO - getrid of this, or make conditional on debugging
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "uassert.h"
U_NAMESPACE_BEGIN
@ -308,7 +308,7 @@ UBool RBBIRuleScanner::doParseActions(EParseAction action,
break;
}
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "rtree")) {printNodeStack("end of rule");}
assert(fNodeStackPtr == 1);
U_ASSERT(fNodeStackPtr == 1);
// If this rule includes a look-ahead '/', add a endMark node to the
// expression tree.
@ -456,7 +456,7 @@ UBool RBBIRuleScanner::doParseActions(EParseAction action,
{
n = fNodeStack[fNodeStackPtr];
uint32_t v = u_charDigitValue(fC.fChar);
assert(v >= 0);
U_ASSERT(v >= 0);
n->fVal = n->fVal*10 + v;
break;
}
@ -646,7 +646,7 @@ void RBBIRuleScanner::findSetFor(const UnicodeString &s, RBBINode *node, Unicode
if (el != NULL) {
delete setToAdopt;
node->fLeftChild = el->val;
assert(node->fLeftChild->fType == RBBINode::uset);
U_ASSERT(node->fLeftChild->fType == RBBINode::uset);
return;
}

View File

@ -31,7 +31,7 @@
#include "unicode/uniset.h"
#include "utrie.h"
#include "uvector.h"
#include "assert.h"
#include "uassert.h"
#include "cmemory.h"
#include <stdio.h>
@ -521,7 +521,7 @@ RangeDescriptor::~RangeDescriptor() {
//
//-------------------------------------------------------------------------------------
void RangeDescriptor::split(UChar32 where, UErrorCode &status) {
assert(where>fStartChar && where<=fEndChar);
U_ASSERT(where>fStartChar && where<=fEndChar);
RangeDescriptor *nr = new RangeDescriptor(*this, status);
/* test for NULL */
if(nr == 0) {

View File

@ -18,7 +18,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "uassert.h"
U_NAMESPACE_BEGIN
@ -367,7 +367,7 @@ void RBBITableBuilder::buildStateTable() {
int32_t ux;
UBool UinDstates = FALSE;
if (U != NULL) {
assert(U->size() > 0);
U_ASSERT(U->size() > 0);
int ix;
for (ix=0; ix<fDStates->size(); ix++) {
RBBIStateDescriptor *temp2;
@ -649,8 +649,8 @@ void RBBITableBuilder::exportTable(void *where) {
for (state=0; state<table->fNumStates; state++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(state);
RBBIStateTableRow *row = (RBBIStateTableRow *)(table->fTableData + state*table->fRowLen);
assert (-32768 < sd->fAccepting && sd->fAccepting <= 32767);
assert (-32768 < sd->fLookAhead && sd->fLookAhead <= 32767);
U_ASSERT (-32768 < sd->fAccepting && sd->fAccepting <= 32767);
U_ASSERT (-32768 < sd->fLookAhead && sd->fLookAhead <= 32767);
row->fAccepting = (int16_t)sd->fAccepting;
row->fLookAhead = (int16_t)sd->fLookAhead;
row->fTag = (int16_t)sd->fTagVal;

View File

@ -0,0 +1,26 @@
/*
******************************************************************************
*
* Copyright (C) 2002, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
*
* File uassert.h
*
* Contains U_ASSERT macro
*
* By default, U_ASSERT just wraps the C library assert macro.
* By changing the definition here, the assert behavior for ICU can be changed
* without affecting other non-ICU uses of the C library assert().
*
******************************************************************************
*/
#ifndef U_ASSERT_H
#define U_ASSERT_H
#include <assert.h>
#define U_ASSERT(exp) assert(exp)
#endif

View File

@ -14,6 +14,7 @@
#include "unicode/ustring.h"
#include "cstring.h"
#include "cmemory.h"
#include "uassert.h"
/* This hashtable is implemented as a double hash. All elements are
* stored in a single array with no secondary storage for collision
@ -131,25 +132,6 @@ static const float RESIZE_POLICY_RATIO_TABLE[6] = {
* Debugging
********************************************************************/
/* Enable this section to compile in runtime assertion checking. */
/* #define HASH_DEBUG */
#ifdef HASH_DEBUG
#include <stdio.h>
#define assert(exp) (void)( (exp) || (_assert(#exp, __FILE__, __LINE__), 0) )
static void _assert(const char* exp, const char* file, int line) {
printf("ERROR: assert(%s) failed: %s, line %d\n",
exp, file, line);
}
#else
#define assert(exp)
#endif
/********************************************************************
* PRIVATE Prototypes
@ -211,7 +193,7 @@ uhash_openSize(UHashFunction *keyHash, UKeyComparator *keyComp,
U_CAPI void U_EXPORT2
uhash_close(UHashtable *hash) {
assert(hash != NULL);
U_ASSERT(hash != NULL);
if (hash->elements != NULL) {
if (hash->keyDeleter != NULL || hash->valueDeleter != NULL) {
int32_t pos=-1;
@ -358,13 +340,13 @@ U_CAPI void U_EXPORT2
uhash_removeAll(UHashtable *hash) {
int32_t pos = -1;
const UHashElement *e;
assert(hash != NULL);
U_ASSERT(hash != NULL);
if (hash->count != 0) {
while ((e = uhash_nextElement(hash, &pos)) != NULL) {
uhash_removeElement(hash, e);
}
}
assert(hash->count == 0);
U_ASSERT(hash->count == 0);
}
U_CAPI const UHashElement* U_EXPORT2
@ -382,7 +364,7 @@ uhash_nextElement(const UHashtable *hash, int32_t *pos) {
* EMPTY and not DELETED.
*/
int32_t i;
assert(hash != NULL);
U_ASSERT(hash != NULL);
for (i = *pos + 1; i < hash->length; ++i) {
if (!IS_EMPTY_OR_DELETED(hash->elements[i].hashcode)) {
*pos = i;
@ -396,8 +378,8 @@ uhash_nextElement(const UHashtable *hash, int32_t *pos) {
U_CAPI void* U_EXPORT2
uhash_removeElement(UHashtable *hash, const UHashElement* e) {
assert(hash != NULL);
assert(e != NULL);
U_ASSERT(hash != NULL);
U_ASSERT(e != NULL);
if (!IS_EMPTY_OR_DELETED(e->hashcode)) {
return _uhash_internalRemoveElement(hash, (UHashElement*) e).pointer;
}
@ -565,8 +547,8 @@ _uhash_create(UHashFunction *keyHash, UKeyComparator *keyComp,
UHashtable *result;
if (U_FAILURE(*status)) return NULL;
assert(keyHash != NULL);
assert(keyComp != NULL);
U_ASSERT(keyHash != NULL);
U_ASSERT(keyComp != NULL);
result = (UHashtable*) uprv_malloc(sizeof(UHashtable));
if (result == NULL) {
@ -609,7 +591,7 @@ _uhash_allocate(UHashtable *hash,
if (U_FAILURE(*status)) return;
assert(primeIndex >= 0 && primeIndex < PRIMES_LENGTH);
U_ASSERT(primeIndex >= 0 && primeIndex < PRIMES_LENGTH);
hash->primeIndex = primeIndex;
hash->length = PRIMES[primeIndex];
@ -679,8 +661,8 @@ _uhash_rehash(UHashtable *hash) {
for (i = oldLength - 1; i >= 0; --i) {
if (!IS_EMPTY_OR_DELETED(old[i].hashcode)) {
UHashElement *e = _uhash_find(hash, old[i].key, old[i].hashcode);
assert(e != NULL);
assert(e->hashcode == HASH_EMPTY);
U_ASSERT(e != NULL);
U_ASSERT(e->hashcode == HASH_EMPTY);
e->key = old[i].key;
e->value = old[i].value;
e->hashcode = old[i].hashcode;
@ -765,7 +747,7 @@ _uhash_find(const UHashtable *hash, UHashTok key,
* WILL NEVER HAPPEN as long as uhash_put() makes sure that
* count is always < length.
*/
assert(FALSE);
U_ASSERT(FALSE);
return NULL; /* Never happens if uhash_put() behaves */
}
return &(hash->elements[theIndex]);
@ -790,7 +772,7 @@ _uhash_put(UHashtable *hash,
if (U_FAILURE(*status)) {
goto err;
}
assert(hash != NULL);
U_ASSERT(hash != NULL);
/* Cannot always check pointer here or iSeries sees NULL every time. */
if ((hint & HINT_VALUE_POINTER) && value.pointer == NULL) {
/* Disallow storage of NULL values, since NULL is returned by
@ -804,7 +786,7 @@ _uhash_put(UHashtable *hash,
hashcode = (*hash->keyHasher)(key);
e = _uhash_find(hash, key, hashcode);
assert(e != NULL);
U_ASSERT(e != NULL);
if (IS_EMPTY_OR_DELETED(e->hashcode)) {
/* Important: We must never actually fill the table up. If we
@ -851,7 +833,7 @@ _uhash_remove(UHashtable *hash,
*/
UHashTok result;
UHashElement* e = _uhash_find(hash, key, hash->keyHasher(key));
assert(e != NULL);
U_ASSERT(e != NULL);
result.pointer = NULL; result.integer = 0;
if (!IS_EMPTY_OR_DELETED(e->hashcode)) {
result = _uhash_internalRemoveElement(hash, e);
@ -905,7 +887,7 @@ _uhash_setElement(UHashtable *hash, UHashElement* e,
static UHashTok
_uhash_internalRemoveElement(UHashtable *hash, UHashElement* e) {
UHashTok empty;
assert(!IS_EMPTY_OR_DELETED(e->hashcode));
U_ASSERT(!IS_EMPTY_OR_DELETED(e->hashcode));
--hash->count;
empty.pointer = NULL; empty.integer = 0;
return _uhash_setElement(hash, e, HASH_DELETED, empty, empty, 0);
@ -913,9 +895,9 @@ _uhash_internalRemoveElement(UHashtable *hash, UHashElement* e) {
static void
_uhash_internalSetResizePolicy(UHashtable *hash, enum UHashResizePolicy policy) {
assert(hash == 0);
assert(((int32_t)policy) >= 0);
assert(((int32_t)policy) < 3);
U_ASSERT(hash == 0);
U_ASSERT(((int32_t)policy) >= 0);
U_ASSERT(((int32_t)policy) < 3);
hash->lowWaterRatio = RESIZE_POLICY_RATIO_TABLE[policy * 2];
hash->highWaterRatio = RESIZE_POLICY_RATIO_TABLE[policy * 2 + 1];
}