mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-27 09:58:45 +01:00
Fix problem with writing server to stream changing its internal state
so that snapshotting made score strings disappear. Also rename stream_copyFromStream to stream_getFromStream to make it clearer that the src is modified. And swap params in stream_setPos().
This commit is contained in:
parent
a8cf03f68e
commit
07fba2c71b
4 changed files with 27 additions and 25 deletions
|
@ -292,8 +292,8 @@ mem_stream_putBits( XWStreamCtxt* p_sctx, XP_U16 nBits, XP_U32 data
|
|||
} /* mem_stream_putBits */
|
||||
|
||||
static void
|
||||
mem_stream_copyFromStream( XWStreamCtxt* p_sctx, XWStreamCtxt* src,
|
||||
XP_U16 nBytes )
|
||||
mem_stream_getFromStream( XWStreamCtxt* p_sctx, XWStreamCtxt* src,
|
||||
XP_U16 nBytes )
|
||||
{
|
||||
while ( nBytes > 0 ) {
|
||||
XP_U8 buf[256];
|
||||
|
@ -305,7 +305,7 @@ mem_stream_copyFromStream( XWStreamCtxt* p_sctx, XWStreamCtxt* src,
|
|||
stream_putBytes( p_sctx, buf, len );
|
||||
nBytes -= len;
|
||||
}
|
||||
} /* mem_stream_copyFromStream */
|
||||
} /* mem_stream_getFromStream */
|
||||
|
||||
static void
|
||||
mem_stream_open( XWStreamCtxt* p_sctx )
|
||||
|
@ -396,8 +396,9 @@ mem_stream_getPos( XWStreamCtxt* p_sctx, PosWhich which )
|
|||
} /* mem_stream_getPos */
|
||||
|
||||
static XWStreamPos
|
||||
mem_stream_setPos( XWStreamCtxt* p_sctx, XWStreamPos newpos, PosWhich which )
|
||||
mem_stream_setPos( XWStreamCtxt* p_sctx, PosWhich which, XWStreamPos newpos )
|
||||
{
|
||||
XP_ASSERT( END_OF_STREAM != newpos ); /* not handling this yet */
|
||||
MemStreamCtxt* stream = (MemStreamCtxt*)p_sctx;
|
||||
XWStreamPos oldPos = mem_stream_getPos( p_sctx, which );
|
||||
|
||||
|
@ -448,7 +449,7 @@ make_vtable( MemStreamCtxt* stream )
|
|||
SET_VTABLE_ENTRY( vtable, stream_putU32, mem );
|
||||
SET_VTABLE_ENTRY( vtable, stream_putBits, mem );
|
||||
|
||||
SET_VTABLE_ENTRY( vtable, stream_copyFromStream, mem );
|
||||
SET_VTABLE_ENTRY( vtable, stream_getFromStream, mem );
|
||||
|
||||
SET_VTABLE_ENTRY( vtable, stream_setPos, mem );
|
||||
SET_VTABLE_ENTRY( vtable, stream_getPos, mem );
|
||||
|
|
|
@ -100,7 +100,7 @@ stack_loadFromStream( StackCtxt* stack, XWStreamCtxt* stream )
|
|||
NULL, 0,
|
||||
(MemStreamCloseCallback)NULL );
|
||||
|
||||
stream_copyFromStream( stack->data, stream, nBytes );
|
||||
stream_getFromStream( stack->data, stream, nBytes );
|
||||
} else {
|
||||
XP_ASSERT( stack->nEntries == 0 );
|
||||
XP_ASSERT( stack->top == 0 );
|
||||
|
@ -115,7 +115,7 @@ stack_writeToStream( const StackCtxt* stack, XWStreamCtxt* stream )
|
|||
XWStreamPos oldPos = START_OF_STREAM;
|
||||
|
||||
if ( !!data ) {
|
||||
oldPos = stream_setPos( data, START_OF_STREAM, POS_READ );
|
||||
oldPos = stream_setPos( data, POS_READ, START_OF_STREAM );
|
||||
nBytes = stream_getSize( data );
|
||||
} else {
|
||||
nBytes = 0;
|
||||
|
@ -128,13 +128,13 @@ stack_writeToStream( const StackCtxt* stack, XWStreamCtxt* stream )
|
|||
stream_putU16( stream, stack->nEntries );
|
||||
stream_putU32( stream, stack->top );
|
||||
|
||||
stream_setPos( data, START_OF_STREAM, POS_READ );
|
||||
stream_copyFromStream( stream, data, nBytes );
|
||||
stream_setPos( data, POS_READ, START_OF_STREAM );
|
||||
stream_getFromStream( stream, data, nBytes );
|
||||
}
|
||||
|
||||
if ( !!data ) {
|
||||
/* in case it'll be used further */
|
||||
(void)stream_setPos( data, oldPos, POS_READ );
|
||||
(void)stream_setPos( data, POS_READ, oldPos );
|
||||
}
|
||||
} /* stack_writeToStream */
|
||||
|
||||
|
@ -167,7 +167,7 @@ pushEntry( StackCtxt* stack, const StackEntry* entry )
|
|||
stack->data = stream;
|
||||
}
|
||||
|
||||
oldLoc = stream_setPos( stream, stack->top, POS_WRITE );
|
||||
oldLoc = stream_setPos( stream, POS_WRITE, stack->top );
|
||||
|
||||
stream_putBits( stream, 2, entry->moveType );
|
||||
stream_putBits( stream, 2, entry->playerNum );
|
||||
|
@ -211,7 +211,7 @@ pushEntry( StackCtxt* stack, const StackEntry* entry )
|
|||
|
||||
++stack->nEntries;
|
||||
stack->highWaterMark = stack->nEntries;
|
||||
stack->top = stream_setPos( stream, oldLoc, POS_WRITE );
|
||||
stack->top = stream_setPos( stream, POS_WRITE, oldLoc );
|
||||
} /* pushEntry */
|
||||
|
||||
static void
|
||||
|
@ -327,7 +327,7 @@ setCacheReadyFor( StackCtxt* stack, XP_U16 n )
|
|||
StackEntry dummy;
|
||||
XP_U16 i;
|
||||
|
||||
stream_setPos( stack->data, START_OF_STREAM, POS_READ );
|
||||
stream_setPos( stack->data, POS_READ, START_OF_STREAM );
|
||||
for ( i = 0; i < n; ++i ) {
|
||||
readEntry( stack, &dummy );
|
||||
}
|
||||
|
@ -360,13 +360,13 @@ stack_getNthEntry( StackCtxt* stack, XP_U16 n, StackEntry* entry )
|
|||
}
|
||||
|
||||
if ( found ) {
|
||||
XWStreamPos oldPos = stream_setPos( stack->data, stack->cachedPos,
|
||||
POS_READ );
|
||||
XWStreamPos oldPos = stream_setPos( stack->data, POS_READ,
|
||||
stack->cachedPos );
|
||||
|
||||
readEntry( stack, entry );
|
||||
entry->moveNum = (XP_U8)n;
|
||||
|
||||
stack->cachedPos = stream_setPos( stack->data, oldPos, POS_READ );
|
||||
stack->cachedPos = stream_setPos( stack->data, POS_READ, oldPos );
|
||||
++stack->cacheNext;
|
||||
}
|
||||
|
||||
|
|
|
@ -339,7 +339,7 @@ readStreamIf( ServerCtxt* server, XWStreamCtxt* in )
|
|||
XP_U16 len = stream_getU16( in );
|
||||
if ( 0 < len ) {
|
||||
result = mkServerStream( server );
|
||||
stream_copyFromStream( result, in, len );
|
||||
stream_getFromStream( result, in, len );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -350,7 +350,9 @@ writeStreamIf( XWStreamCtxt* dest, XWStreamCtxt* src )
|
|||
XP_U16 len = !!src ? stream_getSize( src ) : 0;
|
||||
stream_putU16( dest, len );
|
||||
if ( 0 < len ) {
|
||||
stream_copyFromStream( dest, src, len );
|
||||
XWStreamPos pos = stream_getPos( src, POS_READ );
|
||||
stream_getFromStream( dest, src, len );
|
||||
(void)stream_setPos( src, POS_READ, pos );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -430,7 +432,6 @@ server_writeToStream( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
|
||||
writeStreamIf( stream, server->nv.prevMoveStream );
|
||||
writeStreamIf( stream, server->nv.prevWordsStream );
|
||||
|
||||
} /* server_writeToStream */
|
||||
|
||||
static void
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
|
||||
#define START_OF_STREAM 0
|
||||
#define END_OF_STREAM -1
|
||||
|
||||
typedef XP_U32 XWStreamPos; /* low 3 bits are bit offset; rest byte offset */
|
||||
|
||||
enum { POS_READ, POS_WRITE };
|
||||
typedef XP_U8 PosWhich;
|
||||
|
||||
|
@ -58,12 +58,12 @@ typedef struct StreamCtxVTable {
|
|||
void (*m_stream_putBits)( XWStreamCtxt* dctx, XP_U16 nBits, XP_U32 bits
|
||||
DBG_LINE_FILE_FORMAL );
|
||||
|
||||
void (*m_stream_copyFromStream)( XWStreamCtxt* dctx, XWStreamCtxt* src,
|
||||
void (*m_stream_getFromStream)( XWStreamCtxt* dctx, XWStreamCtxt* src,
|
||||
XP_U16 nBytes );
|
||||
|
||||
XWStreamPos (*m_stream_getPos)( XWStreamCtxt* dctx, PosWhich which );
|
||||
XWStreamPos (*m_stream_setPos)( XWStreamCtxt* dctx, XWStreamPos newpos,
|
||||
PosWhich which );
|
||||
XWStreamPos (*m_stream_setPos)( XWStreamCtxt* dctx, PosWhich which,
|
||||
XWStreamPos newpos );
|
||||
|
||||
void (*m_stream_open)( XWStreamCtxt* dctx );
|
||||
void (*m_stream_close)( XWStreamCtxt* dctx );
|
||||
|
@ -127,8 +127,8 @@ struct XWStreamCtxt {
|
|||
#define 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))
|
||||
#define stream_getFromStream( sc, src, nb ) \
|
||||
(sc)->vtable->m_stream_getFromStream((sc), (src), (nb))
|
||||
|
||||
#define stream_getPos(sc, w) \
|
||||
(sc)->vtable->m_stream_getPos((sc), (w))
|
||||
|
|
Loading…
Reference in a new issue