Re: [AD] Re: binary compatibility check |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: alleg-developers@xxxxxxxxxx
- Subject: Re: [AD] Re: binary compatibility check
- From: Chris <chris.kcat@xxxxxxxxxx>
- Date: Fri, 17 Feb 2006 14:52:09 -0800
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:from:to:subject:date:user-agent:references:in-reply-to:mime-version:content-type:message-id; b=cxIm+ofYmpg+mLSet/ikznfEWuXu0hvFAy4aDgM0iOcQ+jR0+e8WcQeB75RMGAW8FUQ1d96spLRqG+07wsd0lRP1nuAaJ6H9UGANyeVo+JJC14YHL6UK40RxdRTxbxVZn0jDzPLe/ZOXruGV8WCtiv/J/n9Me7CmdKsHa231p2c=
On Friday 17 February 2006 14:44, Elias Pschernig wrote:
> Oh, and KittyCat just pointed out in #allegro that
> _install_allegro_version_check can also be called frin install_allegro,
> so when applying the patch, install_allegro would be modified to look
> like install_allegro, and the comment removed.
This patch should work. :)
Index: include/allegro/system.h
===================================================================
--- include/allegro/system.h (revision 5716)
+++ include/allegro/system.h (working copy)
@@ -75,37 +75,21 @@
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_version_check(system_id, errno_ptr, atexit_ptr, \
+ MAKE_VERSION(ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, ALLEGRO_WIP_VERSION));
})
-#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 5716)
+++ 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.
*/