From: storm@cua.dk (Kim F. Storm)
Cc: emacs-devel@gnu.org
Subject: Re: request for review: Doing direct file I/O in Emacs Lisp
Date: 10 May 2004 08:52:33 +0200 [thread overview]
Message-ID: <m34qqodb9q.fsf@kfs-l.imdomain.dk> (raw)
In-Reply-To: <m2d65cx1ow.fsf@Majnun.local>
John Wiegley <johnw@gnu.org> 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 ("#<file-handle ", -1, -1, printcharfun, 0);
if (!NILP (XFILE_HANDLE (obj)->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 <storm@cua.dk> http://www.cua.dk
next prev parent reply other threads:[~2004-05-10 6:52 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-10 5:59 request for review: Doing direct file I/O in Emacs Lisp John Wiegley
2004-05-10 6:52 ` Kim F. Storm [this message]
2004-05-10 8:27 ` David Kastrup
2004-05-10 14:21 ` Stefan Monnier
2004-05-10 15:59 ` David Kastrup
2004-05-10 16:36 ` Stefan Monnier
2004-05-10 17:00 ` David Kastrup
2004-05-10 17:22 ` Stefan Monnier
2004-05-11 9:23 ` John Wiegley
2004-05-11 10:22 ` David Kastrup
2004-05-10 9:38 ` Andreas Schwab
2004-05-10 11:29 ` Eli Zaretskii
2004-05-10 11:23 ` Andreas Schwab
2004-05-10 15:04 ` Eli Zaretskii
2004-05-10 14:19 ` Stefan Monnier
2004-05-10 17:46 ` Oliver Scholz
2004-05-10 18:21 ` Stefan Monnier
2004-05-10 22:40 ` Oliver Scholz
2004-05-11 12:22 ` Richard Stallman
2004-05-10 17:54 ` Richard Stallman
2004-05-11 9:20 ` John Wiegley
2004-05-12 19:41 ` Richard Stallman
2004-05-13 7:59 ` Kai Grossjohann
2004-05-14 9:21 ` Richard Stallman
2004-05-14 10:42 ` Kai Grossjohann
2004-05-15 8:53 ` Richard Stallman
2004-05-15 16:27 ` Kai Grossjohann
2004-05-16 13:20 ` Richard Stallman
2004-05-14 21:43 ` John Wiegley
2004-05-15 18:33 ` Richard Stallman
2004-05-15 21:36 ` John Wiegley
2004-05-15 22:13 ` David Kastrup
2004-05-16 6:41 ` Eli Zaretskii
2004-05-16 17:46 ` David Kastrup
2004-05-17 11:04 ` Richard Stallman
2004-05-13 22:50 ` John Wiegley
2004-05-14 21:02 ` Richard Stallman
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/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m34qqodb9q.fsf@kfs-l.imdomain.dk \
--to=storm@cua.dk \
--cc=emacs-devel@gnu.org \
/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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).