Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1.  
  2. /** \file stubs.h interface to platform-dependent functions
  3.  */
  4.  
  5. #ifndef __stubs_h__
  6. #define __stubs_h__
  7.  
  8. #include "lisptype.h"
  9.  
  10. /** Simple function that determines if two strings are equal,
  11.   should be defined in stubs.inl */
  12. //inline LispInt StrEqual(const LispChar * ptr1, const LispChar * ptr2);
  13.  
  14. #ifdef NO_GLOBALS
  15.   #define PlatAlloc malloc
  16.   #define PlatReAlloc realloc
  17.   #define PlatFree free
  18.   #define NEW new
  19.   #define CHECKPTR(ptr)
  20. #else  // NO_GLOBALS -- goes almost to EOF
  21.   void *PlatObAlloc(size_t nbytes);
  22.   void PlatObFree(void *p);
  23.   void *PlatObReAlloc(void *p, size_t nbytes);
  24.  
  25. #ifdef YACAS_DEBUG
  26.   #include "debugmem.h"
  27.   #define PlatAlloc(nr)        YacasMallocPrivate((size_t)nr,__FILE__,__LINE__)
  28.   #define PlatReAlloc(orig,nr) YacasReAllocPrivate(orig,(size_t)nr,__FILE__,__LINE__)
  29.   #define PlatFree(orig)       YacasFreePrivate(orig)
  30.   #define NEW new (__FILE__,__LINE__)
  31.   #define CHECKPTR(ptr) CheckPtr(ptr,__FILE__,__LINE__)
  32. #else  // YACAS_DEBUG
  33.   #define PlatAlloc(nr)        PlatObAlloc((size_t)nr)
  34.   #define PlatReAlloc(orig,nr) PlatObReAlloc(orig,(size_t)nr)
  35.   #define PlatFree(orig)       PlatObFree(orig)
  36.   #define NEW new
  37.   #define CHECKPTR(ptr)
  38. #endif  // YACAS_DEBUG
  39.  
  40. template <class T>
  41. inline T * PlatAllocN(LispInt aSize) { return (T*)PlatAlloc(aSize*sizeof(T)); }
  42.  
  43.  
  44. #ifdef YACAS_DEBUG  // goes almost to EOF
  45.  
  46. /* Operators new and delete are only defined globally here in debug mode. This is because
  47.  * the global new and delete operators should not be used. So the debug version makes sure
  48.  * the executable crashes if one of these are called.
  49.  */
  50.  
  51. #define NEW_THROWER throw ()//(std::bad_alloc)
  52. #define DELETE_THROWER throw ()
  53.  
  54. // TODO: why doesn't MSC itself have this problem? Perhaps wrong signature of these new and delete operators?
  55. #if defined(_MSC_VER) && _MSC_VER <= 1310  // getting C4290 warnings?  slowly increase number.
  56. #pragma warning( disable : 4290 )  // C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
  57. #endif
  58.  
  59. void* operator new(size_t size) NEW_THROWER;
  60. void* operator new[](size_t size) NEW_THROWER;
  61. void operator delete(void* object) DELETE_THROWER;
  62. void operator delete[](void* object) DELETE_THROWER;
  63.  
  64. #endif  // YACAS_DEBUG
  65.  
  66. #endif  // NO_GLOBALS
  67.  
  68. #include "stubs.inl"
  69.  
  70. #endif  // __stubs_h__
  71.