From 7a7108b847cd17d629eed53060bbda4c5f989cb8 Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Fri, 30 Sep 2022 19:23:54 +0200 Subject: [PATCH 01/16] Added cabal.project --- .gitignore | 1 + cabal.project | 1 + 2 files changed, 2 insertions(+) create mode 100644 cabal.project diff --git a/.gitignore b/.gitignore index a5f630a..26cfce9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.swp .ghc.* .stack-work +cabal.project.local diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..6a6840c --- /dev/null +++ b/cabal.project @@ -0,0 +1 @@ +packages: ./unix-compat.cabal From 5f809285d2a6c9fc32ebfa548911c0afb746dd67 Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Fri, 30 Sep 2022 19:24:13 +0200 Subject: [PATCH 02/16] Updated CI to use the latest minor versions of GHC --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d507b54..1ab0b91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,8 +13,8 @@ jobs: ghc: - 8.8.4 - 8.10.7 - - 9.0.1 - - 9.2.1 + - 9.0.2 + - 9.2.4 fail-fast: false continue-on-error: ${{ startsWith(matrix.os, 'windows') && startsWith(matrix.ghc, '9.2') }} From 327342418be40995e72b4c87f67f8822fbcbe227 Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Fri, 30 Sep 2022 19:24:21 +0200 Subject: [PATCH 03/16] Added new check-types testsuite --- tests/check-types.hs | 131 +++++++++++++++++++++++++++++++++++++++++++ unix-compat.cabal | 12 ++++ 2 files changed, 143 insertions(+) create mode 100644 tests/check-types.hs diff --git a/tests/check-types.hs b/tests/check-types.hs new file mode 100644 index 0000000..7d6eb4f --- /dev/null +++ b/tests/check-types.hs @@ -0,0 +1,131 @@ +{-# LANGUAGE CPP #-} + +{-# OPTIONS_GHC -Wno-unused-top-binds #-} + +module Main (main) where + +import Data.Int +import Data.Word +import System.PosixCompat.Types + +import qualified Foreign +import qualified Foreign.C.Types + +main :: IO () +main = pure () + +#if MIN_VERSION_base(4, 13, 0) +newtypeCBlkCnt :: CBlkCnt -> Int64 +newtypeCBlkCnt (CBlkCnt x) = x + +newtypeCBlkSize :: CBlkSize -> Int64 +newtypeCBlkSize (CBlkSize x) = x + +newtypeCCc :: CCc -> Word8 +newtypeCCc (CCc x) = x + +newtypeCClockId :: CClockId -> Int32 +newtypeCClockId (CClockId x) = x + +newtypeCDev :: CDev -> Word64 +newtypeCDev (CDev x) = x + +newtypeCFsBlkCnt :: CFsBlkCnt -> Word64 +newtypeCFsBlkCnt (CFsBlkCnt x) = x + +newtypeCFsFilCnt :: CFsFilCnt -> Word64 +newtypeCFsFilCnt (CFsFilCnt x) = x + +newtypeCGid :: CGid -> Word32 +newtypeCGid (CGid x) = x + +newtypeCId :: CId -> Word32 +newtypeCId (CId x) = x + +newtypeCIno :: CIno -> Word64 +newtypeCIno (CIno x) = x + +newtypeCKey :: CKey -> Int32 +newtypeCKey (CKey x) = x + +newtypeCMode :: CMode -> Word32 +newtypeCMode (CMode x) = x + +newtypeCNlink :: CNlink -> Word64 +newtypeCNlink (CNlink x) = x + +newtypeCOff :: COff -> Int64 +newtypeCOff (COff x) = x + +newtypeCPid :: CPid -> Int32 +newtypeCPid (CPid x) = x + +newtypeCRLim :: CRLim -> Word64 +newtypeCRLim (CRLim x) = x + +newtypeCSpeed :: CSpeed -> Word32 +newtypeCSpeed (CSpeed x) = x + +newtypeCSsize :: CSsize -> Int64 +newtypeCSsize (CSsize x) = x + +newtypeCTcflag :: CTcflag -> Word32 +newtypeCTcflag (CTcflag x) = x + +newtypeCTimer :: CTimer -> Foreign.Ptr () +newtypeCTimer (CTimer x) = x + +newtypeCUid :: CUid -> Word32 +newtypeCUid (CUid x) = x + +newtypeFd :: Fd -> Foreign.C.Types.CInt +newtypeFd (Fd x) = x + +typeByteCount :: ByteCount -> Foreign.C.Types.CSize +typeByteCount = id + +typeClockTick :: ClockTick -> Foreign.C.Types.CClock +typeClockTick = id + +typeDeviceID :: DeviceID -> CDev +typeDeviceID = id + +typeEpochTime :: EpochTime -> Foreign.C.Types.CTime +typeEpochTime = id + +typeFileID :: FileID -> CIno +typeFileID = id + +typeFileMode :: FileMode -> CMode +typeFileMode = id + +typeFileOffset :: FileOffset -> COff +typeFileOffset = id + +typeGroupID :: GroupID -> CGid +typeGroupID = id + +typeLimit :: Limit -> Foreign.C.Types.CLong +typeLimit = id + +typeLinkCount :: LinkCount -> CNlink +typeLinkCount = id + +typeProcessGroupID :: ProcessGroupID -> CPid +typeProcessGroupID = id + +typeProcessID :: ProcessID -> CPid +typeProcessID = id + +typeUserID :: UserID -> CUid +typeUserID = id + +#if MIN_VERSION_base(4, 14, 3) +newtypeCNfds :: CNfds -> Word64 +newtypeCNfds (CNfds x) = x + +newtypeCSocklen :: CSocklen -> Word32 +newtypeCSocklen (CSocklen x) = x + +#endif +#endif diff --git a/unix-compat.cabal b/unix-compat.cabal index 8879404..94eb267 100644 --- a/unix-compat.cabal +++ b/unix-compat.cabal @@ -146,3 +146,15 @@ Test-Suite unix-compat-testsuite cc-options: -DSOLARIS build-depends: directory >= 1.3.1 && < 1.4 + +Test-Suite unix-compat-check-types + default-language: Haskell2010 + type: exitcode-stdio-1.0 + hs-source-dirs: tests + ghc-options: -Wall + main-is: check-types.hs + + build-depends: + unix-compat + , base == 4.* + From 966e639d2584d22be749e269ed1f3731092f65a7 Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Fri, 30 Sep 2022 22:24:07 +0200 Subject: [PATCH 04/16] Add missing types Also define LinkCount/UserID/GroupID in terms of the new types. Expose constructors of all newtypes. --- src/System/PosixCompat/Types.hs | 89 ++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 17 deletions(-) diff --git a/src/System/PosixCompat/Types.hs b/src/System/PosixCompat/Types.hs index f9288bc..fca401a 100644 --- a/src/System/PosixCompat/Types.hs +++ b/src/System/PosixCompat/Types.hs @@ -3,45 +3,100 @@ {-| This module re-exports the types from @System.Posix.Types@ on all platforms. - -On Windows 'UserID', 'GroupID' and 'LinkCount' are missing, so they are -redefined by this module. +It defines drop-in replacements for types that are missing from that module on a +specific OS. Namely Mac OS and Windows are supported. -} module System.PosixCompat.Types ( module System.Posix.Types +#ifdef darwin_HOST_OS + , CTimer(..) +#endif #ifdef mingw32_HOST_OS + , CBlkCnt(..) + , CBlkSize(..) + , CCc(..) + , CFsBlkCnt(..) + , CFsFilCnt(..) , UserID + , CUid(..) , GroupID + , CGid(..) , LinkCount + , CNlink(..) #endif ) where +import System.Posix.Types + +#ifdef darwin_HOST_OS +import Foreign.C.Types (CUIntPtr) + +newtype CTimer = CTimer CUIntPtr + deriving (Eq, Ord) +instance Show CTimer where show (CTimer x) = show x + +#else #ifdef mingw32_HOST_OS -- Since CIno (FileID's underlying type) reflects ino_t, -- which mingw defines as short int (int16), it must be overriden to -- match the size of windows fileIndex (word64). -import System.Posix.Types -import Data.Word (Word32) +import Data.Int (Int64) +import Data.Word (Word8, Word32, Word64) + +newtype CBlkCnt = CBlkCnt Int64 + deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) +instance Show CBlkCnt where show (CBlkCnt x) = show x +instance Read CBlkCnt where readsPrec i s = [ (CBlkCnt x, s') + | (x,s') <- readsPrec i s] -newtype UserID = UserID Word32 +newtype CBlkSize = CBlkSize Int64 deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) -instance Show UserID where show (UserID x) = show x -instance Read UserID where readsPrec i s = [ (UserID x, s') +instance Show CBlkSize where show (CBlkSize x) = show x +instance Read CBlkSize where readsPrec i s = [ (CBlkSize x, s') | (x,s') <- readsPrec i s] -newtype GroupID = GroupID Word32 +newtype CCc = Ccs Word8 + deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) +instance Show CCc where show (CCc x) = show x +instance Read CCc where readsPrec i s = [ (CCc x, s') + | (x,s') <- readsPrec i s] + +newtype CFsBlkCnt = CFsBlkCnt Word64 + deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) +instance Show CFsBlkCnt where show (CFsBlkCnt x) = show x +instance Read CFsBlkCnt where readsPrec i s = [ (CFsBlkCnt x, s') + | (x,s') <- readsPrec i s] + +newtype CFsFilCnt = CFsFilCnt Word64 deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) -instance Show GroupID where show (GroupID x) = show x -instance Read GroupID where readsPrec i s = [ (GroupID x, s') +instance Show CFsFilCnt where show (CFsFilCnt x) = show x +instance Read CFsFilCnt where readsPrec i s = [ (CFsFilCnt x, s') | (x,s') <- readsPrec i s] -newtype LinkCount = LinkCount Word32 +type UserID = UserID CUid + +newtype CUid = CUid Word32 deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) -instance Show LinkCount where show (LinkCount x) = show x -instance Read LinkCount where readsPrec i s = [ (LinkCount x, s') - | (x,s') <- readsPrec i s] +instance Show CUid where show (CUid x) = show x +instance Read CUid where readsPrec i s = [ (CUid x, s') + | (x,s') <- readsPrec i s] -#else -import System.Posix.Types +type GroupID = CGid + +newtype CGid = CGid Word32 + deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) +instance Show CGid where show (CGid x) = show x +instance Read CGid where readsPrec i s = [ (CGid x, s') + | (x,s') <- readsPrec i s] + +type LinkCount = CNlink + +newtype CNlink = CNlink Word64 + deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) +instance Show CNlink where show (CNlink x) = show x +instance Read CNlink where readsPrec i s = [ (CNlink x, s') + | (x,s') <- readsPrec i s] + +#endif #endif From 57bd7b9310c5ef44147b6a23243b0a962a087948 Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Fri, 30 Sep 2022 22:57:13 +0200 Subject: [PATCH 05/16] Added CNfds and CSocklen for older base versions --- src/System/PosixCompat/Types.hs | 35 +++++++++++++++++++++++++++------ tests/check-types.hs | 14 ++++++------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/System/PosixCompat/Types.hs b/src/System/PosixCompat/Types.hs index fca401a..a4ed417 100644 --- a/src/System/PosixCompat/Types.hs +++ b/src/System/PosixCompat/Types.hs @@ -1,6 +1,8 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# OPTIONS_GHC -Wno-unused-imports #-} + {-| This module re-exports the types from @System.Posix.Types@ on all platforms. It defines drop-in replacements for types that are missing from that module on a @@ -23,27 +25,32 @@ module System.PosixCompat.Types ( , CGid(..) , LinkCount , CNlink(..) +#endif +#if MIN_VERSION_base(4, 14, 3) +#else + , CNfds(..) + , CSocklen(..) #endif ) where +import Data.Int (Int64) +import Data.Word (Word8, Word32, Word64) +import Foreign.C.Types (CUIntPtr) import System.Posix.Types #ifdef darwin_HOST_OS -import Foreign.C.Types (CUIntPtr) newtype CTimer = CTimer CUIntPtr deriving (Eq, Ord) instance Show CTimer where show (CTimer x) = show x -#else +#endif + #ifdef mingw32_HOST_OS -- Since CIno (FileID's underlying type) reflects ino_t, -- which mingw defines as short int (int16), it must be overriden to -- match the size of windows fileIndex (word64). -import Data.Int (Int64) -import Data.Word (Word8, Word32, Word64) - newtype CBlkCnt = CBlkCnt Int64 deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) instance Show CBlkCnt where show (CBlkCnt x) = show x @@ -56,7 +63,7 @@ instance Show CBlkSize where show (CBlkSize x) = show x instance Read CBlkSize where readsPrec i s = [ (CBlkSize x, s') | (x,s') <- readsPrec i s] -newtype CCc = Ccs Word8 +newtype CCc = CCc Word8 deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) instance Show CCc where show (CCc x) = show x instance Read CCc where readsPrec i s = [ (CCc x, s') @@ -99,4 +106,20 @@ instance Read CNlink where readsPrec i s = [ (CNlink x, s') | (x,s') <- readsPrec i s] #endif + +#if MIN_VERSION_base(4, 14, 3) +#else + +newtype CNfds = CNfds Word64 + deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) +instance Show CNfds where show (CNfds x) = show x +instance Read CNfds where readsPrec i s = [ (CNfds x, s') + | (x,s') <- readsPrec i s] + +newtype CSocklen = CSocklen Word32 + deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) +instance Show CSocklen where show (CSocklen x) = show x +instance Read CSocklen where readsPrec i s = [ (CSocklen x, s') + | (x,s') <- readsPrec i s] + #endif diff --git a/tests/check-types.hs b/tests/check-types.hs index 7d6eb4f..45250db 100644 --- a/tests/check-types.hs +++ b/tests/check-types.hs @@ -51,6 +51,9 @@ newtypeCKey (CKey x) = x newtypeCMode :: CMode -> Word32 newtypeCMode (CMode x) = x +newtypeCNfds :: CNfds -> Word64 +newtypeCNfds (CNfds x) = x + newtypeCNlink :: CNlink -> Word64 newtypeCNlink (CNlink x) = x @@ -63,6 +66,9 @@ newtypeCPid (CPid x) = x newtypeCRLim :: CRLim -> Word64 newtypeCRLim (CRLim x) = x +newtypeCSocklen :: CSocklen -> Word32 +newtypeCSocklen (CSocklen x) = x + newtypeCSpeed :: CSpeed -> Word32 newtypeCSpeed (CSpeed x) = x @@ -120,12 +126,4 @@ typeProcessID = id typeUserID :: UserID -> CUid typeUserID = id -#if MIN_VERSION_base(4, 14, 3) -newtypeCNfds :: CNfds -> Word64 -newtypeCNfds (CNfds x) = x - -newtypeCSocklen :: CSocklen -> Word32 -newtypeCSocklen (CSocklen x) = x - -#endif #endif From 5d16409cf128baa2d94c65157557e4ebaebd14dd Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Fri, 30 Sep 2022 23:11:15 +0200 Subject: [PATCH 06/16] Adjusted types on Mac OS --- src/System/PosixCompat/Types.hs | 4 ++-- tests/check-types.hs | 39 ++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/System/PosixCompat/Types.hs b/src/System/PosixCompat/Types.hs index a4ed417..672ef28 100644 --- a/src/System/PosixCompat/Types.hs +++ b/src/System/PosixCompat/Types.hs @@ -40,7 +40,7 @@ import System.Posix.Types #ifdef darwin_HOST_OS -newtype CTimer = CTimer CUIntPtr +newtype CTimer = CTimer (Ptr ()) deriving (Eq, Ord) instance Show CTimer where show (CTimer x) = show x @@ -81,7 +81,7 @@ instance Show CFsFilCnt where show (CFsFilCnt x) = show x instance Read CFsFilCnt where readsPrec i s = [ (CFsFilCnt x, s') | (x,s') <- readsPrec i s] -type UserID = UserID CUid +type UserID = CUid newtype CUid = CUid Word32 deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) diff --git a/tests/check-types.hs b/tests/check-types.hs index 45250db..fa157d6 100644 --- a/tests/check-types.hs +++ b/tests/check-types.hs @@ -14,26 +14,45 @@ import qualified Foreign.C.Types main :: IO () main = pure () -#if MIN_VERSION_base(4, 13, 0) newtypeCBlkCnt :: CBlkCnt -> Int64 newtypeCBlkCnt (CBlkCnt x) = x +#ifdef darwin_HOST_OS +newtypeCBlkSize :: CBlkSize -> Int32 +#else newtypeCBlkSize :: CBlkSize -> Int64 +#endif newtypeCBlkSize (CBlkSize x) = x newtypeCCc :: CCc -> Word8 newtypeCCc (CCc x) = x +#ifdef darwin_HOST_OS +newtypeCClockId :: CClockId -> Word32 +#else newtypeCClockId :: CClockId -> Int32 +#endif newtypeCClockId (CClockId x) = x +#ifdef darwin_HOST_OS +newtypeCDev :: CDev -> Int32 +#else newtypeCDev :: CDev -> Word64 +#endif newtypeCDev (CDev x) = x +#ifdef darwin_HOST_OS +newtypeCFsBlkCnt :: CFsBlkCnt -> Word32 +#else newtypeCFsBlkCnt :: CFsBlkCnt -> Word64 +#endif newtypeCFsBlkCnt (CFsBlkCnt x) = x +#ifdef darwin_HOST_OS +newtypeCFsFilCnt :: CFsFilCnt -> Word32 +#else newtypeCFsFilCnt :: CFsFilCnt -> Word64 +#endif newtypeCFsFilCnt (CFsFilCnt x) = x newtypeCGid :: CGid -> Word32 @@ -48,13 +67,21 @@ newtypeCIno (CIno x) = x newtypeCKey :: CKey -> Int32 newtypeCKey (CKey x) = x +#ifdef darwin_HOST_OS +newtypeCMode :: CMode -> Word16 +#else newtypeCMode :: CMode -> Word32 +#endif newtypeCMode (CMode x) = x newtypeCNfds :: CNfds -> Word64 newtypeCNfds (CNfds x) = x +#ifdef darwin_HOST_OS +newtypeCNlink :: CNlink -> Word16 +#else newtypeCNlink :: CNlink -> Word64 +#endif newtypeCNlink (CNlink x) = x newtypeCOff :: COff -> Int64 @@ -69,13 +96,21 @@ newtypeCRLim (CRLim x) = x newtypeCSocklen :: CSocklen -> Word32 newtypeCSocklen (CSocklen x) = x +#ifdef darwin_HOST_OS +newtypeCSpeed :: CSpeed -> Word64 +#else newtypeCSpeed :: CSpeed -> Word32 +#endif newtypeCSpeed (CSpeed x) = x newtypeCSsize :: CSsize -> Int64 newtypeCSsize (CSsize x) = x +#ifdef darwin_HOST_OS +newtypeCTcflag :: CTcflag -> Word64 +#else newtypeCTcflag :: CTcflag -> Word32 +#endif newtypeCTcflag (CTcflag x) = x newtypeCTimer :: CTimer -> Foreign.Ptr () @@ -125,5 +160,3 @@ typeProcessID = id typeUserID :: UserID -> CUid typeUserID = id - -#endif From 7a7e2050f6ff1a775ab21e1bbdf6ebf6ffb4141f Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Fri, 30 Sep 2022 23:14:52 +0200 Subject: [PATCH 07/16] Fixed imports --- src/System/PosixCompat/Types.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System/PosixCompat/Types.hs b/src/System/PosixCompat/Types.hs index 672ef28..2ddc470 100644 --- a/src/System/PosixCompat/Types.hs +++ b/src/System/PosixCompat/Types.hs @@ -35,7 +35,7 @@ module System.PosixCompat.Types ( import Data.Int (Int64) import Data.Word (Word8, Word32, Word64) -import Foreign.C.Types (CUIntPtr) +import Foreign (Ptr) import System.Posix.Types #ifdef darwin_HOST_OS From e1e9d26079ff9c2c0e8662b93b270ce951455394 Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Fri, 30 Sep 2022 23:33:12 +0200 Subject: [PATCH 08/16] Added more missing types --- src/System/PosixCompat/Types.hs | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/System/PosixCompat/Types.hs b/src/System/PosixCompat/Types.hs index 2ddc470..f02b499 100644 --- a/src/System/PosixCompat/Types.hs +++ b/src/System/PosixCompat/Types.hs @@ -19,6 +19,12 @@ module System.PosixCompat.Types ( , CCc(..) , CFsBlkCnt(..) , CFsFilCnt(..) + , CId(..) + , CKey(..) + , CRLim(..) + , CSpeed(..) + , CTcFlag(..) + , CTimer(..) , UserID , CUid(..) , GroupID @@ -81,6 +87,40 @@ instance Show CFsFilCnt where show (CFsFilCnt x) = show x instance Read CFsFilCnt where readsPrec i s = [ (CFsFilCnt x, s') | (x,s') <- readsPrec i s] +newtype CId = CId Word32 + deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) +instance Show CId where show (CId x) = show x +instance Read CId where readsPrec i s = [ (CId x, s') + | (x,s') <- readsPrec i s] + +newtype CKey = CId Int32 + deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) +instance Show CKey where show (CKey x) = show x +instance Read CKey where readsPrec i s = [ (CKey x, s') + | (x,s') <- readsPrec i s] + +newtype CRLim = CRLim Word64 + deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) +instance Show CRLim where show (CRLim x) = show x +instance Read CRLim where readsPrec i s = [ (CRLim x, s') + | (x,s') <- readsPrec i s] + +newtype CSpeed = CSpeed Word32 + deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) +instance Show CSpeed where show (CSpeed x) = show x +instance Read CSpeed where readsPrec i s = [ (CSpeed x, s') + | (x,s') <- readsPrec i s] + +newtype CTcflag = CTcflag Word32 + deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) +instance Show CTcflag where show (CTcflag x) = show x +instance Read CTcflag where readsPrec i s = [ (CTcflag x, s') + | (x,s') <- readsPrec i s] + +newtype CTimer = CTimer (Ptr ()) + deriving (Eq, Ord) +instance Show CTimer where show (CTimer x) = show x + type UserID = CUid newtype CUid = CUid Word32 From 0e0acac1b74b4a5466665e7d00ac299330f5d7e5 Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Fri, 30 Sep 2022 23:54:32 +0200 Subject: [PATCH 09/16] Removed CId for Windows --- src/System/PosixCompat/Types.hs | 13 ++----------- tests/check-types.hs | 4 ++++ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/System/PosixCompat/Types.hs b/src/System/PosixCompat/Types.hs index f02b499..2713dd9 100644 --- a/src/System/PosixCompat/Types.hs +++ b/src/System/PosixCompat/Types.hs @@ -19,7 +19,6 @@ module System.PosixCompat.Types ( , CCc(..) , CFsBlkCnt(..) , CFsFilCnt(..) - , CId(..) , CKey(..) , CRLim(..) , CSpeed(..) @@ -32,8 +31,7 @@ module System.PosixCompat.Types ( , LinkCount , CNlink(..) #endif -#if MIN_VERSION_base(4, 14, 3) -#else +#if !MIN_VERSION_base(4, 14, 3) , CNfds(..) , CSocklen(..) #endif @@ -87,12 +85,6 @@ instance Show CFsFilCnt where show (CFsFilCnt x) = show x instance Read CFsFilCnt where readsPrec i s = [ (CFsFilCnt x, s') | (x,s') <- readsPrec i s] -newtype CId = CId Word32 - deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) -instance Show CId where show (CId x) = show x -instance Read CId where readsPrec i s = [ (CId x, s') - | (x,s') <- readsPrec i s] - newtype CKey = CId Int32 deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) instance Show CKey where show (CKey x) = show x @@ -147,8 +139,7 @@ instance Read CNlink where readsPrec i s = [ (CNlink x, s') #endif -#if MIN_VERSION_base(4, 14, 3) -#else +#if !MIN_VERSION_base(4, 14, 3) newtype CNfds = CNfds Word64 deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) diff --git a/tests/check-types.hs b/tests/check-types.hs index fa157d6..8aa8bb5 100644 --- a/tests/check-types.hs +++ b/tests/check-types.hs @@ -74,7 +74,11 @@ newtypeCMode :: CMode -> Word32 #endif newtypeCMode (CMode x) = x +#if defined darwin_HOST_OS && MIN_VERSION_base(4,14,0) +newtypeCNfds :: CNfds -> Word32 +#else newtypeCNfds :: CNfds -> Word64 +#endif newtypeCNfds (CNfds x) = x #ifdef darwin_HOST_OS From 3a8b9a8d6f6da2c0eb69cf9ff2c910a4d64d8179 Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Fri, 30 Sep 2022 23:59:57 +0200 Subject: [PATCH 10/16] Fixed: Import Int32 --- src/System/PosixCompat/Types.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System/PosixCompat/Types.hs b/src/System/PosixCompat/Types.hs index 2713dd9..3b81be4 100644 --- a/src/System/PosixCompat/Types.hs +++ b/src/System/PosixCompat/Types.hs @@ -37,7 +37,7 @@ module System.PosixCompat.Types ( #endif ) where -import Data.Int (Int64) +import Data.Int (Int32, Int64) import Data.Word (Word8, Word32, Word64) import Foreign (Ptr) import System.Posix.Types From c85742b4c8a35d826ea151cacb1e23d29ac63719 Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Sat, 1 Oct 2022 00:06:14 +0200 Subject: [PATCH 11/16] Fixed: Wrong constructor name for CKey --- src/System/PosixCompat/Types.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System/PosixCompat/Types.hs b/src/System/PosixCompat/Types.hs index 3b81be4..ca55f8c 100644 --- a/src/System/PosixCompat/Types.hs +++ b/src/System/PosixCompat/Types.hs @@ -85,7 +85,7 @@ instance Show CFsFilCnt where show (CFsFilCnt x) = show x instance Read CFsFilCnt where readsPrec i s = [ (CFsFilCnt x, s') | (x,s') <- readsPrec i s] -newtype CKey = CId Int32 +newtype CKey = CKey Int32 deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) instance Show CKey where show (CKey x) = show x instance Read CKey where readsPrec i s = [ (CKey x, s') From 1ee5d097b1a57d090a6d804af141751fed439512 Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Sat, 1 Oct 2022 00:13:10 +0200 Subject: [PATCH 12/16] Typo: CTcFlag -> CTcflag --- src/System/PosixCompat/Types.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System/PosixCompat/Types.hs b/src/System/PosixCompat/Types.hs index ca55f8c..53f6cf9 100644 --- a/src/System/PosixCompat/Types.hs +++ b/src/System/PosixCompat/Types.hs @@ -22,7 +22,7 @@ module System.PosixCompat.Types ( , CKey(..) , CRLim(..) , CSpeed(..) - , CTcFlag(..) + , CTcflag(..) , CTimer(..) , UserID , CUid(..) From 63a82fdf8fef958ba362dac2e565663c783bc89d Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Sat, 1 Oct 2022 00:22:30 +0200 Subject: [PATCH 13/16] Added CId for Windows again --- src/System/PosixCompat/Types.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/System/PosixCompat/Types.hs b/src/System/PosixCompat/Types.hs index 53f6cf9..5decd02 100644 --- a/src/System/PosixCompat/Types.hs +++ b/src/System/PosixCompat/Types.hs @@ -19,6 +19,7 @@ module System.PosixCompat.Types ( , CCc(..) , CFsBlkCnt(..) , CFsFilCnt(..) + , CId(..) , CKey(..) , CRLim(..) , CSpeed(..) @@ -85,6 +86,12 @@ instance Show CFsFilCnt where show (CFsFilCnt x) = show x instance Read CFsFilCnt where readsPrec i s = [ (CFsFilCnt x, s') | (x,s') <- readsPrec i s] +newtype CId = CId Word32 + deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) +instance Show CId where show (CId x) = show x +instance Read CId where readsPrec i s = [ (CId x, s') + | (x,s') <- readsPrec i s] + newtype CKey = CKey Int32 deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) instance Show CKey where show (CKey x) = show x From 4e8251eaf6896b6c58592021e8aebe657615830a Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Sat, 1 Oct 2022 00:28:39 +0200 Subject: [PATCH 14/16] Fixed CPP for CNfds and CSocklen --- src/System/PosixCompat/Types.hs | 4 ++-- tests/check-types.hs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/System/PosixCompat/Types.hs b/src/System/PosixCompat/Types.hs index 5decd02..5454a02 100644 --- a/src/System/PosixCompat/Types.hs +++ b/src/System/PosixCompat/Types.hs @@ -32,7 +32,7 @@ module System.PosixCompat.Types ( , LinkCount , CNlink(..) #endif -#if !MIN_VERSION_base(4, 14, 3) +#if !MIN_VERSION_base(4, 14, 0) , CNfds(..) , CSocklen(..) #endif @@ -146,7 +146,7 @@ instance Read CNlink where readsPrec i s = [ (CNlink x, s') #endif -#if !MIN_VERSION_base(4, 14, 3) +#if defined mingw32_HOST_OS || !MIN_VERSION_base(4, 14, 0) newtype CNfds = CNfds Word64 deriving (Eq, Ord, Enum, Bounded, Integral, Num, Real) diff --git a/tests/check-types.hs b/tests/check-types.hs index 8aa8bb5..9cd57c2 100644 --- a/tests/check-types.hs +++ b/tests/check-types.hs @@ -74,7 +74,7 @@ newtypeCMode :: CMode -> Word32 #endif newtypeCMode (CMode x) = x -#if defined darwin_HOST_OS && MIN_VERSION_base(4,14,0) +#if defined darwin_HOST_OS && MIN_VERSION_base(4, 14, 0) newtypeCNfds :: CNfds -> Word32 #else newtypeCNfds :: CNfds -> Word64 From 1a1c70ff7476b31313980e2bc38559e84488ed1d Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Sat, 1 Oct 2022 00:35:15 +0200 Subject: [PATCH 15/16] Fixed CPP for CNfds and CSocklen --- src/System/PosixCompat/Types.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System/PosixCompat/Types.hs b/src/System/PosixCompat/Types.hs index 5454a02..82fcbb9 100644 --- a/src/System/PosixCompat/Types.hs +++ b/src/System/PosixCompat/Types.hs @@ -32,7 +32,7 @@ module System.PosixCompat.Types ( , LinkCount , CNlink(..) #endif -#if !MIN_VERSION_base(4, 14, 0) +#if defined mingw32_HOST_OS || !MIN_VERSION_base(4, 14, 0) , CNfds(..) , CSocklen(..) #endif From ef0c9e6ad056c082a1d6d6918fb3865e8954f5f5 Mon Sep 17 00:00:00 2001 From: Mann mit Hut Date: Sat, 1 Oct 2022 00:46:18 +0200 Subject: [PATCH 16/16] Adjusted tests for some types on Windows --- tests/check-types.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/check-types.hs b/tests/check-types.hs index 9cd57c2..3505046 100644 --- a/tests/check-types.hs +++ b/tests/check-types.hs @@ -36,6 +36,8 @@ newtypeCClockId (CClockId x) = x #ifdef darwin_HOST_OS newtypeCDev :: CDev -> Int32 +#elif defined mingw32_HOST_OS +newtypeCDev :: CDev -> Word32 #else newtypeCDev :: CDev -> Word64 #endif @@ -61,7 +63,11 @@ newtypeCGid (CGid x) = x newtypeCId :: CId -> Word32 newtypeCId (CId x) = x +#ifdef mingw32_HOST_OS +newtypeCIno :: CIno -> Word16 +#else newtypeCIno :: CIno -> Word64 +#endif newtypeCIno (CIno x) = x newtypeCKey :: CKey -> Int32 @@ -69,6 +75,8 @@ newtypeCKey (CKey x) = x #ifdef darwin_HOST_OS newtypeCMode :: CMode -> Word16 +#elif defined mingw32_HOST_OS +newtypeCMode :: CMode -> Word16 #else newtypeCMode :: CMode -> Word32 #endif @@ -91,7 +99,11 @@ newtypeCNlink (CNlink x) = x newtypeCOff :: COff -> Int64 newtypeCOff (COff x) = x +#ifdef mingw32_HOST_OS +newtypeCPid :: CPid -> Int64 +#else newtypeCPid :: CPid -> Int32 +#endif newtypeCPid (CPid x) = x newtypeCRLim :: CRLim -> Word64