[AD] version check in allegro_init

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Not sure this is needed - but Evert and me tracked down a problem
someone had on allegro.cc yesterday which made seemingly no sense, and
it turned out to be a version conflict between two WIP versions. The
attached patch is a very simple check which would have caught this
(allegro_init checks if it is a WIP version, and fails if the version
differs in that case). It would also help a lot for people like me, who
have 5 different WIP versions of Allegro installed, and regularly mix
them up (e.g. by forgetting to run make depend before make install) :P

Index: src/allegro.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/allegro.c,v
retrieving revision 1.45
diff -u -p -r1.45 allegro.c
--- src/allegro.c	28 Feb 2004 16:17:03 -0000	1.45
+++ src/allegro.c	1 Nov 2004 11:13:58 -0000
@@ -390,6 +390,23 @@ int install_allegro(int system_id, int *
 
 
 
+/* install_allegro_version:
+ *  Version checking version of instal_allegro.
+ */
+int install_allegro_version(int system_id, int *errno_ptr, int (*atexit_ptr)(void(*func)(void)),
+   int version, int sub_version, int wip_version)
+{
+   if (version != ALLEGRO_VERSION || sub_version != ALLEGRO_SUB_VERSION ||
+      ((sub_version & 1) && wip_version != ALLEGRO_WIP_VERSION)) {
+      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text(
+      "Incompatible Allegro version. Make sure headers and library are from compatible versions."));
+      return -1;
+   }
+   return install_allegro(system_id, errno_ptr, atexit_ptr);
+}
+
+
+
 /* allegro_exit:
  *  Closes down the Allegro system.
  */
Index: include/allegro/system.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/system.h,v
retrieving revision 1.12
diff -u -p -r1.12 system.h
--- include/allegro/system.h	19 May 2003 15:32:46 -0000	1.12
+++ include/allegro/system.h	1 Nov 2004 11:13:58 -0000
@@ -67,8 +67,14 @@ AL_VAR(int, os_multitasking);
 #define SYSTEM_AUTODETECT  0
 #define SYSTEM_NONE        AL_ID('N','O','N','E')
 
-AL_FUNC(int, install_allegro, (int system_id, int *errno_ptr, AL_METHOD(int, atexit_ptr, (AL_METHOD(void, func, (void))))));
-#define allegro_init()  install_allegro(SYSTEM_AUTODETECT, &errno, (int (*)(void (*)(void)))atexit)
+AL_FUNC(int, install_allegro, (int system_id, int *errno_ptr,
+   AL_METHOD(int, atexit_ptr, (AL_METHOD(void, func, (void))))));
+AL_FUNC(int, install_allegro_version, (int system_id, int *errno_ptr,
+   AL_METHOD(int, atexit_ptr, (AL_METHOD(void, func, (void)))),
+   int version, int sub_version, int wip_version));
+#define allegro_init() install_allegro_version(SYSTEM_AUTODETECT, &errno, \
+   (int (*)(void (*)(void)))atexit, ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, \
+   ALLEGRO_WIP_VERSION)
 AL_FUNC(void, allegro_exit, (void));
 
 AL_PRINTFUNC(void, allegro_message, (AL_CONST char *msg, ...), 1, 2);


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/