summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-09-10 02:39:13 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2015-09-10 02:44:41 -0700
commit6ee7eabb5dbdf39f2d7471c9e42fc90c315e6a9f (patch)
treef3534f8cd5fa457d3a8ba09760a246eca6e1f142
parent831945a1cb675444fb819d8b820cd65402930545 (diff)
downloademacs-6ee7eabb5dbdf39f2d7471c9e42fc90c315e6a9f.tar.gz
Port to GIFLIB 5.0.6 and later
Problem reported by Mitchel Humpherys in: http://lists.gnu.org/archive/html/emacs-devel/2015-09/msg00420.html * src/image.c (HAVE_GIFERRORSTRING) [HAVE_GIF]: New macro. (GifErrorString, init_gif_functions) [HAVE_GIF && WINDOWSNT]: (gif_load) [HAVE_GIF]: Use it.
-rw-r--r--src/image.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/image.c b/src/image.c
index 85cf801f6a9..2aa01e4a990 100644
--- a/src/image.c
+++ b/src/image.c
@@ -7499,6 +7499,12 @@ gif_image_p (Lisp_Object object)
# define GIFLIB_MAJOR 4
# endif
+/* GifErrorString is declared to return char const * when GIFLIB_MAJOR
+ and GIFLIB_MINOR indicate 5.1 or later. Do not bother using it in
+ earlier releases, where either it returns char * or GIFLIB_MINOR
+ may be incorrect. */
+# define HAVE_GIFERRORSTRING (5 < GIFLIB_MAJOR + (1 <= GIFLIB_MINOR))
+
# ifdef WINDOWSNT
/* GIF library details. */
@@ -7514,7 +7520,9 @@ DEF_DLL_FN (GifFileType *, DGifOpenFileName, (const char *));
# else
DEF_DLL_FN (GifFileType *, DGifOpen, (void *, InputFunc, int *));
DEF_DLL_FN (GifFileType *, DGifOpenFileName, (const char *, int *));
-DEF_DLL_FN (char *, GifErrorString, (int));
+# endif
+# if HAVE_GIFERRORSTRING
+DEF_DLL_FN (char const *, GifErrorString, (int));
# endif
static bool
@@ -7529,7 +7537,7 @@ init_gif_functions (void)
LOAD_DLL_FN (library, DGifSlurp);
LOAD_DLL_FN (library, DGifOpen);
LOAD_DLL_FN (library, DGifOpenFileName);
-# if GIFLIB_MAJOR >= 5
+# if HAVE_GIFERRORSTRING
LOAD_DLL_FN (library, GifErrorString);
# endif
return 1;
@@ -7641,20 +7649,19 @@ gif_load (struct frame *f, struct image *img)
/* Open the GIF file. */
#if GIFLIB_MAJOR < 5
gif = DGifOpenFileName (SSDATA (encoded_file));
- if (gif == NULL)
- {
- image_error ("Cannot open `%s'", file);
- return 0;
- }
#else
gif = DGifOpenFileName (SSDATA (encoded_file), &gif_err);
+#endif
if (gif == NULL)
{
+#if HAVE_GIFERRORSTRING
image_error ("Cannot open `%s': %s",
file, build_string (GifErrorString (gif_err)));
+#else
+ image_error ("Cannot open `%s'", file);
+#endif
return 0;
}
-#endif
}
else
{
@@ -7672,20 +7679,19 @@ gif_load (struct frame *f, struct image *img)
#if GIFLIB_MAJOR < 5
gif = DGifOpen (&memsrc, gif_read_from_memory);
- if (!gif)
- {
- image_error ("Cannot open memory source `%s'", img->spec);
- return 0;
- }
#else
gif = DGifOpen (&memsrc, gif_read_from_memory, &gif_err);
+#endif
if (!gif)
{
+#if HAVE_GIFERRORSTRING
image_error ("Cannot open memory source `%s': %s",
img->spec, build_string (GifErrorString (gif_err)));
+#else
+ image_error ("Cannot open memory source `%s'", img->spec);
+#endif
return 0;
}
-#endif
}
/* Before reading entire contents, check the declared image size. */
@@ -7980,8 +7986,8 @@ gif_load (struct frame *f, struct image *img)
if (gif_close (gif, &gif_err) == GIF_ERROR)
{
-#if 5 <= GIFLIB_MAJOR
- char *error_text = GifErrorString (gif_err);
+#if HAVE_GIFERRORSTRING
+ char const *error_text = GifErrorString (gif_err);
if (error_text)
image_error ("Error closing `%s': %s",