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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
diff --git a/ChangeLog b/ChangeLog
index 4d2867e..bfb902c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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,
diff --git a/include/freetype/config/ftstdlib.h b/include/freetype/config/ftstdlib.h
index 09ccf0c..aaba8b3 100644
--- a/include/freetype/config/ftstdlib.h
+++ b/include/freetype/config/ftstdlib.h
@@ -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., if */
+ /* FT_DEBUG_LEVEL_ERROR or FT_DEBUG_LEVEL_TRACE are defined */
- /* the following is only used for debugging purposes, i.e. when */
- /* FT_DEBUG_LEVEL_ERROR or FT_DEBUG_LEVEL_TRACE are defined */
- /* */
#include <stdarg.h>
diff --git a/include/freetype/fttypes.h b/include/freetype/fttypes.h
index 7727ebb..fc65404 100644
--- a/include/freetype/fttypes.h
+++ b/include/freetype/fttypes.h
@@ -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. */
/* */
diff --git a/src/base/ftmac.c b/src/base/ftmac.c
index 3be12cf..5aed896 100644
--- a/src/base/ftmac.c
+++ b/src/base/ftmac.c
@@ -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 */
diff --git a/src/base/ftsystem.c b/src/base/ftsystem.c
index 8900e95..f61a3ed 100644
--- a/src/base/ftsystem.c
+++ b/src/base/ftsystem.c
@@ -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;
diff --git a/src/cache/ftcimage.c b/src/cache/ftcimage.c
index 500c524..15d4e80 100644
--- a/src/cache/ftcimage.c
+++ b/src/cache/ftcimage.c
@@ -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;
diff --git a/src/cff/cffobjs.c b/src/cff/cffobjs.c
index 56c1fc0..2d1204e 100644
--- a/src/cff/cffobjs.c
+++ b/src/cff/cffobjs.c
@@ -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;
diff --git a/src/gxvalid/gxvfgen.c b/src/gxvalid/gxvfgen.c
index ca077b1..2af9a0d 100644
--- a/src/gxvalid/gxvfgen.c
+++ b/src/gxvalid/gxvfgen.c
@@ -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,
diff --git a/src/gzip/zutil.c b/src/gzip/zutil.c
index 5da9f98..0b47dd4 100644
--- a/src/gzip/zutil.c
+++ b/src/gzip/zutil.c
@@ -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 */
}
diff --git a/src/gzip/zutil.h b/src/gzip/zutil.h
index ce02022..5f2d543 100644
--- a/src/gzip/zutil.h
+++ b/src/gzip/zutil.h
@@ -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 */