From: ludo@gnu.org (Ludovic Courtès)
To: guile-devel@gnu.org
Subject: Re: [PATCH] Add a `read' method for ports
Date: Tue, 24 Jun 2008 22:50:12 +0200 [thread overview]
Message-ID: <87tzfi8smz.fsf@gnu.org> (raw)
In-Reply-To: 49dd78620806121718o3cb1ae2dta673ef86cee79382@mail.gmail.com
Hi Neil,
Sorry for the delay, I was off-line last week.
"Neil Jerram" <neiljerram@googlemail.com> writes:
> Agreed. Yesterday I was worried about possible confusion from
> bypassing a port's read buffer at a time when the read buffer has some
> data in it. But in fact this is not a problem, because
> scm_fill_input() should be (and in practice is) only called when the
> port's read buffer is empty.
Right. Putting an assertion in there to make sure can't hurt.
> Aesthetics are always tricky. I accept your point here, but against
> that we have to count
>
> - the cost of adding a new method to libguile's port definition
>
> - the benefit of (some) existing fill_input code being able to work
> with caller-supplied buffers automatically. (I say "some", because
> some fill_input implementations may make assumptions about the read
> buffer size and so not automatically take advantage of a larger
> caller-supplied buffer. But at least the important fport case will
> work automatically.)
Yeah, right.
These arguments make a lot of sense in 1.8. In the longer run, though,
I'd prefer to see `fill_input' superseded by a `read' method akin to
what I proposed. What do you think?
> Based on all this, I'd like to update my suggestion so that
>
> - scm_fill_input_buf always uses the caller's buffer
>
> - the remaining scm_fill_input_buf logic is inlined into scm_c_read
> (since that is the only place that uses scm_fill_input_buf, and
> inlining it permits some further simplifications).
OK. The issue is that if the caller-supplied buffer is smaller than the
port's buffer, we end up reading less data than we'd otherwise do. I
think this scenario should be addressed (by comparing `read_buf_size'
and `size'), as was the case in my proposal.
> + /* Now we will call scm_fill_input repeatedly until we have read the
> + requested number of bytes. (Note that a single scm_fill_input
> + call does not guarantee to fill the whole of the port's read
> + buffer.) For these calls, since we already have a buffer here to
> + read into, we bypass the port's own read buffer (if it has one),
> + by saving it off and modifying the port structure to point to our
> + own buffer. */
> + saved_buf = pt->read_buf;
> + saved_buf_size = pt->read_buf_size;
> + pt->read_pos = pt->read_buf = pt->read_end = buffer;
> + pt->read_buf_size = size;
`fill_input' methods can raise an exception, as is the case with soft
parts. Thus, this code should be protected by a `dynwind' that
restores the port's buffer and size.
> + remaining -= scm_c_read (port_or_fd, base + off, remaining);
> + if (remaining % sz != 0)
> + SCM_MISC_ERROR ("unexpected EOF", SCM_EOL);
> + ans -= remaining / sz;
Likewise, `scm_c_read ()' might raise an exception, so we may need a
`dynwind' here (my original patch for `uniform-vector-read!' did that).
Other than that, I'm OK with your patch.
Thanks,
Ludovic.
next prev parent reply other threads:[~2008-06-24 20:50 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-01 18:58 [PATCH] Add a `read' method for ports Ludovic Courtès
2008-06-08 21:01 ` Ludovic Courtès
2008-06-09 17:01 ` Neil Jerram
2008-06-09 20:59 ` Ludovic Courtès
2008-06-11 21:38 ` Neil Jerram
2008-06-12 0:19 ` Neil Jerram
2008-06-12 7:58 ` Ludovic Courtès
2008-06-13 0:18 ` Neil Jerram
2008-06-24 20:50 ` Ludovic Courtès [this message]
2008-07-15 19:24 ` Ludovic Courtès
2008-07-15 20:05 ` Neil Jerram
2008-07-15 22:08 ` Neil Jerram
2008-07-16 21:41 ` Ludovic Courtès
2008-09-12 20:09 ` Ludovic Courtès
2008-09-14 23:08 ` Neil Jerram
2008-09-15 1:01 ` Neil Jerram
2008-09-15 7:47 ` Ludovic Courtès
2008-09-15 7:44 ` Ludovic Courtès
2008-09-15 19:18 ` Neil Jerram
2008-09-15 19:20 ` Ludovic Courtès
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=87tzfi8smz.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=guile-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.
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).