diff --git a/xwords4/common/memstream.c b/xwords4/common/memstream.c index 7b87eed52..37b7829e4 100644 --- a/xwords4/common/memstream.c +++ b/xwords4/common/memstream.c @@ -268,9 +268,13 @@ putOneBit( MemStreamCtxt* stream, XP_U16 bit ) } /* putOneBit */ static void -mem_stream_putBits( XWStreamCtxt* p_sctx, XP_U16 nBits, XP_U32 data ) +mem_stream_putBits( XWStreamCtxt* p_sctx, XP_U16 nBits, XP_U32 data + DBG_LINE_FILE_FORMAL ) { MemStreamCtxt* stream = (MemStreamCtxt*)p_sctx; +#ifdef DEBUG + XP_U16 origBits = nBits; +#endif XP_ASSERT( nBits > 0 ); @@ -278,7 +282,13 @@ mem_stream_putBits( XWStreamCtxt* p_sctx, XP_U16 nBits, XP_U32 data ) putOneBit( stream, (XP_U16)(((data & 1L) != 0)? 1:0) ); data >>= 1; } - XP_ASSERT( data == 0 ); /* otherwise nBits was too small */ + XP_ASSERT( data == 0 ); /* otherwise nBits was too small */ +#ifdef DEBUG + if ( data != 0 ) { + XP_LOGF( "%s: nBits was %d from line %d, %s", __FUNCTION__, + origBits, lin, fil ); + } +#endif } /* mem_stream_putBits */ static void diff --git a/xwords4/common/xwstream.h b/xwords4/common/xwstream.h index 2c094b3d8..b44f6455b 100644 --- a/xwords4/common/xwstream.h +++ b/xwords4/common/xwstream.h @@ -31,6 +31,14 @@ typedef XP_U32 XWStreamPos; /* low 3 bits are bit offset; rest byte offset * enum { POS_READ, POS_WRITE }; typedef XP_U8 PosWhich; +#ifdef DEBUG +# define DBG_LINE_FILE_FORMAL , XP_U16 lin, const char* fil +# define DBG_LINE_FILE_PARM , __LINE__, __FILE__ +#else +# define DBG_LINE_FILE_FORMAL +# define DBG_LINE_FILE_PARM +#endif + typedef struct StreamCtxVTable { void (*m_stream_destroy)( XWStreamCtxt* dctx ); @@ -47,7 +55,8 @@ typedef struct StreamCtxVTable { void (*m_stream_putString)( XWStreamCtxt* dctx, const char* whence ); void (*m_stream_putU16)( XWStreamCtxt* dctx, XP_U16 data ); void (*m_stream_putU32)( XWStreamCtxt* dctx, XP_U32 data ); - void (*m_stream_putBits)( XWStreamCtxt* dctx, XP_U16 nBits, XP_U32 bits ); + void (*m_stream_putBits)( XWStreamCtxt* dctx, XP_U16 nBits, XP_U32 bits + DBG_LINE_FILE_FORMAL ); void (*m_stream_copyFromStream)( XWStreamCtxt* dctx, XWStreamCtxt* src, XP_U16 nBytes ); @@ -114,7 +123,7 @@ struct XWStreamCtxt { (sc)->vtable->m_stream_putU32((sc), (d)) #define stream_putBits(sc, n, b) \ - (sc)->vtable->m_stream_putBits((sc), (n), (b)) + (sc)->vtable->m_stream_putBits((sc), (n), (b) DBG_LINE_FILE_PARM ) #define stream_copyFromStream( sc, src, nb ) \ (sc)->vtable->m_stream_copyFromStream((sc), (src), (nb))