From ff903159781d9652206057640543d6f934146d81 Mon Sep 17 00:00:00 2001 From: Kp Date: Thu, 27 Jun 2013 02:35:22 +0000 Subject: [PATCH] Use SConscript configure support to probe for format(printf) attribute --- SConstruct | 11 +++++++++++ common/include/console.h | 3 ++- common/include/dxxerror.h | 7 +++---- common/include/editor/editor.h | 3 ++- common/include/gr.h | 5 +++-- common/include/physfsx.h | 2 ++ common/include/ui.h | 3 ++- common/main/ai.h | 3 ++- common/main/hudmsg.h | 5 +++-- common/main/powerup.h | 3 ++- d1x-rebirth/main/dumpmine.c | 6 ++++-- d1x-rebirth/main/gameseq.c | 3 ++- d2x-rebirth/main/dumpmine.c | 6 ++++-- d2x-rebirth/main/escort.c | 3 ++- d2x-rebirth/main/gameseq.c | 3 ++- similar/editor/autosave.c | 4 +++- similar/main/scores.c | 3 ++- 17 files changed, 51 insertions(+), 22 deletions(-) diff --git a/SConstruct b/SConstruct index 18b9e9282..7355e87ad 100644 --- a/SConstruct +++ b/SConstruct @@ -140,6 +140,17 @@ help:assume compiler supports __attribute__((format_arg)) self._check_macro(context,macro_name=macro_name,macro_value=macro_value,test=""" char*a(char*)__attribute_format_arg(1); """, msg='for function __attribute__((format_arg))') + @_custom_test + def check_attribute_format_printf(self,context): + """ +help:assume compiler supports __attribute__((format(printf))) +""" + macro_name = '__attribute_format_printf(A,B)' + macro_value = '__attribute__((format(printf,A,B)))' + self._check_macro(context,macro_name=macro_name,macro_value=macro_value,test=""" +int a(char*,...)__attribute_format_printf(1,2); +int b(char*)__attribute_format_printf(1,0); +""", msg='for function __attribute__((format(printf)))') class LazyObjectConstructor: def __lazy_objects(self,name,source): diff --git a/common/include/console.h b/common/include/console.h index 450c35f3e..534b00bb7 100644 --- a/common/include/console.h +++ b/common/include/console.h @@ -4,6 +4,7 @@ #define _CONSOLE_H_ #include "pstypes.h" +#include "dxxsconf.h" /* Priority levels */ #define CON_CRITICAL -3 @@ -30,7 +31,7 @@ typedef struct console_buffer } __pack__ console_buffer; void con_init(void); -void con_printf(int level, const char *fmt, ...); +void con_printf(int level, const char *fmt, ...) __attribute_format_printf(2, 3); void con_showup(void); #endif /* _CONSOLE_H_ */ diff --git a/common/include/dxxerror.h b/common/include/dxxerror.h index 9987b73bc..4e86d71b1 100644 --- a/common/include/dxxerror.h +++ b/common/include/dxxerror.h @@ -21,22 +21,21 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define _ERROR_H #include +#include "dxxsconf.h" #include #ifdef __GNUC__ #define __noreturn __attribute__ ((noreturn)) -#define __attribute_gcc_format(X) __attribute__ ((format X)) #else #define __noreturn -#define __attribute_gcc_format(X) #endif void warn_printf(const char *s); int error_init(void (*func)(const char *)); //init error system, returns 0=ok -void Warning(const char *fmt,...); //print out warning message to user +void Warning(const char *fmt,...) __attribute_format_printf(1, 2); //print out warning message to user void set_warn_func(void (*f)(const char *s));//specifies the function to call with warning messages void clear_warn_func();//say this function no longer valid -void Error(const char *fmt,...) __noreturn __attribute_gcc_format((printf, 1, 2)); //exit with error code=1, print message +void Error(const char *fmt,...) __noreturn __attribute_format_printf(1, 2); //exit with error code=1, print message #define Assert assert #ifndef NDEBUG //macros for debugging diff --git a/common/include/editor/editor.h b/common/include/editor/editor.h index 28f2efa23..a79b9b67d 100644 --- a/common/include/editor/editor.h +++ b/common/include/editor/editor.h @@ -20,6 +20,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #ifndef _EDITOR_H #define _EDITOR_H +#include "dxxsconf.h" #include "vecmat.h" #include "segment.h" #include "inferno.h" @@ -481,7 +482,7 @@ extern void print_status_icon( char icon[1], int position ); extern void clear_status_icon( char icon[1], int position ); // Editor status message. -extern void editor_status_fmt(const char *format, ... ); +extern void editor_status_fmt(const char *format, ... ) __attribute_format_printf(1, 2); // Variables in editor.c that the k*.c files need diff --git a/common/include/gr.h b/common/include/gr.h index 630017745..7316857ba 100644 --- a/common/include/gr.h +++ b/common/include/gr.h @@ -22,6 +22,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "pstypes.h" #include "fix.h" +#include "dxxsconf.h" #ifdef DXX_BUILD_DESCENT_I extern int HiresGFXAvailable; @@ -328,8 +329,8 @@ void gr_set_curfont( grs_font * ); void gr_set_fontcolor( int fg_color, int bg_color ); int gr_string(int x, int y, const char *s ); int gr_ustring(int x, int y, const char *s ); -int gr_printf( int x, int y, const char * format, ... ); -int gr_uprintf( int x, int y, const char * format, ... ); +int gr_printf( int x, int y, const char * format, ... ) __attribute_format_printf(3, 4); +int gr_uprintf( int x, int y, const char * format, ... ) __attribute_format_printf(3, 4); void gr_get_string_size(const char *s, int *string_width, int *string_height, int *average_width ); diff --git a/common/include/physfsx.h b/common/include/physfsx.h index ab3c53e96..25e707fde 100644 --- a/common/include/physfsx.h +++ b/common/include/physfsx.h @@ -19,6 +19,7 @@ #include #endif +#include "dxxsconf.h" #include "pstypes.h" #include "strutil.h" #include "u_mem.h" @@ -188,6 +189,7 @@ static inline char * PHYSFSX_fgets(char *buf, size_t n, PHYSFS_file *const fp) return buf; } +static inline int PHYSFSX_printf(PHYSFS_file *file, const char *format, ...) __attribute_format_printf(2, 3); static inline int PHYSFSX_printf(PHYSFS_file *file, const char *format, ...) { char buffer[1024]; diff --git a/common/include/ui.h b/common/include/ui.h index b7976dc14..be28cebb9 100644 --- a/common/include/ui.h +++ b/common/include/ui.h @@ -20,6 +20,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #ifndef _UI_H #define _UI_H +#include "dxxsconf.h" #include "event.h" struct window; @@ -261,7 +262,7 @@ extern int ui_scrollbar_do( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar, str extern void ui_draw_scrollbar( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar ); -extern void ui_dprintf_at( UI_DIALOG * dlg, short x, short y, const char * format, ... ); +extern void ui_dprintf_at( UI_DIALOG * dlg, short x, short y, const char * format, ... ) __attribute_format_printf(4, 5); extern void ui_draw_radio( UI_DIALOG *dlg, UI_GADGET_RADIO * radio ); extern UI_GADGET_RADIO * ui_add_gadget_radio( UI_DIALOG * dlg, short x, short y, short w, short h, short group, const char * text ); diff --git a/common/main/ai.h b/common/main/ai.h index 92805ccc9..7640ba7a5 100644 --- a/common/main/ai.h +++ b/common/main/ai.h @@ -20,6 +20,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #ifndef _AI_H #define _AI_H +#include "dxxsconf.h" #include "object.h" #if defined(DXX_BUILD_DESCENT_II) #include "fvi.h" @@ -314,7 +315,7 @@ extern int Buddy_objnum, Buddy_allowed_to_talk; extern void start_robot_death_sequence(object *objp); extern int do_any_robot_dying_frame(object *objp); -extern void buddy_message(const char * format, ... ); +extern void buddy_message(const char * format, ... ) __attribute_format_printf(1, 2); #define SPECIAL_REACTOR_ROBOT 65 extern void special_reactor_stuff(void); diff --git a/common/main/hudmsg.h b/common/main/hudmsg.h index ffe4954f9..93221883f 100644 --- a/common/main/hudmsg.h +++ b/common/main/hudmsg.h @@ -2,6 +2,7 @@ #define _HUD_MSG_H #include +#include "dxxsconf.h" #define HUD_MESSAGE_LENGTH 150 #define HUD_MAX_NUM_DISP 4 @@ -16,8 +17,8 @@ extern int HUD_toolong; extern void HUD_clear_messages(); extern void HUD_render_message_frame(); -int HUD_init_message(int class_flag, const char * format, ... ); -int HUD_init_message_va(int class_flag, const char * format, va_list args); +int HUD_init_message(int class_flag, const char * format, ... ) __attribute_format_printf(2, 3); +int HUD_init_message_va(int class_flag, const char * format, va_list args) __attribute_format_printf(2, 0); int HUD_init_message_literal(int class_flag, const char *str); #endif diff --git a/common/main/powerup.h b/common/main/powerup.h index 22b0d3d27..ee3fd0872 100644 --- a/common/main/powerup.h +++ b/common/main/powerup.h @@ -21,6 +21,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #ifndef _POWERUP_H #define _POWERUP_H +#include "dxxsconf.h" #include "vclip.h" enum powerup_type_t @@ -133,7 +134,7 @@ extern void diminish_towards_max(void); extern void do_megawow_powerup(int quantity); -extern void powerup_basic(int redadd, int greenadd, int blueadd, int score, const char *format, ...) __attribute_gcc_format((printf, 5, 6)); +extern void powerup_basic(int redadd, int greenadd, int blueadd, int score, const char *format, ...) __attribute_format_printf(5, 6); /* * reads n powerup_type_info structs from a PHYSFS_file diff --git a/d1x-rebirth/main/dumpmine.c b/d1x-rebirth/main/dumpmine.c index 1bbadae74..f307dd486 100644 --- a/d1x-rebirth/main/dumpmine.c +++ b/d1x-rebirth/main/dumpmine.c @@ -72,7 +72,8 @@ char *object_ids(int objnum) return NULL; } -void err_printf(PHYSFS_file *my_file, char * format, ... ) +static void err_printf(PHYSFS_file *my_file, char * format, ... ) __attribute_format_printf(2, 3); +static void err_printf(PHYSFS_file *my_file, char * format, ... ) { va_list args; char message[256]; @@ -86,7 +87,8 @@ void err_printf(PHYSFS_file *my_file, char * format, ... ) Errors_in_mine++; } -void warning_printf(PHYSFS_file *my_file, char * format, ... ) +static void warning_printf(PHYSFS_file *my_file, char * format, ... ) __attribute_format_printf(2, 3); +static void warning_printf(PHYSFS_file *my_file, char * format, ... ) { va_list args; char message[256]; diff --git a/d1x-rebirth/main/gameseq.c b/d1x-rebirth/main/gameseq.c index bde27ef8f..d26c3b023 100644 --- a/d1x-rebirth/main/gameseq.c +++ b/d1x-rebirth/main/gameseq.c @@ -787,7 +787,8 @@ int draw_rock(newmenu *menu, d_event *event, grs_bitmap *background) return 0; } -void do_screen_message(char *fmt, ...) +static void do_screen_message(const char *fmt, ...) __attribute_format_printf(1, 2); +static void do_screen_message(const char *fmt, ...) { va_list arglist; grs_bitmap background; diff --git a/d2x-rebirth/main/dumpmine.c b/d2x-rebirth/main/dumpmine.c index 1ae885697..e2f9cd35d 100644 --- a/d2x-rebirth/main/dumpmine.c +++ b/d2x-rebirth/main/dumpmine.c @@ -87,7 +87,8 @@ char *object_ids(int objnum) return NULL; } -void err_printf(PHYSFS_file *my_file, char * format, ... ) +static void err_printf(PHYSFS_file *my_file, char * format, ... ) __attribute_format_printf(2, 3); +static void err_printf(PHYSFS_file *my_file, char * format, ... ) { va_list args; char message[256]; @@ -101,7 +102,8 @@ void err_printf(PHYSFS_file *my_file, char * format, ... ) Errors_in_mine++; } -void warning_printf(PHYSFS_file *my_file, char * format, ... ) +static void warning_printf(PHYSFS_file *my_file, char * format, ... ) __attribute_format_printf(2, 3); +static void warning_printf(PHYSFS_file *my_file, char * format, ... ) { va_list args; char message[256]; diff --git a/d2x-rebirth/main/escort.c b/d2x-rebirth/main/escort.c index 3ca694498..a049a054d 100644 --- a/d2x-rebirth/main/escort.c +++ b/d2x-rebirth/main/escort.c @@ -426,7 +426,8 @@ void buddy_message(const char * format, ... ) } // ----------------------------------------------------------------------------- -void thief_message(const char * format, ... ) +static void thief_message(const char * format, ... ) __attribute_format_printf(1, 2); +static void thief_message(const char * format, ... ) { char gb_str[16], new_format[128]; diff --git a/d2x-rebirth/main/gameseq.c b/d2x-rebirth/main/gameseq.c index 0011a1ebf..670a7bf6a 100644 --- a/d2x-rebirth/main/gameseq.c +++ b/d2x-rebirth/main/gameseq.c @@ -945,7 +945,8 @@ int draw_stars_bg(newmenu *menu, d_event *event, grs_bitmap *background) return 0; } -void do_screen_message(char *fmt, ...) +static void do_screen_message(const char *fmt, ...) __attribute_format_printf(1, 2); +static void do_screen_message(const char *fmt, ...) { va_list arglist; grs_bitmap background; diff --git a/similar/editor/autosave.c b/similar/editor/autosave.c index f9dcfe942..1699ac1a0 100644 --- a/similar/editor/autosave.c +++ b/similar/editor/autosave.c @@ -134,7 +134,9 @@ void print_clock( int seconds, char message[10] ) { static char the_time[14]; // changed from 10, I don't think that was long enough -void clock_message( int seconds, char *format, ... ) { +static void clock_message( int seconds, const char *format, ... ) __attribute_format_printf(2, 3); +static void clock_message( int seconds, const char *format, ... ) +{ va_list ap; va_start(ap, format); diff --git a/similar/main/scores.c b/similar/main/scores.c index 8e0afd583..b625ac4d0 100644 --- a/similar/main/scores.c +++ b/similar/main/scores.c @@ -265,7 +265,8 @@ void scores_maybe_add_player(int abort_flag) window_close(Game_wind); // prevent the next game from doing funny things } -void scores_rprintf(int x, int y, char * format, ... ) +static void scores_rprintf(int x, int y, const char * format, ... ) __attribute_format_printf(3, 4); +static void scores_rprintf(int x, int y, const char * format, ... ) { va_list args; char buffer[128];