unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* documentation.scm close files
@ 2003-05-07 22:58 Kevin Ryde
  2003-05-17 20:07 ` Marius Vollmer
  0 siblings, 1 reply; 12+ messages in thread
From: Kevin Ryde @ 2003-05-07 22:58 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 957 bytes --]

In documentation.scm I noticed file-commentary and
find-documentation-in-file don't close their files before returning.
I think it'd be good to do so explicitly,

        * documentation.scm (file-commentary, find-documentation-in-file): Use
        call-with-input-file, so as to close ports when done.

(Patch below, un-indented to make the changes clear.)

I know ports get closed when gc'ed, but I'd suggest it does the system
and the program no good to keep stuff open long after finished with.

As it stands, in fact, by artificially lowering the number of files
available an error can be induced (on my i386 debian at least),

	ulimit -n 30
	guile -s foo.scm

with foo.scm containing

	(use-modules (ice-9 documentation))
	(while #t (file-commentary "/dev/null"))
or
	(use-modules (ice-9 documentation))
	(while #t (search-documentation-files 'car "/dev/null"))

both giving

	ERROR: In procedure open-file:
	ERROR: Too many open files: "/dev/null"


[-- Attachment #2: documentation.scm.with-input.diff --]
[-- Type: text/plain, Size: 1713 bytes --]

--- documentation.scm.~1.8.~	2003-04-07 08:04:58.000000000 +1000
+++ documentation.scm	2003-05-06 13:44:39.000000000 +1000
@@ -115,8 +115,9 @@
                    default-scrub
                    (let ((v (caddr cust)))
                      (cond ((procedure? v) v)
-                           (else default-scrub)))))
-        (port (open-input-file filename)))
+                           (else default-scrub))))))
+    (call-with-input-file filename
+      (lambda (port)
     (let loop ((line (read-delimited "\n" port))
                (doc "")
                (parse-state 'before))
@@ -132,7 +133,7 @@
                       (if (and (eq? 'in new-state) (eq? 'in parse-state))
                           (string-append doc (scrub line) "\n")
                           doc)
-                      new-state)))))))
+                      new-state)))))))))
 
 \f
 
@@ -151,8 +152,9 @@
 
 (define (find-documentation-in-file name file)
   (and (file-exists? file)
-       (let ((port (open-input-file file))
-	     (name (symbol->string name)))
+       (call-with-input-file file
+	 (lambda (port)
+       (let ((name (symbol->string name)))
 	 (let ((len (string-length name)))
 	   (read-delimited entry-delimiter port) ;skip to first entry
 	   (let loop ((entry (read-delimited entry-delimiter port)))
@@ -166,7 +168,7 @@
 			 (memq (string-ref entry len) '(#\newline)))
 		    ;; cut away name tag and extra surrounding newlines
 		    (substring entry (+ len 2) (- (string-length entry) 2)))
-		   (else (loop (read-delimited entry-delimiter port)))))))))
+		   (else (loop (read-delimited entry-delimiter port)))))))))))
 
 (define (search-documentation-files name . files)
   (or-map (lambda (file)

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2003-06-05  1:17 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-05-07 22:58 documentation.scm close files Kevin Ryde
2003-05-17 20:07 ` Marius Vollmer
2003-05-18 22:54   ` Kevin Ryde
2003-05-21 22:40     ` Kevin Ryde
2003-05-22  9:59       ` tomas
2003-05-24  1:50         ` Kevin Ryde
2003-05-24  8:46           ` tomas
2003-06-05  1:00             ` Kevin Ryde
2003-05-22 15:20       ` Marius Vollmer
2003-05-23 21:20         ` Kevin Ryde
2003-06-01 21:02           ` Marius Vollmer
2003-06-05  1:17         ` doco with-input-from-file, with-output-to-file (was: documentation.scm close files) Kevin Ryde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).