瀏覽代碼

better 64-bit support

David Rose 19 年之前
父節點
當前提交
846e46b8c7
共有 3 個文件被更改,包括 41 次插入1 次删除
  1. 9 0
      dtool/src/dtoolbase/dtoolbase.h
  2. 19 1
      dtool/src/dtoolbase/numeric_types.h
  3. 13 0
      dtool/src/dtoolbase/typeRegistry.cxx

+ 9 - 0
dtool/src/dtoolbase/dtoolbase.h

@@ -265,6 +265,15 @@
 
 
 #endif
 #endif
 
 
+/* Try to determine if we're compiling in a 64-bit mode. */
+
+#if defined(_LP64)
+#define NATIVE_WORDSIZE 64
+#else
+#define NATIVE_WORDSIZE 32
+#endif
+
+
 /*
 /*
  We define the macros BEGIN_PUBLISH and END_PUBLISH to bracket
  We define the macros BEGIN_PUBLISH and END_PUBLISH to bracket
  functions and global variable definitions that are to be published
  functions and global variable definitions that are to be published

+ 19 - 1
dtool/src/dtoolbase/numeric_types.h

@@ -25,7 +25,24 @@
 // the various numeric types for unsigned and signed numbers of
 // the various numeric types for unsigned and signed numbers of
 // various widths.
 // various widths.
 
 
-// For now, we'll just assume a typical 32-bit environment.
+#if defined(_LP64)
+// A 64-bit environment.
+
+typedef signed char PN_int8;
+typedef short PN_int16;
+typedef int PN_int32;
+
+typedef unsigned char PN_uint8;
+typedef unsigned short PN_uint16;
+typedef unsigned int PN_uint32;
+typedef long PN_int64;
+typedef unsigned long PN_uint64;
+
+typedef double PN_float64;
+typedef float PN_float32;
+
+#else  // _LP64
+// A 32-bit environment.
 
 
 typedef signed char PN_int8;
 typedef signed char PN_int8;
 typedef short PN_int16;
 typedef short PN_int16;
@@ -46,6 +63,7 @@ typedef unsigned long long PN_uint64;
 typedef double PN_float64;
 typedef double PN_float64;
 typedef float PN_float32;
 typedef float PN_float32;
 
 
+#endif  // _LP64
 #endif
 #endif
 
 
 
 

+ 13 - 0
dtool/src/dtoolbase/typeRegistry.cxx

@@ -21,6 +21,7 @@
 #include "typeHandle.h"
 #include "typeHandle.h"
 #include "typedObject.h"
 #include "typedObject.h"
 #include "indent.h"
 #include "indent.h"
+#include "numeric_types.h"
 
 
 #include <algorithm>
 #include <algorithm>
 
 
@@ -567,6 +568,18 @@ TypeRegistry() {
   _handle_registry.push_back(NULL);
   _handle_registry.push_back(NULL);
 
 
   _derivations_fresh = false;
   _derivations_fresh = false;
+
+  // Here's a few sanity checks on the sizes of our words.  We have to
+  // put it here, at runtime, since there doesn't appear to be a
+  // cross-platform compile-time way to verify that we've chosen the
+  // right word sizes.
+  assert(sizeof(PN_uint8) == 1 && sizeof(PN_int8) == 1);
+  assert(sizeof(PN_uint16) == 2 && sizeof(PN_int16) == 2);
+  assert(sizeof(PN_uint32) == 4 && sizeof(PN_int32) == 4);
+  assert(sizeof(PN_uint64) == 8 && sizeof(PN_int64) == 8);
+
+  assert(sizeof(PN_float32) == 4);
+  assert(sizeof(PN_float64) == 8);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////