From fe18b9b01f984c1319ebec0dbda4fffa338fca85 Mon Sep 17 00:00:00 2001
From: Ben Gamari <ben@smart-cactus.org>
Date: Thu, 5 Oct 2023 23:17:08 -0400
Subject: [PATCH] TArray: Don't rely on undefined CPP behavior

Fixes #75.
---
 Control/Concurrent/STM/TArray.hs | 10 ++++++----
 changelog.md                     |  4 ++++
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/Control/Concurrent/STM/TArray.hs b/Control/Concurrent/STM/TArray.hs
index 4ac2db4..2bce545 100644
--- a/Control/Concurrent/STM/TArray.hs
+++ b/Control/Concurrent/STM/TArray.hs
@@ -4,9 +4,11 @@
 {-# LANGUAGE Trustworthy #-}
 #endif
 
-#define HAS_UNLIFTED_ARRAY defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 904
+#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 904
+#define HAS_UNLIFTED_ARRAY 1
+#endif
 
-#if HAS_UNLIFTED_ARRAY
+#if defined(HAS_UNLIFTED_ARRAY)
 {-# LANGUAGE MagicHash, UnboxedTuples #-}
 #endif
 
@@ -30,7 +32,7 @@ module Control.Concurrent.STM.TArray (
 
 import Control.Monad.STM (STM, atomically)
 import Data.Typeable (Typeable)
-#if HAS_UNLIFTED_ARRAY
+#if defined(HAS_UNLIFTED_ARRAY)
 import Control.Concurrent.STM.TVar (readTVar, readTVarIO, writeTVar)
 import Data.Array.Base (safeRangeSize, MArray(..))
 import Data.Ix (Ix)
@@ -47,7 +49,7 @@ import Data.Array.Base (safeRangeSize, unsafeAt, MArray(..), IArray(numElements)
 -- interface for mutable arrays.
 --
 -- It is conceptually implemented as @Array i (TVar e)@.
-#if HAS_UNLIFTED_ARRAY
+#if defined(HAS_UNLIFTED_ARRAY)
 data TArray i e = TArray
     !i   -- lower bound
     !i   -- upper bound
diff --git a/changelog.md b/changelog.md
index ec40e66..7bb017b 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,9 @@
 # Changelog for [`stm` package](http://hackage.haskell.org/package/stm)
 
+## 2.5.2.1 *September 2023*
+
+  * Eliminate reliance on undefined CPP behavior ([#75](https://github.com/haskell/stm/issues/75))
+
 ## 2.5.2.0 *September 2023*
 
   * Fix strictness of `stateTVar` ([#30](https://github.com/haskell/stm/ssues/30))
-- 
GitLab