Skip to content
Snippets Groups Projects
Commit a47a4aac authored by sof's avatar sof
Browse files

[project @ 1999-09-30 12:42:25 by sof]

primGetClockTime was incorrectly calling prim_getClockTime; fixed dormant bug in Show instance for ClockTime
parent 15e576ec
No related merge requests found
......@@ -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}
/*
* (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);
}
}
/*
* (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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment