From 6dc75914a6f37ff7b7b7316ca954b88a27e25cb8 Mon Sep 17 00:00:00 2001 From: ehouse Date: Sun, 18 Mar 2007 23:31:51 +0000 Subject: [PATCH] turn stringFromStream into macro to aid logging for leak detection. Debug builds only effected. --- common/dictnry.c | 2 +- common/game.c | 6 +++--- common/server.c | 2 +- common/strutils.c | 12 ++++++++++-- common/strutils.h | 12 +++++++++++- palm/palmmain.c | 3 +-- wince/cemain.c | 3 +-- 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/common/dictnry.c b/common/dictnry.c index f07513b56..958a4b23f 100644 --- a/common/dictnry.c +++ b/common/dictnry.c @@ -333,7 +333,7 @@ dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream ) for ( nSpecials = i = 0; i < nFaces; ++i ) { XP_UCHAR face = dict_getTileChar( dict, (Tile)i ); if ( IS_SPECIAL( face ) ) { - XP_UCHAR* txt = stringFromStream( MPPARM(dict->mpool) stream ); + XP_UCHAR* txt = stringFromStream( dict->mpool, stream ); XP_ASSERT( !!txt ); localTexts[nSpecials] = txt; diff --git a/common/game.c b/common/game.c index 8193f6fdc..e9ac8bc22 100644 --- a/common/game.c +++ b/common/game.c @@ -367,7 +367,7 @@ gi_readFromStream( MPFORMAL XWStreamCtxt* stream, CurGameInfo* gi ) XP_UCHAR* str; XP_U16 strVersion = stream_getVersion( stream ); - str = stringFromStream( MPPARM(mpool) stream ); + str = stringFromStream( mpool, stream ); replaceStringIfDifferent( mpool, &gi->dictName, str ); if ( !!str ) { XP_FREE( mpool, str ); @@ -395,13 +395,13 @@ gi_readFromStream( MPFORMAL XWStreamCtxt* stream, CurGameInfo* gi ) } for ( pl = gi->players, i = 0; i < gi->nPlayers; ++pl, ++i ) { - str = stringFromStream( MPPARM(mpool) stream ); + str = stringFromStream( mpool, stream ); replaceStringIfDifferent( mpool, &pl->name, str ); if ( !!str ) { XP_FREE( mpool, str ); } - str = stringFromStream( MPPARM(mpool) stream ); + str = stringFromStream( mpool, stream ); replaceStringIfDifferent( mpool, &pl->password, str ); if ( !!str ) { XP_FREE( mpool, str ); diff --git a/common/server.c b/common/server.c index 3de31a717..72c31743e 100644 --- a/common/server.c +++ b/common/server.c @@ -1152,7 +1152,7 @@ bwiFromStream( MPFORMAL XWStreamCtxt* stream, BadWordInfo* bwi ) bwi->nWords = nWords; for ( sp = bwi->words; nWords; ++sp, --nWords ) { - *sp = stringFromStream( MPPARM(mpool) stream ); + *sp = stringFromStream( mpool, stream ); } } /* bwiFromStream */ diff --git a/common/strutils.c b/common/strutils.c index 42a1c69fd..42343efae 100644 --- a/common/strutils.c +++ b/common/strutils.c @@ -98,14 +98,22 @@ signedFromStream( XWStreamCtxt* stream, XP_U16 nBits ) #endif XP_UCHAR* -stringFromStream( MPFORMAL XWStreamCtxt* stream ) +p_stringFromStream( MPFORMAL XWStreamCtxt* stream +#ifdef MEM_DEBUG + , const char* file, XP_U32 lineNo +#endif + ) { XP_UCHAR buf[0xFF]; XP_UCHAR* str = (XP_UCHAR*)NULL; XP_U16 len = stringFromStreamHere( stream, buf, sizeof(buf) ); if ( len > 0 ) { - str = (XP_UCHAR*)XP_MALLOC( mpool, len + 1 ); +#ifdef MEM_DEBUG + str = mpool_alloc( mpool, len + 1, file, lineNo ); +#else + str = (XP_UCHAR*)XP_MALLOC( mpool, len + 1 ); /* leaked */ +#endif XP_MEMCPY( str, buf, len + 1 ); } return str; diff --git a/common/strutils.h b/common/strutils.h index 0c4a51507..2aa756a9c 100644 --- a/common/strutils.h +++ b/common/strutils.h @@ -37,7 +37,17 @@ void traySetFromStream( XWStreamCtxt* stream, TrayTileSet* ts ); XP_S32 signedFromStream( XWStreamCtxt* stream, XP_U16 nBits ); void signedToStream( XWStreamCtxt* stream, XP_U16 nBits, XP_S32 num ); -XP_UCHAR* stringFromStream( MPFORMAL XWStreamCtxt* stream ); +XP_UCHAR* p_stringFromStream( MPFORMAL XWStreamCtxt* stream +#ifdef MEM_DEBUG + , const char* file, XP_U32 lineNo +#endif + ); +#ifdef MEM_DEBUG +# define stringFromStream( p, in ) p_stringFromStream( (p), (in), __FILE__, __LINE__ ) +#else +# define stringFromStream( p, in ) p_stringFromStream( in ) +#endif + XP_U16 stringFromStreamHere( XWStreamCtxt* stream, XP_UCHAR* buf, XP_U16 len ); void stringToStream( XWStreamCtxt* stream, const XP_UCHAR* str ); diff --git a/palm/palmmain.c b/palm/palmmain.c index 76b2299e3..68f2d0ffc 100644 --- a/palm/palmmain.c +++ b/palm/palmmain.c @@ -581,8 +581,7 @@ loadCurrentGame( PalmAppGlobals* globals, XP_U16 gIndex, hasDict = stream_getU8( recStream ); if ( hasDict ) { - XP_UCHAR* name = stringFromStream( MPPARM(globals->mpool) - recStream ); + XP_UCHAR* name = stringFromStream( globals->mpool, recStream ); dict = palm_dictionary_make( MPPARM(globals->mpool) globals, name, globals->dictList ); success = dict != NULL; diff --git a/wince/cemain.c b/wince/cemain.c index af0d2487d..f9c091029 100755 --- a/wince/cemain.c +++ b/wince/cemain.c @@ -955,8 +955,7 @@ ceLoadSavedGame( CEAppGlobals* globals ) #ifdef STUBBED_DICT XP_ASSERT(0); /* just don't do this!!!! */ #else - XP_UCHAR* name = stringFromStream( MPPARM(globals->mpool) - stream ); + XP_UCHAR* name = stringFromStream( globals->mpool, stream ); dict = ce_dictionary_make( globals, name ); XP_FREE( globals->mpool, name ); success = dict != NULL;