1.0.29.39: SLEEP on large integers
authorNikodemus Siivola <nikodemus@random-state.net>
Thu, 25 Jun 2009 10:32:55 +0000 (10:32 +0000)
committerNikodemus Siivola <nikodemus@random-state.net>
Thu, 25 Jun 2009 10:32:55 +0000 (10:32 +0000)
* Truncate arguments to nanosleep to SIGNED-WORD -- sleeping for 68
  years should be enough for anyone. (reported by Leslie Polzer, patch
  by Stas Boukarev)

* Also fix a snafu from the last commit: GET-UNIVERSAL-TIME, not
  GET-INTERNAL-REAL. Feh.

NEWS
src/code/toplevel.lisp
src/compiler/main.lisp
tests/interface.pure.lisp
version.lisp-expr

diff --git a/NEWS b/NEWS
index 219257d..68c9042 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -41,6 +41,9 @@
     anymore.
   * bug fix: GENTEMP is now unaffected by pretty printer dispatch table.
     (thanks to Alex Plotnick)
+  * bug fix: SLEEP accepts large integer arguments, truncating them to
+    SIGNED-WORD on the assumption that sleeping for 68 years is sufficient
+    for anyone. (reported by Leslie Polzer, thanks to Stas Boukarev)
 
 changes in sbcl-1.0.29 relative to 1.0.28:
   * IMPORTANT: bug database has moved from the BUGS file to Launchpad
index 419e8a1..66b0b3f 100644 (file)
@@ -156,27 +156,29 @@ command-line.")
 \f
 ;;;; miscellaneous external functions
 
-(defun sleep (n)
+(defun sleep (seconds)
   #!+sb-doc
-  "This function causes execution to be suspended for N seconds. N may
-  be any non-negative, non-complex number."
-  (when (or (not (realp n))
-            (minusp n))
+  "This function causes execution to be suspended for SECONDS. SECONDS may be
+any non-negative real number."
+  (when (or (not (realp seconds))
+            (minusp seconds))
     (error 'simple-type-error
            :format-control "invalid argument to SLEEP: ~S"
-           :format-arguments (list n)
-           :datum n
+           :format-arguments (list seconds)
+           :datum seconds
            :expected-type '(real 0)))
   #!-win32
   (multiple-value-bind (sec nsec)
-      (if (integerp n)
-          (values n 0)
+      (if (integerp seconds)
+          (values seconds 0)
           (multiple-value-bind (sec frac)
-              (truncate n)
+              (truncate seconds)
             (values sec (truncate frac 1e-9))))
-    (sb!unix:nanosleep sec nsec))
+    ;; nanosleep accepts time_t as the first argument,
+    ;; so truncating is needed. 68 years on 32-bit platform should be enough
+    (sb!unix:nanosleep (min sec (1- (ash 1 (1- sb!vm:n-word-bits)))) nsec))
   #!+win32
-  (sb!win32:millisleep (truncate (* n 1000)))
+  (sb!win32:millisleep (truncate (* seconds 1000)))
   nil)
 \f
 ;;;; the default toplevel function
index 00d78a0..759f06e 100644 (file)
                               (print-unreadable-object (s stream :type t))))
              (:copier nil))
   ;; the UT that compilation started at
-  (start-time (get-internal-real) :type unsigned-byte)
+  (start-time (get-universal-time) :type unsigned-byte)
   ;; the IRT that compilation started at
   (start-real-time (get-internal-real-time) :type unsigned-byte)
   ;; the FILE-INFO structure for this compilation
index 285ddcb..81a987b 100644 (file)
       (sleep 2)
       (sleep 2))))
 
+;;; SLEEP should work with large integers as well -- no timers
+;;; on win32, so don't test there.
+#-win32
+(with-test (:name (sleep pretty-much-forever))
+  (assert (eq :timeout
+              (handler-case
+                  (sb-ext:with-timeout 1
+                    (sleep (ash 1 (* 2 sb-vm:n-word-bits))))
+                (sb-ext:timeout ()
+                  :timeout)))))
+
 ;;; DOCUMENTATION should return nil, not signal slot-unbound
 (documentation 'fixnum 'type)
 (documentation 'class 'type)
index 467aa95..a87f76c 100644 (file)
@@ -17,4 +17,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"1.0.29.38"
+"1.0.29.39"