Take over and use static assertion macro found in LuaJIT sources.

git-svn-id: https://svn.eduke32.com/eduke32@3644 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-04-05 17:53:14 +00:00
parent 6ebe2d4745
commit 203bd1e9e9
5 changed files with 22 additions and 12 deletions

View file

@ -728,5 +728,16 @@ static inline char *Bstrncpyz(char *dst, const char *src, bsize_t n)
#define initprintf_nowarn(fmt, ...) NOWARN(initprintf, fmt, ## __VA_ARGS__)
#define message_nowarn(fmt, ...) NOWARN(message, fmt, ## __VA_ARGS__)
/* Static assertions, based on source found in LuaJIT's src/lj_def.h. */
#define EDUKE32_ASSERT_NAME2(name, line) name ## line
#define EDUKE32_ASSERT_NAME(line) EDUKE32_ASSERT_NAME2(eduke32_assert_, line)
#ifdef __COUNTER__
# define EDUKE32_STATIC_ASSERT(cond) \
extern void EDUKE32_ASSERT_NAME(__COUNTER__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
#else
# define EDUKE32_STATIC_ASSERT(cond) \
extern void EDUKE32_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
#endif
#endif // __compat_h__

View file

@ -28,12 +28,12 @@ const char *animvpx_read_ivf_header_errmsg[] = {
"invalid framerate numerator or denominator after correction, must not be 0",
};
EDUKE32_STATIC_ASSERT(sizeof(animvpx_ivf_header_t) == 32);
int32_t animvpx_read_ivf_header(int32_t inhandle, animvpx_ivf_header_t *hdr)
{
int32_t err;
Bassert(sizeof(animvpx_ivf_header_t) == 32);
if (kread(inhandle, hdr, sizeof(animvpx_ivf_header_t)) != sizeof(animvpx_ivf_header_t))
return 1; // "couldn't read header"

View file

@ -10113,6 +10113,9 @@ void G_MaybeAllocPlayer(int32_t pnum)
#endif
}
EDUKE32_STATIC_ASSERT(sizeof(actor_t)==128);
EDUKE32_STATIC_ASSERT(sizeof(DukePlayer_t)%4 == 0);
int32_t app_main(int32_t argc, const char **argv)
{
int32_t i = 0, j;
@ -10124,9 +10127,6 @@ int32_t app_main(int32_t argc, const char **argv)
ENetCallbacks callbacks = { NULL, NULL, NULL };
#endif
Bassert(sizeof(actor_t)==128);
Bassert(sizeof(DukePlayer_t)%4 == 0);
G_ExtPreInit();
#ifdef _WIN32

View file

@ -6119,9 +6119,7 @@ void C_InitProjectiles(void)
0, 1, 32, {0,0,0,0,0,0},
};
// this will only happen if I forget to update this function...
if (sizeof(projectile_t) != sizeof(DefaultProjectile))
G_GameExit("ERROR: C_InitProjectiles(): projectile_t mismatch!");
EDUKE32_STATIC_ASSERT(sizeof(projectile_t) == sizeof(DefaultProjectile));
for (i=MAXTILES-1; i>=0; i--)
{

View file

@ -1126,13 +1126,13 @@ static int32_t doallocsnap(int32_t allocinit)
}
EDUKE32_STATIC_ASSERT(sizeof(savehead_t) == 310);
// make snapshot only if spot < 0 (demo)
int32_t sv_saveandmakesnapshot(FILE *fil, int8_t spot, int8_t recdiffsp, int8_t diffcompress, int8_t synccompress)
{
savehead_t h;
Bassert(sizeof(savehead_t) == 310);
// set a few savegame system globals
savegame_comprthres = SV_DEFAULTCOMPRTHRES;
savegame_diffcompress = diffcompress;
@ -1237,13 +1237,14 @@ int32_t sv_saveandmakesnapshot(FILE *fil, int8_t spot, int8_t recdiffsp, int8_t
return 0;
}
EDUKE32_STATIC_ASSERT(sizeof(savehead_t) == 310);
// if file is not an EDuke32 savegame/demo, h->headerstr will be all zeros
int32_t sv_loadheader(int32_t fil, int32_t spot, savehead_t *h)
{
int32_t havedemo = (spot < 0);
Bassert(sizeof(savehead_t) == 310);
if (kread(fil, h, sizeof(savehead_t)) != sizeof(savehead_t))
{
OSD_Printf("%s %d header corrupt.\n", havedemo ? "Demo":"Savegame", havedemo ? -spot : spot);