Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/pr/21'
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Jun 25, 2024
2 parents 4390b95 + 6a175fa commit 9c71692
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions System/OsString/Internal/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TemplateHaskellQuotes #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeApplications #-}
Expand Down Expand Up @@ -46,9 +46,7 @@ import GHC.Generics (Generic)
import System.OsString.Encoding.Internal
import qualified System.OsString.Data.ByteString.Short as BS
import qualified System.OsString.Data.ByteString.Short.Word16 as BS16
#if MIN_VERSION_template_haskell(2,16,0)
import qualified Language.Haskell.TH.Syntax as TH
#endif

-- Using unpinned bytearrays to avoid Heap fragmentation and
-- which are reasonably cheap to pass to FFI calls
Expand Down Expand Up @@ -77,8 +75,7 @@ pattern WS { unWS } <- WindowsString unWS where


instance Lift WindowsString where
lift (WindowsString bs)
= [| WindowsString (BS.pack $(lift $ BS.unpack bs)) :: WindowsString |]
lift (WindowsString bs) = TH.AppE (TH.ConE 'WindowsString) <$> (lift bs)
#if MIN_VERSION_template_haskell(2,17,0)
liftTyped = TH.unsafeCodeCoerce . TH.lift
#elif MIN_VERSION_template_haskell(2,16,0)
Expand All @@ -103,8 +100,7 @@ pattern PS { unPS } <- PosixString unPS where
#endif

instance Lift PosixString where
lift (PosixString bs)
= [| PosixString (BS.pack $(lift $ BS.unpack bs)) :: PosixString |]
lift (PosixString bs) = TH.AppE (TH.ConE 'PosixString) <$> (lift bs)
#if MIN_VERSION_template_haskell(2,17,0)
liftTyped = TH.unsafeCodeCoerce . TH.lift
#elif MIN_VERSION_template_haskell(2,16,0)
Expand Down Expand Up @@ -185,7 +181,7 @@ instance Monoid OsString where
#if MIN_VERSION_base(4,11,0)
mappend = (<>)
#else
mappend = coerce (mappend :: BS.ShortByteString -> BS.ShortByteString -> BS.ShortByteString))
mappend = coerce (mappend :: BS.ShortByteString -> BS.ShortByteString -> BS.ShortByteString)
#endif

#if MIN_VERSION_base(4,11,0)
Expand All @@ -197,9 +193,9 @@ instance Semigroup OsString where
instance Lift OsString where
lift xs = case coercionToPlatformTypes of
Left (_, co) ->
[| OsString (WindowsString (BS.pack $(lift $ BS.unpack $ coerce $ coerceWith co xs))) :: OsString |]
Right (_, co) ->
[| OsString (PosixString (BS.pack $(lift $ BS.unpack $ coerce $ coerceWith co xs))) :: OsString |]
TH.AppE (TH.ConE 'OsString) <$> (lift $ coerceWith co xs)
Right (_, co) -> do
TH.AppE (TH.ConE 'OsString) <$> (lift $ coerceWith co xs)
#if MIN_VERSION_template_haskell(2,17,0)
liftTyped = TH.unsafeCodeCoerce . TH.lift
#elif MIN_VERSION_template_haskell(2,16,0)
Expand Down

0 comments on commit 9c71692

Please sign in to comment.