Commit 226f3619750ff34ca698304f1d009d0abdcf720e

suzuki toshiya 2012-01-14T06:40:03

Fix PIC build broken by d9145241fe378104ba4c12a42534549faacc92e6. Under PIC configuration, FT_{CFF,PSCMAPS,SFNT,TT}_SERVICES_GET take no arguments but derefer the variable named `library' internally. * src/cff/cffdrivr.c (cff_get_interface): Declare `library' and set it if non-NULL driver is passed. * src/truetype/ttdriver.c (tt_get_interface): Ditto. * src/sfnt/sfdriver.c (sfnt_get_interface): Declare `library' under PIC configuration, and set it if non-NULL module is given. * src/psnames/psmodule.c (psnames_get_interface): Ditto.

diff --git a/ChangeLog b/ChangeLog
index 77bc180..6c0a3b4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2012-01-13  suzuki toshiya  <mpsuzuki@hiroshima-u.ac.jp>
 
+	Fix PIC build broken by d9145241fe378104ba4c12a42534549faacc92e6.
+
+	Under PIC configuration, FT_{CFF,PSCMAPS,SFNT,TT}_SERVICES_GET
+	take no arguments but derefer the variable named `library'
+	internally.
+
+	* src/cff/cffdrivr.c (cff_get_interface): Declare `library' and
+	set it if non-NULL driver is passed.
+	* src/truetype/ttdriver.c (tt_get_interface): Ditto.
+
+	* src/sfnt/sfdriver.c (sfnt_get_interface): Declare `library'
+	under PIC configuration, and set it if non-NULL module is given.
+	* src/psnames/psmodule.c (psnames_get_interface): Ditto.
+
+2012-01-13  suzuki toshiya  <mpsuzuki@hiroshima-u.ac.jp>
+
 	Make PIC files to include module error headers, to use the
 	error codes with per-module prefix.
 
diff --git a/src/cff/cffdrivr.c b/src/cff/cffdrivr.c
index 61ab705..49453f1 100644
--- a/src/cff/cffdrivr.c
+++ b/src/cff/cffdrivr.c
@@ -599,19 +599,35 @@
   cff_get_interface( FT_Module    driver,       /* CFF_Driver */
                      const char*  module_interface )
   {
+    FT_Library           library;
     FT_Module            sfnt;
     FT_Module_Interface  result;
 
 
+    /* FT_CFF_SERVICES_GET derefers `library' in PIC mode */
+#ifdef FT_CONFIG_OPTION_PIC
+    if ( !driver )
+      return NULL;
+    library = driver->library;
+    if ( !library )
+      return NULL;
+#endif
+
     result = ft_service_list_lookup( FT_CFF_SERVICES_GET, module_interface );
     if ( result != NULL )
-      return  result;
+      return result;
 
+    /* `driver' is not yet evaluated in non-PIC mode */
+#ifndef FT_CONFIG_OPTION_PIC
     if ( !driver )
       return NULL;
+    library = driver->library;
+    if ( !library )
+      return NULL;
+#endif
 
     /* we pass our request to the `sfnt' module */
-    sfnt = FT_Get_Module( driver->library, "sfnt" );
+    sfnt = FT_Get_Module( library, "sfnt" );
 
     return sfnt ? sfnt->clazz->get_interface( sfnt, module_interface ) : 0;
   }
diff --git a/src/psnames/psmodule.c b/src/psnames/psmodule.c
index 7528696..2577382 100644
--- a/src/psnames/psmodule.c
+++ b/src/psnames/psmodule.c
@@ -563,7 +563,19 @@
   psnames_get_service( FT_Module    module,
                        const char*  service_id )
   {
+    /* FT_PSCMAPS_SERVICES_GET derefers `library' in PIC mode */
+#ifdef FT_CONFIG_OPTION_PIC
+    FT_Library  library;
+
+
+    if ( !module )
+      return NULL;
+    library = module->library;
+    if ( !library )
+      return NULL;
+#else
     FT_UNUSED( module );
+#endif
 
     return ft_service_list_lookup( FT_PSCMAPS_SERVICES_GET, service_id );
   }
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index 17ef310..fadb15b 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -422,8 +422,19 @@
   sfnt_get_interface( FT_Module    module,
                       const char*  module_interface )
   {
-    FT_UNUSED( module );
+    /* FT_SFNT_SERVICES_GET derefers `library' in PIC mode */
+#ifdef FT_CONFIG_OPTION_PIC
+    FT_Library  library;
+
 
+    if ( !module )
+      return NULL;
+    library = module->library;
+    if ( !library ) 
+      return NULL;
+#else
+    FT_UNUSED( module );
+#endif
     return ft_service_list_lookup( FT_SFNT_SERVICES_GET, module_interface );
   }
 
diff --git a/src/truetype/ttdriver.c b/src/truetype/ttdriver.c
index b217197..c30bec2 100644
--- a/src/truetype/ttdriver.c
+++ b/src/truetype/ttdriver.c
@@ -402,19 +402,35 @@
   tt_get_interface( FT_Module    driver,    /* TT_Driver */
                     const char*  tt_interface )
   {
+    FT_Library           library;
     FT_Module_Interface  result;
     FT_Module            sfntd;
     SFNT_Service         sfnt;
 
+
+    /* FT_TT_SERVICES_GET derefers `library' in PIC mode */
+#ifdef FT_CONFIG_OPTION_PIC
+    if ( !driver )
+      return NULL;
+    library = driver->library;
+    if ( !library )
+      return NULL;
+#endif
+
     result = ft_service_list_lookup( FT_TT_SERVICES_GET, tt_interface );
     if ( result != NULL )
       return result;
 
+#ifndef FT_CONFIG_OPTION_PIC
     if ( !driver )
       return NULL;
+    library = driver->library;
+    if ( !library )
+      return NULL;
+#endif
 
     /* only return the default interface from the SFNT module */
-    sfntd = FT_Get_Module( driver->library, "sfnt" );
+    sfntd = FT_Get_Module( library, "sfnt" );
     if ( sfntd )
     {
       sfnt = (SFNT_Service)( sfntd->clazz->module_interface );