libtiff: Changes to allow building with cmake -DCMAKE_UNITY_BUILD=ON

From 2a78a5bcfb3f1514630383429a2be6afa8f6c834 Mon Sep 17 00:00:00 2001
From: Even Rouault <[EMAIL REDACTED]>
Date: Wed, 22 Nov 2023 19:40:47 +0100
Subject: [PATCH] Changes to allow building with cmake -DCMAKE_UNITY_BUILD=ON

---
 libtiff/CMakeLists.txt           |  4 ++++
 libtiff/tif_dirread.c            |  8 ++-----
 libtiff/tif_lerc.c               | 30 +++++++++++++-------------
 libtiff/tif_lzma.c               | 28 ++++++++++++-------------
 libtiff/tif_lzw.c                | 36 ++++++++++++++++----------------
 libtiff/tif_pixarlog.c           | 18 ++++++++--------
 libtiff/tif_zip.c                | 28 ++++++++++++-------------
 libtiff/tif_zstd.c               | 28 ++++++++++++-------------
 test/rational_precision2double.c |  2 --
 9 files changed, 90 insertions(+), 92 deletions(-)

diff --git a/libtiff/CMakeLists.txt b/libtiff/CMakeLists.txt
index a675f19d..1f36360f 100755
--- a/libtiff/CMakeLists.txt
+++ b/libtiff/CMakeLists.txt
@@ -98,6 +98,10 @@ target_sources(tiff PRIVATE
         tif_zip.c
         tif_zstd.c)
 
+if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16)
+  set_property(SOURCE tif_jpeg.c tif_jpeg12.c PROPERTY SKIP_UNITY_BUILD_INCLUSION ON)
+endif ()
+
 if(USE_WIN32_FILEIO)
   target_sources(tiff PRIVATE tif_win32.c)
 else()
diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
index 122ec34d..c7969414 100644
--- a/libtiff/tif_dirread.c
+++ b/libtiff/tif_dirread.c
@@ -5256,9 +5256,7 @@ int TIFFReadCustomDirectory(TIFF *tif, toff_t diroff,
  */
 int TIFFReadEXIFDirectory(TIFF *tif, toff_t diroff)
 {
-    const TIFFFieldArray *exifFieldArray;
-    exifFieldArray = _TIFFGetExifFields();
-    return TIFFReadCustomDirectory(tif, diroff, exifFieldArray);
+    return TIFFReadCustomDirectory(tif, diroff, _TIFFGetExifFields());
 }
 
 /*
@@ -5266,9 +5264,7 @@ int TIFFReadEXIFDirectory(TIFF *tif, toff_t diroff)
  */
 int TIFFReadGPSDirectory(TIFF *tif, toff_t diroff)
 {
-    const TIFFFieldArray *gpsFieldArray;
-    gpsFieldArray = _TIFFGetGpsFields();
-    return TIFFReadCustomDirectory(tif, diroff, gpsFieldArray);
+    return TIFFReadCustomDirectory(tif, diroff, _TIFFGetGpsFields());
 }
 
 static int EstimateStripByteCounts(TIFF *tif, TIFFDirEntry *dir,
diff --git a/libtiff/tif_lerc.c b/libtiff/tif_lerc.c
index 4f357a60..b2a3eb8a 100644
--- a/libtiff/tif_lerc.c
+++ b/libtiff/tif_lerc.c
@@ -86,9 +86,9 @@ typedef struct
     TIFFVSetMethod vsetparent; /* super-class method */
 } LERCState;
 
-#define LState(tif) ((LERCState *)(tif)->tif_data)
-#define DecoderState(tif) LState(tif)
-#define EncoderState(tif) LState(tif)
+#define GetLERCState(tif) ((LERCState *)(tif)->tif_data)
+#define LERCDecoderState(tif) GetLERCState(tif)
+#define LERCEncoderState(tif) GetLERCState(tif)
 
 static int LERCEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s);
 static int LERCDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s);
@@ -101,7 +101,7 @@ static int LERCFixupTags(TIFF *tif)
 
 static int LERCSetupDecode(TIFF *tif)
 {
-    LERCState *sp = DecoderState(tif);
+    LERCState *sp = LERCDecoderState(tif);
 
     assert(sp != NULL);
 
@@ -277,7 +277,7 @@ static int LERCPreDecode(TIFF *tif, uint16_t s)
     static const char module[] = "LERCPreDecode";
     lerc_status lerc_ret;
     TIFFDirectory *td = &tif->tif_dir;
-    LERCState *sp = DecoderState(tif);
+    LERCState *sp = LERCDecoderState(tif);
     int lerc_data_type;
     unsigned int infoArray[8];
     unsigned nomask_bands = td->td_samplesperpixel;
@@ -553,7 +553,7 @@ static int LERCPreDecode(TIFF *tif, uint16_t s)
 static int LERCDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
 {
     static const char module[] = "LERCDecode";
-    LERCState *sp = DecoderState(tif);
+    LERCState *sp = LERCDecoderState(tif);
 
     (void)s;
     assert(sp != NULL);
@@ -580,7 +580,7 @@ static int LERCDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
 
 static int LERCSetupEncode(TIFF *tif)
 {
-    LERCState *sp = EncoderState(tif);
+    LERCState *sp = LERCEncoderState(tif);
 
     assert(sp != NULL);
     if (sp->state & LSTATE_INIT_DECODE)
@@ -599,7 +599,7 @@ static int LERCSetupEncode(TIFF *tif)
 static int LERCPreEncode(TIFF *tif, uint16_t s)
 {
     static const char module[] = "LERCPreEncode";
-    LERCState *sp = EncoderState(tif);
+    LERCState *sp = LERCEncoderState(tif);
     int lerc_data_type;
 
     (void)s;
@@ -623,7 +623,7 @@ static int LERCPreEncode(TIFF *tif, uint16_t s)
 static int LERCEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
 {
     static const char module[] = "LERCEncode";
-    LERCState *sp = EncoderState(tif);
+    LERCState *sp = LERCEncoderState(tif);
 
     (void)s;
     assert(sp != NULL);
@@ -649,7 +649,7 @@ static int LERCPostEncode(TIFF *tif)
 {
     lerc_status lerc_ret;
     static const char module[] = "LERCPostEncode";
-    LERCState *sp = EncoderState(tif);
+    LERCState *sp = LERCEncoderState(tif);
     unsigned int numBytes = 0;
     unsigned int numBytesWritten = 0;
     TIFFDirectory *td = &tif->tif_dir;
@@ -950,7 +950,7 @@ static int LERCPostEncode(TIFF *tif)
 
 static void LERCCleanup(TIFF *tif)
 {
-    LERCState *sp = LState(tif);
+    LERCState *sp = GetLERCState(tif);
 
     assert(sp != 0);
 
@@ -995,7 +995,7 @@ static const TIFFField LERCFields[] = {
 
 static int LERCVSetFieldBase(TIFF *tif, uint32_t tag, ...)
 {
-    LERCState *sp = LState(tif);
+    LERCState *sp = GetLERCState(tif);
     int ret;
     va_list ap;
     va_start(ap, tag);
@@ -1007,7 +1007,7 @@ static int LERCVSetFieldBase(TIFF *tif, uint32_t tag, ...)
 static int LERCVSetField(TIFF *tif, uint32_t tag, va_list ap)
 {
     static const char module[] = "LERCVSetField";
-    LERCState *sp = LState(tif);
+    LERCState *sp = GetLERCState(tif);
 
     switch (tag)
     {
@@ -1115,7 +1115,7 @@ static int LERCVSetField(TIFF *tif, uint32_t tag, va_list ap)
 
 static int LERCVGetField(TIFF *tif, uint32_t tag, va_list ap)
 {
-    LERCState *sp = LState(tif);
+    LERCState *sp = GetLERCState(tif);
 
     switch (tag)
     {
@@ -1163,7 +1163,7 @@ int TIFFInitLERC(TIFF *tif, int scheme)
     tif->tif_data = (uint8_t *)_TIFFcallocExt(tif, 1, sizeof(LERCState));
     if (tif->tif_data == NULL)
         goto bad;
-    sp = LState(tif);
+    sp = GetLERCState(tif);
 
     /*
      * Override parent get/set field methods.
diff --git a/libtiff/tif_lzma.c b/libtiff/tif_lzma.c
index 4cfd5e88..6fdc9280 100644
--- a/libtiff/tif_lzma.c
+++ b/libtiff/tif_lzma.c
@@ -58,9 +58,9 @@ typedef struct
     TIFFVSetMethod vsetparent; /* super-class method */
 } LZMAState;
 
-#define LState(tif) ((LZMAState *)(tif)->tif_data)
-#define DecoderState(tif) LState(tif)
-#define EncoderState(tif) LState(tif)
+#define GetLZMAState(tif) ((LZMAState *)(tif)->tif_data)
+#define LZMADecoderState(tif) GetLZMAState(tif)
+#define LZMAEncoderState(tif) GetLZMAState(tif)
 
 static int LZMAEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s);
 static int LZMADecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s);
@@ -106,7 +106,7 @@ static int LZMAFixupTags(TIFF *tif)
 
 static int LZMASetupDecode(TIFF *tif)
 {
-    LZMAState *sp = DecoderState(tif);
+    LZMAState *sp = LZMADecoderState(tif);
 
     assert(sp != NULL);
 
@@ -127,7 +127,7 @@ static int LZMASetupDecode(TIFF *tif)
 static int LZMAPreDecode(TIFF *tif, uint16_t s)
 {
     static const char module[] = "LZMAPreDecode";
-    LZMAState *sp = DecoderState(tif);
+    LZMAState *sp = LZMADecoderState(tif);
     lzma_ret ret;
 
     (void)s;
@@ -162,7 +162,7 @@ static int LZMAPreDecode(TIFF *tif, uint16_t s)
 static int LZMADecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
 {
     static const char module[] = "LZMADecode";
-    LZMAState *sp = DecoderState(tif);
+    LZMAState *sp = LZMADecoderState(tif);
 
     (void)s;
     assert(sp != NULL);
@@ -232,7 +232,7 @@ static int LZMADecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
 
 static int LZMASetupEncode(TIFF *tif)
 {
-    LZMAState *sp = EncoderState(tif);
+    LZMAState *sp = LZMAEncoderState(tif);
 
     assert(sp != NULL);
     if (sp->state & LSTATE_INIT_DECODE)
@@ -251,7 +251,7 @@ static int LZMASetupEncode(TIFF *tif)
 static int LZMAPreEncode(TIFF *tif, uint16_t s)
 {
     static const char module[] = "LZMAPreEncode";
-    LZMAState *sp = EncoderState(tif);
+    LZMAState *sp = LZMAEncoderState(tif);
     lzma_ret ret;
 
     (void)s;
@@ -283,7 +283,7 @@ static int LZMAPreEncode(TIFF *tif, uint16_t s)
 static int LZMAEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
 {
     static const char module[] = "LZMAEncode";
-    LZMAState *sp = EncoderState(tif);
+    LZMAState *sp = LZMAEncoderState(tif);
 
     assert(sp != NULL);
     assert(sp->state == LSTATE_INIT_ENCODE);
@@ -329,7 +329,7 @@ static int LZMAEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
 static int LZMAPostEncode(TIFF *tif)
 {
     static const char module[] = "LZMAPostEncode";
-    LZMAState *sp = EncoderState(tif);
+    LZMAState *sp = LZMAEncoderState(tif);
     lzma_ret ret;
 
     sp->stream.avail_in = 0;
@@ -365,7 +365,7 @@ static int LZMAPostEncode(TIFF *tif)
 
 static void LZMACleanup(TIFF *tif)
 {
-    LZMAState *sp = LState(tif);
+    LZMAState *sp = GetLZMAState(tif);
 
     assert(sp != 0);
 
@@ -388,7 +388,7 @@ static void LZMACleanup(TIFF *tif)
 static int LZMAVSetField(TIFF *tif, uint32_t tag, va_list ap)
 {
     static const char module[] = "LZMAVSetField";
-    LZMAState *sp = LState(tif);
+    LZMAState *sp = GetLZMAState(tif);
 
     switch (tag)
     {
@@ -414,7 +414,7 @@ static int LZMAVSetField(TIFF *tif, uint32_t tag, va_list ap)
 
 static int LZMAVGetField(TIFF *tif, uint32_t tag, va_list ap)
 {
-    LZMAState *sp = LState(tif);
+    LZMAState *sp = GetLZMAState(tif);
 
     switch (tag)
     {
@@ -457,7 +457,7 @@ int TIFFInitLZMA(TIFF *tif, int scheme)
     tif->tif_data = (uint8_t *)_TIFFmallocExt(tif, sizeof(LZMAState));
     if (tif->tif_data == NULL)
         goto bad;
-    sp = LState(tif);
+    sp = GetLZMAState(tif);
     memcpy(&sp->stream, &tmp_stream, sizeof(lzma_stream));
 
     /*
diff --git a/libtiff/tif_lzw.c b/libtiff/tif_lzw.c
index 5cd536d5..05ac8aa1 100644
--- a/libtiff/tif_lzw.c
+++ b/libtiff/tif_lzw.c
@@ -161,8 +161,8 @@ typedef struct
 } LZWCodecState;
 
 #define LZWState(tif) ((LZWBaseState *)(tif)->tif_data)
-#define DecoderState(tif) ((LZWCodecState *)LZWState(tif))
-#define EncoderState(tif) ((LZWCodecState *)LZWState(tif))
+#define LZWDecoderState(tif) ((LZWCodecState *)LZWState(tif))
+#define LZWEncoderState(tif) ((LZWCodecState *)LZWState(tif))
 
 static int LZWDecode(TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s);
 #ifdef LZW_COMPAT
@@ -183,7 +183,7 @@ static int LZWFixupTags(TIFF *tif)
 static int LZWSetupDecode(TIFF *tif)
 {
     static const char module[] = "LZWSetupDecode";
-    LZWCodecState *sp = DecoderState(tif);
+    LZWCodecState *sp = LZWDecoderState(tif);
     int code;
 
     if (sp == NULL)
@@ -199,7 +199,7 @@ static int LZWSetupDecode(TIFF *tif)
             return (0);
         }
 
-        sp = DecoderState(tif);
+        sp = LZWDecoderState(tif);
         sp->dec_codetab = NULL;
         sp->dec_decode = NULL;
 
@@ -245,7 +245,7 @@ static int LZWSetupDecode(TIFF *tif)
 static int LZWPreDecode(TIFF *tif, uint16_t s)
 {
     static const char module[] = "LZWPreDecode";
-    LZWCodecState *sp = DecoderState(tif);
+    LZWCodecState *sp = LZWDecoderState(tif);
 
     (void)s;
     assert(sp != NULL);
@@ -403,7 +403,7 @@ static int LZWPreDecode(TIFF *tif, uint16_t s)
 static int LZWDecode(TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s)
 {
     static const char module[] = "LZWDecode";
-    LZWCodecState *sp = DecoderState(tif);
+    LZWCodecState *sp = LZWDecoderState(tif);
     uint8_t *op = (uint8_t *)op0;
     tmsize_t occ = occ0;
     uint8_t *bp;
@@ -794,7 +794,7 @@ static int LZWDecode(TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s)
 static int LZWDecodeCompat(TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s)
 {
     static const char module[] = "LZWDecodeCompat";
-    LZWCodecState *sp = DecoderState(tif);
+    LZWCodecState *sp = LZWDecoderState(tif);
     uint8_t *op = (uint8_t *)op0;
     tmsize_t occ = occ0;
     uint8_t *tp;
@@ -1020,7 +1020,7 @@ static int LZWDecodeCompat(TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s)
 static int LZWSetupEncode(TIFF *tif)
 {
     static const char module[] = "LZWSetupEncode";
-    LZWCodecState *sp = EncoderState(tif);
+    LZWCodecState *sp = LZWEncoderState(tif);
 
     assert(sp != NULL);
     sp->enc_hashtab = (hash_t *)_TIFFmallocExt(tif, HSIZE * sizeof(hash_t));
@@ -1037,7 +1037,7 @@ static int LZWSetupEncode(TIFF *tif)
  */
 static int LZWPreEncode(TIFF *tif, uint16_t s)
 {
-    LZWCodecState *sp = EncoderState(tif);
+    LZWCodecState *sp = LZWEncoderState(tif);
 
     (void)s;
     assert(sp != NULL);
@@ -1108,7 +1108,7 @@ static int LZWPreEncode(TIFF *tif, uint16_t s)
  */
 static int LZWEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
 {
-    register LZWCodecState *sp = EncoderState(tif);
+    register LZWCodecState *sp = LZWEncoderState(tif);
     register long fcode;
     register hash_t *hp;
     register int h, c;
@@ -1293,7 +1293,7 @@ static int LZWEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
  */
 static int LZWPostEncode(TIFF *tif)
 {
-    register LZWCodecState *sp = EncoderState(tif);
+    register LZWCodecState *sp = LZWEncoderState(tif);
     uint8_t *op = tif->tif_rawcp;
     long nextbits = sp->lzw_nextbits;
     WordType nextdata = sp->lzw_nextdata;
@@ -1375,11 +1375,11 @@ static void LZWCleanup(TIFF *tif)
 
     assert(tif->tif_data != 0);
 
-    if (DecoderState(tif)->dec_codetab)
-        _TIFFfreeExt(tif, DecoderState(tif)->dec_codetab);
+    if (LZWDecoderState(tif)->dec_codetab)
+        _TIFFfreeExt(tif, LZWDecoderState(tif)->dec_codetab);
 
-    if (EncoderState(tif)->enc_hashtab)
-        _TIFFfreeExt(tif, EncoderState(tif)->enc_hashtab);
+    if (LZWEncoderState(tif)->enc_hashtab)
+        _TIFFfreeExt(tif, LZWEncoderState(tif)->enc_hashtab);
 
     _TIFFfreeExt(tif, tif->tif_data);
     tif->tif_data = NULL;
@@ -1398,9 +1398,9 @@ int TIFFInitLZW(TIFF *tif, int scheme)
     tif->tif_data = (uint8_t *)_TIFFmallocExt(tif, sizeof(LZWCodecState));
     if (tif->tif_data == NULL)
         goto bad;
-    DecoderState(tif)->dec_codetab = NULL;
-    DecoderState(tif)->dec_decode = NULL;
-    EncoderState(tif)->enc_hashtab = NULL;
+    LZWDecoderState(tif)->dec_codetab = NULL;
+    LZWDecoderState(tif)->dec_decode = NULL;
+    LZWEncoderState(tif)->enc_hashtab = NULL;
     LZWState(tif)->rw_mode = tif->tif_mode;
 
     /*
diff --git a/libtiff/tif_pixarlog.c b/libtiff/tif_pixarlog.c
index 5c0346b6..5ed921eb 100644
--- a/libtiff/tif_pixarlog.c
+++ b/libtiff/tif_pixarlog.c
@@ -670,8 +670,8 @@ static int PixarLogMakeTables(TIFF *tif, PixarLogState *sp)
     return 1;
 }
 
-#define DecoderState(tif) ((PixarLogState *)(tif)->tif_data)
-#define EncoderState(tif) ((PixarLogState *)(tif)->tif_data)
+#define PixarLogDecoderState(tif) ((PixarLogState *)(tif)->tif_data)
+#define PixarLogEncoderState(tif) ((PixarLogState *)(tif)->tif_data)
 
 static int PixarLogEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s);
 static int PixarLogDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s);
@@ -740,7 +740,7 @@ static int PixarLogSetupDecode(TIFF *tif)
 {
     static const char module[] = "PixarLogSetupDecode";
     TIFFDirectory *td = &tif->tif_dir;
-    PixarLogState *sp = DecoderState(tif);
+    PixarLogState *sp = PixarLogDecoderState(tif);
     tmsize_t tbuf_size;
     uint32_t strip_height;
 
@@ -813,7 +813,7 @@ static int PixarLogSetupDecode(TIFF *tif)
 static int PixarLogPreDecode(TIFF *tif, uint16_t s)
 {
     static const char module[] = "PixarLogPreDecode";
-    PixarLogState *sp = DecoderState(tif);
+    PixarLogState *sp = PixarLogDecoderState(tif);
 
     (void)s;
     assert(sp != NULL);
@@ -835,7 +835,7 @@ static int PixarLogDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
 {
     static const char module[] = "PixarLogDecode";
     TIFFDirectory *td = &tif->tif_dir;
-    PixarLogState *sp = DecoderState(tif);
+    PixarLogState *sp = PixarLogDecoderState(tif);
     tmsize_t i;
     tmsize_t nsamples;
     int llen;
@@ -988,7 +988,7 @@ static int PixarLogSetupEncode(TIFF *tif)
 {
     static const char module[] = "PixarLogSetupEncode";
     TIFFDirectory *td = &tif->tif_dir;
-    PixarLogState *sp = EncoderState(tif);
+    PixarLogState *sp = PixarLogEncoderState(tif);
     tmsize_t tbuf_size;
 
     assert(sp != NULL);
@@ -1038,7 +1038,7 @@ static int PixarLogSetupEncode(TIFF *tif)
 static int PixarLogPreEncode(TIFF *tif, uint16_t s)
 {
     static const char module[] = "PixarLogPreEncode";
-    PixarLogState *sp = EncoderState(tif);
+    PixarLogState *sp = PixarLogEncoderState(tif);
 
     (void)s;
     assert(sp != NULL);
@@ -1294,7 +1294,7 @@ static int PixarLogEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
 {
     static const char module[] = "PixarLogEncode";
     TIFFDirectory *td = &tif->tif_dir;
-    PixarLogState *sp = EncoderState(tif);
+    PixarLogState *sp = PixarLogEncoderState(tif);
     tmsize_t i;
     tmsize_t n;
     int llen;
@@ -1401,7 +1401,7 @@ static int PixarLogEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
 static int PixarLogPostEncode(TIFF *tif)
 {
     static const char module[] = "PixarLogPostEncode";
-    PixarLogState *sp = EncoderState(tif);
+    PixarLogState *sp = PixarLogEncoderState(tif);
     int state;
 
     sp->stream.avail_in = 0;
diff --git a/libtiff/tif_zip.c b/libtiff/tif_zip.c
index fcf51004..a351ba56 100644
--- a/libtiff/tif_zip.c
+++ b/libtiff/tif_zip.c
@@ -83,9 +83,9 @@ typedef struct
     TIFFVSetMethod vsetparent; /* super-class method */
 } ZIPState;
 
-#define ZState(tif) ((ZIPState *)(tif)->tif_data)
-#define DecoderState(tif) ZState(tif)
-#define EncoderState(tif) ZState(tif)
+#define GetZIPState(tif) ((ZIPState *)(tif)->tif_data)
+#define ZIPDecoderState(tif) GetZIPState(tif)
+#define ZIPEncoderState(tif) GetZIPState(tif)
 
 static int ZIPEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s);
 static int ZIPDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s);
@@ -99,7 +99,7 @@ static int ZIPFixupTags(TIFF *tif)
 static int ZIPSetupDecode(TIFF *tif)
 {
     static const char module[] = "ZIPSetupDecode";
-    ZIPState *sp = DecoderState(tif);
+    ZIPState *sp = ZIPDecoderState(tif);
 
     assert(sp != NULL);
 
@@ -131,7 +131,7 @@ static int ZIPSetupDecode(TIFF *tif)
  */
 static int ZIPPreDecode(TIFF *tif, uint16_t s)
 {
-    ZIPState *sp = DecoderState(tif);
+    ZIPState *sp = ZIPDecoderState(tif);
 
     (void)s;
     assert(sp != NULL);
@@ -156,7 +156,7 @@ static int ZIPPreDecode(TIFF *tif, uint16_t s)
 static int ZIPDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
 {
     static const char module[] = "ZIPDecode";
-    ZIPState *sp = DecoderState(tif);
+    ZIPState *sp = ZIPDecoderState(tif);
 
     (void)s;
     assert(sp != NULL);
@@ -290,7 +290,7 @@ static int ZIPDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
 static int ZIPSetupEncode(TIFF *tif)
 {
     static const char module[] = "ZIPSetupEncode";
-    ZIPState *sp = EncoderState(tif);
+    ZIPState *sp = ZIPEncoderState(tif);
     int cappedQuality;
 
     assert(sp != NULL);
@@ -321,7 +321,7 @@ static int ZIPSetupEncode(TIFF *tif)
  */
 static int ZIPPreEncode(TIFF *tif, uint16_t s)
 {
-    ZIPState *sp = EncoderState(tif);
+    ZIPState *sp = ZIPEncoderState(tif);
 
     (void)s;
     assert(sp != NULL);
@@ -348,7 +348,7 @@ static int ZIPPreEncode(TIFF *tif, uint16_t s)
 static int ZIPEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
 {
     static const char module[] = "ZIPEncode";
-    ZIPState *sp = EncoderState(tif);
+    ZIPState *sp = ZIPEncoderState(tif);
 
     assert(sp != NULL);
     assert(sp->state == ZSTATE_INIT_ENCODE);
@@ -487,7 +487,7 @@ static int ZIPEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
 static int ZIPPostEncode(TIFF *tif)
 {
     static const char module[] = "ZIPPostEncode";
-    ZIPState *sp = EncoderState(tif);
+    ZIPState *sp = ZIPEncoderState(tif);
     int state;
 
 #if LIBDEFLATE_SUPPORT
@@ -526,7 +526,7 @@ static int ZIPPostEncode(TIFF *tif)
 
 static void ZIPCleanup(TIFF *tif)
 {
-    ZIPState *sp = ZState(tif);
+    ZIPState *sp = GetZIPState(tif);
 
     assert(sp != 0);
 
@@ -562,7 +562,7 @@ static void ZIPCleanup(TIFF *tif)
 static int ZIPVSetField(TIFF *tif, uint32_t tag, va_list ap)
 {
     static const char module[] = "ZIPVSetField";
-    ZIPState *sp = ZState(tif);
+    ZIPState *sp = GetZIPState(tif);
 
     switch (tag)
     {
@@ -628,7 +628,7 @@ static int ZIPVSetField(TIFF *tif, uint32_t tag, va_list ap)
 
 static int ZIPVGetField(TIFF *tif, uint32_t tag, va_list ap)
 {
-    ZIPState *sp = ZState(tif);
+    ZIPState *sp = GetZIPState(tif);
 
     switch (tag)
     {
@@ -680,7 +680,7 @@ int TIFFInitZIP(TIFF *tif, int scheme)
     tif->tif_data = (uint8_t *)_TIFFcallocExt(tif, sizeof(ZIPState), 1);
     if (tif->tif_data == NULL)
         goto bad;
-    sp = ZState(tif);
+    sp = GetZIPState(tif);
     sp->stream.zalloc = NULL;
     sp->stream.zfree = NULL;
     sp->stream.opaque = NULL;
diff --git a/libtiff/tif_zstd.c b/libtiff/tif_zstd.c
index 64699310..5aaf4c44 100644
--- a/libtiff/tif_zstd.c
+++ b/libtiff/tif_zstd.c
@@ -54,9 +54,9 @@ typedef struct
     TIFFVSetMethod vsetparent; /* super-class method */
 } ZSTDState;
 
-#define LState(tif) ((ZSTDState *)(tif)->tif_data)
-#define DecoderState(tif) LState(tif)
-#define EncoderState(tif) LState(tif)
+#define GetZSTDState(tif) ((ZSTDState *)(tif)->tif_data)
+#define ZSTDDecoderState(tif) GetZSTDState(tif)
+#define ZSTDEncoderState(tif) GetZSTDState(tif)
 
 static int ZSTDEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s);
 static int ZSTDDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s);
@@ -69,7 +69,7 @@ static int ZSTDFixupTags(TIFF *tif)
 
 static int ZSTDSetupDecode(TIFF *tif)
 {
-    ZSTDState *sp = DecoderState(tif);
+    ZSTDState *sp = ZSTDDecoderState(tif);
 
     assert(sp != NULL);
 
@@ -91,7 +91,7 @@ static int ZSTDSetupDecode(TIFF *tif)
 static int ZSTDPreDecode(TIFF *tif, uint16_t s)
 {
     static const char module[] = "ZSTDPreDecode";
-    ZSTDState *sp = DecoderState(tif);
+    ZSTDState *sp = ZSTDDecoderState(tif);
     size_t zstd_ret;
 
     (void)s;
@@ -124,7 +124,7 @@ static int ZSTDPreDecode(TIFF *tif, uint16_t s)
 static int ZSTDDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
 {
     static const char module[] = "ZSTDDecode";
-    ZSTDState *sp = DecoderState(tif);
+    ZSTDState *sp = ZSTDDecoderState(tif);
     ZSTD_inBuffer in_buffer;
     ZSTD_outBuffer out_buffer;
     size_t zstd_ret;
@@ -170,7 +170,7 @@ static int ZSTDDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
 
 static int ZSTDSetupEncode(TIFF *tif)
 {
-    ZSTDState *sp = EncoderState(tif);
+    ZSTDState *sp = ZSTDEncoderState(tif);
 
     assert(sp != NULL);
     if (sp->state & LSTATE_INIT_DECODE)
@@ -190,7 +190,7 @@ static int ZSTDSetupEncode(TIFF *tif)
 static int ZSTDPreEncode(TIFF *tif, uint16_t s)
 {
     static const char module[] = "ZSTDPreEncode";
-    ZSTDState *sp = EncoderState(tif);
+    ZSTDState *sp = ZSTDEncoderState(tif);
     size_t zstd_ret;
 
     (void)s;
@@ -229,7 +229,7 @@ static int ZSTDPreEncode(TIFF *tif, uint16_t s)
 static int ZSTDEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
 {
     static const char module[] = "ZSTDEncode";
-    ZSTDState *sp = EncoderState(tif);
+    ZSTDState *sp = ZSTDEncoderState(tif);
     ZSTD_inBuffer in_buffer;
     size_t zstd_ret;
 
@@ -271,7 +271,7 @@ static int ZSTDEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
 static int ZSTDPostEncode(TIFF *tif)
 {
     static const char module[] = "ZSTDPostEncode";
-    ZSTDState *sp = EncoderState(tif);
+    ZSTDState *sp = ZSTDEncoderState(tif);
     size_t zstd_ret;
 
     do
@@ -297,7 +297,7 @@ static int ZSTDPostEncode(TIFF *tif)
 
 static void ZSTDCleanup(TIFF *tif)
 {
-    ZSTDState *sp = LState(tif);
+    ZSTDState *sp = GetZSTDState(tif);
 
     assert(sp != 0);
 
@@ -325,7 +325,7 @@ static void ZSTDCleanup(TIFF *tif)
 static int ZSTDVSetField(TIFF *tif, uint32_t tag, va_list ap)
 {
     static const char module[] = "ZSTDVSetField";
-    ZSTDState *sp = LState(tif);
+    ZSTDState *sp = GetZSTDState(tif);
 
     switch (tag)
     {
@@ -347,7 +347,7 @@ static int ZSTDVSetField(TIFF *tif, uint32_t tag, va_list ap)
 
 static int ZSTDVGetField(TIFF *tif, uint32_t tag, va_list ap)
 {
-    ZSTDState *sp = LState(tif);
+    ZSTDState *sp = GetZSTDState(tif);
 
     switch (tag)
     {
@@ -389,7 +389,7 @@ int TIFFInitZSTD(TIFF *tif, int scheme)
     tif->tif_data = (uint8_t *)_TIFFmallocExt(tif, sizeof(ZSTDState));
     if (tif->tif_data == NULL)
         goto bad;
-    sp = LState(tif);
+    sp = GetZSTDState(tif);
 
     /*
      * Override parent get/set field methods.
diff --git a/test/rational_precision2double.c b/test/rational_precision2double.c
index 55b77dd9..1683cb9a 100644
--- a/test/rational_precision2double.c
+++ b/test/rational_precision2double.c
@@ -67,8 +67,6 @@
 #include "tiffiop.h"
 #include "tifftest.h"
 
-#include "tif_dirwrite.c"
-
 int write_test_tiff(TIFF *tif, const char *filenameRead, int blnAllCustomTags);
 
 #define SPP 3 /* Samples per pixel */