cst_alloc.h 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*************************************************************************/
  2. /* */
  3. /* Language Technologies Institute */
  4. /* Carnegie Mellon University */
  5. /* Copyright (c) 1999 */
  6. /* All Rights Reserved. */
  7. /* */
  8. /* Permission is hereby granted, free of charge, to use and distribute */
  9. /* this software and its documentation without restriction, including */
  10. /* without limitation the rights to use, copy, modify, merge, publish, */
  11. /* distribute, sublicense, and/or sell copies of this work, and to */
  12. /* permit persons to whom this work is furnished to do so, subject to */
  13. /* the following conditions: */
  14. /* 1. The code must retain the above copyright notice, this list of */
  15. /* conditions and the following disclaimer. */
  16. /* 2. Any modifications must be clearly marked as such. */
  17. /* 3. Original authors' names are not deleted. */
  18. /* 4. The authors' names are not used to endorse or promote products */
  19. /* derived from this software without specific prior written */
  20. /* permission. */
  21. /* */
  22. /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
  23. /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
  24. /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
  25. /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
  26. /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
  27. /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
  28. /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
  29. /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
  30. /* THIS SOFTWARE. */
  31. /* */
  32. /*************************************************************************/
  33. /* Author: Alan W Black (awb@cs.cmu.edu) */
  34. /* Date: July 1999 */
  35. /*************************************************************************/
  36. /* */
  37. /* Basic wraparounds for malloc and free */
  38. /* */
  39. /*************************************************************************/
  40. #ifndef __CST_ALLOC_H__
  41. #define __CST_ALLOC_H__
  42. #ifndef TRUE
  43. #define TRUE (1==1)
  44. #endif
  45. #ifndef FALSE
  46. #define FALSE (1==0)
  47. #endif
  48. /* Global allocation (the only kind on Unix) */
  49. void *cst_safe_alloc(int size);
  50. void *cst_safe_calloc(int size);
  51. void *cst_safe_realloc(void *p,int size);
  52. /* Allocate on local heap (needed on WinCE for various reasons) */
  53. #ifdef UNDER_CE
  54. #include <windows.h>
  55. typedef HANDLE cst_alloc_context;
  56. cst_alloc_context new_alloc_context(int size);
  57. void delete_alloc_context(cst_alloc_context ctx);
  58. void *cst_local_alloc(cst_alloc_context ctx, int size);
  59. void cst_local_free(cst_alloc_context ctx, void *p);
  60. #else /* not UNDER_CE */
  61. typedef void * cst_alloc_context;
  62. #define new_alloc_context(size) (NULL)
  63. #define delete_alloc_context(ctx)
  64. #define cst_local_alloc(ctx,size) cst_safe_alloc(size)
  65. #define cst_local_free(cst,p) cst_free(p)
  66. #endif /* UNDER_CE */
  67. /* The public interface to the alloc functions */
  68. /* Note the underlying call is calloc, so everything is zero'd */
  69. #define cst_alloc(TYPE,SIZE) ((TYPE *)cst_safe_alloc(sizeof(TYPE)*(SIZE)))
  70. #define cst_calloc(TYPE,SIZE) ((TYPE *)cst_safe_calloc(sizeof(TYPE)*(SIZE)))
  71. #define cst_realloc(P,TYPE,SIZE) ((TYPE *)cst_safe_realloc((void *)(P),sizeof(TYPE)*(SIZE)))
  72. void cst_free(void *p);
  73. #endif