run-time validate endianness, numeric sizes

This commit is contained in:
David Rose 2006-08-04 14:43:31 +00:00
parent 1ea11e7073
commit 26b1e8f6cd

View File

@ -30,6 +30,7 @@
#include "virtualFileMountSystem.h" #include "virtualFileMountSystem.h"
#include "virtualFileSimple.h" #include "virtualFileSimple.h"
#include "pandaSystem.h" #include "pandaSystem.h"
#include "numeric_types.h"
#include "dconfig.h" #include "dconfig.h"
@ -163,10 +164,28 @@ init_libexpress() {
init_system_type_handles(); init_system_type_handles();
#ifdef HAVE_ZLIB #ifdef HAVE_ZLIB
{ {
PandaSystem *ps = PandaSystem::get_global_ptr(); PandaSystem *ps = PandaSystem::get_global_ptr();
ps->add_system("zlib"); ps->add_system("zlib");
} }
#endif
// This is a fine place to ensure that the numeric types have been
// chosen correctly.
nassertv(sizeof(PN_int8) == 1 && sizeof(PN_uint8) == 1);
nassertv(sizeof(PN_int16) == 2 && sizeof(PN_uint16) == 2);
nassertv(sizeof(PN_int32) == 4 && sizeof(PN_uint32) == 4);
nassertv(sizeof(PN_int64) == 8 && sizeof(PN_uint64) == 8);
nassertv(sizeof(PN_float32) == 4);
nassertv(sizeof(PN_float64) == 8);
// Also, ensure that we have the right endianness.
PN_uint32 word;
memcpy(&word, "\1\2\3\4", 4);
#ifdef WORDS_BIGENDIAN
nassertv(word == 0x01020304);
#else
nassertv(word == 0x04030201);
#endif #endif
} }