Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics in the check of library version vs. header version
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 21 Jul 2015 10:04:53 +0000 (12:04 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 21 Jul 2015 10:06:16 +0000 (12:06 +0200)
include/simgrid/msg.h
include/xbt/misc.h
src/surf/surf_interface.cpp

index f5e1144..7fd3357 100644 (file)
@@ -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.
  */
  *
  *  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);
 
 XBT_PUBLIC(void) MSG_init_nocheck(int *argc, char **argv);
 XBT_PUBLIC(msg_error_t) MSG_main(void);
index a8d8c00..3d29597 100644 (file)
@@ -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);
 
     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;
 
 /** Contains all the parameters we got from the command line */
 XBT_PUBLIC_DATA(xbt_dynar_t) sg_cmdline;
 
index f49641e..8fdc1db 100644 (file)
@@ -339,6 +339,23 @@ static XBT_INLINE void surf_storage_free(void *r)
   delete static_cast<Storage*>(r);
 }
 
   delete static_cast<Storage*>(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;
 
 void sg_version(int *ver_major,int *ver_minor,int *ver_patch) {
   *ver_major = SIMGRID_VERSION_MAJOR;