diff --git a/xwords4/android/jni/anddict.c b/xwords4/android/jni/anddict.c index 0d85b6e22..2f01d7e8a 100644 --- a/xwords4/android/jni/anddict.c +++ b/xwords4/android/jni/anddict.c @@ -232,8 +232,7 @@ static void splitFaces_via_java( JNIEnv* env, AndDictionaryCtxt* ctxt, const XP_U8* ptr, int nFaceBytes, int nFaces, XP_Bool isUTF8 ) { - const size_t facesBufSize = nFaces*16; - XP_UCHAR facesBuf[facesBufSize]; /* seems a reasonable upper bound... */ + XP_UCHAR facesBuf[nFaces*16]; /* seems a reasonable upper bound... */ int indx = 0; int offsets[nFaces]; int nBytes; @@ -268,7 +267,7 @@ splitFaces_via_java( JNIEnv* env, AndDictionaryCtxt* ctxt, const XP_U8* ptr, } deleteLocalRef( env, jstrs ); - XP_ASSERT( indx < facesBufSize ); + XP_ASSERT( indx < VSIZE(facesBuf) ); } deleteLocalRef( env, jstrarr ); @@ -573,7 +572,7 @@ makeDicts( MPFORMAL JNIEnv *env, DictMgrCtxt* dictMgr, JNIUtilCtxt* jniutil, jsize len = (*env)->GetArrayLength( env, jdicts ); XP_ASSERT( len == (*env)->GetArrayLength( env, jnames ) ); - for ( int ii = 0; ii <= MAX_NUM_PLAYERS; ++ii ) { + for ( int ii = 0; ii <= VSIZE(dicts->dicts); ++ii ) { DictionaryCtxt* dict = NULL; if ( ii < len ) { jobject jdict = (*env)->GetObjectArrayElement( env, jdicts, ii ); @@ -591,7 +590,7 @@ makeDicts( MPFORMAL JNIEnv *env, DictMgrCtxt* dictMgr, JNIUtilCtxt* jniutil, if ( 0 == ii ) { *dictp = dict; } else { - XP_ASSERT( ii-1 < MAX_NUM_PLAYERS ); + XP_ASSERT( ii-1 < VSIZE( dicts->dicts ) ); dicts->dicts[ii-1] = dict; } } diff --git a/xwords4/android/jni/andutils.c b/xwords4/android/jni/andutils.c index 9b141b67c..1df845e25 100644 --- a/xwords4/android/jni/andutils.c +++ b/xwords4/android/jni/andutils.c @@ -576,9 +576,9 @@ getJAddrRec( JNIEnv* env, CommsAddrRec* addr, jobject jaddr ) case COMMS_CONN_RELAY: addr->u.ip_relay.port = getInt( env, jaddr, "ip_relay_port" ); getString( env, jaddr, "ip_relay_hostName", addr->u.ip_relay.hostName, - MAX_HOSTNAME_LEN + 1 ); + VSIZE(addr->u.ip_relay.hostName) ); getString( env, jaddr, "ip_relay_invite", addr->u.ip_relay.invite, - MAX_INVITE_LEN + 1 ); + VSIZE(addr->u.ip_relay.invite) ); addr->u.ip_relay.seeksPublicRoom = getBool( env, jaddr, "ip_relay_seeksPublicRoom" ); addr->u.ip_relay.advertiseRoom = @@ -587,19 +587,19 @@ getJAddrRec( JNIEnv* env, CommsAddrRec* addr, jobject jaddr ) break; case COMMS_CONN_SMS: getString( env, jaddr, "sms_phone", addr->u.sms.phone, - MAX_PHONE_LEN + 1 ); + VSIZE(addr->u.sms.phone) ); // XP_LOGF( "%s: got SMS; phone=%s", __func__, addr->u.sms.phone ); addr->u.sms.port = getInt( env, jaddr, "sms_port" ); break; case COMMS_CONN_BT: getString( env, jaddr, "bt_hostName", addr->u.bt.hostName, - MAX_HOSTNAME_LEN + 1 ); + VSIZE(addr->u.bt.hostName) ); getString( env, jaddr, "bt_btAddr", addr->u.bt.btAddr.chars, - MAX_BTADDR_STR_LEN ); + VSIZE(addr->u.bt.btAddr.chars) ); break; case COMMS_CONN_P2P: getString( env, jaddr, "p2p_addr", addr->u.p2p.mac_addr, - MAX_P2P_MAC_LEN + 1 ); + VSIZE(addr->u.p2p.mac_addr) ); break; default: XP_ASSERT(0); diff --git a/xwords4/android/jni/utilwrapper.c b/xwords4/android/jni/utilwrapper.c index 3c1f35bb9..03eab0bf4 100644 --- a/xwords4/android/jni/utilwrapper.c +++ b/xwords4/android/jni/utilwrapper.c @@ -323,7 +323,7 @@ and_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why, XP_U16 when, { UTIL_CBK_HEADER("setTimer", "(III)V" ); - XP_ASSERT( why < NUM_TIMERS_PLUS_ONE ); + XP_ASSERT( why < VSIZE(util->timerStorage) ); TimerStorage* storage = &util->timerStorage[why]; storage->proc = proc; storage->closure = closure; @@ -388,7 +388,7 @@ and_dutil_getUserString( XW_DUtilCtxt* duc, XP_U16 stringCode ) XP_UCHAR* result = ""; DUTIL_CBK_HEADER("getUserString", "(I)Ljava/lang/String;" ); int index = stringCode - 1; /* see LocalizedStrIncludes.h */ - XP_ASSERT( index < N_AND_USER_STRINGS ); + XP_ASSERT( index < VSIZE( dutil->userStrings ) ); XP_ASSERT( 0 == (dutil->userStringsBits & (1 << index)) ); @@ -417,7 +417,7 @@ and_dutil_getUserQuantityString( XW_DUtilCtxt* duc, XP_U16 stringCode, XP_U16 qu XP_UCHAR* result = ""; DUTIL_CBK_HEADER("getUserQuantityString", "(II)Ljava/lang/String;" ); int index = stringCode - 1; /* see LocalizedStrIncludes.h */ - XP_ASSERT( index < N_AND_USER_STRINGS ); + XP_ASSERT( index < VSIZE( dutil->userStrings ) ); XP_UCHAR** ptrs; dutil->userStringsBits |= 1 << index; @@ -908,7 +908,7 @@ destroyDUtil( XW_DUtilCtxt** dutilp ) (*env)->DeleteGlobalRef( env, dutil->jdutil ); } - for ( int ii = 0; ii < N_AND_USER_STRINGS; ++ii ) { + for ( int ii = 0; ii < VSIZE(dutil->userStrings); ++ii ) { XP_UCHAR* ptr = dutil->userStrings[ii]; if ( NULL != ptr ) { if ( 0 == (dutil->userStringsBits & (1 << ii)) ) { diff --git a/xwords4/android/jni/xwjni.c b/xwords4/android/jni/xwjni.c index b1acd2474..52de70eca 100644 --- a/xwords4/android/jni/xwjni.c +++ b/xwords4/android/jni/xwjni.c @@ -329,8 +329,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_cleanGlobals } } -#define GI_INTS_SIZE 6 -static const SetInfo gi_ints[GI_INTS_SIZE] = { +static const SetInfo gi_ints[] = { ARR_MEMBER( CurGameInfo, nPlayers ) ,ARR_MEMBER( CurGameInfo, gameSeconds ) ,ARR_MEMBER( CurGameInfo, boardSize ) @@ -339,16 +338,14 @@ static const SetInfo gi_ints[GI_INTS_SIZE] = { ,ARR_MEMBER( CurGameInfo, forceChannel ) }; -#define GI_BOOLS_SIZE 4 -static const SetInfo gi_bools[GI_BOOLS_SIZE] = { +static const SetInfo gi_bools[] = { ARR_MEMBER( CurGameInfo, hintsNotAllowed ) ,ARR_MEMBER( CurGameInfo, timerEnabled ) ,ARR_MEMBER( CurGameInfo, allowPickTiles ) ,ARR_MEMBER( CurGameInfo, allowHintRect ) }; -#define PL_INTS_SIZE 2 -static const SetInfo pl_ints[PL_INTS_SIZE] = { +static const SetInfo pl_ints[] = { ARR_MEMBER( LocalPlayer, robotIQ ) ,ARR_MEMBER( LocalPlayer, secondsUsed ) }; @@ -357,10 +354,10 @@ static CurGameInfo* makeGI( MPFORMAL JNIEnv* env, jobject jgi ) { CurGameInfo* gi = (CurGameInfo*)XP_CALLOC( mpool, sizeof(*gi) ); - VDECL( XP_UCHAR, buf, 256 ); /* in case needs whole path */ + XP_UCHAR buf[256]; /* in case needs whole path */ - getInts( env, (void*)gi, jgi, gi_ints, GI_INTS_SIZE ); - getBools( env, (void*)gi, jgi, gi_bools, GI_BOOLS_SIZE ); + getInts( env, (void*)gi, jgi, gi_ints, VSIZE(gi_ints) ); + getBools( env, (void*)gi, jgi, gi_bools, VSIZE(gi_bools) ); /* Unlike on other platforms, gi is created without a call to game_makeNewGame, which sets gameID. So check here if it's still unset @@ -393,7 +390,7 @@ makeGI( MPFORMAL JNIEnv* env, jobject jgi ) jobject jlp = (*env)->GetObjectArrayElement( env, jplayers, ii ); XP_ASSERT( !!jlp ); - getInts( env, (void*)lp, jlp, pl_ints, PL_INTS_SIZE ); + getInts( env, (void*)lp, jlp, pl_ints, VSIZE(pl_ints) ); lp->isLocal = getBool( env, jlp, "isLocal" ); @@ -414,8 +411,7 @@ makeGI( MPFORMAL JNIEnv* env, jobject jgi ) return gi; } /* makeGI */ -#define NLI_INTS_SIZE 7 -static const SetInfo nli_ints[NLI_INTS_SIZE] = { +static const SetInfo nli_ints[] = { ARR_MEMBER( NetLaunchInfo, _conTypes ), ARR_MEMBER( NetLaunchInfo, lang ), ARR_MEMBER( NetLaunchInfo, forceChannel ), @@ -425,13 +421,11 @@ static const SetInfo nli_ints[NLI_INTS_SIZE] = { ARR_MEMBER( NetLaunchInfo, osVers ), }; -#define NLI_BOOLS_SIZE 1 -static const SetInfo nli_bools[NLI_BOOLS_SIZE] = { +static const SetInfo nli_bools[] = { ARR_MEMBER( NetLaunchInfo, isGSM ) }; -#define NLI_STRS_SIZE 7 -static const SetInfo nli_strs[NLI_STRS_SIZE] = { +static const SetInfo nli_strs[] = { ARR_MEMBER( NetLaunchInfo, dict ), ARR_MEMBER( NetLaunchInfo, gameName ), ARR_MEMBER( NetLaunchInfo, room ), @@ -444,17 +438,17 @@ static const SetInfo nli_strs[NLI_STRS_SIZE] = { static void loadNLI( JNIEnv* env, NetLaunchInfo* nli, jobject jnli ) { - getInts( env, (void*)nli, jnli, nli_ints, NLI_INTS_SIZE ); - getBools( env, (void*)nli, jnli, nli_bools, NLI_BOOLS_SIZE ); - getStrings( env, (void*)nli, jnli, nli_strs, NLI_STRS_SIZE ); + getInts( env, (void*)nli, jnli, nli_ints, VSIZE(nli_ints) ); + getBools( env, (void*)nli, jnli, nli_bools, VSIZE(nli_bools) ); + getStrings( env, (void*)nli, jnli, nli_strs, VSIZE(nli_strs) ); } static void setNLI( JNIEnv* env, jobject jnli, const NetLaunchInfo* nli ) { - setInts( env, jnli, (void*)nli, nli_ints, NLI_INTS_SIZE ); - setBools( env, jnli, (void*)nli, nli_bools, NLI_BOOLS_SIZE ); - setStrings( env, jnli, (void*)nli, nli_strs, NLI_STRS_SIZE ); + setInts( env, jnli, (void*)nli, nli_ints, VSIZE(nli_ints) ); + setBools( env, jnli, (void*)nli, nli_bools, VSIZE(nli_bools) ); + setStrings( env, jnli, (void*)nli, nli_strs, VSIZE(nli_strs) ); } static void @@ -462,8 +456,8 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi ) { // set fields - setInts( env, jgi, (void*)gi, gi_ints, GI_INTS_SIZE ); - setBools( env, jgi, (void*)gi, gi_bools, GI_BOOLS_SIZE ); + setInts( env, jgi, (void*)gi, gi_ints, VSIZE(gi_ints) ); + setBools( env, jgi, (void*)gi, gi_bools, VSIZE(gi_bools) ); setString( env, jgi, "dictName", gi->dictName ); @@ -482,7 +476,7 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi ) jobject jlp = (*env)->GetObjectArrayElement( env, jplayers, ii ); XP_ASSERT( !!jlp ); - setInts( env, jlp, (void*)lp, pl_ints, PL_INTS_SIZE ); + setInts( env, jlp, (void*)lp, pl_ints, VSIZE(pl_ints) ); setBool( env, jlp, "isLocal", lp->isLocal ); setString( env, jlp, "name", lp->name ); @@ -498,8 +492,7 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi ) } /* setJGI */ #ifdef COMMON_LAYOUT -#define BD_INTS_SIZE 16 -static const SetInfo bd_ints[BD_INTS_SIZE] = { +static const SetInfo bd_ints[] = { ARR_MEMBER( BoardDims, left ) ,ARR_MEMBER( BoardDims, top ) ,ARR_MEMBER( BoardDims, width ) @@ -521,13 +514,13 @@ static const SetInfo bd_ints[BD_INTS_SIZE] = { static void dimsJToC( JNIEnv* env, BoardDims* out, jobject jdims ) { - getInts( env, (void*)out, jdims, bd_ints, BD_INTS_SIZE ); + getInts( env, (void*)out, jdims, bd_ints, VSIZE(bd_ints) ); } static void dimsCtoJ( JNIEnv* env, jobject jdims, const BoardDims* in ) { - setInts( env, jdims, (void*)in, bd_ints, BD_INTS_SIZE ); + setInts( env, jdims, (void*)in, bd_ints, VSIZE(bd_ints) ); } #endif @@ -1256,7 +1249,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1zoom XWJNI_START(); XP_Bool canInOut[2]; result = board_zoom( state->game.board, zoomBy, canInOut ); - VDECL( jboolean, canZoom, 2 ) = { canInOut[0], canInOut[1] }; + jboolean canZoom[2] = { canInOut[0], canInOut[1] }; setBoolArray( env, jCanZoom, VSIZE(canZoom), canZoom ); XWJNI_END(); return result; @@ -1791,7 +1784,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddrs XWJNI_START(); XP_ASSERT( state->game.comms ); if ( !!state->game.comms ) { - VDECL( CommsAddrRec, addrs, MAX_NUM_PLAYERS ); + CommsAddrRec addrs[MAX_NUM_PLAYERS]; XP_U16 count = VSIZE(addrs); comms_getAddrs( state->game.comms, addrs, &count ); @@ -1884,7 +1877,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize for ( XP_U32 st = 0; addr_iter( &addr, &typ, &st ); ) { switch( typ ) { case COMMS_CONN_RELAY: { - VDECL( XP_UCHAR, buf, 128 ); + XP_UCHAR buf[128]; XP_U16 len = VSIZE(buf); if ( comms_getRelayID( comms, buf, &len ) ) { XP_ASSERT( '\0' == buf[len-1] ); /* failed! */ @@ -1897,7 +1890,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize case COMMS_CONN_BT: case COMMS_CONN_P2P: case COMMS_CONN_SMS: { - VDECL( CommsAddrRec, addrs, MAX_NUM_PLAYERS ); + CommsAddrRec addrs[MAX_NUM_PLAYERS]; XP_U16 count = VSIZE(addrs); comms_getAddrs( comms, addrs, &count ); @@ -2017,15 +2010,12 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1getGi XWJNI_END(); } -#define GSI_INTS_SIZE 3 -static const SetInfo gsi_ints[GSI_INTS_SIZE] = { +static const SetInfo gsi_ints[] = { ARR_MEMBER( GameStateInfo, visTileCount ), ARR_MEMBER( GameStateInfo, nPendingMessages ), ARR_MEMBER( GameStateInfo, trayVisState ), }; - -#define GSI_BOOLS_SIZE 10 -static const SetInfo gsi_bools[GSI_BOOLS_SIZE] = { +static const SetInfo gsi_bools[] = { ARR_MEMBER( GameStateInfo,canHint ), ARR_MEMBER( GameStateInfo, canUndo ), ARR_MEMBER( GameStateInfo, canRedo ), @@ -2046,8 +2036,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1getState GameStateInfo info; game_getState( &state->game, &info ); - setInts( env, jgsi, (void*)&info, gsi_ints, GSI_INTS_SIZE ); - setBools( env, jgsi, (void*)&info, gsi_bools, GSI_BOOLS_SIZE ); + setInts( env, jgsi, (void*)&info, gsi_ints, VSIZE(gsi_ints) ); + setBools( env, jgsi, (void*)&info, gsi_bools, VSIZE(gsi_bools) ); XWJNI_END(); } @@ -2340,7 +2330,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getCounts LengthsArray lens; if ( 0 < dict_countWords( &iter, &lens ) ) { XP_ASSERT( sizeof(jint) == sizeof(lens.lens[0]) ); - result = makeIntArray( env, MAX_COLS_DICT+1, (jint*)&lens.lens, + result = makeIntArray( env, VSIZE(lens.lens), (jint*)&lens.lens, sizeof(lens.lens[0]) ); } } @@ -2358,7 +2348,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getPrefixes XP_U16 depth = data->depth; for ( int ii = 0; ii < data->idata.count; ++ii ) { - VDECL( XP_UCHAR, buf, 16 ); + XP_UCHAR buf[16]; (void)dict_tilesToString( data->dict, &data->idata.prefixes[depth*ii], depth, buf, VSIZE(buf) ); @@ -2394,7 +2384,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1nthWord DictIterData* data = (DictIterData*)closure; if ( NULL != data ) { if ( dict_getNthWord( &data->iter, nn, data->depth, &data->idata ) ) { - VDECL( XP_UCHAR, buf, 64 ); + XP_UCHAR buf[64]; dict_wordToString( &data->iter, buf, VSIZE(buf) ); result = (*env)->NewStringUTF( env, buf ); } diff --git a/xwords4/common/board.c b/xwords4/common/board.c index f29ab9598..d3f832c8c 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -2254,7 +2254,7 @@ figureScale( BoardCtxt* board, XP_U16 count, XP_U16 dimension, ScrollData* sd ) sd->lastVisible = count - board->zoomCount + sd->offset - 1; - if ( figureDims( sd->dims, MAX_COLS, nVis, + if ( figureDims( sd->dims, VSIZE(sd->dims), nVis, scale, spares ) ) { board_invalAll( board ); } @@ -2344,7 +2344,7 @@ figureBoardRect( BoardCtxt* board ) vsd->lastVisible = nVisible + vsd->offset - 1; - if ( figureDims( vsd->dims, MAX_COLS, nVisible, + if ( figureDims( vsd->dims, VSIZE(vsd->dims), nVisible, vsd->scale, extra ) ) { board_invalAll( board ); } diff --git a/xwords4/common/boarddrw.c b/xwords4/common/boarddrw.c index ee38365ec..f8f5bb495 100644 --- a/xwords4/common/boarddrw.c +++ b/xwords4/common/boarddrw.c @@ -395,7 +395,7 @@ drawCell( BoardCtxt* board, const XP_U16 col, const XP_U16 row, XP_Bool skipBlan /* This 'while' is only here so I can 'break' below */ while ( board->trayVisState == TRAY_HIDDEN || !rectContainsRect( &board->trayBounds, &cellRect ) ) { - VDECL(XP_UCHAR, ch, 4) = {'\0'}; + XP_UCHAR ch[4] = {'\0'}; XP_S16 owner = -1; XP_Bool invert = XP_FALSE; XP_Bitmaps bitmaps; @@ -470,7 +470,7 @@ drawCell( BoardCtxt* board, const XP_U16 col, const XP_U16 row, XP_Bool skipBlan tile, value, owner, bonus, hintAtts, flags ); #ifdef LOG_CELL_DRAW - VDECL( XP_UCHAR, buf, 64 ); + XP_UCHAR buf[64]; XP_LOGF( "%s(col=%d, row=%d, flags=%s)=>%s", __func__, col, row, formatFlags(buf, VSIZE(buf), flags), success?"true":"false" ); #endif diff --git a/xwords4/common/comms.c b/xwords4/common/comms.c index a41efc2a7..2d3da8487 100644 --- a/xwords4/common/comms.c +++ b/xwords4/common/comms.c @@ -734,8 +734,8 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util, } if ( STREAM_VERS_DISABLEDS <= version ) { - for ( int typ = 0; typ < COMMS_CONN_NTYPES; ++typ ) { - for ( int ii = 0; ii < 2; ++ii ) { + for ( int typ = 0; typ < VSIZE(comms->disableds); ++typ ) { + for ( int ii = 0; ii < VSIZE(comms->disableds[0]); ++ii ) { comms->disableds[typ][ii] = 0 != stream_getBits( stream, 1 ); } } @@ -929,8 +929,8 @@ comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream, stream_putBytes( stream, msg->msg, msg->len ); } - for ( int typ = 0; typ < COMMS_CONN_NTYPES; ++typ ) { - for ( int ii = 0; ii < 2; ++ii ) { + for ( int typ = 0; typ < VSIZE(comms->disableds); ++typ ) { + for ( int ii = 0; ii < VSIZE(comms->disableds[0]); ++ii ) { stream_putBits( stream, 1, comms->disableds[typ][ii] ? 1 : 0 ); } } diff --git a/xwords4/common/comms.h b/xwords4/common/comms.h index 400d7fd41..31ddfae82 100644 --- a/xwords4/common/comms.h +++ b/xwords4/common/comms.h @@ -71,8 +71,7 @@ typedef enum { /* on Palm BtLibDeviceAddressType is a 48-bit quantity. Linux's typeis the same size. Goal is something all platforms support */ typedef struct XP_BtAddr { XP_U8 bits[6]; } XP_BtAddr; -#define MAX_BTADDR_STR_LEN 18 -typedef struct XP_BtAddrStr { XP_UCHAR chars[MAX_BTADDR_STR_LEN]; } XP_BtAddrStr; +typedef struct XP_BtAddrStr { XP_UCHAR chars[18]; } XP_BtAddrStr; #ifdef COMMS_HEARTBEAT # define IF_CH(a) a, diff --git a/xwords4/common/comtypes.h b/xwords4/common/comtypes.h index 5e256aaa6..2e916c7c4 100644 --- a/xwords4/common/comtypes.h +++ b/xwords4/common/comtypes.h @@ -40,10 +40,7 @@ # endif #endif -#define VSIZE(_arr) __name_of ## _arr -#define VDECL(_type, _arr, _count) \ - enum {VSIZE(_arr) = _count}; \ - _type _arr[VSIZE(_arr)] +#define VSIZE(arr) (sizeof(arr)/sizeof(arr[0])) #ifndef MAX_ROWS # define MAX_ROWS 16 diff --git a/xwords4/common/dbgutil.c b/xwords4/common/dbgutil.c index a99f046de..d6bbec783 100644 --- a/xwords4/common/dbgutil.c +++ b/xwords4/common/dbgutil.c @@ -97,7 +97,7 @@ dbg_logstream( const XWStreamCtxt* stream, const char* func, int line ) stream_copyBits( stream, end, NULL, &len ); XP_U8 buf[len]; stream_copyBits( stream, end, buf, &len ); - VDECL( char, comment, 128 ); + char comment[128]; XP_SNPRINTF( comment, VSIZE(comment), "%s line %d", func, line ); LOG_HEX( buf, len, comment ); } else { diff --git a/xwords4/common/dictmgr.c b/xwords4/common/dictmgr.c index 87d08c66e..ebedb7238 100644 --- a/xwords4/common/dictmgr.c +++ b/xwords4/common/dictmgr.c @@ -107,7 +107,7 @@ dmgr_put( DictMgrCtxt* dmgr, const XP_UCHAR* key, DictionaryCtxt* dict ) XP_S16 loc = findFor( dmgr, key ); if ( NOT_FOUND == loc ) { /* reuse the last one */ - moveToFront( dmgr, DMGR_MAX_DICTS - 1 ); + moveToFront( dmgr, VSIZE(dmgr->pairs) - 1 ); DictPair* pair = dmgr->pairs; /* the head */ dict_unref( pair->dict ); pair->dict = dict_ref( dict ); @@ -126,7 +126,7 @@ findFor( DictMgrCtxt* dmgr, const XP_UCHAR* key ) { XP_S16 result = NOT_FOUND; XP_U16 ii; - for ( ii = 0; ii < DMGR_MAX_DICTS; ++ii ) { + for ( ii = 0; ii < VSIZE(dmgr->pairs); ++ii ) { DictPair* pair = &dmgr->pairs[ii]; if ( !!pair->key && 0 == XP_STRCMP( key, pair->key ) ) { result = ii; @@ -151,7 +151,7 @@ static void printInOrder( const DictMgrCtxt* dmgr ) { XP_U16 ii; - for ( ii = 0; ii < DMGR_MAX_DICTS; ++ii ) { + for ( ii = 0; ii < VSIZE(dmgr->pairs); ++ii ) { const XP_UCHAR* name = dmgr->pairs[ii].key; XP_LOGF( "%s: dict[%d]: %s", __func__, ii, (NULL == name)? "" : name ); diff --git a/xwords4/common/dictnry.c b/xwords4/common/dictnry.c index 25d6c79ed..c72f88821 100644 --- a/xwords4/common/dictnry.c +++ b/xwords4/common/dictnry.c @@ -454,7 +454,7 @@ dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream ) XP_U16 maxCountBits, maxValueBits; XP_U16 ii, nSpecials; XP_UCHAR* localTexts[32]; - VDECL( XP_U8, utf8, MAX_UNIQUE_TILES ); + XP_U8 utf8[MAX_UNIQUE_TILES]; XP_ASSERT( !dict->destructor ); dict->destructor = common_destructor; diff --git a/xwords4/common/draw.h b/xwords4/common/draw.h index b840691c9..81027ac04 100644 --- a/xwords4/common/draw.h +++ b/xwords4/common/draw.h @@ -223,8 +223,6 @@ typedef struct DrawCtxVTable { const XP_Rect* rect, void** closure ); #endif #ifndef DRAW_LINK_DIRECT - - void* tableEnd; } DrawCtxVTable; /* */ #endif diff --git a/xwords4/common/engine.c b/xwords4/common/engine.c index 78043314a..b0b9c99be 100644 --- a/xwords4/common/engine.c +++ b/xwords4/common/engine.c @@ -75,8 +75,7 @@ typedef struct MoveIterationData { /* one bit per tile that's possible here *\/ */ typedef XP_U32 CrossBits; -#define NUM_CBITS 2 -typedef struct Crosscheck { CrossBits bits[NUM_CBITS]; } Crosscheck; +typedef struct Crosscheck { CrossBits bits[2]; } Crosscheck; struct EngineCtxt { const ModelCtxt* model; @@ -278,7 +277,7 @@ print_savedMoves( const EngineCtxt* engine, const char* label ) { int ii; int pos = 0; - VDECL(char, buf, (NUM_SAVED_ENGINE_MOVES*10) + 3) = {0}; + char buf[(NUM_SAVED_ENGINE_MOVES*10) + 3] = {0}; for ( ii = 0; ii < engine->nMovesToSave; ++ii ) { if ( 0 < engine->miData.savedMoves[ii].score ) { pos += XP_SNPRINTF( &buf[pos], VSIZE(buf)-pos, "[%d]: %d; ", @@ -726,7 +725,8 @@ figureCrosschecks( EngineCtxt* engine, XP_U16 x, XP_U16 y, XP_U16* scoreP, XP_ASSERT( tile < MAX_UNIQUE_TILES ); tiles[0] = tile; if ( lookup( dict, in_edge, tiles, 0, tilesAfter ) ) { - XP_ASSERT( (tile >> 5) < NUM_CBITS ); + XP_ASSERT( (tile >> 5) + < (VSIZE(check->bits)) ); check->bits[tile>>5] |= (1L << (tile & 0x1F)); } diff --git a/xwords4/common/model.c b/xwords4/common/model.c index cd6e8e7c4..1c6788e10 100644 --- a/xwords4/common/model.c +++ b/xwords4/common/model.c @@ -551,7 +551,7 @@ model_setPlayerDicts( ModelCtxt* model, const PlayerDicts* dicts ) #ifdef DEBUG DictionaryCtxt* gameDict = model_getDictionary( model ); #endif - for ( ii = 0; ii < MAX_NUM_PLAYERS; ++ii ) { + for ( ii = 0; ii < VSIZE(dicts->dicts); ++ii ) { DictionaryCtxt* oldDict = model->vol.dicts.dicts[ii]; DictionaryCtxt* newDict = dicts->dicts[ii]; if ( oldDict != newDict ) { @@ -573,7 +573,7 @@ model_getDictionary( const ModelCtxt* model ) { XP_U16 ii; DictionaryCtxt* result = model->vol.dict; - for ( ii = 0; !result && ii < MAX_NUM_PLAYERS; ++ii ) { + for ( ii = 0; !result && ii < VSIZE(model->vol.dicts.dicts); ++ii ) { result = model->vol.dicts.dicts[ii]; } return result; @@ -594,7 +594,7 @@ static void model_unrefDicts( ModelCtxt* model ) { XP_U16 ii; - for ( ii = 0; ii < MAX_NUM_PLAYERS; ++ii ) { + for ( ii = 0; ii < VSIZE(model->vol.dicts.dicts); ++ii ) { dict_unref( model->vol.dicts.dicts[ii] ); model->vol.dicts.dicts[ii] = NULL; } @@ -611,7 +611,7 @@ getPendingTileFor( const ModelCtxt* model, XP_U16 turn, XP_U16 col, XP_U16 row, const PendingTile* pendings; XP_U16 ii; - XP_ASSERT( turn < MAX_NUM_PLAYERS ); + XP_ASSERT( turn < VSIZE(model->players) ); player = &model->players[turn]; pendings = player->pendingTiles; @@ -2064,7 +2064,7 @@ printMovePre( ModelCtxt* model, XP_U16 XP_UNUSED(moveN), const StackEntry* entry { if ( entry->moveType != ASSIGN_TYPE ) { const XP_UCHAR* format; - VDECL( XP_UCHAR, buf, 64 ); + XP_UCHAR buf[64]; XP_UCHAR traybuf[MAX_TRAY_TILES+1]; MovePrintClosure* closure = (MovePrintClosure*)p_closure; XWStreamCtxt* stream = closure->stream; @@ -2293,7 +2293,7 @@ scoreLastMove( ModelCtxt* model, MoveInfo* moveInfo, XP_U16 howMany, model_destroy( tmpModel ); lmi->score = score; - XP_SNPRINTF( lmi->word, MAX_COLS+1, "%s", data.word ); + XP_SNPRINTF( lmi->word, VSIZE(lmi->word), "%s", data.word ); } /* scoreLastMove */ static XP_U16 diff --git a/xwords4/common/server.c b/xwords4/common/server.c index 22e4a2249..d898a0f1f 100644 --- a/xwords4/common/server.c +++ b/xwords4/common/server.c @@ -493,7 +493,7 @@ static void cleanupServer( ServerCtxt* server ) { XP_U16 ii; - for ( ii = 0; ii < MAX_NUM_PLAYERS; ++ii ){ + for ( ii = 0; ii < VSIZE(server->players); ++ii ){ ServerPlayer* player = &server->players[ii]; if ( player->engine != NULL ) { engine_destroy( player->engine ); @@ -1346,8 +1346,8 @@ client_readInitialMessage( ServerCtxt* server, XWStreamCtxt* stream ) XP_U32 gameID; PoolContext* pool; #ifdef STREAM_VERS_BIGBOARD - VDECL( XP_UCHAR, rmtDictName,128 ); - VDECL( XP_UCHAR, rmtDictSum, 64 ); + XP_UCHAR rmtDictName[128]; + XP_UCHAR rmtDictSum[64]; #endif /* version; any dependencies here? */ @@ -3172,11 +3172,10 @@ server_figureFinishBonus( const ServerCtxt* server, XP_U16 turn ) if ( 0 < nOthers ) { Tile tile; const DictionaryCtxt* dict = model_getDictionary( server->vol.model ); - const size_t numFaces = dict_numTileFaces( dict ); - XP_U16 counts[numFaces]; + XP_U16 counts[dict_numTileFaces( dict )]; XP_MEMSET( counts, 0, sizeof(counts) ); model_countAllTrayTiles( server->vol.model, counts, turn ); - for ( tile = 0; tile < numFaces; ++tile ) { + for ( tile = 0; tile < VSIZE(counts); ++tile ) { XP_U16 count = counts[tile]; if ( 0 < count ) { result += count * dict_getTileValue( dict, tile ); diff --git a/xwords4/common/smsproto.c b/xwords4/common/smsproto.c index 8a66716ae..b000696ff 100644 --- a/xwords4/common/smsproto.c +++ b/xwords4/common/smsproto.c @@ -668,7 +668,7 @@ restorePartials( SMSProto* state ) && PARTIALS_FORMAT == stream_getU8( stream ) ) { int nFromPhones = stream_getU8( stream ); for ( int ii = 0; ii < nFromPhones; ++ii ) { - VDECL( XP_UCHAR, phone, 32 ); + XP_UCHAR phone[32]; (void)stringFromStreamHere( stream, phone, VSIZE(phone) ); int nMsgIDs = stream_getU8( stream ); XP_LOGF( "%s(): got %d message records for phone %s", __func__, @@ -861,7 +861,7 @@ smsproto_runTests( MPFORMAL XW_DUtilCtxt* dutil ) SMSProto* state = smsproto_init( mpool, dutil ); const int smallSiz = 20; - VDECL(char*, phones, 4) = {"1234", "3456", "5467", "9877"}; + const char* phones[] = {"1234", "3456", "5467", "9877"}; const char* buf = "asoidfaisdfoausdf aiousdfoiu asodfu oiuasdofi oiuaosiduf oaisudf oiasd f" ";oiaisdjfljiojaklj asdlkjalskdjf laksjd flkjasdlfkj aldsjkf lsakdjf lkjsad flkjsd fl;kj" "asdifaoaosidfoiauosidufoaus doifuoaiusdoifu aoisudfoaisd foia sdoifuasodfu aosiud foiuas odfiu asd" @@ -869,7 +869,7 @@ smsproto_runTests( MPFORMAL XW_DUtilCtxt* dutil ) ; const XP_Bool forceOld = XP_TRUE; - VDECL( SMSMsgArray*, arrs, VSIZE(phones) ); + SMSMsgArray* arrs[VSIZE(phones)]; for ( int ii = 0; ii < VSIZE(arrs); ++ii ) { arrs[ii] = NULL; } diff --git a/xwords4/common/tray.c b/xwords4/common/tray.c index b3081a19f..1eb926c07 100644 --- a/xwords4/common/tray.c +++ b/xwords4/common/tray.c @@ -409,7 +409,7 @@ getSelTiles( const BoardCtxt* board, TileBit selBits, TrayTileSet* selTiles ) for ( index = 0; selBits != 0; selBits >>= 1, ++index ) { if ( 0 != (selBits & 0x01) ) { Tile tile = model_getPlayerTile( model, turn, index ); - XP_ASSERT( nTiles < MAX_TRAY_TILES ); + XP_ASSERT( nTiles < VSIZE(selTiles->tiles) ); selTiles->tiles[nTiles++] = tile; } } diff --git a/xwords4/linux/cursesdraw.c b/xwords4/linux/cursesdraw.c index 602976d70..7e7eb2eca 100644 --- a/xwords4/linux/cursesdraw.c +++ b/xwords4/linux/cursesdraw.c @@ -149,7 +149,7 @@ curses_draw_measureRemText( DrawCtx* XP_UNUSED(dctx), XP_U16* width, XP_U16* height ) { char buf[64]; - VDECL( char*, lines, 2 ) = {0}; + char* lines[2] = {0}; formatRemText( nTilesLeft, rect, buf, lines ); *width = 0; @@ -170,7 +170,7 @@ curses_draw_drawRemText( DrawCtx* p_dctx, const XP_Rect* rInner, CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx; char buf[32]; - VDECL( char*, lines, 2 ) = {0}; + char* lines[2] = {0}; formatRemText( nTilesLeft, rInner, buf, lines ); int ii; for ( ii = 0; ii < VSIZE(lines) && !!lines[ii]; ++ii ) { @@ -270,7 +270,7 @@ curses_draw_measureScoreText( DrawCtx* XP_UNUSED(p_dctx), XP_U16* width, XP_U16* height ) { XP_UCHAR buf[100]; - VDECL( char*, lines, 3 ) = {0}; + char* lines[3] = {0}; formatScoreText( buf, dsi, rect, lines ); int ii; @@ -295,7 +295,7 @@ curses_draw_score_drawPlayer( DrawCtx* p_dctx, const XP_Rect* rInner, curses_draw_clearRect( p_dctx, rOuter ); /* print the name and turn/remoteness indicator */ - VDECL( char*, lines, 3 ) = {0}; + char* lines[3] = {0}; formatScoreText( buf, dsi, rInner, lines ); int ii; for ( ii = 0; ii < VSIZE(lines) && !!lines[ii]; ++ii ) { diff --git a/xwords4/linux/cursesletterask.c b/xwords4/linux/cursesletterask.c index 74bd902d9..1dc5d0e19 100644 --- a/xwords4/linux/cursesletterask.c +++ b/xwords4/linux/cursesletterask.c @@ -57,7 +57,7 @@ curses_askLetter( CursesAppGlobals* globals, XP_UCHAR* query, short curSelButton = 1; /* force draw by being different */ short maxWidth; short numCtlButtons; - VDECL( const char*, ctlButtons, 2 ) = { "Ok", "Cancel" }; + const char* ctlButtons[] = { "Ok", "Cancel" }; XP_Bool dismissed = XP_FALSE; FormatInfo fi; int len; diff --git a/xwords4/linux/cursesmain.c b/xwords4/linux/cursesmain.c index 43598a967..4ae3ab22a 100644 --- a/xwords4/linux/cursesmain.c +++ b/xwords4/linux/cursesmain.c @@ -221,7 +221,7 @@ cursesUserError( CursesAppGlobals* globals, const char* format, ... ) vsprintf( buf, format, ap ); - VDECL( const char*, buttons, 1 ) = {"OK"}; + const char* buttons[] = {"OK"}; (void)cursesask( globals, buf, VSIZE(buttons), buttons ); va_end(ap); @@ -285,7 +285,7 @@ ask_move( gpointer data ) { CursesAppGlobals* globals = (CursesAppGlobals*)data; CommonGlobals* cGlobals = &globals->cGlobals; - VDECL( const char*, answers, 3 ) = {"Ok", "Cancel", NULL}; + const char* answers[] = {"Ok", "Cancel", NULL}; if (0 == cursesask(globals, cGlobals->question, VSIZE(answers)-1, answers) ) { BoardCtxt* board = cGlobals->game.board; @@ -304,7 +304,7 @@ curses_util_notifyMove( XW_UtilCtxt* uc, XWStreamCtxt* stream ) CursesAppGlobals* globals = (CursesAppGlobals*)uc->closure; CommonGlobals* cGlobals = &globals->cGlobals; XP_U16 len = stream_getSize( stream ); - XP_ASSERT( len <= QUESTION_LEN ); + XP_ASSERT( len <= VSIZE(cGlobals->question) ); stream_getBytes( stream, cGlobals->question, len ); (void)g_idle_add( ask_move, globals ); } /* curses_util_userQuery */ @@ -315,7 +315,7 @@ ask_trade( gpointer data ) CursesAppGlobals* globals = (CursesAppGlobals*)data; CommonGlobals* cGlobals = &globals->cGlobals; - VDECL( const char*, buttons, 2 ) = { "Ok", "Cancel" }; + const char* buttons[] = { "Ok", "Cancel" }; if (0 == cursesask( globals, cGlobals->question, VSIZE(buttons), buttons ) ) { BoardCtxt* board = cGlobals->game.board; if ( board_commitTurn( board, XP_TRUE, XP_TRUE, NULL ) ) { @@ -353,7 +353,7 @@ cursesShowFinalScores( CursesAppGlobals* globals ) text = strFromStream( stream ); - VDECL( const char*, buttons, 1 ) = { "Ok" }; + const char* buttons[] = { "Ok" }; (void)cursesask( globals, text, VSIZE(buttons), buttons ); free( text ); @@ -366,7 +366,7 @@ curses_util_informMove( XW_UtilCtxt* uc, XP_S16 XP_UNUSED(turn), { CursesAppGlobals* globals = (CursesAppGlobals*)uc->closure; char* question = strFromStream( expl ); - VDECL( const char*, buttons, 1 ) = { "Ok" }; + const char* buttons[] = { "Ok" }; (void)cursesask( globals, question, VSIZE(buttons), buttons ); free( question ); } @@ -1412,7 +1412,7 @@ curses_util_remSelected( XW_UtilCtxt* uc ) text = strFromStream( stream ); - VDECL( const char*, buttons, 1 ) = { "Ok" }; + const char* buttons[] = { "Ok" }; (void)cursesask( globals, text, VSIZE(buttons), buttons ); free( text ); @@ -1795,7 +1795,7 @@ cursesErrorMsgRcvd( void* closure, const XP_UCHAR* msg ) } else { g_free( globals->lastErr ); globals->lastErr = g_strdup( msg ); - VDECL( const char*, buttons, 1 ) = { "Ok" }; + const char* buttons[] = { "Ok" }; (void)cursesask( globals, msg, VSIZE(buttons), buttons ); } } @@ -2015,7 +2015,7 @@ cursesmain( XP_Bool isServer, LaunchParams* params ) } #ifdef XWFEATURE_SMS - VDECL( gchar, buf, 32 ); + gchar buf[32]; const gchar* myPhone = params->connInfo.sms.myPhone; if ( !!myPhone ) { db_store( params->pDb, KEY_SMSPHONE, myPhone ); @@ -2023,7 +2023,7 @@ cursesmain( XP_Bool isServer, LaunchParams* params ) params->connInfo.sms.myPhone = myPhone = buf; } XP_U16 myPort = params->connInfo.sms.port; - VDECL( gchar, portbuf, 8 ); + gchar portbuf[8]; if ( 0 < myPort ) { sprintf( portbuf, "%d", myPort ); db_store( params->pDb, KEY_SMSPORT, portbuf ); diff --git a/xwords4/linux/gamesdb.c b/xwords4/linux/gamesdb.c index 2aba5e9e9..a2b53e204 100644 --- a/xwords4/linux/gamesdb.c +++ b/xwords4/linux/gamesdb.c @@ -222,7 +222,7 @@ summarize( CommonGlobals* cGlobals ) // gchar* connvia = "local"; gchar connvia[128] = {0}; - VDECL( XP_UCHAR, relayID, 32 ) = {0}; + XP_UCHAR relayID[32] = {0}; if ( !!game->comms ) { nMissing = server_getMissingPlayers( game->server ); @@ -341,7 +341,7 @@ getRelayIDsToRowsMap( sqlite3* pDb ) switch( sqlite3_step( ppStmt ) ) { case SQLITE_ROW: /* have data */ { - VDECL( XP_UCHAR, relayID, 32 ); + XP_UCHAR relayID[32]; int len = VSIZE(relayID); getColumnText( ppStmt, 0, relayID, &len ); gpointer key = g_strdup( relayID ); diff --git a/xwords4/linux/gtkboard.c b/xwords4/linux/gtkboard.c index f954f088c..4d439f98c 100644 --- a/xwords4/linux/gtkboard.c +++ b/xwords4/linux/gtkboard.c @@ -1113,7 +1113,7 @@ change_dictionary( GtkWidget* XP_UNUSED(widget), GtkGameGlobals* globals ) CommonGlobals* cGlobals = &globals->cGlobals; LaunchParams* params = cGlobals->params; GSList* dicts = listDicts( params ); - VDECL( gchar, buf, 265 ); + gchar buf[265]; gchar* name = gtkaskdict( dicts, buf, VSIZE(buf) ); if ( !!name ) { DictionaryCtxt* dict = @@ -1662,7 +1662,7 @@ send_invites( CommonGlobals* cGlobals, XP_U16 nPlayers, #endif if ( '\0' != addrs->u.sms.phone[0] && 0 < addrs->u.sms.port ) { - VDECL( gchar, gameName, 64 ); + gchar gameName[64]; snprintf( gameName, VSIZE(gameName), "Game %d", cGlobals->gi->gameID ); linux_sms_invite( cGlobals->params, &nli, @@ -1844,7 +1844,7 @@ ask_password( gpointer data ) { GtkGameGlobals* globals = (GtkGameGlobals*)data; CommonGlobals* cGlobals = &globals->cGlobals; - VDECL( XP_UCHAR, buf, 32 ); + XP_UCHAR buf[32]; XP_U16 len = VSIZE(buf); if ( gtkpasswdask( cGlobals->askPassName, buf, &len ) ) { BoardCtxt* board = cGlobals->game.board; @@ -2003,7 +2003,7 @@ gtk_util_informNetDict( XW_UtilCtxt* uc, XP_LangCode XP_UNUSED(lang), { if ( 0 != strcmp( oldName, newName ) ) { GtkGameGlobals* globals = (GtkGameGlobals*)uc->closure; - VDECL( gchar, buf, 512 ); + gchar buf[512]; int offset = snprintf( buf, VSIZE(buf), "dict changing from %s to %s (sum=%s).", oldName, newName, newSum ); @@ -2298,7 +2298,7 @@ gtk_util_showChat( XW_UtilCtxt* uc, const XP_UCHAR* const msg, XP_S16 from, XP_U32 timestamp ) { GtkGameGlobals* globals = (GtkGameGlobals*)uc->closure; - VDECL( XP_UCHAR, buf, 1024 ); + XP_UCHAR buf[1024]; XP_UCHAR* name = ""; if ( 0 <= from ) { name = globals->cGlobals.gi->players[from].name; @@ -2338,7 +2338,7 @@ gtk_util_playerScoreHeld( XW_UtilCtxt* uc, XP_U16 player ) LastMoveInfo lmi; if ( model_getPlayersLastScore( globals->cGlobals.game.model, player, &lmi ) ) { - VDECL( XP_UCHAR, buf, 128 ); + XP_UCHAR buf[128]; formatLMI( &lmi, buf, VSIZE(buf) ); (void)gtkask( globals->window, buf, GTK_BUTTONS_OK, NULL ); } @@ -2393,7 +2393,7 @@ gtk_util_notifyMove( XW_UtilCtxt* uc, XWStreamCtxt* stream ) /* XP_Bool freeMe = XP_FALSE; */ XP_U16 len = stream_getSize( stream ); - XP_ASSERT( len <= QUESTION_LEN ); + XP_ASSERT( len <= VSIZE(cGlobals->question) ); stream_getBytes( stream, cGlobals->question, len ); (void)g_idle_add( ask_move, globals ); diff --git a/xwords4/linux/gtkconnsdlg.c b/xwords4/linux/gtkconnsdlg.c index 24078d2a7..cd0bd74e6 100644 --- a/xwords4/linux/gtkconnsdlg.c +++ b/xwords4/linux/gtkconnsdlg.c @@ -67,7 +67,7 @@ conTypeToPageNum( const GtkConnsState* state, CommsConnType conType ) pageNum = ii; break; } - XP_ASSERT( ii < COMMS_CONN_NTYPES ); + XP_ASSERT( ii < VSIZE(state->pageData) ); } return pageNum; } diff --git a/xwords4/linux/gtkdraw.c b/xwords4/linux/gtkdraw.c index cd90df35d..b222dbd92 100644 --- a/xwords4/linux/gtkdraw.c +++ b/xwords4/linux/gtkdraw.c @@ -745,7 +745,7 @@ gtkDrawTileImpl( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* textP, XP_Bool clearBack ) { GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; - VDECL( XP_UCHAR, numbuf, 3 ); + XP_UCHAR numbuf[3]; XP_Rect insetR = *rect; XP_Bool isCursor = (flags & CELL_ISCURSOR) != 0; XP_Bool valHidden = (flags & CELL_VALHIDDEN) != 0; @@ -1113,13 +1113,13 @@ formatScoreText( PangoLayout* layout, XP_UCHAR* buf, XP_U16 bufLen, XP_U16 nTilesLeft = dsi->nTilesLeft; XP_Bool isTurn = dsi->isTurn; XP_S16 maxWidth = bounds->width; - VDECL( XP_UCHAR, numBuf, 16 ); + XP_UCHAR numBuf[16]; int width, height; *nLines = 1; XP_SNPRINTF( numBuf, VSIZE(numBuf), "%d", score ); if ( (nTilesLeft < MAX_TRAY_TILES) && (nTilesLeft > 0) ) { - VDECL( XP_UCHAR, tmp, 10 ); + XP_UCHAR tmp[10]; XP_SNPRINTF( tmp, VSIZE(tmp), ":%d", nTilesLeft ); (void)XP_STRCAT( numBuf, tmp ); } @@ -1134,7 +1134,7 @@ formatScoreText( PangoLayout* layout, XP_UCHAR* buf, XP_U16 bufLen, } /* Reformat name + ':' until it fits */ - VDECL( XP_UCHAR, name, MAX_SCORE_LEN ) = { 0 }; + XP_UCHAR name[MAX_SCORE_LEN] = { 0 }; if ( isTurn && maxWidth > 0 ) { XP_U16 len = 1 + XP_STRLEN( dsi->name ); /* +1 for "\0" */ if ( scoreIsVertical ) { @@ -1181,7 +1181,7 @@ gtk_draw_measureScoreText( DrawCtx* p_dctx, const XP_Rect* bounds, XP_U16* widthP, XP_U16* heightP ) { GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; - VDECL( XP_UCHAR, buf, 36 ); + XP_UCHAR buf[36]; PangoLayout* layout; int lineHeight = GTK_HOR_SCORE_HEIGHT, nLines; @@ -1191,9 +1191,9 @@ gtk_draw_measureScoreText( DrawCtx* p_dctx, const XP_Rect* bounds, *heightP = nLines * lineHeight; XP_U16 playerNum = dsi->playerNum; - XP_ASSERT( playerNum < MAX_NUM_PLAYERS ); + XP_ASSERT( playerNum < VSIZE(dctx->scoreCache) ); XP_SNPRINTF( dctx->scoreCache[playerNum].str, - MAX_SCORE_LEN+1, "%s", buf ); + VSIZE(dctx->scoreCache[playerNum].str), "%s", buf ); dctx->scoreCache[playerNum].fontHt = lineHeight; } /* gtk_draw_measureScoreText */ @@ -1203,7 +1203,7 @@ gtk_draw_score_pendingScore( DrawCtx* p_dctx, const XP_Rect* rect, XP_S16 curTurn, CellFlags flags ) { GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; - VDECL( XP_UCHAR, buf, 5 ); + XP_UCHAR buf[5]; XP_U16 ht; XP_Rect localR; GdkRGBA* cursor = ((flags & CELL_ISCURSOR) != 0) @@ -1259,7 +1259,7 @@ gtk_draw_drawTimer( DrawCtx* p_dctx, const XP_Rect* rInner, GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; XP_Bool hadCairo = haveCairo( dctx ); if ( hadCairo || initCairo( dctx ) ) { - VDECL( XP_UCHAR, buf, 10 ); + XP_UCHAR buf[10]; gtkFormatTimerText( buf, VSIZE(buf), secondsLeft ); @@ -1406,10 +1406,8 @@ gtkDrawCtxtMake( GtkWidget* drawing_area, GtkGameGlobals* globals ) dctx->vtable = g_malloc( sizeof(*(((GtkDrawCtx*)dctx)->vtable)) ); - void** ptr = (void**)dctx->vtable; - void** tableEnd = (void**)&dctx->vtable->tableEnd; - while ( ptr < tableEnd ) { - *ptr++ = draw_doNothing; + for ( int ii = 0; ii < VSIZE(dctx->vtable); ++ii ) { + ((void**)(dctx->vtable))[ii] = draw_doNothing; /* bad? */ } SET_VTABLE_ENTRY( dctx->vtable, draw_clearRect, gtk ); diff --git a/xwords4/linux/gtkinvit.c b/xwords4/linux/gtkinvit.c index ba94fdc38..d2ca40fc1 100644 --- a/xwords4/linux/gtkinvit.c +++ b/xwords4/linux/gtkinvit.c @@ -76,7 +76,7 @@ conTypeToPageNum( const GtkInviteState* state, CommsConnType conType ) pageNum = ii; break; } - XP_ASSERT( ii < COMMS_CONN_NTYPES ); + XP_ASSERT( ii < VSIZE(state->pageData) ); } return pageNum; } diff --git a/xwords4/linux/gtkmain.c b/xwords4/linux/gtkmain.c index fd8a2ead2..4f5a5b8b2 100644 --- a/xwords4/linux/gtkmain.c +++ b/xwords4/linux/gtkmain.c @@ -350,7 +350,7 @@ make_rematch( GtkAppGlobals* apg, const CommonGlobals* cGlobals ) comms_getAddr( comms, &addr ); addrToStream( stream, &addr ); - VDECL( CommsAddrRec, addrs, 4 ); + CommsAddrRec addrs[4]; XP_U16 nRecs = VSIZE(addrs); comms_getAddrs( comms, addrs, &nRecs ); @@ -478,7 +478,7 @@ setWindowTitle( GtkAppGlobals* apg ) GtkWidget* window = apg->window; LaunchParams* params = apg->params; - VDECL( gchar, title, 128 ) = {0}; + gchar title[128] = {0}; if ( !!params->dbName ) { strcat( title, params->dbName ); } @@ -696,7 +696,7 @@ relayInviteReceived( void* closure, NetLaunchInfo* invite ) GtkAppGlobals* apg = (GtkAppGlobals*)closure; XP_U32 gameID = invite->gameID; - VDECL( sqlite3_int64, rowids, 1 ); + sqlite3_int64 rowids[1]; int nRowIDs = VSIZE(rowids); getRowsForGameID( apg->params->pDb, gameID, rowids, &nRowIDs ); @@ -782,7 +782,7 @@ smsMsgReceivedGTK( void* closure, const CommsAddrRec* from, XP_U32 gameID, GtkAppGlobals* apg = (GtkAppGlobals*)closure; LaunchParams* params = apg->params; - VDECL( sqlite3_int64, rowids, 4 ); + sqlite3_int64 rowids[4]; int nRowIDs = VSIZE(rowids); getRowsForGameID( params->pDb, gameID, rowids, &nRowIDs ); XP_LOGF( "%s: found %d rows for gameID %d", __func__, nRowIDs, gameID ); @@ -888,7 +888,7 @@ gtkmain( LaunchParams* params ) } #ifdef XWFEATURE_SMS - VDECL( gchar, buf, 32 ); + gchar buf[32]; const gchar* myPhone = params->connInfo.sms.myPhone; if ( !!myPhone ) { db_store( params->pDb, KEY_SMSPHONE, myPhone ); @@ -896,7 +896,7 @@ gtkmain( LaunchParams* params ) params->connInfo.sms.myPhone = myPhone = buf; } XP_U16 myPort = params->connInfo.sms.port; - VDECL( gchar, portbuf, 8 ); + gchar portbuf[8]; if ( 0 < myPort ) { sprintf( portbuf, "%d", myPort ); db_store( params->pDb, KEY_SMSPORT, portbuf ); diff --git a/xwords4/linux/gtknewgame.c b/xwords4/linux/gtknewgame.c index 6b54055fd..e0d1ffe41 100644 --- a/xwords4/linux/gtknewgame.c +++ b/xwords4/linux/gtknewgame.c @@ -216,7 +216,8 @@ addPhoniesCombo( GtkNewGameState* state, GtkWidget* parent ) FALSE, TRUE, 0 ); GtkWidget* phoniesCombo = gtk_combo_box_text_new(); - VDECL( const char*, ptxts, 3 ) = { "IGNORE", "WARN", "DISALLOW" }; + const char* ptxts[] = { "IGNORE", "WARN", "DISALLOW" }; + for ( int ii = 0; ii < VSIZE(ptxts); ++ii ) { gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT(phoniesCombo), ptxts[ii] ); @@ -239,7 +240,7 @@ makeNewGameDialog( GtkNewGameState* state ) GtkWidget* hbox; #ifndef XWFEATURE_STANDALONE_ONLY GtkWidget* roleCombo; - VDECL( char*, roles, 3 ) = { "Standalone", "Host", "Guest" }; + char* roles[] = { "Standalone", "Host", "Guest" }; #endif GtkWidget* nPlayersCombo; GtkWidget* boardSizeCombo; diff --git a/xwords4/linux/linuxdict.c b/xwords4/linux/linuxdict.c index 232583501..b41a0ddde 100644 --- a/xwords4/linux/linuxdict.c +++ b/xwords4/linux/linuxdict.c @@ -268,7 +268,7 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const LaunchParams* params, XP_Bool isUTF8 = XP_FALSE; XP_Bool hasHeader = XP_FALSE; const XP_U8* ptr; - VDECL( char, path, 256 ); + char path[256]; if ( !getDictPath( params, fileName, path, VSIZE(path) ) ) { XP_LOGF( "%s: path=%s", __func__, path ); diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index ef2d3bece..845e6b41d 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -327,7 +327,7 @@ catFinalScores( const CommonGlobals* cGlobals, XP_S16 quitter ) cGlobals->params->vtMgr, NULL, CHANNEL_NONE, catOnClose ); if ( -1 != quitter ) { - VDECL( XP_UCHAR, buf, 128 ); + XP_UCHAR buf[128]; XP_SNPRINTF( buf, VSIZE(buf), "Player %s resigned\n", cGlobals->gi->players[quitter].name ); stream_catString( stream, buf ); @@ -818,7 +818,7 @@ static CmdInfoRec CmdInfoRecs[] = { static struct option* make_longopts() { - int count = N_CMDS; + int count = VSIZE( CmdInfoRecs ); struct option* result = calloc( count+1, sizeof(*result) ); int ii; for ( ii = 0; ii < count; ++ii ) { @@ -841,7 +841,7 @@ usage( char* appName, char* msg ) fprintf( stderr, "usage: %s \n", appName ); int maxWidth = 0; - for ( ii = 0; ii < N_CMDS; ++ii ) { + for ( ii = 0; ii < VSIZE(CmdInfoRecs); ++ii ) { const CmdInfoRec* rec = &CmdInfoRecs[ii]; int width = strlen(rec->param) + 1; if ( rec->hasArg ) { @@ -852,7 +852,7 @@ usage( char* appName, char* msg ) } } - for ( ii = 0; ii < N_CMDS; ++ii ) { + for ( ii = 0; ii < VSIZE(CmdInfoRecs); ++ii ) { const CmdInfoRec* rec = &CmdInfoRecs[ii]; char buf[120]; snprintf( buf, sizeof(buf), "--%s %s", rec->param, @@ -1624,7 +1624,7 @@ static void testGetNthWord( const DictionaryCtxt* dict, char** XP_UNUSED_DBG(words), XP_U16 depth, IndexData* data, XP_U16 min, XP_U16 max ) { - VDECL( XP_UCHAR, buf, 64 ); + XP_UCHAR buf[64]; XP_U32 ii, jj; DictIter iter; @@ -1678,7 +1678,7 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict, XP_U32 count = dict_countWords( &iter, &lens ); XP_U32 sum = 0; - for ( jj = 0; jj < MAX_COLS_DICT+1; ++jj ) { + for ( jj = 0; jj < VSIZE(lens.lens); ++jj ) { sum += lens.lens[jj]; XP_LOGF( "%d words of length %ld", lens.lens[jj], jj ); } @@ -1692,7 +1692,7 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict, gotOne; gotOne = dict_getNextWord( &iter ) ) { XP_ASSERT( dict_getPosition( &iter ) == jj ); - VDECL( XP_UCHAR, buf, 64 ); + XP_UCHAR buf[64]; dict_wordToString( &iter, buf, VSIZE(buf) ); # ifdef PRINT_ALL fprintf( stderr, "%.6ld: %s\n", jj, buf ); @@ -1708,7 +1708,7 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict, gotOne; ++jj, gotOne = dict_getPrevWord( &iter ) ) { XP_ASSERT( dict_getPosition(&iter) == count-jj-1 ); - VDECL( XP_UCHAR, buf, 64 ); + XP_UCHAR buf[64]; dict_wordToString( &iter, buf, VSIZE(buf) ); # ifdef PRINT_ALL fprintf( stderr, "%.6ld: %s\n", jj, buf ); @@ -1750,13 +1750,13 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict, XP_ASSERT( 0 ); } XP_ASSERT( word.index == indices[ii] ); - VDECL( XP_UCHAR, buf1, 64 ); + XP_UCHAR buf1[64]; dict_wordToString( dict, &word, buf1, VSIZE(buf1) ); - VDECL( XP_UCHAR, buf2, 64 ) = {0}; + XP_UCHAR buf2[64] = {0}; if ( ii > 0 && dict_getNthWord( dict, &word, indices[ii]-1 ) ) { dict_wordToString( dict, &word, buf2, VSIZE(buf2) ); } - VDECL( char, prfx, 8 ); + char prfx[8]; dict_tilesToString( dict, &prefixes[depth*ii], depth, prfx, VSIZE(prfx) ); fprintf( stderr, "%d: index: %ld; prefix: %s; word: %s (prev: %s)\n", @@ -1774,8 +1774,8 @@ walk_dict_test( MPFORMAL const DictionaryCtxt* dict, gchar* prefix = (gchar*)g_slist_nth_data( testPrefixes, ii ); XP_S16 lenMatched = dict_findStartsWith( &iter, prefix ); if ( 0 <= lenMatched ) { - VDECL( XP_UCHAR, buf, 32 ); - VDECL( XP_UCHAR, bufPrev, 32 ) = {0}; + XP_UCHAR buf[32]; + XP_UCHAR bufPrev[32] = {0}; dict_wordToString( &iter, buf, VSIZE(buf) ); /* This doesn't work with synonyms like "L-L" for "L·L" */ @@ -1832,7 +1832,7 @@ dumpDict( DictionaryCtxt* dict ) for ( XP_Bool result = dict_firstWord( &iter ); result; result = dict_getNextWord( &iter ) ) { - VDECL( XP_UCHAR, buf, 32 ); + XP_UCHAR buf[32]; dict_wordToString( &iter, buf, VSIZE(buf) ); fprintf( stdout, "%s\n", buf ); } @@ -1841,7 +1841,7 @@ dumpDict( DictionaryCtxt* dict ) static void trimDictPath( const char* input, char* buf, int bufsiz, char** path, char** dict ) { - VDECL( char, unlinked, 256 ); + char unlinked[256]; XP_ASSERT( strlen(input) < VSIZE(unlinked) ); ssize_t siz = readlink( input, unlinked, VSIZE(unlinked) ); if ( 0 <= siz ) { @@ -1883,7 +1883,7 @@ getDictPath( const LaunchParams *params, const char* name, result[0] = '\0'; for ( iter = params->dictDirs; !!iter; iter = iter->next ) { const char* path = iter->data; - VDECL( char, buf, 256 ); + char buf[256]; int len = snprintf( buf, VSIZE(buf), "%s/%s.xwd", path, name ); if ( len < VSIZE(buf) && file_exists( buf ) ) { snprintf( result, resultLen, "%s", buf ); @@ -2064,7 +2064,7 @@ main( int argc, char** argv ) GSList* testPrefixes = NULL; char* testMinMax = NULL; #endif - VDECL( char, dictbuf, 256 ); + char dictbuf[256]; char* dict; char* path; diff --git a/xwords4/linux/linuxutl.c b/xwords4/linux/linuxutl.c index 34c548156..abf6c7bd0 100644 --- a/xwords4/linux/linuxutl.c +++ b/xwords4/linux/linuxutl.c @@ -68,7 +68,7 @@ linux_debugf( const char* format, ... ) void linux_backtrace( void ) { - VDECL( void*, buffer, 128 ); + void* buffer[128]; int nFound = backtrace( buffer, VSIZE(buffer) ); XP_ASSERT( nFound < VSIZE(buffer) ); char** traces = backtrace_symbols( buffer, nFound ); @@ -105,13 +105,10 @@ linux_util_makeEmptyDict( XW_UtilCtxt* XP_UNUSED_DBG(uctx) ) #define TL BONUS_TRIPLE_LETTER #define TW BONUS_TRIPLE_WORD -#define SC_BOARD_SIZE 36 -#define SEVENTEEN_BOARD_SIZE 45 - static XWBonusType* bonusesFor( XP_U16 boardSize, XP_U16* len ) { - static XWBonusType scrabbleBoard[SC_BOARD_SIZE] = { + static XWBonusType scrabbleBoard[] = { TW,//EM,EM,DL,EM,EM,EM,TW, EM,DW,//EM,EM,EM,TL,EM,EM, @@ -125,7 +122,7 @@ bonusesFor( XP_U16 boardSize, XP_U16* len ) TW,EM,EM,DL,EM,EM,EM,DW, }; /* scrabbleBoard */ - static XWBonusType seventeen[SEVENTEEN_BOARD_SIZE] = { + static XWBonusType seventeen[] = { TW,//EM,EM,DL,EM,EM,EM,TW, EM,DW,//EM,EM,EM,TL,EM,EM, @@ -143,10 +140,10 @@ bonusesFor( XP_U16 boardSize, XP_U16* len ) XWBonusType* result = NULL; if ( boardSize == 15 ) { result = scrabbleBoard; - *len = SC_BOARD_SIZE; + *len = VSIZE(scrabbleBoard); } else if ( boardSize == 17 ) { result = seventeen; - *len = SEVENTEEN_BOARD_SIZE; + *len = VSIZE(seventeen); } return result; @@ -484,7 +481,7 @@ formatConfirmTrade( CommonGlobals* cGlobals, const XP_UCHAR** tiles, } tileBuf[offset-2] = '\0'; - snprintf( cGlobals->question, QUESTION_LEN, + snprintf( cGlobals->question, VSIZE(cGlobals->question), "Are you sure you want to trade the selected tiles (%s)?", tileBuf ); } diff --git a/xwords4/linux/main.h b/xwords4/linux/main.h index e6cf21862..0ed10b6cf 100644 --- a/xwords4/linux/main.h +++ b/xwords4/linux/main.h @@ -188,7 +188,6 @@ typedef struct _TimerInfo { typedef void (*OnSaveFunc)( void* closure, sqlite3_int64 rowid, XP_Bool firstTime ); -#define QUESTION_LEN 256*4 struct CommonGlobals { LaunchParams* params; CommonPrefs cp; @@ -224,7 +223,7 @@ struct CommonGlobals { /* Saved state from util method to response method */ XP_U16 selPlayer; - char question[QUESTION_LEN]; + char question[256*4]; const XP_UCHAR* askPassName; XP_U16 nTiles; XP_U16 nToPick; diff --git a/xwords4/linux/relaycon.c b/xwords4/linux/relaycon.c index 0346c5560..995ccbd38 100644 --- a/xwords4/linux/relaycon.c +++ b/xwords4/linux/relaycon.c @@ -32,8 +32,6 @@ #define MAX_MOVE_CHECK_MS ((XP_U16)(1000 * 60 * 60 * 24)) #define RELAY_API_PROTO "http" -#define HOST_LEN 64 - typedef struct _RelayConStorage { pthread_t mainThread; guint moveCheckerID; @@ -52,7 +50,7 @@ typedef struct _RelayConStorage { uint32_t nextID; XWPDevProto proto; LaunchParams* params; - XP_UCHAR host[HOST_LEN]; + XP_UCHAR host[64]; int nextTaskID; } RelayConStorage; @@ -261,7 +259,7 @@ relaycon_init( LaunchParams* params, const RelayConnProcs* procs, pthread_mutex_init( &storage->gotDataMutex, NULL ); g_timeout_add( 50, gotDataTimer, storage ); - XP_ASSERT( XP_STRLEN(host) < HOST_LEN ); + XP_ASSERT( XP_STRLEN(host) < VSIZE(storage->host) ); XP_MEMCPY( storage->host, host, XP_STRLEN(host) + 1 ); } else { storage->socket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); diff --git a/xwords4/relay/xwrelay.h b/xwords4/relay/xwrelay.h index 5244d9d7b..cb547ce5a 100644 --- a/xwords4/relay/xwrelay.h +++ b/xwords4/relay/xwrelay.h @@ -281,8 +281,6 @@ typedef unsigned short CookieID; #define COOKIE_ID_NONE 0 -#ifndef VSIZE -# define VSIZE(arr) (sizeof(arr)/sizeof(arr[0])) -#endif +#define VSIZE(arr) (sizeof(arr)/sizeof(arr[0])) #endif