freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ft-devel] FT_Init_FreeType allocating memory before I get a chance to s


From: Tom van Dijck
Subject: [ft-devel] FT_Init_FreeType allocating memory before I get a chance to set the allocators.
Date: Sun, 21 Jun 2009 12:08:23 -0700

Hey,

Forgive me if this is the wrong address to mail to, or if I should have simply filed this as a bug.

The Freetype library allows you to set the malloc/free/realloc methods in case you want to override the default behavior...
Normally this is done at least as far as I'm aware by getting the FT_Memory handle, and set the alloc, realloc and free function pointers....

This is awesome, however FT_Init_FreeType is creating that structure by calling alloc, which is not so awesome, because I want to control ALL memory..

both FT_New_Memory, and FT_New_Library (functions called within FT_Init_FreeType) are allocating memory, before I have a chance of setting the function pointers in FT_Memory..
To get around that I added an extra argument to the FT_Init_FreeType, which allows me to provide an FT_Memory structure, before any other freetype code is running.

I locally changed FT_Init_FreeType to:

  FT_EXPORT_DEF( FT_Error )
  FT_Init_FreeType(FT_Library* alibrary, FT_Memory amemory)
  {
      FT_Error   error;

      /* build a library out of it, then fill it with the set of */
      /* default drivers.                                        */

      error = FT_New_Library( amemory, alibrary );
      if ( error )
      {
          return error;
      }

      (*alibrary)->version_major = FREETYPE_MAJOR;
      (*alibrary)->version_minor = FREETYPE_MINOR;
      (*alibrary)->version_patch = FREETYPE_PATCH;
      FT_Add_Default_Modules( *alibrary );
      return error;
  }

  FT_EXPORT_DEF( FT_Error )
  FT_Done_FreeType( FT_Library  library )
  {
      if ( library )
      {
          /* Discard the library object */
          FT_Done_Library( library );
      }
      return FT_Err_Ok;
  }


this serves my purpose, but is obviously not backwards compatible, so a mix of this and old would be required if backwards compatibility is a requirement...
or you can just ignore me, and I'll keep making the change locally, I just thought this was good to report.

Tom.


PS: redefining
    #define ft_scalloc   calloc
    #define ft_sfree     free
    #define ft_smalloc   malloc
   #define ft_srealloc  realloc
is not a valid option, since that would require me to include header files that have no relationship with freetype, and thus would add dependencies on a library that has nothing to do with freetype.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]