cssysdef.h
Go to the documentation of this file.
00001 /* 00002 Copyright (C) 1998-2008 by Jorrit Tyberghein 00003 Written by Andrew Zabolotny <bit@eltech.ru> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_CSSYSDEF_H__ 00021 #define __CS_CSSYSDEF_H__ 00022 00023 #define CSDEF_FRIEND 00024 #include "csdef.h" 00025 #undef CSDEF_FRIEND 00026 00036 /* 00037 * Pull in platform-specific overrides of the requested functionality. 00038 */ 00039 #include "csutil/csosdefs.h" 00040 00041 // Defaults for platforms that do not define their own. 00042 #ifndef CS_VISIBILITY_DEFAULT 00043 # define CS_VISIBILITY_DEFAULT 00044 #endif 00045 #ifndef CS_VISIBILITY_HIDDEN 00046 # define CS_VISIBILITY_HIDDEN 00047 #endif 00048 #ifndef CS_EXPORT_SYM_DLL 00049 # define CS_EXPORT_SYM_DLL CS_VISIBILITY_DEFAULT 00050 #endif 00051 #ifndef CS_IMPORT_SYM_DLL 00052 # define CS_IMPORT_SYM_DLL extern 00053 #endif 00054 #ifndef CS_EXPORT_SYM 00055 # if defined(CS_BUILD_SHARED_LIBS) 00056 # define CS_EXPORT_SYM CS_VISIBILITY_DEFAULT 00057 # else 00058 # define CS_EXPORT_SYM 00059 # endif 00060 #endif 00061 #ifndef CS_IMPORT_SYM 00062 # define CS_IMPORT_SYM 00063 #endif 00064 00065 #include "csextern.h" 00066 00067 /* On MinGW, with some versions of the MinGW runtime (3.15 and above), using 00068 the STL together with -ansi is broken: the C runtime functions swprintf() 00069 and vswprintf() are not declared, but an STL header (<cwchar>) 00070 unconditionally references it via 'using'. 00071 To work around the problem provide our own dummy declarations of these 00072 functions. */ 00073 #if defined(__STRICT_ANSI__) && \ 00074 (defined(CS_ANSI_BREAKS_SWPRINTF) || defined(CS_ANSI_BREAKS_VSWPRINTF)) 00075 #if defined(CS_ANSI_BREAKS_SWPRINTF) 00076 int swprintf (); 00077 #endif 00078 #if defined(CS_ANSI_BREAKS_VSWPRINTF) 00079 int vswprintf (); 00080 #endif 00081 #include <cwchar> 00082 #endif 00083 00084 /* 00085 * Default definitions for requested functionality. Platform-specific 00086 * configuration files may override these. 00087 */ 00088 00089 #ifndef CS_FORCEINLINE 00090 # ifdef CS_COMPILER_GCC 00091 # define CS_FORCEINLINE inline __attribute__((always_inline)) 00092 # if (__GNUC__ == 3) && (__GNUC_MINOR__ == 4) 00093 // Work around a gcc 3.4 issue where forcing inline doesn't always work 00094 # define CS_FORCEINLINE_TEMPLATEMETHOD inline 00095 # endif 00096 # else 00097 # define CS_FORCEINLINE inline 00098 # endif 00099 #endif 00100 #ifndef CS_FORCEINLINE_TEMPLATEMETHOD 00101 # define CS_FORCEINLINE_TEMPLATEMETHOD CS_FORCEINLINE 00102 #endif 00103 00108 #ifndef CS_ATTRIBUTE_MALLOC 00109 # define CS_ATTRIBUTE_MALLOC 00110 #endif 00111 00115 #ifndef CS_ATTRIBUTE_INIT_PRIORITY 00116 # define CS_ATTRIBUTE_INIT_PRIORITY(PRI) 00117 #endif 00118 00119 // Set up deprecation macros 00120 #ifdef CS_COMPILER_GCC 00121 # define CS_DEPRECATED_METHOD CS_ATTRIBUTE_DEPRECATED 00122 # define CS_DEPRECATED_TYPE CS_ATTRIBUTE_DEPRECATED 00123 # define CS_DEPRECATED_VAR(decl) decl CS_ATTRIBUTE_DEPRECATED 00124 #endif 00125 00137 #if !defined(CS_DEPRECATED_METHOD) || defined(DOXYGEN_RUN) 00138 # if defined(CS_COMPILER_MSVC) 00139 # define CS_DEPRECATED_METHOD __declspec(deprecated) 00140 /* Unfortunately, MSVC is overzealous with warnings; it even emits one 00141 when a deprecated method is overridden, e.g. when implementing an 00142 interface method. 00143 To work around this, use msvc_deprecated_warn_off.h/ 00144 msvc_deprecated_warn_on.h. */ 00145 # else 00146 # define CS_DEPRECATED_METHOD 00147 # endif 00148 #endif 00149 00154 #if !defined(CS_DEPRECATED_METHOD_MSG) || defined(DOXYGEN_RUN) 00155 # if defined(CS_COMPILER_MSVC) && _MSC_VER >= 1400 00156 # define CS_DEPRECATED_METHOD_MSG(msg) __declspec(deprecated(msg)) 00157 # else 00158 # define CS_DEPRECATED_METHOD_MSG(msg) CS_DEPRECATED_METHOD 00159 # endif 00160 #endif 00161 00172 #if !defined(CS_DEPRECATED_TYPE) || defined(DOXYGEN_RUN) 00173 # if defined(CS_COMPILER_MSVC) 00174 # define CS_DEPRECATED_TYPE __declspec(deprecated) 00175 # else 00176 # define CS_DEPRECATED_TYPE 00177 # endif 00178 #endif 00179 00184 #if !defined(CS_DEPRECATED_TYPE_MSG) || defined(DOXYGEN_RUN) 00185 # if defined(CS_COMPILER_MSVC) && _MSC_VER >= 1400 00186 # define CS_DEPRECATED_TYPE_MSG(msg) __declspec(deprecated(msg)) 00187 # else 00188 # define CS_DEPRECATED_TYPE_MSG(msg) CS_DEPRECATED_TYPE 00189 # endif 00190 #endif 00191 00205 #if !defined(CS_DEPRECATED_VAR) || defined(DOXYGEN_RUN) 00206 # if defined(CS_COMPILER_MSVC) 00207 # define CS_DEPRECATED_VAR(decl) __declspec(deprecated) decl 00208 # else 00209 # define CS_DEPRECATED_VAR(decl) decl 00210 # endif 00211 #endif 00212 00217 #if !defined(CS_DEPRECATED_VAR_MSG) || defined(DOXYGEN_RUN) 00218 # if defined(CS_COMPILER_MSVC) && _MSC_VER >= 1400 00219 # define CS_DEPRECATED_VAR_MSG(msg, decl) __declspec(deprecated(msg)) decl 00220 # else 00221 # define CS_DEPRECATED_VAR_MSG(msg, decl) CS_DEPRECATED_VAR(decl) 00222 # endif 00223 #endif 00224 00229 #if defined(CS_COMPILER_MSVC) 00230 #include <exception> 00231 #if !_HAS_EXCEPTIONS 00232 #define CS_NO_EXCEPTIONS 00233 #endif 00234 #elif defined(CS_COMPILER_GCC) && !defined(__EXCEPTIONS) 00235 #define CS_NO_EXCEPTIONS 00236 #endif 00237 00242 #ifndef CS_MAXPATHLEN 00243 #define CS_MAXPATHLEN 1024 00244 #endif 00245 #include <stdio.h> 00246 #ifdef CS_HAVE_SYS_PARAM_H 00247 #include <sys/param.h> 00248 #endif 00249 00256 #if defined(CS_COMPILER_GCC) && !defined(__STRICT_ANSI__) 00257 // In GCC we are able to declare stack vars of dynamic size directly 00258 # define CS_ALLOC_STACK_ARRAY(type, var, size) \ 00259 type var [size] 00260 #else 00261 # include <stdlib.h> 00262 # define CS_ALLOC_STACK_ARRAY(type, var, size) \ 00263 type *var = (type *)alloca ((size) * sizeof (type)) 00264 # if defined(CS_COMPILER_GCC) && defined(__STRICT_ANSI__) && !defined(alloca) 00265 # define alloca(x) __builtin_alloca(x) 00266 # endif 00267 #endif 00268 00269 00293 #define CS_HEADER_GLOBAL(X,Y) CS_HEADER_GLOBAL_COMPOSE(X,Y) 00294 #define CS_HEADER_GLOBAL_COMPOSE(X,Y) <X/Y> 00295 00308 #define CS_HEADER_LOCAL(X,Y) CS_HEADER_LOCAL_COMPOSE1(X,Y) 00309 #define CS_HEADER_LOCAL_COMPOSE1(X,Y) CS_HEADER_LOCAL_COMPOSE2(X/Y) 00310 #define CS_HEADER_LOCAL_COMPOSE2(X) #X 00311 00312 00318 #if !defined(CS_EXPORTED_FUNCTION) 00319 # if defined(CS_STATIC_LINKED) 00320 # define CS_EXPORTED_FUNCTION extern "C" 00321 # else 00322 # define CS_EXPORTED_FUNCTION extern "C" CS_EXPORT_SYM_DLL 00323 # endif 00324 #endif 00325 00337 #if !defined(CS_EXPORTED_NAME) 00338 # define CS_EXPORTED_NAME(Prefix, Suffix) Prefix ## Suffix 00339 #endif 00340 00341 #ifndef CS_IMPLEMENT_PLATFORM_PLUGIN 00342 # define CS_IMPLEMENT_PLATFORM_PLUGIN 00343 #endif 00344 00345 #ifndef CS_IMPLEMENT_PLATFORM_APPLICATION 00346 # define CS_IMPLEMENT_PLATFORM_APPLICATION 00347 #endif 00348 00355 #ifndef CS_INITIALIZE_PLATFORM_APPLICATION 00356 # define CS_INITIALIZE_PLATFORM_APPLICATION /* */ 00357 /* 00358 This definition may seem odd, but it's here for doxygen's sake, which 00359 apparently fails to document empty macro definitions. 00360 */ 00361 #endif 00362 00363 typedef void (*csStaticVarCleanupFN) (void (*p)()); 00364 extern csStaticVarCleanupFN csStaticVarCleanup; 00365 00366 #ifndef CS_IMPLEMENT_STATIC_VARIABLE_REGISTRATION 00367 # define CS_IMPLEMENT_STATIC_VARIABLE_REGISTRATION(Name) \ 00368 void Name (void (*p)()) \ 00369 { \ 00370 static void (**a)() = 0; \ 00371 static int lastEntry = 0; \ 00372 static int maxEntries = 0; \ 00373 \ 00374 if (p != 0) \ 00375 { \ 00376 if (lastEntry >= maxEntries) \ 00377 { \ 00378 maxEntries += 10; \ 00379 if (a == 0) \ 00380 a = (void (**)())malloc(maxEntries * sizeof(void*)); \ 00381 else \ 00382 a = (void (**)())realloc(a, maxEntries * sizeof(void*)); \ 00383 } \ 00384 a[lastEntry++] = p; \ 00385 } \ 00386 else if (a != 0) \ 00387 { \ 00388 for (int i = lastEntry - 1; i >= 0; i--) \ 00389 a[i] (); \ 00390 free (a); \ 00391 a = 0; \ 00392 lastEntry = 0; \ 00393 maxEntries = 0; \ 00394 } \ 00395 } 00396 #endif 00397 00398 #ifndef CS_DEFINE_STATIC_VARIABLE_REGISTRATION 00399 # define CS_DEFINE_STATIC_VARIABLE_REGISTRATION(func) \ 00400 csStaticVarCleanupFN csStaticVarCleanup = &func 00401 #endif 00402 00403 #ifndef CS_DECLARE_STATIC_VARIABLE_REGISTRATION 00404 # define CS_DECLARE_STATIC_VARIABLE_REGISTRATION(func) \ 00405 void func (void (*p)()) 00406 #endif 00407 00408 #ifndef CS_DECLARE_DEFAULT_STATIC_VARIABLE_REGISTRATION 00409 # define CS_DECLARE_DEFAULT_STATIC_VARIABLE_REGISTRATION \ 00410 CS_CRYSTALSPACE_EXPORT \ 00411 CS_DECLARE_STATIC_VARIABLE_REGISTRATION (csStaticVarCleanup_csutil); 00412 #endif 00413 00414 /* scfStaticallyLinked - Flag indicating whether external linkage was used when 00415 * building the application. Determines whether SCF scans for plugins at 00416 * startup. 00417 */ 00421 #if defined(CS_BUILD_SHARED_LIBS) 00422 # define CS_DEFINE_STATICALLY_LINKED_FLAG 00423 #elif defined(CS_STATIC_LINKED) 00424 # define CS_DEFINE_STATICALLY_LINKED_FLAG bool scfStaticallyLinked = true; 00425 #else 00426 # define CS_DEFINE_STATICALLY_LINKED_FLAG bool scfStaticallyLinked = false; 00427 #endif 00428 00429 #if defined(CS_EXTENSIVE_MEMDEBUG) || defined(CS_MEMORY_TRACKER) 00430 # define CS_DEFINE_MEMTRACKER_MODULE \ 00431 class csMemTrackerModule; \ 00432 namespace CS \ 00433 { \ 00434 namespace Debug \ 00435 { \ 00436 namespace MemTracker \ 00437 { \ 00438 namespace Impl \ 00439 { \ 00440 csMemTrackerModule* thisModule = 0; \ 00441 } \ 00442 } \ 00443 } \ 00444 } 00445 #else 00446 # define CS_DEFINE_MEMTRACKER_MODULE 00447 #endif 00448 00468 #ifndef CS_IMPLEMENT_FOREIGN_DLL 00469 # if defined(CS_BUILD_SHARED_LIBS) 00470 # define CS_IMPLEMENT_FOREIGN_DLL \ 00471 CS_IMPLEMENT_STATIC_VARIABLE_REGISTRATION(csStaticVarCleanup_local); \ 00472 CS_DEFINE_STATICALLY_LINKED_FLAG \ 00473 CS_DEFINE_STATIC_VARIABLE_REGISTRATION (csStaticVarCleanup_local); \ 00474 CS_DEFINE_MEMTRACKER_MODULE 00475 # else 00476 # define CS_IMPLEMENT_FOREIGN_DLL \ 00477 CS_DECLARE_DEFAULT_STATIC_VARIABLE_REGISTRATION \ 00478 CS_DEFINE_STATICALLY_LINKED_FLAG \ 00479 CS_DEFINE_STATIC_VARIABLE_REGISTRATION (csStaticVarCleanup_csutil); \ 00480 CS_DEFINE_MEMTRACKER_MODULE 00481 # endif 00482 #endif 00483 00492 #if defined(CS_STATIC_LINKED) 00493 00494 # ifndef CS_IMPLEMENT_PLUGIN 00495 # define CS_IMPLEMENT_PLUGIN \ 00496 CS_IMPLEMENT_PLATFORM_PLUGIN 00497 # endif 00498 00499 #elif !defined(CS_BUILD_SHARED_LIBS) 00500 00501 # ifndef CS_IMPLEMENT_PLUGIN 00502 # define CS_IMPLEMENT_PLUGIN \ 00503 CS_IMPLEMENT_PLATFORM_PLUGIN \ 00504 CS_DEFINE_STATICALLY_LINKED_FLAG \ 00505 CS_DECLARE_DEFAULT_STATIC_VARIABLE_REGISTRATION \ 00506 CS_DEFINE_STATIC_VARIABLE_REGISTRATION (csStaticVarCleanup_csutil); \ 00507 CS_DEFINE_MEMTRACKER_MODULE 00508 # endif 00509 00510 #else 00511 00512 # ifndef CS_IMPLEMENT_PLUGIN 00513 # define CS_IMPLEMENT_PLUGIN \ 00514 CS_DEFINE_STATICALLY_LINKED_FLAG \ 00515 CS_IMPLEMENT_STATIC_VARIABLE_REGISTRATION(csStaticVarCleanup_local) \ 00516 CS_DEFINE_STATIC_VARIABLE_REGISTRATION (csStaticVarCleanup_local); \ 00517 CS_IMPLEMENT_PLATFORM_PLUGIN \ 00518 CS_DEFINE_MEMTRACKER_MODULE 00519 # endif 00520 00521 #endif 00522 00531 #ifndef CS_IMPLEMENT_APPLICATION 00532 # define CS_IMPLEMENT_APPLICATION \ 00533 CS_DECLARE_DEFAULT_STATIC_VARIABLE_REGISTRATION \ 00534 CS_DEFINE_STATICALLY_LINKED_FLAG \ 00535 CS_DEFINE_STATIC_VARIABLE_REGISTRATION (csStaticVarCleanup_csutil); \ 00536 CS_IMPLEMENT_PLATFORM_APPLICATION \ 00537 CS_DEFINE_MEMTRACKER_MODULE 00538 #endif 00539 00543 #ifndef CS_REGISTER_STATIC_FOR_DESTRUCTION 00544 #define CS_REGISTER_STATIC_FOR_DESTRUCTION(getterFunc)\ 00545 csStaticVarCleanup (getterFunc); 00546 #endif 00547 00551 #ifndef CS_STATIC_VARIABLE_CLEANUP 00552 #define CS_STATIC_VARIABLE_CLEANUP \ 00553 csStaticVarCleanup (0); 00554 #endif 00555 00568 #ifndef CS_IMPLEMENT_STATIC_VAR_EXT 00569 #define CS_IMPLEMENT_STATIC_VAR_EXT(getterFunc,Type,initParam,kill_how) \ 00570 namespace { \ 00571 static Type *getterFunc ## _v=0; \ 00572 static Type* getterFunc (); \ 00573 static void getterFunc ## _kill (); \ 00574 static void getterFunc ## _kill_array (); \ 00575 void getterFunc ## _kill () \ 00576 { \ 00577 (void)(&getterFunc ## _kill_array); \ 00578 delete getterFunc ## _v; \ 00579 getterFunc ## _v = 0; \ 00580 } \ 00581 void getterFunc ## _kill_array () \ 00582 { \ 00583 (void)(&getterFunc ## _kill); \ 00584 delete [] getterFunc ## _v; \ 00585 getterFunc ## _v = 0; \ 00586 } \ 00587 Type* getterFunc () \ 00588 { \ 00589 if (!getterFunc ## _v) \ 00590 { \ 00591 getterFunc ## _v = new Type initParam; \ 00592 csStaticVarCleanup (getterFunc ## kill_how); \ 00593 } \ 00594 return getterFunc ## _v; \ 00595 } \ 00596 } 00597 #endif 00598 00599 #ifndef CS_IMPLEMENT_STATIC_VAR 00600 #define CS_IMPLEMENT_STATIC_VAR(getterFunc,Type,initParam) \ 00601 CS_IMPLEMENT_STATIC_VAR_EXT(getterFunc,Type,initParam,_kill) 00602 #endif 00603 00604 #ifndef CS_IMPLEMENT_STATIC_VAR_ARRAY 00605 #define CS_IMPLEMENT_STATIC_VAR_ARRAY(getterFunc,Type,initParam) \ 00606 CS_IMPLEMENT_STATIC_VAR_EXT(getterFunc,Type,initParam,_kill_array) 00607 #endif 00608 00616 #ifndef CS_DECLARE_STATIC_CLASSVAR 00617 #define CS_DECLARE_STATIC_CLASSVAR(var,getterFunc,Type) \ 00618 static Type *var; \ 00619 static Type *getterFunc (); \ 00620 static void getterFunc ## _kill (); \ 00621 static void getterFunc ## _kill_array (); 00622 #endif 00623 00624 #ifndef CS_DECLARE_STATIC_CLASSVAR_REF 00625 #define CS_DECLARE_STATIC_CLASSVAR_REF(var,getterFunc,Type) \ 00626 static Type *var; \ 00627 static Type &getterFunc (); \ 00628 static void getterFunc ## _kill (); \ 00629 static void getterFunc ## _kill_array (); 00630 #endif 00631 00642 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_EXT 00643 #define CS_IMPLEMENT_STATIC_CLASSVAR_EXT(Class,var,getterFunc,Type,initParam,\ 00644 kill_how) \ 00645 Type *Class::var = 0; \ 00646 void Class::getterFunc ## _kill () \ 00647 { \ 00648 delete getterFunc (); \ 00649 var = 0; \ 00650 } \ 00651 void Class::getterFunc ## _kill_array () \ 00652 { \ 00653 delete [] getterFunc (); \ 00654 var = 0; \ 00655 } \ 00656 Type* Class::getterFunc () \ 00657 { \ 00658 if (!var) \ 00659 { \ 00660 var = new Type initParam; \ 00661 csStaticVarCleanup (getterFunc ## kill_how); \ 00662 } \ 00663 return var; \ 00664 } 00665 #endif 00666 00667 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR 00668 #define CS_IMPLEMENT_STATIC_CLASSVAR(Class,var,getterFunc,Type,initParam) \ 00669 CS_IMPLEMENT_STATIC_CLASSVAR_EXT(Class,var,getterFunc,Type,initParam,_kill) 00670 #endif 00671 00672 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_ARRAY 00673 #define CS_IMPLEMENT_STATIC_CLASSVAR_ARRAY(Class,var,getterFunc,Type,\ 00674 initParam) \ 00675 CS_IMPLEMENT_STATIC_CLASSVAR_EXT(Class,var,getterFunc,Type,initParam,\ 00676 _kill_array) 00677 #endif 00678 00679 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT 00680 #define CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT(Class,var,getterFunc,Type,\ 00681 initParam,kill_how) \ 00682 Type *Class::var = 0; \ 00683 void Class::getterFunc ## _kill () \ 00684 { \ 00685 delete &getterFunc (); \ 00686 var = 0; \ 00687 } \ 00688 void Class::getterFunc ## _kill_array () \ 00689 { \ 00690 delete [] &getterFunc (); \ 00691 var = 0; \ 00692 } \ 00693 Type &Class::getterFunc () \ 00694 { \ 00695 if (!var) \ 00696 { \ 00697 var = new Type initParam; \ 00698 csStaticVarCleanup (getterFunc ## kill_how); \ 00699 } \ 00700 return *var; \ 00701 } 00702 #endif 00703 00704 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_REF 00705 #define CS_IMPLEMENT_STATIC_CLASSVAR_REF(Class,var,getterFunc,Type,initParam)\ 00706 CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT(Class,var,getterFunc,Type,\ 00707 initParam,_kill) 00708 #endif 00709 00710 #ifndef CS_IMPLEMENT_STATIC_CLASSVAR_REF_ARRAY 00711 #define CS_IMPLEMENT_STATIC_CLASSVAR_REF_ARRAY(Class,var,getterFunc,Type,\ 00712 initParam) \ 00713 CS_IMPLEMENT_STATIC_CLASSVAR_REF_EXT(Class,var,getterFunc,Type,initParam,\ 00714 _kill_array) 00715 #endif 00716 00721 #if defined(CS_COMPILER_GCC) 00722 # define CS_FUNCTION_NAME __PRETTY_FUNCTION__ 00723 #elif defined(__FUNCTION__) 00724 # define CS_FUNCTION_NAME __FUNCTION__ 00725 #else 00726 # define CS_FUNCTION_NAME "<?\?\?>" 00727 #endif 00728 00729 #include <stdlib.h> 00730 #ifdef CS_HAVE_MALLOC_H 00731 #include <malloc.h> 00732 #endif 00733 #include <new> 00734 00735 #ifndef CS_NO_PTMALLOC 00736 00737 00741 extern CS_CRYSTALSPACE_EXPORT CS_ATTRIBUTE_MALLOC void* ptmalloc (size_t n); 00742 extern CS_CRYSTALSPACE_EXPORT void ptfree (void* p); 00743 extern CS_CRYSTALSPACE_EXPORT void* ptrealloc (void* p, size_t n); 00744 extern CS_CRYSTALSPACE_EXPORT CS_ATTRIBUTE_MALLOC void* ptcalloc (size_t n, 00745 size_t s); 00747 00749 00753 extern CS_CRYSTALSPACE_EXPORT CS_ATTRIBUTE_MALLOC void* ptmalloc_sentinel ( 00754 size_t n); 00755 extern CS_CRYSTALSPACE_EXPORT void ptfree_sentinel (void* p); 00756 extern CS_CRYSTALSPACE_EXPORT void* ptrealloc_sentinel (void* p, size_t n); 00757 extern CS_CRYSTALSPACE_EXPORT CS_ATTRIBUTE_MALLOC void* ptcalloc_sentinel ( 00758 size_t n, size_t s); 00760 00762 00766 extern CS_CRYSTALSPACE_EXPORT CS_ATTRIBUTE_MALLOC void* ptmalloc_located ( 00767 size_t n); 00768 extern CS_CRYSTALSPACE_EXPORT void ptfree_located (void* p); 00769 extern CS_CRYSTALSPACE_EXPORT void* ptrealloc_located (void* p, size_t n); 00770 extern CS_CRYSTALSPACE_EXPORT CS_ATTRIBUTE_MALLOC void* ptcalloc_located ( 00771 size_t n, size_t s); 00773 00775 00779 extern CS_CRYSTALSPACE_EXPORT CS_ATTRIBUTE_MALLOC void* ptmalloc_checking ( 00780 size_t n); 00781 extern CS_CRYSTALSPACE_EXPORT void ptfree_checking (void* p); 00782 extern CS_CRYSTALSPACE_EXPORT void* ptrealloc_checking (void* p, size_t n); 00783 extern CS_CRYSTALSPACE_EXPORT CS_ATTRIBUTE_MALLOC void* ptcalloc_checking ( 00784 size_t n, size_t s); 00786 00787 #ifndef CS_DEBUG 00788 # undef CS_EXTENSIVE_MEMDEBUG 00789 # undef CS_REF_TRACKER 00790 #else 00791 # if defined(CS_EXTENSIVE_MEMDEBUG) && defined(CS_MEMORY_TRACKER) 00792 # error Do not use CS_EXTENSIVE_MEMDEBUG and CS_MEMORY_TRACKER together! 00793 # endif 00794 #endif 00795 00796 #endif // CS_NO_PTMALLOC 00797 00803 extern CS_CRYSTALSPACE_EXPORT CS_ATTRIBUTE_MALLOC void* cs_malloc (size_t n); 00804 extern CS_CRYSTALSPACE_EXPORT void cs_free (void* p); 00805 extern CS_CRYSTALSPACE_EXPORT void* cs_realloc (void* p, size_t n); 00806 extern CS_CRYSTALSPACE_EXPORT void* cs_calloc (size_t n, size_t s); 00808 00809 #ifdef CS_USE_CUSTOM_ISDIR 00810 static inline bool isdir (const char *path, struct dirent *de) 00811 { 00812 int pathlen = strlen (path); 00813 char* fullname = new char[pathlen + 2 + strlen (de->d_name)]; 00814 memcpy (fullname, path, pathlen + 1); 00815 if ((pathlen) && (fullname[pathlen-1] != CS_PATH_SEPARATOR)) 00816 { 00817 fullname[pathlen++] = CS_PATH_SEPARATOR; 00818 fullname[pathlen] = 0; 00819 } 00820 strcat (&fullname [pathlen], de->d_name); 00821 struct stat st; 00822 stat (fullname, &st); 00823 delete[] fullname; 00824 return ((st.st_mode & S_IFMT) == S_IFDIR); 00825 } 00826 #endif 00827 00828 00829 // The following define should only be enabled if you have defined 00830 // a special version of overloaded new that accepts two additional 00831 // parameters: a (void*) pointing to the filename and an int with the 00832 // line number. This is typically used for memory debugging. 00833 // In csutil/memdebug.cpp there is a memory debugger which can (optionally) 00834 // use this feature. Note that if CS_EXTENSIVE_MEMDEBUG is enabled while 00835 // the memory debugger is not the memory debugger will still provide the 00836 // needed overloaded operators so you can leave CS_EXTENSIVE_MEMDEBUG on in 00837 // that case and the only overhead will be a little more arguments to 'new'. 00838 // Do not enable CS_EXTENSIVE_MEMDEBUG if your platform or your own code 00839 // defines its own 'new' operator, since this version will interfere with your 00840 // own. 00841 // CS_MEMORY_TRACKER is treated like CS_EXTENSIVE_MEMDEBUG here. 00842 #if defined(CS_EXTENSIVE_MEMDEBUG) || defined(CS_MEMORY_TRACKER) 00843 extern CS_CRYSTALSPACE_EXPORT void operator delete (void* p); 00844 extern CS_CRYSTALSPACE_EXPORT void operator delete[] (void* p); 00845 00846 extern CS_CRYSTALSPACE_EXPORT void* operator new (size_t s, 00847 void* filename, int line); 00848 inline void operator delete (void* p, void*, int) { operator delete (p); } 00849 extern CS_CRYSTALSPACE_EXPORT void* operator new[] (size_t s, 00850 void* filename, int line); 00851 inline void operator delete[] (void* p, void*, int) { operator delete[] (p); } 00852 00853 inline void* operator new (size_t s) 00854 { return operator new (s, (void*)__FILE__, 0); } 00855 inline void* operator new[] (size_t s) 00856 { return operator new (s, (void*)__FILE__, 0); } 00857 00858 #define CS_EXTENSIVE_MEMDEBUG_NEW new ((void*)CS_FUNCTION_NAME, __LINE__) 00859 #define new CS_EXTENSIVE_MEMDEBUG_NEW 00860 #endif 00861 00862 namespace CS 00863 { 00864 namespace Debug 00865 { 00866 extern void CS_CRYSTALSPACE_EXPORT AssertMessage (const char* expr, 00867 const char* filename, int line, const char* msg = 0); 00868 00875 static inline void DebugBreak () 00876 { 00877 # if defined (CS_PLATFORM_WIN32) 00878 ::DebugBreak(); 00879 # elif defined (CS_PROCESSOR_X86) 00880 # if defined (CS_COMPILER_GCC) 00881 asm ("int $3"); 00882 # else 00883 _asm int 3; 00884 # endif 00885 # elif defined (CS_PROCESSOR_POWERPC) 00886 // Source: http://cocoawithlove.com/2008/03/break-into-debugger.html 00887 asm("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" 00888 : : : "memory","r0","r3","r4" ); 00889 # else 00890 static int x = 0; x /= x; 00891 # endif 00892 } 00893 00899 extern bool CS_CRYSTALSPACE_EXPORT VerifyAllMemory (); 00904 extern void CS_CRYSTALSPACE_EXPORT DumpAllocateMemoryBlocks (); 00905 } // namespace Debug 00906 } // namespace CS 00907 00908 #if defined(CS_DEBUG) || defined(CS_WITH_ASSERTIONS) 00909 # define CS_DEBUG_BREAK CS::Debug::DebugBreak() 00910 # if !defined (CS_ASSERT_MSG) 00911 # define CS_ASSERT_MSG(msg,x) \ 00912 if (!(x)) CS::Debug::AssertMessage (#x, __FILE__, __LINE__, msg); 00913 # endif 00914 # if !defined (CS_ASSERT) 00915 # define CS_ASSERT(x) CS_ASSERT_MSG(0, x) 00916 # endif 00917 #else 00918 # undef CS_DEBUG_BREAK 00919 # define CS_DEBUG_BREAK 00920 # undef CS_ASSERT 00921 # define CS_ASSERT(x) (void)0 00922 # undef CS_ASSERT_MSG 00923 # define CS_ASSERT_MSG(m,x) (void)0 00924 #endif 00925 00941 // Check if the csosdefs.h defined either CS_LITTLE_ENDIAN or CS_BIG_ENDIAN 00942 #if !defined (CS_LITTLE_ENDIAN) && !defined (CS_BIG_ENDIAN) 00943 # error No CS_XXX_ENDIAN macro defined in your OS-specific csosdefs.h! 00944 #endif 00945 00946 /* 00947 * This is a bit of overkill but if you're sure your CPU doesn't require 00948 * strict alignment add your CPU to the !defined below to get slightly 00949 * smaller and faster code in some cases. 00950 * 00951 * \todo In the future, this should be moved to csconfig.h and determined as 00952 * part of the configuration process. 00953 */ 00954 #if defined (CS_PROCESSOR_SPARC) 00955 # define CS_STRICT_ALIGNMENT 00956 #endif 00957 00958 // Adjust some definitions contained in csconfig.h 00959 #if !defined (CS_PROCESSOR_X86) || !defined (CS_HAVE_NASM) 00960 # undef CS_HAVE_MMX 00961 # undef CS_HAVE_NASM 00962 #endif 00963 00964 // Use special knowledge of IEEE float format in some cases for CPU's that are 00965 // known to support it 00966 #if !defined (CS_IEEE_DOUBLE_FORMAT) 00967 # if defined (CS_PROCESSOR_X86) || \ 00968 defined (CS_PROCESSOR_POWERPC) || \ 00969 defined (CS_PROCESSOR_MIPS) || \ 00970 defined (CS_PROCESSOR_SPARC) || \ 00971 defined (CS_PROCESSOR_ALPHA) || \ 00972 defined (CS_PROCESSOR_M68K) || \ 00973 defined (CS_PROCESSOR_ARM) 00974 # define CS_IEEE_DOUBLE_FORMAT 00975 # endif 00976 #endif 00977 00978 // gcc can perform usefull checking for printf/scanf format strings, just add 00979 // this define at the end of the function declaration 00980 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) 00981 # define CS_GNUC_PRINTF(format_idx, arg_idx) \ 00982 __attribute__((format (__printf__, format_idx, arg_idx))) 00983 # define CS_GNUC_SCANF(format_idx, arg_idx) \ 00984 __attribute__((format (__scanf__, format_idx, arg_idx))) 00985 // Unfortunately, gcc doesn't support format argument checking for wide strings 00986 # define CS_GNUC_WPRINTF(format_idx, arg_idx) \ 00987 /*__attribute__((format (__wprintf__, format_idx, arg_idx)))*/ 00988 # define CS_GNUC_WSCANF(format_idx, arg_idx) \ 00989 /*__attribute__((format (__wscanf__, format_idx, arg_idx)))*/ 00990 #else 00991 # define CS_GNUC_PRINTF(format_idx, arg_idx) 00992 # define CS_GNUC_SCANF(format_idx, arg_idx) 00993 # define CS_GNUC_WPRINTF(format_idx, arg_idx) 00994 # define CS_GNUC_WSCANF(format_idx, arg_idx) 00995 #endif 00996 00997 // Remove __attribute__ on non GNUC compilers. 00998 #ifndef __GNUC__ 00999 #define __attribute__(x) 01000 #endif 01001 01002 // Support for alignment and packing of structures. 01003 #if !defined(CS_STRUCT_ALIGN_4BYTE_BEGIN) 01004 # if defined(__GNUC__) && defined(CS_STRICT_ALIGNMENT) 01005 # define CS_STRUCT_ALIGN_4BYTE_BEGIN 01006 # define CS_STRUCT_ALIGN_4BYTE_END __attribute__ ((aligned(4))) 01007 # else 01008 # define CS_STRUCT_ALIGN_4BYTE_BEGIN 01009 # define CS_STRUCT_ALIGN_4BYTE_END 01010 # endif 01011 #endif 01012 01013 #if defined(CS_COMPILER_MSVC) 01014 #define CS_ALIGNED_MEMBER(Member, Align) \ 01015 __declspec(align(Align)) Member 01016 #elif defined(CS_COMPILER_GCC) 01017 01029 #define CS_ALIGNED_MEMBER(Member, Align) \ 01030 Member __attribute((aligned(Align))) 01031 #else 01032 #define CS_ALIGNED_MEMBER(Member, Align) Member 01033 #endif 01034 01035 // Macro used to define static implicit pointer conversion function. 01036 // Only use within a class declaration. 01037 #ifndef _CS_IMPLICITPTRCAST_NAME 01038 # define _CS_IMPLICITPTRCAST_NAME __ImplicitPtrCast 01039 #endif 01040 01062 #define CS_IMPLEMENT_IMPLICIT_PTR_CAST(classname) \ 01063 inline static classname* _CS_IMPLICITPTRCAST_NAME (classname* ptr) \ 01064 { \ 01065 return ptr;\ 01066 } 01067 01076 #define CS_IMPLICIT_PTR_CAST(classname, ptr) \ 01077 (classname::_CS_IMPLICITPTRCAST_NAME(ptr)) 01078 01082 #ifdef CS_HAVE_VA_COPY 01083 # define CS_VA_COPY(dest, src) va_copy(dest, src) 01084 #else 01085 # ifdef CS_HAVE___VA_COPY 01086 # define CS_VA_COPY(dest, src) __va_copy(dest, src) 01087 # else 01088 # define CS_VA_COPY(dest, src) dest = src; 01089 # endif 01090 #endif 01091 01092 #define CS_STRING_TO_WIDE_(x) L ## x 01093 01100 #define CS_STRING_TO_WIDE(x) CS_STRING_TO_WIDE_(x) 01101 01102 #ifdef PACKAGE_NAME 01103 # define CS_NAMESPACE_PACKAGE_NAME PACKAGE_NAME 01104 #else 01105 # define CS_NAMESPACE_PACKAGE_NAME CS 01106 #endif 01107 01131 #define CS_PLUGIN_NAMESPACE_BEGIN(name) \ 01132 namespace CS_NAMESPACE_PACKAGE_NAME { namespace Plugin { namespace name 01133 #define CS_PLUGIN_NAMESPACE_END(name) \ 01134 } } 01135 #define CS_PLUGIN_NAMESPACE_NAME(name) \ 01136 CS_NAMESPACE_PACKAGE_NAME::Plugin::name 01137 01139 #endif // __CS_CSSYSDEF_H__
Generated for Crystal Space 1.4.1 by doxygen 1.7.1