Re: [AD] Re: binary compatibility check

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


On 2006-02-23, Peter Wang <tjaden@xxxxxxxxxx> wrote:
> On 2006-02-20, Elias Pschernig <elias@xxxxxxxxxx> wrote:
> > On Fri, 2006-02-17 at 14:52 -0800, Chris wrote:
> > > 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. :)
> > 
> > Thanks, committed. The Mingw port hopefully compiles again now.
> 
> Unfortunately binary compatilibity was broken since your combine r5668,
> r5671, r5672 change.  When I run a binary compiled against 4.2.0
> but dynamically linked to 4.2.1, I get a segfault (this is in linux).
> If I revert all the version checking changes then it works.

Here is the reason.  This is the definition of install_allegro() in
4.2.0:

    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"));
	  return !0;
       }

       return _install_allegro(system_id, errno_ptr, atexit_ptr);
    })

The call to get_config_text() calls get_executable_name() indirectly
before the system driver is installed leading to a segfault.  Elias
fixed this in r5668, but that doesn't help binaries compiled against
4.2.0 which have the get_config_text() call embedded.

I propose a patch for this special case in get_config_text() so as to
avoid the crash (attached).

However, that will still not allow binaries compiled with 4.2.0 to
compile with 4.2.1 because the comparison above uses !=, relying on the
fact that _get_allegro_version() would mask out the third component of
the version number, which it no longer does.  What should we do about
this?

Peter
--- src/config.c	(revision 5775)
+++ src/config.c	(local)
@@ -1304,7 +1304,7 @@ void reload_config_texts(AL_CONST char *
 AL_CONST char *get_config_text(AL_CONST char *msg)
 {
    char tmp1[256];
-   AL_CONST char *section = uconvert_ascii("[language]", tmp1);
+   AL_CONST char *section;
    AL_CONST char *umsg;
    AL_CONST char *s;
    AL_CONST char *ret = NULL;
@@ -1314,8 +1314,19 @@ AL_CONST char *get_config_text(AL_CONST 
    int c, pos, size;
    ASSERT(msg);
 
+   /* Hack: the inline definition of install_allegro() from 4.2.0 calls
+    * get_config_text() even before Allegro has been initialised, leading
+    * to a crash in get_executable_name().  To retain binary compatibility
+    * we check for this case.
+    */
+   if (_allegro_count == 0) {
+      return msg;
+   }
+
    init_config(TRUE);
 
+   section = uconvert_ascii("[language]", tmp1);
+
    /* allocate memory and convert message to current encoding format */
    if (need_uconvert(msg, U_ASCII, U_CURRENT)) {
       size = uconvert_size(msg, U_ASCII, U_CURRENT);


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