vrshoot

diff libs/ft2static/freetype/internal/ftmemory.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/ft2static/freetype/internal/ftmemory.h	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,380 @@
     1.4 +/***************************************************************************/
     1.5 +/*                                                                         */
     1.6 +/*  ftmemory.h                                                             */
     1.7 +/*                                                                         */
     1.8 +/*    The FreeType memory management macros (specification).               */
     1.9 +/*                                                                         */
    1.10 +/*  Copyright 1996-2001, 2002, 2004, 2005, 2006, 2007, 2010 by             */
    1.11 +/*  David Turner, Robert Wilhelm, and Werner Lemberg                       */
    1.12 +/*                                                                         */
    1.13 +/*  This file is part of the FreeType project, and may only be used,       */
    1.14 +/*  modified, and distributed under the terms of the FreeType project      */
    1.15 +/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
    1.16 +/*  this file you indicate that you have read the license and              */
    1.17 +/*  understand and accept it fully.                                        */
    1.18 +/*                                                                         */
    1.19 +/***************************************************************************/
    1.20 +
    1.21 +
    1.22 +#ifndef __FTMEMORY_H__
    1.23 +#define __FTMEMORY_H__
    1.24 +
    1.25 +
    1.26 +#include <ft2build.h>
    1.27 +#include FT_CONFIG_CONFIG_H
    1.28 +#include FT_TYPES_H
    1.29 +
    1.30 +
    1.31 +FT_BEGIN_HEADER
    1.32 +
    1.33 +
    1.34 +  /*************************************************************************/
    1.35 +  /*                                                                       */
    1.36 +  /* <Macro>                                                               */
    1.37 +  /*    FT_SET_ERROR                                                       */
    1.38 +  /*                                                                       */
    1.39 +  /* <Description>                                                         */
    1.40 +  /*    This macro is used to set an implicit `error' variable to a given  */
    1.41 +  /*    expression's value (usually a function call), and convert it to a  */
    1.42 +  /*    boolean which is set whenever the value is != 0.                   */
    1.43 +  /*                                                                       */
    1.44 +#undef  FT_SET_ERROR
    1.45 +#define FT_SET_ERROR( expression ) \
    1.46 +          ( ( error = (expression) ) != 0 )
    1.47 +
    1.48 +
    1.49 +
    1.50 +  /*************************************************************************/
    1.51 +  /*************************************************************************/
    1.52 +  /*************************************************************************/
    1.53 +  /****                                                                 ****/
    1.54 +  /****                                                                 ****/
    1.55 +  /****                           M E M O R Y                           ****/
    1.56 +  /****                                                                 ****/
    1.57 +  /****                                                                 ****/
    1.58 +  /*************************************************************************/
    1.59 +  /*************************************************************************/
    1.60 +  /*************************************************************************/
    1.61 +
    1.62 +
    1.63 +  /*
    1.64 +   *  C++ refuses to handle statements like p = (void*)anything, with `p' a
    1.65 +   *  typed pointer.  Since we don't have a `typeof' operator in standard
    1.66 +   *  C++, we have to use a template to emulate it.
    1.67 +   */
    1.68 +
    1.69 +#ifdef __cplusplus
    1.70 +
    1.71 +  extern "C++"
    1.72 +  template <typename T> inline T*
    1.73 +  cplusplus_typeof(        T*,
    1.74 +                    void  *v )
    1.75 +  {
    1.76 +    return static_cast <T*> ( v );
    1.77 +  }
    1.78 +
    1.79 +#define FT_ASSIGNP( p, val )  (p) = cplusplus_typeof( (p), (val) )
    1.80 +
    1.81 +#else
    1.82 +
    1.83 +#define FT_ASSIGNP( p, val )  (p) = (val)
    1.84 +
    1.85 +#endif
    1.86 +
    1.87 +
    1.88 +
    1.89 +#ifdef FT_DEBUG_MEMORY
    1.90 +
    1.91 +  FT_BASE( const char* )  _ft_debug_file;
    1.92 +  FT_BASE( long )         _ft_debug_lineno;
    1.93 +
    1.94 +#define FT_DEBUG_INNER( exp )  ( _ft_debug_file   = __FILE__, \
    1.95 +                                 _ft_debug_lineno = __LINE__, \
    1.96 +                                 (exp) )
    1.97 +
    1.98 +#define FT_ASSIGNP_INNER( p, exp )  ( _ft_debug_file   = __FILE__, \
    1.99 +                                      _ft_debug_lineno = __LINE__, \
   1.100 +                                      FT_ASSIGNP( p, exp ) )
   1.101 +
   1.102 +#else /* !FT_DEBUG_MEMORY */
   1.103 +
   1.104 +#define FT_DEBUG_INNER( exp )       (exp)
   1.105 +#define FT_ASSIGNP_INNER( p, exp )  FT_ASSIGNP( p, exp )
   1.106 +
   1.107 +#endif /* !FT_DEBUG_MEMORY */
   1.108 +
   1.109 +
   1.110 +  /*
   1.111 +   *  The allocation functions return a pointer, and the error code
   1.112 +   *  is written to through the `p_error' parameter.  See below for
   1.113 +   *  for documentation.
   1.114 +   */
   1.115 +
   1.116 +  FT_BASE( FT_Pointer )
   1.117 +  ft_mem_alloc( FT_Memory  memory,
   1.118 +                FT_Long    size,
   1.119 +                FT_Error  *p_error );
   1.120 +
   1.121 +  FT_BASE( FT_Pointer )
   1.122 +  ft_mem_qalloc( FT_Memory  memory,
   1.123 +                 FT_Long    size,
   1.124 +                 FT_Error  *p_error );
   1.125 +
   1.126 +  FT_BASE( FT_Pointer )
   1.127 +  ft_mem_realloc( FT_Memory  memory,
   1.128 +                  FT_Long    item_size,
   1.129 +                  FT_Long    cur_count,
   1.130 +                  FT_Long    new_count,
   1.131 +                  void*      block,
   1.132 +                  FT_Error  *p_error );
   1.133 +
   1.134 +  FT_BASE( FT_Pointer )
   1.135 +  ft_mem_qrealloc( FT_Memory  memory,
   1.136 +                   FT_Long    item_size,
   1.137 +                   FT_Long    cur_count,
   1.138 +                   FT_Long    new_count,
   1.139 +                   void*      block,
   1.140 +                   FT_Error  *p_error );
   1.141 +
   1.142 +  FT_BASE( void )
   1.143 +  ft_mem_free( FT_Memory    memory,
   1.144 +               const void*  P );
   1.145 +
   1.146 +
   1.147 +#define FT_MEM_ALLOC( ptr, size )                                         \
   1.148 +          FT_ASSIGNP_INNER( ptr, ft_mem_alloc( memory, (size), &error ) )
   1.149 +
   1.150 +#define FT_MEM_FREE( ptr )                \
   1.151 +          FT_BEGIN_STMNT                  \
   1.152 +            ft_mem_free( memory, (ptr) ); \
   1.153 +            (ptr) = NULL;                 \
   1.154 +          FT_END_STMNT
   1.155 +
   1.156 +#define FT_MEM_NEW( ptr )                        \
   1.157 +          FT_MEM_ALLOC( ptr, sizeof ( *(ptr) ) )
   1.158 +
   1.159 +#define FT_MEM_REALLOC( ptr, cursz, newsz )                        \
   1.160 +          FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, 1,        \
   1.161 +                                                 (cursz), (newsz), \
   1.162 +                                                 (ptr), &error ) )
   1.163 +
   1.164 +#define FT_MEM_QALLOC( ptr, size )                                         \
   1.165 +          FT_ASSIGNP_INNER( ptr, ft_mem_qalloc( memory, (size), &error ) )
   1.166 +
   1.167 +#define FT_MEM_QNEW( ptr )                        \
   1.168 +          FT_MEM_QALLOC( ptr, sizeof ( *(ptr) ) )
   1.169 +
   1.170 +#define FT_MEM_QREALLOC( ptr, cursz, newsz )                         \
   1.171 +          FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, 1,        \
   1.172 +                                                  (cursz), (newsz), \
   1.173 +                                                  (ptr), &error ) )
   1.174 +
   1.175 +#define FT_MEM_QRENEW_ARRAY( ptr, cursz, newsz )                             \
   1.176 +          FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
   1.177 +                                                  (cursz), (newsz),          \
   1.178 +                                                  (ptr), &error ) )
   1.179 +
   1.180 +#define FT_MEM_ALLOC_MULT( ptr, count, item_size )                    \
   1.181 +          FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, (item_size), \
   1.182 +                                                 0, (count),          \
   1.183 +                                                 NULL, &error ) )
   1.184 +
   1.185 +#define FT_MEM_REALLOC_MULT( ptr, oldcnt, newcnt, itmsz )            \
   1.186 +          FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, (itmsz),    \
   1.187 +                                                 (oldcnt), (newcnt), \
   1.188 +                                                 (ptr), &error ) )
   1.189 +
   1.190 +#define FT_MEM_QALLOC_MULT( ptr, count, item_size )                    \
   1.191 +          FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, (item_size), \
   1.192 +                                                  0, (count),          \
   1.193 +                                                  NULL, &error ) )
   1.194 +
   1.195 +#define FT_MEM_QREALLOC_MULT( ptr, oldcnt, newcnt, itmsz)             \
   1.196 +          FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, (itmsz),    \
   1.197 +                                                  (oldcnt), (newcnt), \
   1.198 +                                                  (ptr), &error ) )
   1.199 +
   1.200 +
   1.201 +#define FT_MEM_SET_ERROR( cond )  ( (cond), error != 0 )
   1.202 +
   1.203 +
   1.204 +#define FT_MEM_SET( dest, byte, count )     ft_memset( dest, byte, count )
   1.205 +
   1.206 +#define FT_MEM_COPY( dest, source, count )  ft_memcpy( dest, source, count )
   1.207 +
   1.208 +#define FT_MEM_MOVE( dest, source, count )  ft_memmove( dest, source, count )
   1.209 +
   1.210 +
   1.211 +#define FT_MEM_ZERO( dest, count )  FT_MEM_SET( dest, 0, count )
   1.212 +
   1.213 +#define FT_ZERO( p )                FT_MEM_ZERO( p, sizeof ( *(p) ) )
   1.214 +
   1.215 +
   1.216 +#define FT_ARRAY_ZERO( dest, count )                        \
   1.217 +          FT_MEM_ZERO( dest, (count) * sizeof ( *(dest) ) )
   1.218 +
   1.219 +#define FT_ARRAY_COPY( dest, source, count )                        \
   1.220 +          FT_MEM_COPY( dest, source, (count) * sizeof ( *(dest) ) )
   1.221 +
   1.222 +#define FT_ARRAY_MOVE( dest, source, count )                        \
   1.223 +          FT_MEM_MOVE( dest, source, (count) * sizeof ( *(dest) ) )
   1.224 +
   1.225 +
   1.226 +  /*
   1.227 +   *  Return the maximum number of addressable elements in an array.
   1.228 +   *  We limit ourselves to INT_MAX, rather than UINT_MAX, to avoid
   1.229 +   *  any problems.
   1.230 +   */
   1.231 +#define FT_ARRAY_MAX( ptr )           ( FT_INT_MAX / sizeof ( *(ptr) ) )
   1.232 +
   1.233 +#define FT_ARRAY_CHECK( ptr, count )  ( (count) <= FT_ARRAY_MAX( ptr ) )
   1.234 +
   1.235 +
   1.236 +  /*************************************************************************/
   1.237 +  /*                                                                       */
   1.238 +  /* The following functions macros expect that their pointer argument is  */
   1.239 +  /* _typed_ in order to automatically compute array element sizes.        */
   1.240 +  /*                                                                       */
   1.241 +
   1.242 +#define FT_MEM_NEW_ARRAY( ptr, count )                                      \
   1.243 +          FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, sizeof ( *(ptr) ), \
   1.244 +                                                 0, (count),                \
   1.245 +                                                 NULL, &error ) )
   1.246 +
   1.247 +#define FT_MEM_RENEW_ARRAY( ptr, cursz, newsz )                             \
   1.248 +          FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, sizeof ( *(ptr) ), \
   1.249 +                                                 (cursz), (newsz),          \
   1.250 +                                                 (ptr), &error ) )
   1.251 +
   1.252 +#define FT_MEM_QNEW_ARRAY( ptr, count )                                      \
   1.253 +          FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
   1.254 +                                                  0, (count),                \
   1.255 +                                                  NULL, &error ) )
   1.256 +
   1.257 +#define FT_MEM_QRENEW_ARRAY( ptr, cursz, newsz )                             \
   1.258 +          FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
   1.259 +                                                  (cursz), (newsz),          \
   1.260 +                                                  (ptr), &error ) )
   1.261 +
   1.262 +
   1.263 +#define FT_ALLOC( ptr, size )                           \
   1.264 +          FT_MEM_SET_ERROR( FT_MEM_ALLOC( ptr, size ) )
   1.265 +
   1.266 +#define FT_REALLOC( ptr, cursz, newsz )                           \
   1.267 +          FT_MEM_SET_ERROR( FT_MEM_REALLOC( ptr, cursz, newsz ) )
   1.268 +
   1.269 +#define FT_ALLOC_MULT( ptr, count, item_size )                           \
   1.270 +          FT_MEM_SET_ERROR( FT_MEM_ALLOC_MULT( ptr, count, item_size ) )
   1.271 +
   1.272 +#define FT_REALLOC_MULT( ptr, oldcnt, newcnt, itmsz )              \
   1.273 +          FT_MEM_SET_ERROR( FT_MEM_REALLOC_MULT( ptr, oldcnt,      \
   1.274 +                                                 newcnt, itmsz ) )
   1.275 +
   1.276 +#define FT_QALLOC( ptr, size )                           \
   1.277 +          FT_MEM_SET_ERROR( FT_MEM_QALLOC( ptr, size ) )
   1.278 +
   1.279 +#define FT_QREALLOC( ptr, cursz, newsz )                           \
   1.280 +          FT_MEM_SET_ERROR( FT_MEM_QREALLOC( ptr, cursz, newsz ) )
   1.281 +
   1.282 +#define FT_QALLOC_MULT( ptr, count, item_size )                           \
   1.283 +          FT_MEM_SET_ERROR( FT_MEM_QALLOC_MULT( ptr, count, item_size ) )
   1.284 +
   1.285 +#define FT_QREALLOC_MULT( ptr, oldcnt, newcnt, itmsz )              \
   1.286 +          FT_MEM_SET_ERROR( FT_MEM_QREALLOC_MULT( ptr, oldcnt,      \
   1.287 +                                                  newcnt, itmsz ) )
   1.288 +
   1.289 +#define FT_FREE( ptr )  FT_MEM_FREE( ptr )
   1.290 +
   1.291 +#define FT_NEW( ptr )  FT_MEM_SET_ERROR( FT_MEM_NEW( ptr ) )
   1.292 +
   1.293 +#define FT_NEW_ARRAY( ptr, count )                           \
   1.294 +          FT_MEM_SET_ERROR( FT_MEM_NEW_ARRAY( ptr, count ) )
   1.295 +
   1.296 +#define FT_RENEW_ARRAY( ptr, curcnt, newcnt )                           \
   1.297 +          FT_MEM_SET_ERROR( FT_MEM_RENEW_ARRAY( ptr, curcnt, newcnt ) )
   1.298 +
   1.299 +#define FT_QNEW( ptr )                           \
   1.300 +          FT_MEM_SET_ERROR( FT_MEM_QNEW( ptr ) )
   1.301 +
   1.302 +#define FT_QNEW_ARRAY( ptr, count )                          \
   1.303 +          FT_MEM_SET_ERROR( FT_MEM_NEW_ARRAY( ptr, count ) )
   1.304 +
   1.305 +#define FT_QRENEW_ARRAY( ptr, curcnt, newcnt )                          \
   1.306 +          FT_MEM_SET_ERROR( FT_MEM_RENEW_ARRAY( ptr, curcnt, newcnt ) )
   1.307 +
   1.308 +
   1.309 +#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
   1.310 +
   1.311 +  FT_BASE( FT_Error )
   1.312 +  FT_Alloc( FT_Memory  memory,
   1.313 +            FT_Long    size,
   1.314 +            void*     *P );
   1.315 +
   1.316 +  FT_BASE( FT_Error )
   1.317 +  FT_QAlloc( FT_Memory  memory,
   1.318 +             FT_Long    size,
   1.319 +             void*     *p );
   1.320 +
   1.321 +  FT_BASE( FT_Error )
   1.322 +  FT_Realloc( FT_Memory  memory,
   1.323 +              FT_Long    current,
   1.324 +              FT_Long    size,
   1.325 +              void*     *P );
   1.326 +
   1.327 +  FT_BASE( FT_Error )
   1.328 +  FT_QRealloc( FT_Memory  memory,
   1.329 +               FT_Long    current,
   1.330 +               FT_Long    size,
   1.331 +               void*     *p );
   1.332 +
   1.333 +  FT_BASE( void )
   1.334 +  FT_Free( FT_Memory  memory,
   1.335 +           void*     *P );
   1.336 +
   1.337 +#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
   1.338 +
   1.339 +
   1.340 +  FT_BASE( FT_Pointer )
   1.341 +  ft_mem_strdup( FT_Memory    memory,
   1.342 +                 const char*  str,
   1.343 +                 FT_Error    *p_error );
   1.344 +
   1.345 +  FT_BASE( FT_Pointer )
   1.346 +  ft_mem_dup( FT_Memory    memory,
   1.347 +              const void*  address,
   1.348 +              FT_ULong     size,
   1.349 +              FT_Error    *p_error );
   1.350 +
   1.351 +#define FT_MEM_STRDUP( dst, str )                                            \
   1.352 +          (dst) = (char*)ft_mem_strdup( memory, (const char*)(str), &error )
   1.353 +
   1.354 +#define FT_STRDUP( dst, str )                           \
   1.355 +          FT_MEM_SET_ERROR( FT_MEM_STRDUP( dst, str ) )
   1.356 +
   1.357 +#define FT_MEM_DUP( dst, address, size )                                    \
   1.358 +          (dst) = ft_mem_dup( memory, (address), (FT_ULong)(size), &error )
   1.359 +
   1.360 +#define FT_DUP( dst, address, size )                           \
   1.361 +          FT_MEM_SET_ERROR( FT_MEM_DUP( dst, address, size ) )
   1.362 +
   1.363 +
   1.364 +  /* Return >= 1 if a truncation occurs.            */
   1.365 +  /* Return 0 if the source string fits the buffer. */
   1.366 +  /* This is *not* the same as strlcpy().           */
   1.367 +  FT_BASE( FT_Int )
   1.368 +  ft_mem_strcpyn( char*        dst,
   1.369 +                  const char*  src,
   1.370 +                  FT_ULong     size );
   1.371 +
   1.372 +#define FT_STRCPYN( dst, src, size )                                         \
   1.373 +          ft_mem_strcpyn( (char*)dst, (const char*)(src), (FT_ULong)(size) )
   1.374 +
   1.375 + /* */
   1.376 +
   1.377 +
   1.378 +FT_END_HEADER
   1.379 +
   1.380 +#endif /* __FTMEMORY_H__ */
   1.381 +
   1.382 +
   1.383 +/* END */