* with-input-from-file, call-with-input-file, with-output-to-file,

and call-with-output-file no longer use dynamic-wind to track if
  an exit continuation is invoked multiple times.
This commit is contained in:
Abdulaziz Ghuloum 2006-12-21 10:56:07 +03:00
parent f7aa4c99e1
commit 2fcae826d1
4 changed files with 36 additions and 44 deletions

1
TODO
View File

@ -1,4 +1,5 @@
* Guardians: * Guardians:
CHECK - Implement guardians.
- clean up after file ports are dead by flushing/closing the - clean up after file ports are dead by flushing/closing the
underlying file handle. underlying file handle.

Binary file not shown.

View File

@ -679,16 +679,15 @@
(error 'with-output-to-file "~s is not a procedure" proc)) (error 'with-output-to-file "~s is not a procedure" proc))
(let ([p (apply open-output-file name args)] (let ([p (apply open-output-file name args)]
[shot #f]) [shot #f])
(parameterize ([current-output-port p]) (call-with-values
(dynamic-wind (lambda ()
(lambda () (parameterize ([current-output-port p])
(when shot (proc)))
(error 'with-output-to-file (case-lambda
"cannot reenter"))) [(v) (close-output-port p) v]
proc [v*
(lambda () (close-output-port p)
(close-output-port p) (apply values v*)])))))
(set! shot #t)))))))
(primitive-set! 'call-with-output-file (primitive-set! 'call-with-output-file
(lambda (name proc . args) (lambda (name proc . args)
@ -696,16 +695,13 @@
(error 'call-with-output-file "~s is not a string" name)) (error 'call-with-output-file "~s is not a string" name))
(unless (procedure? proc) (unless (procedure? proc)
(error 'call-with-output-file "~s is not a procedure" proc)) (error 'call-with-output-file "~s is not a procedure" proc))
(let ([p (apply open-output-file name args)] (let ([p (apply open-output-file name args)])
[shot #f]) (call-with-values (lambda () (proc p))
(dynamic-wind (case-lambda
(lambda () [(v) (close-output-port p) v]
(when shot [v*
(error 'call-with-output-file "cannot reenter"))) (close-output-port p)
(lambda () (proc p)) (apply values v*)])))))
(lambda ()
(close-output-port p)
(set! shot #t))))))
(primitive-set! 'with-input-from-file (primitive-set! 'with-input-from-file
(lambda (name proc) (lambda (name proc)
@ -713,33 +709,28 @@
(error 'with-input-from-file "~s is not a string" name)) (error 'with-input-from-file "~s is not a string" name))
(unless (procedure? proc) (unless (procedure? proc)
(error 'with-input-from-file "~s is not a procedure" proc)) (error 'with-input-from-file "~s is not a procedure" proc))
(let ([p (open-input-file name)] (let ([p (open-input-file name)])
[shot #f]) (call-with-values
(parameterize ([current-input-port p]) (lambda ()
(dynamic-wind (parameterize ([current-input-port p])
(lambda () (proc)))
(when shot (case-lambda
(error 'with-input-from-file [(v) (close-input-port p) v]
"cannot reenter"))) [v*
proc (close-input-port p)
(lambda () (apply values v*)])))))
(close-input-port p)
(set! shot #t)))))))
(primitive-set! 'call-with-input-file (primitive-set! 'call-with-input-file
(lambda (name proc) (lambda (name proc)
(unless (string? name) (unless (string? name)
(error 'call-with-input-file "~s is not a string" name)) (error 'call-with-input-file "~s is not a string" name))
(unless (procedure? proc) (unless (procedure? proc)
(error 'call-with-input-file "~s is not a procedure" proc)) (error 'call-with-input-file "~s is not a procedure" proc))
(let ([p (open-input-file name)] (let ([p (open-input-file name)])
[shot #f]) (call-with-values (lambda () (proc p))
(dynamic-wind (case-lambda
(lambda () [(v) (close-input-port p) v]
(when shot [v*
(error 'call-with-input-file "cannot reenter"))) (close-input-port p)
(lambda () (proc p)) (apply values v*)])))))
(lambda ()
(close-input-port p)
(set! shot #t))))))
) )

View File

@ -83,7 +83,7 @@
file-exists? delete-file + - add1 sub1 * expt file-exists? delete-file + - add1 sub1 * expt
quotient+remainder quotient remainder number? positive? quotient+remainder quotient remainder number? positive?
negative? zero? number->string logand = < > <= >= negative? zero? number->string logand = < > <= >=
make-guardian make-guardian weak-cons
)) ))
(define system-primitives (define system-primitives