Skip to content

Commit afd05ee

Browse files
Remove compatibilty code for GHC 7.6.x and earlier
1 parent df6ab5c commit afd05ee

File tree

2 files changed

+7
-61
lines changed

2 files changed

+7
-61
lines changed

src/Database/PostgreSQL/Simple/Compat.hs

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,67 +28,30 @@ import Data.Text.Lazy.Builder.Scientific (scientificBuilder)
2828
import Data.Scientific (scientificBuilder)
2929
#endif
3030

31-
#if __GLASGOW_HASKELL__ >= 702
3231
import System.IO.Unsafe (unsafeDupablePerformIO)
33-
#elif __GLASGOW_HASKELL__ >= 611
34-
import GHC.IO (unsafeDupablePerformIO)
35-
#else
36-
import GHC.IOBase (unsafeDupablePerformIO)
37-
#endif
3832

3933
import Data.Fixed (Pico)
40-
#if MIN_VERSION_base(4,7,0)
4134
import Data.Fixed (Fixed(MkFixed))
42-
#else
43-
import Unsafe.Coerce (unsafeCoerce)
44-
#endif
4535

46-
-- | Like 'E.mask', but backported to base before version 4.3.0.
47-
--
48-
-- Note that the restore callback is monomorphic, unlike in 'E.mask'. This
49-
-- could be fixed by changing the type signature, but it would require us to
50-
-- enable the RankNTypes extension (since 'E.mask' has a rank-3 type). The
51-
-- 'withTransactionMode' function calls the restore callback only once, so we
52-
-- don't need that polymorphism.
36+
-- | Like 'E.mask', but with a monomorphic restore callback, unlike in
37+
-- 'E.mask'. This could be fixed by changing the type signature, but
38+
-- it would require us to enable the RankNTypes extension (since
39+
-- 'E.mask' has a rank-3 type). The 'withTransactionMode' function
40+
-- calls the restore callback only once, so we don't need that
41+
-- polymorphism.
5342
mask :: ((IO a -> IO a) -> IO b) -> IO b
54-
#if MIN_VERSION_base(4,3,0)
55-
mask io = E.mask $ \restore -> io restore
56-
#else
57-
mask io = do
58-
b <- E.blocked
59-
E.block $ io $ \m -> if b then m else E.unblock m
60-
#endif
43+
mask io = E.mask io
6144
{-# INLINE mask #-}
6245

63-
#if !MIN_VERSION_base(4,5,0)
64-
infixr 6 <>
65-
66-
(<>) :: Monoid m => m -> m -> m
67-
(<>) = mappend
68-
{-# INLINE (<>) #-}
69-
#endif
70-
7146
toByteString :: Builder -> ByteString
7247
#if MIN_VERSION_bytestring(0,10,0)
7348
toByteString x = toStrict (toLazyByteString x)
7449
#else
7550
toByteString x = B.concat (toChunks (toLazyByteString x))
7651
#endif
7752

78-
#if MIN_VERSION_base(4,7,0)
79-
8053
toPico :: Integer -> Pico
8154
toPico = MkFixed
8255

8356
fromPico :: Pico -> Integer
8457
fromPico (MkFixed i) = i
85-
86-
#else
87-
88-
toPico :: Integer -> Pico
89-
toPico = unsafeCoerce
90-
91-
fromPico :: Pico -> Integer
92-
fromPico = unsafeCoerce
93-
94-
#endif

src/Database/PostgreSQL/Simple/Notification.hs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ import GHC.IO.Exception ( ioe_location )
4747

4848
#if defined(mingw32_HOST_OS)
4949
import Control.Concurrent ( threadDelay )
50-
#elif !MIN_VERSION_base(4,7,0)
51-
import Control.Concurrent ( threadWaitRead )
5250
#else
5351
import GHC.Conc ( atomically )
5452
import Control.Concurrent ( threadWaitReadSTM )
@@ -94,21 +92,6 @@ getNotification conn = join $ withConnection conn fetch
9492
-- with async exceptions, whereas threadDelay can.
9593
Just _fd -> do
9694
return (threadDelay 1000000 >> loop)
97-
#elif !MIN_VERSION_base(4,7,0)
98-
-- Technically there's a race condition that is usually benign.
99-
-- If the connection is closed or reset after we drop the
100-
-- lock, and then the fd index is reallocated to a new
101-
-- descriptor before we call threadWaitRead, then
102-
-- we could end up waiting on the wrong descriptor.
103-
--
104-
-- Now, if the descriptor becomes readable promptly, then
105-
-- it's no big deal as we'll wake up and notice the change
106-
-- on the next iteration of the loop. But if are very
107-
-- unlucky, then we could end up waiting a long time.
108-
Just fd -> do
109-
return $ do
110-
threadWaitRead fd `catch` (throwIO . setIOErrorLocation)
111-
loop
11295
#else
11396
-- This case fixes the race condition above. By registering
11497
-- our interest in the descriptor before we drop the lock,

0 commit comments

Comments
 (0)