[project @ 1999-09-30 12:42:25 by sof]
authorsof <unknown>
Thu, 30 Sep 1999 12:42:26 +0000 (12:42 +0000)
committersof <unknown>
Thu, 30 Sep 1999 12:42:26 +0000 (12:42 +0000)
primGetClockTime was incorrectly calling prim_getClockTime; fixed dormant bug in Show instance for ClockTime

ghc/lib/std/Time.lhs
ghc/lib/std/cbits/showTime.c
ghc/lib/std/cbits/stgio.h

index b9bd4ca..20d7510 100644 (file)
@@ -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}
index 1ec1ddd..4efab2c 100644 (file)
@@ -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
  */
 #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);
+    }
 }
index 0e3bb77..8dfa5c2 100644 (file)
@@ -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);