github.com/rajveermalviya/gamen@v0.1.2-0.20220930195403-9be15877c1aa/internal/xcb/include/X11/Xalloca.h (about)

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