From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel Subject: Re: request for review: Doing direct file I/O in Emacs Lisp Date: 10 May 2004 08:52:33 +0200 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1084179822 17083 80.91.224.253 (10 May 2004 09:03:42 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 10 May 2004 09:03:42 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Mon May 10 11:03:37 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BN6hE-0001bt-00 for ; Mon, 10 May 2004 11:03:36 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BN6hE-00039M-00 for ; Mon, 10 May 2004 11:03:36 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.33) id 1BN6eU-0002MH-4T for emacs-devel@quimby.gnus.org; Mon, 10 May 2004 05:00:46 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.33) id 1BN6eA-0002KB-Nr for emacs-devel@gnu.org; Mon, 10 May 2004 05:00:26 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.33) id 1BN6dd-0002BF-Qr for emacs-devel@gnu.org; Mon, 10 May 2004 05:00:25 -0400 Original-Received: from [212.88.64.25] (helo=mail-relay.sonofon.dk) by monty-python.gnu.org with smtp (Exim 4.33) id 1BN6dd-0002Av-AF for emacs-devel@gnu.org; Mon, 10 May 2004 04:59:53 -0400 Original-Received: (qmail 18821 invoked from network); 10 May 2004 08:53:11 -0000 Original-Received: from unknown (HELO kfs-l.imdomain.dk.cua.dk) (213.83.150.2) by 0 with SMTP; 10 May 2004 08:53:11 -0000 Original-To: John Wiegley In-Reply-To: Original-Lines: 84 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:23028 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:23028 John Wiegley writes: > The following patch implements a file-handle interface for Emacs Lisp, > which allows files to be directly opened and read/written to without > an intervening buffer. Eshell can now use this, for example, to > greatly speed up output redirection (by several orders of magnitude). > > It is a simple interface that reads in strings, given a length, and > writes strings by examining their length: > > (let ((handle (file-handle-open "/tmp/some-file" "w"))) > (file-handle-write handle "Test data\n") > (file-handle-close handle) > > (setq handle (file-handle-open "/tmp/some-file" "r")) > (message (file-handle-read handle 128)) > (file-handle-close handle)) > This seems like a great idea, but it is not up to me to decide. Some comments: The doc string for -open need improvement. I'm not sure about using "r", "w", etc for the mode; using things like 'read 'write and 'append seems more lisp like. But I don't prefer either. The doc strings for -read and -write are bad. Instead of an explicit CONS as the handle, I would rather declare the file handle like this: struct Lisp_File_Handle { EMACS_INT size; struct Lisp_Vector *v_next; Lisp_Object handle_hi; Lisp_Object handle_lo; Lisp_Object file_name; Lisp_Object open_mode; }; and use handle_hi and handle_lo directly instead of all the CAR and CDR'ing. When you close the file handle, open_mode is set to nil. The file_name and open_mode can be used to improve the printing of the file handle as in else if (FILE_HANDLEP (obj)) { strout ("#open_mode)) { strout (XFILE_HANDLE (obj)->file_name, -1, -1, printcharfun, 0); strout (" ", -1, -1, printcharfun, 0); strout (XFILE_HANDLE (obj)->open_mode, -1, -1, printcharfun, 0); } else strout (" closed", -1, -1, printcharfun, 0); PRINTCHAR (')>'); } You don't address the issue of multibyte in -read and -write. It seems that you always assume things to be unibyte. I don't know what the right thing to do is, but maybe you should at least signal an error if things are not unibyte ? Otherwise, you should associate a coding system with the file-handle and use that for read and write. As a first shot at this, you could add the coding system as an optional third arg to -open, and assume unibyte/binary if no coding system was specified. A -seek operation would be nice I guess. And a -position (aka ftell) would be nice too. -- Kim F. Storm http://www.cua.dk