Re: [AD] Re: binary compatibility check |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Wed, 2006-02-08 at 11:29 +0100, Elias Pschernig wrote:
> Since this code looks so ugly now though, I'm wondering about changing
> _install_allegro to get a 4th parameter with the compile-time version,
> and then simply have this:
>
> #define allegro_init _install_allegro(SYSTEM_AUTODETECT, errno, atexit, MAKE_VERSION(...))
>
> And let install_allegro again be a normal function, which simply calls
> _install_allegro. It would mean, only allegro_init could do the version
> check, but that should be enough, and all involved code stays clean.
The attached patch does just that. I left the current allegro_install
intact, since I'm not sure how changing an AL_INLINE function to a
normal function affects binary compatibility.
--
Elias Pschernig
Index: include/allegro/system.h
===================================================================
--- include/allegro/system.h (revision 5704)
+++ include/allegro/system.h (working copy)
@@ -75,37 +75,20 @@
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))))),
{
- int r = _install_allegro(system_id, errno_ptr, atexit_ptr);
- int dll_v = _get_allegro_version(); /* This comes from the DLL. */
- int dll_wip = dll_v & 255;
- int dll_ver = dll_v & ~255;
-
-#if ((ALLEGRO_SUB_VERSION&1) == 0)
-
- /* 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 r;
+ return _install_allegro(system_id, errno_ptr, atexit_ptr);
})
-#define allegro_init() install_allegro(SYSTEM_AUTODETECT, &errno, (int (*)(void (*)(void)))atexit)
+
+#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);
Index: src/allegro.c
===================================================================
--- src/allegro.c (revision 5704)
+++ src/allegro.c (working copy)
@@ -411,6 +411,48 @@
+/* _install_allegro_version_check:
+ * 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)
+{
+ int r = _install_allegro(system_id, errno_ptr, atexit_ptr);
+
+ int build_wip = version & 255;
+ int build_ver = version & ~255;
+
+ int version_ok;
+
+ if (r)
+ return r;
+
+#if ALLEGRO_SUB_VERSION&1
+ /* This is a WIP runtime, so enforce strict compatibility. */
+ version_ok = version == _get_allegro_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
+ * functions may have been used which aren't available in this runtime).
+ */
+ version_ok = (MAKE_VERSION(ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, 0) == build_ver) &&
+ (ALLEGRO_WIP_VERSION >= build_wip);
+#endif
+
+ if (!version_ok) {
+ 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)."),
+ ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, ALLEGRO_WIP_VERSION,
+ build_ver >> 16, (build_ver >> 8) & 255, build_wip);
+ return -1;
+ }
+ return 0;
+}
+
+
+
/* allegro_exit:
* Closes down the Allegro system.
*/