Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removing undefined as many as possible. #456

Merged
merged 1 commit into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Network/Socket/ByteString/Lazy/Posix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ send s lbs = do
| k < maxNumBytes = unsafeUseAsCStringLen c $ \(ptr, len) -> do
poke q $ IOVec (castPtr ptr) (fromIntegral len)
loop cs
(q `plusPtr` sizeOf (undefined :: IOVec))
(q `plusPtr` sizeOf (IOVec nullPtr 0))
(k + fromIntegral len)
(niovs + 1)
| otherwise = f niovs
Expand Down
31 changes: 5 additions & 26 deletions Network/Socket/Info.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ data AddrInfo = AddrInfo {

instance Storable AddrInfo where
sizeOf _ = #const sizeof(struct addrinfo)
alignment _ = alignment (undefined :: CInt)
alignment _ = alignment (0 :: CInt)

peek p = do
ai_flags <- (#peek struct addrinfo, ai_flags) p
Expand Down Expand Up @@ -181,9 +181,7 @@ niFlagMapping = [(NI_DGRAM, #const NI_DGRAM),
(NI_NUMERICHOST, #const NI_NUMERICHOST),
(NI_NUMERICSERV, #const NI_NUMERICSERV)]

-- | Default hints for address lookup with 'getAddrInfo'. The values
-- of the 'addrAddress' and 'addrCanonName' fields are 'undefined',
-- and are never inspected by 'getAddrInfo'.
-- | Default hints for address lookup with 'getAddrInfo'.
--
-- >>> addrFlags defaultHints
-- []
Expand All @@ -200,29 +198,10 @@ defaultHints = AddrInfo {
, addrFamily = AF_UNSPEC
, addrSocketType = NoSocketType
, addrProtocol = defaultProtocol
, addrAddress = undefined
, addrCanonName = undefined
, addrAddress = SockAddrInet 0 0
, addrCanonName = Nothing
}

-- | Shows the fields of 'defaultHints', without inspecting the by-default undefined fields 'addrAddress' and 'addrCanonName'.
showDefaultHints :: AddrInfo -> String
showDefaultHints AddrInfo{..} = concat [
"AddrInfo {"
, "addrFlags = "
, show addrFlags
, ", addrFamily = "
, show addrFamily
, ", addrSocketType = "
, show addrSocketType
, ", addrProtocol = "
, show addrProtocol
, ", addrAddress = "
, "<assumed to be undefined>"
, ", addrCanonName = "
, "<assumed to be undefined>"
, "}"
]

-----------------------------------------------------------------------------
-- | Resolve a host or service name to one or more addresses.
-- The 'AddrInfo' values that this function returns contain 'SockAddr'
Expand Down Expand Up @@ -294,7 +273,7 @@ getAddrInfo hints node service = alloc getaddrinfo
err
message = concat [
"Network.Socket.getAddrInfo (called with preferred socket type/protocol: "
, maybe (show hints) showDefaultHints hints
, maybe "Nothing" show hints
, ", host name: "
, show node
, ", service name: "
Expand Down
4 changes: 2 additions & 2 deletions Network/Socket/Options.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ pattern CustomSockOpt xy <- ((\(SockOpt x y) -> (x, y)) -> xy)
data StructLinger = StructLinger CInt CInt

instance Storable StructLinger where
sizeOf _ = (#const sizeof(struct linger))
alignment _ = alignment (undefined :: CInt)
sizeOf _ = (#const sizeof(struct linger))
alignment _ = alignment (0 :: CInt)

peek p = do
onoff <- (#peek struct linger, l_onoff) p
Expand Down
12 changes: 6 additions & 6 deletions Network/Socket/Posix/Cmsg.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ instance ControlMessage IPv4PktInfo where

instance Storable IPv4PktInfo where
#if defined (IP_PKTINFO)
sizeOf _ = (#size struct in_pktinfo)
alignment _ = alignment (undefined :: CInt)
sizeOf _ = (#size struct in_pktinfo)
alignment _ = alignment (0 :: CInt)
poke p (IPv4PktInfo n sa ha) = do
(#poke struct in_pktinfo, ipi_ifindex) p (fromIntegral n :: CInt)
(#poke struct in_pktinfo, ipi_spec_dst) p sa
Expand All @@ -181,7 +181,7 @@ instance Storable IPv4PktInfo where
ha <- (#peek struct in_pktinfo, ipi_addr) p
return $ IPv4PktInfo n sa ha
#else
sizeOf _ = 0
sizeOf _ = 0
alignment _ = 1
poke _ _ = error "Unsupported control message type"
peek _ = error "Unsupported control message type"
Expand All @@ -200,8 +200,8 @@ instance ControlMessage IPv6PktInfo where

instance Storable IPv6PktInfo where
#if defined (IPV6_PKTINFO)
sizeOf _ = (#size struct in6_pktinfo)
alignment _ = alignment (undefined :: CInt)
sizeOf _ = (#size struct in6_pktinfo)
alignment _ = alignment (0 :: CInt)
poke p (IPv6PktInfo n ha6) = do
(#poke struct in6_pktinfo, ipi6_ifindex) p (fromIntegral n :: CInt)
(#poke struct in6_pktinfo, ipi6_addr) p (In6Addr ha6)
Expand All @@ -210,7 +210,7 @@ instance Storable IPv6PktInfo where
n :: CInt <- (#peek struct in6_pktinfo, ipi6_ifindex) p
return $ IPv6PktInfo (fromIntegral n) ha6
#else
sizeOf _ = 0
sizeOf _ = 0
alignment _ = 1
poke _ _ = error "Unsupported control message type"
peek _ = error "Unsupported control message type"
Expand Down
4 changes: 2 additions & 2 deletions Network/Socket/Posix/CmsgHdr.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ data CmsgHdr = CmsgHdr {
} deriving (Eq, Show)

instance Storable CmsgHdr where
sizeOf _ = (#size struct cmsghdr)
alignment _ = alignment (undefined :: CInt)
sizeOf _ = (#size struct cmsghdr)
alignment _ = alignment (0 :: CInt)

peek p = do
len <- (#peek struct cmsghdr, cmsg_len) p
Expand Down
4 changes: 2 additions & 2 deletions Network/Socket/Posix/IOVec.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ data IOVec = IOVec
}

instance Storable IOVec where
sizeOf _ = (#const sizeof(struct iovec))
alignment _ = alignment (undefined :: CInt)
sizeOf _ = (#const sizeof(struct iovec))
alignment _ = alignment (0 :: CInt)

peek p = do
base <- (#peek struct iovec, iov_base) p
Expand Down
4 changes: 2 additions & 2 deletions Network/Socket/Posix/MsgHdr.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ data MsgHdr sa = MsgHdr
}

instance Storable (MsgHdr sa) where
sizeOf _ = (#const sizeof(struct msghdr))
alignment _ = alignment (undefined :: CInt)
sizeOf _ = (#const sizeof(struct msghdr))
alignment _ = alignment (0 :: CInt)

peek p = do
name <- (#peek struct msghdr, msg_name) p
Expand Down
6 changes: 3 additions & 3 deletions Network/Socket/Types.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,8 @@ foreign import CALLCONV unsafe "ntohl" ntohl :: Word32 -> Word32
{-# DEPRECATED ntohl "Use getAddrInfo instead" #-}

instance Storable PortNumber where
sizeOf _ = sizeOf (undefined :: Word16)
alignment _ = alignment (undefined :: Word16)
sizeOf _ = sizeOf (0 :: Word16)
alignment _ = alignment (0 :: Word16)
poke p (PortNum po) = poke (castPtr p) (htons po)
peek p = PortNum . ntohs <$> peek (castPtr p)

Expand Down Expand Up @@ -1221,7 +1221,7 @@ newtype In6Addr = In6Addr HostAddress6
#endif

instance Storable In6Addr where
sizeOf _ = #const sizeof(struct in6_addr)
sizeOf _ = #const sizeof(struct in6_addr)
alignment _ = #alignment struct in6_addr

peek p = do
Expand Down
4 changes: 2 additions & 2 deletions Network/Socket/Unix.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ getPeerCred s = do

newtype PeerCred = PeerCred (CUInt, CUInt, CUInt)
instance Storable PeerCred where
sizeOf _ = (#const sizeof(struct ucred))
alignment _ = alignment (undefined :: CInt)
sizeOf _ = (#const sizeof(struct ucred))
alignment _ = alignment (0 :: CInt)
poke _ _ = return ()
peek p = do
pid <- (#peek struct ucred, pid) p
Expand Down
4 changes: 2 additions & 2 deletions Network/Socket/Win32/Cmsg.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ instance ControlMessage IPv4PktInfo where
controlMessageId = CmsgIdIPv4PktInfo

instance Storable IPv4PktInfo where
sizeOf = const #{size IN_PKTINFO}
sizeOf _ = #{size IN_PKTINFO}
alignment _ = #alignment IN_PKTINFO
poke p (IPv4PktInfo n ha) = do
(#poke IN_PKTINFO, ipi_ifindex) p (fromIntegral n :: CInt)
Expand All @@ -169,7 +169,7 @@ instance ControlMessage IPv6PktInfo where
controlMessageId = CmsgIdIPv6PktInfo

instance Storable IPv6PktInfo where
sizeOf = const #{size IN6_PKTINFO}
sizeOf _ = #{size IN6_PKTINFO}
alignment _ = #alignment IN6_PKTINFO
poke p (IPv6PktInfo n ha6) = do
(#poke IN6_PKTINFO, ipi6_ifindex) p (fromIntegral n :: CInt)
Expand Down
2 changes: 1 addition & 1 deletion Network/Socket/Win32/CmsgHdr.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ data CmsgHdr = CmsgHdr {
} deriving (Eq, Show)

instance Storable CmsgHdr where
sizeOf = const #{size WSACMSGHDR}
sizeOf _ = #{size WSACMSGHDR}
alignment _ = #alignment WSACMSGHDR

peek p = do
Expand Down
2 changes: 1 addition & 1 deletion Network/Socket/Win32/MsgHdr.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data MsgHdr sa = MsgHdr
} deriving Show

instance Storable (MsgHdr sa) where
sizeOf = const #{size WSAMSG}
sizeOf _ = #{size WSAMSG}
alignment _ = #alignment WSAMSG

peek p = do
Expand Down
2 changes: 1 addition & 1 deletion Network/Socket/Win32/WSABuf.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data WSABuf = WSABuf
}

instance Storable WSABuf where
sizeOf = const #{size WSABUF}
sizeOf _ = #{size WSABUF}
alignment _ = #alignment WSABUF

peek p = do
Expand Down