From 26b1e8f6cdcfd2a7191b685623e14ec8bcdafff4 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 4 Aug 2006 14:43:31 +0000 Subject: [PATCH] run-time validate endianness, numeric sizes --- panda/src/express/config_express.cxx | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/panda/src/express/config_express.cxx b/panda/src/express/config_express.cxx index b5c51cb6e7..2c7c453ba1 100644 --- a/panda/src/express/config_express.cxx +++ b/panda/src/express/config_express.cxx @@ -30,6 +30,7 @@ #include "virtualFileMountSystem.h" #include "virtualFileSimple.h" #include "pandaSystem.h" +#include "numeric_types.h" #include "dconfig.h" @@ -163,10 +164,28 @@ init_libexpress() { init_system_type_handles(); #ifdef HAVE_ZLIB - { - PandaSystem *ps = PandaSystem::get_global_ptr(); - ps->add_system("zlib"); - } + { + PandaSystem *ps = PandaSystem::get_global_ptr(); + 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 }