Re: [AD] Indexed datafiles

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


On Thu, 2006-01-05 at 14:49 -0800, Chris wrote:

> With backwards binary compatiblity (eg. only adding functions, not taking away 
> or changing struct sizes), I think the system would throw an error about 
> missing/unresolved functions before the program itself is ever run, if the 

True. Would that also work under Windows? It would be anothe reason to
not do the check for it in that case, I guess.

> program and DLL are incompatible (lazy checking). However, if you wanted to 
> enforce that older DLLs may not be used on programs compiled with newer 
> headers, something like this would be sufficient:

Ok, I attached a patch with just your version, only made the error
message print out the actual incompatible versions.

To make code work with 4.2.0 as well as 4.2.1, the following should be
enough with this:

#if MAKE_VERSION(ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, ALLEGRO_WIP_VERSION) >= MAKE_VERSION(4, 2, 1)
   /* use 4.2.1 only function */
#else
   /* work around, or quite with error */
#endif

The question is now, should the patch be applied as is, or should that
one (dll_wip < ALLEGRO_WIP_VERSION) condition be thrown out? Throwing it
out means, you can run 4.2.1 compiled programs with the 4.2.0 DLL, but
there's no warning. Leaving it in, Allegro will detect it and print an
error message (well, or maybe not since no system driver was
initialized, but that's a separate issue..). Running a 4.2.0 compiled
program with the 4.2.1 DLL will of course work in both cases.

-- 
Elias Pschernig
Index: include/allegro/system.h
===================================================================
--- include/allegro/system.h	(revision 5626)
+++ include/allegro/system.h	(working copy)
@@ -71,25 +71,39 @@
 #define SYSTEM_AUTODETECT  0
 #define SYSTEM_NONE        AL_ID('N','O','N','E')
 
-#if (ALLEGRO_SUB_VERSION&1)
 #define MAKE_VERSION(a, b, c) (((a)<<16)|((b)<<8)|(c))
-#else
-#define MAKE_VERSION(a, b, c) (((a)<<16)|((b)<<8))
-#endif
 
 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_INLINE(int, install_allegro, (int system_id, int *errno_ptr, AL_METHOD(int, atexit_ptr, (AL_METHOD(void, func, (void))))),
+AL_INLINE(int, install_allegro, (int system_id, int *errno_ptr,
+   AL_METHOD(int, atexit_ptr, (AL_METHOD(void, func, (void))))),
 {
-   if (MAKE_VERSION(ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, ALLEGRO_WIP_VERSION) !=
-       _get_allegro_version()) {
-      ustrzcpy(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Library version mismatch"));
+   int dll_v = _get_allegro_version(); /* This comes from the DLL. */
+
+#if ((ALLEGRO_SUB_VERSION&1) == 0)
+   int dll_wip = dll_v & 255;
+   int dll_ver = dll_v & ~255;
+
+   /* Check that the x.y versions match (eg. 4.2 = 4.2) and that the DLL WIP
+    * version is at least as new as the headers we were compiled with */
+   if ((dll_ver != MAKE_VERSION(ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, 0)) ||
+       (dll_wip < ALLEGRO_WIP_VERSION)) {
+#else
+   /* Enforce strict header x.y.z == lib x.y.z for WIP branches */
+   if (dll_v != MAKE_VERSION(ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, 
+      ALLEGRO_WIP_VERSION)) {
+#endif
+      uszprintf(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text(
+         "The detected dynamic Allegro library (%d.%d.%d) is "
+         "not compatible with this program (%d.%d.%d)."),
+         dll_ver >> 16, (dll_ver >> 8) & 255, dll_wip,
+         ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, ALLEGRO_WIP_VERSION);
       return !0;
    }
-
    return _install_allegro(system_id, errno_ptr, atexit_ptr);
 })
+
 #define allegro_init()  install_allegro(SYSTEM_AUTODETECT, &errno, (int (*)(void (*)(void)))atexit)
 AL_FUNC(void, allegro_exit, (void));
 


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