From c5cdf8bcf1bded63fbd57853ded641a42292a91c Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 27 Jul 2000 21:40:22 +0000 Subject: [PATCH] re-adding a "unix-dev.mk". Debugging libtool output is just too much of a pain for me, I prefer a good old static lib without optimizations :-) "make devel" is back on Unix then.. --- CHANGES | 15 ++++ builds/unix/detect.mk | 39 ++++---- builds/unix/ftsystem.c | 16 ++++ builds/unix/unix-dev.mk | 140 +++++++++++++++++++++++++++++ include/freetype/internal/ftobjs.h | 1 + src/autohint/ahglyph.c | 9 +- src/base/ftinit.c | 34 +++++++ src/base/ftobjs.c | 60 +++++-------- src/base/ftsystem.c | 16 ++++ src/psnames/psnames.c | 2 +- src/truetype/ttgload.c | 5 +- src/truetype/ttobjs.c | 4 +- src/truetype/ttobjs.h | 1 + 13 files changed, 276 insertions(+), 66 deletions(-) create mode 100644 builds/unix/unix-dev.mk diff --git a/CHANGES b/CHANGES index d9d5816cb..8cec03249 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,20 @@ LATEST CHANGES + - fixed two memory leaks: + - the memory manager (16 bytes) isn't released in FT_Done_FreeType !! + + - using custom input streams, the copy of the original stream + was never released + + - fixed the auto-hinter by performing automatic computation of the + "filling direction" of each glyph. This is done through a simple and + fast approximation, and seems to work (problems spotted by Werner + though). The Arphic fonts are a lot nicer though there are still a + lot of things to do to handle Asian fonts correctly.. + +=========================================================================== +BETA-8 (RELEASE CANDIDATE) CHANGES + - deactivated the trueType bytecode interpreter by default - deactivated the "src/type1" font driver. Now "src/type1z" is diff --git a/builds/unix/detect.mk b/builds/unix/detect.mk index dec1baa79..6d7f6ea77 100644 --- a/builds/unix/detect.mk +++ b/builds/unix/detect.mk @@ -22,30 +22,29 @@ ifeq ($(PLATFORM),ansi) COPY := cp DELETE := rm -f - # If a Unix platform is detected, the configure script is called and - # `unix.mk' is created. - # - # Arguments to `configure' should be in the CFG variable. Example: - # - # make CFG="--prefix=/usr --disable-static" - # - # If you need to set CFLAGS or LDFLAGS, do it here also. - # - # Feel free to add support for other platform specific compilers in this - # directory (e.g. solaris.mk + changes here to detect the platform). - # - CONFIG_FILE := unix.mk - setup: unix.mk - unix: setup - # If `devel' is the requested target, use `-g -O0' as the default value - # for CFLAGS if CFLAGS isn't set. + # If `devel' is the requested target, we use a special configuration + # file named "unix-dev.mk". It disables optimization and libtool.. # ifneq ($(findstring devel,$(MAKECMDGOALS)),) - ifndef CFLAGS - USE_CFLAGS := CFLAGS="-g -O0" - endif + CONFIG_FILE := unix-dev.mk devel: setup + else + # If a Unix platform is detected, the configure script is called and + # `unix.mk' is created. + # + # Arguments to `configure' should be in the CFG variable. Example: + # + # make CFG="--prefix=/usr --disable-static" + # + # If you need to set CFLAGS or LDFLAGS, do it here also. + # + # Feel free to add support for other platform specific compilers in this + # directory (e.g. solaris.mk + changes here to detect the platform). + # + CONFIG_FILE := unix.mk + setup: unix.mk + unix: setup endif setup: std_setup diff --git a/builds/unix/ftsystem.c b/builds/unix/ftsystem.c index 9ecd95c7d..cb9ce8bfd 100644 --- a/builds/unix/ftsystem.c +++ b/builds/unix/ftsystem.c @@ -302,5 +302,21 @@ return memory; } + /*************************************************************************/ + /* */ + /* */ + /* FT_Done_Memory */ + /* */ + /* */ + /* Discards memory manager. */ + /* */ + /* */ + /* memory :: handle to memory manager */ + /* */ + FT_EXPORT_FUNC( void ) FT_Done_Memory( FT_Memory memory ) + { + free( memory ); + } + /* END */ diff --git a/builds/unix/unix-dev.mk b/builds/unix/unix-dev.mk new file mode 100644 index 000000000..6f24a589a --- /dev/null +++ b/builds/unix/unix-dev.mk @@ -0,0 +1,140 @@ +# +# FreeType 2 Configuration rules for Unix + GCC +# +# Development version without optimizations & libtool +# + + +# Copyright 1996-2000 by +# David Turner, Robert Wilhelm, and Werner Lemberg. +# +# This file is part of the FreeType project, and may only be used, modified, +# and distributed under the terms of the FreeType project license, +# LICENSE.TXT. By continuing to use, modify, or distribute this file you +# indicate that you have read the license and understand and accept it +# fully. +# +# NOTE: This version requires that GNU Make is invoked from the Windows +# Shell (_not_ Cygwin BASH)! +# + +ifndef TOP + TOP := . +endif + +DELETE := rm -f +SEP := / +HOSTSEP := $(SEP) +BUILD := $(TOP)/builds/unix +PLATFORM := unixdev # do not set it to "unix", or libtool will trick you.. +CC := gcc + +# The directory where all object files are placed. +# +# Note that this is not $(TOP)/obj! +# This lets you build the library in your own directory with something like +# +# set TOP=.../path/to/freetype2/top/dir... +# mkdir obj +# make -f %TOP%/Makefile setup [options] +# make -f %TOP%/Makefile +# +OBJ_DIR := obj + + +# The directory where all library files are placed. +# +# By default, this is the same as $(OBJ_DIR), however, this can be changed +# to suit particular needs. +# +LIB_DIR := $(OBJ_DIR) + + +# The object file extension (for standard and static libraries). This can be +# .o, .tco, .obj, etc., depending on the platform. +# +O := o +SO := o + +# The library file extension (for standard and static libraries). This can +# be .a, .lib, etc., depending on the platform. +# +A := a +SA := a + + +# The name of the final library file. Note that the DOS-specific Makefile +# uses a shorter (8.3) name. +# +LIBRARY := libfreetype + + +# Path inclusion flag. Some compilers use a different flag than `-I' to +# specify an additional include path. Examples are `/i=' or `-J'. +# +I := -I + + +# C flag used to define a macro before the compilation of a given source +# object. Usually is `-D' like in `-DDEBUG'. +# +D := -D + + +# The link flag used to specify a given library file on link. Note that +# this is only used to compile the demo programs, not the library itself. +# +L := -l + + +# Target flag. +# +T := -o # Don't remove this comment line! We need the space after `-o'. + + +# C flags +# +# These should concern: debug output, optimization & warnings. +# +# Use the ANSIFLAGS variable to define the compiler flags used to enfore +# ANSI compliance. +# +ifndef CFLAGS + CFLAGS := -c -g -O0 -Wall -W +endif + +# ANSIFLAGS: Put there the flags used to make your compiler ANSI-compliant. +# +ANSIFLAGS := -ansi -pedantic + + +ifdef BUILD_FREETYPE + + # Now include the main sub-makefile. It contains all the rules used to + # build the library with the previous variables defined. + # + include $(TOP)/builds/freetype.mk + + # The cleanup targets. + # + clean_freetype: clean_freetype_std + distclean_freetype: distclean_freetype_std + + # Librarian to use to build the static library + # + FT_LIBRARIAN := $(AR) -r + + + # This final rule is used to link all object files into a single library. + # It is part of the system-specific sub-Makefile because not all + # librarians accept a simple syntax like + # + # librarian library_file {list of object files} + # + $(FT_LIBRARY): $(OBJECTS_LIST) + -$(DELETE) $(subst $(SEP),$(HOSTSEP),$(FT_LIBRARY)) 2> nul + $(FT_LIBRARIAN) $@ $(OBJECTS_LIST) + +endif + +# EOF diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h index 0d0f5d80a..05b8dcfbf 100644 --- a/include/freetype/internal/ftobjs.h +++ b/include/freetype/internal/ftobjs.h @@ -506,6 +506,7 @@ FT_EXPORT_DEF( FT_Memory ) FT_New_Memory( void ); + FT_EXPORT_DEF( void ) FT_Done_Memory( FT_Memory memory ); #endif /* !FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM */ diff --git a/src/autohint/ahglyph.c b/src/autohint/ahglyph.c index 7e0ad471e..2037f42b7 100644 --- a/src/autohint/ahglyph.c +++ b/src/autohint/ahglyph.c @@ -322,10 +322,13 @@ outline->max_contours = new_contours; } - /* then, realloc the points, segments & edges arrays if needed */ - if ( num_points > outline->max_points ) + /* then, realloc the points, segments & edges arrays if needed */ + /* note that we reserved two additional point positions, used to */ + /* hint metrics appropriately.. */ + /* */ + if ( num_points+2 > outline->max_points ) { - FT_Int news = ( num_points + 7 ) & -8; + FT_Int news = ( num_points+2 + 7 ) & -8; FT_Int max = outline->max_points; diff --git a/src/base/ftinit.c b/src/base/ftinit.c index cc754eb85..cba8f7c02 100644 --- a/src/base/ftinit.c +++ b/src/base/ftinit.c @@ -152,4 +152,38 @@ const FT_Module_Class* ft_default_modules[] = } + /*************************************************************************/ + /* */ + /* */ + /* FT_Done_FreeType */ + /* */ + /* */ + /* Destroys a given FreeType library object and all of its childs, */ + /* including resources, drivers, faces, sizes, etc. */ + /* */ + /* */ + /* library :: A handle to the target library object. */ + /* */ + /* */ + /* FreeType error code. 0 means success. */ + /* */ + FT_EXPORT_FUNC( FT_Error ) FT_Done_FreeType( FT_Library library ) + { + if (library) + { + FT_Memory memory = library->memory; + + + /* Discard the library object */ + FT_Done_Library( library ); + + /* discard memory manager */ + FT_Done_Memory( memory ); + } + + return FT_Err_Ok; + } + + + /* END */ diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index de7488255..3ddd5c7af 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -265,8 +265,10 @@ } else if ( args->flags & ft_open_stream && args->stream ) { - *stream = *(args->stream); - stream->memory = memory; + /* in this case, we do not need to allocate a new stream */ + /* object. The caller is responsible for closing it himself!! */ + FREE(stream); + stream = args->stream; } else error = FT_Err_Invalid_Argument; @@ -300,16 +302,19 @@ static - void ft_done_stream( FT_Stream* astream ) + void ft_done_stream( FT_Stream* astream, FT_Int external ) { FT_Stream stream = *astream; - FT_Memory memory = stream->memory; if ( stream->close ) stream->close( stream ); - FREE( stream ); + if (!external) + { + FT_Memory memory = stream->memory; + FREE( stream ); + } *astream = 0; } @@ -1146,8 +1151,8 @@ clazz->done_face( face ); /* close the stream for this face if needed */ - if ( ( face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) == 0 ) - ft_done_stream( &face->stream ); + ft_done_stream( &face->stream, + (face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM) != 0 ); /* get rid of it */ FREE( face ); @@ -1392,7 +1397,7 @@ FT_Stream stream; FT_Face face = 0; FT_ListNode node = 0; - + FT_Bool external_stream; /* test for valid `library' and `args' delayed to */ /* ft_new_input_stream() */ @@ -1402,6 +1407,8 @@ *aface = 0; + external_stream = ( args->flags & ft_open_stream && args->stream ); + /* create input stream */ error = ft_new_input_stream( library, args, &stream ); if ( error ) @@ -1436,7 +1443,7 @@ else error = FT_Err_Invalid_Handle; - ft_done_stream( &stream ); + ft_done_stream( &stream, external_stream ); goto Fail; } else @@ -1473,7 +1480,7 @@ } } - ft_done_stream( &stream ); + ft_done_stream( &stream, external_stream ); /* no driver is able to handle this format */ error = FT_Err_Unknown_File_Format; @@ -1484,7 +1491,7 @@ FT_TRACE4(( "FT_New_Face: New face object, adding to list\n" )); /* set the FT_FACE_FLAG_EXTERNAL_STREAM bit for FT_Done_Face */ - if ( args->flags & ft_open_stream && args->stream ) + if ( external_stream ) face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM; /* add the face object to its driver's list */ @@ -1654,8 +1661,9 @@ error = clazz->attach_file( face, stream ); /* close the attached stream */ - if ( !parameters->stream || ( parameters->flags & ft_open_stream ) ) - ft_done_stream( &stream ); + ft_done_stream( &stream, + (FT_Bool)(parameters->stream && + (parameters->flags & ft_open_stream)) ); Exit: return error; @@ -3217,30 +3225,4 @@ } - /*************************************************************************/ - /* */ - /* */ - /* FT_Done_FreeType */ - /* */ - /* */ - /* Destroys a given FreeType library object and all of its childs, */ - /* including resources, drivers, faces, sizes, etc. */ - /* */ - /* */ - /* library :: A handle to the target library object. */ - /* */ - /* */ - /* FreeType error code. 0 means success. */ - /* */ - FT_EXPORT_FUNC( FT_Error ) FT_Done_FreeType( FT_Library library ) - { - /* test for valid `library' delayed to FT_Done_Library() */ - - /* Discard the library object */ - FT_Done_Library( library ); - - return FT_Err_Ok; - } - - /* END */ diff --git a/src/base/ftsystem.c b/src/base/ftsystem.c index b99b0eaae..52167b014 100644 --- a/src/base/ftsystem.c +++ b/src/base/ftsystem.c @@ -296,4 +296,20 @@ } + /*************************************************************************/ + /* */ + /* */ + /* FT_Done_Memory */ + /* */ + /* */ + /* Discards memory manager. */ + /* */ + /* */ + /* memory :: handle to memory manager */ + /* */ + FT_EXPORT_FUNC( void ) FT_Done_Memory( FT_Memory memory ) + { + free( memory ); + } + /* END */ diff --git a/src/psnames/psnames.c b/src/psnames/psnames.c index 0491b4814..034412965 100644 --- a/src/psnames/psnames.c +++ b/src/psnames/psnames.c @@ -18,7 +18,7 @@ #define FT_MAKE_OPTION_SINGLE_OBJECT -#include +#include /* END */ diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c index 6823cb12f..afdc157f4 100644 --- a/src/truetype/ttgload.c +++ b/src/truetype/ttgload.c @@ -539,6 +539,8 @@ FT_Error error = FT_Err_Ok; + FT_UNUSED(debug); /* used by truetype interpreter only */ + n_ins = load->glyph->control_len; /* add shadow points */ @@ -674,7 +676,8 @@ FT_GlyphLoader* gloader = loader->gloader; FT_Bool opened_frame = 0; - + FT_UNUSED(stream); /* used with bytecode interpreter only */ + /* check glyph index */ index = glyph_index; if ( index >= (FT_UInt)face->root.num_glyphs ) diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c index b47736638..01685f22d 100644 --- a/src/truetype/ttobjs.c +++ b/src/truetype/ttobjs.c @@ -143,7 +143,6 @@ return error; } - #endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ @@ -730,7 +729,8 @@ TT_Destroy_Context( driver->context, driver->root.root.memory ); driver->context = NULL; } - +#else + FT_UNUSED(driver); #endif } diff --git a/src/truetype/ttobjs.h b/src/truetype/ttobjs.h index bb00d08bf..8f0759de9 100644 --- a/src/truetype/ttobjs.h +++ b/src/truetype/ttobjs.h @@ -119,6 +119,7 @@ #endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */ + /*************************************************************************/ /* */ /* EXECUTION SUBTABLES */