primGetClockTime was incorrectly calling prim_getClockTime; fixed dormant bug in Show instance for ClockTime
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
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
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
*/
#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.
*/
StgInt setCurrentDirectory (StgByteArray);
/* showTime.c */
-StgAddr showTime (StgInt, StgByteArray, StgByteArray);
+StgInt showTime (StgInt, StgByteArray, StgInt, StgByteArray);
/* system.c */
StgInt systemCmd (StgByteArray);