Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:14:31

0001 /*
0002 
0003 Copyright 1995, 1998  The Open Group
0004 
0005 Permission to use, copy, modify, distribute, and sell this software and its
0006 documentation for any purpose is hereby granted without fee, provided that
0007 the above copyright notice appear in all copies and that both that
0008 copyright notice and this permission notice appear in supporting
0009 documentation.
0010 
0011 The above copyright notice and this permission notice shall be
0012 included in all copies or substantial portions of the Software.
0013 
0014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0015 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0016 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
0017 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020 OTHER DEALINGS IN THE SOFTWARE.
0021 
0022 Except as contained in this notice, the name of The Open Group shall
0023 not be used in advertising or otherwise to promote the sale, use or
0024 other dealings in this Software without prior written authorization
0025 from The Open Group.
0026 
0027 */
0028 /*
0029  * The purpose of this header is to define the macros ALLOCATE_LOCAL and
0030  * DEALLOCATE_LOCAL appropriately for the platform being compiled on.
0031  * These macros are used to make fast, function-local memory allocations.
0032  * Their characteristics are as follows:
0033  *
0034  * void *ALLOCATE_LOCAL(int size)
0035  *    Returns a pointer to size bytes of memory, or NULL if the allocation
0036  *    failed.  The memory must be freed with DEALLOCATE_LOCAL before the
0037  *    function that made the allocation returns.  You should not ask for
0038  *    large blocks of memory with this function, since on many platforms
0039  *    the memory comes from the stack, which may have limited size.
0040  *
0041  * void DEALLOCATE_LOCAL(void *)
0042  *    Frees the memory allocated by ALLOCATE_LOCAL.  Omission of this
0043  *    step may be harmless on some platforms, but will result in
0044  *    memory leaks or worse on others.
0045  *
0046  * Before including this file, you should define two macros,
0047  * ALLOCATE_LOCAL_FALLBACK and DEALLOCATE_LOCAL_FALLBACK, that have the
0048  * same characteristics as ALLOCATE_LOCAL and DEALLOCATE_LOCAL.  The
0049  * header uses the fallbacks if it doesn't know a "better" way to define
0050  * ALLOCATE_LOCAL and DEALLOCATE_LOCAL.  Typical usage would be:
0051  *
0052  *    #define ALLOCATE_LOCAL_FALLBACK(_size) malloc(_size)
0053  *    #define DEALLOCATE_LOCAL_FALLBACK(_ptr) free(_ptr)
0054  *    #include "Xalloca.h"
0055  */
0056 
0057 #ifndef XALLOCA_H
0058 #define XALLOCA_H 1
0059 
0060 #ifndef INCLUDE_ALLOCA_H
0061 /* Need to add more here to match Imake *.cf's */
0062 # if defined(HAVE_ALLOCA_H) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
0063 #  define INCLUDE_ALLOCA_H
0064 # endif
0065 #endif
0066 
0067 #ifdef INCLUDE_ALLOCA_H
0068 #  include <alloca.h>
0069 #endif
0070 
0071 #ifndef NO_ALLOCA
0072 /*
0073  * os-dependent definition of local allocation and deallocation
0074  * If you want something other than (DE)ALLOCATE_LOCAL_FALLBACK
0075  * for ALLOCATE/DEALLOCATE_LOCAL then you add that in here.
0076  */
0077 
0078 
0079 #  ifdef __GNUC__
0080 #    ifndef alloca
0081 #      define alloca __builtin_alloca
0082 #    endif /* !alloca */
0083 #    define ALLOCATE_LOCAL(size) alloca((int)(size))
0084 #  else /* ! __GNUC__ */
0085 
0086 /*
0087  * warning: old mips alloca (pre 2.10) is unusable, new one is built in
0088  * Test is easy, the new one is named __builtin_alloca and comes
0089  * from alloca.h which #defines alloca.
0090  */
0091 #      if defined(__sun) || defined(alloca)
0092 /*
0093  * Some System V boxes extract alloca.o from /lib/libPW.a; if you
0094  * decide that you don't want to use alloca, you might want to fix it here.
0095  */
0096 /* alloca might be a macro taking one arg (hi, Sun!), so give it one. */
0097 #        if !defined(__cplusplus)
0098 #          define __Xnullarg        /* as nothing */
0099            extern void *alloca(__Xnullarg);
0100 #        endif
0101 #        define ALLOCATE_LOCAL(size) alloca((int)(size))
0102 #      endif /* who does alloca */
0103 #  endif /* __GNUC__ */
0104 
0105 #endif /* NO_ALLOCA */
0106 
0107 #if !defined(ALLOCATE_LOCAL)
0108 #  if defined(ALLOCATE_LOCAL_FALLBACK) && defined(DEALLOCATE_LOCAL_FALLBACK)
0109 #    define ALLOCATE_LOCAL(_size)  ALLOCATE_LOCAL_FALLBACK(_size)
0110 #    define DEALLOCATE_LOCAL(_ptr) DEALLOCATE_LOCAL_FALLBACK(_ptr)
0111 #  else /* no fallbacks supplied; error */
0112 #    define ALLOCATE_LOCAL(_size)  ALLOCATE_LOCAL_FALLBACK undefined!
0113 #    define DEALLOCATE_LOCAL(_ptr) DEALLOCATE_LOCAL_FALLBACK undefined!
0114 #  endif /* defined(ALLOCATE_LOCAL_FALLBACK && DEALLOCATE_LOCAL_FALLBACK) */
0115 #else
0116 #  if !defined(DEALLOCATE_LOCAL)
0117 #    define DEALLOCATE_LOCAL(_ptr) do {} while(0)
0118 #  endif
0119 #endif /* defined(ALLOCATE_LOCAL) */
0120 
0121 #endif /* XALLOCA_H */