home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / py2s152.zip / Include / mymalloc.h < prev    next >
C/C++ Source or Header  |  1999-06-27  |  4KB  |  123 lines

  1. #ifndef Py_MYMALLOC_H
  2. #define Py_MYMALLOC_H
  3. /***********************************************************
  4. Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
  5. The Netherlands.
  6.  
  7.                         All Rights Reserved
  8.  
  9. Permission to use, copy, modify, and distribute this software and its
  10. documentation for any purpose and without fee is hereby granted,
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in
  13. supporting documentation, and that the names of Stichting Mathematisch
  14. Centrum or CWI or Corporation for National Research Initiatives or
  15. CNRI not be used in advertising or publicity pertaining to
  16. distribution of the software without specific, written prior
  17. permission.
  18.  
  19. While CWI is the initial source for this software, a modified version
  20. is made available by the Corporation for National Research Initiatives
  21. (CNRI) at the Internet address ftp://ftp.python.org.
  22.  
  23. STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
  24. REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  25. MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
  26. CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  27. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  28. PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  29. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  30. PERFORMANCE OF THIS SOFTWARE.
  31.  
  32. ******************************************************************/
  33.  
  34. /* Lowest-level memory allocation interface */
  35.  
  36. #ifdef macintosh
  37. #define ANY void
  38. #endif
  39.  
  40. #ifdef __STDC__
  41. #define ANY void
  42. #endif
  43.  
  44. #ifdef __TURBOC__
  45. #define ANY void
  46. #endif
  47.  
  48. #ifdef __GNUC__
  49. #define ANY void
  50. #endif
  51.  
  52. #ifndef ANY
  53. #define ANY char
  54. #endif
  55.  
  56. #ifdef HAVE_STDLIB_H
  57. #include <stdlib.h>
  58. #endif
  59.  
  60. #ifdef __cplusplus
  61. /* Move this down here since some C++ #include's don't like to be included
  62.    inside an extern "C" */
  63. extern "C" {
  64. #endif
  65.  
  66. #ifdef SYMANTEC__CFM68K__
  67. #pragma lib_export on
  68. #endif
  69.  
  70. /* The following should never be necessary */
  71. #ifdef NEED_TO_DECLARE_MALLOC_AND_FRIEND
  72. extern ANY *malloc Py_PROTO((size_t));
  73. extern ANY *calloc Py_PROTO((size_t, size_t));
  74. extern ANY *realloc Py_PROTO((ANY *, size_t));
  75. extern void free Py_PROTO((ANY *)); /* XXX sometimes int on Unix old systems */
  76. #endif
  77.  
  78. #ifndef NULL
  79. #define NULL ((ANY *)0)
  80. #endif
  81.  
  82. #ifdef MALLOC_ZERO_RETURNS_NULL
  83. /* XXX Always allocate one extra byte, since some malloc's return NULL
  84.    XXX for malloc(0) or realloc(p, 0). */
  85. #define _PyMem_EXTRA 1
  86. #else
  87. #define _PyMem_EXTRA 0
  88. #endif
  89.  
  90. #define PyMem_NEW(type, n) \
  91.     ( (type *) malloc(_PyMem_EXTRA + (n) * sizeof(type)) )
  92. #define PyMem_RESIZE(p, type, n) \
  93.     if ((p) == NULL) \
  94.         (p) =  (type *) malloc(_PyMem_EXTRA + (n) * sizeof(type)); \
  95.     else \
  96.         (p) = (type *) realloc((ANY *)(p), \
  97.                        _PyMem_EXTRA + (n) * sizeof(type))
  98. #define PyMem_DEL(p) free((ANY *)p)
  99. #define PyMem_XDEL(p) if ((p) == NULL) ; else PyMem_DEL(p)
  100.  
  101.  
  102. /* Two sets of function wrappers around malloc and friends; useful if
  103.    you need to be sure that you are using the same memory allocator as
  104.    Python.  Note that the wrappers make sure that allocating 0 bytes
  105.    returns a non-NULL pointer, even if the underlying malloc doesn't.
  106.    The Python interpreter continues to use PyMem_NEW etc. */
  107.  
  108. /* These wrappers around malloc call PyErr_NoMemory() on failure */
  109. extern DL_IMPORT(ANY *) Py_Malloc Py_PROTO((size_t));
  110. extern DL_IMPORT(ANY *) Py_Realloc Py_PROTO((ANY *, size_t));
  111. extern DL_IMPORT(void) Py_Free Py_PROTO((ANY *));
  112.  
  113. /* These wrappers around malloc *don't* call anything on failure */
  114. extern DL_IMPORT(ANY *) PyMem_Malloc Py_PROTO((size_t));
  115. extern DL_IMPORT(ANY *) PyMem_Realloc Py_PROTO((ANY *, size_t));
  116. extern DL_IMPORT(void) PyMem_Free Py_PROTO((ANY *));
  117.  
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121.  
  122. #endif /* !Py_MYMALLOC_H */
  123.