From ce33a312daca1944e61a11c4e7522d37f4da4f4d Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Sun, 21 Dec 2008 10:29:30 +0000 Subject: [PATCH] FT_USE_MODULE declares things as: extern const FT_Module_Class (or similar for C++). However, the actual types of the variables being declared are often different, e.g., FT_Driver_ClassRec or FT_Renderer_Class. (Some are, indeed, FT_Module_Class.) This works with most C compilers (since those structs begin with an FT_Module_Class struct), but technically it's undefined behavior. To quote the ISO/IEC 9899:TC2 final committee draft, section 6.2.7 paragraph 2: All declarations that refer to the same object or function shall have compatible type; otherwise, the behavior is undefined. (And they are not compatible types.) Most C compilers don't reject (or even detect!) code which has this issue, but the GCC LTO development branch compiler does. (It outputs the types of the objects while generating .o files, along with a bunch of other information, then compares them when doing the final link-time code generation pass.) Patch from Savannah bug #25133. * src/base/ftinit.c (FT_USE_MODULE): Include variable type. * builds/amiga/include/freetype/config/ftmodule.h, include/freetype/config/ftmodule.h, */module.mk: Updated to declare pass correct types to FT_USE_MODULE. --- ChangeLog | 38 +++++++++++++++++- .../amiga/include/freetype/config/ftmodule.h | 40 +++++++++---------- include/freetype/config/ftmodule.h | 36 ++++++++--------- src/autofit/module.mk | 2 +- src/base/ftinit.c | 6 +-- src/bdf/module.mk | 2 +- src/cff/module.mk | 2 +- src/cid/module.mk | 2 +- src/gxvalid/module.mk | 2 +- src/otvalid/module.mk | 2 +- src/pcf/module.mk | 2 +- src/pfr/module.mk | 2 +- src/psaux/module.mk | 2 +- src/pshinter/module.mk | 2 +- src/psnames/module.mk | 2 +- src/raster/module.mk | 2 +- src/sfnt/module.mk | 2 +- src/smooth/module.mk | 6 +-- src/truetype/module.mk | 2 +- src/type1/module.mk | 2 +- src/type42/module.mk | 2 +- src/winfonts/module.mk | 2 +- 22 files changed, 98 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index 233623223..7092d8438 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,44 @@ +2008-12-21 anonymous + + FT_USE_MODULE declares things as: + + extern const FT_Module_Class + + (or similar for C++). However, the actual types of the variables + being declared are often different, e.g., FT_Driver_ClassRec or + FT_Renderer_Class. (Some are, indeed, FT_Module_Class.) + + This works with most C compilers (since those structs begin with an + FT_Module_Class struct), but technically it's undefined behavior. + + To quote the ISO/IEC 9899:TC2 final committee draft, section 6.2.7 + paragraph 2: + + All declarations that refer to the same object or function shall + have compatible type; otherwise, the behavior is undefined. + + (And they are not compatible types.) + + Most C compilers don't reject (or even detect!) code which has this + issue, but the GCC LTO development branch compiler does. (It + outputs the types of the objects while generating .o files, along + with a bunch of other information, then compares them when doing the + final link-time code generation pass.) + + Patch from Savannah bug #25133. + + * src/base/ftinit.c (FT_USE_MODULE): Include variable type. + + * builds/amiga/include/freetype/config/ftmodule.h, + include/freetype/config/ftmodule.h, */module.mk: Updated to declare + pass correct types to FT_USE_MODULE. + 2008-12-21 Hongbo Ni * src/autofit/aflatin.c (af_latin_hint_edges), src/autofit/aflatin2.c (af_latin2_hint_edges), src/autofit/afcjk.c - (af_cjk_hint_edges): Protect against division by zero. + (af_cjk_hint_edges): Protect against division by zero. This fixes + Savannah bug #25124. 2008-12-18 Werner Lemberg diff --git a/builds/amiga/include/freetype/config/ftmodule.h b/builds/amiga/include/freetype/config/ftmodule.h index c8a5bee22..5873bab74 100644 --- a/builds/amiga/include/freetype/config/ftmodule.h +++ b/builds/amiga/include/freetype/config/ftmodule.h @@ -80,77 +80,77 @@ /* Now include the modules */ #ifdef FT_USE_AUTOFIT -FT_USE_MODULE(autofit_module_class) +FT_USE_MODULE( FT_Module_Class, autofit_module_class ) #endif #ifdef FT_USE_TT -FT_USE_MODULE(tt_driver_class) +FT_USE_MODULE( FT_Driver_ClassRec, tt_driver_class ) #endif #ifdef FT_USE_T1 -FT_USE_MODULE(t1_driver_class) +FT_USE_MODULE( FT_Driver_ClassRec, t1_driver_class ) #endif #ifdef FT_USE_CFF -FT_USE_MODULE(cff_driver_class) +FT_USE_MODULE( FT_Driver_ClassRec, cff_driver_class ) #endif #ifdef FT_USE_T1CID -FT_USE_MODULE(t1cid_driver_class) +FT_USE_MODULE( FT_Driver_ClassRec, t1cid_driver_class ) #endif #ifdef FT_USE_PFR -FT_USE_MODULE(pfr_driver_class) +FT_USE_MODULE( FT_Driver_ClassRec, pfr_driver_class ) #endif #ifdef FT_USE_T42 -FT_USE_MODULE(t42_driver_class) +FT_USE_MODULE( FT_Driver_ClassRec, t42_driver_class ) #endif #ifdef FT_USE_WINFNT -FT_USE_MODULE(winfnt_driver_class) +FT_USE_MODULE( FT_Driver_ClassRec, winfnt_driver_class ) #endif #ifdef FT_USE_PCF -FT_USE_MODULE(pcf_driver_class) +FT_USE_MODULE( FT_Driver_ClassRec, pcf_driver_class ) #endif #ifdef FT_USE_PSAUX -FT_USE_MODULE(psaux_module_class) +FT_USE_MODULE( FT_Module_Class, psaux_module_class ) #endif #ifdef FT_USE_PSNAMES -FT_USE_MODULE(psnames_module_class) +FT_USE_MODULE( FT_Module_Class, psnames_module_class ) #endif #ifdef FT_USE_PSHINT -FT_USE_MODULE(pshinter_module_class) +FT_USE_MODULE( FT_Module_Class, pshinter_module_class ) #endif #ifdef FT_USE_RASTER -FT_USE_MODULE(ft_raster1_renderer_class) +FT_USE_MODULE( FT_Renderer_Class, ft_raster1_renderer_class ) #endif #ifdef FT_USE_SFNT -FT_USE_MODULE(sfnt_module_class) +FT_USE_MODULE( FT_Module_Class, sfnt_module_class ) #endif #ifdef FT_USE_SMOOTH -FT_USE_MODULE(ft_smooth_renderer_class) -FT_USE_MODULE(ft_smooth_lcd_renderer_class) -FT_USE_MODULE(ft_smooth_lcdv_renderer_class) +FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcd_renderer_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcdv_renderer_class ) #endif #ifdef FT_USE_OTV -FT_USE_MODULE(otv_module_class) +FT_USE_MODULE( FT_Module_Class, otv_module_class ) #endif #ifdef FT_USE_BDF -FT_USE_MODULE(bdf_driver_class) +FT_USE_MODULE( FT_Driver_ClassRec, bdf_driver_class ) #endif #ifdef FT_USE_GXV -FT_USE_MODULE(gxv_module_class) +FT_USE_MODULE( FT_Module_Class, gxv_module_class ) #endif /* diff --git a/include/freetype/config/ftmodule.h b/include/freetype/config/ftmodule.h index d92b0ee6a..76d271a74 100644 --- a/include/freetype/config/ftmodule.h +++ b/include/freetype/config/ftmodule.h @@ -10,23 +10,23 @@ * */ -FT_USE_MODULE(autofit_module_class) -FT_USE_MODULE(tt_driver_class) -FT_USE_MODULE(t1_driver_class) -FT_USE_MODULE(cff_driver_class) -FT_USE_MODULE(t1cid_driver_class) -FT_USE_MODULE(pfr_driver_class) -FT_USE_MODULE(t42_driver_class) -FT_USE_MODULE(winfnt_driver_class) -FT_USE_MODULE(pcf_driver_class) -FT_USE_MODULE(psaux_module_class) -FT_USE_MODULE(psnames_module_class) -FT_USE_MODULE(pshinter_module_class) -FT_USE_MODULE(ft_raster1_renderer_class) -FT_USE_MODULE(sfnt_module_class) -FT_USE_MODULE(ft_smooth_renderer_class) -FT_USE_MODULE(ft_smooth_lcd_renderer_class) -FT_USE_MODULE(ft_smooth_lcdv_renderer_class) -FT_USE_MODULE(bdf_driver_class) +FT_USE_MODULE( FT_Module_Class, autofit_module_class ) +FT_USE_MODULE( FT_Driver_ClassRec, tt_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, t1_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, cff_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, t1cid_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, pfr_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, t42_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, winfnt_driver_class ) +FT_USE_MODULE( FT_Driver_ClassRec, pcf_driver_class ) +FT_USE_MODULE( FT_Module_Class, psaux_module_class ) +FT_USE_MODULE( FT_Module_Class, psnames_module_class ) +FT_USE_MODULE( FT_Module_Class, pshinter_module_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_raster1_renderer_class ) +FT_USE_MODULE( FT_Module_Class, sfnt_module_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcd_renderer_class ) +FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcdv_renderer_class ) +FT_USE_MODULE( FT_Driver_ClassRec, bdf_driver_class ) /* EOF */ diff --git a/src/autofit/module.mk b/src/autofit/module.mk index 4a386ce66..6ec60912a 100644 --- a/src/autofit/module.mk +++ b/src/autofit/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += AUTOFIT_MODULE define AUTOFIT_MODULE -$(OPEN_DRIVER)autofit_module_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Module_Class, autofit_module_class $(CLOSE_DRIVER) $(ECHO_DRIVER)autofit $(ECHO_DRIVER_DESC)automatic hinting module$(ECHO_DRIVER_DONE) endef diff --git a/src/base/ftinit.c b/src/base/ftinit.c index 7af19c3d8..dac30b0d8 100644 --- a/src/base/ftinit.c +++ b/src/base/ftinit.c @@ -55,9 +55,9 @@ #undef FT_USE_MODULE #ifdef __cplusplus -#define FT_USE_MODULE( x ) extern "C" const FT_Module_Class x; +#define FT_USE_MODULE( type, x ) extern "C" const type x; #else -#define FT_USE_MODULE( x ) extern const FT_Module_Class x; +#define FT_USE_MODULE( type, x ) extern const type x; #endif @@ -65,7 +65,7 @@ #undef FT_USE_MODULE -#define FT_USE_MODULE( x ) (const FT_Module_Class*)&(x), +#define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x), static const FT_Module_Class* const ft_default_modules[] = diff --git a/src/bdf/module.mk b/src/bdf/module.mk index dfaa2744e..fe06ae8e0 100644 --- a/src/bdf/module.mk +++ b/src/bdf/module.mk @@ -27,7 +27,7 @@ FTMODULE_H_COMMANDS += BDF_DRIVER define BDF_DRIVER -$(OPEN_DRIVER)bdf_driver_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Driver_ClassRec, bdf_driver_class $(CLOSE_DRIVER) $(ECHO_DRIVER)bdf $(ECHO_DRIVER_DESC)bdf bitmap fonts$(ECHO_DRIVER_DONE) endef diff --git a/src/cff/module.mk b/src/cff/module.mk index 0474e37b6..ef1391c27 100644 --- a/src/cff/module.mk +++ b/src/cff/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += CFF_DRIVER define CFF_DRIVER -$(OPEN_DRIVER)cff_driver_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Driver_ClassRec, cff_driver_class $(CLOSE_DRIVER) $(ECHO_DRIVER)cff $(ECHO_DRIVER_DESC)OpenType fonts with extension *.otf$(ECHO_DRIVER_DONE) endef diff --git a/src/cid/module.mk b/src/cid/module.mk index 41e5a68e5..ce30bfd7a 100644 --- a/src/cid/module.mk +++ b/src/cid/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += TYPE1CID_DRIVER define TYPE1CID_DRIVER -$(OPEN_DRIVER)t1cid_driver_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Driver_ClassRec, t1cid_driver_class $(CLOSE_DRIVER) $(ECHO_DRIVER)cid $(ECHO_DRIVER_DESC)Postscript CID-keyed fonts, no known extension$(ECHO_DRIVER_DONE) endef diff --git a/src/gxvalid/module.mk b/src/gxvalid/module.mk index 44ef94add..9fd098e2c 100644 --- a/src/gxvalid/module.mk +++ b/src/gxvalid/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += GXVALID_MODULE define GXVALID_MODULE -$(OPEN_DRIVER)gxv_module_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Module_Class, gxv_module_class $(CLOSE_DRIVER) $(ECHO_DRIVER)gxvalid $(ECHO_DRIVER_DESC)TrueTypeGX/AAT validation module$(ECHO_DRIVER_DONE) endef diff --git a/src/otvalid/module.mk b/src/otvalid/module.mk index aa4db047d..9cadde55e 100644 --- a/src/otvalid/module.mk +++ b/src/otvalid/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += OTVALID_MODULE define OTVALID_MODULE -$(OPEN_DRIVER)otv_module_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Module_Class, otv_module_class $(CLOSE_DRIVER) $(ECHO_DRIVER)otvalid $(ECHO_DRIVER_DESC)OpenType validation module$(ECHO_DRIVER_DONE) endef diff --git a/src/pcf/module.mk b/src/pcf/module.mk index 0c51cd6fc..df383ff0f 100644 --- a/src/pcf/module.mk +++ b/src/pcf/module.mk @@ -27,7 +27,7 @@ FTMODULE_H_COMMANDS += PCF_DRIVER define PCF_DRIVER -$(OPEN_DRIVER)pcf_driver_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Driver_ClassRec, pcf_driver_class $(CLOSE_DRIVER) $(ECHO_DRIVER)pcf $(ECHO_DRIVER_DESC)pcf bitmap fonts$(ECHO_DRIVER_DONE) endef diff --git a/src/pfr/module.mk b/src/pfr/module.mk index 53ab34aa9..8d1d28a9d 100644 --- a/src/pfr/module.mk +++ b/src/pfr/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += PFR_DRIVER define PFR_DRIVER -$(OPEN_DRIVER)pfr_driver_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Driver_ClassRec, pfr_driver_class $(CLOSE_DRIVER) $(ECHO_DRIVER)pfr $(ECHO_DRIVER_DESC)PFR/TrueDoc font files with extension *.pfr$(ECHO_DRIVER_DONE) endef diff --git a/src/psaux/module.mk b/src/psaux/module.mk index 543152208..42bf6f519 100644 --- a/src/psaux/module.mk +++ b/src/psaux/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += PSAUX_MODULE define PSAUX_MODULE -$(OPEN_DRIVER)psaux_module_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Module_Class, psaux_module_class $(CLOSE_DRIVER) $(ECHO_DRIVER)psaux $(ECHO_DRIVER_DESC)Postscript Type 1 & Type 2 helper module$(ECHO_DRIVER_DONE) endef diff --git a/src/pshinter/module.mk b/src/pshinter/module.mk index cd171d035..ed24eb7fa 100644 --- a/src/pshinter/module.mk +++ b/src/pshinter/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += PSHINTER_MODULE define PSHINTER_MODULE -$(OPEN_DRIVER)pshinter_module_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Module_Class, pshinter_module_class $(CLOSE_DRIVER) $(ECHO_DRIVER)pshinter $(ECHO_DRIVER_DESC)Postscript hinter module$(ECHO_DRIVER_DONE) endef diff --git a/src/psnames/module.mk b/src/psnames/module.mk index a93063b92..a6e908257 100644 --- a/src/psnames/module.mk +++ b/src/psnames/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += PSNAMES_MODULE define PSNAMES_MODULE -$(OPEN_DRIVER)psnames_module_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Module_Class, psnames_module_class $(CLOSE_DRIVER) $(ECHO_DRIVER)psnames $(ECHO_DRIVER_DESC)Postscript & Unicode Glyph name handling$(ECHO_DRIVER_DONE) endef diff --git a/src/raster/module.mk b/src/raster/module.mk index 59c737b93..cbff5df96 100644 --- a/src/raster/module.mk +++ b/src/raster/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += RASTER_MODULE define RASTER_MODULE -$(OPEN_DRIVER)ft_raster1_renderer_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Renderer_Class, ft_raster1_renderer_class $(CLOSE_DRIVER) $(ECHO_DRIVER)raster $(ECHO_DRIVER_DESC)monochrome bitmap renderer$(ECHO_DRIVER_DONE) endef diff --git a/src/sfnt/module.mk b/src/sfnt/module.mk index d33913809..95fd6a314 100644 --- a/src/sfnt/module.mk +++ b/src/sfnt/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += SFNT_MODULE define SFNT_MODULE -$(OPEN_DRIVER)sfnt_module_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Module_Class, sfnt_module_class $(CLOSE_DRIVER) $(ECHO_DRIVER)sfnt $(ECHO_DRIVER_DESC)helper module for TrueType & OpenType formats$(ECHO_DRIVER_DONE) endef diff --git a/src/smooth/module.mk b/src/smooth/module.mk index 05ad4ba0a..47f6c0407 100644 --- a/src/smooth/module.mk +++ b/src/smooth/module.mk @@ -16,11 +16,11 @@ FTMODULE_H_COMMANDS += SMOOTH_RENDERER define SMOOTH_RENDERER -$(OPEN_DRIVER)ft_smooth_renderer_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Renderer_Class, ft_smooth_renderer_class $(CLOSE_DRIVER) $(ECHO_DRIVER)smooth $(ECHO_DRIVER_DESC)anti-aliased bitmap renderer$(ECHO_DRIVER_DONE) -$(OPEN_DRIVER)ft_smooth_lcd_renderer_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Renderer_Class, ft_smooth_lcd_renderer_class $(CLOSE_DRIVER) $(ECHO_DRIVER)smooth $(ECHO_DRIVER_DESC)anti-aliased bitmap renderer for LCDs$(ECHO_DRIVER_DONE) -$(OPEN_DRIVER)ft_smooth_lcdv_renderer_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Renderer_Class, ft_smooth_lcdv_renderer_class $(CLOSE_DRIVER) $(ECHO_DRIVER)smooth $(ECHO_DRIVER_DESC)anti-aliased bitmap renderer for vertical LCDs$(ECHO_DRIVER_DONE) endef diff --git a/src/truetype/module.mk b/src/truetype/module.mk index 3b05afc7f..baee81a77 100644 --- a/src/truetype/module.mk +++ b/src/truetype/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += TRUETYPE_DRIVER define TRUETYPE_DRIVER -$(OPEN_DRIVER)tt_driver_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Driver_ClassRec, tt_driver_class $(CLOSE_DRIVER) $(ECHO_DRIVER)truetype $(ECHO_DRIVER_DESC)Windows/Mac font files with extension *.ttf or *.ttc$(ECHO_DRIVER_DONE) endef diff --git a/src/type1/module.mk b/src/type1/module.mk index baf98c00e..ade0210d7 100644 --- a/src/type1/module.mk +++ b/src/type1/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += TYPE1_DRIVER define TYPE1_DRIVER -$(OPEN_DRIVER)t1_driver_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Driver_ClassRec, t1_driver_class $(CLOSE_DRIVER) $(ECHO_DRIVER)type1 $(ECHO_DRIVER_DESC)Postscript font files with extension *.pfa or *.pfb$(ECHO_DRIVER_DONE) endef diff --git a/src/type42/module.mk b/src/type42/module.mk index 8bd40a5cc..b3f10a8d3 100644 --- a/src/type42/module.mk +++ b/src/type42/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += TYPE42_DRIVER define TYPE42_DRIVER -$(OPEN_DRIVER)t42_driver_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Driver_ClassRec, t42_driver_class $(CLOSE_DRIVER) $(ECHO_DRIVER)type42 $(ECHO_DRIVER_DESC)Type 42 font files with no known extension$(ECHO_DRIVER_DONE) endef diff --git a/src/winfonts/module.mk b/src/winfonts/module.mk index 0ace3ae6d..b44d7f057 100644 --- a/src/winfonts/module.mk +++ b/src/winfonts/module.mk @@ -16,7 +16,7 @@ FTMODULE_H_COMMANDS += WINDOWS_DRIVER define WINDOWS_DRIVER -$(OPEN_DRIVER)winfnt_driver_class$(CLOSE_DRIVER) +$(OPEN_DRIVER) FT_Driver_ClassRec, winfnt_driver_class $(CLOSE_DRIVER) $(ECHO_DRIVER)winfnt $(ECHO_DRIVER_DESC)Windows bitmap fonts with extension *.fnt or *.fon$(ECHO_DRIVER_DONE) endef