hraban / trivial-shell

A simple Common-Lisp interface to the underlying Operating System
http://common-lisp.net/project/trivial-shell
Other
31 stars 7 forks source link

trivial-timeout weird in my SBCL 1.1.13 #8

Open muyinliu opened 10 years ago

muyinliu commented 10 years ago
* (ql:quickload "trivial-shell")
To load "trivial-shell":
  Install 1 Quicklisp release:
    trivial-shell
; Fetching #<URL "http://beta.quicklisp.org/archive/trivial-shell/2013-03-12/trivial-shell-20130312-git.tgz">
; 13.97KB
==================================================
14,310 bytes in 0.01 seconds (1164.55KB/sec)
; Loading "trivial-shell"
[package com.metabang.trivial-timeout]............
[package trivial-shell]..
("trivial-shell")
* (macroexpand-1 '(trivial-shell:with-timeout (0.2) (sleep 3)))

(LET ((#:|seconds-877| 0.2))
  (FLET ((#:|doit-878| ()
           (PROGN (SLEEP 3))))
    (COND
     (#:|seconds-877|
      (HANDLER-CASE
       (WITH-TIMEOUT #:|seconds-877|
         (#:|doit-878|))
       (TIMEOUT (COM.METABANG.TRIVIAL-TIMEOUT::C)
        (DECLARE (IGNORE COM.METABANG.TRIVIAL-TIMEOUT::C))
        (ERROR 'COM.METABANG.TRIVIAL-TIMEOUT:TIMEOUT-ERROR))))
     (T (#:|doit-878|)))))
T
* (quit)
~$ sbcl
This is SBCL 1.1.13, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (ql:quickload "trivial-shell")
To load "trivial-shell":
  Load 1 ASDF system:
    trivial-shell
; Loading "trivial-shell"

("trivial-shell")
* (macroexpand-1 '(trivial-shell:with-timeout (0.2) (sleep 3)))

(LET ((#:|seconds-768| 0.2))
  (FLET ((#:|doit-769| ()
           (PROGN (SLEEP 3))))
    (COND (#:|seconds-768| (#:|doit-769|)) (T (#:|doit-769|)))))
T

First time trivial-timeout works fine. But after that, it's so weird! And I try the same code on SBCL 1.1.14.27-df21751, the same result.

I try standalone trivial-timeout(without trivial-shell), it works fine. Is there something wrong in trivial-shell's ASD files? I copy with-timeout.lisp from standalone trivial-timeout to replace the on in trivial-shell, and it works fine.

The only difference between them is the position of function build-with-timeout and macro with-timeout, before generate-platform-specific-code in trivial-timeout and after generate-platform-specific-code in trivial-shell's with-timeout.lisp.

gwkkwg commented 10 years ago

That's curious. I'll take a look.

gwkkwg commented 10 years ago

The source file uses this form to define the platform specific code for platforms that it doesn't know about

(unless (let ((symbol
         (find-symbol (symbol-name '#:generate-platform-specific-code)
          '#:com.metabang.trivial-timeout)))
    (and symbol (fboundp symbol)))
  (defun generate-platform-specific-code (seconds-symbol doit-symbol)
    (declare (ignore seconds-symbol))
    `(,doit-symbol)))

On SBCL, this is working the way I intended when the file is compiled but not when the file is loaded. I'll get a fix out soon.