From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: documentation.scm close files Date: Thu, 08 May 2003 08:58:00 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87smrqxt3b.fsf@zip.com.au> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1052348543 20411 80.91.224.249 (7 May 2003 23:02:23 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 7 May 2003 23:02:23 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu May 08 01:02:20 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19DXvY-0005It-00 for ; Thu, 08 May 2003 01:02:20 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19DXth-0002JD-02 for guile-devel@m.gmane.org; Wed, 07 May 2003 19:00:25 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 19DXsQ-0001B7-00 for guile-devel@gnu.org; Wed, 07 May 2003 18:59:07 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 19DXrz-00006Z-00 for guile-devel@gnu.org; Wed, 07 May 2003 18:58:41 -0400 Original-Received: from snoopy.pacific.net.au ([61.8.0.36]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19DXrd-0007fA-00 for guile-devel@gnu.org; Wed, 07 May 2003 18:58:17 -0400 Original-Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.2.228.40]) h47MwCPc003036 for ; Thu, 8 May 2003 08:58:13 +1000 Original-Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id h47MwCQg011738 for ; Thu, 8 May 2003 08:58:12 +1000 (EST) Original-Received: from localhost (ppp108.dyn228.pacific.net.au [203.143.228.108]) by wisma.pacific.net.au (8.12.9/8.12.9) with ESMTP id h47MwAYZ028716 for ; Thu, 8 May 2003 08:58:11 +1000 (EST) Original-Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 19DXrN-0006OW-00; Thu, 08 May 2003 08:58:01 +1000 Original-To: guile-devel@gnu.org User-Agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.2 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2285 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2285 --=-=-= 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" --=-=-= Content-Disposition: attachment; filename=documentation.scm.with-input.diff --- 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))))))))) @@ -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) --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel --=-=-=--