From: Christophe CURIS <[email protected]>

As reported by Nicolas (nhs), compilation of wrlib is broken when
switching to gif_lib v5.

The API of gif_lib has known little change to provide thread-safe usage,
so we now detect this in configure and and use the functions as appropriate
in gif.c

Signed-off-by: Christophe CURIS <[email protected]>
---
 m4/wm_imgfmt_check.m4 | 16 +++++++++++++---
 wrlib/gif.c           | 15 ++++++++++++++-
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/m4/wm_imgfmt_check.m4 b/m4/wm_imgfmt_check.m4
index ef3f478..8092b8a 100644
--- a/m4/wm_imgfmt_check.m4
+++ b/m4/wm_imgfmt_check.m4
@@ -19,7 +19,7 @@
 # WM_IMGFMT_CHECK_GIF
 # -------------------
 #
-# Check for GIF file support through 'libgif' or 'libungif'
+# Check for GIF file support through 'libgif', 'libungif' or 'giflib v5'
 # The check depends on variable 'enable_gif' being either:
 #   yes  - detect, fail if not found
 #   no   - do not detect, disable support
@@ -53,7 +53,17 @@ AS_IF([test "x$enable_gif" = "xno"],
               [AC_MSG_ERROR([found $wm_cv_imgfmt_gif but could not find 
appropriate header - are you missing libgif-dev package?])])
             AS_IF([wm_fn_imgfmt_try_compile "gif_lib.h" 
"DGifOpenFileName(filename)" ""],
               [wm_cv_imgfmt_gif="$wm_cv_imgfmt_gif version:4"],
-              [AC_MSG_ERROR([found $wm_cv_imgfmt_gif and header, but cannot 
compile - unsupported version?])])
+              [AC_COMPILE_IFELSE(
+                [AC_LANG_PROGRAM(
+                  [@%:@include <gif_lib.h>
+
+const char *filename = "dummy";],
+                  [  int error_code;
+  DGifOpenFileName(filename, &error_code);] )],
+                [wm_cv_imgfmt_gif="$wm_cv_imgfmt_gif version:5"],
+                [AC_MSG_ERROR([found $wm_cv_imgfmt_gif and header, but cannot 
compile - unsupported version?])])dnl
+              ]
+            )
             CFLAGS="$wm_save_CFLAGS"])
          ])
     AS_IF([test "x$wm_cv_imgfmt_gif" = "xno"],
@@ -62,7 +72,7 @@ AS_IF([test "x$enable_gif" = "xno"],
         [supported_gfx="$supported_gfx GIF"
          GFXLIBS="$GFXLIBS `echo "$wm_cv_imgfmt_gif" | sed -e 's, 
*version:.*,,' `"
          AC_DEFINE_UNQUOTED([USE_GIF],
-           [1],
+           [`echo "$wm_cv_imgfmt_gif" | sed -e 's,.*version:,,' `],
            [defined when valid GIF library with header was found])])
     ])
     AM_CONDITIONAL([USE_GIF], [test "x$enable_gif" != "xno"])dnl
diff --git a/wrlib/gif.c b/wrlib/gif.c
index e1b1a73..acbf7da 100644
--- a/wrlib/gif.c
+++ b/wrlib/gif.c
@@ -48,6 +48,7 @@ RImage *RLoadGIF(const char *file, int index)
        GifRecordType recType;
        ColorMapObject *colormap;
        unsigned char rmap[256], gmap[256], bmap[256];
+       int gif_error;
 
        if (index < 0)
                index = 0;
@@ -55,10 +56,17 @@ RImage *RLoadGIF(const char *file, int index)
        /* default error message */
        RErrorCode = RERR_BADINDEX;
 
+#if USE_GIF == 4
        gif = DGifOpenFileName(file);
+#else /* USE_GIF == 5 */
+       gif = DGifOpenFileName(file, &gif_error);
+#endif
 
        if (!gif) {
-               switch (GifLastError()) {
+#if USE_GIF == 4
+               gif_error = GifLastError();
+#endif
+               switch (gif_error) {
                case D_GIF_ERR_OPEN_FAILED:
                        RErrorCode = RERR_OPEN;
                        break;
@@ -182,6 +190,7 @@ RImage *RLoadGIF(const char *file, int index)
        /* yuck! */
        goto did_not_get_any_errors;
  giferr:
+#if USE_GIF == 4
        switch (GifLastError()) {
        case D_GIF_ERR_OPEN_FAILED:
                RErrorCode = RERR_OPEN;
@@ -193,6 +202,10 @@ RImage *RLoadGIF(const char *file, int index)
                RErrorCode = RERR_BADIMAGEFILE;
                break;
        }
+#else
+       /* With gif_lib v5 there's no way to know what went wrong */
+       RErrorCode = RERR_BADIMAGEFILE;
+#endif
  bye:
        if (image)
                RReleaseImage(image);
-- 
1.8.4.rc3


-- 
To unsubscribe, send mail to [email protected].

Reply via email to