freetype-devel
[Top][All Lists]
Advanced

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

[ft-devel] Fixes for some compile and link errors when using FT_CONFIG_O


From: Erik Dahlstrom
Subject: [ft-devel] Fixes for some compile and link errors when using FT_CONFIG_OPTION_PIC
Date: Wed, 04 Jan 2012 14:49:09 +0100
User-agent: Opera Mail/11.61 (Linux)

Hello,

I ran into a few issues with the latest release of freetype (2.4.8), and I'd like to provide a couple of patches for your consideration. My patches are included below, if it's more convinient to you, you can also fetch these fixes from my freetype2 repo, https://github.com/erikdahlstrom/freetype2.

The commits in question are both dealing with compilation of 'complex' structures and static globals.


commit c07500d5385bacc4f64a0cbff057b5b2d87c1539
Author: Erik Dahlström <address@hidden>
Date:   Tue Jan 3 17:55:34 2012 +0100

    Complex global variables should be in PIC object.

diff --git a/include/freetype/internal/ftrfork.h b/include/freetype/internal/ftrfork.h
index aa573c8..c6c32e5 100644
--- a/include/freetype/internal/ftrfork.h
+++ b/include/freetype/internal/ftrfork.h
@@ -48,6 +48,48 @@ FT_BEGIN_HEADER

   } FT_RFork_Ref;

+#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
+  typedef FT_Error
+  (*raccess_guess_func)( FT_Library  library,
+                         FT_Stream   stream,
+                         char       *base_file_name,
+                         char      **result_file_name,
+                         FT_Long    *result_offset );
+
+  typedef enum  FT_RFork_Rule_ {
+    FT_RFork_Rule_invalid = -2,
+    FT_RFork_Rule_uknown, /* -1 */
+    FT_RFork_Rule_apple_double,
+    FT_RFork_Rule_apple_single,
+    FT_RFork_Rule_darwin_ufs_export,
+    FT_RFork_Rule_darwin_newvfs,
+    FT_RFork_Rule_darwin_hfsplus,
+    FT_RFork_Rule_vfat,
+    FT_RFork_Rule_linux_cap,
+    FT_RFork_Rule_linux_double,
+    FT_RFork_Rule_linux_netatalk
+  } FT_RFork_Rule;
+
+  /* For fast translation between rule index and rule type,
+   * the macros FT_RFORK_xxx should be kept consistent with
+   * the raccess_guess_funcs table
+   */
+  typedef struct raccess_guess_rec_ {
+    raccess_guess_func  func;
+    FT_RFork_Rule       type;
+  } raccess_guess_rec;
+
+#ifndef FT_CONFIG_OPTION_PIC
+# define CONST_FT_GUESS_REC_ARRAY(name,type) const type name[] = {
+# define CONST_FT_GUESS_REC_ENTRY(func,type) { func, type },
+# define CONST_FT_GUESS_REC_END(func,type)   { func, type } };
+#else /* FT_CONFIG_OPTION_PIC */
+# define CONST_FT_GUESS_REC_ARRAY(name,type) void FT_Init_##name (type *storage) { type *local = storage; int i=0; +# define CONST_FT_GUESS_REC_ENTRY(funci,typei) local[i].func = funci; local[i].type = typei; i++; +# define CONST_FT_GUESS_REC_END(funci,typei) local[i].func = funci; local[i].type = typei; i++; }
+#endif /* FT_CONFIG_OPTION_PIC */
+
+#endif /* FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */

   /*************************************************************************/
/* */
diff --git a/src/base/basepic.c b/src/base/basepic.c
index c0bccb6..97762ce 100644
--- a/src/base/basepic.c
+++ b/src/base/basepic.c
@@ -27,6 +27,9 @@
   void FT_Init_Class_ft_outline_glyph_class(FT_Glyph_Class*);
   void FT_Init_Class_ft_bitmap_glyph_class(FT_Glyph_Class*);

+  /* forward declaration of PIC init function from ftrfork.c */
+  void FT_Init_raccess_guess_table(raccess_guess_rec*);
+
   /* forward declaration of PIC init functions from ftinit.c */
   FT_Error ft_create_default_module_classes(FT_Library);
   void ft_destroy_default_module_classes(FT_Library);
@@ -69,6 +72,7 @@
/* initialize pointer table - this is how the module usually expects this data */
     FT_Init_Class_ft_outline_glyph_class(&container->ft_outline_glyph_class);
     FT_Init_Class_ft_bitmap_glyph_class(&container->ft_bitmap_glyph_class);
+ FT_Init_raccess_guess_table((raccess_guess_rec*)&container->raccess_guess_table);

 Exit:
     if(error)
diff --git a/src/base/basepic.h b/src/base/basepic.h
index bb17745..34cf63a 100644
--- a/src/base/basepic.h
+++ b/src/base/basepic.h
@@ -28,22 +28,36 @@ FT_BEGIN_HEADER
 #define FT_OUTLINE_GLYPH_CLASS_GET &ft_outline_glyph_class
 #define FT_BITMAP_GLYPH_CLASS_GET  &ft_bitmap_glyph_class
 #define FT_DEFAULT_MODULES_GET     ft_default_modules
+#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
+#define FT_RACCESS_GUESS_TABLE_GET   raccess_guess_table
+#endif /* FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */

 #else /* FT_CONFIG_OPTION_PIC */

 #include FT_GLYPH_H

+#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
+#include FT_INTERNAL_RFORK_H
+#endif /* FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */
+
+
   typedef struct BasePIC_
   {
     FT_Module_Class** default_module_classes;
     FT_Glyph_Class ft_outline_glyph_class;
     FT_Glyph_Class ft_bitmap_glyph_class;
+#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
+    raccess_guess_rec raccess_guess_table[FT_RACCESS_N_RULES];
+#endif /* FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */
   } BasePIC;

#define GET_PIC(lib) ((BasePIC*)((lib)->pic_container.base)) #define FT_OUTLINE_GLYPH_CLASS_GET (&GET_PIC(library)->ft_outline_glyph_class) #define FT_BITMAP_GLYPH_CLASS_GET (&GET_PIC(library)->ft_bitmap_glyph_class) #define FT_DEFAULT_MODULES_GET (GET_PIC(library)->default_module_classes)
+#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
+#define FT_RACCESS_GUESS_TABLE_GET (GET_PIC(library)->raccess_guess_table)
+#endif /* FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */

   void
   ft_base_pic_free( FT_Library library );
diff --git a/src/base/ftbase.h b/src/base/ftbase.h
index cb55197..27a12ee 100644
--- a/src/base/ftbase.h
+++ b/src/base/ftbase.h
@@ -57,7 +57,7 @@ FT_BEGIN_HEADER
   /* on Darwin VFS should be grouped and skip the rest methods after   */
   /* the case the resource is opened but found to lack a font in it.   */
   FT_LOCAL( FT_Bool )
-  raccess_rule_by_darwin_vfs( FT_UInt  rule_index );
+  raccess_rule_by_darwin_vfs( FT_Library library, FT_UInt  rule_index );
 #endif


diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 1a5a327..f16ff3e 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -1875,7 +1875,7 @@

     for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
     {
-      is_darwin_vfs = raccess_rule_by_darwin_vfs( i );
+      is_darwin_vfs = raccess_rule_by_darwin_vfs( library, i );
       if ( is_darwin_vfs && vfs_rfork_has_no_font )
       {
         FT_TRACE3(( "Skip rule %d: darwin vfs resource fork"
diff --git a/src/base/ftrfork.c b/src/base/ftrfork.c
index e58d2fc..36157ad 100644
--- a/src/base/ftrfork.c
+++ b/src/base/ftrfork.c
@@ -28,7 +28,7 @@
 #include FT_INTERNAL_DEBUG_H
 #include FT_INTERNAL_STREAM_H
 #include FT_INTERNAL_RFORK_H
-
+#include "basepic.h"

 #undef  FT_COMPONENT
 #define FT_COMPONENT  trace_raccess
@@ -253,14 +253,6 @@
   /*************************************************************************/
   /*************************************************************************/

-  typedef FT_Error
-  (*raccess_guess_func)( FT_Library  library,
-                         FT_Stream   stream,
-                         char       *base_file_name,
-                         char      **result_file_name,
-                         FT_Long    *result_offset );
-
-
   static FT_Error
   raccess_guess_apple_double( FT_Library  library,
                               FT_Stream   stream,
@@ -325,6 +317,18 @@
                                 FT_Long    *result_offset );


+  CONST_FT_GUESS_REC_ARRAY(raccess_guess_table, raccess_guess_rec)
+ CONST_FT_GUESS_REC_ENTRY(raccess_guess_apple_double, FT_RFork_Rule_apple_double) + CONST_FT_GUESS_REC_ENTRY(raccess_guess_apple_single, FT_RFork_Rule_apple_single) + CONST_FT_GUESS_REC_ENTRY(raccess_guess_darwin_ufs_export, FT_RFork_Rule_darwin_ufs_export) + CONST_FT_GUESS_REC_ENTRY(raccess_guess_darwin_newvfs, FT_RFork_Rule_darwin_newvfs) + CONST_FT_GUESS_REC_ENTRY(raccess_guess_darwin_hfsplus, FT_RFork_Rule_darwin_hfsplus)
+  CONST_FT_GUESS_REC_ENTRY(raccess_guess_vfat, FT_RFork_Rule_vfat)
+ CONST_FT_GUESS_REC_ENTRY(raccess_guess_linux_cap, FT_RFork_Rule_linux_cap) + CONST_FT_GUESS_REC_ENTRY(raccess_guess_linux_double, FT_RFork_Rule_linux_double) + CONST_FT_GUESS_REC_END(raccess_guess_linux_netatalk, FT_RFork_Rule_linux_netatalk)
+
+
   /*************************************************************************/
/**** ****/ /**** Helper functions ****/
@@ -349,42 +353,6 @@
                           const char  *insertion );


-  typedef enum  FT_RFork_Rule_ {
-    FT_RFork_Rule_invalid = -2,
-    FT_RFork_Rule_uknown, /* -1 */
-    FT_RFork_Rule_apple_double,
-    FT_RFork_Rule_apple_single,
-    FT_RFork_Rule_darwin_ufs_export,
-    FT_RFork_Rule_darwin_newvfs,
-    FT_RFork_Rule_darwin_hfsplus,
-    FT_RFork_Rule_vfat,
-    FT_RFork_Rule_linux_cap,
-    FT_RFork_Rule_linux_double,
-    FT_RFork_Rule_linux_netatalk
-  } FT_RFork_Rule;
-
-  /* For fast translation between rule index and rule type,
-   * the macros FT_RFORK_xxx should be kept consistent with
-   * the raccess_guess_funcs table
-   */
-  typedef struct raccess_guess_rec_ {
-    raccess_guess_func  func;
-    FT_RFork_Rule       type;
-  } raccess_guess_rec;
-
-  static raccess_guess_rec  raccess_guess_table[FT_RACCESS_N_RULES] =
-  {
-    { raccess_guess_apple_double,      FT_RFork_Rule_apple_double, },
-    { raccess_guess_apple_single,      FT_RFork_Rule_apple_single, },
-    { raccess_guess_darwin_ufs_export, FT_RFork_Rule_darwin_ufs_export, },
-    { raccess_guess_darwin_newvfs,     FT_RFork_Rule_darwin_newvfs, },
-    { raccess_guess_darwin_hfsplus,    FT_RFork_Rule_darwin_hfsplus, },
-    { raccess_guess_vfat,              FT_RFork_Rule_vfat, },
-    { raccess_guess_linux_cap,         FT_RFork_Rule_linux_cap, },
-    { raccess_guess_linux_double,      FT_RFork_Rule_linux_double, },
-    { raccess_guess_linux_netatalk,    FT_RFork_Rule_linux_netatalk, },
-  };
-
   FT_BASE_DEF( void )
   FT_Raccess_Guess( FT_Library  library,
                     FT_Stream   stream,
@@ -407,7 +375,7 @@
       if ( errors[i] )
         continue ;

-      errors[i] = (raccess_guess_table[i].func)( library,
+      errors[i] = (FT_RACCESS_GUESS_TABLE_GET[i].func)( library,
                                                  stream, base_name,
                                                  &(new_names[i]),
                                                  &(offsets[i]) );
@@ -419,19 +387,19 @@

 #ifndef FT_MACINTOSH
   static FT_RFork_Rule
-  raccess_get_rule_type_from_rule_index( FT_UInt  rule_index )
+ raccess_get_rule_type_from_rule_index( FT_Library library, FT_UInt rule_index )
   {
     if ( rule_index >= FT_RACCESS_N_RULES )
       return FT_RFork_Rule_invalid;

-    return raccess_guess_table[rule_index].type;
+    return FT_RACCESS_GUESS_TABLE_GET[rule_index].type;
   }


   FT_LOCAL_DEF( FT_Bool )
-  raccess_rule_by_darwin_vfs( FT_UInt  rule_index )
+  raccess_rule_by_darwin_vfs( FT_Library library, FT_UInt  rule_index )
   {
-    switch( raccess_get_rule_type_from_rule_index( rule_index ) )
+    switch( raccess_get_rule_type_from_rule_index( library, rule_index ) )
     {
       case FT_RFork_Rule_darwin_newvfs:
       case FT_RFork_Rule_darwin_hfsplus:




commit 44fc92c26ef4f6e5149795e22cb41e1ae177a723
Author: Erik Dahlström <address@hidden>
Date:   Tue Jan 3 18:00:06 2012 +0100

Certain linkers are incapable of handling static arrays that contain strings.

diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index f16ff3e..340e4d5 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -4533,7 +4533,9 @@
      */
     {
       FT_UInt      m, n;
-      const char*  driver_name[] = { "type42", NULL };
+      const char*  driver_name[2];
+         driver_name[0] = "type42";
+         driver_name[1] = NULL;


       for ( m = 0;


Thanks
--
Erik Dahlstrom, Core Technology Developer, Opera Software
Co-Chair, W3C SVG Working Group
Personal blog: http://my.opera.com/macdev_ed



reply via email to

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