Panda3D

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 #ifdef __GNUC__
00123 // Large file >2GB support
00124 // this needs be be before systypes.h and other C headers
00125 #define _FILE_OFFSET_BITS 64
00126 #define _LARGEFILE_SOURCE 1
00127 #endif
00128 
00129 #ifdef PHAVE_TYPES_H
00130 #include <types.h>
00131 #endif
00132 
00133 #ifdef PHAVE_SYS_TYPES_H
00134 #include <sys/types.h>
00135 #endif
00136 
00137 #ifdef PHAVE_MALLOC_H
00138 #include <malloc.h>
00139 #endif
00140 
00141 #ifdef PHAVE_SYS_MALLOC_H
00142 #include <sys/malloc.h>
00143 #endif
00144 
00145 #ifdef PHAVE_ALLOCA_H
00146 #include <alloca.h>
00147 #endif
00148 
00149 #ifdef PHAVE_UNISTD_H
00150 #include <unistd.h>
00151 #endif
00152 
00153 #ifdef PHAVE_IO_H
00154 #include <io.h>
00155 #endif
00156 
00157 #ifdef PHAVE_LOCALE_H
00158 #include <locale.h>
00159 #endif
00160 
00161 #ifdef PHAVE_STRING_H
00162 #include <string.h>
00163 #endif
00164 
00165 #ifdef PHAVE_STDLIB_H
00166 #include <stdlib.h>
00167 #endif
00168 
00169 #ifdef PHAVE_LIMITS_H
00170 #include <limits.h>
00171 #endif
00172 
00173 #ifdef PHAVE_MINMAX_H
00174 #include <minmax.h>
00175 #endif
00176 
00177 #ifdef PHAVE_SYS_TIME_H
00178 #include <sys/time.h>
00179 #endif
00180 
00181 #ifdef PHAVE_STDINT_H
00182 #include <stdint.h>
00183 #endif
00184 
00185 #ifdef CPPPARSER
00186 #include <stdtypedefs.h>
00187 #endif
00188 
00189 #ifdef USE_TAU
00190 /* If we're building with the Tau instrumentor, include the
00191    appropriate header file to pick up the TAU macros. */
00192 #include <TAU.h>
00193 #include <Profile/Profiler.h>
00194 #else
00195 /* Otherwise, if we're not building with the Tau instrumentor, turn
00196    off all the TAU macros.  We could include the Tau header file to do
00197    this, but it's better not to assume that Tau is installed. */
00198 #define TAU_TYPE_STRING(profileString, str)
00199 #define TAU_PROFILE(name, type, group)
00200 #define TAU_PROFILE_TIMER(var, name, type, group)
00201 #define TAU_PROFILE_START(var)
00202 #define TAU_PROFILE_STOP(var)
00203 #define TAU_PROFILE_STMT(stmt)
00204 #define TAU_PROFILE_EXIT(msg)
00205 #define TAU_PROFILE_INIT(argc, argv)
00206 #define TAU_PROFILE_SET_NODE(node)
00207 #define TAU_PROFILE_SET_CONTEXT(context)
00208 #define TAU_PROFILE_SET_GROUP_NAME(newname)
00209 #define TAU_PROFILE_TIMER_SET_GROUP_NAME(t, newname)
00210 #define TAU_PROFILE_CALLSTACK()
00211 #define TAU_DB_DUMP()
00212 #define TAU_DB_PURGE()
00213 
00214 #define TAU_REGISTER_CONTEXT_EVENT(event, name)
00215 #define TAU_CONTEXT_EVENT(event, data)
00216 #define TAU_DISABLE_CONTEXT_EVENT(event)
00217 #define TAU_ENABLE_CONTEXT_EVENT(event)
00218 
00219 #define TAU_REGISTER_EVENT(event, name)
00220 #define TAU_EVENT(event, data)
00221 #define TAU_EVENT_DISABLE_MIN(event)
00222 #define TAU_EVENT_DISABLE_MAX(event)
00223 #define TAU_EVENT_DISABLE_MEAN(event)
00224 #define TAU_EVENT_DISABLE_STDDEV(event)
00225 #define TAU_REPORT_STATISTICS()
00226 #define TAU_REPORT_THREAD_STATISTICS()
00227 #define TAU_REGISTER_THREAD()
00228 #define TAU_REGISTER_FORK(id, op)
00229 #define TAU_ENABLE_INSTRUMENTATION()
00230 #define TAU_DISABLE_INSTRUMENTATION()
00231 #define TAU_ENABLE_GROUP(group)
00232 #define TAU_DISABLE_GROUP(group)
00233 #define TAU_ENABLE_GROUP_NAME(group)
00234 #define TAU_DISABLE_GROUP_NAME(group)
00235 #define TAU_ENABLE_ALL_GROUPS()
00236 #define TAU_DISABLE_ALL_GROUPS()
00237 #define TAU_TRACK_MEMORY()
00238 #define TAU_TRACK_MEMORY_HERE()
00239 #define TAU_ENABLE_TRACKING_MEMORY()
00240 #define TAU_DISABLE_TRACKING_MEMORY()
00241 #define TAU_TRACK_MEMORY()
00242 #define TAU_TRACK_MEMORY_HERE()
00243 #define TAU_ENABLE_TRACKING_MUSE_EVENTS()
00244 #define TAU_DISABLE_TRACKING_MUSE_EVENTS()
00245 #define TAU_TRACK_MUSE_EVENTS()
00246 #define TAU_SET_INTERRUPT_INTERVAL(value)
00247 
00248 #define TAU_TRACE_SENDMSG(type, destination, length)
00249 #define TAU_TRACE_RECVMSG(type, source, length)
00250 
00251 #define TAU_MAPPING(stmt, group) stmt
00252 #define TAU_MAPPING_OBJECT(FuncInfoVar)
00253 #define TAU_MAPPING_LINK(FuncInfoVar, Group)
00254 #define TAU_MAPPING_PROFILE(FuncInfoVar)
00255 #define TAU_MAPPING_CREATE(name, type, key, groupname, tid)
00256 #define TAU_MAPPING_PROFILE_TIMER(Timer, FuncInfoVar, tid)
00257 #define TAU_MAPPING_TIMER_CREATE(t, name, type, gr, group_name)
00258 #define TAU_MAPPING_PROFILE_START(Timer, tid)
00259 #define TAU_MAPPING_PROFILE_STOP(tid)
00260 #define TAU_MAPPING_PROFILE_EXIT(msg, tid)
00261 #define TAU_MAPPING_DB_DUMP(tid)
00262 #define TAU_MAPPING_DB_PURGE(tid)
00263 #define TAU_MAPPING_PROFILE_SET_NODE(node, tid)
00264 #define TAU_MAPPING_PROFILE_SET_GROUP_NAME(timer, name)
00265 #define TAU_PROFILE_TIMER_SET_NAME(t, newname)
00266 #define TAU_PROFILE_TIMER_SET_TYPE(t, newname)
00267 #define TAU_PROFILE_TIMER_SET_GROUP(t, id)
00268 #define TAU_MAPPING_PROFILE_SET_NAME(timer, name)
00269 #define TAU_MAPPING_PROFILE_SET_TYPE(timer, name)
00270 #define TAU_MAPPING_PROFILE_SET_GROUP(timer, id)
00271 #define TAU_MAPPING_PROFILE_GET_GROUP_NAME(timer)
00272 #define TAU_MAPPING_PROFILE_GET_GROUP(timer)
00273 #define TAU_MAPPING_PROFILE_GET_NAME(timer)
00274 #define TAU_MAPPING_PROFILE_GET_TYPE(timer)
00275 
00276 #define TAU_PHASE(name, type, group)
00277 #define TAU_PHASE_CREATE_STATIC(var, name, type, group)
00278 #define TAU_PHASE_CREATE_DYNAMIC(var, name, type, group)
00279 #define TAU_PHASE_START(var)
00280 #define TAU_PHASE_STOP(var)
00281 #define TAU_GLOBAL_PHASE(timer, name, type, group)
00282 #define TAU_GLOBAL_PHASE_START(timer)
00283 #define TAU_GLOBAL_PHASE_STOP(timer)
00284 #define TAU_GLOBAL_PHASE_EXTERNAL(timer)
00285 #define TAU_GLOBAL_TIMER(timer, name, type, group)
00286 #define TAU_GLOBAL_TIMER_EXTERNAL(timer)
00287 #define TAU_GLOBAL_TIMER_START(timer)
00288 #define TAU_GLOBAL_TIMER_STOP()
00289 
00290 #endif  /* USE_TAU */
00291 
00292 /* Try to infer the endianness of the host based on compiler
00293    predefined macros.  For systems on which the compiler does not
00294    define these macros, we rely on ppremake to define WORDS_BIGENDIAN
00295    correctly.  For systems on which the compiler *does* define these
00296    macros, we ignore what ppremake said and define WORDS_BIGENDIAN
00297    correctly here.  (This is essential on OSX, which requires
00298    compiling each file twice in different modes, for universal binary
00299    support.) */
00300 
00301 #if defined(__LITTLE_ENDIAN__) || defined(__i386__)
00302 #undef WORDS_BIGENDIAN
00303 
00304 #elif defined(__BIG_ENDIAN__) || defined(__ppc__)
00305 #undef WORDS_BIGENDIAN
00306 #define WORDS_BIGENDIAN 1
00307 
00308 #endif
00309 
00310 /* Try to determine if we're compiling in a 64-bit mode. */
00311 
00312 #ifdef __WORDSIZE
00313 #define NATIVE_WORDSIZE __WORDSIZE
00314 #elif defined(_LP64)
00315 #define NATIVE_WORDSIZE 64
00316 #else
00317 #define NATIVE_WORDSIZE 32
00318 #endif
00319 
00320 /* Some byte-alignment macros. */
00321 #ifdef CPPPARSER
00322 #define ALIGN_4BYTE
00323 #define ALIGN_8BYTE
00324 #define ALIGN_16BYTE
00325 #elif defined(WIN32_VC)
00326 #define ALIGN_4BYTE __declspec(align(4))
00327 #define ALIGN_8BYTE __declspec(align(8))
00328 #define ALIGN_16BYTE __declspec(align(16))
00329 #elif defined(__GNUC__)
00330 #define ALIGN_4BYTE __attribute__ ((aligned (4)))
00331 #define ALIGN_8BYTE __attribute__ ((aligned (8)))
00332 #define ALIGN_16BYTE __attribute__ ((aligned (16)))
00333 #else
00334 #define ALIGN_4BYTE
00335 #define ALIGN_8BYTE
00336 #define ALIGN_16BYTE
00337 #endif
00338 
00339 // Do we need to implement memory-alignment enforcement within the
00340 // MemoryHook class, or will the underlying malloc implementation
00341 // provide it automatically?
00342 #if !defined(LINMATH_ALIGN)
00343 // We don't actually require any special memory-alignment beyond what
00344 // the underlying implementation is likely to provide anyway.
00345 #undef MEMORY_HOOK_DO_ALIGN
00346 
00347 #elif defined(USE_MEMORY_DLMALLOC)
00348 // This specialized malloc implementation can perform the required
00349 // alignment.
00350 #undef MEMORY_HOOK_DO_ALIGN
00351 
00352 #elif defined(USE_MEMORY_PTMALLOC2)
00353 // But not this one.  For some reason it crashes when we try to build
00354 // it with alignment 16.  So if we're using ptmalloc2, we need to
00355 // enforce alignment externally.
00356 #define MEMORY_HOOK_DO_ALIGN 1
00357 
00358 #elif defined(IS_OSX) || defined(_WIN64)
00359 // The OS-provided malloc implementation will do the required
00360 // alignment.
00361 #undef MEMORY_HOOK_DO_ALIGN
00362 
00363 #elif defined(MEMORY_HOOK_DO_ALIGN)
00364 // We need memory alignment, and we're willing to provide it ourselves.
00365 
00366 #else
00367 // We need memory alignment, and we haven't specified whether it
00368 // should be provided on top of the existing malloc library, or
00369 // otherwise.  Let's rely on dlmalloc to provide it, it seems to be
00370 // the most memory-efficient option.
00371 #define USE_MEMORY_DLMALLOC 1
00372 
00373 #endif
00374 
00375 /* Determine our memory-allocation requirements. */
00376 #if defined(USE_MEMORY_PTMALLOC2) || defined(USE_MEMORY_DLMALLOC) || defined(DO_MEMORY_USAGE) || defined(MEMORY_HOOK_DO_ALIGN)
00377 /* In this case we have some custom memory management requirements. */
00378 #else 
00379 /* Otherwise, if we have no custom memory management needs at all, we
00380    might as well turn it all off and go straight to the OS-level
00381    calls. */
00382 #define USE_MEMORY_NOWRAPPERS 1
00383 #endif
00384 
00385 /* We must always use the STL allocator nowadays, because we have
00386    redefined the constructors for pvector, pmap, etc. */
00387 #define USE_STL_ALLOCATOR 1
00388 
00389 /*
00390  We define the macros BEGIN_PUBLISH and END_PUBLISH to bracket
00391  functions and global variable definitions that are to be published
00392  via interrogate to scripting languages.  Also, the macro BLOCKING is
00393  used to flag any function or method that might perform I/O blocking
00394  and thus needs to release Python threads for its duration.
00395  */
00396 #ifdef CPPPARSER
00397 #define BEGIN_PUBLISH __begin_publish
00398 #define END_PUBLISH __end_publish
00399 #define BLOCKING __blocking
00400 #define MAKE_SEQ(seq_name, num_name, element_name) __make_seq(seq_name, num_name, element_name)
00401 #undef USE_STL_ALLOCATOR  /* Don't try to parse these template classes in interrogate. */
00402 #define EXTENSION(x) __extension x
00403 #define EXTEND __extension
00404 #define EXT_FUNC(func) ::func()
00405 #define EXT_FUNC_ARGS(func, ...) ::func(__VA_ARGS__)
00406 #define CALL_EXT_FUNC(func, ...) ::func (__VA_ARGS__)
00407 #else
00408 #define BEGIN_PUBLISH
00409 #define END_PUBLISH
00410 #define BLOCKING
00411 #define MAKE_SEQ(seq_name, num_name, element_name)
00412 #define EXTENSION(x)
00413 #define EXTEND
00414 /* If you change these, don't forget to also change it in interrogate itself. */
00415 #define _EXT_FUNC(func) _ext__ ## func
00416 #define EXT_FUNC(func) _EXT_FUNC(func) ()
00417 #define EXT_FUNC_ARGS(func, ...) _EXT_FUNC(func) (__VA_ARGS__)
00418 #define CALL_EXT_FUNC(func, ...) _EXT_METHOD(cl, m) (__VA_ARGS__)
00419 #endif
00420 
00421 #ifdef __cplusplus
00422 #include "dtoolbase_cc.h"
00423 #endif
00424 
00425 #endif
00426 
 All Classes Functions Variables Enumerations