📄 ftobjs.c
字号:
/***************************************************************************//* *//* ftobjs.c *//* *//* The FreeType private base classes (base). *//* *//* 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. *//* *//***************************************************************************/#include <ftobjs.h>#include <ftlist.h>#include <ftdebug.h>#include <ftstream.h> /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /**** ****/ /**** ****/ /**** M E M O R Y ****/ /**** ****/ /**** ****/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /* */ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ /* messages during execution. */ /* */#undef FT_COMPONENT#define FT_COMPONENT trace_memory /*************************************************************************/ /* */ /* <Function> */ /* FT_Alloc */ /* */ /* <Description> */ /* Allocates a new block of memory. The returned area is always */ /* zero-filled; this is a strong convention in many FreeType parts. */ /* */ /* <Input> */ /* memory :: A handle to a given `memory object' where allocation */ /* occurs. */ /* */ /* size :: The size in bytes of the block to allocate. */ /* */ /* <Output> */ /* P :: A pointer to the fresh new block. It should be set to */ /* NULL if `size' is 0, or in case of error. */ /* */ /* <Return> */ /* FreeType error code. 0 means success. */ /* */ BASE_FUNC FT_Error FT_Alloc( FT_Memory memory, FT_Long size, void** P ) { FT_Assert( P != 0 ); if ( size > 0 ) { *P = memory->alloc( memory, size ); if ( !*P ) { FT_ERROR(( "FT.Alloc:" )); FT_ERROR(( " Out of memory? (%ld requested)\n", size )); return FT_Err_Out_Of_Memory; } MEM_Set( *P, 0, size ); } else *P = NULL; FT_TRACE2(( "FT_Alloc:" )); FT_TRACE2(( " size = %ld, block = 0x%08lx, ref = 0x%08lx\n", size, (long)*P, (long)P )); return FT_Err_Ok; } /*************************************************************************/ /* */ /* <Function> */ /* FT_Realloc */ /* */ /* <Description> */ /* Reallocates a block of memory pointed to by `*P' to `Size' bytes */ /* from the heap, possibly changing `*P'. */ /* */ /* <Input> */ /* memory :: A handle to a given `memory object' where allocation */ /* occurs. */ /* */ /* current :: The current block size in bytes. */ /* size :: The new block size in bytes. */ /* */ /* <InOut> */ /* P :: A pointer to the fresh new block. It should be set to */ /* NULL if `size' is 0, or in case of error. */ /* */ /* <Return> */ /* FreeType error code. 0 means success. */ /* */ /* <Note> */ /* All callers of FT_Realloc() _must_ provide the current block size */ /* as well as the new one. */ /* */ /* If the memory object's flag FT_SYSTEM_FLAG_NO_REALLOC is set, this */ /* function will try to emulate a reallocation using FT_Alloc() and */ /* FT_Free(). Otherwise, it will call the system-specific `realloc' */ /* implementation. */ /* */ /* (Some embedded systems do not have a working realloc function). */ /* */ BASE_FUNC FT_Error FT_Realloc( FT_Memory memory, FT_Long current, FT_Long size, void** P ) { void* Q; FT_Assert( P != 0 ); /* if the original pointer is NULL, call FT_Alloc() */ if ( !*P ) return FT_Alloc( memory, size, P ); /* if the new block if zero-sized, clear the current one */ if ( size <= 0 ) { FT_Free( memory, P ); return FT_Err_Ok; } Q = memory->realloc( memory, current, size, *P ); if ( !Q ) goto Fail; *P = Q; return FT_Err_Ok; Fail: FT_ERROR(( "FT.Realloc:" )); FT_ERROR(( " Failed (current %ld, requested %ld)\n", current, size )); return FT_Err_Out_Of_Memory; } /*************************************************************************/ /* */ /* <Function> */ /* FT_Free */ /* */ /* <Description> */ /* Releases a given block of memory allocated through FT_Alloc(). */ /* */ /* <Input> */ /* memory :: A handle to a given `memory object' where allocation */ /* occurred. */ /* */ /* P :: This is the _address_ of a _pointer_ which points to the */ /* allocated block. It is always set to NULL on exit. */ /* */ /* <Return> */ /* FreeType error code. 0 means success. */ /* */ /* <Note> */ /* If P or *P are NULL, this function should return successfully. */ /* This is a strong convention within all of FreeType and its */ /* drivers. */ /* */ BASE_FUNC void FT_Free( FT_Memory memory, void** P ) { FT_TRACE2(( "FT_Free:" )); FT_TRACE2(( " Freeing block 0x%08lx, ref 0x%08lx\n", (long)P, (P ? (long)*P : -1) )); FT_Assert( P != 0 ); if ( *P ) { memory->free( memory, *P ); *P = 0; } } /*************************************************************************/ /* */ /* <Function> */ /* ft_new_input_stream */ /* */ /* <Description> */ /* Creates a new input stream object from an FT_Open_Args structure. */ /* */ static FT_Error ft_new_input_stream( FT_Library library, FT_Open_Args* args, FT_Stream* astream ) { FT_Error error; FT_Memory memory; FT_Stream stream; memory = library->memory; if ( ALLOC( stream, sizeof ( *stream ) ) ) return error; stream->memory = memory; /* is it a memory stream? */ if ( args->memory_base && args->memory_size ) FT_New_Memory_Stream( library, args->memory_base, args->memory_size, stream ); /* do we have an 8-bit pathname? */ else if ( args->pathname ) { error = FT_New_Stream( args->pathname, stream ); stream->pathname.pointer = args->pathname; } /* do we have a custom stream? */ else if ( args->stream ) { /* copy the contents of the argument stream */ /* into the new stream object */ *stream = *(args->stream); stream->memory = memory; } else error = FT_Err_Invalid_Argument; if ( error ) FREE( stream ); *astream = stream; return error; } /*************************************************************************/ /* */ /* <Function> */ /* ft_done_stream */ /* */ /* <Description> */ /* Closes and destroys a stream object. */ /* */ static void ft_done_stream( FT_Stream* astream ) { FT_Stream stream = *astream; FT_Memory memory = stream->memory; if ( stream->close ) stream->close( stream ); FREE( stream ); *astream = 0; } /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ /**** ****/ /**** ****/ /**** O B J E C T M A N A G E M E N T ****/ /**** ****/ /**** ****/ /*************************************************************************/ /*************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -