We are planning to upgrade GitLab to the latest version this Friday morning. Expect some downtime!

Commit d0593825 authored by Mart Lubbers's avatar Mart Lubbers

fix nsTime on 64 bit windows machines

parent 8d549114
Pipeline #31486 passed with stage
in 3 minutes and 3 seconds
implementation module System.Time implementation module System.Time
import StdString, StdArray, StdClass, StdOverloaded, StdInt, StdMisc, StdBool import StdEnv
import System._Pointer import System._Pointer
import System._WinBase import System._WinBase
import Data.Integer import Data.Integer
...@@ -166,18 +166,31 @@ packTm32 tm = { tm.sec ...@@ -166,18 +166,31 @@ packTm32 tm = { tm.sec
, tm.yday , tm.yday
, tm.isdst , tm.isdst
} }
//Number of ticks difference between the windows and linux epoch
TICKSDIFF :== {integer_s=0,integer_a={-1240428288,2}} * TICKSPERSEC //Number of 100ns ticks difference between the windows and linux epoch
//Number of ticks per second on windows machines TICKSDIFF32 =: toInteger "11644473600" * TICKSPERSEC32
TICKSPERSEC :== {integer_s=10000000,integer_a={}} TICKSDIFF64 =: 11644473600 * TICKSPERSEC64
BIGTWO :== {integer_s=2,integer_a={}}
//Number of ticks per second (100 ns ticks)
TICKSPERSEC32 =: toInteger 10000000
TICKSPERSEC64 =: 10000000
/*
* On windows GetSystemTimeAsFileTime returns a struct containing 2 32bit unsigned integers.
* On 64 bit we therefore use an array of length 1, on 32 bit of length two.
* On 64 bit we can use native integers, on windows we use bigints.
*/
nsTime :: !*World -> (!Timespec, !*World) nsTime :: !*World -> (!Timespec, !*World)
nsTime w nsTime w = IF_INT_64_OR_32 nsTime64 nsTime32 w
# (is, w) = GetSystemTimeAsFileTime (createArray 2 0) w where
# ticks = uintToInt is.[0] + foldr ($) (uintToInt is.[1]) (repeatn 32 ((*) BIGTWO)) - TICKSDIFF nsTime64 w
= ({Timespec | tv_sec=toInt (ticks / TICKSPERSEC), tv_nsec=toInt (ticks rem TICKSPERSEC) *100}, w) # (is, w) = GetSystemTimeAsFileTime {0} w
= ({tv_sec=(is.[0] - TICKSDIFF64) / TICKSPERSEC64, tv_nsec=(is.[0] rem TICKSPERSEC64) * 100}, w)
nsTime32 w
# (is, w) = GetSystemTimeAsFileTime {0,0} w
# ticks = uintToInt is.[0] + foldr ($) (uintToInt is.[1]) (repeatn 32 ((*) (toInteger 2))) - TICKSDIFF32
= ({tv_sec=toInt (ticks / TICKSPERSEC32), tv_nsec=toInt (ticks rem TICKSPERSEC32) * 100}, w)
uintToInt :: Int -> Integer uintToInt :: Int -> Integer
uintToInt i uintToInt i
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment