ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

ftmemory.h
Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  ftmemory.h                                                             */
00004 /*                                                                         */
00005 /*    The FreeType memory management macros (specification).               */
00006 /*                                                                         */
00007 /*  Copyright 1996-2001, 2002, 2004, 2005, 2006, 2007, 2010 by             */
00008 /*  David Turner, Robert Wilhelm, and Werner Lemberg                       */
00009 /*                                                                         */
00010 /*  This file is part of the FreeType project, and may only be used,       */
00011 /*  modified, and distributed under the terms of the FreeType project      */
00012 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
00013 /*  this file you indicate that you have read the license and              */
00014 /*  understand and accept it fully.                                        */
00015 /*                                                                         */
00016 /***************************************************************************/
00017 
00018 
00019 #ifndef __FTMEMORY_H__
00020 #define __FTMEMORY_H__
00021 
00022 
00023 #include <ft2build.h>
00024 #include FT_CONFIG_CONFIG_H
00025 #include FT_TYPES_H
00026 
00027 
00028 FT_BEGIN_HEADER
00029 
00030 
00031   /*************************************************************************/
00032   /*                                                                       */
00033   /* <Macro>                                                               */
00034   /*    FT_SET_ERROR                                                       */
00035   /*                                                                       */
00036   /* <Description>                                                         */
00037   /*    This macro is used to set an implicit `error' variable to a given  */
00038   /*    expression's value (usually a function call), and convert it to a  */
00039   /*    boolean which is set whenever the value is != 0.                   */
00040   /*                                                                       */
00041 #undef  FT_SET_ERROR
00042 #define FT_SET_ERROR( expression ) \
00043           ( ( error = (expression) ) != 0 )
00044 
00045 
00046 
00047   /*************************************************************************/
00048   /*************************************************************************/
00049   /*************************************************************************/
00050   /****                                                                 ****/
00051   /****                                                                 ****/
00052   /****                           M E M O R Y                           ****/
00053   /****                                                                 ****/
00054   /****                                                                 ****/
00055   /*************************************************************************/
00056   /*************************************************************************/
00057   /*************************************************************************/
00058 
00059 
00060   /*
00061    *  C++ refuses to handle statements like p = (void*)anything, with `p' a
00062    *  typed pointer.  Since we don't have a `typeof' operator in standard
00063    *  C++, we have to use a template to emulate it.
00064    */
00065 
00066 #ifdef __cplusplus
00067 
00068   extern "C++"
00069   template <typename T> inline T*
00070   cplusplus_typeof(        T*,
00071                     void  *v )
00072   {
00073     return static_cast <T*> ( v );
00074   }
00075 
00076 #define FT_ASSIGNP( p, val )  (p) = cplusplus_typeof( (p), (val) )
00077 
00078 #else
00079 
00080 #define FT_ASSIGNP( p, val )  (p) = (val)
00081 
00082 #endif
00083 
00084 
00085 
00086 #ifdef FT_DEBUG_MEMORY
00087 
00088   FT_BASE( const char* )  _ft_debug_file;
00089   FT_BASE( long )         _ft_debug_lineno;
00090 
00091 #define FT_DEBUG_INNER( exp )  ( _ft_debug_file   = __FILE__, \
00092                                  _ft_debug_lineno = __LINE__, \
00093                                  (exp) )
00094 
00095 #define FT_ASSIGNP_INNER( p, exp )  ( _ft_debug_file   = __FILE__, \
00096                                       _ft_debug_lineno = __LINE__, \
00097                                       FT_ASSIGNP( p, exp ) )
00098 
00099 #else /* !FT_DEBUG_MEMORY */
00100 
00101 #define FT_DEBUG_INNER( exp )       (exp)
00102 #define FT_ASSIGNP_INNER( p, exp )  FT_ASSIGNP( p, exp )
00103 
00104 #endif /* !FT_DEBUG_MEMORY */
00105 
00106 
00107   /*
00108    *  The allocation functions return a pointer, and the error code
00109    *  is written to through the `p_error' parameter.  See below for
00110    *  for documentation.
00111    */
00112 
00113   FT_BASE( FT_Pointer )
00114   ft_mem_alloc( FT_Memory  memory,
00115                 FT_Long    size,
00116                 FT_Error  *p_error );
00117 
00118   FT_BASE( FT_Pointer )
00119   ft_mem_qalloc( FT_Memory  memory,
00120                  FT_Long    size,
00121                  FT_Error  *p_error );
00122 
00123   FT_BASE( FT_Pointer )
00124   ft_mem_realloc( FT_Memory  memory,
00125                   FT_Long    item_size,
00126                   FT_Long    cur_count,
00127                   FT_Long    new_count,
00128                   void*      block,
00129                   FT_Error  *p_error );
00130 
00131   FT_BASE( FT_Pointer )
00132   ft_mem_qrealloc( FT_Memory  memory,
00133                    FT_Long    item_size,
00134                    FT_Long    cur_count,
00135                    FT_Long    new_count,
00136                    void*      block,
00137                    FT_Error  *p_error );
00138 
00139   FT_BASE( void )
00140   ft_mem_free( FT_Memory    memory,
00141                const void*  P );
00142 
00143 
00144 #define FT_MEM_ALLOC( ptr, size )                                         \
00145           FT_ASSIGNP_INNER( ptr, ft_mem_alloc( memory, (size), &error ) )
00146 
00147 #define FT_MEM_FREE( ptr )                \
00148           FT_BEGIN_STMNT                  \
00149             ft_mem_free( memory, (ptr) ); \
00150             (ptr) = NULL;                 \
00151           FT_END_STMNT
00152 
00153 #define FT_MEM_NEW( ptr )                        \
00154           FT_MEM_ALLOC( ptr, sizeof ( *(ptr) ) )
00155 
00156 #define FT_MEM_REALLOC( ptr, cursz, newsz )                        \
00157           FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, 1,        \
00158                                                  (cursz), (newsz), \
00159                                                  (ptr), &error ) )
00160 
00161 #define FT_MEM_QALLOC( ptr, size )                                         \
00162           FT_ASSIGNP_INNER( ptr, ft_mem_qalloc( memory, (size), &error ) )
00163 
00164 #define FT_MEM_QNEW( ptr )                        \
00165           FT_MEM_QALLOC( ptr, sizeof ( *(ptr) ) )
00166 
00167 #define FT_MEM_QREALLOC( ptr, cursz, newsz )                         \
00168           FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, 1,        \
00169                                                   (cursz), (newsz), \
00170                                                   (ptr), &error ) )
00171 
00172 #define FT_MEM_QRENEW_ARRAY( ptr, cursz, newsz )                             \
00173           FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
00174                                                   (cursz), (newsz),          \
00175                                                   (ptr), &error ) )
00176 
00177 #define FT_MEM_ALLOC_MULT( ptr, count, item_size )                    \
00178           FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, (item_size), \
00179                                                  0, (count),          \
00180                                                  NULL, &error ) )
00181 
00182 #define FT_MEM_REALLOC_MULT( ptr, oldcnt, newcnt, itmsz )            \
00183           FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, (itmsz),    \
00184                                                  (oldcnt), (newcnt), \
00185                                                  (ptr), &error ) )
00186 
00187 #define FT_MEM_QALLOC_MULT( ptr, count, item_size )                    \
00188           FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, (item_size), \
00189                                                   0, (count),          \
00190                                                   NULL, &error ) )
00191 
00192 #define FT_MEM_QREALLOC_MULT( ptr, oldcnt, newcnt, itmsz)             \
00193           FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, (itmsz),    \
00194                                                   (oldcnt), (newcnt), \
00195                                                   (ptr), &error ) )
00196 
00197 
00198 #define FT_MEM_SET_ERROR( cond )  ( (cond), error != 0 )
00199 
00200 
00201 #define FT_MEM_SET( dest, byte, count )     ft_memset( dest, byte, count )
00202 
00203 #define FT_MEM_COPY( dest, source, count )  ft_memcpy( dest, source, count )
00204 
00205 #define FT_MEM_MOVE( dest, source, count )  ft_memmove( dest, source, count )
00206 
00207 
00208 #define FT_MEM_ZERO( dest, count )  FT_MEM_SET( dest, 0, count )
00209 
00210 #define FT_ZERO( p )                FT_MEM_ZERO( p, sizeof ( *(p) ) )
00211 
00212 
00213 #define FT_ARRAY_ZERO( dest, count )                        \
00214           FT_MEM_ZERO( dest, (count) * sizeof ( *(dest) ) )
00215 
00216 #define FT_ARRAY_COPY( dest, source, count )                        \
00217           FT_MEM_COPY( dest, source, (count) * sizeof ( *(dest) ) )
00218 
00219 #define FT_ARRAY_MOVE( dest, source, count )                        \
00220           FT_MEM_MOVE( dest, source, (count) * sizeof ( *(dest) ) )
00221 
00222 
00223   /*
00224    *  Return the maximum number of addressable elements in an array.
00225    *  We limit ourselves to INT_MAX, rather than UINT_MAX, to avoid
00226    *  any problems.
00227    */
00228 #define FT_ARRAY_MAX( ptr )           ( FT_INT_MAX / sizeof ( *(ptr) ) )
00229 
00230 #define FT_ARRAY_CHECK( ptr, count )  ( (count) <= FT_ARRAY_MAX( ptr ) )
00231 
00232 
00233   /*************************************************************************/
00234   /*                                                                       */
00235   /* The following functions macros expect that their pointer argument is  */
00236   /* _typed_ in order to automatically compute array element sizes.        */
00237   /*                                                                       */
00238 
00239 #define FT_MEM_NEW_ARRAY( ptr, count )                                      \
00240           FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, sizeof ( *(ptr) ), \
00241                                                  0, (count),                \
00242                                                  NULL, &error ) )
00243 
00244 #define FT_MEM_RENEW_ARRAY( ptr, cursz, newsz )                             \
00245           FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, sizeof ( *(ptr) ), \
00246                                                  (cursz), (newsz),          \
00247                                                  (ptr), &error ) )
00248 
00249 #define FT_MEM_QNEW_ARRAY( ptr, count )                                      \
00250           FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
00251                                                   0, (count),                \
00252                                                   NULL, &error ) )
00253 
00254 #define FT_MEM_QRENEW_ARRAY( ptr, cursz, newsz )                             \
00255           FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, sizeof ( *(ptr) ), \
00256                                                   (cursz), (newsz),          \
00257                                                   (ptr), &error ) )
00258 
00259 
00260 #define FT_ALLOC( ptr, size )                           \
00261           FT_MEM_SET_ERROR( FT_MEM_ALLOC( ptr, size ) )
00262 
00263 #define FT_REALLOC( ptr, cursz, newsz )                           \
00264           FT_MEM_SET_ERROR( FT_MEM_REALLOC( ptr, cursz, newsz ) )
00265 
00266 #define FT_ALLOC_MULT( ptr, count, item_size )                           \
00267           FT_MEM_SET_ERROR( FT_MEM_ALLOC_MULT( ptr, count, item_size ) )
00268 
00269 #define FT_REALLOC_MULT( ptr, oldcnt, newcnt, itmsz )              \
00270           FT_MEM_SET_ERROR( FT_MEM_REALLOC_MULT( ptr, oldcnt,      \
00271                                                  newcnt, itmsz ) )
00272 
00273 #define FT_QALLOC( ptr, size )                           \
00274           FT_MEM_SET_ERROR( FT_MEM_QALLOC( ptr, size ) )
00275 
00276 #define FT_QREALLOC( ptr, cursz, newsz )                           \
00277           FT_MEM_SET_ERROR( FT_MEM_QREALLOC( ptr, cursz, newsz ) )
00278 
00279 #define FT_QALLOC_MULT( ptr, count, item_size )                           \
00280           FT_MEM_SET_ERROR( FT_MEM_QALLOC_MULT( ptr, count, item_size ) )
00281 
00282 #define FT_QREALLOC_MULT( ptr, oldcnt, newcnt, itmsz )              \
00283           FT_MEM_SET_ERROR( FT_MEM_QREALLOC_MULT( ptr, oldcnt,      \
00284                                                   newcnt, itmsz ) )
00285 
00286 #define FT_FREE( ptr )  FT_MEM_FREE( ptr )
00287 
00288 #define FT_NEW( ptr )  FT_MEM_SET_ERROR( FT_MEM_NEW( ptr ) )
00289 
00290 #define FT_NEW_ARRAY( ptr, count )                           \
00291           FT_MEM_SET_ERROR( FT_MEM_NEW_ARRAY( ptr, count ) )
00292 
00293 #define FT_RENEW_ARRAY( ptr, curcnt, newcnt )                           \
00294           FT_MEM_SET_ERROR( FT_MEM_RENEW_ARRAY( ptr, curcnt, newcnt ) )
00295 
00296 #define FT_QNEW( ptr )                           \
00297           FT_MEM_SET_ERROR( FT_MEM_QNEW( ptr ) )
00298 
00299 #define FT_QNEW_ARRAY( ptr, count )                          \
00300           FT_MEM_SET_ERROR( FT_MEM_NEW_ARRAY( ptr, count ) )
00301 
00302 #define FT_QRENEW_ARRAY( ptr, curcnt, newcnt )                          \
00303           FT_MEM_SET_ERROR( FT_MEM_RENEW_ARRAY( ptr, curcnt, newcnt ) )
00304 
00305 
00306 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
00307 
00308   FT_BASE( FT_Error )
00309   FT_Alloc( FT_Memory  memory,
00310             FT_Long    size,
00311             void*     *P );
00312 
00313   FT_BASE( FT_Error )
00314   FT_QAlloc( FT_Memory  memory,
00315              FT_Long    size,
00316              void*     *p );
00317 
00318   FT_BASE( FT_Error )
00319   FT_Realloc( FT_Memory  memory,
00320               FT_Long    current,
00321               FT_Long    size,
00322               void*     *P );
00323 
00324   FT_BASE( FT_Error )
00325   FT_QRealloc( FT_Memory  memory,
00326                FT_Long    current,
00327                FT_Long    size,
00328                void*     *p );
00329 
00330   FT_BASE( void )
00331   FT_Free( FT_Memory  memory,
00332            void*     *P );
00333 
00334 #endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
00335 
00336 
00337   FT_BASE( FT_Pointer )
00338   ft_mem_strdup( FT_Memory    memory,
00339                  const char*  str,
00340                  FT_Error    *p_error );
00341 
00342   FT_BASE( FT_Pointer )
00343   ft_mem_dup( FT_Memory    memory,
00344               const void*  address,
00345               FT_ULong     size,
00346               FT_Error    *p_error );
00347 
00348 #define FT_MEM_STRDUP( dst, str )                                            \
00349           (dst) = (char*)ft_mem_strdup( memory, (const char*)(str), &error )
00350 
00351 #define FT_STRDUP( dst, str )                           \
00352           FT_MEM_SET_ERROR( FT_MEM_STRDUP( dst, str ) )
00353 
00354 #define FT_MEM_DUP( dst, address, size )                                    \
00355           (dst) = ft_mem_dup( memory, (address), (FT_ULong)(size), &error )
00356 
00357 #define FT_DUP( dst, address, size )                           \
00358           FT_MEM_SET_ERROR( FT_MEM_DUP( dst, address, size ) )
00359 
00360 
00361   /* Return >= 1 if a truncation occurs.            */
00362   /* Return 0 if the source string fits the buffer. */
00363   /* This is *not* the same as strlcpy().           */
00364   FT_BASE( FT_Int )
00365   ft_mem_strcpyn( char*        dst,
00366                   const char*  src,
00367                   FT_ULong     size );
00368 
00369 #define FT_STRCPYN( dst, src, size )                                         \
00370           ft_mem_strcpyn( (char*)dst, (const char*)(src), (FT_ULong)(size) )
00371 
00372  /* */
00373 
00374 
00375 FT_END_HEADER
00376 
00377 #endif /* __FTMEMORY_H__ */
00378 
00379 
00380 /* END */

Generated on Fri May 25 2012 04:32:06 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.