Commit d8021097 authored by David Turner's avatar David Turner
Browse files

* include/freetype/internal/ftmemory.h, and a lot of other files !!:

            changed the names of memory macros. Examples:

              MEM_Set   => FT_MEM_SET
              MEM_Copy  => FT_MEM_COPY
              MEM_Move  => FT_MEM_MOVE

              ALLOC     => FT_ALLOC
              FREE      => FT_FREE
              REALLOC   = >FT_REALLOC

            FT_NEW was introduced to allocate a new object from a _typed_
            pointer..

            note that ALLOC_ARRAY and REALLOC_ARRAY have been replaced
            by FT_NEW_ARRAY and FT_RENEW_ARRAY which take _typed_ pointer
            arguments.

            This results in _lots_ of sources being changed, but makes the
            code more generic and less error-prone..
parent c9bcd833
2002-03-22 David Turner <david@freetype.org>
* include/freetype/internal/ftmemory.h, and a lot of other files !!:
changed the names of memory macros. Examples:
MEM_Set => FT_MEM_SET
MEM_Copy => FT_MEM_COPY
MEM_Move => FT_MEM_MOVE
ALLOC => FT_ALLOC
FREE => FT_FREE
REALLOC = >FT_REALLOC
FT_NEW was introduced to allocate a new object from a _typed_
pointer..
note that ALLOC_ARRAY and REALLOC_ARRAY have been replaced
by FT_NEW_ARRAY and FT_RENEW_ARRAY which take _typed_ pointer
arguments.
This results in _lots_ of sources being changed, but makes the
code more generic and less error-prone..
* include/freetype/internal/ftstream.h,
src/base/ftstream.c, src/cff/cffload.c, src/pcf/pcfread.c,
src/sfnt/ttcmap.c, src/sfnt/ttcmap0.c, src/sfnt/ttload.c,
......
......@@ -176,108 +176,117 @@ FT_BEGIN_HEADER
/* available on all platforms we know of. */
#include <string.h>
#define MEM_Set( dest, byte, count ) memset( dest, byte, count )
#define FT_MEM_SET( dest, byte, count ) memset( dest, byte, count )
#define MEM_Copy( dest, source, count ) memcpy( dest, source, count )
#define FT_MEM_COPY( dest, source, count ) memcpy( dest, source, count )
#define MEM_Move( dest, source, count ) memmove( dest, source, count )
#define FT_MEM_MOVE( dest, source, count ) memmove( dest, source, count )
/*************************************************************************/
/* */
/* We now support closures to produce completely reentrant code. This */
/* means the allocation functions now takes an additional argument */
/* (`memory'). It is a handle to a given memory object, responsible for */
/* all low-level operations, including memory management and */
/* synchronisation. */
/* */
/* In order to keep our code readable and use the same macros in the */
/* font drivers and the rest of the library, MEM_Alloc(), ALLOC(), and */
/* ALLOC_ARRAY() now use an implicit variable, `memory'. It must be */
/* defined at all locations where a memory operation is queried. */
/* */
/**************************************************************************
*
* we first define FT_MEM_ALLOC, FT_MEM_REALLOC and FT_MEM_FREE
* all macros use an _implicit_ 'memory' parameter to access the
* current memory allocator
*
*/
#ifdef FT_DEBUG_MEMORY
#define MEM_Alloc( _pointer_, _size_ ) \
FT_Alloc_Debug( memory, _size_, \
# define FT_MEM_ALLOC( _pointer_, _size_ ) \
FT_Alloc_Debug( memory, _size_, \
(void**)&(_pointer_), __FILE__, __LINE__ )
#define MEM_Alloc_Array( _pointer_, _count_, _type_ ) \
FT_Alloc_Debug( memory, (_count_)*sizeof ( _type_ ), \
(void**)&(_pointer_), __FILE__, __LINE__ )
#define MEM_Realloc( _pointer_, _current_, _size_ ) \
FT_Realloc_Debug( memory, _current_, _size_, \
(void**)&(_pointer_), __FILE__, __LINE__ )
#define MEM_Realloc_Array( _pointer_, _current_, _new_, _type_ ) \
FT_Realloc_Debug( memory, (_current_)*sizeof ( _type_ ), \
(_new_)*sizeof ( _type_ ), \
# define FT_MEM_REALLOC( _pointer_, _current_, _size_ ) \
FT_Realloc_Debug( memory, _current_, _size_, \
(void**)&(_pointer_), __FILE__, __LINE__ )
#define MEM_Free( _pointer_ ) \
# define FT_MEM_FREE( _pointer_ ) \
FT_Free_Debug( memory, (void**)&(_pointer_), __FILE__, __LINE__ )
#else /* !FT_DEBUG_MEMORY */
#define MEM_Alloc( _pointer_, _size_ ) \
# define FT_MEM_ALLOC( _pointer_, _size_ ) \
FT_Alloc( memory, _size_, (void**)&(_pointer_) )
#define MEM_New( _pointer_ ) MEM_Alloc( _pointer_, sizeof(*(_pointer_)) )
# define FT_MEM_FREE( _pointer_ ) \
FT_Free( memory, (void**)&(_pointer_) )
# define FT_MEM_REALLOC( _pointer_, _current_, _size_ ) \
FT_Realloc( memory, _current_, _size_, (void**)&(_pointer_) )
#define MEM_Alloc_Array( _pointer_, _count_, _type_ ) \
FT_Alloc( memory, (_count_)*sizeof ( _type_ ), \
(void**)&(_pointer_) )
#endif /* !FT_DEBUG_MEMORY */
#define MEM_New_Array( _pointer_, _count_ ) \
MEM_Alloc_Array( _pointer_, _count_, sizeof(*(_pointer_)) )
#define MEM_Realloc( _pointer_, _current_, _size_ ) \
FT_Realloc( memory, _current_, _size_, (void**)&(_pointer_) )
/**************************************************************************
*
* the following functions macros that their pointer argument is _typed_
* in order to automatically compute array element sizes..
*/
#define FT_MEM_NEW( _pointer_ ) \
FT_MEM_ALLOC( _pointer_, sizeof(*(_pointer_)) )
#define MEM_Realloc_Array( _pointer_, _current_, _new_, _type_ ) \
FT_Realloc( memory, (_current_)*sizeof ( _type_ ), \
(_new_)*sizeof ( _type_ ), (void**)&(_pointer_) )
#define FT_MEM_NEW_ARRAY( _pointer_, _count_ ) \
FT_MEM_ALLOC( _pointer_, (_count_)*sizeof(*(_pointer_)) )
#define MEM_Renew_Array( _pointer_, _current_, _new_ ) \
MEM_Realloc_Array( _pointer_, _current_, _new_, *(_pointer_) )
#define FT_MEM_RENEW_ARRAY( _pointer_, _old_, _new_ ) \
FT_MEM_REALLOC( _pointer_, (_old_)*sizeof(*(_pointer_)), \
(_new_)*sizeof(*(_pointer_)) )
#define MEM_Free( _pointer_ ) \
FT_Free( memory, (void**)&(_pointer_) )
#endif /* !FT_DEBUG_MEMORY */
/**************************************************************************
*
* the following macros are obsolete but kept for compatibility reasons
*/
#define FT_MEM_ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
FT_MEM_ALLOC( _pointer_, (_count_)*sizeof(_type_) )
#define ALLOC( _pointer_, _size_ ) \
FT_SET_ERROR( MEM_Alloc( _pointer_, _size_ ) )
#define FT_MEM_REALLOC_ARRAY( _pointer_, _current_, _new_, _type_ ) \
FT_MEM_REALLOC( _pointer_, (_current_)*sizeof(_type), \
(_new_)*sizeof(_type_) )
#define NEW( _pointer_ ) \
FT_SET_ERROR( MEM_New( _pointer_ ) )
#define REALLOC( _pointer_, _current_, _size_ ) \
FT_SET_ERROR( MEM_Realloc( _pointer_, _current_, _size_ ) )
#define ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
FT_SET_ERROR( MEM_Alloc( _pointer_, \
(_count_)*sizeof ( _type_ ) ) )
/**************************************************************************
*
* the following macros are variants of their FT_MEM_XXXX equivalents
* they're used to set an _implicit_ 'error' variable and return TRUE
* if an error occured (i.e. if 'error != 0')
*/
#define NEW_ARRAY( _pointer_, _count_ ) \
FT_SET_ERROR( MEM_New_Array( _pointer_, _count_ ) )
#define REALLOC_ARRAY( _pointer_, _current_, _count_, _type_ ) \
FT_SET_ERROR( MEM_Realloc( _pointer_, \
(_current_)*sizeof ( _type_ ), \
(_count_)*sizeof ( _type_ ) ) )
#define RENEW_ARRAY( _pointer_, _current_, _new_ ) \
FT_SET_ERROR( MEM_Renew_Array( _pointer_, _current_, _new_ ) )
#define FT_ALLOC( _pointer_, _size_ ) \
FT_SET_ERROR( FT_MEM_ALLOC( _pointer_, _size_ ) )
#define FT_REALLOC( _pointer_, _current_, _size_ ) \
FT_SET_ERROR( FT_MEM_REALLOC( _pointer_, _current_, _size_ ) )
#define FT_FREE( _pointer_ ) \
FT_MEM_FREE( _pointer_ )
#define FT_NEW( _pointer_ ) \
FT_SET_ERROR( FT_MEM_NEW( _pointer_ ) )
#define FREE( _pointer_ ) \
MEM_Free( _pointer_ )
#define FT_RENEW_ARRAY( _pointer_, _current_, _new_ ) \
FT_SET_ERROR( FT_MEM_RENEW_ARRAY( _pointer_, _current_, _new_ ) )
#define FT_ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
FT_SET_ERROR( FT_MEM_ALLOC( _pointer_, \
(_count_)*sizeof ( _type_ ) ) )
#define FT_NEW_ARRAY( _pointer_, _count_ ) \
FT_SET_ERROR( FT_MEM_NEW_ARRAY( _pointer_, _count_ ) )
#define FT_REALLOC_ARRAY( _pointer_, _current_, _count_, _type_ ) \
FT_SET_ERROR( FT_MEM_REALLOC( _pointer_, \
(_current_)*sizeof ( _type_ ), \
(_count_)*sizeof ( _type_ ) ) )
/* */
FT_END_HEADER
#endif /* __FTMEMORY_H__ */
......
......@@ -307,7 +307,7 @@
AH_Outline* outline;
if ( !ALLOC( outline, sizeof ( *outline ) ) )
if ( !FT_NEW( outline ) )
{
outline->memory = memory;
*aoutline = outline;
......@@ -331,12 +331,12 @@
FT_Memory memory = outline->memory;
FREE( outline->horz_edges );
FREE( outline->horz_segments );
FREE( outline->contours );
FREE( outline->points );
FT_FREE( outline->horz_edges );
FT_FREE( outline->horz_segments );
FT_FREE( outline->contours );
FT_FREE( outline->points );
FREE( outline );
FT_FREE( outline );
}
......@@ -408,8 +408,9 @@
FT_Int new_contours = ( num_contours + 3 ) & -4;
if ( REALLOC_ARRAY( outline->contours, outline->max_contours,
new_contours, AH_Point* ) )
if ( FT_RENEW_ARRAY( outline->contours,
outline->max_contours,
new_contours ) )
goto Exit;
outline->max_contours = new_contours;
......@@ -425,12 +426,9 @@
FT_Int max = outline->max_points;
if ( REALLOC_ARRAY( outline->points,
max, news, AH_Point ) ||
REALLOC_ARRAY( outline->horz_edges,
max * 2, news * 2, AH_Edge ) ||
REALLOC_ARRAY( outline->horz_segments,
max * 2, news * 2, AH_Segment ) )
if ( FT_RENEW_ARRAY( outline->points, max, news ) ||
FT_RENEW_ARRAY( outline->horz_edges, max * 2, news * 2 ) ||
FT_RENEW_ARRAY( outline->horz_segments, max * 2, news * 2 ) )
goto Exit;
/* readjust some pointers */
......@@ -816,7 +814,7 @@
segment_dir = point->out_dir;
/* clear all segment fields */
MEM_Set( segment, 0, sizeof ( *segment ) );
FT_MEM_SET( segment, 0, sizeof ( *segment ) );
segment->dir = segment_dir;
segment->flags = ah_edge_normal;
......@@ -878,7 +876,7 @@
if ( min_point )
{
/* clear all segment fields */
MEM_Set( segment, 0, sizeof ( *segment ) );
FT_MEM_SET( segment, 0, sizeof ( *segment ) );
segment->dir = segment_dir;
segment->flags = ah_edge_normal;
......@@ -894,7 +892,7 @@
if ( max_point )
{
/* clear all segment fields */
MEM_Set( segment, 0, sizeof ( *segment ) );
FT_MEM_SET( segment, 0, sizeof ( *segment ) );
segment->dir = segment_dir;
segment->flags = ah_edge_normal;
......@@ -1117,7 +1115,7 @@
edge_limit++;
/* clear all edge fields */
MEM_Set( edge, 0, sizeof ( *edge ) );
FT_MEM_SET( edge, 0, sizeof ( *edge ) );
/* add the segment to the new edge's list */
edge->first = seg;
......
......@@ -913,7 +913,7 @@
hinter->globals = 0;
hinter->face = 0;
FREE( hinter );
FT_FREE( hinter );
}
}
......@@ -931,7 +931,7 @@
*ahinter = 0;
/* allocate object */
if ( ALLOC( hinter, sizeof ( *hinter ) ) )
if ( FT_NEW( hinter ) )
goto Exit;
hinter->memory = memory;
......@@ -965,7 +965,7 @@
AH_Face_Globals* face_globals;
if ( ALLOC( face_globals, sizeof ( *face_globals ) ) )
if ( FT_NEW( face_globals ) )
goto Exit;
hinter->face = face;
......@@ -994,7 +994,7 @@
FT_Memory memory = face->memory;
FREE( globals );
FT_FREE( globals );
}
......@@ -1067,13 +1067,13 @@
if ( error )
goto Exit;
MEM_Copy( gloader->current.extra_points, slot->outline.points,
FT_MEM_COPY( gloader->current.extra_points, slot->outline.points,
slot->outline.n_points * sizeof ( FT_Vector ) );
MEM_Copy( gloader->current.outline.contours, slot->outline.contours,
FT_MEM_COPY( gloader->current.outline.contours, slot->outline.contours,
slot->outline.n_contours * sizeof ( short ) );
MEM_Copy( gloader->current.outline.tags, slot->outline.tags,
FT_MEM_COPY( gloader->current.outline.tags, slot->outline.tags,
slot->outline.n_points * sizeof ( char ) );
gloader->current.outline.n_points = slot->outline.n_points;
......@@ -1151,7 +1151,7 @@
if ( error )
goto Exit;
MEM_Copy( gloader->current.subglyphs, slot->subglyphs,
FT_MEM_COPY( gloader->current.subglyphs, slot->subglyphs,
num_subglyphs * sizeof ( FT_SubGlyph ) );
gloader->current.num_subglyphs = num_subglyphs;
......@@ -1393,7 +1393,7 @@
/* allocate new master globals */
if ( ALLOC( globals, sizeof ( *globals ) ) )
if ( FT_NEW( globals ) )
goto Fail;
/* compute face globals if needed */
......@@ -1411,7 +1411,7 @@
return;
Fail:
FREE( globals );
FT_FREE( globals );
*global_hints = 0;
*global_len = 0;
......@@ -1425,7 +1425,7 @@
FT_Memory memory = hinter->memory;
FREE( global_hints );
FT_FREE( global_hints );
}
......
......@@ -32,7 +32,7 @@
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H /* for ALLOC_ARRAY() and FREE() */
#include FT_INTERNAL_OBJECTS_H /* for FT_ALLOC_ARRAY() and FT_FREE() */
#include "ahoptim.h"
......@@ -220,7 +220,7 @@
AH_Stem* stem;
if ( ALLOC_ARRAY( stems, num_stems, AH_Stem ) )
if ( FT_NEW_ARRAY( stems, num_stems ) )
goto Exit;
stem = stems;
......@@ -409,7 +409,7 @@
/* allocate table of springs */
if ( ALLOC_ARRAY( springs, num_springs, AH_Spring ) )
if ( FT_NEW_ARRAY( springs, num_springs ) )
goto Exit;
/* fill the springs table */
......@@ -796,11 +796,11 @@
FT_Memory memory = optimizer->memory;
FREE( optimizer->horz_stems );
FREE( optimizer->vert_stems );
FREE( optimizer->horz_springs );
FREE( optimizer->vert_springs );
FREE( optimizer->positions );
FT_FREE( optimizer->horz_stems );
FT_FREE( optimizer->vert_stems );
FT_FREE( optimizer->horz_springs );
FT_FREE( optimizer->vert_springs );
FT_FREE( optimizer->positions );
}
}
......@@ -814,7 +814,7 @@
FT_Error error;
MEM_Set( optimizer, 0, sizeof ( *optimizer ) );
FT_MEM_SET( optimizer, 0, sizeof ( *optimizer ) );
optimizer->outline = outline;
optimizer->memory = memory;
......@@ -834,8 +834,7 @@
if ( max_stems < optimizer->num_vstems )
max_stems = optimizer->num_vstems;
if ( ALLOC_ARRAY( optimizer->positions,
max_stems * AH_MAX_CONFIGS, FT_Pos ) )
if ( FT_NEW_ARRAY( optimizer->positions, max_stems * AH_MAX_CONFIGS ) )
goto Fail;
optimizer->num_configs = 0;
......
......@@ -205,7 +205,7 @@
if ( new_buckets == NULL )
return;
MEM_Set( new_buckets, 0, sizeof ( FT_MemNode ) * new_size );
FT_MEM_SET( new_buckets, 0, sizeof ( FT_MemNode ) * new_size );
for ( i = 0; i < table->size; i++ )
{
......@@ -246,7 +246,7 @@
if ( table == NULL )
goto Exit;
MEM_Set( table, 0, sizeof ( *table ) );
FT_MEM_SET( table, 0, sizeof ( *table ) );
table->size = FT_MEM_SIZE_MIN;
table->nodes = 0;
......@@ -263,7 +263,7 @@
memory->alloc( memory,
table->size * sizeof ( FT_MemNode ) );
if ( table->buckets )
MEM_Set( table->buckets, 0, sizeof ( FT_MemNode ) * table->size );
FT_MEM_SET( table->buckets, 0, sizeof ( FT_MemNode ) * table->size );
else
{
memory->free( memory, table );
......@@ -452,7 +452,7 @@
/* we simply invert the node's size to indicate that the node */
/* was freed. We also change its contents. */
MEM_Set( address, 0xF3, node->size );
FT_MEM_SET( address, 0xF3, node->size );
table->alloc_current -= node->size;
node->size = -node->size;
......
......@@ -53,7 +53,7 @@
FT_Error error;
if ( !ALLOC( loader, sizeof ( *loader ) ) )
if ( !FT_NEW( loader ) )
{
loader->memory = memory;
*aloader = loader;
......@@ -86,11 +86,11 @@
FT_Memory memory = loader->memory;
FREE( loader->base.outline.points );
FREE( loader->base.outline.tags );
FREE( loader->base.outline.contours );
FREE( loader->base.extra_points );
FREE( loader->base.subglyphs );
FT_FREE( loader->base.outline.points );
FT_FREE( loader->base.outline.tags );
FT_FREE( loader->base.outline.contours );
FT_FREE( loader->base.extra_points );
FT_FREE( loader->base.subglyphs );
loader->max_points = 0;
loader->max_contours = 0;
......@@ -110,7 +110,7 @@
FT_GlyphLoader_Reset( loader );
FREE( loader );
FT_FREE( loader );
}
}
......@@ -141,8 +141,7 @@
FT_Memory memory = loader->memory;
if ( !ALLOC_ARRAY( loader->base.extra_points,
loader->max_points, FT_Vector ) )
if ( !FT_NEW_ARRAY( loader->base.extra_points, loader->max_points ) )
{
loader->use_extra = 1;
FT_GlyphLoader_Adjust_Points( loader );
......@@ -189,13 +188,12 @@
{
new_max = ( new_max + 7 ) & -8;
if ( REALLOC_ARRAY( base->points, old_max, new_max, FT_Vector ) ||
REALLOC_ARRAY( base->tags, old_max, new_max, FT_Byte ) )
if ( FT_RENEW_ARRAY( base->points, old_max, new_max ) ||
FT_RENEW_ARRAY( base->tags, old_max, new_max ) )
goto Exit;
if ( loader->use_extra &&
REALLOC_ARRAY( loader->base.extra_points, old_max,
new_max, FT_Vector ) )
FT_RENEW_ARRAY( loader->base.extra_points, old_max, new_max ) )
goto Exit;
adjust = 1;
......@@ -209,7 +207,7 @@
if ( new_max > old_max )
{
new_max = ( new_max + 3 ) & -4;
if ( REALLOC_ARRAY( base->contours, old_max, new_max, FT_Short ) )
if ( FT_RENEW_ARRAY( base->contours, old_max, new_max ) )
goto Exit;
adjust = 1;
......@@ -245,7 +243,7 @@
if ( new_max > old_max )
{
new_max = ( new_max + 1 ) & -2;
if ( REALLOC_ARRAY( base->subglyphs, old_max, new_max, FT_SubGlyphRec ) )
if ( FT_RENEW_ARRAY( base->subglyphs, old_max, new_max ) )
goto Exit;
loader->max_subglyphs = new_max;
......@@ -319,16 +317,16 @@
FT_Outline* in = &source->base.outline;
MEM_Copy( out->points, in->points,
FT_MEM_COPY( out->points, in->points,
num_points * sizeof ( FT_Vector ) );
MEM_Copy( out->tags, in->tags,
FT_MEM_COPY( out->tags, in->tags,
num_points * sizeof ( char ) );
MEM_Copy( out->contours, in->contours,
FT_MEM_COPY( out->contours, in->contours,
num_contours * sizeof ( short ) );
/* do we need to copy the extra points? */
if ( target->use_extra && source->use_extra )
MEM_Copy( target->base.extra_points, source->base.extra_points,
FT_MEM_COPY( target->base.extra_points, source->base.extra_points,
num_points * sizeof ( FT_Vector ) );
out->n_points = (short)num_points;
......
......@@ -131,8 +131,8 @@
size = (FT_ULong)( pitch * source->rows );
if ( !ALLOC( target->buffer, size ) )
MEM_Copy( target->buffer, source->buffer, size );
if ( !FT_ALLOC( target->buffer, size ) )
FT_MEM_COPY( target->buffer, source->buffer, size );
return error;
}
......@@ -191,7 +191,7 @@
FT_Memory memory = FT_GLYPH(glyph)->library->memory;
FREE( glyph->bitmap.buffer );
FT_FREE( glyph->bitmap.buffer );
}
......@@ -253,13 +253,13 @@
goto Exit;
/* copy it */
MEM_Copy( target->points, source->points,
FT_MEM_COPY( target->points, source->points,
source->n_points * sizeof ( FT_Vector ) );
MEM_Copy( target->tags, source->tags,
FT_MEM_COPY( target->tags, source->tags,
source->n_points * sizeof ( FT_Byte ) );
MEM_Copy( target->contours, source->contours,
FT_MEM_COPY( target->contours, source->contours,
source->n_contours * sizeof ( FT_Short ) );
/* copy all flags, except the `ft_outline_owner' one */
......@@ -361,7 +361,7 @@
*aglyph = 0;
if ( !ALLOC( glyph, clazz->glyph_size ) )
if ( !FT_ALLOC( glyph, clazz->glyph_size ) )
{