Subject: bug#51484: [PATCH] Move runtime check for recent giflib to compile time

From: Stefan Kangas <[email-masked]>
Date: Fri, 29 Oct 2021 09:30:40 -0700

Eli Zaretskii <[email-masked]> writes:

> (What patch?)

Oops, let's try that again.

> The compiler converts that into a run-time constant anyway.  The
> reason for using such "run-time" testing is usually to have a more
> readable code, since #ifdef's make the code harder to read.  There are
> no downsides, since the test is compiled away.

Right, hence my asking what you all think of the patch.  Which is now
hopefully also attached.
From ee975ee6b2c9496c49cfb36aa22acab9ceca2d32 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Fri, 29 Oct 2021 15:24:26 +0200
Subject: [PATCH] Move runtime check for recent giflib to compile time

* src/image.c
(interlace_start, interlace_increment) [GIFLIB_MAJOR < 5]:
Don't define when using recent giflib.
(gif_load): Replace runtime check for "GIFLIB_MAJOR < 5" with
preprocessor directive.
---
 src/image.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/image.c b/src/image.c
index 99533bbd1b..0f105131aa 100644
--- a/src/image.c
+++ b/src/image.c
@@ -8358,8 +8358,10 @@ gif_close (GifFileType *gif, int *err)
 /* Load GIF image IMG for use on frame F.  Value is true if
    successful.  */
 
+#if GIFLIB_MAJOR < 5
 static const int interlace_start[] = {0, 4, 2, 1};
 static const int interlace_increment[] = {8, 8, 4, 2};
+#endif
 
 #define GIF_LOCAL_DESCRIPTOR_EXTENSION 249
 
@@ -8626,7 +8628,8 @@ gif_load (struct frame *f, struct image *img)
 	  }
 
       /* Apply the pixel values.  */
-      if (GIFLIB_MAJOR < 5 && gif->SavedImages[j].ImageDesc.Interlace)
+#if GIFLIB_MAJOR < 5
+      if (gif->SavedImages[j].ImageDesc.Interlace)
 	{
 	  int row, pass;
 
@@ -8650,6 +8653,7 @@ gif_load (struct frame *f, struct image *img)
 	}
       else
 	{
+#endif
           for (y = 0; y < subimg_height; ++y)
 	    for (x = 0; x < subimg_width; ++x)
 	      {
@@ -8661,7 +8665,9 @@ gif_load (struct frame *f, struct image *img)
                   }
 	      }
 	}
+#if GIFLIB_MAJOR < 5
     }
+#endif
 
 #ifdef COLOR_TABLE_SUPPORT
   img->colors = colors_in_color_table (&img->ncolors);
-- 
2.30.2