Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/sconfig.h

Go to the documentation of this file.
00001 /*
00002  * lib/sconfig.h
00003  * 
00004  * Standard / shared basic config include for all lib/ files. 
00005  * 
00006  * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 
00029 #ifndef _LIB_SCONFIG_H_
00030 #define _LIB_SCONFIG_H_ 1
00031 
00032 /*
00033  * NOTE about #if and defined(): 
00034  * (This holds at least for gcc-3.4)
00035  * 
00036  * In case a symbol is NOT defined at all, then: 
00037  *   #if SYMBOL      will NOT be compiled
00038  *   #ifdef SYMBOL   will NOT be compiled
00039  *   #if !SYMBOL     WILL be compiled
00040  * 
00041  * In case a symbol is defined and empty (i.e. #define SYMBOL), then: 
00042  *   #if SYMBOL      is an error (#if with no expression)
00043  *   #ifdef SYMBOL   WILL be compiled
00044  *   #if !SYMBOL     is an error (operator '!' has no right operand)
00045  * 
00046  * In case a symbol is defined as 1 (i.e. #define SYMBOL 1), then: 
00047  *   #if SYMBOL      WILL be compiled
00048  *   #ifdef SYMBOL   WILL be compiled
00049  *   #if !SYMBOL     will NOT be compiled
00050  * 
00051  * In case a symbol is defined as 0 (i.e. #define SYMBOL 1), then: 
00052  *   #if SYMBOL      will NOT be compiled
00053  *   #ifdef SYMBOL   WILL be compiled
00054  *   #if !SYMBOL     WILL be compiled
00055  * 
00056  * NOTE also that identifiers are not compared as one may expect: 
00057  * #define SYMBOL foo
00058  *   #if SYMBOL == bar         WILL be compiled (although foo!=bar)
00059  *   #if SYMBOL != bar         will NOT compiled (although foo!=bar)
00060  *   #if SYMBOL                will NOT compiled
00061  *   #if !SYMBOL               WILL be compiled
00062  * 
00063  * HENCE, since configure will not define HAVE_XXX if we do not have it 
00064  *        and WILL define it to 1 if we DO have it, the following DOES 
00065  *        work: 
00066  *          #if HAVE_XXX        -> we have it
00067  *          #if !HAVE_XXX       -> we do not have it
00068  *        ...and note that this still works when we define HAVE_XXX to 0 
00069  *        in case we do NOT "have" it. AND it even works correctly when 
00070  *        we use && and || in the expression. 
00071  * 
00072  */
00073 
00074 /*#warning (------- Reading sconfig.h -------)*/
00075 
00076 /* THIS HERE... are the first lines of any source code file in hlib 
00077  * seen by the compiler. So this is the right place to make some 
00078  * important definitions. 
00079  */
00080 #if /*defined(__GNUC__) &&*/ !defined(_GNU_SOURCE)
00081 # define _GNU_SOURCE
00082 #endif
00083 
00084 /* This is (probably) needed on some systems. */
00085 #ifndef _REENTRANT
00086 # define _REENTRANT
00087 #endif
00088 
00089 /* NOTE: We do not rely on defined(__GNUC__) any more as nowadays the Intel 
00090  * compiler defines __GNUC__ as well. */
00091 
00092 #if !defined(__cplusplus) && \
00093   (defined(__CPLUSPLUS) || defined(c_plusplus) || defined(C_PLUSPLUS))
00094 #define __cplusplus 1
00095 #endif
00096 
00097 /*** FIRST, INCLUDE GLIB CONFIGURATION ***/
00098 
00099 #include <glibconfig.h>
00100 //#include "../3rdparty/glib/glibconfig.h"
00101 /* For win32, also include some extra config: */
00102 #if defined(G_OS_WIN32)
00103 # include "config-w32.h"
00104 #endif
00105 
00106 /* Include config header as generated by configure: */
00107 #if HAVE_CONFIG_H
00108 # include <config.h>
00109 #endif
00110 
00111 /* Need NULL, etc. */
00112 /* This is copied from autoconf manual and meant 
00113  * to save a lot of trouble... */
00114 #if STDC_HEADERS
00115 # include <stdlib.h>
00116 # include <stddef.h>
00117 #else
00118 # if HAVE_STDLIB_H
00119 #  include <stdlib.h>
00120 # endif
00121 #endif
00122 #if HAVE_STRING_H
00123 # if !STDC_HEADERS && HAVE_MEMORY_H
00124 #  include <memory.h>
00125 # endif
00126 # include <string.h>
00127 #endif
00128 #if HAVE_STRINGS_H
00129 # include <strings.h>
00130 #endif
00131 #if HAVE_INTTYPES_H
00132 # include <inttypes.h>
00133 #else
00134 # if HAVE_STDINT_H
00135 #  include <stdint.h>
00136 # endif
00137 #endif
00138 
00139 /*** ALL INCLUDES DONE. ***/
00140 
00141 #ifndef G_THREADS_ENABLED
00142 # error "You need to enable threads in glib."
00143 #endif
00144 
00147 #ifndef USE_PRIVATE__PTHREADS
00148 # ifdef G_THREADS_IMPL_POSIX
00149   /* Good, we're using the posix threads. So we can use or own native 
00150    * version which should be somewhat faster since it gets all inlined :) */
00151 #  define USE_PRIVATE__PTHREADS 1
00152 # else
00153 #  define USE_PRIVATE__PTHREADS 0
00154 # endif
00155 #endif
00156 
00157 /* See if we use Posix semaphores or if we emulate them using a mutex. */
00160 #ifndef USE_PRIVATE__POSIX_SEMAPHORES
00161 # if USE_PRIVATE__PTHREADS && HAVE_SEMAPHORE_H
00162 #  define USE_PRIVATE__POSIX_SEMAPHORES 1
00163 # else
00164 #  define USE_PRIVATE__POSIX_SEMAPHORES 0
00165 # endif
00166 #endif
00167 
00168 /* See if we use private atomic implementation. */
00171 #ifndef USE_PRIVATE__ATOMIC
00172 # if HAVE_ASM_ATOMIC_H || HAVE_ATOMIC_H
00173 #  define USE_PRIVATE__ATOMIC 1
00174 # else
00175 #  define USE_PRIVATE__ATOMIC 0
00176 # endif
00177 #endif
00178 
00179 /* See if we use private gettimeofday implementation. */
00180 // NOTE...
00181 #ifndef USE_PRIVATE__TIMEVAL
00182 # if HAVE_GETTIMEOFDAY
00183 #  define USE_PRIVATE__TIMEVAL 1
00184 #else
00185 #  define USE_PRIVATE__TIMEVAL 0
00186 # endif
00187 #endif
00188 
00189 
00191 typedef unsigned char uchar;
00192 
00195 typedef unsigned int uint;    // one word on the system
00196 
00198 typedef unsigned char uint8;  // 1 byte
00199 
00201 typedef signed char int8;  // 1 byte
00202 
00204 typedef guint16 uint16;     // 2 bytes
00205 
00207 typedef gint16 int16;     // 2 bytes
00208 
00210 typedef guint32 uint32;     // 4 bytes
00211 
00213 typedef gint32 int32;     // 4 bytes
00214 
00216 typedef guint64 uint64;     // 8 bytes
00217 
00219 typedef gint64 int64;     // 8 bytes
00220 
00221 
00223 typedef int64 filepos_t;
00224 
00226 typedef double dbl;
00227 
00229 typedef float flt;
00230 
00231 
00232 #if !HAVE_SSIZE_T
00233 typedef signed int ssize_t;
00234 #endif
00235 
00236 #if HAVE_ATTRIBUTE_ALWAYS_INLINE
00237 # ifdef __OPTIMIZE__
00238 #  define inline inline __attribute__((always_inline))
00239 # endif
00240 #endif
00241 
00242 #if HAVE_ATTRIBUTE_NOINLINE
00243 # define _noinline_  __attribute__((noinline))
00244 #endif
00245 
00246 /* USAGE: void _constfn_ _deprecated_ _pure_ ... function() { ... } */
00247 
00248 #if HAVE_ATTRIBUTE_CONST
00249 # define _constfn_  __attribute__((__const__))
00250 /*# warning "Attribute const present."*/
00251 #else
00252 # define _constfn_
00253 /*# warning "Attribute const missing."*/
00254 #endif
00255 
00256 #if HAVE_ATTRIBUTE_PURE
00257 # define _purefn_  __attribute__((pure))
00258 #else
00259 # define _purefn_
00260 #endif
00261 
00262 #if HAVE_ATTRIBUTE_DEPRECATED
00263 # define _deprecated_  __attribute__((deprecated))
00264 #else
00265 # define _deprecated_
00266 #endif
00267 
00268 /* USAGE: class _packed_ X {}; */
00269 #if HAVE_ATTRIBUTE_PACKED
00270 # define _packed_ __attribute__((__packed__))
00271 #else
00272 # define _packed_
00273 #endif
00274 
00275 /* USAGE: A::sprintf(const char *fmt,...) _fnformat_(__printf__,2,3); */
00276 #if HAVE_ATTRIBUTE_FORMAT
00277 # define _fnformat_(A,B,C) __attribute__((__format__ (A, B, C)))
00278 #else
00279 # define _fnformat_(A,B,C)
00280 #endif
00281 
00282 /* USAGE: int _unused_ rv; */
00283 #if HAVE_ATTRIBUTE_UNUSED
00284 # define _unused_ __attribute__((__unused__))
00285 #else
00286 # define _unused_
00287 #endif
00288 
00289 
00290 #if HAVE_FIELD_COLON_VALUE_INIT
00291 // This is the way g++ supports it. ISO C99 way (ala .x=) is yet missing in 
00292 // the C++ frontend while the C frontend has it. 
00293 #  define INIT_FIELD(x)  x:
00294 #else
00295 // 
00296 #  define INIT_FIELD(x) .x=
00297 #endif
00298 
00299 /* Finally, the static const member issue... */
00300 #if HAVE_STATIC_CONST_FP_MEMB
00301 #  define USE_STATIC_CONST_FP_MEMB 1
00302 #else
00303 #  define USE_STATIC_CONST_FP_MEMB 0
00304 #endif
00305 
00306 #ifndef DOXYGEN_IS_SCANNING
00307 /* These are useful for conditions which are (un)likely to happen, e.g. 
00308  *   if(unlikely(ptr==NULL))
00309  * This is actually taken from Linux kernel code. */
00310 #if HAVE_BUILTIN_EXPECT
00311 # define likely(x)    __builtin_expect(!!(x), 1)
00312 # define unlikely(x)  __builtin_expect(!!(x), 0)
00313 #else
00314 /*#warning "Do not have likely/unlikely."*/
00315 # define likely(x)    (x)
00316 # define unlikely(x)  (x)
00317 #endif
00318 #else  /* !defined(DOXYGEN_IS_SCANNING) */
00319 
00320 #error "We may not be here!"
00321 
00331 #define likely(x)
00332 
00343 #define unlikely(x)
00344 
00345 #endif  /* DOXYGEN_IS_SCANNING */
00346 
00347 
00348 /* Do some tweaks for doxygen: */
00349 #if defined(DOXYGEN_IS_SCANNING)
00350 # error "You may not compile with DOXYGEN_IS_SCANNING enabled."
00351 /*# undef _fnformat_
00352 #   define _fnformat_
00353 # undef _packed_
00354 #   define _packed_
00355 # undef _deprecated_
00356 #   define _deprecated_
00357 # undef _purefn_
00358 #   define _purefn_
00359 # undef _constfn_
00360 #   define _constfn_
00361 # undef _noinline_
00362 #   define _noinline_*/
00363 #endif
00364 
00365 
00366 #include <assert.h>
00367 
00395 #define Assert(X)    do { if(!likely(X)) assert(X); } while(0)
00396 
00408 #define CritAssert(X)   do { if(!likely(X)) assert(X); } while(0)
00409 
00410 
00416 #ifndef LMALLOC_DEBUGGING
00417 #define LMALLOC_DEBUGGING 1     /* Currently defaults to 1. */
00418 #endif
00419 
00420 #ifndef USE_MALLOC_USABLE_SIZE
00421 # define USE_MALLOC_USABLE_SIZE HAVE_MALLOC_USABLE_SIZE
00422 #endif
00423 
00424 /* We MUST include this to provide the correct operator new/delete. */
00425 #include <lib/salloc.h>
00426 
00427 #endif  /* _LIB_SCONFIG_H_ */

Generated on Sat Feb 19 22:33:46 2005 for Ray by doxygen 1.3.5