diff --git a/ghc/lib/std/Time.lhs b/ghc/lib/std/Time.lhs index b9bd4caa9efc4d647ae0b6263766e107b3112b44..20d75100f5cd9d363c73fdd1054ae66d6938ed21 100644 --- a/ghc/lib/std/Time.lhs +++ b/ghc/lib/std/Time.lhs @@ -44,7 +44,9 @@ import PrelHandle import PrelArr import PrelST import PrelAddr -import PrelPack ( unpackCString, new_ps_array ) +import PrelPack ( unpackCString, new_ps_array, + freeze_ps_array, unpackCStringBA + ) #endif import Ix @@ -100,9 +102,17 @@ instance Show ClockTime where case int2Integer# i of (# s, d #) -> showsPrec p (TOD (J# s d) _nsec) showsPrec _ (TOD (J# s# d#) _nsec) = showString $ unsafePerformIO $ do - buf <- allocChars 38 -- exactly enough for error message - str <- showTime (I# s#) d# buf - return (unpackCString str) + let buflen@(I# buflen#) = 50 -- big enough for error message + buf <- allocChars buflen + if s# <# (negateInt# 1#) || s# ># 1# then + return "ClockTime.show{Time}: out of range" + else do + rc <- showTime (I# s#) d# buflen buf + if rc < 0 then + return "ClockTime.show{Time}: internal error" + else do + ba <- stToIO (freeze_ps_array buf buflen#) + return (unpackCStringBA ba) showList = showList__ (showsPrec 0) #endif @@ -603,13 +613,14 @@ foreign import "libHS_cbits" "toClockSec" toClockSec :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> MBytes -> IO Int -foreign import "libHS_cbits" "prim_getClockTime" +foreign import "libHS_cbits" "getClockTime" primGetClockTime :: MutableByteArray RealWorld Int -> MutableByteArray RealWorld Int -> IO Int foreign import "libHS_cbits" "showTime" showTime :: Int -> Bytes + -> Int -> MBytes - -> IO Addr{-packed C string -} + -> IO Int \end{code} diff --git a/ghc/lib/std/cbits/showTime.c b/ghc/lib/std/cbits/showTime.c index 1ec1ddd2c8ea06da780eeb8da2cc0725181ec8a5..4efab2c09b29e844bc4f26d262874b22781cf52b 100644 --- a/ghc/lib/std/cbits/showTime.c +++ b/ghc/lib/std/cbits/showTime.c @@ -1,7 +1,7 @@ /* * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998 * - * $Id: showTime.c,v 1.3 1998/12/02 13:27:57 simonm Exp $ + * $Id: showTime.c,v 1.4 1999/09/30 12:42:26 sof Exp $ * * ClockTime.showsPrec Runtime Support */ @@ -21,31 +21,28 @@ #endif StgAddr -showTime(I_ size, StgByteArray d, StgByteArray buf) +showTime(I_ size, StgByteArray d, I_ maxsize, StgByteArray buf) { time_t t; struct tm *tm; switch(size) { - default: - return (StgAddr)strcpy(buf, "ClockTime.show{LibTime}: out of range"); case 0: t = 0; break; case -1: t = - (time_t) ((StgInt *)d)[0]; - if (t > 0) - return - (StgAddr)strcpy(buf, "ClockTime.show{LibTime}: out of range"); break; case 1: t = (time_t) ((StgInt *)d)[0]; - if (t < 0) - return (StgAddr) strcpy(buf, "ClockTime.show{LibTime}: out of range"); break; + default: + return (-1); } tm = localtime(&t); - if (tm != NULL && strftime(buf, 32 /*Magic number*/, "%a %b %d %T %Z %Y", tm) > 0) - return (StgAddr)buf; - return (StgAddr)strcpy(buf, "ClockTime.show{LibTime}: internal error"); + if (tm != NULL && strftime(buf, maxsize, "%a %b %d %T %Z %Y", tm) > 0) { + return 1; + } else { + return (-1); + } } diff --git a/ghc/lib/std/cbits/stgio.h b/ghc/lib/std/cbits/stgio.h index 0e3bb7770c70a1c51f9aa6eab0ef13091ca9c763..8dfa5c2b9344ccbc4e3f92d41849e8c9fba9b572 100644 --- a/ghc/lib/std/cbits/stgio.h +++ b/ghc/lib/std/cbits/stgio.h @@ -1,7 +1,7 @@ /* * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998 * - * $Id: stgio.h,v 1.12 1999/09/19 19:26:57 sof Exp $ + * $Id: stgio.h,v 1.13 1999/09/30 12:42:26 sof Exp $ * * Helper code for GHC's IO subsystem. */ @@ -196,7 +196,7 @@ StgInt const_BUFSIZ (void); StgInt setCurrentDirectory (StgByteArray); /* showTime.c */ -StgAddr showTime (StgInt, StgByteArray, StgByteArray); +StgInt showTime (StgInt, StgByteArray, StgInt, StgByteArray); /* system.c */ StgInt systemCmd (StgByteArray);