Panda3D
 All Classes Functions Variables Enumerations
dtoolbase.h
00001 /* Filename: dtoolbase.h
00002  * Created by:  drose (12Sep00)
00003  *
00004  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00005  *
00006  * PANDA 3D SOFTWARE
00007  * Copyright (c) Carnegie Mellon University.  All rights reserved.
00008  *
00009  * All use of this software is subject to the terms of the revised BSD
00010  * license.  You should have received a copy of this license along
00011  * with this source code in a file named "LICENSE."
00012  *
00013  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00014 
00015 /* This file is included at the beginning of every header file and/or
00016    C or C++ file.  It must be compilable for C as well as C++ files,
00017    so no C++-specific code or syntax can be put here.  See
00018    dtoolbase_cc.h for C++-specific stuff. */
00019 
00020 #ifndef DTOOLBASE_H
00021 #define DTOOLBASE_H
00022 
00023 #include "dtool_config.h"
00024 
00025 /* Make sure WIN32 and WIN32_VC are defined when using MSVC */
00026 #ifdef _WIN32
00027 #ifndef WIN32
00028 #define WIN32
00029 #endif
00030 #ifdef _MSC_VER
00031 #ifndef WIN32_VC
00032 #define WIN32_VC
00033 #endif
00034 #endif
00035 #endif
00036 
00037 #ifdef WIN32_VC
00038 /* These warning pragmas must appear before anything else for VC++ to
00039    respect them.  Sheesh. */
00040 
00041 /* C4231: extern before template instantiation */
00042 /* For some reason, this particular warning won't disable. */
00043 #pragma warning (disable : 4231)
00044 /* C4786: 255 char debug symbols */
00045 #pragma warning (disable : 4786)
00046 /* C4251: needs dll interface */
00047 #pragma warning (disable : 4251)
00048 /* C4503: decorated name length exceeded */
00049 #pragma warning (disable : 4503)
00050 /* C4305: truncation from 'const double' to 'float' */
00051 #pragma warning (disable : 4305)
00052 /* C4250: 'myclass' : inherits 'baseclass::member' via dominance */
00053 #pragma warning (disable : 4250)
00054 /* C4355: 'this' : used in base member initializer list */
00055 #pragma warning (disable : 4355)
00056 /* C4244: 'initializing' : conversion from 'double' to 'float', possible loss of data */
00057 #pragma warning (disable : 4244)
00058 
00059 #if _MSC_VER >= 1300
00060  #if _MSC_VER >= 1310
00061    #define USING_MSVC7_1
00062 //#pragma message("VC 7.1")
00063  #else
00064 //#pragma message("VC 7.0")
00065  #endif
00066 #define USING_MSVC7
00067 #else
00068 // #pragma message("VC 6.0")
00069 #endif
00070 
00071 // Use NODEFAULT to optimize a switch() stmt to tell MSVC to automatically go to the final untested case
00072 // after it has failed all the other cases (i.e. 'assume at least one of the cases is always true')
00073 #ifdef _DEBUG
00074 # define NODEFAULT  default: assert(0);
00075 #else
00076 # define NODEFAULT  default: __assume(0);   // special VC keyword
00077 #endif
00078 
00079 #else /* if !WIN32_VC */
00080 #ifdef _DEBUG
00081 # define NODEFAULT   default: assert(0);
00082 #else
00083 # define NODEFAULT
00084 #endif
00085 #endif  /* WIN32_VC */
00086 
00087 /*
00088   include win32 defns for everything up to WinServer2003, and assume
00089   I'm smart enough to use GetProcAddress for backward compat on
00090   w95/w98 for newer fns
00091 */
00092 #ifdef _WIN32_WINNT
00093 #undef _WIN32_WINNT
00094 #endif
00095 #define _WIN32_WINNT 0x0502
00096 
00097 #ifdef __cplusplus
00098 #ifndef __STDC_LIMIT_MACROS
00099 #define __STDC_LIMIT_MACROS
00100 #endif
00101 #ifndef __STDC_CONSTANT_MACROS
00102 #define __STDC_CONSTANT_MACROS
00103 #endif
00104 #endif
00105 
00106 #ifdef HAVE_PYTHON
00107 #undef _POSIX_C_SOURCE
00108 #undef _XOPEN_SOURCE
00109 #include "pyconfig.h"
00110 #endif
00111 
00112 #ifndef HAVE_EIGEN
00113 // If we don't have the Eigen library, don't define LINMATH_ALIGN.
00114 #undef LINMATH_ALIGN
00115 #endif
00116 
00117 #include "dtoolsymbols.h"
00118 
00119 // always include assert.h until drose unbreaks it for opt4
00120 #include <assert.h>
00121 
00122 // (rdb) last resort bugfix for compile issue on OSX Tiger
00123 #include <signal.h>
00124 
00125 #ifdef __GNUC__
00126 // Large file >2GB support
00127 // this needs be be before systypes.h and other C headers
00128 #define _FILE_OFFSET_BITS 64
00129 #define _LARGEFILE_SOURCE 1
00130 #endif
00131 
00132 #ifdef PHAVE_TYPES_H
00133 #include <types.h>
00134 #endif
00135 
00136 #ifdef PHAVE_SYS_TYPES_H
00137 #include <sys/types.h>
00138 #endif
00139 
00140 #ifdef PHAVE_MALLOC_H
00141 #include <malloc.h>
00142 #endif
00143 
00144 #ifdef PHAVE_SYS_MALLOC_H
00145 #include <sys/malloc.h>
00146 #endif
00147 
00148 #ifdef PHAVE_ALLOCA_H
00149 #include <alloca.h>
00150 #endif
00151 
00152 #ifdef PHAVE_UNISTD_H
00153 #include <unistd.h>
00154 #endif
00155 
00156 #ifdef PHAVE_IO_H
00157 #include <io.h>
00158 #endif
00159 
00160 #ifdef PHAVE_LOCALE_H
00161 #include <locale.h>
00162 #endif
00163 
00164 #ifdef PHAVE_STRING_H
00165 #include <string.h>
00166 #endif
00167 
00168 #ifdef PHAVE_STDLIB_H
00169 #include <stdlib.h>
00170 #endif
00171 
00172 #ifdef PHAVE_LIMITS_H
00173 #include <limits.h>
00174 #endif
00175 
00176 #ifdef PHAVE_MINMAX_H
00177 #include <minmax.h>
00178 #endif
00179 
00180 #ifdef PHAVE_SYS_TIME_H
00181 #include <sys/time.h>
00182 #endif
00183 
00184 #ifdef PHAVE_STDINT_H
00185 #include <stdint.h>
00186 #endif
00187 
00188 #ifdef CPPPARSER
00189 #include <stdtypedefs.h>
00190 #endif
00191 
00192 #ifdef USE_TAU
00193 /* If we're building with the Tau instrumentor, include the
00194    appropriate header file to pick up the TAU macros. */
00195 #include <TAU.h>
00196 #include <Profile/Profiler.h>
00197 #else
00198 /* Otherwise, if we're not building with the Tau instrumentor, turn
00199    off all the TAU macros.  We could include the Tau header file to do
00200    this, but it's better not to assume that Tau is installed. */
00201 #define TAU_TYPE_STRING(profileString, str)
00202 #define TAU_PROFILE(name, type, group)
00203 #define TAU_PROFILE_TIMER(var, name, type, group)
00204 #define TAU_PROFILE_START(var)
00205 #define TAU_PROFILE_STOP(var)
00206 #define TAU_PROFILE_STMT(stmt)
00207 #define TAU_PROFILE_EXIT(msg)
00208 #define TAU_PROFILE_INIT(argc, argv)
00209 #define TAU_PROFILE_SET_NODE(node)
00210 #define TAU_PROFILE_SET_CONTEXT(context)
00211 #define TAU_PROFILE_SET_GROUP_NAME(newname)
00212 #define TAU_PROFILE_TIMER_SET_GROUP_NAME(t, newname)
00213 #define TAU_PROFILE_CALLSTACK()
00214 #define TAU_DB_DUMP()
00215 #define TAU_DB_PURGE()
00216 
00217 #define TAU_REGISTER_CONTEXT_EVENT(event, name)
00218 #define TAU_CONTEXT_EVENT(event, data)
00219 #define TAU_DISABLE_CONTEXT_EVENT(event)
00220 #define TAU_ENABLE_CONTEXT_EVENT(event)
00221 
00222 #define TAU_REGISTER_EVENT(event, name)
00223 #define TAU_EVENT(event, data)
00224 #define TAU_EVENT_DISABLE_MIN(event)
00225 #define TAU_EVENT_DISABLE_MAX(event)
00226 #define TAU_EVENT_DISABLE_MEAN(event)
00227 #define TAU_EVENT_DISABLE_STDDEV(event)
00228 #define TAU_REPORT_STATISTICS()
00229 #define TAU_REPORT_THREAD_STATISTICS()
00230 #define TAU_REGISTER_THREAD()
00231 #define TAU_REGISTER_FORK(id, op)
00232 #define TAU_ENABLE_INSTRUMENTATION()
00233 #define TAU_DISABLE_INSTRUMENTATION()
00234 #define TAU_ENABLE_GROUP(group)
00235 #define TAU_DISABLE_GROUP(group)
00236 #define TAU_ENABLE_GROUP_NAME(group)
00237 #define TAU_DISABLE_GROUP_NAME(group)
00238 #define TAU_ENABLE_ALL_GROUPS()
00239 #define TAU_DISABLE_ALL_GROUPS()
00240 #define TAU_TRACK_MEMORY()
00241 #define TAU_TRACK_MEMORY_HERE()
00242 #define TAU_ENABLE_TRACKING_MEMORY()
00243 #define TAU_DISABLE_TRACKING_MEMORY()
00244 #define TAU_TRACK_MEMORY()
00245 #define TAU_TRACK_MEMORY_HERE()
00246 #define TAU_ENABLE_TRACKING_MUSE_EVENTS()
00247 #define TAU_DISABLE_TRACKING_MUSE_EVENTS()
00248 #define TAU_TRACK_MUSE_EVENTS()
00249 #define TAU_SET_INTERRUPT_INTERVAL(value)
00250 
00251 #define TAU_TRACE_SENDMSG(type, destination, length)
00252 #define TAU_TRACE_RECVMSG(type, source, length)
00253 
00254 #define TAU_MAPPING(stmt, group) stmt
00255 #define TAU_MAPPING_OBJECT(FuncInfoVar)
00256 #define TAU_MAPPING_LINK(FuncInfoVar, Group)
00257 #define TAU_MAPPING_PROFILE(FuncInfoVar)
00258 #define TAU_MAPPING_CREATE(name, type, key, groupname, tid)
00259 #define TAU_MAPPING_PROFILE_TIMER(Timer, FuncInfoVar, tid)
00260 #define TAU_MAPPING_TIMER_CREATE(t, name, type, gr, group_name)
00261 #define TAU_MAPPING_PROFILE_START(Timer, tid)
00262 #define TAU_MAPPING_PROFILE_STOP(tid)
00263 #define TAU_MAPPING_PROFILE_EXIT(msg, tid)
00264 #define TAU_MAPPING_DB_DUMP(tid)
00265 #define TAU_MAPPING_DB_PURGE(tid)
00266 #define TAU_MAPPING_PROFILE_SET_NODE(node, tid)
00267 #define TAU_MAPPING_PROFILE_SET_GROUP_NAME(timer, name)
00268 #define TAU_PROFILE_TIMER_SET_NAME(t, newname)
00269 #define TAU_PROFILE_TIMER_SET_TYPE(t, newname)
00270 #define TAU_PROFILE_TIMER_SET_GROUP(t, id)
00271 #define TAU_MAPPING_PROFILE_SET_NAME(timer, name)
00272 #define TAU_MAPPING_PROFILE_SET_TYPE(timer, name)
00273 #define TAU_MAPPING_PROFILE_SET_GROUP(timer, id)
00274 #define TAU_MAPPING_PROFILE_GET_GROUP_NAME(timer)
00275 #define TAU_MAPPING_PROFILE_GET_GROUP(timer)
00276 #define TAU_MAPPING_PROFILE_GET_NAME(timer)
00277 #define TAU_MAPPING_PROFILE_GET_TYPE(timer)
00278 
00279 #define TAU_PHASE(name, type, group)
00280 #define TAU_PHASE_CREATE_STATIC(var, name, type, group)
00281 #define TAU_PHASE_CREATE_DYNAMIC(var, name, type, group)
00282 #define TAU_PHASE_START(var)
00283 #define TAU_PHASE_STOP(var)
00284 #define TAU_GLOBAL_PHASE(timer, name, type, group)
00285 #define TAU_GLOBAL_PHASE_START(timer)
00286 #define TAU_GLOBAL_PHASE_STOP(timer)
00287 #define TAU_GLOBAL_PHASE_EXTERNAL(timer)
00288 #define TAU_GLOBAL_TIMER(timer, name, type, group)
00289 #define TAU_GLOBAL_TIMER_EXTERNAL(timer)
00290 #define TAU_GLOBAL_TIMER_START(timer)
00291 #define TAU_GLOBAL_TIMER_STOP()
00292 
00293 #endif  /* USE_TAU */
00294 
00295 /* Try to infer the endianness of the host based on compiler
00296    predefined macros.  For systems on which the compiler does not
00297    define these macros, we rely on ppremake to define WORDS_BIGENDIAN
00298    correctly.  For systems on which the compiler *does* define these
00299    macros, we ignore what ppremake said and define WORDS_BIGENDIAN
00300    correctly here.  (This is essential on OSX, which requires
00301    compiling each file twice in different modes, for universal binary
00302    support.) */
00303 
00304 #if defined(__LITTLE_ENDIAN__) || defined(__i386__)
00305 #undef WORDS_BIGENDIAN
00306 
00307 #elif defined(__BIG_ENDIAN__) || defined(__ppc__)
00308 #undef WORDS_BIGENDIAN
00309 #define WORDS_BIGENDIAN 1
00310 
00311 #endif
00312 
00313 /* Try to determine if we're compiling in a 64-bit mode. */
00314 
00315 #ifdef __WORDSIZE
00316 #define NATIVE_WORDSIZE __WORDSIZE
00317 #elif defined(_LP64)
00318 #define NATIVE_WORDSIZE 64
00319 #else
00320 #define NATIVE_WORDSIZE 32
00321 #endif
00322 
00323 /* Some byte-alignment macros. */
00324 #ifdef CPPPARSER
00325 #define ALIGN_4BYTE
00326 #define ALIGN_8BYTE
00327 #define ALIGN_16BYTE
00328 #elif defined(WIN32_VC)
00329 #define ALIGN_4BYTE __declspec(align(4))
00330 #define ALIGN_8BYTE __declspec(align(8))
00331 #define ALIGN_16BYTE __declspec(align(16))
00332 #elif defined(__GNUC__)
00333 #define ALIGN_4BYTE __attribute__ ((aligned (4)))
00334 #define ALIGN_8BYTE __attribute__ ((aligned (8)))
00335 #define ALIGN_16BYTE __attribute__ ((aligned (16)))
00336 #else
00337 #define ALIGN_4BYTE
00338 #define ALIGN_8BYTE
00339 #define ALIGN_16BYTE
00340 #endif
00341 
00342 // Do we need to implement memory-alignment enforcement within the
00343 // MemoryHook class, or will the underlying malloc implementation
00344 // provide it automatically?
00345 #if !defined(LINMATH_ALIGN)
00346 // We don't actually require any special memory-alignment beyond what
00347 // the underlying implementation is likely to provide anyway.
00348 #undef MEMORY_HOOK_DO_ALIGN
00349 
00350 #elif defined(USE_MEMORY_DLMALLOC)
00351 // This specialized malloc implementation can perform the required
00352 // alignment.
00353 #undef MEMORY_HOOK_DO_ALIGN
00354 
00355 #elif defined(USE_MEMORY_PTMALLOC2)
00356 // But not this one.  For some reason it crashes when we try to build
00357 // it with alignment 16.  So if we're using ptmalloc2, we need to
00358 // enforce alignment externally.
00359 #define MEMORY_HOOK_DO_ALIGN 1
00360 
00361 #elif defined(IS_OSX) || defined(_WIN64)
00362 // The OS-provided malloc implementation will do the required
00363 // alignment.
00364 #undef MEMORY_HOOK_DO_ALIGN
00365 
00366 #elif defined(MEMORY_HOOK_DO_ALIGN)
00367 // We need memory alignment, and we're willing to provide it ourselves.
00368 
00369 #else
00370 // We need memory alignment, and we haven't specified whether it
00371 // should be provided on top of the existing malloc library, or
00372 // otherwise.  Let's rely on dlmalloc to provide it, it seems to be
00373 // the most memory-efficient option.
00374 #define USE_MEMORY_DLMALLOC 1
00375 
00376 #endif
00377 
00378 /* Determine our memory-allocation requirements. */
00379 #if defined(USE_MEMORY_PTMALLOC2) || defined(USE_MEMORY_DLMALLOC) || defined(DO_MEMORY_USAGE) || defined(MEMORY_HOOK_DO_ALIGN)
00380 /* In this case we have some custom memory management requirements. */
00381 #else 
00382 /* Otherwise, if we have no custom memory management needs at all, we
00383    might as well turn it all off and go straight to the OS-level
00384    calls. */
00385 #define USE_MEMORY_NOWRAPPERS 1
00386 #endif
00387 
00388 /* We must always use the STL allocator nowadays, because we have
00389    redefined the constructors for pvector, pmap, etc. */
00390 #define USE_STL_ALLOCATOR 1
00391 
00392 /*
00393  We define the macros BEGIN_PUBLISH and END_PUBLISH to bracket
00394  functions and global variable definitions that are to be published
00395  via interrogate to scripting languages.  Also, the macro BLOCKING is
00396  used to flag any function or method that might perform I/O blocking
00397  and thus needs to release Python threads for its duration.
00398  */
00399 #ifdef CPPPARSER
00400 #define BEGIN_PUBLISH __begin_publish
00401 #define END_PUBLISH __end_publish
00402 #define BLOCKING __blocking
00403 #define MAKE_SEQ(seq_name, num_name, element_name) __make_seq(seq_name, num_name, element_name)
00404 #undef USE_STL_ALLOCATOR  /* Don't try to parse these template classes in interrogate. */
00405 #define EXTENSION(x) __extension x
00406 #define EXTEND __extension
00407 #define EXT_FUNC(func) ::func()
00408 #define EXT_FUNC_ARGS(func, ...) ::func(__VA_ARGS__)
00409 #define CALL_EXT_FUNC(func, ...) ::func (__VA_ARGS__)
00410 #else
00411 #define BEGIN_PUBLISH
00412 #define END_PUBLISH
00413 #define BLOCKING
00414 #define MAKE_SEQ(seq_name, num_name, element_name)
00415 #define EXTENSION(x)
00416 #define EXTEND
00417 /* If you change these, don't forget to also change it in interrogate itself. */
00418 #define _EXT_FUNC(func) _ext__ ## func
00419 #define EXT_FUNC(func) _EXT_FUNC(func) ()
00420 #define EXT_FUNC_ARGS(func, ...) _EXT_FUNC(func) (__VA_ARGS__)
00421 #define CALL_EXT_FUNC(func, ...) _EXT_METHOD(cl, m) (__VA_ARGS__)
00422 #endif
00423 
00424 #ifdef __cplusplus
00425 #include "dtoolbase_cc.h"
00426 #endif
00427 
00428 #endif
 All Classes Functions Variables Enumerations