Further C library abstraction. Based on a patch from

msn2@bidyut.com.

* include/freetype/config/ftstdlib.h (FT_CHAR_BIT, FT_FILE,
ft_fopen, ft_fclose, ft_fseek, ft_ftell, ft_fread, ft_smalloc,
ft_scalloc, ft_srealloc, ft_sfree, ft_labs): New wrapper macros for
C library functions.  Update all users accordingly (and catch some
other places where the C library function was used instead of the
wrapper functions).

* src/base/ftsystem.c: Don't include stdio.h and stdlib.h.
* src/gzip/zutil.h [MSDOS && !(__TURBOC__ || __BORLANDC__)]: Don't
include malloc.h.
This commit is contained in:
Werner Lemberg 2006-04-29 07:31:16 +00:00
parent 50ef72b6e3
commit 8fe6539026
10 changed files with 98 additions and 49 deletions

View File

@ -1,3 +1,19 @@
2006-04-29 Werner Lemberg <wl@gnu.org>
Further C library abstraction. Based on a patch from
msn2@bidyut.com.
* include/freetype/config/ftstdlib.h (FT_CHAR_BIT, FT_FILE,
ft_fopen, ft_fclose, ft_fseek, ft_ftell, ft_fread, ft_smalloc,
ft_scalloc, ft_srealloc, ft_sfree, ft_labs): New wrapper macros for
C library functions. Update all users accordingly (and catch some
other places where the C library function was used instead of the
wrapper functions).
* src/base/ftsystem.c: Don't include stdio.h and stdlib.h.
* src/gzip/zutil.h [MSDOS && !(__TURBOC__ || __BORLANDC__)]: Don't
include malloc.h.
2006-04-28 Werner Lemberg <wl@gnu.org>
* src/lzw/ftlzw.c, src/lzw/zopen.c, src/lzw/zopen.h: Removed,

View File

@ -65,8 +65,9 @@
#include <limits.h>
#define FT_UINT_MAX UINT_MAX
#define FT_CHAR_BIT CHAR_BIT
#define FT_INT_MAX INT_MAX
#define FT_UINT_MAX UINT_MAX
#define FT_ULONG_MAX ULONG_MAX
@ -80,19 +81,19 @@
#include <ctype.h>
#define ft_isalnum isalnum
#define ft_isupper isupper
#define ft_islower islower
#define ft_isdigit isdigit
#define ft_islower islower
#define ft_isupper isupper
#define ft_isxdigit isxdigit
#include <string.h>
#define ft_memchr memchr
#define ft_memcmp memcmp
#define ft_memcpy memcpy
#define ft_memmove memmove
#define ft_memset memset
#define ft_memchr memchr
#define ft_strcat strcat
#define ft_strcmp strcmp
#define ft_strcpy strcpy
@ -102,8 +103,21 @@
#define ft_strrchr strrchr
/**********************************************************************/
/* */
/* file handling */
/* */
/**********************************************************************/
#include <stdio.h>
#define FT_FILE FILE
#define ft_fclose fclose
#define ft_fopen fopen
#define ft_fread fread
#define ft_fseek fseek
#define ft_ftell ftell
#define ft_sprintf sprintf
@ -117,9 +131,32 @@
#include <stdlib.h>
#define ft_qsort qsort
#define ft_exit exit /* only used to exit from unhandled exceptions */
/**********************************************************************/
/* */
/* memory allocation */
/* */
/**********************************************************************/
#define ft_scalloc calloc
#define ft_sfree free
#define ft_smalloc malloc
#define ft_srealloc realloc
/**********************************************************************/
/* */
/* miscellaneous */
/* */
/**********************************************************************/
#define ft_atol atol
#define ft_labs labs
/**********************************************************************/
@ -135,13 +172,13 @@
/* jmp_buf is defined as a macro */
/* on certain platforms */
#define ft_setjmp setjmp /* same thing here */
#define ft_longjmp longjmp /* likewise */
#define ft_setjmp setjmp /* same thing here */
/* the following is only used for debugging purposes, i.e. when */
/* FT_DEBUG_LEVEL_ERROR or FT_DEBUG_LEVEL_TRACE are defined */
/* */
/* the following is only used for debugging purposes, i.e., if */
/* FT_DEBUG_LEVEL_ERROR or FT_DEBUG_LEVEL_TRACE are defined */
#include <stdarg.h>

View File

@ -4,7 +4,7 @@
/* */
/* FreeType simple types definitions (specification only). */
/* */
/* Copyright 1996-2001, 2002, 2004 by */
/* Copyright 1996-2001, 2002, 2004, 2006 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -308,7 +308,7 @@ FT_BEGIN_HEADER
/* FT_Offset */
/* */
/* <Description> */
/* This is equivalent to the ANSI C `size_t' type, i.e. the largest */
/* This is equivalent to the ANSI C `size_t' type, i.e., the largest */
/* _unsigned_ integer type used to express a file size or position, */
/* or a memory block size. */
/* */
@ -321,7 +321,7 @@ FT_BEGIN_HEADER
/* FT_PtrDist */
/* */
/* <Description> */
/* This is equivalent to the ANSI C `ptrdiff_t' type, i.e. the */
/* This is equivalent to the ANSI C `ptrdiff_t' type, i.e., the */
/* largest _signed_ integer type used to express the distance */
/* between two pointers. */
/* */

View File

@ -196,9 +196,9 @@
/* build up a complete face name */
ft_strcpy( fullName, famName );
if ( style & bold )
strcat( fullName, " Bold" );
ft_strcat( fullName, " Bold" );
if ( style & italic )
strcat( fullName, " Italic" );
ft_strcat( fullName, " Italic" );
/* compare with the name we are looking for */
if ( ft_strcmp( fullName, fontName ) == 0 )
@ -292,13 +292,13 @@
#if defined( __MWERKS__ ) && !TARGET_RT_MAC_MACHO
#define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer )
#define STREAM_FILE( stream ) ( (FT_FILE*)stream->descriptor.pointer )
FT_CALLBACK_DEF( void )
ft_FSp_stream_close( FT_Stream stream )
{
fclose( STREAM_FILE( stream ) );
ft_fclose( STREAM_FILE( stream ) );
stream->descriptor.pointer = NULL;
stream->size = 0;
@ -312,14 +312,14 @@
unsigned char* buffer,
unsigned long count )
{
FILE* file;
FT_FILE* file;
file = STREAM_FILE( stream );
fseek( file, offset, SEEK_SET );
ft_fseek( file, offset, SEEK_SET );
return (unsigned long)fread( buffer, 1, count, file );
return (unsigned long)ft_fread( buffer, 1, count, file );
}
#endif /* __MWERKS__ && !TARGET_RT_MAC_MACHO */

View File

@ -33,9 +33,6 @@
#include FT_ERRORS_H
#include FT_TYPES_H
#include <stdio.h>
#include <stdlib.h>
/*************************************************************************/
/* */
@ -74,7 +71,7 @@
{
FT_UNUSED( memory );
return malloc( size );
return ft_smalloc( size );
}
@ -107,7 +104,7 @@
FT_UNUSED( memory );
FT_UNUSED( cur_size );
return realloc( block, new_size );
return ft_srealloc( block, new_size );
}
@ -130,7 +127,7 @@
{
FT_UNUSED( memory );
free( block );
ft_sfree( block );
}
@ -152,7 +149,7 @@
/* We use the macro STREAM_FILE for convenience to extract the */
/* system-specific stream handle from a given FreeType stream object */
#define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer )
#define STREAM_FILE( stream ) ( (FT_FILE*)stream->descriptor.pointer )
/*************************************************************************/
@ -169,7 +166,7 @@
FT_CALLBACK_DEF( void )
ft_ansi_stream_close( FT_Stream stream )
{
fclose( STREAM_FILE( stream ) );
ft_fclose( STREAM_FILE( stream ) );
stream->descriptor.pointer = NULL;
stream->size = 0;
@ -203,14 +200,14 @@
unsigned char* buffer,
unsigned long count )
{
FILE* file;
FT_FILE* file;
file = STREAM_FILE( stream );
fseek( file, offset, SEEK_SET );
ft_fseek( file, offset, SEEK_SET );
return (unsigned long)fread( buffer, 1, count, file );
return (unsigned long)ft_fread( buffer, 1, count, file );
}
@ -220,13 +217,13 @@
FT_Stream_Open( FT_Stream stream,
const char* filepathname )
{
FILE* file;
FT_FILE* file;
if ( !stream )
return FT_Err_Invalid_Stream_Handle;
file = fopen( filepathname, "rb" );
file = ft_fopen( filepathname, "rb" );
if ( !file )
{
FT_ERROR(( "FT_Stream_Open:" ));
@ -235,9 +232,9 @@
return FT_Err_Cannot_Open_Resource;
}
fseek( file, 0, SEEK_END );
stream->size = ftell( file );
fseek( file, 0, SEEK_SET );
ft_fseek( file, 0, SEEK_END );
stream->size = ft_ftell( file );
ft_fseek( file, 0, SEEK_SET );
stream->descriptor.pointer = file;
stream->pathname.pointer = (char*)filepathname;
@ -273,7 +270,7 @@
FT_Memory memory;
memory = (FT_Memory)malloc( sizeof ( *memory ) );
memory = (FT_Memory)ft_smalloc( sizeof ( *memory ) );
if ( memory )
{
memory->user = 0;

View File

@ -122,7 +122,7 @@
bitg = (FT_BitmapGlyph)glyph;
size = bitg->bitmap.rows * labs( bitg->bitmap.pitch ) +
size = bitg->bitmap.rows * ft_labs( bitg->bitmap.pitch ) +
sizeof ( *bitg );
}
break;

View File

@ -612,8 +612,8 @@
/* double check */
if ( !(flags & FT_STYLE_FLAG_BOLD) && cffface->style_name )
if ( !strncmp( cffface->style_name, "Bold", 4 ) ||
!strncmp( cffface->style_name, "Black", 5 ) )
if ( !ft_strncmp( cffface->style_name, "Bold", 4 ) ||
!ft_strncmp( cffface->style_name, "Black", 5 ) )
flags |= FT_STYLE_FLAG_BOLD;
cffface->style_flags = flags;

View File

@ -5,7 +5,7 @@
/* Generate feature registry data for gxv `feat' validator. */
/* This program is derived from gxfeatreg.c in gxlayout. */
/* */
/* Copyright 2004, 2005 by Masatake YAMATO and Redhat K.K. */
/* Copyright 2004, 2005, 2006 by Masatake YAMATO and Redhat K.K. */
/* */
/* This file may only be used, */
/* modified, and distributed under the terms of the FreeType project */
@ -464,9 +464,9 @@
printf( " {%1d, %1d, %1d, %2d}, /* %s */\n",
feat_name ? 1 : 0,
( feat_name &&
( strncmp( feat_name,
APPLE_RESERVED, APPLE_RESERVED_LENGTH ) == 0 )
( feat_name &&
( ft_strncmp( feat_name,
APPLE_RESERVED, APPLE_RESERVED_LENGTH ) == 0 )
) ? 1 : 0,
featreg_table[i].exclusive ? 1 : 0,
nSettings,

View File

@ -157,8 +157,8 @@ void zcfree (voidpf opaque, voidpf ptr)
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
#ifndef STDC
extern voidp calloc OF((uInt items, uInt size));
extern void free OF((voidpf ptr));
extern voidp ft_scalloc OF((uInt items, uInt size));
extern void ft_sfree OF((voidpf ptr));
#endif
voidpf zcalloc (opaque, items, size)
@ -167,14 +167,14 @@ voidpf zcalloc (opaque, items, size)
unsigned size;
{
if (opaque) items += size - size; /* make compiler happy */
return (voidpf)calloc(items, size);
return (voidpf)ft_scalloc(items, size);
}
void zcfree (opaque, ptr)
voidpf opaque;
voidpf ptr;
{
free(ptr);
ft_sfree(ptr);
if (opaque) return; /* make compiler happy */
}

View File

@ -80,7 +80,6 @@ typedef unsigned long ulg;
# include <alloc.h>
# endif
# else /* MSC or DJGPP */
# include <malloc.h>
# endif
#endif
@ -95,7 +94,7 @@ typedef unsigned long ulg;
#if defined(VAXC) || defined(VMS)
# define OS_CODE 0x02
# define F_OPEN(name, mode) \
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
ft_fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
#endif
#ifdef AMIGA
@ -141,7 +140,7 @@ typedef unsigned long ulg;
#endif
#ifndef F_OPEN
# define F_OPEN(name, mode) fopen((name), (mode))
# define F_OPEN(name, mode) ft_fopen((name), (mode))
#endif
/* functions */