1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 03:30:27 +02:00

file-exists? doesn't cause a throw, simpler try-module-autoload

* module/ice-9/boot-9.scm (file-exists?): Change to use the stat
  interface that doesn't throw exceptions.
  (try-module-autoload): Simplify to take advantage of the fact that
  primitive-load-path does the right thing with regards to loading
  compiled files if they are available.
This commit is contained in:
Andy Wingo 2009-06-02 22:39:30 +02:00
parent d1e47c6e6c
commit 727c259ac5

View file

@ -611,12 +611,10 @@
(primitive-load-path "ice-9/networking"))
;; For reference, Emacs file-exists-p uses stat in this same way.
;; ENHANCE-ME: Catching an exception from stat is a bit wasteful, do this in
;; C where all that's needed is to inspect the return from stat().
(define file-exists?
(if (provided? 'posix)
(lambda (str)
(->bool (false-if-exception (stat str))))
(->bool (stat str #f)))
(lambda (str)
(let ((port (catch 'system-error (lambda () (open-file str OPEN_READ))
(lambda args #f))))
@ -2278,21 +2276,10 @@ module '(ice-9 q) '(make-q q-length))}."
(dynamic-wind
(lambda () (autoload-in-progress! dir-hint name))
(lambda ()
(let ((file (in-vicinity dir-hint name)))
(let ((compiled (and load-compiled
(%search-load-path
(string-append file ".go"))))
(source (%search-load-path file)))
(cond ((and source
(or (not compiled)
(< (stat:mtime (stat compiled))
(stat:mtime (stat source)))))
(if compiled
(warn "source file" source "newer than" compiled))
(with-fluid* current-reader #f
(lambda () (load-file primitive-load source))))
(compiled
(load-file load-compiled compiled))))))
(with-fluid* current-reader #f
(lambda ()
(load-file primitive-load-path
(in-vicinity dir-hint name)))))
(lambda () (set-autoloaded! dir-hint name didit)))
didit))))