haskell / win32

Haskell support for the Win32 API
http://hackage.haskell.org/package/Win32
Other
97 stars 63 forks source link

poke and peek aren't inverses for TIME_ZONE_INFORMATION #64

Closed RyanGlScott closed 7 years ago

RyanGlScott commented 7 years ago
module Main where

import Control.Exception (assert)
import Foreign
import System.Win32.Time

main :: IO ()
main = do
    (_, tzi) <- getTimeZoneInformation
    alloca $ \buf -> do
        poke buf tzi
        tzi' <- peek buf
        print tzi
        print tzi'
        assert (tzi == tzi') $ return ()
$ runghc TZI.hs
TIME_ZONE_INFORMATION {tziBias = 300, tziStandardName = "Eastern Standard Time", tziStandardDate = SYSTEMTIME {wYear = 0, wMonth = 11, wDayOfWeek = 0, wDay = 1, wHour = 2, wMinute = 0, wSecond = 0, wMilliseconds = 0}, tziStandardBias = 0, tziDaylightName = "Eastern Daylight Time", tziDaylightDate = SYSTEMTIME {wYear = 0, wMonth = 3, wDayOfWeek = 0, wDay = 2, wHour = 2, wMinute = 0, wSecond = 0, wMilliseconds = 0}, tziDaylightBias = -60}
TIME_ZONE_INFORMATION {tziBias = 300, tziStandardName = "", tziStandardDate = SYSTEMTIME {wYear = 0, wMonth = 11, wDayOfWeek = 0, wDay = 1, wHour = 2, wMinute = 0, wSecond = 0, wMilliseconds = 0}, tziStandardBias = 0, tziDaylightName = "\54232\2564", tziDaylightDate = SYSTEMTIME {wYear = 0, wMonth = 3, wDayOfWeek = 0, wDay = 2, wHour = 2, wMinute = 0, wSecond = 0, wMilliseconds = 0}, tziDaylightBias = -60}
TZI.hs: Assertion failed
CallStack (from HasCallStack):
  assert, called at TZI.hs:15:9 in main:Main

You'll notice that tzi and tzi' are almost the same, but their String values are different. I believe I know what's causing this, so I'll open a PR to fix it.