unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
Subject: documentation.scm close files
Date: Thu, 08 May 2003 08:58:00 +1000	[thread overview]
Message-ID: <87smrqxt3b.fsf@zip.com.au> (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

             reply	other threads:[~2003-05-07 22:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-07 22:58 Kevin Ryde [this message]
2003-05-17 20:07 ` documentation.scm close files 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87smrqxt3b.fsf@zip.com.au \
    --to=user42@zip.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).