From e6e1d8b3ea002440b1df35703609fab3815d47b2 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Tue, 19 May 2020 09:28:36 +0900 Subject: [PATCH] removing undefined as many as possible. --- Network/Socket/ByteString/Lazy/Posix.hs | 2 +- Network/Socket/Info.hsc | 31 ++++--------------------- Network/Socket/Options.hsc | 4 ++-- Network/Socket/Posix/Cmsg.hsc | 12 +++++----- Network/Socket/Posix/CmsgHdr.hsc | 4 ++-- Network/Socket/Posix/IOVec.hsc | 4 ++-- Network/Socket/Posix/MsgHdr.hsc | 4 ++-- Network/Socket/Types.hsc | 6 ++--- Network/Socket/Unix.hsc | 4 ++-- Network/Socket/Win32/Cmsg.hsc | 4 ++-- Network/Socket/Win32/CmsgHdr.hsc | 2 +- Network/Socket/Win32/MsgHdr.hsc | 2 +- Network/Socket/Win32/WSABuf.hsc | 2 +- 13 files changed, 30 insertions(+), 51 deletions(-) diff --git a/Network/Socket/ByteString/Lazy/Posix.hs b/Network/Socket/ByteString/Lazy/Posix.hs index fa1c4fde..5d799bea 100644 --- a/Network/Socket/ByteString/Lazy/Posix.hs +++ b/Network/Socket/ByteString/Lazy/Posix.hs @@ -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 diff --git a/Network/Socket/Info.hsc b/Network/Socket/Info.hsc index 463c9ce7..9e7fb276 100644 --- a/Network/Socket/Info.hsc +++ b/Network/Socket/Info.hsc @@ -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 @@ -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 -- [] @@ -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 = " - , "" - , ", addrCanonName = " - , "" - , "}" - ] - ----------------------------------------------------------------------------- -- | Resolve a host or service name to one or more addresses. -- The 'AddrInfo' values that this function returns contain 'SockAddr' @@ -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: " diff --git a/Network/Socket/Options.hsc b/Network/Socket/Options.hsc index 5e1d4ad7..efe31f77 100644 --- a/Network/Socket/Options.hsc +++ b/Network/Socket/Options.hsc @@ -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 diff --git a/Network/Socket/Posix/Cmsg.hsc b/Network/Socket/Posix/Cmsg.hsc index 3d237d78..b695a8a4 100644 --- a/Network/Socket/Posix/Cmsg.hsc +++ b/Network/Socket/Posix/Cmsg.hsc @@ -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 @@ -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" @@ -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) @@ -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" diff --git a/Network/Socket/Posix/CmsgHdr.hsc b/Network/Socket/Posix/CmsgHdr.hsc index 3a26ced2..f122ea3b 100644 --- a/Network/Socket/Posix/CmsgHdr.hsc +++ b/Network/Socket/Posix/CmsgHdr.hsc @@ -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 diff --git a/Network/Socket/Posix/IOVec.hsc b/Network/Socket/Posix/IOVec.hsc index 90d0b5ae..fc84b888 100644 --- a/Network/Socket/Posix/IOVec.hsc +++ b/Network/Socket/Posix/IOVec.hsc @@ -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 diff --git a/Network/Socket/Posix/MsgHdr.hsc b/Network/Socket/Posix/MsgHdr.hsc index 3c812a06..40b1c7a5 100644 --- a/Network/Socket/Posix/MsgHdr.hsc +++ b/Network/Socket/Posix/MsgHdr.hsc @@ -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 diff --git a/Network/Socket/Types.hsc b/Network/Socket/Types.hsc index 3eb2d465..d2ee1766 100644 --- a/Network/Socket/Types.hsc +++ b/Network/Socket/Types.hsc @@ -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) @@ -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 diff --git a/Network/Socket/Unix.hsc b/Network/Socket/Unix.hsc index e70409d2..9e55e3c0 100644 --- a/Network/Socket/Unix.hsc +++ b/Network/Socket/Unix.hsc @@ -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 diff --git a/Network/Socket/Win32/Cmsg.hsc b/Network/Socket/Win32/Cmsg.hsc index b84c592c..b7a192c5 100644 --- a/Network/Socket/Win32/Cmsg.hsc +++ b/Network/Socket/Win32/Cmsg.hsc @@ -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) @@ -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) diff --git a/Network/Socket/Win32/CmsgHdr.hsc b/Network/Socket/Win32/CmsgHdr.hsc index e1248a6d..3773374c 100644 --- a/Network/Socket/Win32/CmsgHdr.hsc +++ b/Network/Socket/Win32/CmsgHdr.hsc @@ -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 diff --git a/Network/Socket/Win32/MsgHdr.hsc b/Network/Socket/Win32/MsgHdr.hsc index da5f6b01..4b7b6fe3 100644 --- a/Network/Socket/Win32/MsgHdr.hsc +++ b/Network/Socket/Win32/MsgHdr.hsc @@ -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 diff --git a/Network/Socket/Win32/WSABuf.hsc b/Network/Socket/Win32/WSABuf.hsc index c5026434..13c4182e 100644 --- a/Network/Socket/Win32/WSABuf.hsc +++ b/Network/Socket/Win32/WSABuf.hsc @@ -20,7 +20,7 @@ data WSABuf = WSABuf } instance Storable WSABuf where - sizeOf = const #{size WSABUF} + sizeOf _ = #{size WSABUF} alignment _ = #alignment WSABUF peek p = do