[AD] binary compatibility check for 4.2.x

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


The following patch fixes the version check problems on the 4.2.x
branch.  Older binaries will run with newer libraries, but newer
binaries will not run with older libraries.  That's still the policy
for 4.2.x, right?

Was there anything else that needed to be done for 4.2.1?

Peter
--- include/allegro/internal/aintern.h	(revision 5785)
+++ include/allegro/internal/aintern.h	(local)
@@ -40,6 +40,13 @@ AL_VAR(int, _allegro_count);
 AL_VAR(int, _allegro_in_exit);
 
 
+/* These functions are referenced by 4.2.0 binaries, but should no longer be
+ * used by newer versions directly.
+ */
+AL_FUNC_DEPRECATED(int, _get_allegro_version, (void));
+AL_FUNC(int, _install_allegro, (int system_id, int *errno_ptr, AL_METHOD(int, atexit_ptr, (AL_METHOD(void, func, (void))))));
+
+
 /* flag to decide whether to disable the screensaver */
 enum {
   NEVER_DISABLED,
--- include/allegro/system.h	(revision 5785)
+++ include/allegro/system.h	(local)
@@ -73,12 +73,9 @@ AL_VAR(int, os_multitasking);
 
 #define MAKE_VERSION(a, b, c) (((a)<<16)|((b)<<8)|(c))
 
-AL_FUNC(int, _get_allegro_version, (void));
-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_check, (int system_id, int *errno_ptr,
    AL_METHOD(int, atexit_ptr, (AL_METHOD(void, func, (void)))), int version));
 
-/* This is only here because of binary compatibility with 4.2.0. */
 AL_INLINE(int, install_allegro, (int system_id, int *errno_ptr,
    AL_METHOD(int, atexit_ptr, (AL_METHOD(void, func, (void))))),
 {
@@ -86,10 +83,10 @@ AL_INLINE(int, install_allegro, (int sys
       MAKE_VERSION(ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, ALLEGRO_WIP_VERSION));
 })
 
-
 #define allegro_init()  _install_allegro_version_check(SYSTEM_AUTODETECT, &errno, \
    (int (*)(void (*)(void)))atexit, \
    MAKE_VERSION(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);
--- src/allegro.c	(revision 5785)
+++ src/allegro.c	(local)
@@ -232,11 +232,17 @@ static struct al_exit_func *exit_func_li
 
 
 /* _get_allegro_version:
- *  Retrieves the library version.
+ *  Retrieves the library version.  This is an obsolete definition which should
+ *  only be used by Allegro 4.2.0 binaries, which have a call to this function
+ *  embedded.
  */
 int _get_allegro_version(void)
 {
-   return MAKE_VERSION(ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, ALLEGRO_WIP_VERSION);
+#if ALLEGRO_VERSION == 4 && ALLEGRO_SUB_VERSION == 2
+   return MAKE_VERSION(ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, 0);
+#else
+#error _get_allegro_version should not exist in other versions of Allegro
+#endif
 }
 
 
@@ -303,6 +309,9 @@ static void allegro_exit_stub(void)
 
 /* _install_allegro:
  *  Initialises the Allegro library, activating the system driver.
+ *
+ *  This is non-static because 4.2.0 binaries reference it.  Newer binaries
+ *  should only call this through _install_allegro_version_check().
  */
 int _install_allegro(int system_id, int *errno_ptr, int (*atexit_ptr)(void (*func)(void)))
 {
@@ -412,8 +421,8 @@ int _install_allegro(int system_id, int 
 
 
 /* _install_allegro_version_check:
- *  Initialises the Allegro library, but return with an error if an incompatible version
- *  is found.
+ *  Initialises the Allegro library, but return with an error if an
+ *  incompatible version is found.
  */
 int _install_allegro_version_check(int system_id, int *errno_ptr,
    int (*atexit_ptr)(void (*func)(void)), int version)
@@ -425,12 +434,14 @@ int _install_allegro_version_check(int s
 
    int version_ok;
 
-   if (r)
+   if (r != 0) {
+      /* failed */
       return r;
+   }
 
-#if ALLEGRO_SUB_VERSION&1
+#if ALLEGRO_SUB_VERSION & 1
    /* This is a WIP runtime, so enforce strict compatibility. */
-   version_ok = version == _get_allegro_version();
+   version_ok = version == MAKE_VERSION(ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, ALLEGRO_WIP_VERSION);
 #else
    /* This is a stable runtime, so the runtime should be at least as new
     * as the build headers (otherwise we may get a crash, since some


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