Subject: | Image::Scale uses deprecated PrintGifError() for giflib > 4.2.0 |
Date: | Thu, 22 Jan 2015 08:05:04 -0800 |
To: | bug-Image-Scale [...] rt.cpan.org |
From: | Mark Atkinson <atkin901 [...] gmail.com> |
Perl 5.18.4
Image::Scale 0.08
giflib 4.2.x
os: 11.0-CURRENT FreeBSD 11.0-CURRENT #1 r271093:271175: Fri Sep 5
10:37:26 PDT 2014
As FreeBSD ports maintainer for p5-Image-Scale I came up with the following
patch, which I won't submit since giflib 5.x introduces further
incompatibility with src/gif.c
However, this patch fixes the 4.2 series of giflib.
--- src/gif.c 2015-01-21 10:00:21.000000000 -0800
+++ src/gif.c 2015-01-21 10:17:54.000000000 -0800
@@ -17,7 +17,25 @@
static int InterlacedOffset[] = { 0, 4, 2, 1 };
static int InterlacedJumps[] = { 8, 8, 4, 2 };
-static int
+static void
+CompatPrintGifError(void)
+{
+/* Taking a cue and cut and pasto a bit from mac ports patches for this */
+/* issue */
+/* GIFLIB_MAJOR is only defined in libgif >= 4.2.0 */
+/* libgif 4.2.0 has retired PrintGifError() and added GifErrorString() */
+#if defined(GIFLIB_MAJOR) && defined(GIFLIB_MINOR) && \
+ ((GIFLIB_MAJOR == 4 && GIFLIB_MINOR >= 2) || GIFLIB_MAJOR > 4)
+ const char* giflib_error_str = (const char*) GifErrorString();
+ if (giflib_error_str == NULL)
+ giflib_error_str = "Unknown error";
+ warn("GIFLib Error: %s\n", giflib_error_str);
+#else
+ PrintGifError();
+#endif
+}
+
+static int
image_gif_read_buf(GifFileType *gif, GifByteType *data, int len)
{
image *im = (image *)gif->UserData;
@@ -57,8 +75,8 @@
{
im->gif = DGifOpen(im, image_gif_read_buf);
if (im->gif == NULL) {
- PrintGifError();
+ CompatPrintGifError();
warn("Image::Scale unable to open GIF file (%s)\n", SvPVX(im->path));
image_gif_finish(im);
return 0;
@@ -108,7 +125,7 @@
do {
if (DGifGetRecordType(im->gif, &RecordType) == GIF_ERROR) {
- PrintGifError();
+ CompatPrintGifError();
warn("Image::Scale unable to read GIF file (%s)\n", SvPVX(im->path));
image_gif_finish(im);
return 0;
@@ -117,7 +134,7 @@
switch (RecordType) {
case IMAGE_DESC_RECORD_TYPE:
if (DGifGetImageDesc(im->gif) == GIF_ERROR) {
- PrintGifError();
+ CompatPrintGifError();
warn("Image::Scale unable to read GIF file (%s)\n",
SvPVX(im->path));
image_gif_finish(im);
return 0;
@@ -148,7 +165,7 @@
for (x = InterlacedOffset[i]; x < im->height; x +=
InterlacedJumps[i]) {
ofs = x * im->width;
if (DGifGetLine(im->gif, line, 0) != GIF_OK) {
- PrintGifError();
+ CompatPrintGifError();
warn("Image::Scale unable to read GIF file (%s)\n",
SvPVX(im->path));
image_gif_finish(im);
return 0;
@@ -170,7 +187,7 @@
ofs = 0;
for (x = 0; x < im->height; x++) {
if (DGifGetLine(im->gif, line, 0) != GIF_OK) {
- PrintGifError();
+ CompatPrintGifError();
warn("Image::Scale unable to read GIF file (%s)\n",
SvPVX(im->path));
image_gif_finish(im);
return 0;
@@ -193,7 +210,7 @@
case EXTENSION_RECORD_TYPE:
if (DGifGetExtension(im->gif, &temp_save.Function, &ExtData) ==
GIF_ERROR) {
- PrintGifError();
+ CompatPrintGifError();
warn("Image::Scale unable to read GIF file (%s)\n",
SvPVX(im->path));
image_gif_finish(im);
return 0;
@@ -211,14 +228,14 @@
while (ExtData != NULL) {
/* Create an extension block with our data */
if (AddExtensionBlock(&temp_save, ExtData[0], &ExtData[1]) ==
GIF_ERROR) {
- PrintGifError();
+ CompatPrintGifError();
warn("Image::Scale unable to read GIF file (%s)\n",
SvPVX(im->path));
image_gif_finish(im);
return 0;
}
if (DGifGetExtensionNext(im->gif, &ExtData) == GIF_ERROR) {
- PrintGifError();
+ CompatPrintGifError();
warn("Image::Scale unable to read GIF file (%s)\n",
SvPVX(im->path));
image_gif_finish(im);
return 0;
@@ -242,7 +259,7 @@
{
if (im->gif != NULL) {
if (DGifCloseFile(im->gif) != GIF_OK) {
- PrintGifError();
+ CompatPrintGifError();
warn("Image::Scale unable to close GIF file (%s)\n",
SvPVX(im->path));
}
im->gif = NULL;