From 846e46b8c7124c303de947871cbb99dbe49e55a0 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 5 Apr 2007 15:33:53 +0000 Subject: [PATCH] better 64-bit support --- dtool/src/dtoolbase/dtoolbase.h | 9 +++++++++ dtool/src/dtoolbase/numeric_types.h | 20 +++++++++++++++++++- dtool/src/dtoolbase/typeRegistry.cxx | 13 +++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/dtool/src/dtoolbase/dtoolbase.h b/dtool/src/dtoolbase/dtoolbase.h index 06d9c1594a..a66084f7ad 100644 --- a/dtool/src/dtoolbase/dtoolbase.h +++ b/dtool/src/dtoolbase/dtoolbase.h @@ -265,6 +265,15 @@ #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 functions and global variable definitions that are to be published diff --git a/dtool/src/dtoolbase/numeric_types.h b/dtool/src/dtoolbase/numeric_types.h index 48c60eed65..3cb867fe25 100644 --- a/dtool/src/dtoolbase/numeric_types.h +++ b/dtool/src/dtoolbase/numeric_types.h @@ -25,7 +25,24 @@ // the various numeric types for unsigned and signed numbers of // 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 short PN_int16; @@ -46,6 +63,7 @@ typedef unsigned long long PN_uint64; typedef double PN_float64; typedef float PN_float32; +#endif // _LP64 #endif diff --git a/dtool/src/dtoolbase/typeRegistry.cxx b/dtool/src/dtoolbase/typeRegistry.cxx index e1299f600d..69d0a61ddb 100644 --- a/dtool/src/dtoolbase/typeRegistry.cxx +++ b/dtool/src/dtoolbase/typeRegistry.cxx @@ -21,6 +21,7 @@ #include "typeHandle.h" #include "typedObject.h" #include "indent.h" +#include "numeric_types.h" #include @@ -567,6 +568,18 @@ TypeRegistry() { _handle_registry.push_back(NULL); _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); } ////////////////////////////////////////////////////////////////////