From e5f87484cdf760f6bec69d72e8f474c1e7697b70 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 21 Jul 2015 12:04:53 +0200 Subject: [PATCH] cosmetics in the check of library version vs. header version --- include/simgrid/msg.h | 14 ++++---------- include/xbt/misc.h | 3 +++ src/surf/surf_interface.cpp | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index f5e114464e..7fd3357cc8 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -221,16 +221,10 @@ XBT_PUBLIC(void) MSG_config(const char *key, const char *value); * * We allow to link against compiled versions that differ in the patch level. */ -#define MSG_init(argc,argv) { \ - int ver_major,ver_minor,ver_patch; \ - sg_version(&ver_major,&ver_minor,&ver_patch); \ - if ((ver_major != SIMGRID_VERSION_MAJOR) || \ - (ver_minor != SIMGRID_VERSION_MINOR)) { \ - fprintf(stderr,"FATAL ERROR: Your program was compiled with SimGrid version %d.%d.%d, and then linked against SimGrid %d.%d.%d. Please fix this.\n", \ - SIMGRID_VERSION_MAJOR,SIMGRID_VERSION_MINOR,SIMGRID_VERSION_PATCH,ver_major,ver_minor,ver_patch); \ - } \ - MSG_init_nocheck(argc,argv); \ - } +#define MSG_init(argc,argv) do { \ + sg_version_check(SIMGRID_VERSION_MAJOR,SIMGRID_VERSION_MINOR,SIMGRID_VERSION_PATCH);\ + MSG_init_nocheck(argc,argv); \ + } while (0) XBT_PUBLIC(void) MSG_init_nocheck(int *argc, char **argv); XBT_PUBLIC(msg_error_t) MSG_main(void); diff --git a/include/xbt/misc.h b/include/xbt/misc.h index a8d8c00107..3d29597a53 100644 --- a/include/xbt/misc.h +++ b/include/xbt/misc.h @@ -29,6 +29,9 @@ XBT_PUBLIC(const char *) xbt_procname(void); SIMGRID_VERSION_MAJOR and friends give the version numbers of the used header files */ XBT_PUBLIC(void) sg_version(int *major,int *minor,int *patch); +/** Helps ensuring that the header version (SIMGRID_VERSION_MAJOR and friends) and the dynamic library version do match. */ +void sg_version_check(int lib_version_major,int lib_version_minor,int lib_version_patch); + /** Contains all the parameters we got from the command line */ XBT_PUBLIC_DATA(xbt_dynar_t) sg_cmdline; diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index f49641e416..8fdc1db634 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -339,6 +339,23 @@ static XBT_INLINE void surf_storage_free(void *r) delete static_cast(r); } +void sg_version_check(int lib_version_major,int lib_version_minor,int lib_version_patch) { + if ((lib_version_major != SIMGRID_VERSION_MAJOR) || (lib_version_minor != SIMGRID_VERSION_MINOR)) { + fprintf(stderr, + "FATAL ERROR: Your program was compiled with SimGrid version %d.%d.%d, " + "and then linked against SimGrid %d.%d.%d. Please fix this.\n", + SIMGRID_VERSION_MAJOR,SIMGRID_VERSION_MINOR,SIMGRID_VERSION_PATCH, + lib_version_major,lib_version_minor,lib_version_patch); + abort(); + } + if (lib_version_patch != SIMGRID_VERSION_PATCH) { + fprintf(stderr, + "Warning: Your program was compiled with SimGrid version %d.%d.%d, " + "and then linked against SimGrid %d.%d.%d. Proceeding anyway.\n", + SIMGRID_VERSION_MAJOR,SIMGRID_VERSION_MINOR,SIMGRID_VERSION_PATCH, + lib_version_major,lib_version_minor,lib_version_patch); + } +} void sg_version(int *ver_major,int *ver_minor,int *ver_patch) { *ver_major = SIMGRID_VERSION_MAJOR; -- 2.20.1