refactor: make vtable population test xplatform

This commit is contained in:
Eric House 2020-04-19 12:56:11 -07:00
parent ddb01d8930
commit 988facccd1
6 changed files with 34 additions and 17 deletions

View file

@ -27,6 +27,7 @@
#include "andutils.h"
#include "paths.h"
#include "LocalizedStrIncludes.h"
#include "dbgutil.h"
#define MAX_QUANTITY_STRS 4
@ -909,6 +910,7 @@ makeUtil( MPFORMAL EnvThreadInfo* ti, jobject jutil, CurGameInfo* gi,
SET_PROC(getDevUtilCtxt);
#undef SET_PROC
assertTableFull( vtable, sizeof(*vtable), "util" );
return (XW_UtilCtxt*)util;
} /* makeUtil */
@ -965,6 +967,9 @@ makeDUtil( MPFORMAL EnvThreadInfo* ti, jobject jdutil, VTableMgr* vtMgr,
SET_DPROC(notifyPause);
SET_DPROC(onDupTimerChanged);
#undef SET_DPROC
assertTableFull( vtable, sizeof(*vtable), "dutil" );
return &dutil->dutil;
}

View file

@ -126,5 +126,24 @@ devIDTypeToStr(DevIDType typ)
}
#undef CASESTR
typedef void (*ProcPtr)();
void
assertTableFull( void* table, size_t sizeInBytes, const XP_UCHAR* tableName )
{
if ( 0 != sizeInBytes % sizeof(ProcPtr) ) {
XP_LOGFF( "bad call? vtable size: %zu; proc ptr size: %zu", sizeInBytes, sizeof(ProcPtr) );
XP_ASSERT( 0 );
}
#endif
ProcPtr* proc = (ProcPtr*)table;
int count = sizeInBytes / sizeof(ProcPtr);
for ( int ii = 0; ii < count; ++ii ) {
if ( !*proc ) {
XP_LOGFF( "%s.vtable[%d] missing", tableName, ii );
XP_ASSERT( 0 );
}
++proc;
}
}
#endif /* DEBUG */

View file

@ -53,4 +53,10 @@ const char* devIDTypeToStr(DevIDType typ);
# define SET_DIRTY( ptr )
# endif
# ifdef DEBUG
void assertTableFull( void* table, size_t sizeInBytes, const XP_UCHAR* tableName );
# else
# define assertTableFull( table, sizeInBytes, tableName )
# endif
#endif

View file

@ -34,6 +34,7 @@
#include "gsrcwrap.h"
#include "linuxsms.h"
#include "strutils.h"
#include "dbgutil.h"
typedef struct CursesBoardState {
CursesAppGlobals* aGlobals;
@ -1128,7 +1129,7 @@ setupCursesUtilCallbacks( CursesBoardGlobals* bGlobals, XW_UtilCtxt* util )
#endif
#undef SET_PROC
assertUtilCallbacksSet( util );
assertTableFull( util->vtable, sizeof(*util->vtable), "curses util" );
} /* setupCursesUtilCallbacks */
static bool

View file

@ -2232,7 +2232,7 @@ setupGtkUtilCallbacks( GtkGameGlobals* globals, XW_UtilCtxt* util )
#undef SET_PROC
assertUtilCallbacksSet( util );
assertTableFull( util->vtable, sizeof(*util->vtable), "gtk util" );
} /* setupGtkUtilCallbacks */
#ifndef XWFEATURE_STANDALONE_ONLY

View file

@ -2388,20 +2388,6 @@ setupLinuxUtilCallbacks( XW_UtilCtxt* util )
#undef SET_PROC
}
void
assertUtilCallbacksSet( XW_UtilCtxt* util )
{
XWStreamCtxt* (**proc)(XW_UtilCtxt*, XP_PlayerAddr ) =
&util->vtable->m_util_makeStreamFromAddr;
for ( int ii = 0; ii < sizeof(*util->vtable)/sizeof(*proc); ++ii ) {
if ( !*proc ) {
XP_LOGF( "%s(): null ptr at index %d", __func__, ii );
XP_ASSERT( 0 );
}
++proc;
}
}
void
assertDrawCallbacksSet( const DrawCtxVTable* vtable )
{