diff --git a/prism/include/PrismHybridGlob.h b/prism/include/PrismHybridGlob.h index c27eeb02..8d072425 100644 --- a/prism/include/PrismHybridGlob.h +++ b/prism/include/PrismHybridGlob.h @@ -45,11 +45,11 @@ extern double last_unif; // macros, function prototypes #define logtwo(X) log((double)X)/log(2.0) -void PH_PrintToMainLog(JNIEnv *env, const char *str, ...); -void PH_PrintWarningToMainLog(JNIEnv *env, const char *str, ...); -void PH_PrintToTechLog(JNIEnv *env, const char *str, ...); +void PH_PrintToMainLog(JNIEnv *env, const char *str, ...) IS_LIKE_PRINTF(2,3); +void PH_PrintWarningToMainLog(JNIEnv *env, const char *str, ...) IS_LIKE_PRINTF(2,3); +void PH_PrintToTechLog(JNIEnv *env, const char *str, ...) IS_LIKE_PRINTF(2,3); void PH_PrintMemoryToMainLog(JNIEnv *env, const char *before, double mem, const char *after); -void PH_SetErrorMessage(const char *str, ...); +void PH_SetErrorMessage(const char *str, ...) IS_LIKE_PRINTF(1,2); char *PH_GetErrorMessage(); bool PH_GetFlagExportIterations(); diff --git a/prism/include/PrismMTBDDGlob.h b/prism/include/PrismMTBDDGlob.h index 1eeead0c..6cba3e17 100644 --- a/prism/include/PrismMTBDDGlob.h +++ b/prism/include/PrismMTBDDGlob.h @@ -44,13 +44,15 @@ extern JNIEnv *export_env; // function prototypes -void PM_PrintToMainLog(JNIEnv *env, const char *str, ...); -void PM_PrintWarningToMainLog(JNIEnv *env, const char *str, ...); -void PM_PrintToTechLog(JNIEnv *env, const char *str, ...); -void PM_SetErrorMessage(const char *str, ...); +void PM_PrintToMainLog(JNIEnv *env, const char *str, ...) IS_LIKE_PRINTF(2,3); +void PM_PrintWarningToMainLog(JNIEnv *env, const char *str, ...) IS_LIKE_PRINTF(2,3); +void PM_PrintToTechLog(JNIEnv *env, const char *str, ...) IS_LIKE_PRINTF(2,3); +void PM_SetErrorMessage(const char *str, ...) IS_LIKE_PRINTF(1,2); char *PM_GetErrorMessage(); int store_export_info(int type, jstring fn, JNIEnv *env); -void export_string(const char *str, ...); + + +void export_string(const char *str, ...) IS_LIKE_PRINTF(1,2); bool PM_GetFlagExportIterations(); //------------------------------------------------------------------------------ diff --git a/prism/include/PrismNativeGlob.h b/prism/include/PrismNativeGlob.h index a44acda9..fbfe2fc7 100644 --- a/prism/include/PrismNativeGlob.h +++ b/prism/include/PrismNativeGlob.h @@ -28,6 +28,7 @@ #define PRISMNATIVEGLOB_H //------------------------------------------------------------------------------ +#include #include // Flags for building Windows DLLs @@ -37,6 +38,35 @@ #define EXPORT #endif +//------------------------------------------------------------------------------ + +// macro for attributing printf-like functions to notify the compiler +// that we'd like to have format string / argument sanity checking + +#ifdef __GNUC__ + // __attribute__ should be supported by compilers that claim to behave like GNU GCC + + // we have to determine the printf format string, as MINGW supports two printf backends +#if defined(__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO + // this should be the default for C++ +#define PRISM_PRINTF_FORMAT gnu_printf +#elif defined(__USE_MINGW_ANSI_STDIO) && !(__USE_MINGW_ANSI_STDIO) +#define PRISM_PRINTF_FORMAT ms_printf +#else + // normal GCC: use printf as format +#define PRISM_PRINTF_FORMAT printf +#endif + +// define IS_LIKE_PRINTF, which can be placed after a printf-like function +// first parameter is index of format string, second parameter is first vararg +#define IS_LIKE_PRINTF(format_index, first_arg) __attribute__((__format__(PRISM_PRINTF_FORMAT, format_index,first_arg))) + +#else // !defined __GNUC__ +// empty IS_LIKE_PRINTF +#define IS_LIKE_PRINTF(format_index, first_arg) +#endif + + //------------------------------------------------------------------------------ // Constants - these need to match the definitions in prism/Prism.java diff --git a/prism/include/PrismSparseGlob.h b/prism/include/PrismSparseGlob.h index 4574e451..a6e8dc16 100644 --- a/prism/include/PrismSparseGlob.h +++ b/prism/include/PrismSparseGlob.h @@ -45,14 +45,14 @@ extern JNIEnv *export_env; // macros, function prototypes #define logtwo(X) log((double)X)/log(2.0) -void PS_PrintToMainLog(JNIEnv *env, const char *str, ...); -void PS_PrintWarningToMainLog(JNIEnv *env, const char *str, ...); -void PS_PrintToTechLog(JNIEnv *env, const char *str, ...); +void PS_PrintToMainLog(JNIEnv *env, const char *str, ...) IS_LIKE_PRINTF(2,3); +void PS_PrintWarningToMainLog(JNIEnv *env, const char *str, ...) IS_LIKE_PRINTF(2,3); +void PS_PrintToTechLog(JNIEnv *env, const char *str, ...) IS_LIKE_PRINTF(2,3); void PS_PrintMemoryToMainLog(JNIEnv *env, const char *before, double mem, const char *after); -void PS_SetErrorMessage(const char *str, ...); +void PS_SetErrorMessage(const char *str, ...) IS_LIKE_PRINTF(1,2); char *PS_GetErrorMessage(); int store_export_info(int type, jstring fn, JNIEnv *env); -void export_string(const char *str, ...); +void export_string(const char *str, ...) IS_LIKE_PRINTF(1,2); bool PS_GetFlagExportIterations(); //------------------------------------------------------------------------------