Browse Source

run-time validate endianness, numeric sizes

David Rose 19 years ago
parent
commit
26b1e8f6cd
1 changed files with 23 additions and 4 deletions
  1. 23 4
      panda/src/express/config_express.cxx

+ 23 - 4
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
 }