home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-bin / x11r6.1 / include / x11 / xalloca.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-17  |  5.2 KB  |  138 lines

  1. /* $XConsortium: Xalloca.h /main/4 1996/01/12 10:07:00 kaleb $ */
  2.  
  3. /*
  4.  
  5. Copyright (c) 1995  X Consortium
  6.  
  7. Permission is hereby granted, free of charge, to any person obtaining
  8. a copy of this software and associated documentation files (the
  9. "Software"), to deal in the Software without restriction, including
  10. without limitation the rights to use, copy, modify, merge, publish,
  11. distribute, sublicense, and/or sell copies of the Software, and to
  12. permit persons to whom the Software is furnished to do so, subject to
  13. the following conditions:
  14.  
  15. The above copyright notice and this permission notice shall be
  16. included in all copies or substantial portions of the Software.
  17.  
  18. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  21. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
  22. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. OTHER DEALINGS IN THE SOFTWARE.
  25.  
  26. Except as contained in this notice, the name of the X Consortium shall
  27. not be used in advertising or otherwise to promote the sale, use or
  28. other dealings in this Software without prior written authorization
  29. from the X Consortium.
  30.  
  31. */
  32.  
  33. /*
  34.  * The purpose of this header is to define the macros ALLOCATE_LOCAL and
  35.  * DEALLOCATE_LOCAL appropriately for the platform being compiled on.
  36.  * These macros are used to make fast, function-local memory allocations.
  37.  * Their characteristics are as follows:
  38.  *
  39.  * void *ALLOCATE_LOCAL(int size)
  40.  *    Returns a pointer to size bytes of memory, or NULL if the allocation
  41.  *    failed.  The memory must be freed with DEALLOCATE_LOCAL before the
  42.  *    function that made the allocation returns.  You should not ask for
  43.  *    large blocks of memory with this function, since on many platforms
  44.  *    the memory comes from the stack, which may have limited size.
  45.  *
  46.  * void DEALLOCATE_LOCAL(void *)
  47.  *    Frees the memory allocated by ALLOCATE_LOCAL.  Omission of this
  48.  *    step may be harmless on some platforms, but will result in
  49.  *    memory leaks or worse on others.
  50.  *
  51.  * Before including this file, you should define two macros,
  52.  * ALLOCATE_LOCAL_FALLBACK and DEALLOCATE_LOCAL_FALLBACK, that have the
  53.  * same characteristics as ALLOCATE_LOCAL and DEALLOCATE_LOCAL.  The
  54.  * header uses the fallbacks if it doesn't know a "better" way to define
  55.  * ALLOCATE_LOCAL and DEALLOCATE_LOCAL.  Typical usage would be:
  56.  *
  57.  *    #define ALLOCATE_LOCAL_FALLBACK(_size) malloc(_size)
  58.  *    #define DEALLOCATE_LOCAL_FALLBACK(_ptr) free(_ptr)
  59.  *    #include "Xalloca.h"
  60.  */
  61.  
  62. #ifndef XALLOCA_H
  63. #define XALLOCA_H 1
  64.  
  65. #ifdef INCLUDE_ALLOCA_H
  66. #  include <alloca.h>
  67. #endif
  68.  
  69. #ifndef NO_ALLOCA
  70. /*
  71.  * os-dependent definition of local allocation and deallocation
  72.  * If you want something other than (DE)ALLOCATE_LOCAL_FALLBACK
  73.  * for ALLOCATE/DEALLOCATE_LOCAL then you add that in here.
  74.  */
  75. #  if defined(__HIGHC__)
  76. #    ifndef NCR
  77.        extern char *alloca();
  78. #      if HCVERSION < 21003
  79. #        define ALLOCATE_LOCAL(size)    alloca((int)(size))
  80.          pragma on(alloca);
  81. #      else /* HCVERSION >= 21003 */
  82. #        define    ALLOCATE_LOCAL(size)    _Alloca((int)(size))
  83. #      endif /* HCVERSION < 21003 */
  84. #    else /* NCR */
  85. #      define ALLOCATE_LOCAL(size)    alloca(size)
  86. #    endif
  87. #  define DEALLOCATE_LOCAL(ptr)  /* as nothing */
  88. #  endif /* defined(__HIGHC__) */
  89.  
  90.  
  91. #  ifdef __GNUC__
  92. #    ifndef alloca
  93. #      define alloca __builtin_alloca
  94. #    endif /* !alloca */
  95. #    define ALLOCATE_LOCAL(size) alloca((int)(size))
  96. #    define DEALLOCATE_LOCAL(ptr)  /* as nothing */
  97. #  else /* ! __GNUC__ */
  98.  
  99. /*
  100.  * warning: old mips alloca (pre 2.10) is unusable, new one is built in
  101.  * Test is easy, the new one is named __builtin_alloca and comes
  102.  * from alloca.h which #defines alloca.
  103.  */
  104. #    ifndef NCR
  105. #      if defined(vax) || defined(sun) || defined(apollo) || defined(stellar) || defined(alloca)
  106. /*
  107.  * Some System V boxes extract alloca.o from /lib/libPW.a; if you
  108.  * decide that you don't want to use alloca, you might want to fix it here.
  109.  */
  110. /* alloca might be a macro taking one arg (hi, Sun!), so give it one. */
  111. #        ifndef __sgi            /* IRIX 5/6 has definition */
  112. #          define __Xnullarg        /* as nothing */
  113. #          ifndef X_NOT_STDC_ENV
  114.              extern void *alloca(__Xnullarg);
  115. #          else
  116.              extern char *alloca(__Xnullarg);
  117. #          endif
  118. #        endif /* __sgi */
  119. #        define ALLOCATE_LOCAL(size) alloca((int)(size))
  120. #        define DEALLOCATE_LOCAL(ptr)  /* as nothing */
  121. #      endif /* who does alloca */
  122. #    endif /* NCR */
  123. #  endif /* __GNUC__ */
  124.  
  125. #endif /* NO_ALLOCA */
  126.  
  127. #if !defined(ALLOCATE_LOCAL)
  128. #  if defined(ALLOCATE_LOCAL_FALLBACK) && defined(DEALLOCATE_LOCAL_FALLBACK)
  129. #    define ALLOCATE_LOCAL(_size)  ALLOCATE_LOCAL_FALLBACK(_size)
  130. #    define DEALLOCATE_LOCAL(_ptr) DEALLOCATE_LOCAL_FALLBACK(_ptr)
  131. #  else /* no fallbacks supplied; error */
  132. #    define ALLOCATE_LOCAL(_size)  ALLOCATE_LOCAL_FALLBACK undefined!
  133. #    define DEALLOCATE_LOCAL(_ptr) DEALLOCATE_LOCAL_FALLBACK undefined!
  134. #  endif /* defined(ALLOCATE_LOCAL_FALLBACK && DEALLOCATE_LOCAL_FALLBACK) */
  135. #endif /* !defined(ALLOCATE_LOCAL) */
  136.  
  137. #endif /* XALLOCA_H */
  138.